function showHideNavPop(elemID, showHide) {
		if(document.getElementById(elemID)) {
			document.getElementById(elemID).style.display = (showHide == 'show' ? 'block' : 'none');
		}
	}



// ##
// ## Function: setCookie
// ## Sets a Cookie with the given name and value.
// ##
// ## name       Name of the cookie
// ## value      Value of the cookie
// ## [expires]  Expiration date of the cookie (if empty: end of current session)
// ## [path]     Path where the cookie is valid (default: path of calling document)
// ## [domain]   Domain where the cookie is valid
// ##              (default: domain of calling document)
// ## [secure]   Boolean value indicating if the cookie transmission requires a
// ##              secure transmission
// ##
// 
 

	function setCookie (cookiename, cookievalue, expirationDate, path, domain, secure) {
		
		var expiresdate = new Date()
	
		if(expirationDate) {
			expiresdate.setTime(expiresdate.getTime() + (expirationDate))
		}
	
		document.cookie = cookiename + '=' + escape(cookievalue) + ((expirationDate) ? '; expires=' + expiresdate.toGMTString() : '') + ((path) ? '; path=' + path : '') + ((domain) ? '; domain=' + domain : '') + ((secure) ? '; secure' : '');
	
	}



// 
// ##
// ## Function: getCookie
// ## Return requested cookie data
// ##
// 
 

	function getCookie(cookiename)
	{
	   //split up the cookies into an array. if you use "; " as a value in a cookie, this script won't work.
	   //special characters such as "=", ";", etc, should always be escaped.
	   var cookies = document.cookie.split('; ');
	   for (var i = 0; i < cookies.length; i++)
	   {
		  //if the name of the cookie is found
		  if (cookies[i].indexOf(cookiename) == 0)
		  {
			 //return everything that comes after the cookiename + "=" character.
			 return unescape(cookies[i].substring(cookiename.length + 1));
		  }
	   }
	
	   return null;
	}




/* toolbar / recently viewed javascript */
function recentUpdateCookie()
{
	var boyurl = document.getElementById('boyurl').innerHTML;
	var boyname = document.getElementById('boyname').innerHTML;
	var expiryDate = 30*24*60*60*1000;
	if( getCookie('eguysrv') )
	{
		if( getCookie('eguysrv') != 'off' )
		{
			var cookieArray = getCookie('eguysrv').split('#');
			var recentDest = cookieArray.shift();
			
			var cookieString = recentDest+"#";
			cookieArray = recentRemoveDupe(cookieArray);
			cookieArray.unshift(boyurl+'^'+boyname);
			while (cookieArray.length>11) cookieArray.pop();
			for(var i=0; i<cookieArray.length-1; i++) cookieString += cookieArray[i]+'#';
			setCookie('eguysrv',cookieString,expiryDate,'/');
		}
	}
	else if(getCookie('eguysrv') != 'off')
	{
		var recentDest = 'x^x^x#';
		
		
		setCookie( 'eguysrv', recentDest + boyurl+'^'+boyname+'#',expiryDate,'/');
	}
}
function shortenTitle(titleString)
{
	if(titleString.length>25) titleString = titleString.substring(0,23) + "...";
	return titleString;
}
function recentOutputCookie()
{
	if( getCookie('eguysrv') )
	{
		if( getCookie('eguysrv') != 'off' )
		{
			var cookieArray = getCookie('eguysrv').split('#');
			var linkText = '';
			cookieArray.shift();
			document.write('<ol id="p_recent"  >');
			for(var i=0; i<10; i++)
			{
			   if (cookieArray[i]!=undefined)
			   {
				if(cookieArray[i].split('^')[1]!=undefined)
				{
				        document.write('<li>');
					if (cookieArray[i].split('^')[1].length > 28)
					{
					   linkText = cookieArray[i].split('^')[1].substring(0,27);
					}
					else
					{
					   linkText = cookieArray[i].split('^')[1]
					}
					document.write('<a href=\"'+cleanRecentOutput(cookieArray[i].split('^')[0])+'\">'+linkText+'</a>');
					document.write('</li>');
				}
				else 
				{
				document.write('<li>&nbsp;</li>');
				}
			   }
			   else
			   {
			   document.write('<li>&nbsp;</li>');   
			   }
			   
			   
			}
			document.write('<li class=\"nonum\"><span class=\'option1\'><a href=\"javascript:recentKillCookie()\">Clear</a></span><span class=\'option2\'><a href=\"javascript:recentChangeClass(\'hide\')\">Close</a></span><span class=\'option3\'><a href=\"javascript:recentChangeClass(\'hide\')\"><img src="/images/icon-close.gif"></a></span>');
			document.write('</ol>');
			
		}
		else recentKillCookie(true);
	}
	else if(getCookie('eguysrv')==null){
		document.write('<ol id="p_recent" onclick="recentChangeClass(\'show\');">');
		document.write('<li class=\"messageBox\">This feature requires cookies to be enabled</li>');
		document.write('<li class=\"nonum\"><span class=\'option1\'><a href=\"javascript:recentKillCookie()\">Clear</a></span><span class=\'option2\'><a href=\"javascript:recentChangeClass(\'hide\')\">Close</a></span><span class=\'option3\'><a href=\"javascript:recentChangeClass(\'hide\')\"><img src="/images/icon-close.gif"></a></span>');
		document.write('</ol>');
	}
}


function cleanRecentOutput(inStr) { // remove rogue elements from input
	var norty = new Array('</', '%3C/', '&lt;/', '%3C', '<', '>', '%3E', '&lt;', '&gt;'); // define list of exclusions
	for(var i=0; i < norty.length; i++) {
		var regExStr = new RegExp(norty[i], 'gi');
		inStr = inStr.replace(regExStr, "");
	}
	return(inStr);
}



function recentRemoveDupe(cookieArray)
{
	var boyname = document.getElementById('boyname').innerHTML;
	for(var i=0; i<cookieArray.length; i++)
	{
		if(cookieArray[i].split("^")[1]==boyname) cookieArray.splice(i,1);
	}
	return cookieArray;
}


function recentChangeClass(showhide) {

    showHideNavPop('thhead_recent', 'show');
    showHideNavPop('p_recent', showhide);
}


function recentKillCookie(turnoff)
{	

        var outputHTML = '';
	
	if(turnoff)
	{
	  
		var expiryDate = 30*24*60*60*1000;
		var message = 'You have turned off this feature';
		var linkinfo = '<span class=\"option1\"><a href=\"javascript:recentKillCookie()\">Turn on</a></span><span class=\"option2\"><a href=\"javascript:recentChangeClass(\'hide\')\">Close</a></span><span class=\"option3\"><a href=\"javascript:recentChangeClass(\'hide\')\"><img src=\"/images/icon-close.gif\"></a></span>';	
		var visible = 'style=\"visibility:hidden;\"';
	}
	else
	{
		var expiryDate = -60*60*1000;
		var message = 'You have no recently viewed escorts';
		var linkinfo = '<span class=\"option2\"><a href=\"javascript:recentChangeClass(\'hide\')\">Close</a></span><span class=\"option3\"><a href=\"javascript:recentChangeClass(\'hide\')\"><img src=\"/images/icon-close.gif\"></a></span>';
		var visible = '';
	}
	recentChangeClass('hide');
	
	outputHTML += '<li class=\"messageBox\">'+message+'</li>';
	outputHTML += '<li class=\"nonum\"><span class=\"option1\"><a href=\"javascript:recentKillCookie()\" '+visible+'>Clear</a></span>';
	outputHTML += linkinfo;
	
	document.getElementById('p_recent').innerHTML = outputHTML;
	setCookie('eguysrv','off',expiryDate,'/');
}




