var popUpWindow, sTitle;
var opopUp = ""

function openPopUp(sItem, sURL, pResize, pWidth, pHeight, pScrollBars) {

	var iResize, iWidth, iHeight, sScrollBars;

	sItem = sItem.toUpperCase();

	if (pResize ==  undefined || pResize == "") {
		iResize = "no";
	} else {
		iResize = pResize;
	}		

	if (pWidth ==  undefined || pWidth == "") {
		iWidth = 530;
	} else {
		iWidth = pWidth;
	}		
	
	if (pHeight ==  undefined || pHeight == "") {
		iHeight = 474;
	} else {
		iHeight = pHeight;
	}			


	if (pScrollBars ==  undefined || pScrollBars == "") {
		sScrollBars = "auto";
	} else {
		sScrollBars = pScrollBars;
	}			


	var sPopupWindowOptions= "width=" + iWidth + ",height=" + iHeight + ",toolbar=yes,location=no,status=yes,resizable=" + iResize + ",top=100,left=150;scrollbars=" + sScrollBars;

	if (getsubid() == "subid=ENG") {
		sURL = sURL + "popup/default.asp?popup=" + sItem;
	} else {
		sURL = sURL + "popup/default.asp?" + getsubid() + "%26popup=" + sItem;
	}	

	switch (sItem) {
		case "MYMORTGAGECALCULATOR","REGMBSABS":
			if (opopUp != "" & opopUp.closed != true) {
			       	opopUp.focus();
			       	opopUp = window.open(sURL,"NewWin",sPopupWindowOptions);
			} else {
			       	opopUp = window.open(sURL,"NewWin",sPopupWindowOptions);
			}
		        break;	
		default:
		    popUpWindow= window.open(sURL,'',sPopupWindowOptions);	
		    break;
	}	   		
}

function loadOpener(sURL) {
    parent.window.opener.top.location = sURL;
    parent.window.opener.top.focus();
    parent.window.close();
}

function launchLivePerson(){
	var livePersonURL

	livePersonURL = "https://vip2.cluster1.v3x.nyc.service.liveperson.net/faq.asp?lp_aname=indymacpb&lp_gname=default&lp_faq_interface_type=STAND_ALONE"
	window.open(livePersonURL, 'liveperson', 'width=420,height=400,scrollbars=yes')
}


function launchLivePerson2(){
	var livePersonURL

	livePersonURL = "http://indymac.client.liveperson.net/clients/indymac/"
	window.open(livePersonURL, 'liveperson', 'width=300,height=350,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=yes')
}

function launchGlossary(pUnit,pHere) {
	var where;	
	where="/glossaries/default.asp?"+ getsubid() + "&unit=" + pUnit + "&goto=" + pHere;	
	newWind=window.open(where,"newWindow","status=no,toolbar=no,scrollbars=yes,directories=no,location=no,resize=on,width=530,height=320")
	newWind.focus();
}


var oNewWin = ""
//more flexible pop up window without top banner
function goRemote(vLoc,vWidth,vHeight,vResize)  {
        var options = "location=0,toolbar=1,menubar=0,scrollbars=yes,width=" + vWidth+ ",height=" + vHeight + ",resizable=" + vResize + ",top=100,left=150";
        // alert(oNewWin);
        if (oNewWin != "" & oNewWin.closed != true) {
        	oNewWin.focus();
        	oNewWin = window.open(vLoc,"NewWin",options);
        } else {
        	oNewWin = window.open(vLoc,"NewWin",options);
        }
}

function getsubid(a)
{

        var url;
        
        
        if (a=="" || a == null)
         {
            url = document.location;	
         }	
        else{
          url = a;
        }
        	
        var pattern = new RegExp("subid=\\w{3}","i");
        
        var result = pattern.exec(url);
        
        if (result !=null)
          {  	
           return(result);
          }
        else
          {
           return("subid=ENG");	
          }

}

function gosubid(id)
{
	var url = String(document.location);		
	var pattern = new RegExp("subid=(\\w{3})","i");
        
        var result = pattern.exec(url);        
        
        if (result !=null)
          {  	                      
           document.location = url.replace(result[0], "subid="+id);
          }
        else
          {
           if (url.indexOf(".asp")<0)
           {
             if ( url.charAt(url.length-1) !="/" )
               {
                  url += "/default.asp"	
               }	
             else
               {
                  url += "default.asp"	
               }
           }           
           if (url.indexOf("?")>0)
             {
               	document.location = url + "&subid="+id;
             }
           else
             {
             	document.location = url + "?subid="+id;
             }	
          }
}

//Script for surveys
var showSurveyPop = true;
function showSurvey(){
	if(surveyCookieDuration == ""){
		surveyCookieDuration = 7;
	}
	if(surveyURL == ""){
		surveyURL = "http://63.94.60.203/sm/usindym000/popup.asp"
	}
	var hideIt = readCookie(surveyName);
	if(!hideIt){
		if(showSurveyPop){
			createCookie(surveyName,"1",surveyCookieDuration)
			window.open(surveyURL,"ExitDemo","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=290,height=275");
		}
	}
}

function createCookie(name,value,days){
	if (days){
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0; i < ca.length; i++){
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name){
	createCookie(name,"",-1);
}
