function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie = c_name + "=" + escape(value) + ((expiredays==null)?"":";expires="+exdate.toGMTString()) + ";path=/";
}


function deleteCookie( name, path, domain ) {
if ( getCookie( name ) ) 
	document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

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 "";
}

function goToLandingPage(portal, destPage)
{
	var pref, region;
	var destURL = location.protocol + "//" + location.host + "/" + portal + "/";
	
	pref = getCookie(portal);
	region = pref.substring(0, pref.indexOf("|"));
	if (region != null && region != "")
	{  	    
		destURL +=  region + "/" + destPage;					
	}
	else
	{
		destURL += destPage;			
	}
	location.replace(destURL);
}


function goToLevel3Link(portal, toPage)
{
	var pref;
	var destURL = staticContentBase;
	
	pref = getCookie(portal);
	if (pref != null && pref != "")
	{  
		destURL += portal + "/" + pref + "/" + toPage;			
	}
	else
	{
		destURL += portal + "/interim_level_3.html?toPage=" + toPage;	
	}
	location.replace(destURL);
}

function querySt(p) 
{
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0;i<gy.length;i++) 
	{
		ft = gy[i].split("=");
		if (ft[0] == p) 
		{
			return ft[1];
		}
	}
}

function changePreference()
{
	var s = location.pathname;
	var start = s.lastIndexOf("/") + 1;
    var end = s.indexOf(".");
	s = s.slice(start, end);
	
	var redirectURL = "../broker_level_3.html?target=" + s;
	//alert("redirectURL = "+redirectURL);
	location.replace(redirectURL);
}

function getPreference(portal)
{
	var pref, start;
	
	pref = getCookie(portal);
	if (pref != null && pref != "")
	{  
		if (portal == "provider")
		{
			switch (pref) {
				case "ny" :	
				  pref = "the Number 8";
				  break;
				case "rochester" :
				  pref = "a Letter";
				  break;
			}
		}
		if (portal == "medicare")
		{
			// get county name 
			start = pref.indexOf("|"); 
			pref = pref.substring(start+1);
		}
	}
	else
	{
		//alert("not possible");
	}
	document.writeln(pref);
}