var popUpWindow, sTitle;
	
function openPopUp(sItem, sURL) {
	
	var sPopupWindowOptions= "width=530,height=474,toolbar=yes,location=no,status=yes,resizable=yes,top=100,left=150";
	//For Spanish Site 
	var isSPA=0;
	
	switch (sItem) {
		case "ABOUTUS":
			sURL= sURL+"corp/default.aspx" ;
            sPopupWindowOptions= "width=530,height=474,scrollbars=yes,toolbar=yes,location=no,status=no,resizable=yes,top=50,left=100";           
			break;
		case "CONTACTUS":
			sURL= "/popup/default.asp?popup=CONTACTUSB2B";
			break;
		case "SUGGESTION":
			sURL= "/Suggestion/default.asp";
			sPopupWindowOptions= "width=810,height=600,scrollbars=yes,toolbar=yes,location=yes,status=yes,menubar=yes,resizable=yes,top=50,left=100";
			break;
		case "CONTACTUSDOCMAN":
			sURL= sURL+ "popup/default.asp?popup=CONTACTUSDOCMAN";
			break;
		case "CONTACTUSASTMAN":
			sURL= sURL+ "popup/default.asp?popup=CONTACTUSASTMAN";
			break;
		case "PRIVACY":
			sURL= sURL+"corp/default.aspx?pid=oc\\PrivacyPolicy";
sPopupWindowOptions= "width=766,height=500,scrollbars=yes,toolbar=yes,location=no,status=no,resizable=yes,top=50,left=100";
			break;
		case "IDNOTICE":
			sURL= sURL+"corp/default.aspx?pid=oc\\CustomerIDNotice";
sPopupWindowOptions= "width=766,height=500,scrollbars=yes,toolbar=yes,location=no,status=no,resizable=yes,top=50,left=100";
			break;
		case "SECURITY":
			sURL= sURL+"corp/default.aspx?pid=oc\\SecurityPolicy";
sPopupWindowOptions= "width=766,height=500,scrollbars=yes,toolbar=yes,location=no,status=no,resizable=yes,top=50,left=100";
			break;
		case "CAREERS":
			//sURL= sURL";
			sURL= sURL+"corp/default.aspx?pid=ca\\Default";

			sPopupWindowOptions= "width=766,height=500,scrollbars=yes,toolbar=yes,location=no,status=no,resizable=yes,top=50,left=100";
			break;
		case "LICENSING":
			sURL= sURL+"corp/default.aspx"+"?pid=oc\\LicensingDisclosure";
            sPopupWindowOptions= "width=530,height=474,scrollbars=yes,toolbar=yes,location=no,status=no,resizable=yes,top=50,left=100";           
			break;
		case "TERMSOFUSE":
			sURL= sURL+ "corp/?pid=oc\\WebsiteTermsofUse";
            sPopupWindowOptions= "width=530,height=474,scrollbars=yes,toolbar=yes,location=no,status=no,resizable=yes,top=50,left=100";           
			break;
		case "SITEFEEDBACK":
			sURL= sURL+ "popup/default.asp?popup=SITEFEEDBACKB2B";
			break;
		case "WHERENOW":
			sURL= sURL+ "popup/default.asp?popup=WHERENOW";
			break;
		case "B2BHOME":
			sURL= sURL+ "B2BAuto/pr/demo/QP/default.html";
			sPopupWindowOptions= "width=490,height=253,toolbar=no,location=no,status=no,menubar=no,resizable=yes,top=50,left=100";
			break;
		case "WHATISE-MITS":
			sURL= "/popup/default.asp?popup=WHATISE-MITS";
			break;
		case "APPROVALPOP":
			sURL= "/popup/default.asp?popup=APPROVALPOP";
			break;
		case "CLTUTORIAL":
			sURL= "/popup/default.asp?popup=CLTUTORIAL";
			var sPopupWindowOptions= "width=530,height=634,toolbar=yes,location=no,status=yes,resizable=yes,top=25,left=150";
			break;
		case "EMITSFAQ":
			sURL= sURL+ "help/livefaq.asp?CURRENTPAGE=EMITS&amp;FROM=EMITS";
			break;
		case "CSAGFAQ":
			sURL= sURL+ "help/livefaq.asp?CURRENTPAGE=CSAG&amp;FROM=EMITS";
			break;
		case "URAVGTTDEF":
			sURL= "/popup/default.asp?popup=URAVGTTDEF";
			break;
		case "PTDAVGTTDEF":
			sURL= "/popup/default.asp?popup=PTDAVGTTDEF";
			break;
		case "LDAVGTTDEF":
			sURL= "/popup/default.asp?popup=LDAVGTTDEF";
			break;
		case "FRAVGTTDEF":
			sURL= "/popup/default.asp?popup=FRAVGTTDEF";
			break;
		case "EMAILCORR":
			sURL= "/popup/default.asp?popup=EMAILCORR";
			break;
		case "SELLERCORR":
			sURL= "/popup/default.asp?popup=SELLERCORR";
			break;
			//>>>> Average Turn Time - JDI
			case "DATAVALIDATIONARCHIVE":
				sURL= "/popup/default.asp?popup=DATAVALIDATIONARCHIVE";
				
				break;
			case "FUNDINGREVIEWARCHIVE":
				sURL= "/popup/default.asp?popup=FUNDINGREVIEWARCHIVE";
				break;
			case "PTDCONDITIONARCHIVE":
				sURL= "/popup/default.asp?popup=PTDCONDITIONARCHIVE";
			break;
		//Prior To Purchase Condition - Pradeep Juyal
		case "PFRCONDITIONARCHIVE":
			sURL= "/popup/default.asp?popup=PFRCONDITIONARCHIVE";
			break;	
		//Prior To Purchase Condition - Pradeep Juyal Ends Here
		case "DATAVALIDATION":
		sURL= "/popup/default.asp?popup=DATAVALIDATION";
		
		break;
		
		//New Avg Turn Time Links - Starts here
		//Added By : Pradeep Juyal
		
		case "DATAVALIDATIONATTC":
		sURL= "/popup/default.asp?popup=DATAVALIDATIONATTC";
		break;
				
		case "PTDCONDITIONATTC":
		sURL= "/popup/default.asp?popup=PTDCONDITIONATTC";
		break;
		
		case "FUNDINGATTC":
		sURL= "/popup/default.asp?popup=FUNDINGATTC";
		break;
			
		case "PREFUNDINGATTC":
		sURL= "/popup/default.asp?popup=PREFUNDINGATTC";
		break;
		
		case "PRIFUNDINGATTC":
		sURL= "/popup/default.asp?popup=PRIFUNDINGATTC";
		break;
		//New Avg Turn Time Links -Ends Here
				
			case "FUNDINGREVIEW":
				sURL= "/popup/default.asp?popup=FUNDINGREVIEW";
				break;
			case "PFRCONDITION":
				sURL= "/popup/default.asp?popup=PFRCONDITION";
				break;
			case "PTDCONDITION":
				sURL= "/popup/default.asp?popup=PTDCONDITION";
				break;
		//<<<< Average Turn Time - JDI
		case "Zonahipotecaria":
			isSPA=1;
			sURL= "/spanish/default.asp?popup=0";
			sPopupWindowOptions= "width=810,height=600,scrollbars=yes,toolbar=yes,location=yes,status=yes,menubar=yes,resizable=yes,top=50,left=100";
			break;			
			
		case "SPANISH":
			//>>>> FixSiteLoopHoles
			var stest
			sURL=sURL.toLowerCase()
			sURL= sURL.replace("https://", "http://");
			sURL= sURL.replace("http://www.", "http://");
		  
			stest=window.parent.location + ""
			
			stest=stest.toLowerCase()
			stest= stest.replace("https://", "http://");
			stest= stest.replace("http://www.", "http://");
		
			stest = stest.replace(sURL, "")
			firstChar = stest.slice(0,1)
			
			if(firstChar=="/")
			{
			 stest = stest.slice(1)
			}
			sURL="/spanish/Redirect.asp?url=" + stest
		    //<<<< FixSiteLoopHoles
			/*return;
			isSPA=1;
			sURL= "/spanish/default.asp?popup=1";*/
			sPopupWindowOptions= "width=810,height=600,scrollbars=yes,toolbar=yes,location=yes,status=yes,menubar=yes,resizable=yes,top=50,left=100";
			break;	

		case "SPANISHBANNER":
			isSPA=1;
			sPopupWindowOptions= "width=810,height=600,scrollbars=yes,toolbar=yes,location=yes,status=yes,menubar=yes,resizable=yes,top=50,left=100";
			break;	
		case "LTFB":
			sPopupWindowOptions= "width=810,height=625,scrollbars=yes,toolbar=yes,location=yes,status=yes,menubar=yes,resizable=yes,top=50,left=100";			
		break;
			
		//>>>> FixSiteLoopHoles
        case "RATES":
			//This case added as a part of the Site loophole fix
			window.location= sURL + "eMITS/Frames.asp"
			sURL="/popup/default.asp?popup=RATES"
			sPopupWindowOptions= "width=530,height=590,toolbar=yes,location=no,status=yes,resizable=yes,top=50,left=150";
		
			break;
	    case "PRODUCTS":
			//sURL= sURL+ "../rates/default.asp?popup=1";
			sURL= "/popup/default.asp?popup=PRODUCTS"
			sPopupWindowOptions= "width=530,height=590,toolbar=yes,location=no,status=yes,resizable=yes,top=50,left=150";
			break;
		//<<<< FixSiteLoopHoles
	}
	
	if (sItem=="B2BHOME") {
		var count = GetCookie('HomePagePopup');
		if (count==null) {
			var date = new Date();
			date.setTime(date.getTime()+(3*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();

			document.cookie = 'HomePagePopup=B2BHomePagePopup' + expires + '; path=/'
			
			if(isSPA==1){
				var spaPopUP= open(sURL,'spanish',sPopupWindowOptions);
				spaPopUP.focus();
			if(spaPopUP.closed){
				var spaPopUP= open(sURL,'spanish',sPopupWindowOptions);
				spaPopUP.focus();
			}
			}
			
			else{
			popUpWindow=window.open(sURL,'',sPopupWindowOptions);
			}
		}
	}
	else
	{
			if(isSPA==1){
				var spaPopUP= open(sURL,'spanish',sPopupWindowOptions);
				spaPopUP.focus();
			if(spaPopUP.closed){
				var spaPopUP= open(sURL,'spanish',sPopupWindowOptions);
				spaPopUP.focus();
			}
			}
			else{
				popUpWindow=window.open(sURL,'',sPopupWindowOptions);
			}
	}
}

function launchGlossary(here, sURL) {
	var where;
	where=sURL+"b2bauto/glossary/glossary_index.asp?goto="+here;
	newWind=window.open(where,"newWindow","status=no,toolbar=no,scrollbars=yes,directories=no,location=no,resize=on,width=530,height=320")
	newWind.focus();
}

//approval validation

function isBlank(param) {
	for (var i =0; i < param.length; i++) {
		var c = param.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}	
	return true;
}		

function validateEmail( strValue) {
/************************************************
DESCRIPTION: Validates that a string contains a 
  valid email pattern. 
  
 PARAMETERS:
   strValue - String to be tested for validity
   
RETURNS:
   True if valid, otherwise false.
   
REMARKS: Accounts for email with country appended
  does not validate that email contains valid URL
  type (.com, .gov, etc.) and optionally,
  a valid country suffix.  Since email has many
  forms this expression only tests for near valid
  address.  Some additional validation may be
  required.
*************************************************/
var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,4}(\.[a-z]{2}){0,2})$/i;
  //check for valid email
  return objRegExp.test(strValue);
}

function validateUSPhone( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains valid
  US phone pattern. 
  Ex. (999) 999-9999 or (999)999-9999
  
PARAMETERS:
   strValue - String to be tested for validity
   
RETURNS:
   True if valid, otherwise false.
*************************************************/
  var objRegExp  = /(^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$)|(^\d{3}\-\d{3}\-\d{4}$)|(^\d{10}$)/;
 
  //check for valid us phone with or without space between 
  //area code
  return objRegExp.test(strValue); 
}

function validateForm(pageno)
{
		if (pageno == 1)
			{
			if (document.all.headstate[0].selected)
				{
					alert("Please select a state from the drop down.");
					document.all.headstate.focus();
					return (false);
				}	
				return true;	
			}
		if (isBlank(document.all.companyname.value))
		{
			alert("You must enter a valid name");
			document.all.companyname.value = ""
			document.all.companyname.focus();
			return false;
		}
				
		if (document.all.headstate[0].selected) {
				alert("Please select a state from the drop down.");
				document.all.headstate.focus();
				return (false);
			}	
			
		if (isBlank(document.all.name.value))
		{
			alert("You must enter a valid name");
			document.all.name.value = ""
			document.all.name.focus();
			return false;
		}
		
		if (!validateUSPhone(document.all.phone.value))
			{
				alert("Please enter a valid phone number XXXXXXXXXX ");
				document.all.phone.value = "";
				document.all.phone.focus();
				return (false);
	
			}
		
		if (!validateEmail(document.all.email.value) || isBlank(document.all.email.value))
			{
				alert("You must enter a valid E-mail Format");
				document.all.email.value = "";
				document.all.email.focus();
				return false;
		}
					
				
		return true;

}

function launchPdf(source, sURL) {
	var where;
	switch (source) {
			
			case "12MATFAQ":
				if (getCookieeValue("SELLERTYPE") == "CORRESPONDENT") 
					{
						where=sURL+"b2bauto/products/12MATFAQ-Corr.pdf";		
					}
				else	
					{
						where=sURL+"b2bauto/products/12MATFAQ-Whol.pdf";		
					}
				break;

			case "12MATCOMPARISION":
				if (getCookieeValue("SELLERTYPE") == "CORRESPONDENT") 
					{
						where=sURL+"b2bauto/products/12MATComparison-Corr.pdf";		
					}
				else	
					{
						where=sURL+"b2bauto/products/12MATComparison-Whol.pdf";		
					}
				break;

			}
	window.location = where;
	
}
function getCookieeValue(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}


function getCookie(sName) {
	// cookies are separated by & when set by vbscript in asp
	var aCookie = document.cookie.split("&");
	for (var i=0; i < aCookie.length; i++)
	{
		// a name/value pair (a crumb) is separated by an equal sign
		var aCrumb = aCookie[i].split("=");
		if (sName == aCrumb[0]) {
		  return unescape(aCrumb[1]);
		}
	}

	// a cookie with the requested name does not exist
	return null;
}

function gotoeMITS() {
	if (getCookie("USERNAME") == null) {
		alert("The information you've requested can only be accessed by\nIndyMac Bank B2B Approved Customers. You will now be\ntaken to the Approved Customers Log In page.");
	}
}

function loadOpener(sURL, beMITS) {
	if (beMITS) {
		window.opener.location = sURL;
	}
	else {
		parent.window.opener.top.location = sURL;
	}
    parent.window.opener.top.focus();
    parent.window.close();
}

function doPopUp( sfile ){
	window.open( sfile ,null,"height=400,width=450,status=no,toolbar=no,menubar=no,location=no");
	//window.showModalDialog ( sfile, null, 'dialogHeight=15;dialogWidth=20;status=no;help=no' );
}

function popUp(link)
{
	popUpWindow = window.open(link,'POPUP','width=530,height=474,toolbar=yes,location=no,status=no,resizable=yes,top=50,left=100')
}	
	
function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
		return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

////// This is for the Tabs
var CurTab;

function loadPage(sPage, bPOPUP, bFramed) 
{
	switch (sPage) {
		case "RATESHEETS":
			sURL= "/rates/default.asp";
			break;
		case "RATECOMPARISONS":
			sURL= "/rates/comparisons.asp";
			break;
		case "E-RATESHEETS":
			sURL= "/rates/eratesheets/default.asp";
			break;
		case "MM":
			sURL= "/customerresourcecenter/marketingmaterials/marketingmaterials.asp";
			break;
		case "MM_SPA":
			sURL= "/customerresourcecenter/marketingmaterials/spa/marketingmaterials.asp";
			break;
	}
	if (bPOPUP) {
		sURL+= "?popup=1"
	}

	if (bFramed) {
		parent.document.location.href= sURL;
	}
	else {
		document.location.href= sURL;
	}
}

function makeHighLighted(el)
{
	var txtObj
	
	if (navigator.appVersion.indexOf("MSIE 4.0") != -1)
	{
		txtObj = document.all(el);
	}
	else
	{
		txtObj= document.getElementById(el);
	}
	
	with (txtObj.style) {
		if (el != CurTab) {
			//color= "white";
			textDecoration= "underline";
		}	
	}
}
function makeUnHighLighted(el)
{
	var txtObj
	
	if (navigator.appVersion.indexOf("MSIE 4.0") != -1)
	{
		txtObj = document.all(el);
	}
	else
	{
		txtObj= document.getElementById(el);
	}
	
	with (txtObj.style)
	{
		if (el != CurTab) {
			//color= "#E0E0E0";
		}
		textDecoration= "none";
	}
}

function makeLinkUnHighLighted(el)
{
	var txtObj;
	
	if (navigator.appVersion.indexOf("MSIE 4.0") != -1)
	{
		txtObj = document.all(el);
	}
	else
	{
		txtObj= document.getElementById(el);
	}
	
	with (txtObj.style)
	{
		color= "#336699";
	}
}

function makeLinkHighLighted(el)
{
	var txtObj;
	
	if (navigator.appVersion.indexOf("MSIE 4.0") != -1)
	{
		txtObj = document.all(el);
	}
	else
	{
		txtObj= document.getElementById(el);
	}
	
	with (txtObj.style)
	{
		color= "#FF9900";
	}
}

function hideShowSection(SectionID)
{ 	
	var oObj;
	var imgObj;
		
	if (navigator.appVersion.indexOf("MSIE 4.0") != -1)
	{
		oObj = document.all(SectionID);
		imgObj= document.all("img_"+SectionID);
	}
	else
	{
		oObj= document.getElementById(SectionID);
		imgObj= document.getElementById("img_"+SectionID);
	}
		
	if (oObj.style.display == 'block')
	{ 		
		oObj.style.display = 'none'; 		
  		imgObj.src = '/b2bauto/images/buttons/icnExpand.gif';
	} 	
	else	
	{
		oObj.style.display = 'block'; 		
  		imgObj.src = '/b2bauto/images/buttons/btnClose.gif';  		
	}
}

function addBookMark()
{
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4))
	{
		window.external.AddFavorite (window.location,document.title);
	}
	else {
		var msg = "Don't forget to bookmark us!";
		if(navigator.appName == "Netscape") msg += " (CTRL-D)";
		alert(msg);
	}
}

function gotoPage(value)
{
	

	//parent.location.href = value;

   //>>>> FixSiteLoopHoles
	strURL=encodeURI(window.parent.location) + ""
	if (value=='whole')
	  strURL= strURL.replace('/corr','/whole')
	if (value=='corr')
	  strURL= strURL.replace('/whole','/corr')
	parent.location.href = "/include/SetCookie.asp?"+"ST="+value+"&url="+strURL
	//<<<< FixSiteLoopHoles
}

//RCS - Spanish Micro-site Helper functions


//Purpose of Change: JDI - www.zonahipotecaria.com
//Updated by: Kalpana Khedkar
//Date: 11/16/2004
//Logic: Added the logic for Zonahipotecaria main site
//Change:Start

function TransferSpaMainSite(sTransferUrl, sTarget,bpopup) {
	var returnVal = window.showModalDialog("/spanish/TransferPopup.asp", null, "dialogHeight:200px; dialogLeft:200px; dialogWidth:520px;help:no; resizable:yes; scroll:no; status:no;");
	if (bpopup != "False") 
	{
	switch (returnVal) {
		case "Direct" :	
			if (sTarget == "_new") {
					window.open(sTransferUrl,'');
				}
			else {
				if(!window.opener.closed)	
				{
				window.opener.location.href = sTransferUrl;
				window.opener.focus();
				}
				else
				{
				var w = window.screen.availWidth;
				var h = window.screen.availHeight;
				var win = window.open(sTransferUrl,'facts','screenX=0,screenY=0,left=0,top=0,width=' + w + ',height=' + h +
				',resizable=1,status=1,menubar=1,toolbar=1,location=1,scrollbars=1');
				win.focus();
				if (!win.closed){
					var win = open (sTransferUrl, 'facts',
					'screenX=0,screenY=0,left=0,top=0,width=' + w + ',height=' + h +
					',resizable=1,status=1,menubar=1,toolbar=1,location=1,scrollbars=1');
					win.focus();
					}
				}
			}
			break;
		default :
	 }
	}
	else
	{
	 switch (returnVal) {
		case "Direct" :
			var w = window.screen.availWidth;
			var h = window.screen.availHeight;
			var win = open (sTransferUrl, 'facts',
				'screenX=0,screenY=0,left=0,top=0,width=' + w + ',height=' + h +
				',resizable=1,status=1,menubar=1,toolbar=1,location=1,scrollbars=1');
				win.focus();
			if (!win.closed){
				var win = open (sTransferUrl, 'facts',
				'screenX=0,screenY=0,left=0,top=0,width=' + w + ',height=' + h +
				',resizable=1,status=1,menubar=1,toolbar=1,location=1,scrollbars=1');
				win.focus();
				}
			break;

		default :
	 }
	}
}

//To open th English link in the spanish site
function MainWindow(sTransferUrl)
{
	
	var w = window.screen.availWidth;
	var h = window.screen.availHeight;
	var newwin = open (sTransferUrl, 'facts',
		'screenX=0,screenY=0,left=0,top=0,width=' + w + ',height=' + h +
		',resizable=1,status=1,menubar=1,toolbar=1,location=1,scrollbars=1');
	if (newwin && !newwin.closed){
		newwin.focus();
	}
}
//Change:End


function launchOptOut() {
	var j;
	var i;
	var where;
	
	j=document.all.OptOutType.length;
	for (i=0; i<j; i++){
		if(document.all.OptOutType[i].checked) var here = document.all.OptOutType[i].value
	}
		
	if (here == 1) {	
	where = "http://apps.indymacbank.com/cSpam/landing.asp?biz=CORR"; }

	if (here == 2) {	
	where = "http://apps.indymacbank.com/cSpam/landing.asp?biz=WHOLESALE"; }

	if (here == 3) {	
	where = "http://apps.indymacbank.com/cSpam/landing.asp?biz=SUBPRIME"; }

	newWind=window.open(where,"newWindow","status=no,toolbar=no,scrollbars=yes,directories=no,location=no,resize=on")
	newWind.focus();

}

function trim(argvalue)
{
	var tmpstr = ltrim(argvalue);
	return rtrim(tmpstr);
}
function ltrim(argvalue)
{
	while (1)
	{
		if (argvalue.substring(0, 1) != " ")
		break;
		
		argvalue = argvalue.substring(1, argvalue.length);
	}
	return argvalue;
}
function rtrim(argvalue)
{
	while (1)
	{
		if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ")
		break;
		
		argvalue = argvalue.substring(0, argvalue.length - 1);
	}
	return argvalue;
}
