focusInterval = 10000;
timerId = null;
function SetFocus(theObject)
{
	if(theObject == null)
		theObject = document.forms.theForm.nickname;
	try
	{
		parent.focus();
	}
	catch(e)
	{
		self.focus();
	}	
	theObject.focus();
	if(timerId != null)
		clearTimeout(timerId);
	timerId = setTimeout("SetFocus()",focusInterval);
}




function Registration(theLink, targetWindow)
{
	if(theLink == null || theLink == '')
		theLink = "";
	if(targetWindow == null || targetWindow == '')
		targetWindow = "opener";
	premiumRegistrationWinHandler = window.open('http://www.girlsense.com/premium/login/registration.pl?targetWindow=' + targetWindow + '&target=' + theLink,'premiumActivityWinPremiumRegistration','scrollbars=yes,resizable=yes,status=yes,left=10,top=10,width=423,height=582');
}

function RegistrationNow()
{
	if(document.forms.theForm.nickname.value == "")
		{ alert("You didn't pick a NetName."); return; }
	if(document.forms.theForm.password.value == "")
		{ alert("You didn't pick a password."); return; }
	if(document.forms.theForm.password.value != document.forms.theForm.repassword.value)
		{ alert("You didn't re-type the same password."); return; }
	if(document.forms.theForm.age.value == "")
		{ alert("You didn't tell us your age."); return; }
	theAge = parseInt(document.forms.theForm.age.value)
	if(!theAge || theAge<1 || theAge>=100)
		{ alert("Invalid age."); return; }
	
	document.forms.theForm.submit();
}

var recentlyRegister = false;
function RegistrationNow_long()
{
	
	if (recentlyRegister)
		return;
	
	recentlyRegister = true;
	if(document.forms.theForm.nickname.value == "")
		{ alert("You didn't pick a NetName."); recentlyRegister = false; return; }
	if(document.forms.theForm.password.value == "")
		{ alert("You didn't pick a password."); recentlyRegister = false; return; }
	if(document.forms.theForm.password.value != document.forms.theForm.repassword.value)
		{ alert("You didn't re-type the same password."); recentlyRegister = false; return; }
	if(document.forms.theForm.age.value == "")
		{ alert("You didn't tell us your age."); recentlyRegister = false; return; }
	var theAge = document.forms.theForm.age.value;
	theAge = parseInt(theAge);
	if(!theAge || theAge<1 || theAge>=100)
		{ alert("Invalid age."); recentlyRegister = false; return; }
	parentsEmail = document.forms.theForm.newsletter.value;
	if(parentsEmail!="" && !emailQuickCheck(parentsEmail))
	{
		alert("Please enter a correct e-mail address. AOL users: please type in your ENTIRE e-mail address, including @aol.com !");
		recentlyRegister = false;
		return;
	}
	
	/*
	BlackFilterAjax.onResult = function(text, responseText)
	{
		if (responseText !== "OK")
		{
			blackFilterAlert(responseText);
			recentlyRegister = false;
			return;	
		}
		else
		{
			Registration_Go();
		}
	}
	
	/// checking ///
	BlackFilterAjax.check(document.forms.theForm.nickname.value);
	*/
	
	Registration_Go();
	
}

function Registration_Go()
{
	document.forms.theForm.submit();
}

function RegistrationNow_short()
{
	if (recentlyRegister)
		return;
	
	recentlyRegister = true;
	
	if(document.forms.theForm.nickname.value == "")
		{ alert("You didn't pick a NetName."); return; }
	if(document.forms.theForm.password.value == "")
		{ alert("You didn't pick a password."); return; }
		
	parentsEmail = document.forms.theForm.newsletter.value;
	if(parentsEmail!="" && !emailQuickCheck(parentsEmail))
	{
		alert("Please enter a correct e-mail address. AOL users: please type in your ENTIRE e-mail address, including @aol.com !")
		return;
	}
	
	BlackFilterAjax.onResult = function(text, responseText)
	{
		if (responseText !== "OK")
		{
			blackFilterAlert(responseText);
			recentlyRegister = false;
			return;	
		}
		else
		{
			Registration_Go();
		}
	}
	
	/// checking ///
	BlackFilterAjax.check(document.forms.theForm.nickname.value,'registration');
}

function ShowMessage(theMode)
{	
	visibility = (theMode ? 'visible' : 'hidden');
	document.getElementById('messageDiv').style.visibility = visibility;
}

function GenerateMessage(theMessage)
{	
	message = (theMessage != null ? theMessage : message);
	try{
	messageHTML = "" + message + "<br><br><center><a href='javascript:ShowMessage(false)'><font color=black>[close]</font></a></center>";
	document.getElementById('messageDiv').innerHTML = messageHTML;
	ShowMessage(true)
	}
	catch(e)
	{
		alert(message)		
	}
}


function WhyEmail()
{
	message = "Complete this optional field to receive GirlSense newsletters.";
	GenerateMessage();
}

function WhyCredit()
{
	message = "In compliance with the Children's Online Privacy Protection Act (COPPA), we ask for your credit card to verify that we are collecting personal information from an adult, and not from a child. Since a valid credit card serves as legal online verification, we will authorize your card validity. You will NOT be charged during the free trial period.";
	GenerateMessage();
}

function Login(theLink, targetWindow)
{
	if(theLink == null || theLink == '')
		theLink = "";
	if(targetWindow == null || targetWindow == '')
		targetWindow = "opener";
		
	self.location.href = 'login.pl?targetWindow=' + targetWindow + '&target=' + theLink;
}

function LoginNow()
{
	nickname = document.forms.theForm.nickname.value;
	password = document.forms.theForm.password.value;
	if(nickname=="" || password=="")
	{
		alert("Please complete the form");
		return;
	}
	document.forms.theForm.submit();
}


function Why(param)
{
    window.open('why.htm#'+param,'whyWin','scrollbars=yes,toolbar=yes,resizable,left=10,top=10,width=791,height=495');
}

function NoteForParents()
{
    window.open('notesToParents.htm','noteForParentsWin','scrollbars=yes,toolbar=yes,resizable,left=10,top=10,width=791,height=495');
}

function SendToFriends()
{
    window.open('mailto:friend@mail','sendToFriendsWin','scrollbars=yes,toolbar=yes,resizable,left=10,top=10,width=640,height=480');
}

function Privacy()
{
    window.open('privacy.htm','privacyWin','scrollbars=yes,toolbar=yes,resizable,left=10,top=10,width=640,height=480');
}

function NetnameReminder()
{
    window.open('netnameReminder.pl','netnameReminderWin','scrollbars=yes,toolbar=yes,resizable,left=10,top=10,width=640,height=480');
}
function PasswordReminder()
{
    window.open('passwordReminder.pl','passwordReminderWin','scrollbars=yes,toolbar=yes,resizable,left=10,top=10,width=403,height=273');
}

///////////////////////////////////////////////////////////////////////////////////////////////

function LogOut()
{
	Logout()
}
function Logout()
{
	self.location.href = "logOut.pl";
}

function LogoutNow()
{
	//delete_all_cookies("/");
	
	//New procedure - made by Omer 21/8/07
	var CookieArr = document.cookie.split(';');
	for (var i=0;i<CookieArr.length;i++)
	{
		var cookieSp = CookieArr[i].split('=');
		document.cookie=cookieSp[0]+"=; expires=Mon, 19-Aug-1996 00:00:01 GMT; path=/";
	}
	//////////////////////////////////
	
	
	
	//alert(document.cookie)
	
	try
	{
		opener.RefreshPersonalization();
	}
	catch(e){}
	/*
	try
	{
		document.getElementById("logOutDiv").innerHTML = "<center><br><br><font color=#363636>Thanks for playing on <font color=#363636>GirlSense.</font><br>Hope to see you again soon!<br><br><a href='javascript:self.close();'></font><font color=#363636>OK</font></a></center>";
	}
	catch(e){}
	*/
	self.close();		

}	

///////////////////////////////////////////////////////////////////////////////////////////////

function DeleteNow()
{
	nickname = document.forms.theForm.nickname.value;
	password = document.forms.theForm.password.value;
	if(nickname=="" || password=="")
	{
		alert("Please complete the form");
		return;
	}
	document.forms.theForm.submit();
}

///////////////////////////////////////////////////////////////////////////////////////////////

function UpdateUserInfo()
{
	//target = (target!=null ? target : "");
	//self.location.href = "update.pl?target=" + target;
	self.location.href = "update.pl";
}


function UpdateUserInfoNow()
{
	if(document.forms.theForm.password.value == "")
		{ alert("You didn't pick a password."); return; }
	if(document.forms.theForm.password.value != document.forms.theForm.repassword.value)
		{ alert("You didn't re-type the same password."); return; }
	if(document.forms.theForm.age.value == "")
		{ alert("You didn't tell us your age."); return; }
	theAge = parseInt(document.forms.theForm.age.value)
	if(!theAge || theAge<1 || theAge>=100)
		{ alert("Invalid age."); return; }

	yourEmail = document.forms.theForm.newsletter.value;
	if(yourEmail!="" && !emailQuickCheck(yourEmail))
	{
		alert("Please enter a correct e-mail address. AOL users: please type in your ENTIRE e-mail address, including @aol.com !")
		return;
	}
	parentsEmail = document.forms.theForm.newsletter2.value;
	if(parentsEmail!="" && !emailQuickCheck(parentsEmail))
	{
		alert("Please enter a correct e-mail address. AOL users: please type in your ENTIRE e-mail address, including @aol.com !")
		return;
	}
	
	document.forms.theForm.submit();
}

function ChangeUserInfo()
{
	self.location.href = "updateuser.pl?target=" + target;
}

function ChangeUserInfoNow()
{
	if(document.forms.theForm.nickname.value == "")
		{ alert("You didn't pick a NetName."); return; }
	if(document.forms.theForm.password.value == "")
		{ alert("You didn't pick a password."); return; }
	if(document.forms.theForm.age.value == "")
		{ alert("You didn't tell us your age."); return; }
	if(document.forms.theForm.gender[0].checked == false && document.forms.theForm.gender[1].checked == false)
		{ alert("Are you a boy or a girl?"); return; }
	
	document.forms.theForm.submit();
}

function NoThanks()
{
	self.location.href = "noThanks.pl?target=" + target;
}



function chgurl(theurl)
{
	theurl = "http://www.girlsense.com" + theurl
	parent.mainfr.location = theurl;
}

function LinktoAct()
{
	var actlink =  document.forms.acts.selact.options[document.forms.acts.selact.selectedIndex].value;
	chgurl(actlink);
}

function emailQuickCheck (emailStr) 
{
    var emailPat=/^[\w-_\&.]+\@[\w-_]+\.+[\w-_.]+$/
	var matchArray=emailStr.match(emailPat)
	if ( (matchArray==null) || (emailStr.indexOf('..') != -1) )
	{
		return false;
	}
	else
	{
		return true;
	}
}

function CookiesAlertCheck() 
{
	cookiesAlertCheck = '';
	try{
		write_cookie('cookiesAlertCheck','cookiesAlertCheck','/');
		cookiesAlertCheck = ( read_cookie('cookiesAlertCheck')!=null ?  read_cookie('cookiesAlertCheck') : '' );
		delete_cookie ('cookiesAlertCheck', '/');
	}
	catch(e){}
	
	if(cookiesAlertCheck == '')
	{
    	window.open('cookiesAlert.htm','cookiesAlertWin','scrollbars=auto,toolbar=no,resizable,left=10,top=10,width=640,height=400');
    	focusInterval = 1000000;
    }	
}

/******************************************************************************/
	  warnCapsLockAlert = false;
      function warnCapsLock(display)
      {
        //document.getElementById('warning').style.display = display ? 'block' : 'none';
        if(!warnCapsLockAlert && display)
        {
        	alert("Warning: You have CAPS LOCK enabled on your keyboard.  That may cause your password to be incorrectly entered as the system is case sensitive.");
        	warnCapsLockAlert = true;
        }	
      }
      
      function ucasePressed(Event)
      {
	     //alert("ucasePressed")
        if (window.event) Event = window.event;
        
        // this is good for IE and Safari
        if (Event.keyCode) 
        {
	      //alert(Event.keyCode)  
          // if the character is UPPER CASE
          if (Event.keyCode <= 90 && Event.keyCode >= 65) return !Event.shiftKey;
          // if the character is lower case
          if (Event.keyCode <= 122 && Event.keyCode >= 97) return Event.shiftKey;
        }
        
        // other browers that support DOM Level 2 have no way of checking.
        return false;
      }

function OnEnterSubmit(e,myfield)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13)
	{
	   myfield.form.submit();
	   return false;
	}
	else
	   return true;
}

function OnEnter(e,theFunction)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13)
	{
	   eval(theFunction + "()");
	   return false;
	}
	else
	   return true;
}
      
/******************************************************************************
cookies.js, developed by Charlton D. Rose for Inquiry.Com

Permission is granted to modify and use this source code, free of charge, provided that this header remains with the code, unmodified.
******************************************************************************/

/******************************************************************************
function write_cookie (name, value);
function write_cookie (name, value, path);

write_cookie creates a cookie with the name, value, and path given in the parameters.  If no path is supplied, write_cookie uses the document's default cookie path.  Each cookie is set with an expiration time of 1 year. ******************************************************************************/

function write_cookie (name, value, path)
{
	// Build the expiration date string:
	var expiration_date = new Date ();
	expiration_date . setYear (expiration_date . getFullYear () + 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)
function read_cookie (key, skips)

read_cookie searches through the current document's cookie string (i.e., the concatenation of all cookies readable by the current document) for a cookie whose name is identical to key.  If read_cookie finds a matching cookie, it returns a string containing the value of cookie.  If read_cookie cannot find a match, it returns null instead.

An optional skips parameter may be supplied if there is a need to select among multiple cookies with the same name.  If a skips parameter is supplied, read_cookie will skip that many occurrences of matching cookies and then return the next one it finds, or null if there aren't any more.
******************************************************************************/

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;
}

/******************************************************************************
delete_cookie (name)
delete_cookie (name, path)

delete_cookie deletes the cookie with the specified name and path.  If no path is given, the default cookie path for the current document is used instead.  If the name and path do not match an existing cookie, delete_cookie has no effect.
******************************************************************************/

function delete_cookie (name, path)
{
	// Build expiration date string:
	var expiration_date = new Date ();
	expiration_date . setYear (expiration_date . getYear () - 1);
	expiration_date = expiration_date . toGMTString();

	// Build set-cookie string:
	var cookie_string = escape (name) + "=; expires=" + expiration_date;
	if (path != null)
		cookie_string += "; path=" + path;

	// Delete the cookie:
	document . cookie = cookie_string;
}

/******************************************************************************
delete_all_cookies ()
delete_all_cookies (path)

delete_all_cookies deletes all cookies matching the specified path.  If no path is supplied, the document's default cookie path is used.
******************************************************************************/

function delete_all_cookies (path)
{
	// Get cookie string and separate into individual cookie phrases:
	var cookie_string = "" + document . cookie;
	var cookie_array = cookie_string . split ("; ");

	// Try to delete each 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]);
		delete_cookie (name, path);
	}
}

///////////////////////////////////////////////////////////////////////////////////
function ResizeToInner(innerWidth, innerHeight)
{
	var frameWidth,frameHeight;
	if (self.innerHeight) // all except Explorer
	{
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
	{
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}

	var innerWidth = ( innerWidth!=null ? innerWidth : frameWidth );
	var innerHeight = ( innerHeight!=null ? innerHeight : frameHeight );

	difWidth = 0 + innerWidth - frameWidth;
	difHeight = 0 + innerHeight - frameHeight;

	if (difWidth != 0 )
	{
		parent.window.resizeBy(difWidth,0);
	}
	if (difHeight != 0)
	{
		parent.window.resizeBy(0,difHeight);
	}
}


function openHP()
//Opens HP when clicking on the girlsense icon
{
	//if (opener)
	if (window.opener && window.opener.open && !window.opener.closed)
	{
		window.opener.location.href= 'http://www.girlsense.com';
	}	
	else
	{
		top.location.href= 'http://www.girlsense.com';
	}
	
}
