
/*
premium = (read_cookie('premium',null) != null)?read_cookie('premium',null):0;
uid = (read_cookie('uid',null) != null)?read_cookie('uid',null):0;
visitNum = (read_cookie('visitNum',null) != null)?read_cookie('visitNum',null):0;
nickname = (read_cookie('nickname',null) != null)?read_cookie('nickname',null):'';
//alert(uid + " ; " + nickname + " ; " + visitNum)
if(uid == 0 || nickname == '')
{
	self.location.replace('/scripts/cgi/loginall_ex/all_login.pl?target=' + self.location.href);
}
*/
premium = (read_cookie('premium',null) != null)?read_cookie('premium',null):0;
uid = (read_cookie('uid',null) != null)?read_cookie('uid',null):'0';
visitNum = (read_cookie('visitNum',null) != null)?read_cookie('visitNum',null):'0';
if(uid == '0' || visitNum<2)
{
	selfLocation = self.location.href;
	selfLocation = selfLocation.toLowerCase();
	if(selfLocation.indexOf('girlsense.com') != -1 )
	{
		theLink = "http://www.girlsense.com/premium/login/login.pl?target=" + self.location.href ;
		self.location.replace(theLink);
	}
	else
	{
		theLink = "http://www.kiddonet.com/scripts/cgi/loginall_ex/all_entry.pl?target=" + self.location.href ;
		self.location.replace(theLink);
	}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var randBG = "";	
var randImg = "";
	
var numBG = 4;
menuImage = new Array('painter.gif','kid.gif','hawaii.gif','hand.gif');
bgColor = new Array('#2A85FE','#FE761B','#192E5C','#00287F');
var r = Math.random();
r = r*100;
var rint = Math.floor(r);
	
rint = rint%numBG;
randBG = ( (bgColor[rint])? bgColor[rint]:bgColor[0] );
randImg = "<img name='menuImg' id='menuImg' src='addon/general/menu/"+menuImage[rint]+"' border=0 usemap='#FPMap0' width=367 height=410 style='z-index:10;'>"

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function GetRandMenuBG(subject,numBG,extension)
{
	if(extension == null)
		extension = 'gif';
		
	var r = Math.random();
	r = r*100;
	var rint = Math.floor(r);
	rint = rint%numBG;

	//randMenuBG = "<img name='menuImg' id='menuImg' src='addon/" + subject + "/menu/menu"+ rint + "." + extension + "' border=0 usemap='#FPMap0' width=367 height=410>"
	// new_code: only premium users will see a private gallery
	if(premium)
	{
		randMenuBG = "<img name='menuImg' id='menuImg' src='addon/" + subject + "/menu/menu"+ rint + "." + extension + "' border=0 usemap='#FPMap0' width=367 height=410>"
	}
	else
	{
		randMenuBG = "<img name='menuImg' id='menuImg' src='addon/" + subject + "/menu/menu"+ rint + "_reg." + extension + "' border=0 usemap='#FPMap0_reg' width=367 height=410>"
	}
	
	return randMenuBG;
}

var recentlySaved = false;
savedHtml = "feedback.pl";
feedback = "";
subject = "";

waitImg = new Image();
waitImg.src = "images/wait.gif";

function GotoGallery()
{
	theLink = "viewCollection.pl?mode=gallery"  + "&subject=" + subject ;
	self.location.href = theLink;
}
function GotoGreats()
{
	theLink = "viewCollection.pl?mode=greats"  + "&subject=" + subject ;
	self.location.href = theLink;
}

function GotoCreations()
{
	theLink = "viewCollection.pl?myPrivateCollection=1" ;
	self.location.href = theLink;
}

function GotoAnimeGallery()
{
	theLink = "anime/index.htm" ;
	self.location.href = theLink;
}
function SaveInDB()
{
	var clean_title,re;
	re = /"/g;
	clean_title = "" + document.forms.graffitiForm.title.value;
	clean_title = clean_title.replace(re, "'");

	theLink = savedHtml + "?title=" + clean_title  + "&" + feedback ;
	self.location.href = theLink;
}


function passData()
{
  	if(!recentlySaved)
  	{
		if(document.forms.graffitiForm.title.value=='')
		{
			alert("Please give your graffiti a title!");
			return;
		}

		recentlySaved = true;
		document.images.menuImg.src = waitImg.src;
  		document.App.requestData();
  		getData();
	}
	else
	{
		//SaveInDB();
		return;
	}
}


function getData()
{
   feedback = document.App.getReply();
   //alert(feedback);
   if(feedback.indexOf('image=') != -1) 
   {
		SaveInDB();
   }		
   else
   {
   		alert("There was an error saving the image!")
	}		
}



/////////////////////////////////////////////////////////////////////////////////////////////////
function write_cookie (name, value, path)
{
	// Build the expiration date string:
	var expiration_date = new Date ();
	expiration_date . setYear (expiration_date . getYear () + 1);
	expiration_date = expiration_date . toGMTString();

	// Build the set-cookie string:
	var cookie_string = escape (name) + "=" + escape (value) + "; expires=" + expiration_date;
	if (path != null)
		cookie_string += "; path=" + path;

	// Create/update the cookie:
	document . cookie = cookie_string;
}

function read_cookie (key, skips)
{
	// Set skips to 0 if parameter was omitted:
	if (skips == null)
		skips = 0;

	// Get cookie string and separate into individual cookie phrases:
	var cookie_string = "" + document . cookie;
	var cookie_array = cookie_string . split ("; ");

	// Scan for desired cookie:
	for (var i = 0; i < cookie_array . length; ++ i)
	{
		var single_cookie = cookie_array [i] . split ("=");
		if (single_cookie . length != 2)
			continue;
		var name  = unescape (single_cookie [0]);
		var value = unescape (single_cookie [1]);

		// Return cookie if found:
		if (key == name && skips -- == 0)
			return value;
	}

	// Cookie was not found:
	return null;
}

/////////////////////////////////////////////////////////////////////////////////////////////////
