// This script will render the Allstate footer.
//
// Note that there are two terms used through the documentation and script:
//		1. Calling Site -	The site from which this script is called and is need of a footer.
//		2. Source Site  -	The site from which the images, includes, etc. are retrieved from.
//
// The only public method of this script is BuildFooterHtml.
//
// All of the global JavaScript variables that are used are set in the MainHeader.js or Footer.inc.:
//
// To use this file, your footer.inc file would contain the following:
//	<!-- ***************************************************************** -->
// 	<SCRIPT TYPE="text/JavaScript" SRC="https://www.allstate.com/includes/NewFooter.js"></SCRIPT>                       
// 	<SCRIPT LANGUAGE="JavaScript">                                            
//		BuildFooterHtml();                                        
//  </SCRIPT>                                                                 
//  <!-- ***************************************************************** -->



//This function uses a buildLinkURL() function from ****filename**** 
//NOTE: creates the line of links at the bottom of the footer
//var sFooterLinks -- passed in from BuildFooterHtml() below    
function getFooterLinks(sFooterLinks)
    {
       for (j=0;sFooterLinks[j].getAttribute("lastItem")!="yes";j++)
        {
            string = '<a href="'; //Moved href closer to the anchor tag per SEO requirement
            string += buildLinkURL(sFooterLinks[j].getElementsByTagName("FooterLinkUrl")[0].firstChild.nodeValue);
            string += '" id="'; 
            string += sFooterLinks[j].getElementsByTagName("FooterLinkId")[0].firstChild.nodeValue;
            string +='">';
			string += sFooterLinks[j].getElementsByTagName("FooterLinkText")[0].firstChild.nodeValue;
			string += '</a>';
			 
			 if (sFooterLinks[j].getAttribute("noSeparationsLine")=="yes")		//test for the attribute lastItem to not display seperation line
			 {
				string += '&nbsp;&nbsp;';				
			 }
			 else
			 {
				string += '&nbsp;&nbsp;<label style="COLOR:#003270">|&nbsp;&nbsp;</label>';	
			 }
            document.write(string);
        }
    }


// This is the only public method and is responsbile for building the HTML necessary to build the footer.
// This function builds links from the following xml files:
//
// 
function BuildFooterHtml(PushToTalkBoolean)
{	
	// The following variables should have been defined in MainHeader.js, but there are cases where pages 
	// (usually popup pages) don't have the standard main header, but do have the footer.

	if (window.gsSourceWebSite)
		var sSourceWebSite = gsSourceWebSite;
	else
		var sSourceWebSite = document.location.protocol + "//www.allstate.com";
			
	if (window.gsApplAllstate)
		var sApplAllstate = gsApplAllstate;
	else
		var sApplAllstate = "www.allstate.com";

// USD 9559549 
// Defining additional variables for pages that don't call MainHeader.js (ie inTouch newsletter)

	if (window.gsApplBank)
		var sApplBank = gsApplBank;
	else
		var sApplBank = "www.allstatebank.com";
		
	if (window.gsApplAgent)
		var sApplAgent = gsApplAgent;
	else
		var sApplAgent = "agent.allstate.com";
	
	if (window.gsApplCustCare)
		var sApplCustCare = gsApplCustCare;
	else
		var sApplCustCare = "customercare.allstate.com";
// End of USD 9559549 



// 06/21/2006 - gamaa -- Variables for new header 
// NOTE: xmlDoc is declared in **filename**
var sRoot = xmlDoc.documentElement;
var sFooterLinks = sRoot.getElementsByTagName('FooterLinks');
// 06/21/2006 - gamaa -- End variables for new header 
var lastNode = sFooterLinks.length-1;

var theDate = new Date( );
var theYear = theDate.getFullYear( );

	// Generate the HTML.
	alert("New Footer - AWS Cookie Flag " + GetCookieAWS("AWSFlag"));
							
	if (GetCookieAWS("AWSFlag") == "Y")
	{	

								//Start AWS Domain Specific logic
								var currURL = document.location.href.toLowerCase();
								var currDomain = GetDomain(currURL);
								
								//The following html is not needed for the calculators.
								if ( currDomain.indexOf("leadfusion.com") >= 0 )
								{
								}
								else
								{
									document.write('</td>');	
									document.write('<td width="39" height="1"><img src="' + sSourceWebSite + '/Images/ClearSpacer.gif" width="39" height="1"></td>');
									document.write('</td>');
									document.write('</tr>');
								}		
								
								//The following html is not needed for the calculators and messaging.
								if ( currDomain.indexOf("messaging") >= 0 || currDomain.indexOf("leadfusion.com") >= 0 )
								{
								}
								else
								{
									document.write('<tr>');
										document.write('<td colspan="3">&nbsp;</td>');
									document.write('</tr>');
								}

								//The following html is not needed for the calculators.
								if ( currDomain.indexOf("leadfusion.com") >= 0 )
								{
								}
								else
								{
																	document.write('</table>');
																document.write('</td>');
															document.write('</tr>');
														document.write('</table>');
													document.write('</td>');
												document.write('</tr>');
											document.write('</table>');	
										document.write('</td>');
									document.write('</tr>');
								document.write('</table>');
								}
								//End AWS Domain Specific logic
								
									document.write('<!-- Display Agent Web Site Disclaimers -->')
										document.write('<table width="778" cellspacing="14px" cellpadding="0" border="0" bgColor=#FFFFCC colspan="5">');
										
										if ( GetCookieAWS("AgentType") == "13" )
										{
											document.write('<tr>')
													document.write('<td colspan="3">');
														document.write('<p>');
														document.write('<font class="AWSDisclaimer">Allstate, through its insurance companies, subsidiaries and brokers/dealers, offers property and casualty insurance, life insurance and registered securities. Certain products, such as variable annuities, variable universal life insurance, and mutual funds are available only through securities licensed representatives and sales material must be accompanied by a prospectus.');
														document.write( getAWSFooterVariableText (GetCookieAWS("OfficeStateCd"), GetCookieAWS("AgentType") ) );
														document.write('  Securities offered by Personal Financial Representatives through Allstate Financial Services, LLC (LSA Securities in LA and PA).  Registered Broker-Dealer, Member NASD, SIPC.  Main Office: 2920 South 84th Street, Lincoln, NE 68506.  877-525-5727.</FONT>');
														document.write('</p>');
													document.write('</td>');
												document.write('</tr>')
										}
										else
										{
											document.write('<!-- Florida -->')
											if (GetCookieAWS("LicenseState").indexOf("FL")!= -1)
											{	
												document.write('<tr>')
													document.write('<td colspan="3">');
														document.write('<p>');
														document.write('<font class="AWSDisclaimer">*Note: In Florida, Allstate agencies are authorized to represent a number of companies that are part of the Allstate family.  Through these separate and distinct companies a wide variety of insurance products are available.  For example, auto insurance in Florida is available from Allstate Insurance Company, Allstate Indemnity Company and Allstate Property and Casualty Insurance Company.  Property insurance, such as homeowners, condominium owners and renters insurance is available in Florida from Allstate Floridian Insurance Company and Allstate Floridian Indemnity Company.  In addition, an array of life insurance products is available from Allstate Life Insurance Company.</FONT>');
														document.write('</p>');
														document.write('<p>');
														document.write('<font class="AWSDisclaimer">It’s important to note that Allstate Floridian Insurance Company and Allstate Floridian Indemnity Company are separate and distinct companies from each other and from Allstate Insurance Company, Allstate Indemnity Company, Allstate Property and Casualty Insurance Company and Allstate Life Insurance Company.  This means, for example, that property insurance products provided by Allstate Floridian Insurance Company and Allstate Floridian Indemnity Company are not underwritten or reinsured by Allstate Insurance Company or Allstate Life Insurance Company.</FONT>');
													document.write('</p>');
													document.write('</td>');
												document.write('</tr>')
											}
											
											document.write('<!-- Display State Licensing Disclaimer -->')
											document.write('<tr>')
													document.write('<td colspan="3">');
														document.write('<font class="AWSDisclaimer">' + (GetCookieAWS("AgentName")) + ' is licensed to sell Allstate insurance products only in the state(s) of ' + (GetCookieAWS("LicStateListLong")) + '.  The material contained in this Web site is applicable only in the state of ' + (GetCookieAWS("OfficeState")) + '.  If you do not reside in the state(s) of ' + (GetCookieAWS("LicStateListLong")) + ', or you\'re not insuring property located in the state(s) of ' + (GetCookieAWS("LicStateListLong")) + ' please go to the <A href="javascript:goToUrlwoPopUp(&quot;http://' + sApplAgent + '&quot)">Find An Agent</a> section on allstate.com to search for another agent.</FONT>');
													document.write('</td>');
												document.write('</tr>')
											
											if (GetCookieAWS("LicenseState").indexOf("CA")!= -1 || GetCookieAWS("LicenseState").indexOf("MN")!= -1 )
												{
													document.write('<!-- Display License Names and Numbers Disclaimer -->')
													document.write('<tr>')
														document.write('<td colspan="3">');
														if (GetCookieAWS("LicenseState").indexOf("CA")!= -1)
														{
															document.write('<!-- California -->')
															document.write('<font class="AWSLicenseFooter">California Insurance License Name and Number: ' + DetermineStateLicNum("CA") + ' ' + DetermineStateLicName("CA") + '</FONT>');
															document.write('<br>')
														}
														if (GetCookieAWS("LicenseState").indexOf("MN")!= -1)
														{	document.write('<!-- Minnesota -->')	
															document.write('<font class="AWSDisclaimer">Minnesota License Name and Number: ' + DetermineStateLicNum("MN") + ' ' + DetermineStateLicName("MN") + '</FONT>');
															document.write('<br>')
														}
															document.write('</td>');
														document.write('</tr>')
												}
											
											
											document.write('<!-- Display Alstate Disclaimer -->')
												document.write('<tr>')
													document.write('<td colspan="3">');
														document.write('<font class="AWSDisclaimer">This material is intended for educational purposes only. Allstate, through its insurance companies, subsidiaries, and brokers/dealers, offers property and casualty insurance, life insurance and registered securities.  Certain products, such as variable annuities, variable universal life insurance, and mutual funds are available only through securities licensed representatives and sales material must be accompanied by a prospectus.  ');
														document.write( getAWSFooterVariableText (GetCookieAWS("OfficeStateCd"), GetCookieAWS("AgentType") ) );
														document.write('  Securities offered by Personal Financial Representatives through Allstate Financial Services, LLC (LSA Securities in LA and PA).  Registered Broker-Dealer, Member NASD, SIPC.  Main Office: 2920 South 84th Street, Lincoln, NE 68506.  877-525-5727.</FONT>');
														
													document.write('</td>');
												document.write('</tr>')
										}
											document.write('</table>')
										document.write('<table width="778" cellspacing="0" cellpadding="0" border="0">');
											document.write('<tr>');
												document.write('<td colspan="4">&nbsp;</td>');
											document.write('</tr>');
											document.write('<tr>');
												document.write('<td width="10" height="1"><img src="' + sSourceWebSite + '/Images/ClearSpacer.gif" width="10" height="1"></td>');
												document.write('<td width="116" valign="top">');
													document.write('<a href="' + document.location.protocol + '//' + sApplAllstate + '/about/priv.asp"><img src="' + sSourceWebSite + '/images/FinalMark.gif" width="116" height="31" border="0"></a>');
												document.write('</td>');
												document.write('<td width="10" height="1"><img src="' + sSourceWebSite + '/Images/ClearSpacer.gif" width="10" height="1"></td>');
												document.write('<td width="420" valign="top">');
													document.write('<table width="630" cellspacing="0" cellpadding="0" border="0">');
														document.write('<tr>');
															document.write('<td class="AWSFooter">');
																// 9/8/04 - USD10279475 - Superscript (SM) should be (R)
																document.write('Insure today.  Secure tomorrow.<SUP><FONT SIZE=-2>&reg</FONT></SUP><br>');
																document.write('Copyright ' + gsCurDateYYYY + ' Allstate Insurance Company. All rights reserved.<br>');
																document.write('<a href="' + document.location.protocol + '//' + sApplAllstate + '/contactus/nameloc.asp">Company name and location information.</a>');
																document.write('&nbsp&nbsp&nbsp');
																document.write('<a href="' + document.location.protocol + '//' + sApplAllstate + '/about/priv.asp">Privacy Statement</a>');
																document.write('&nbsp&nbsp&nbsp');
																document.write('<a href="' + document.location.protocol + '//' + sApplAllstate + '/About/PageRender.asp?Page=terms.htm">Terms of Use</a>');
															document.write('</td>');
														document.write('</tr>');												
													document.write('</table>');
}
// 6/2/04 - SEO (Search Engine Optimization - [679])
//        - the Allstate.com Homepage Footer has been relocated to \Allstate\includes\FooterHPStatic.inc
else
{
							document.write('</td>');	
							document.write('<td width="39" height="1"><img src="' + sSourceWebSite + '/Images/ClearSpacer.gif" width="39" height="1"></td>');
							document.write('</tr>');
							document.write('<td width="39" height="1"><img src="' + sSourceWebSite + '/Images/ClearSpacer.gif" width="39" border="0" height="1"></td>');							


		

							document.write('</td>');
							document.write('</tr>');							
						document.write('</table>');
						
					document.write('</td>');
				document.write('</tr>');
			document.write('</table>');	
//	5/24/06 - gamaa -- new footer html starts here 
//  update footer to look like homepage
							document.write('<tr>');
							document.write('<td width="156" height="10" align="middle" BGCOLOR="'+ gsBarColor + '" valign="top">');
							document.write('</td>');
							document.write('<td>');
							document.write('</td>');
							document.write('</tr>');																					
							document.write('<tr>');
							document.write('<td colspan="2" valign="top">');
							document.write('<div class=footer800>');
							document.write('	<table cellSpacing="0" cellPadding="0" width="780" border="0">');
							document.write('	<tr>');
							document.write('		<td>');
							document.write('			<img id="ImageSpacer" src="' + gsSourceWebSite + '/Images/spacer.gif" border="0" style="height:30px;width:55px;" />');
							document.write('		</td>');
							document.write('		<td class="footerLinks" vAlign="middle" width="775">');			
								
							//Get all footer links 
							getFooterLinks(sFooterLinks);													
							//start copyright label							
							document.write('			<span id="Label1" class="footerLinks">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Copyright '); 
							//run javascript here to get year							 
							document.write(theYear);
							document.write('&nbsp;');
							//create Allstate Insurance Company from link
							var	string = '<a href="'; //Moved href closer to the anchor tag per SEO requirement
								string += buildLinkURL(sFooterLinks[lastNode].getElementsByTagName("FooterLinkUrl")[0].firstChild.nodeValue);
								string += '" id="'; 
								string += sFooterLinks[lastNode].getElementsByTagName("FooterLinkId")[0].firstChild.nodeValue;
								string +='">';
								string += sFooterLinks[lastNode].getElementsByTagName("FooterLinkText")[0].firstChild.nodeValue;
								string += '</a>.';
								 
								document.write(string);							
					
														
							document.write('');					
							//finish off the copyright label 
							document.write('&nbsp;&nbsp;All rights reserved.  </span>');
							document.write('		</td>');
							document.write('	</tr>');
							document.write('	</table>');
							document.write('</div>');
							

//	5/24/06 - gamaa new footer ends here				
		document.write('</td>');
	document.write('</tr>');
document.write('</table>');
}

if(PushToTalkBoolean == true)
{
document.write("<script type='text/javascript' src='//as00.estara.com/fs/lr.php?accountid=200106282579'></script>");
}

document.write('</body>');
document.write('</html>');		
}
function GetCookieAWS (psTargetCookieName, psOptionalCookiesToSrch) 
{
	// The parameters are case insensitive.
	
	var sResult = "";
	
	if ((psTargetCookieName == "AWSFlag"))
	{
		if (!psOptionalCookiesToSrch) {
			// The optional parameter was omitted.
			var sAllCookies = "; " + document.cookie + ";";
			var sCookieDelim = "; ";
		}
		else
		{
			var sAllCookies = "&" + psOptionalCookiesToSrch + "&";
			var sCookieDelim = "&";
		}
		
		var sAllCookiesLower = sAllCookies.toLowerCase();
		
		var psTargetCookieName = sCookieDelim + psTargetCookieName.toLowerCase() + "=";
		var iTargetCookieStart = sAllCookiesLower.indexOf(psTargetCookieName);
		var iTargetCookieEnd;

		if (iTargetCookieStart != -1) {
			iTargetCookieStart += psTargetCookieName.length;
			iTargetCookieEnd = sAllCookiesLower.indexOf(sCookieDelim, iTargetCookieStart);
			sResult = unescape(sAllCookies.substring(iTargetCookieStart, iTargetCookieEnd));
		}
	}
	else
	{
		sResult = getCookieF("AWSNav",psTargetCookieName)
		if (sResult==null)
			sResult="";
	}
	
	return sResult;
}

function GetDomain(URL){
	var sDomain;
	var iDomainStart;
	var iDomainEnd;

	if (URL != "" || URL != null)	
	{
		iDomainStart = URL.indexOf("//");
		iDomainEnd = URL.indexOf("/", iDomainStart + 2);
			
		sDomain = unescape(URL.substring(iDomainStart + 2, iDomainEnd));
	}
	
	return sDomain;	
}

function parseCookieF(name) {
  var str = ""
  var a = document.cookie.split(";")
  for (var i=0; i<a.length; i++) {
    a[i] = a[i].replace(/(^\s*)|(\s*$)/g, "");
    if (a[i].substring(0,name.length) == name)
      str = a[i].substring(name.length+1)
  }
  var a = str.split("&")
  var obj = new Object()
  if (str.length)
    for (i=0; i<a.length; i++) {
      temp = a[i].split("=")
      obj[temp[0]] = temp[1]
    } return obj
}

function addToCookieF(cookieName,key,value) {
  var cookies = parseCookieF(cookieName)
  cookies[key] = value
  var d = new Date()
  d.setFullYear(d.getFullYear()+1)
  var cookieStr = cookieName + "="
  for (var item in cookies)
    cookieStr += item + "=" + cookies[item] + "&"
  cookieStr = cookieStr.substring(0,cookieStr.length-1)
  //cookieStr = cookieStr + "; expires=" + d.toUTCString()
  cookieStr = cookieStr + "; path=/"
   if ( cookieName.indexOf("AWSNav") > -1 || cookieName.indexOf("AWSFlag") > -1)
  {
  	 cookieStr += "; domain=allstate.com"
  }
  document.cookie = cookieStr
}

function getCookieF(name,key) {
  var cookies = parseCookieF(name)
  return cookies[key]
}

function getAWSFooterVariableText (stateCode, agentType)
{
	var retVal = "";
	
	switch ( stateCode.toUpperCase() )
	{
		case 'NY':
			if ( agentType == '13' )
				retVal = "Life insurance and fixed annuity products are available from Allstate Life Insurance Company of New York, Hauppauge, NY.";
			else
				retVal = "Auto and homeowners insurance, and other property and casualty insurance products, are available from Allstate Insurance Company, Allstate Indemnity Company, Allstate Property & Casualty Insurance Company: Home Offices, Northbrook, IL. Life insurance and fixed annuity products are available from Allstate Life Insurance Company of New York, Hauppauge, NY.";
			break;
		case 'NJ':
			if ( agentType == '13' )
				retVal = "Life insurance and fixed annuity products are available from Allstate Life Insurance Company: Home Office, Northbrook, IL.";
			else
				retVal = "Auto and homeowners insurance, and other property and casualty insurance products, are available from Allstate New Jersey Insurance Company: Home Office, Bridgewater, NJ. Life insurance and fixed annuity products are available from Allstate Life Insurance Company: Home Office, Northbrook, IL.";
			break;
		case 'TX':
			if ( agentType == '13' )
				retVal = "Life insurance and fixed annuity products are available from Allstate Life Insurance Company: Home Office, Northbrook, IL.";
			else
				retVal = "Auto and homeowners insurance, and other property and casualty insurance products, are available from Allstate County Mutual Insurance Company and Allstate Texas Lloyd’s: Home Offices, Irving, TX. Life insurance and fixed annuity products are available from Allstate Life Insurance Company: Home Office, Northbrook, IL.";
			break;
		case 'FL':
			if ( agentType == '13' )
				retVal = "Life insurance and fixed annuity products are available from Allstate Life Insurance Company: Home Office, Northbrook, IL.";
			else
				retVal = "Life insurance and fixed annuity products are available from Allstate Life Insurance Company: Home Office, Northbrook, IL.";
			break;
		default:
			if ( agentType == '13' )
				retVal = "Life insurance and fixed annuity products are available from Allstate Life Insurance Company: Home Office, Northbrook, IL.";
			else
				retVal = "Auto and homeowners insurance, and other property and casualty insurance products, are available from Allstate Insurance Company, Allstate Indemnity Company, Allstate Property & Casualty Insurance Company: Home Offices, Northbrook, IL. Life insurance and fixed annuity products are available from Allstate Life Insurance Company: Home Office, Northbrook, IL.";
			break;
	}
	
	return retVal;
}
