var WindowOpener;

if (!document.layers&&!document.all)
event="test";
function showtip(current,e,text){

if (document.all){
thetitle=text.split('<br>')
if (thetitle.length>1){
thetitles=''
for (i=0;i<thetitle.length;i++)
thetitles+=thetitle[i]
current.title=thetitles
}
else
current.title=text
}

else if (document.layers){
document.tooltip.document.write('<layer bgColor="white" style="border:1px solid black;font-size:12px;">'+text+'</layer>')
document.tooltip.document.close()
document.tooltip.left=e.pageX+5
document.tooltip.top=e.pageY+5
document.tooltip.visibility="show"
}
}
function hidetip(){
if (document.layers)
document.tooltip.visibility="hidden"
}
function OpenSubWindow(sUrl,iWidth,iHeight,sName){
	sName=new String(sName);
	if(sName=="undefined")
		sName="subWindow";
	subWindow=window.open(sUrl,sName,"top=40,left=40,height=" + iHeight + ",width=" + iWidth + ",status=no,scrollbars=yes,toolbar=no,menubar=no,location=no");
	WindowOpener=subWindow.opener;
	setTimeout("subWindow.focus();",100);
}


function OpenWindow(sUrl,sName){
	sName=new String(sName);
	if(sName=="undefined")
		sName="subWindow";
	subWindow=window.open(sUrl,sName);
	WindowOpener=subWindow.opener;
	setTimeout("subWindow.focus();",100);
}

function OpenStatusWindow(sUrl,iWidth,iHeight,sName){
	sName=new String(sName);
	if(sName=="undefined")
		sName="subWindow";
	subWindow=window.open(sUrl,sName,"top=20,left=20,height=" + iHeight + ",width=" + iWidth + ",status=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,resizable=yes");
	WindowOpener=subWindow.opener;
	setTimeout("subWindow.focus();",100);
}

function OpenSubWindowNoScroll(sUrl,iWidth,iHeight,sName){
	sName=new String(sName);
	if(sName=="undefined")
		sName="subWindow";
	subWindow=window.open(sUrl,sName,"top=40,left=40,height=" + iHeight + ",width=" + iWidth + ",status=no,scrollbars=no,toolbar=no,menubar=no,location=no");
	WindowOpener=subWindow.opener;
	setTimeout("subWindow.focus();",100);
}

function OpenSubWindowToolbar(sUrl,iWidth,iHeight,sName){
	sName=new String(sName);
	if(sName=="undefined")
		sName="subWindow";
	subWindow=window.open(sUrl,sName,"top=40,left=40,height=" + iHeight + ",width=" + iWidth + ",status=no,scrollbars=yes,toolbar=yes,menubar=yes,location=yes");
	WindowOpener=subWindow.opener;
	setTimeout("subWindow.focus();",100);
}

function c_SetCookie(sName,sValue,sExpires,sPath,sDomain,bIsSecure){
	if(sExpires=="default"){
		sExpires=new Date();
		sExpires.setTime(sExpires.getTime()+(5*365*24*60*60*1000));//+ five years
	}
	var sExpiresString=((sExpires==null)?"":(";expires=" + sExpires.toGMTString()));
	var sPathString=((sPath==null)?"":(";path=" + sPath));
	var sDomainString=((sDomain==null)?"":(";domain=" + sDomain));
	var sSecureString=(bIsSecure?";secure":"");
	document.cookie=sName+"="+escape(sValue)+sExpiresString+sPathString+sDomainString+sSecureString;
}

function c_SetCookieEZ(sName,sValue){
	document.cookie=sName+"="+escape(sValue);
}

function c_DeleteCookie(sName){
	var sExpires=new Date();
	sExpires.setTime(sExpires.getTime()-(3*24*60*60*1000));//- three days
	document.cookie=sName+"=x"+";expires="+sExpires.toGMTString();
}

function c_GetCookie(sName){
	var sValue=null;
	var sCookie=" " + document.cookie + ";";
	var sSearchName=" " + sName + "=";
	var iCookieStart=sCookie.indexOf(sSearchName);
	var iCookieEnd;
	if(iCookieStart!=-1){
		iCookieStart+=sSearchName.length;
		iCookieEnd=sCookie.indexOf(";",iCookieStart);
		sValue=unescape(sCookie.substring(iCookieStart,iCookieEnd));
	}
	return(sValue);
}

function c_GetCookieCount(){
	var iCount=0;
	var sCookie=" " + document.cookie + ";";
	var sSearchName=" " + sName + "=";
	var iCookieStart=sCookie.indexOf(sSearchName);
	while(iCookieStart!=-1){
		iCount+=1;
		iCookieStart=sCookie.indexOf(sSearchName,iCookieStart+sSearchName.length);
	}
	return(iCount);
}

function c_GetCookieByIndex(sName,iIndex){
	var sValue=null;
	if(iIndex<1)
		return(sValue);
	var sCookie=" " + document.cookie + ";";
	var sSearchName=" " + sName + "=";
	var iCookieStart=sCookie.indexOf(sSearchName);
	var iCookieEnd;
	var i;
	for(i=1;i<iIndex;i++)
		iCookieStart=sCookie.indexOf(sSearchName,iCookieStart+sSearchName.length);
	if(iCookieStart!=-1){
		iCookieStart+=sSearchName.length;
		iCookieEnd=sCookie.indexOf(";",iCookieStart);
		sValue=unescape(sCookie.substring(iCookieStart,iCookieEnd));
	}
	return(sValue);
}


function QueryString(key) {
	var value = null;
	for (var i=0;i<QueryString.keys.length;i++)
	{
		if (QueryString.keys[i]==key)
		{
			value = QueryString.values[i];
			break;
		}
	}
	return value;
}

QueryString.keys = new Array();
QueryString.values = new Array();

function QueryString_Parse() {
	var query = window.location.search.substring(1);
	var pairs = query.split("&");

	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;
		}
	}
}

QueryString_Parse();

	function OpenPetWindow(sUrl, sName){
		sName=new String(sName);
		if(sName=="undefined")
			sName="subWindow";
		subWindow=window.open(sUrl,sName);
		WindowOpener=subWindow.opener;
		setTimeout("subWindow.focus();",100);
	}
function formURL(command) {
	url = '/HICServlet' + '?' + command + '=' + '&code=';
	x=QueryString('code');
	url = url + x;
	OpenPetWindow(url,'PetInsurance')
}
function openPetInCurrWindow(command) {
	url = '/HICServlet' + '?' + command + '=' + '&code=';
	x=QueryString('code');
	url = url + x;
	document.location.href = url;
}	
	
	function appLauncherNOAlt(link, img, alt, extraParams, newWindow) {
		urlToLaunch = link;
		if (extraParams != "") {
			if (link.indexOf("?") != -1) {
				nextChar = "&";
			} else {
				nextChar = "?";
			}
			fields = extraParams.split(",");
			for (var i=0; i<fields.length; i++) {
				var value = QueryString(fields[i]);
				if (value != null) {
					urlToLaunch = urlToLaunch + nextChar + fields[i] + "=" + value;
					nextChar = "&";
				}
			}
		}

		if ((newWindow == "Y") || (newWindow == "y")) {
			destination = 'javascript:OpenStatusWindow(' + "'" + urlToLaunch + "'" + ",655, 500,'" + "app" + "');";
		} else {
			destination = urlToLaunch;
		}

		if (img != "") {
			visual = '<img src="' + img + '" alt="' + alt + '">';
		} else {
			visual = alt;
		}

		builtLink = '<a href="' + destination + '">' + visual + '</a>'
		
		document.write(builtLink);
	}

	function appLauncher(link, img, linkLabel, altText, extraParams, newWindow){
		if(arguments.length == 5){
			appLauncherNOAlt(link, img, linkLabel, altText, extraParams);
		} else {
		
			urlToLaunch = link;
	
			if (extraParams != "") {
		
				if (link.indexOf("?") != -1) {
					nextChar = "&";
				} else {
					nextChar = "?";
				}
			
				fields = extraParams.split(",");
	
				for (var i=0; i<fields.length; i++) {
			
				var value = QueryString(fields[i]);
					if (value != null) {
						urlToLaunch = urlToLaunch + nextChar + fields[i] + "=" + value;
						nextChar = "&";
					}
				}
		
			}
	
			if ((newWindow == "Y") || (newWindow == "y")) {
				destination = 'javascript:OpenStatusWindow(' + "'" + urlToLaunch + "'" + ",655, 500,'" + "app" + "');";
			} else {
				destination = urlToLaunch;
			}
		
			if (img != "") {
				visual = '<img src="' + img + '" alt="' + altText + '">';
			} else {
				visual = linkLabel;
			}
	
			builtLink = '<a href="' + destination + '">' + visual + '</a>';
	
			document.write(builtLink);
		}
	}

	function leaveSiteLink(img, alt) {
	    var linkUrl = QueryString('url');
            builtLink = '<a href="#" onclick="openLink(\'' + linkUrl + '\');"><img src="' + img + '" alt="' + alt + '"></a>';
	    document.write(builtLink);
	}

	
	 function openLink(url) {
	   var isMaximisedWindow = QueryString('MaxWin');
	   if(isMaximisedWindow != null && isMaximisedWindow =='Y'|| isMaximisedWindow =='y' ){
		   window.location.href=url;
		   window.moveTo(0,0);
	   	   window.resizeTo(screen.availWidth,screen.availHeight);
	  }
	  else{
		  window.location.href=url;
	  }
	}

	function maximiseWindow() {
	   var isMaximisedWindow = QueryString('MaxWin');
	   if(isMaximisedWindow != null && isMaximisedWindow =='Y'|| isMaximisedWindow =='y' ){
		   window.moveTo(0,0);
	   	   window.resizeTo(screen.availWidth,screen.availHeight);
	  }
	  else{
		//do not maximise window
	  }
	}
	

	function getElement(name) {
		return document.getElementById(name);
	}

	function checkGecko(sUrl,iWidth,iHeight,sName){
		if (navigator.product == 'Gecko'){
		location.href=sUrl;
		} else {
			OpenStatusWindow(sUrl,iWidth,iHeight,sName);
		}
	}
	
	function SubmitQuote(sproduct, stateField) {
		var product;
		var state;
		var a = QueryString('a');
		var cid = QueryString('cid');
		var target = QueryString('target');
	
		if(a==null){
			a = QueryString('A');
		}

		if(cid==null){
			cid = QueryString('CID');
		}

		if(target==null){
			target = QueryString('TARGET');
		}

		
		var panswerfinancial="";

		if(a==null && cid!=null && target !=null){
			 panswerfinancial = "&cid="+cid+"&target="+target;
		}else if(cid==null && a!=null && target !=null){
			 panswerfinancial = "&a="+a+"&target="+target;
		}else if(target==null && a!=null && cid !=null){
			 panswerfinancial = "&cid="+cid+"&a="+a;
		}else if(target==null && a==null && cid !=null){
			 panswerfinancial = "&cid="+cid;
		}else if(target==null && cid==null && a !=null){
			 panswerfinancial = "&a="+a;
		}else if(target!=null && cid==null && a ==null){
			panswerfinancial = "&target="+target;
		}
		else if(target!=null && cid!=null && a !=null){
			panswerfinancial = "&cid="+cid+"&a="+a+"&target="+target;
		}


		product = sproduct ;
		if(product=="homeowners")
		{
			state=stateField.options[stateField.selectedIndex].value;
			

			if(state=="NY"){
				OpenSubWindowToolbar('/HICServlet?cmd_InsuranceQuoteNY=&lstProperty=' + product +  '&lstState=' + state+ '&accept-language=en-US',650,550,'sub');
			}
			else{

					if(a==null&&cid==null&&target==null){
						window.open('/HICServlet?cmd_InsuranceQuote=&lstProperty=homeowners&accept-language=en-US','sub',"height=" + screen.availheight + ",width=" + screen.availwidth +'screenX=0,screenY=0,top=0,left=0,status=no,scrollbars=yes,toolbar=yes,menubar=yes,resizable=yes,location=yes');

					}else {
						window.open('/HICServlet?cmd_InsuranceQuote=&lstProperty=homeowners'+panswerfinancial+'&accept-language=en-US','sub',"height=" + screen.availheight + ",width=" + screen.availwidth +'screenX=0,screenY=0,top=0,left=0,status=no,scrollbars=yes,toolbar=yes,menubar=yes,resizable=yes,location=yes');
					}
			}
		} else if(product=="renters"){
			state=stateField.options[stateField.selectedIndex].value;
			code = QueryString('code');
				if(code == null){
					code = "001" ;
				}

			window.open('/HICServlet?cmd_InsuranceQuote=&lstProperty=renters&code='+code +panswerfinancial+ '&lstState=' + state+ '&accept-language=en-US','sub',"" +'height=450,width=650, screenX=0,screenY=0,top=0,left=0,status=no,scrollbars=yes,toolbar=yes,menubar=yes,resizable=yes,location=yes');
		} else if(product=="auto"){
			
			if(a==null&&cid==null&&target==null){
				window.open('/HICServlet?cmd_InsuranceQuote=&lstProperty=auto&accept-language=en-US','sub',"height=" + screen.availheight + ",width=" + screen.availwidth +'screenX=0,screenY=0,top=0,left=0,status=no,scrollbars=yes,toolbar=yes,menubar=yes,resizable=yes,location=yes');
			}else{
				window.open('/HICServlet?cmd_InsuranceQuote=&lstProperty=auto'+panswerfinancial+'&accept-language=en-US','sub',"height=" + screen.availheight + ",width=" + screen.availwidth +'screenX=0,screenY=0,top=0,left=0,status=no,scrollbars=yes,toolbar=yes,menubar=yes,resizable=yes,location=yes');
			}
		}	else if(product=="homeownerswithoutstate"){
			
				product="homeowners";
				if(a==null&&cid==null&&target==null){
					window.open('/HICServlet?cmd_InsuranceQuote=&lstProperty=' + product + '&accept-language=en-US','sub',"height=" + screen.availheight + ",width=" + screen.availwidth +'screenX=0,screenY=0,top=0,left=0,status=no,scrollbars=yes,toolbar=yes,menubar=yes,resizable=yes,location=yes');
				}else{

					window.open('/HICServlet?cmd_InsuranceQuote=&lstProperty=homeowners'+panswerfinancial+'&accept-language=en-US','sub',"height=" + screen.availheight + ",width=" + screen.availwidth +'screenX=0,screenY=0,top=0,left=0,status=no,scrollbars=yes,toolbar=yes,menubar=yes,resizable=yes,location=yes');
				}
			}
		
	}

	var isNS=(navigator.appName=="Netscape");

	var documentRef=(isNS)?"document":"document.all";
	var styleRef=(isNS)?"":".style";
	var showRef=(isNS)?"show":"visible";
	var hideRef=(isNS)?"hide":"hidden";

	function showDivAt(divId,popX,popY){
		eval(documentRef + '.' + divId + styleRef + '.visibility = "' + showRef + '"');
		eval(documentRef + '.' + divId + styleRef + '.top = ' + popX);
		eval(documentRef + '.' + divId + styleRef + '.left = ' + popY);
	}

	function hideDiv(divId){
		eval(documentRef + '.' + divId + styleRef + '.visibility = "' + hideRef + '"');
	}


	function HideIt(){
		if(isNS){
			hideDiv("divLinkDisclaimer1");
			hideDiv("divLinkDisclaimer2");
		}
	}

	function ShowIt2(posX,posY){
		if(isNS){
		var popX
		var popY
		popX=(posX + 20)
		popY=(posY + 10)
		showDivAt("divLinkDisclaimer2",popY,popX);
		}
	}


	function swapClass(){
	 var i,x,tB,j=0,tA=new Array(),arg=swapClass.arguments;
	 if(document.getElementsByTagName){for(i=4;i<arg.length;i++){tB=document.getElementsByTagName(arg[i]);
	  for(x=0;x<tB.length;x++){tA[j]=tB[x];j++;}}for(i=0;i<tA.length;i++){
	  if(tA[i].className){if(tA[i].id==arg[1]){if(arg[0]==1){
	  tA[i].className=(tA[i].className==arg[3])?arg[2]:arg[3];}else{tA[i].className=arg[2];}
	  }else if(arg[0]==1 && arg[1]=='none'){if(tA[i].className==arg[2] || tA[i].className==arg[3]){
	  tA[i].className=(tA[i].className==arg[3])?arg[2]:arg[3];}
	  }else if(tA[i].className==arg[2]){tA[i].className=arg[3];}}}}
	}
	
	function writeStyles(op,a){
	if(op==0||document.getElementById){var tS="<sty"+"le type=\"text/css\">";
	tS+=a+"<"+"/sty"+"le>";document.write(tS);document.close();}
	}
	
	writeStyles(1,'.closed p{ display:none;}.open p{ display:block;}');

	function findParam(param){
 		var splitString = "url";
 		var paramCode = "temp";
 		var promoCode = "none";
 		var temp = "none2";
 
 		splitString = window.location.search.split("?"); 
 		splitString[1] = unescape(splitString[1]); 
 		paramCode = splitString[1].split("&");  

 		for(var i=0; i < paramCode.length; i++){
 			temp = paramCode[i].split("=");
 
 			if(temp[0] == param){ 
  
  			promoCode = temp[1];  
   			break;
 			}

 		}
        	return promoCode;
	}