//
// Empire.js 
// Copyright (c) 2007, BetterLead Systems, LLC 
// All rights reserved.

var sealEnabled = false; 
//
// Global Html Functions 
//
function RenderCopyInfo()
{
	document.write('<td align="right">Copyright &copy; 2007 Better Lead Systems, LLC.  All Rights Reserved.</td>');
}

function RenderHeaderMenu()
{
	var sPath = window.location.pathname;
	var sPage = ''; 
	
	if (sPath.indexOf("C:") != -1 )
	 sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
	else 
	 sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
    
	switch(sPage)
	{
		case "index.html":
document.write('<div id="menu"><ul><li class="active"><a href="index.html" id="menu1" accesskey="1" title=""><strong><span>Home</span></strong></a></li><li><a href="leads.html" id="menu2" accesskey="2" title=""><strong><span>leads</span></strong></a></li><li><a href="company.html" id="menu3" accesskey="3" title=""><strong><span>company</span></strong></a></li><li><a href="contact.html" id="menu4" accesskey="4" title=""><strong><span>Contact</span></strong></a></li></ul></div>'); break;

		case "":
document.write('<div id="menu"><ul><li class="active"><a href="index.html" id="menu1" accesskey="1" title=""><strong><span>Home</span></strong></a></li><li><a href="leads.html" id="menu2" accesskey="2" title=""><strong><span>leads</span></strong></a></li><li><a href="company.html" id="menu3" accesskey="3" title=""><strong><span>company</span></strong></a></li><li><a href="contact.html" id="menu4" accesskey="4" title=""><strong><span>Contact</span></strong></a></li></ul></div>'); break;

		case "leads.html":
document.write('<div id="menu"><ul><li><a href="index.html" id="menu1" accesskey="1" title=""><strong><span>Home</span></strong></a></li><li class="active"><a href="leads.html" id="menu2" accesskey="2" title=""><strong><span>leads</span></strong></a></li><li><a href="company.html" id="menu3" accesskey="3" title=""><strong><span>company</span></strong></a></li><li><a href="contact.html" id="menu4" accesskey="4" title=""><strong><span>Contact</span></strong></a></li></ul></div>'); break;

		case "company.html":
document.write('<div id="menu"><ul><li><a href="index.html" id="menu1" accesskey="1" title=""><strong><span>Home</span></strong></a></li><li><a href="leads.html" id="menu2" accesskey="2" title=""><strong><span>leads</span></strong></a></li><li class="active"><a href="company.html" id="menu3" accesskey="3" title=""><strong><span>company</span></strong></a></li><li><a href="contact.html" id="menu4" accesskey="4" title=""><strong><span>Contact</span></strong></a></li></ul></div>'); break;

		case "contact.html":
document.write('<div id="menu"><ul><li><a href="index.html" id="menu1" accesskey="1" title=""><strong><span>Home</span></strong></a></li><li><a href="leads.html" id="menu2" accesskey="2" title=""><strong><span>leads</span></strong></a></li><li><a href="company.html" id="menu3" accesskey="3" title=""><strong><span>company</span></strong></a></li><li class="active"><a href="contact.html" id="menu4" accesskey="4" title=""><strong><span>Contact</span></strong></a></li></ul></div>'); break;

		default:
document.write('<div id="menu"><ul><li><a href="index.html" id="menu1" accesskey="1" title=""><strong><span>Home</span></strong></a></li><li><a href="leads.html" id="menu2" accesskey="2" title=""><strong><span>leads</span></strong></a></li><li><a href="company.html" id="menu3" accesskey="3" title=""><strong><span>company</span></strong></a></li><li><a href="contact.html" id="menu4" accesskey="4" title=""><strong><span>Contact</span></strong></a></li></ul></div>'); break;

		case "privacy.html":
document.write('<div id="menu"><ul><li><a href="index.html" id="menu1" accesskey="1" title=""><strong><span>Home</span></strong></a></li><li class="active"><a href="privacy.html" id="menu2" accesskey="2" title=""><strong><span>privacy</span></strong></a></li><li><a href="terms.html" id="menu3" accesskey="3" title=""><strong><span>terms</span></strong></a></li></ul></div>'); break;

		case "terms.html":
document.write('<div id="menu"><ul><li><a href="index.html" id="menu1" accesskey="1" title=""><strong><span>Home</span></strong></a></li><li><a href="privacy.html" id="menu2" accesskey="2" title=""><strong><span>privacy</span></strong></a></li><li class="active"><a href="terms.html" id="menu3" accesskey="3" title=""><strong><span>terms</span></strong></a></li></ul></div>'); break;

	}
	
}

function RenderTermsAndPrivacy()
{
	document.write('<td><p class="style3"><a href="javascript:OpenWindow(\'terms.aspx\');">Terms of service</a> | <a href="javascript:OpenWindow(\'privacy.aspx\');">Privacy policy</a></p></td>');
}


//
// Form functions
//

function validateForm(f)
{
	var formdata = f; 
	var errorMsg = ""; 
	
	if( f.yourname.value.length == 0  )
		errorMsg += "Please enter your Name\n";
	
	if( f.yourphone.value.length == 0 )
		errorMsg += "Please enter your Phone\n";
		
	if( f.youremail.value.length == 0 )
		errorMsg += "Please enter your Email\n";
	
	if( f.comments.value.length == 0 )
		errorMsg += "Please enter your Comments\n";
		
	
	if( errorMsg != "" )
	{
		alert("Error detected!\n\n" + errorMsg);
		f.yourname.focus();
		return false;
	}
	else
		return true;
	
}

function DisablePEConditions(frmState)
{
    try
    {
        /*
        if( frmState == true )
            document.getElementById('preexistingconditions').style.display = 'inline;';
        else
            document.getElementById('preexistingconditions').style.display = 'none;';
          
            document.getElementById('17').disabled=true;
        */
    }
    catch(e)
    {
        alert(e.description);
    }
}

function validateForm(obForm)
{
   var val=false;
   var charcount=0;
   var fieldcount=0;
   var stateIndex;
   var errorMsg = ""; 
   var lastErrorIdx = 0; 
   var ix=0;
   var fieldIndexList = new Array(); 
   var errorFieldColor = "#ffff99";
   var normalFieldColor = "#ffffff";
   try
   {
       fieldcount=14; 
       if(obForm)
       {
            alert(fieldcount);
            for(var j=0; j< obForm.length; j++)
            {
                switch(obForm[j].type)
                {
                    case 'text': document.getElementById(obForm[j].name).style.backgroundColor = normalFieldColor; 
                    if( obForm[j].value.length > 0 ) 
                        charcount++; 
                    else 
                        errorMsg += 'Please fill in the ' + obForm[j].name + ' field. \n'; lastErrorIdx = j; fieldIndexList[j] = j; 
                    break;
                    /*case 'select-one':  document.getElementById(obForm[j].name).style.backgroundColor = normalFieldColor; stateIndex=obForm[j].selectedIndex;  if ((stateIndex == -1 || stateIndex == 0 )) {errorMsg += "Please select a state.\n"; document.getElementById(obForm[j].name).style.backgroundColor = errorFieldColor; }
                                            break; */
                }
            }
       }
         
      if( charcount != fieldcount )
      {
        alert( 'Please check your input! \n\n' + errorMsg );
        obForm[lastErrorIdx].focus(); 
        for ( ix in fieldIndexList )                 
            document.getElementById(obForm[ix].name).style.backgroundColor = errorFieldColor;
       }
       else
        val=true; 
   }
   catch(e)
   {
        alert(e.description);
        val=false;
   } 
   
    return val;
}

function OpenSpamWindow()
{
    try    
    {
    var w=window.open('SpamPolicy.aspx?', 'spamWindow', 'height=600, width=600, toolbar=no, scrollbars=yes, resizeable=yes, status=yes');
    w.focus();
    }
    catch(e)
    {
        alert('Error, we could not pop open a new window. Please disable any pop-up blockers and try again.');
    }
}

function OpenWindow( pageName )
{
    try
    {
        var w=window.open(pageName, 'newWindow', 'height=600, width=600, toolbar=no, scrollbars=yes, resizeable=yes, status=yes');
        w.focus();
    }
    catch(e)
    {
    alert('Error, we could not pop open a new window. Please disable any pop-up blockers and try again.');
    }
}

function renderSeal(siteName)
{
    if ( sealEnabled ) {
        switch( siteName )
        {
            case 'life': document.write('<noscript><a href="https://seal.verisign.com/splash?form_file=fdf/splash.fdf&dn=WWW.BETTERLIFEQUOTES.COM&lang=en"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="100" height="72"><param name="movie" value="Images/getseal.swf"><param name="quality" value="high"><param name="wmode" value="transparent"><embed src="Images/getseal.swf" width="100" height="72" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" wmode="transparent"></embed></object></a></noscript>'); 
            break;
            case 'health': document.write('<noscript><a href="https://seal.verisign.com/splash?form_file=fdf/splash.fdf&dn=WWW.BETTERHEALTHQUOTES.COM&lang=en"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="100" height="72"><param name="movie" value="Images/getseal.swf"><param name="quality" value="high"><param name="wmode" value="transparent"><embed src="Images/getseal.swf" width="100" height="72" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" wmode="transparent"></embed></object></a></noscript>'); 
            break;
            
        }
    }
     
}

function cleanPhoneNumber( dirtyString )
{
	var okChars = "0123456789";
	var cleanString = "";
	for(var i = 0; i < dirtyString.length; i++){
		if(okChars.indexOf(dirtyString.charAt(i)) != -1)
			cleanString += dirtyString.charAt(i);
	}
	return cleanString;
}

function formatPhone( phone )
{ 
    if( phone ) {
    var cleanPhone = cleanPhoneNumber( phone.value );
	if (cleanPhone.length >= 10)	{
		var formattedPhone = cleanPhone.substr(0,3) + "-" + cleanPhone.substr(3,3) + "-" + cleanPhone.substr(6,4);
		phone.value = formattedPhone;
	}
	else
		phone.value = cleanPhone; 
    }    
}

