﻿
var userState = "";
$(document).ready(function(){
	/*jQuery.get("/isstate.aspx",function(data){			
		isState = data;
		if (isState != "True")
		{
			userState = data;
			showPopUp(data);
		}
		});			*/
})

function showPopUp(state)
{		
	$("body").append("<div id='popupDiv'>");	
	$("#popupDiv").load("popup.html",function(){
		$(".windshields_link").attr("href","http://www.windshields.com/"+state+"_windshield_replacement.html");
		$("#stateSpan").text(state);
		var id = "#dialog";
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		//$('#mask').fadeIn(500);	
		$('#mask').fadeTo(1000,0.9);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
			  
		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
	
		//transition effect
		$(id).fadeIn(1000);
		
		
			//if close button is clicked
		$('.close').click(function (e) {
			//Cancel the link behavior
			e.preventDefault();
			//alert(close);
			$('#mask').fadeOut(300);
			$('.modal').fadeOut(300);
			clearInterval(timerInterval);
		});		
		
		//if mask is clicked
		$('#mask').click(function () {
			$(this).fadeOut(300);
			$('.modal').fadeOut(300);
			clearInterval(timerInterval);
		});	
		timerInterval = setInterval('redirect()',1000);
	});
}
var time = 5;
var timerInterval = 0;
function redirect()
{
	time = (time - 1)	
	$("#secondsSpan").html(time);
	if (time <= 0)
	{
	window.location = "http://www.windshields.com/"+userState+"_windshield_replacement.html";
	clearInterval(timerInterval);
	}
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}
