/**
* functions.js - Comic Archive JavaScript functions
*
* Date Created: 7/07/05
* Last Update: 7/14/05
*
* History
*  7/19/05 (MH): - File creation
*	              - Initial content
*/

/*********************
* 
* Generic Functions
*
*/

/**
* loadImages - Preload images to be used
*/
function loadImages()
{
	//curGame1= new Image()
	//curGame1.src = "../images/curGame1.jpg"
}

/**
* validEmail - Checks valid email address
*
* Arguments
*  - address: The email address
*
* Returns
*  - True if valid
*/
function validEmail(address)
{
	var amp = address.indexOf("@");
	var period = address.indexOf(".");
	var result = true;

	if(amp == -1 || period == -1)
		result = false;

	return result;
}

/**
* validDate - Checks valid dates
* 
* Author: Matt Hartzell
* Last Update: 7/10/05
* 
* Arguments
*  - day: The day
*  - month: The month
*  - year: The year
*
* Returns
*  - True if valid
*/
function validDate(day, month, year)
{
	var result = true;
	
	if(day == 31 && (month == 2 || month == 4 || month == 6 || month == 9 || month == 11))
	{
		result = false;
	}
	
	if((day == 28 || day == 29) && (month != 2))
	{
		result = false;
	}

	return result;
}

/**
* checkAddComment - Check Add comment page
*/
function checkAddComment()
{
	with (document.addCommentForm)
	{
		if(name.value == "")
		{
			alert("Please enter your name!");
			name.focus();
		}
		else if(name.value == "Pmasta" || name.value == "PMasta" || name.value == "pmasta" || name.value == "PMASTA")
		{
			alert("There's only one PMasta, and you're not it!");
			name.focus();
		}
		else if(comment.value == "")
		{
			alert("Please write a comment!");
			comment.focus();
		}
		else
		{			
			submit();
		}
	}
}

/**
* checkAddBlog - Check Add blog page
*/
function checkAddBlog(draft, blogKey)
{
	with (document.createForm) {
	
		if(title.value == "") {
		
			alert("Please enter a title.");
			title.focus();
		}
		
		else {

			action = "../php/scriptDashboard.php?action=Blog&bKey=" + blogKey + "&draft=" + draft;			
			submit();
		}
	}
}

/**
* preview - Goes to preview page
*/
function preview() 
{
	with (document.addBlogForm) {
		action = "../html/admin.php";
		
		submit();
	}
}

/**
* checkEmailSignup - Check email subscription
*/
function checkEmailSignup() 
{
	with(document.subscribeForm)
	{
		if(name.value == "")
		{
			alert("Please enter a name.");
			name.focus();
		}
		else if(email.value == "")
		{
			alert("Please enter an email.");
			email.focus();
		}
		else if(!validEmail(email.value))
		{
			alert("Please enter a valid email.");
			email.focus();
		}
		else
		{
			submit();
		}
	}
}


/***********************************************
* Switch Content script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use. Last updated April 2nd, 2005.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var enablepersist="off" //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="no" //Collapse previously open content when opening present? (yes/no)

var contractsymbol='' //HTML for contract symbol. For image, use: <img src="whatever.gif">
var expandsymbol='' //HTML for expand symbol.


if (document.getElementById){
document.write('<style type="text/css">')
document.write('.switchcontent{display:none;}')
document.write('</style>')
}

function getElementbyClass(rootobj, classname){
var temparray=new Array()
var inc=0
var rootlength=rootobj.length
for (i=0; i<rootlength; i++){
if (rootobj[i].className==classname)
temparray[inc++]=rootobj[i]
}
return temparray
}

function sweeptoggle(ec){
var thestate=(ec=="expand")? "block" : "none"
var inc=0
while (ccollect[inc]){
ccollect[inc].style.display=thestate
inc++
}
revivestatus()
}


function contractcontent(omit){
var inc=0
while (ccollect[inc]){
if (ccollect[inc].id!=omit)
ccollect[inc].style.display="none"
inc++
}
}

function expandcontent(curobj, cid){
var spantags=curobj.getElementsByTagName("SPAN")
var showstateobj=getElementbyClass(spantags, "showstate")
if (ccollect.length>0){
if (collapseprevious=="yes")
contractcontent(cid)
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
if (showstateobj.length>0){ //if "showstate" span exists in header
if (collapseprevious=="no")
showstateobj[0].innerHTML=(document.getElementById(cid).style.display=="block")? contractsymbol : expandsymbol
else
revivestatus()
}
}
}

function revivecontent(){
contractcontent("omitnothing")
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
for (i=0; i<selectedComponents.length-1; i++)
document.getElementById(selectedComponents[i]).style.display="block"
}

function revivestatus(){
var inc=0
while (statecollect[inc]){
if (ccollect[inc].style.display=="block")
statecollect[inc].innerHTML=contractsymbol
else
statecollect[inc].innerHTML=expandsymbol
inc++
}
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function getselectedItem(){
if (get_cookie(window.location.pathname) != ""){
selectedItem=get_cookie(window.location.pathname)
return selectedItem
}
else
return ""
}

function saveswitchstate(){
var inc=0, selectedItem=""
while (ccollect[inc]){
if (ccollect[inc].style.display=="block")
selectedItem+=ccollect[inc].id+"|"
inc++
}

document.cookie=window.location.pathname+"="+selectedItem
}

function do_onload(){
uniqueidn=window.location.pathname+"firsttimeload"
var alltags=document.all? document.all : document.getElementsByTagName("*")
ccollect=getElementbyClass(alltags, "switchcontent")
statecollect=getElementbyClass(alltags, "showstate")
if (enablepersist=="on" && ccollect.length>0){
document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 
firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
if (!firsttimeload)
revivecontent()
}
if (ccollect.length>0 && statecollect.length>0)
revivestatus()
}

if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload

if (enablepersist=="on" && document.getElementById)
window.onunload=saveswitchstate

/***********************************************
* Chromeless Window (v3.5)- By Gabriel Suchowolski (this credit MUST stay intact)
* Author site at http://www.microbians.com
* Visit http://www.dynamicdrive.com for this script
***********************************************/

//For paramater explanations, see accompanying faq.htm file
function openIT(u,W,H,X,Y,n,b,x,m,r) {
	var cU  ='close.gif'   //gif for close on normal state.
	var cO  ='close.gif'  //gif for close on mouseover.
	var cL  ='clock.gif'      //gif for loading indicator.
	var mU  ='minimize.gif'     //gif for minimize to taskbar on normal state.
	var mO  ='minimize.gif'    //gif for minimize to taskbar on mouseover.
	var xU  ='max.gif'     //gif for maximize normal state.
	var xO  ='max.gif'    //gif for maximize on mouseover.
	var rU  ='restore.gif'     //gif for minimize on normal state.
	var rO  ='restore.gif'    //gif for minimize on mouseover.
	var tH  ='<font face=verdana size=2>Chromeless Window</font>'   //title for the title bar in html format.
	var tW  ='Chromeless Window'   //title for the task bar of Windows.
	var wB  ='#D5D5FF'   //Border color.
	var wBs ='#D5D5FF'   //Border color on window drag.
	var wBG ='#D5D5FF'   //Background of the title bar.
	var wBGs='#D5D5FF'   //Background of the title bar on window drag.
	var wNS ='toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0'  //Html parameters for Netscape.
	var fSO ='scrolling=auto noresize'   //Html parameters for main content frame.
	var brd =0;   //Extra border size.
	var max =x||false;   //Maxzimize option (true|false).
	var min =m||false;   //Minimize to taskbar option (true|false).
	var res =r||false;   //Resizable window (true|false).
	var tsz =0;   //Height of title bar.
	return chromeless(u,n,W,H,X,Y,cU,cO,cL,mU,mO,xU,xO,rU,rO,tH,tW,wB,wBs,wBG,wBGs,wNS,fSO,brd,max,min,res,tsz)
}

// Preload images
//window.onload=loadImages
