/*
 * File: global.js
 *
 * Description: ACP global functions
 */


/* Dojo config */
var djConfig = {isDebug: false, debugAtAllCosts: false };


window.onload = doOnLoad;

var ONLOADFUNC = new Array();

/* Flag whether the page is loaded */
var ISLOADED = false;



/**
 * Global onload handler.  Any onload functions can be added from anywhere via
 * the addOnLoad() function.  Those functions then get called in order by 
 * doOnLoad().
 */
function doOnLoad() {
	for (i in window.ONLOADFUNC) {
		window.eval(window.ONLOADFUNC[i] + "()");
	}
	window.ISLOADED = true;
}

/**
 * Add a function name to the onload queue
 *
 * @var string funcname
 */
function addOnLoad(funcname) {
	if (funcname.length > 0) {
		window.ONLOADFUNC[window.ONLOADFUNC.length] = funcname;
	}
}

/**
 * Pop up a window with a set size.  Simple defaults to ease the pain.
 *
 * @var string url
 * @var int width (default 600)
 * @var int height (default 400)
 */
function popWindow(url) {
	var w = 600;
	var h = 400;
	
	if (arguments.length > 1) {
		w = arguments[1];
	}
	if (arguments.length > 2) {
		h = arguments[2];
	}
	
	window.open(url, '_blank', 'width=' + w + ',height=' + h + ',scrollbars=yes,status=yes,resizable=yes,toolbar=no,location=yes,menubar=no');
}

/**
 * Simplest possible rollover call
 */
function rolloverButton(id, state, classname) {
	if (document.getElementById) {
		var element_id = document.getElementById(id);
		element_id.className = classname;
	}
}

/**
 * Submit a form by ID
 *
 * @var string ID
 */
function submitForm(formId) {
	if (document.getElementById && document.getElementById(formId)) {
		document.getElementById(formId).submit();
	} else {
		window.alert("Sorry, the button's not working on your browser.  You can click in one of the fields and press the \"Enter\" key.");
	}
}

/************************************************************\
*
*		freeCap v1.4.1 Copyright 2005 Howard Yeend
*		www.puremango.co.uk
*
*    This file is part of freeCap.
*
*    freeCap is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    freeCap 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.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with freeCap; if not, write to the Free Software
*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
*
\************************************************************/

function new_freecap() {
	// loads new freeCap image
	if (document.getElementById) {
		// extract image name from image source (i.e. cut off ?randomness)
		thesrc = document.getElementById("freecap").src;
		thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
		// add ?(random) to prevent browser/isp caching
		document.getElementById("freecap").src = thesrc+"?"+Math.round(Math.random()*100000);
	} else {
		alert("Sorry, cannot autoreload freeCap image; submit the form and a new freeCap will be loaded");
	}
}


// Websignia check comments form

function checkcomments() {
	error=false;
	msg="";
	if (document.myform.author.value=="") {
		error=true;
		msg = "\r\n\t-Your name";
	}
	if (document.myform.email.value=="" || document.myform.email.value.indexOf("@",0) == - 1 || document.myform.email.value.indexOf(".",0) == - 1) {
		error=true;
		msg += "\r\n\t-Your email";
	}
	if (document.myform.comment.value=="") {
		error=true;
		msg += "\r\n\t-Your comment";
	}
	if (document.myform.security_code.value=="") {
		error=true;
		msg += "\r\n\t-Security code";
	}
	if (error) {
		alert("Please check:"+msg);
		return false;
	} else {
		return true;
	}
}

function checkemailshare() {
	error=false;
	msg="";
	if (document.myform2.email.value=="" || document.myform2.email.value.indexOf("@",0) == - 1 || document.myform2.email.value.indexOf(".",0) == - 1) {
		error=true;
		msg += "\r\n\t-Your email";
	}
	if (document.myform2.email2.value=="" || document.myform2.email2.value.indexOf("@",0) == - 1 || document.myform2.email2.value.indexOf(".",0) == - 1) {
		error=true;
		msg += "\r\n\t-Your friend's email";
	}
	if (error) {
		alert("Please check:"+msg);
		return false;
	} else {
		alert('Message sent!');
		return true;
	}
}

function checkemailshare2() {
	error=false;
	msg="";
	if (document.myform3.email3.value=="" || document.myform3.email3.value.indexOf("@",0) == - 1 || document.myform3.email3.value.indexOf(".",0) == - 1) {
		error=true;
		msg += "\r\n\t-Your email";
	}
	if (document.myform3.email4.value=="" || document.myform3.email4.value.indexOf("@",0) == - 1 || document.myform3.email4.value.indexOf(".",0) == - 1) {
		error=true;
		msg += "\r\n\t-Your friend's email";
	}
	if (error) {
		alert("Please check:"+msg);
		return false;
	} else {
		alert('Message sent!');
		return true;
	}
}

function checkemailshare3() {
	error=false;
	msg="";
	if (document.myform4.email5.value=="" || document.myform4.email5.value.indexOf("@",0) == - 1 || document.myform4.email5.value.indexOf(".",0) == - 1) {
		error=true;
		msg += "\r\n\t-Your email";
	}
	if (document.myform4.email5.value=="" || document.myform4.email5.value.indexOf("@",0) == - 1 || document.myform4.email5.value.indexOf(".",0) == - 1) {
		error=true;
		msg += "\r\n\t-Your friend's email";
	}
	if (error) {
		alert("Please check:"+msg);
		return false;
	} else {
		alert('Message sent!');
		return true;
	}
}