var popUpOn = false;
var e;
var f;

window.onscroll = function()
{
    checkWindowSize();
}

if(top.location != location){
    top.location.href = document.location.href;
}   

function checkWindowSize()
{
    if(popUpOn == true)
        repositionPopup();
}

// Logo Beta Popup
function feedbackBeta()
{
    var stb_recipient = "Feedback@InsuranceRates.com"; 
    var stb_url = "mailto:" + stb_recipient + "?subject=InsuranceRates Feedback";
    location.href=stb_url; 
}

function openPopup()
{
    var container = document.createElement("div");
    popUpOn = true;
    
    //document.getElementById('imageHome').style.visibility = "hidden";
    container.id = "popupCont";
    document.body.appendChild(container);
    
    if(currentPage == "homePage" && hasReqestedVersion)
    {
        document.getElementById('popupCont').innerHTML = "<div id='popUpContainer_beta' onclick='removePopup()'></div>" +
         "<div id='popUp_beta'>" +
            "" +     
		    "</div>";
    }
    else
    {
        document.getElementById('popupCont').innerHTML = "<div id='popUpContainer_beta' onclick='removePopup()'></div>" +
         "<div id='popUp_beta'>" +
            
        "<div id='popUpContainer_betaInner'>" +
         
        
        	 "<div id='logo'>" +
				"<img src='../images/logo_insuranceRates.gif' width='249' height='77' alt='' /></div>" +  
				
			"<table border='0' cellpadding='0' class='infoDetail'>" +
				"<tr>" +
					"<td>" +
						"<div class='closeBtn'>" + 
							"<a href='#' onClick='removePopup()'>" +
							"<img src='../images/spacer.gif' width='31' height='31' alt='Close' /></a>" +
						"</div>" +
					"</td>" +
				"</tr>" +
				"<tr>" +
					"<td>" +
						"<h3 style='margin-top:-25px;'></h3>" +
					"</td>" +
				"</tr>" +
			"</table>" +
			"<table cellpadding='0' cellspacing='0' class='infoDetailMid'>" +
				"<tr>" +
					"<td>We are referring to this as a \"<strong class='textGreen'>Beta</strong>\" site in order to gather feedback from consumers like you and evaluate how the site is performing in \"real world\" environments. We are also working hard to continuously add new providers to our offering, so check back often to see the updated listing. With your feedback, we can create the best possible site to comparison shop for auto insurance." + 

                    "<p>Send your comments to: <a href='mailto: Feedback@InsuranceRates.com?subject=InsuranceRates Feedback'>Feedback@InsuranceRates.com</a>" +
					"</td>" +
				"</tr>" +
			"</table>" +
			"<table cellpadding='0' cellspacing='0' class='infoBottom'>" +
				"<tr>" +
					"<td>&nbsp;</td>" +
				"</tr>" +
			"</table>" +
        
        
        "</div>";
    }
	
	e = document.getElementById('popUpContainer_beta');
	f = document.getElementById('popUp_beta');
	
	repositionPopup();
	
}

function openPopupQuestion() {

    if ($('#questionPopupCont').html() == null || $('#questionPopupCont').html() == '') {
        var containerContent = "" +
        "<div id='popUpContainer_betaInner1'>" +
        	 "<div id='logo'>" +
				"<img src='../images/logo_insuranceRates.gif' width='249' height='77' alt='' /></div>" +

			"<table border='0' cellpadding='0' class='infoDetail'>" +
				"<tr>" +
					"<td>" +
						"<img src='/images/spacer.gif' width='1' height='10' />" +
					"</td>" +
				"</tr>" +
			"</table>" +
			"<table cellpadding='0' cellspacing='0' class='infoDetailMid'>" +
				"<tr>" +
					"<td>By entering your street address, more providers will be able to display a preliminary rate.</td>" +
				"</tr>" +
			"</table>" +
			"<table cellpadding='0' cellspacing='0' class='infoBottom'>" +
				"<tr>" +
					"<td>&nbsp;</td>" +
				"</tr>" +
			"</table>" +
        "</div>";
        $('#questionPopupCont').html(containerContent);
    } 
}

function closePopupQuestion()
{
    document.getElementById('questionPopupCont').innerHTML ="";
}

// Popup layer Function 1 of 4
function repositionPopup()
{
    e.style.width = "0px";    
    
    var frameWidth;
    var frameHeight;
    var marginTopY = getScrollCoordinates() + 50;
    
    if( window.innerHeight && window.scrollMaxY ) 
    {
        // Firefox 
        frameWidth = window.innerWidth + window.scrollMaxX;
        frameHeight = window.innerHeight + window.scrollMaxY;
    }
    else if( document.body.scrollHeight > document.body.offsetHeight ) 
    {
        // all but Explorer Mac
        frameWidth = document.body.scrollWidth;
        frameHeight = document.body.scrollHeight;
    }
    else 
    {
        // works in Explorer 6 Strict, Mozilla (not FF) and Safari
        frameWidth = document.body.offsetWidth + document.body.offsetLeft; 
        frameHeight = document.body.offsetHeight + document.body.offsetTop;
    }
    
    e.style.width= frameWidth+"px";
    e.style.height= frameHeight+"px";
    f.style.left = (frameWidth/2 - f.offsetWidth/2)+ "px";
    f.style.marginTop = marginTopY+ "px";
}

// Popup layer Function 2 of 4 
function getFrameWidth() {    
    return (document.width || document.body.offsetWidth);
}
// Popup layer Function 3 of 4 
function getFrameHeight() {
   return (document.height || document.body.offsetHeight);
}
// Popup layer Function 4 of 4 
function getScrollCoordinates() { 
    var frameWidth;
    var frameHeight;
    var windowHeight;
    var marginTopAmount;
    var scrollTop;
    var windowFrameRatio;

    frameWidth = getFrameWidth();
    frameHeight = getFrameHeight();
    
    if(frameWidth < 1)
        frameWidth =1;
    if(frameHeight < 1)
        frameHeight =1;
    
    scrollTop = window.pageYOffset || document.documentElement.scrollTop || 0; var scrollLeft = window.pageXOffset || document.documentElement.scrollLeft || 0;
    if (window.innerHeight) //if browser supports window.innerWidth
        windowHeight = window.innerHeight;
    else if (document.all) //else if browser supports document.all (IE 4+)
        windowHeight = document.documentElement.clientHeight;
    
    windowFrameRatio = (windowHeight/frameHeight) * frameHeight;
    marginTopAmount = windowFrameRatio * (scrollTop/windowHeight);
    return marginTopAmount;
} 

function removePopup()
{
    popUpOn = false;
    var removePopupCont = document.getElementById('popupCont');
    removePopupCont.parentNode.removeChild(removePopupCont);
    
    if(getMovieName("homeFlash01"))
    {
        getMovieName("homeFlash01").callPlayBall();
    }
    
    e = null;
    f = null;
}

/* This utility function resolves the string movieName to a Flash object reference based on browser type. */
function getMovieName(movieName) {
    if (window[movieName]) return window[movieName];
    if (document[movieName]) return document[movieName];
}

var d=new Date();
var yr=d.getFullYear();
var yearNew;
if (yr!=1995)
    yearNew = "- "+yr;

var _logo = ''
    + '<img src="/images/logo-insuranceRates.gif" width="249" height="77" alt="insuranceRates.com" />';

var _logoWelcome = ''
    + '<a href="/"><img src="/images/logo-insuranceRates.gif" width="249" height="77" alt="insuranceRates.com" /></a>';

var _footer1 = "window.open('insweb/patents.html','myWin','scrollbars=yes,width=550,height=200');";
var _footer = ''
	+ '<div class="footerContainer">'
            + '<ul>'
			+ '<li><a href="/privacy-security.html" target="_blank" rel="nofollow">Privacy &amp; Security</a></li>'
			+ '<li><a href="/terms-of-use.html" target="_blank" rel="nofollow">Terms of Use</a></li>'
			+ '<li><a href="/contact-us.html" target="_blank" rel="nofollow">Contact Us</a></li>'
			+ '<li><a href="/about-us.html" target="_blank" rel="nofollow">About Us</a></li>'
			+ '</ul>'

				
			+ '<div class="copyright">'
				 + '&copy;2008'
				 + yearNew
                 +  ' InsWeb, Inc. All rights reserved. A NASDAQ Company. '
			+ '</div>'
				
			+ '<div class="footerLogos">'
				+ '<a rel="nofollow" href="http://www.truste.org/ivalidate.php?url=www.insurancerates.com&sealid=101" target="_blank">'
					+ '<img src="/images/logo_truste.gif" width="96" height="42" alt="TRUSTe" /></a>'
			+ '</div>'
        + '</div>';

var _footerWelcome = ''
	+ '<div class="footerContainer">'
            + '<ul>'
			+ '<li><a href="/privacy-security.html" target="_blank" rel="nofollow">Privacy &amp; Security</a></li>'
			+ '<li><a href="/terms-of-use.html" target="_blank" rel="nofollow">Terms of Use</a></li>'
			+ '<li><a href="/contact-us.html" target="_blank" rel="nofollow">Contact Us</a></li>'
			+ '<li><a href="/about-us.html" target="_blank" rel="nofollow">About Us</a></li>'
			+ '</ul>'

				
			+ '<div class="copyright">'
				 + '<p>'
				 + '&copy;2008'
				 + yearNew
                 + ' InsWeb, Inc. All rights reserved. A NASDAQ Company. </p>'
                 + '<p>InsWeb owns the following U.S. patents:  6,898,597; 7,107,325; 7,389,246;<br /> 7,640,176; 7,707,505.<br />'
			+ '</div>'
				
			+ '<div class="footerLogos">'
				+ '<a rel="nofollow" href="http://www.truste.org/ivalidate.php?url=www.insurancerates.com&sealid=101" target="_blank">'
					+ '<img src="/images/logo_truste.gif" width="96" height="42" alt="TRUSTe" /></a>'
			+ '</div>'
        + '</div>';

var _footerResourceCtr = ''
        + '<div class="footerContainer">'
            + '<ul>'
			+ '<li><a href="/privacy-security.html" rel="nofollow">Privacy &amp; Security</a></li>'
			+ '<li><a href="/terms-of-use.html" rel="nofollow">Terms of Use</a></li>'
			+ '<li><a href="/contact-us.html" rel="nofollow">Contact Us</a></li>'
			+ '<li><a href="/about-us.html" rel="nofollow">About Us</a></li>'
			+ '<li><a href="/site-map.html" rel="nofollow">Site Map</a></li>'

			+ '</ul>'

				
			+ '<div class="copyright">'
				 + '&copy;2008'
				 + yearNew
                 +  ' InsWeb, Inc. All rights reserved. A NASDAQ Company. '
			+ '</div>'
				
			+ '<div class="footerLogos">'
				+ '<a rel="nofollow" href="http://www.truste.org/ivalidate.php?url=www.insurancerates.com&sealid=101" target="_blank">'
					+ '<img src="/images/logo_truste.gif" width="96" height="42" alt="TRUSTe" /></a>'
			+ '</div>'
        + '</div>';