/**
To manage with cookies
*/

var URL_SUFFIX = ""; //Change this to reflect the current domain.
var PORTAL_URL_SUFFIX = "";
var COOKIE_NAME = "BHPConstiuent";
var VISITOR_CONST = "VISITOR";
var MEMBER_CONST = "MEMBER";
var PROVIDER_CONST = "PROVIDER";
var AGENT_CONST = "AGENT";
var EMPLOYER_CONST = "EMPLOYER";

var VISITOR_URL = "home-visitors.html";
var MEMBER_URL = "home.html";
var PROVIDER_URL = "home-providers.html";
var AGENT_URL = "home-brokers.html";
var EMPLOYER_URL = "home-employers.html";

function getexpirydate( nodays){
	var UTCstring;
	Today = new Date();
	nomilli=Date.parse(Today);
	Today.setTime(nomilli+nodays*24*60*60*1000);
	UTCstring = Today.toUTCString();
	return UTCstring;
}

function getcookie(cookiename) {
	var cookiestring=""+document.cookie;
	var index1=cookiestring.indexOf(cookiename);
	if (index1==-1 || cookiename=="") return ""; 
	var index2=cookiestring.indexOf(';',index1);
	if (index2==-1) index2=cookiestring.length; 
	return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

function setcookie(name,value,duration){
	cookiestring=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration);
	document.cookie=cookiestring;
	if(!getcookie(name)){
		return false;
	}
	else{
		return true;
	}
}

function manageCookie()
{
	var locationUrl = "";
	var cookieValue = getcookie(COOKIE_NAME);
	//alert(cookieValue);
	if(cookieValue == VISITOR_CONST)
	{
		locationUrl = VISITOR_URL;
	}
	else if(cookieValue == PROVIDER_CONST)
	{
		locationUrl = PROVIDER_URL;
	}
	else if(cookieValue == AGENT_CONST)
	{
		locationUrl = AGENT_URL;
	}
	else if(cookieValue == EMPLOYER_CONST)
	{
		locationUrl = EMPLOYER_URL;
	}
	else 
	{
		locationUrl = MEMBER_URL;
	}

	if((cookieValue == "" && currentPage != MEMBER_CONST ) || (cookieValue != "" && currentPage != cookieValue))
	{
		window.location.href = locationUrl;
	}
}

function saveAndForward(cookieConst)
{
	setcookie(COOKIE_NAME, cookieConst, 365);
	var locationUrl = MEMBER_URL;
	if(cookieConst == VISITOR_CONST)
	{
		locationUrl = VISITOR_URL;
	}
	else if(cookieConst == PROVIDER_CONST)
	{
		locationUrl = PROVIDER_URL;
	}
	else if(cookieConst == AGENT_CONST)
	{
		locationUrl = AGENT_URL;
	}
	else if(cookieConst == EMPLOYER_CONST)
	{
		locationUrl = EMPLOYER_URL;
	}
	else 
	{
		locationUrl = MEMBER_URL;
	}
	
	window.location.href = locationUrl;
	
}

function goToLandingPage(url)
{
	window.location.href = PORTAL_URL_SUFFIX + url;
}

function goToStateLandingPage(url, strLabel)
{
	var selecteditem = (null == document.frmState.cboState.selectedIndex)?0:document.frmState.cboState.selectedIndex;
	if(selecteditem==0 || selecteditem == null)
	{
		alert("Please select a state");
		document.frmState.cboState.focus();
	}
	else
	{
		window.location.href = PORTAL_URL_SUFFIX + url + document.frmState.cboState.options[ selecteditem ].value + '&label=' + strLabel;
	}
}

function seturl(cookieConst)
{
	setcookie(COOKIE_NAME, cookieConst, 365);
	
}
function sethomeurl(){
if(location.pathname == "/home.html"){seturl('MEMBER')}

}

function openNewWindow(url)
{
	window.open(url,"","height=400,width=500,resizable=yes,location=no,toolbar=no,menubar=no,scrollbars=yes"); 
}

