function addStyle(){
	alert("addStyle");
	document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/styles/styles.css\" title=\"jonasCSS\">");
}

function checkStyle(){
	alert("style:" + HTMLLinkElement.getAttribute("rel").indexOf("style"));
}

function imgSwap(state, section){
	OBJ = "item_" + section;
	img = document.getElementById(OBJ);

	img_src	= state == 1 ? "images/menu/" + OBJ + "_over.jpg" : "images/menu/" + OBJ + ".jpg";

	img.src	= img_src;	
}

var hide  = true;

function showhide(OBJ, TEXT)
{
	var x = new getObj('HelpBubble');

	if(document.getElementById('HelpText').innerHTML != TEXT && document.getElementById('HelpText').innerHTML != "" && x.style.visibility != "hidden"){
		var x = new getObj('HelpBubble');		
		x.style.visibility = 'hidden';
		hide = !hide;
	}

	hide = !hide;
	x.style.visibility = (hide) ? 'hidden' : 'visible';
	setLyr(OBJ,'HelpBubble');

	var x = new getObj('HelpText');
	document.getElementById('HelpText').innerHTML = TEXT;
}

function setLyr(OBJ,lyr)
{
	var newX = findPosX(OBJ);
	var newY = findPosY(OBJ);
	if (lyr == 'HelpBubble') newY -= 20;
	if (lyr == 'HelpBubble') newX += 20;
	var x = new getObj(lyr);
	x.style.top = newY + 'px';
	x.style.left = newX + 'px';
}

function findPosX(OBJ)
{
	var curleft = 0;
	if (OBJ.offsetParent)
	{
		while (OBJ.offsetParent)
		{
			curleft += OBJ.offsetLeft
			OBJ = OBJ.offsetParent;
		}
	}
	else if (OBJ.x)
		curleft += OBJ.x;
	return curleft;
}

function findPosY(OBJ)
{
	var curtop = 0;
	var printstring = '';
	if (OBJ.offsetParent)
	{
		while (OBJ.offsetParent)
		{
			printstring += ' element ' + OBJ.tagName + ' has ' + OBJ.offsetTop;
			curtop += OBJ.offsetTop
			OBJ = OBJ.offsetParent;
		}
	}
	else if (OBJ.y)
		curtop += OBJ.y;
	//window.status = printstring;
	return curtop;
}


function getObj(name)
{
 if (document.getElementById)
 {
	   this.OBJ = document.getElementById(name);
	   this.style = document.getElementById(name).style;
 }
 else if (document.all)
 {
	   this.OBJ = document.all[name];
	   this.style = document.all[name].style;
 }
 else if (document.layers)
 {
	   if (document.layers[name])
	   {
	   	this.OBJ = document.layers[name];
	   	this.style = document.layers[name];
	   }
	   else
	   {
	    this.OBJ = document.layers.HelpBubble.layers[name];
	    this.style = document.layers.HelpBubble.layers[name];
	   }
 }
}

//--------------------------------------------------------------------------------

function setFormCheck(formFields, formFieldsNames, formName){
	var formFields		= formFields;
	var formFieldsNames	= formFieldsNames;
	var formName		= formName;
}

function submitForm(name){
	if (document.getElementById){
		OBJ = document.getElementById(name).submit();
	}
	else if (document.all){
		OBJ = document.all[name].submit();
	}
	else if (document.layers){
		if (document.layers[name]){
			OBJ = document.layers[name].submit();
		}
	}
}

function getValue(name){
	if (document.getElementById){
		objValue = document.getElementById(name).value;
	}
	else if (document.all){
		objValue = document.all[name].value;
	}
	else if (document.layers){
		if (document.layers[name]){
			objValue = document.layers[name].value;
		}
	}
	return(objValue);
}

var isSubmitted = false;

function checkForm() {

	isError	= 0;
	aFields = formFields.split(",");
	aNames = formFieldsNames.split(",");

	error = "The following fields require your input\n----------------------------------------------";
	count = aFields.length;
	for(n = 0; n < count; n++){
		OBJ		= aFields[n];
		objValue	= "";
		objValue	= getValue(OBJ);
		//alert(aFields[n] + ":" + objValue)
		if(objValue.length == 0 || objValue == "none" || objValue == null || objValue == "null" ){
			isError = 1;
			error += "\n" + aNames[n];
		}
		if(aFields[n] == "Email" || aFields[n] == "email" || aFields[n] == "_email"){
			if(objValue.length > 0){
				isEmail = checkEmail(objValue);
				if(isEmail != "OK"){
					isError = 1;
					error += "\n" + isEmail;
				}
			}
		}

	}

	if(isError == 1){
		alert(error);
	}
	else{
		if (isSubmitted != false){
			alert("The Form Is Already Submitted and Processing, Thank You");
			return;
		}
		isSubmitted =true;
		submitForm(formName);
	}
}


//--------------------------------------------------------------------------------
//	email validation
//--------------------------------------------------------------------------------

function checkEmail(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){return "Invalid E-mail ID";}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){return "Invalid E-mail ID";}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){return "Invalid E-mail ID";}
	if (str.indexOf(at,(lat+1))!=-1){return "Invalid E-mail ID";}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){return "Invalid E-mail ID";}
	if (str.indexOf(dot,(lat+2))==-1){return "Invalid E-mail ID";}
	if (str.indexOf(" ")!=-1){return "Invalid E-mail ID";}
	return "OK";
}