var process;

function noCache(url)
{
	var sep = (-1 < url.indexOf("?")) ? "&" : "?"	
	url = url + sep + "__=" + encodeURIComponent((new Date()).getTime());	
	return url;
}

//------------------------------------------------------------------------------

function getResponse(fromURL)
{	

	if (window.ActiveXObject) 
	{
		HttpGetResponse = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else 
	{
        HttpGetResponse = new XMLHttpRequest;
    }
    
	
	SendUrl = noCache(SendUrl);
    HttpGetResponse.open("GET", SendUrl, true);
    HttpGetResponse.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	
    HttpGetResponse.onreadystatechange = HandleHttpGetResponse;
    HttpGetResponse.send(null);
}

//------------------------------------------------------------------------------

function HandleHttpGetResponse() 
{
	var result;
	
	if (HttpGetResponse.readyState == 4) 
	{
		Response(HttpGetResponse.responseText);
	}	
	
}   

//------------------------------------------------------------------------------
var response_text=null;
function Response(response_text)
{
	//alert(process);
	switch(process)
	{
		case "Sextips" :document.getElementById("Sextips").innerHTML	=	response_text;	break;
		
		case "Trivia" :	document.getElementById("Trivya").innerHTML		=	response_text;	break;

		case "Polling" :document.getElementById("Poll").innerHTML		=	response_text;	break;
		
		case "GetJoke" :document.getElementById("joke").innerHTML		=	response_text;	break;
	
		case "PostJoke" :document.getElementById("joke").innerHTML		=	response_text;	break;
	
		case "Healthcare" :document.getElementById("Healthcare").innerHTML	=	response_text;	break;
	}
	//alert("Joke html"+document.getElementById("joke").innerHTML);
	
}

//------------------------------------------------------------------------------
var aloc;
var t;
var imgtype;
function showPortletInit(portletbox, portletarrow)
{

	obj	=	document.getElementById(portletbox);
	cookieval=retrieveCookie(portletbox);
	
	if(cookieval!=null)
		obj.style.display	= cookieval;

	aloc					=	document.getElementById(portletarrow).src;
	t						=	aloc.lastIndexOf('/')+1;
	aloc					=	aloc.substring(0,t);
	
	
	if(portletbox=='calenderbox')
		imgtype = "gif";
	else
		imgtype = "jpg";

	switch(portletbox)
	{
		case "calenderbox"	:	obj.style.display = "block";
								break;

		case "eroticabox"	:	obj.style.display = "block";
								break;

		case "articlesbox"	:	obj.style.display = "block";
								break;

		case "specialbox"	:	obj.style.display = "block";
								break;

		default				:	obj.style.display = "none";
	}

	if(obj.style.display == "none")
	{		
		
		document.getElementById(portletarrow).src	=	aloc+"downarrow."+imgtype;
		obj.height="20px";
	}
	else
	{		
		document.getElementById(portletarrow).src	=	aloc+"uparrow."+imgtype;
	}
	
}

//------------------------------------------------------------------------------


function showPortlet(portletbox, portletarrow)
{	
	obj			=	document.getElementById(portletbox);
	aloc		=	document.getElementById(portletarrow).src;
	t			=	aloc.lastIndexOf('/')+1;
	aloc		=	aloc.substring(0,t);

	var boxarr	= new Array();

	//boxarr[0]	="calenderbox";
	boxarr[0]	="trivyabox";
	boxarr[1]	="sextipsbox";
	boxarr[2]	="pollbox";
	boxarr[3]	="jokebox";
	boxarr[4]	="healthcarebox";
	boxarr[5]	="featured_productbox";
	//boxarr[7]	="articlesbox";

	arrowarr	= new Array();
	//arrowarr[0]	= "carrow";
	arrowarr[0]	= "tarrow";
	arrowarr[1]	= "sarrow";
	arrowarr[2]	= "parrow";
	arrowarr[3]	= "arrow";
	arrowarr[4]	= "harrow";
	arrowarr[5]	= "fparrow";
	//arrowarr[7]	= "aarrow";

	for(i=0;i<boxarr.length;i++)
	{
		//alert(boxarr[i]+" : "+document.getElementById(boxarr[i]));
		other_obj					= document.getElementById(boxarr[i]);	
		
		if(portletbox != boxarr[i] && document.getElementById(boxarr[i]) != null && other_obj.style.display != "block")
		{
			other_obj.style.display		= "none";
			other_aloc					=	document.getElementById(arrowarr[i]).src;
			other_t						=	other_aloc.lastIndexOf('/')+1;
			other_aloc					=	other_aloc.substring(0,other_t);

			document.getElementById(arrowarr[i]).src	=	other_aloc+"downarrow.jpg";
		}
		
	}
	if(portletbox == 'calenderbox')
		imgtype = "gif";
	else
		imgtype = "jpg";

	if(obj.style.display == "none")
	{
		obj.style.display = "block";		
		document.getElementById(portletarrow).src	=	aloc+"uparrow."+imgtype;
		obj.height="20px";
	}
	else
	{
		obj.style.display = "none";
		document.getElementById(portletarrow).src	=	aloc+"downarrow."+imgtype;
	}

	setCookie( portletbox, obj.style.display, 5000, "/") ;
}

//------------------------------------------------------------------------------

function setCookie( cookieName, cookieValue, lifeTime, path, domain, isSecure ) 
{	
	if( !cookieName ) { return false; }
	if( lifeTime == "delete" ) { lifeTime = -10; } //this is in the past. Expires immediately.
	else
		lifeTime=24*60*60*1000*30;

	/* This next line sets the cookie but does not overwrite other cookies.
	syntax: cookieName=cookieValue[;expires=dataAsString[;path=pathAsString[;domain=domainAsString[;secure]]]]
	Because of the way that document.cookie behaves, writing this here is equivalent to writing
	document.cookie = whatIAmWritingNow + "; " + document.cookie; */
	document.cookie = escape( cookieName ) + "=" + escape( cookieValue ) +
		( lifeTime ? ";expires=" + ( new Date( ( new Date() ).getTime() + ( lifeTime ) ) ).toGMTString() : "" ) +
		( path ? ";path=" + path : "") + ( domain ? ";domain=" + domain : "") + 
		( isSecure ? ";secure" : "");
	//check if the cookie has been set/deleted as required
	
	if( lifeTime < 0 ) { if( typeof( retrieveCookie( cookieName ) ) == "string" ) { return false; } return true; }
	if( typeof( retrieveCookie( cookieName ) ) == "string" ) { return true; } return false;
}

//------------------------------------------------------------------------------

function retrieveCookie( cookieName ) 
{
	/* retrieved in the format
	cookieName4=value; cookieName3=value; cookieName2=value; cookieName1=value
	only cookies for this domain and path will be retrieved */
	var cookieJar = document.cookie.split( "; " );
	for( var x = 0; x < cookieJar.length; x++ ) {
		var oneCookie = cookieJar[x].split( "=" );
		if( oneCookie[0] == escape( cookieName ) ) { return unescape( oneCookie[1] ); }
	}
	return null;
}
//------------------------------------------------------------------------------
