// JavaScript Document

// JavaScript Document

function addOnload(newFunction) {
	var oldOnload = window.onload;
	
	if (typeof oldOnload == "function") {
		window.onload = function() {
			if (oldOnload) {
				oldOnload();
			}
			newFunction();
		}
	}
	else {
		window.onload = newFunction;
	} 
}

var selected;

addOnload(setCal);

function setCal() {
		if (document.getElementById("from_date")) document.getElementById("from_date").onclick = viewCal;
		if (document.getElementById("from_date")) document.getElementById("from_date").onfocus = viewCal;
		if (document.getElementById("from_date")) document.getElementById("from_date").onchange = hideCal;
		if (document.getElementById("from_date_IMG")) document.getElementById("from_date_IMG").onclick = viewCal;
}

function viewCal() {
	document.getElementById("calGrid").style.display = "block";
	document.getElementById("calGrid").style.top = getY(this) + "px"; //+ document.getElementById("calendar").offsetHeight
	document.getElementById("calGrid").style.left = getX(this) + "px";
	return false;
}

function hideCal() {
	document.getElementById("calGrid").style.display = "none";
	return false;
}

function getY(oElement)
{
var iReturnValue=0;
while (oElement!=null)
{
	iReturnValue+=oElement.offsetTop;
	oElement=oElement.offsetParent;
}
return iReturnValue;
}

function getX(oElement)
{
var iReturnValue=0;
while (oElement!=null)
{
	iReturnValue+=oElement.offsetLeft;
	oElement=oElement.offsetParent;
}
return iReturnValue;
}

//////////// FORM CHECKING

function get_form()
{
msg="Please check the following:\n\n"
for (i=0;i<document.forms[0].elements.length;i++) {
	if (document.forms[0].elements[i].value=="" && document.forms[0].elements[i].id!="wsa") {msg+='"'+document.forms[0].elements[i].name+'" cannot be blank\n'; document.forms[0].elements[i].className="err"}
	if (document.forms[0].elements[i].id!="wsa") {
		s_Scheck=document.forms[0].elements[i].value.toUpperCase()
		if (s_Scheck.indexOf('HTTP')>-1) {msg+='For security reasons the phrase \'http\' is not accepted by field "'+document.forms[0].elements[i].name+'"\n'; document.forms[0].elements[i].className="err";}
	}
	}
	if (echeck()) {msg+='E-mail address is not valid!\n';  document.getElementById('mtc').className="err";}
	if (msg!="Please check the following:\n\n") {alert(msg); return false;} else { return true; }
}

function echeck() {
		var str=document.getElementById('mtc').value
		var at="@"
		var dot="."
		var Cat=str.indexOf(at)
		var Cstr=str.length
		var Cdot=str.indexOf(dot)
		var errmsg="E-mail is not valid!"

		if (Cat==-1 || Cat==0 || Cat==Cstr){
		   return errmsg;}

		if (Cdot==-1 || Cdot==0 || Cdot==Cstr){
		   return errmsg;}

		 if (str.indexOf(at,(Cat+1))!=-1){
		   return errmsg;}

		 if (str.substring(Cat-1,Cat)==dot || str.substring(Cat+1,Cat+2)==dot){
		   return errmsg;}

		 if (str.indexOf(dot,(Cat+2))==-1){
		   return errmsg;}
		
		 if (str.indexOf(" ")!=-1){
		   return errmsg;}	
		  
		 return false;
}
