
var popIsOpen = false;
var formIsOpen = false;

function setCookie(c_name,value,exdays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie = c_name + "=" + c_value + "; path=/";
	if (c_name == "formCookie") {
	    //alert("setting cookie");
    }
}

function getCookie(c_name)
{
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++)
	{
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if (x==c_name)
		{
			return unescape(y);
		}
	}
}


function checkFormCookie()
{
    var val = getCookie("formCookie");
	if (val!=null && val!="")
	{
		return true;
	}
	else
	{
		return false;
	}
}



function setLocationCookie()
{
	var val=getCookie("locationCookie");
	if (val!=null && val!="")
	{
	}
	else
	{
		setCookie("locationCookie","NONE",1);
	}
			
	if (currentURL.indexOf("oklahoma") > -1) {
		//alert("okc");
		setCookie("locationCookie","OKC",1);
	}
	if (currentURL.indexOf("illinois") > -1) {
		//alert("chi");
		setCookie("locationCookie","CHI",1);
	}
	if (currentURL.indexOf("newjersey") > -1) {
		setCookie("locationCookie","NJ",1);
	}

}

function setSourceCookie()
{
	var val=getCookie("sourceCookie");
	if (val!=null && val!="")
	{
	}
	else
	{		
		var getQs = new QueryData();

		if(getQs.v == "GOOG")
		{
			setCookie("sourceCookie","SEM",1);
		}
		else if (getQs.v === undefined)
		{
			setCookie("sourceCookie","Organic",1);
		}
		else
		{
			setCookie("sourceCookie","Display",1);
		}
	}
}

/*

QueryData.js

A function to parse data from a query string

Created by Stephen Morley - http://code.stephenmorley.org/ - and released under
the terms of the CC0 1.0 Universal legal code:

http://creativecommons.org/publicdomain/zero/1.0/legalcode

*/

function QueryData(_1,_2)
{
	if(_1==undefined){
		_1=location.search?location.search:"";
	}
	if(_1.charAt(0)=="?"){
		_1=_1.substring(1);
	}
	if(_1.length>0)
	{
		_1=_1.replace(/\+/g," ");
		var _3=_1.split(/[&;]/g);
		for(var _4=0;_4<_3.length;_4++)
		{
			var _5=_3[_4].split("=");
			var _6=decodeURIComponent(_5[0]);
			var _7=_5.length>1?decodeURIComponent(_5[1]):"";
			if(_2)
			{
				if(!(_6 in this))
				{
					this[_6]=[];
				}
				this[_6].push(_7);
			}else{
				this[_6]=_7;
			}
		}
	}
}


$(document).ready(function() {

	// exit survey location cookie:
	setLocationCookie();
	setSourceCookie();

});
