/*
Script Name: Javascript Cookie Script
Author: Public Domain, with some modifications
Script Source URI: http://techpatterns.com/downloads/javascript_cookies.php
Version 1.1.1
Last Update: 4 October 2007

Changes:
1.1.1 fixes a problem with Get_Cookie that did not correctly handle case
where cookie is initialized but it has no "=" and thus no value, the 
Get_Cookie function generates a NULL exception. This was pointed out by olivier, thanks

1.1.0 fixes a problem with Get_Cookie that did not correctly handle
cases where multiple cookies might test as the same, like: site1, site

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
*/

// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );

// To use, simple do: Get_Cookie('cookie_name'); 
// replace cookie_name with the real cookie name, '' are required
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) 
	{
		return null;
	}
}

/*
only the first 2 parameters are required, the cookie name, the cookie
value. Cookie time is in milliseconds, so the below expires will make the 
number you pass in the Set_Cookie function call the number of days the cookie
lasts, if you want it to be hours or minutes, just get rid of 24 and 60.

Generally you don't need to worry about domain, path or secure for most applications
so unless you need that, leave those parameters blank in the function call.
*/
function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

	document.cookie = name + "=" + value  +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}





function read_cookie() {

var cookie = Get_Cookie( 'session' );

if (cookie) {var cookiesplit = cookie.split("|"); }

if (!cookie || cookiesplit[0] == -1 ) {var loggedin = 0; 
				document.getElementById('userdetails').style.display = "none";
				document.getElementById('regmessage').style.display = "block";
				
				Demo_1 = new Carousel($('scroller'), $$('#scroller .slide'), '', {duration: 0.5, auto: true});
				
				$('loginbutton').innerHTML="<a href='/cgi-bin/admin/fam.pl?db=profiles&action=login_form'><span class='menu_ar'><img border='0' src='../../images/menuicons/1downarrow.png' class='key' hspace='3' width='16'>Login / Register</span></a>";
				

				return; }
				
				
var loggedin = 1; 				

var link = cookiesplit[0].toLowerCase(); 

var link2 = link.replace(" ", "-");


var cr = parseFloat(cookiesplit[2]);

var credits=Math.round(cr*100)/100;


if (cookiesplit[0]) {document.getElementById('balance').innerHTML="<b><font color='#FFFF00'>" + cookiesplit[0] + "</font></b>&nbsp;&nbsp;<font color='#FFFFFF'>Credits :</font><font color='#FFFF00'><b>" + credits + "</b></font><font color='#FFFFFF'>&nbsp;&nbsp; Freeviews :&nbsp;</font><font color='#FFFF00'><b>" + cookiesplit[3] + "</b></font>&nbsp;"; }

var siteowner = parseInt(cookiesplit[5]);

$('loginbutton').innerHTML="<a href='/cgi-bin/admin/fam.pl?db=profiles&action=login_form'><span class='menu_ar'><img border='0' src='../../images/menuicons/1downarrow.png' class='key' hspace='3' width='16'>Log Off</span></a>";

document.getElementById('userdetails').style.display = "block";
document.getElementById('regmessage').style.display = "none";

check_status(cookiesplit[0]);

//menubar(cookiesplit[0]);

}





function tomysite() {

var cookie = Get_Cookie( 'session' );

if (cookie) {var cookiesplit = cookie.split("|"); }

if (!cookie || cookiesplit[0] == -1) { window.location.href = 'http://www.findanamateur.com/cgi-bin/admin/fam.pl?db=profiles&action=login_form'; return; }

var siteowner = parseInt(cookiesplit[5]);

if (siteowner == 0) { window.location.href = "http://www.findanamateur.com/cgi-bin/myaccount.pl"; return; }


var nick = cookiesplit[0].toLowerCase(); 

nick.replace(/ /, "-");

var url = "http://www.findanamateur.com/sites/" + nick + "/";

window.location.href = url;







}







function check_status(username) {
var randomnumber=Math.floor(Math.random()*1000)

var urltest = window.location.href;

if (urltest.indexOf("dev.findanamateur") > 0) {var url = 'http://dev.findanamateur.com/cgi-bin/admin/check_status.pl'; }

else {var url = 'http://www.findanamateur.com/cgi-bin/admin/check_status.pl'; }



new Ajax.Request(url,  
 {     method:'get', 
	   parameters: {name: username, rand: randomnumber},  
	    onSuccess: function(transport){       var response = transport.responseText; 
    											var splits = response.split("-");	    
    											//------Check for mail
    											if (splits[2] > 0) {
													window.clearInterval(fl);
															 var fl = setInterval ( "flashbutton()", 900 ); }
    											



												//------Check status
												if (splits[3] == "online") { $('status_icon').src = "/images/online.png"; }
												else {$('status_icon').src = "/images/offline.png"; }

										    }     }); 




}


function statusselector_fill() {


if (document.getElementById('statusselector') == null) {

				Element.insert( $('menubar'), {  after: "<div id='statusselector' style='position: absolute;  z-index: 911; display: block'  > </div>"  }  );

				}


var randomnumber=Math.floor(Math.random()*1000)

var urltest = window.location.href;

if (urltest.indexOf("dev.findanamateur") > 0) {var url = 'http://dev.findanamateur.com/cgi-bin/statusselector_2.pl';}

else {var url = 'http://www.findanamateur.com/cgi-bin/statusselector_2.pl'; }

var pars = 'action=showform&rand=' + randomnumber;
var target = 'statusselector';	

var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars, evalScripts: true});

el = $('mystatusbutton');
se = $('statusselector');

Position.clone(el, se, { setWidth: false, offsetTop: 20, offsetLeft: -50 }); 

//Effect.SlideDown('statusselector', { duration: 0.5 });

$('statusselector').style.display = "block";

}




function close_status() {

$('statusselector').remove();

}
















function popwebcam(hostname,mode) {

var randomnumber=Math.floor(Math.random()*1000)

var cookie = Get_Cookie( 'session' );

if (cookie) {var cookiesplit = cookie.split("|"); }

if (!cookie || cookiesplit[0] == -1 ) {window.location.href="http://www.findanamateur.com/cgi-bin/admin/fam.pl?db=profiles&action=login_form"; }

var test = cookiesplit[0] + "|" + cookiesplit[1] + "|" + cookiesplit[2] + "|" + cookiesplit[3]

var url = "http://www.findanamateur.com/cgi-bin/admin/check_online.pl";


new Ajax.Request(url,  
 {     method:'get', 
	   parameters: {sessionid: test, random: randomnumber},  
	    onSuccess: function(transport){       var response2 = transport.responseText; 
	    										if (response2.match('ok')) {
	    										
	    										var camwindow = "/camplayer/videochat.html?host_name=" + hostname + "&mode_request=" + mode;
	    										
	    										window.open(camwindow, "popcam", "titlebar=no,location=no,toolbar=no,menubar=no,status=no,scrollbars=yes,resizable=yes");
	    										
	    										return;
	    										
	    										
	    										}
	    
	    										
	    										else {
	    										
	    										//document.write("response = " + response2);
	    										
	    										
	    										window.location.href="http://www.findanamateur.com/cgi-bin/admin/fam.pl?db=profiles&action=login_form";
	    										 }
	    


										    }     }); 










}









function menubar(username) {
var randomnumber=Math.floor(Math.random()*1000)

var urltest = window.location.href;

if (urltest.indexOf("dev.findanamateur") > 0) {var url = 'http://dev.findanamateur.com/cgi-bin/menubar.pl?name=' + username + '&rand=' + randomnumber; }

else {var url = 'http://www.findanamateur.com/cgi-bin/menubar.pl?name=' + username + '&rand=' + randomnumber; }



status_ajaxpage(url, 'menubar'); 

}







function toggle_status(type) {

if (type == "online") { if (document.mystatusfrm.mystatus == "online") {return; }

						document.mystatusfrm.onlinechk.src = "/images/key/chkboxon.png";
						document.mystatusfrm.offlinechk.src = "/images/key/chkboxoff2.png";

					    document.mystatusfrm.mystatus.value = "online"; 
					   if (document.mystatusfrm.siteowner.value > 0) { $('innerstatustable').removeClassName('translucent'); }

						return;	
					    }
					    
					    
if (type == "offline") {  if (document.mystatusfrm.mystatus.value == "offline") {return; }
							

						 document.mystatusfrm.onlinechk.src = "/images/key/chkboxoff2.png";
						 document.mystatusfrm.offlinechk.src = "/images/key/chkboxon.png";

					    document.mystatusfrm.mystatus.value = "offline";
					    
						if (document.mystatusfrm.siteowner.value > 0) {$('innerstatustable').addClassName('translucent'); }




						
						return;

						 }
					    
//------------------------doing a sub type so do check first

if (document.mystatusfrm.mystatus.value == "offline" || document.mystatusfrm.siteowner.value < 1) { return; }

eval("check = $F('" + type + "rowonoff');");

if (check != "on") { return; }


if (type == "webcams") { 

				if (document.mystatusfrm.webcamsonline.value == "online") { document.mystatusfrm.webcamsonline.value = "offline"; 
																			document.mystatusfrm.webcamschk.src = 	"/images/key/chkboxoff2.png";
																			}
				else {document.mystatusfrm.webcamsonline.value = "online"; 
					  document.mystatusfrm.webcamschk.src = 	"/images/key/chkboxon.png"; }

						}				    
	

if (type == "phone") { 

				if (document.mystatusfrm.phoneonline.value == "online") { document.mystatusfrm.phoneonline.value = "offline"; 
																			document.mystatusfrm.phonechk.src = 	"/images/key/chkboxoff2.png";
																			}
				else {document.mystatusfrm.phoneonline.value = "online"; 
					  document.mystatusfrm.phonechk.src = 	"/images/key/chkboxon.png"; }

						}				    
	

if (type == "escort") { 

				if (document.mystatusfrm.escortonline.value == "online") { document.mystatusfrm.escortonline.value = "offline"; 
																			document.mystatusfrm.escortchk.src = 	"/images/key/chkboxoff2.png";
																			}
				else {document.mystatusfrm.escortonline.value = "online"; 
					  document.mystatusfrm.escortchk.src = 	"/images/key/chkboxon.png"; }

						}	



if (type == "justcamit") { 

				if (document.mystatusfrm.justcamitonline.value == "online") { document.mystatusfrm.justcamitonline.value = "offline"; 
																			document.mystatusfrm.justcamitchk.src = 	"/images/key/chkboxoff2.png";
																			}
				else {document.mystatusfrm.justcamitonline.value = "online"; 
					  document.mystatusfrm.justcamitchk.src = 	"/images/key/chkboxon.png"; }

						}	
			 
}







function set_status() {

var randomnumber=Math.floor(Math.random()*1000)


var pars = Form.serialize('mystatusfrm');

var urltest = window.location.href;

if (urltest.indexOf("dev.findanamateur") > 0) {var url = 'http://dev.findanamateur.com/cgi-bin/statusselector_2.pl';}

else {var url = 'http://www.findanamateur.com/cgi-bin/statusselector_2.pl'; }

var target = 'statusselector';	

var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars, evalScripts: true});


stat = $F('mystatus');


var cookie = Get_Cookie( 'session' );

if (cookie) {var cookiesplit = cookie.split("|"); 

	//------------------reset cookie with new status
	Delete_Cookie( 'session', '\/' , '.findanamateur.com' );

	newcookie = cookiesplit[0] + "|" + cookiesplit[1] + "|" + cookiesplit[2] + "|" + cookiesplit[3] + "|" + stat;
	
	
	
	
	
	Set_Cookie( 'session', newcookie, 1, '\/' , '.findanamateur.com' )

	}








}




var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function status_ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}





function flashbutton() {

if ($('mailbutton').hasClassName('flashstatusbutton')) { $('mailbutton').removeClassName('flashstatusbutton'); }

else { $('mailbutton').addClassName('flashstatusbutton'); }

//test = document.getElementById("mailbutton").className;

//if ( test.match("flash")) {document.getElementById("mailbutton").className = "statusbutton"; }


//		else { document.getElementById("mailbutton").className = "flashstatusbutton"; }


}



function statusover(button) {
//document.getElementById(button).style.backgroundImage = "url(../../images/menuicons/black2/blackbutton_over.png)"; 

$(button).addClassName('overstatusbutton');

}


function statusout(button) {
//document.getElementById(button).style.backgroundImage = "url('../../images/menuicons/black2/blackbutton.png')"; 

$(button).removeClassName('overstatusbutton');

}









function switchstatusrow(rowname) {


eval('ch=document.mystatus.' + rowname + '.value;');

if (ch == "1") { return; }

else { eval("document.getElementById('row" + rowname + "').className = 'darkrowoff';"); }


}


function togglestatusrow(rowname){



if (rowname == "offline") {

	document.mystatus.offline.value = "1";
	document.getElementById('rowoffline').className = 'darkrowon';

	document.mystatus.online1.value = "0";
	document.getElementById('rowonline1').className = 'darkrowoff';

	if ($('innerstatus') != undefined) {
	
			$('innerstatus').setStyle({ opacity: '0.2', filter: 'alpha(opacity=20)' });

								}
}

else if (rowname == "online1") {

	document.mystatus.online1.value = "1";
	document.mystatus.offline.value = "0";
	document.getElementById('rowoffline').className = 'darkrowoff';

	document.getElementById('rowonline1').className = 'darkrowon';




	if ($('innerstatus') != undefined) {
	
			$('innerstatus').setStyle({ opacity: '1', filter: 'alpha(opacity=100)' });

								}
}



	
	
}







function flashtext() {

$$('p.flash').each(Element.toggle);

}



