/**
	func submitOrder - HINT: See html form for global variables
	inp - formName: Form name="namefrm"
	global array - aRequiredFields: Array of input fields to validate
	global string - sErrorTxt: Global string
	global string - sMailErr: Global string

**/
function submitOrder(formName)
{
	var i = 0;
	var bError = false;
	var sError = sErrorTxt + "\n";
	if(aRequiredFields.length > 0)
	{
		while(e = document[formName][i++])
		{
			if(e.nodeName.toLowerCase() == "input")
			{
				for(var j=0; j<=(aRequiredFields.length-1); j++)
				{
					if(e.name.toLowerCase() == aRequiredFields[j].toLowerCase() && e.value == "")
					{
						bError = true;
						sError += "- "+ e.title + "\n";
					}
				}
				/*
				if(e.type.toLowerCase() == "checkbox")
				{
					if(!document[formName][e.name].checked) { bErrorChk = true; }
				}
				*/
				if(e.name.toLowerCase() == "email" && e.value != "")
				{
					if(checkMyEmail(e.value.toLowerCase()) == false)
					{
						if(bError == false) { bError = true; }
						sError += "- "+ e.title + " = "+ sMailErr +"\n";
					}
				}
			}
		}
		/*
		if(bError == true && bErrorChk == true)
		{
			alert(sError +"\n"+ sErrorChkTxt)
			bError = false; bErrorChk = false;
		}
		else if(bError == true)
		{
			alert(sError +"\n")
			bErrorChk = false;
		}
		else if(bErrorChk == true)
			alert(sErrorChkTxt +"\n")
		*/
		if(bError == true)
			alert(sError +"\n")
		else
			document[formName].submit();
	}
}

function checkMyEmail(parEmail){
	var str = parEmail;
	var filter = /^[\w-]+(?:\.[\w-]+)*@[\w]+(?:\.[\w-]+)*\.(?:(?:[\d]{1,3})|(?:[a-zA-Z]{2,3})|(?:aero|coop|info|museum|name))$/i;
	//var filter = /^[^\s@]+@[^\s@]+\.[a-z]{2,3}$/i;
	if(filter.test(str)){
		return true;
	} else {
		return false;
	}
}
/**
	onclick
	Toogle text in search field functions
	f = object ex. [this]
	txt = input value 
	
**/
function focusField(obj, txt)
{
	// Declare variable
	var field = document.getElementById(obj.id);
	// Clean field, markup if text is not the same as original
	if(field.value == txt)
		field.value = '';
	else
		field.select();
}
/**
	onblur
**/
function blurField(obj, txt)
{
	// Declare variable
	var field = document.getElementById(obj.id);
	// Restore field if not text is original
	if(field.value == '')
		field.value = txt;
}
/**
	onclick
**/
function whichFieldIsFocused(obj)
{
	obj.value = "";
}
/**
	setFocus()
	inp - obj: this
	inp - form: form name
	inp - formObjName: the name on the field to set focus on
**/
function setFocus(obj, form, formObjName)
{
	if(obj.checked == true) { document[form][formObjName].focus(); }
	if(obj.checked == false) { return false; }
}

/**

**/
var j=5; // Count down num.
function redirect(page)
{
	interval = setInterval("redirectAndUpdate('"+page+"')", 1000);
}
function redirectAndUpdate(page)
{
	document.getElementById("timerupdate").innerHTML = j;
	if(j == 1)
		document.location = page;
	j = j-1;
}

function imageResize(obj, sClass, mouseoverout)
{
	var e = obj.getElementsByTagName("img");
	var arr = new Array();
	for(var i=0; i<e.length; i++)
	{
		sImgClass = e[i].className;
		if(mouseoverout == "over")
		{
			if(sImgClass.indexOf(sClass) != -1)
			{
				e[i].style.width = "130px";
				e[i].style.height = "130px";
			}
		}
		if(mouseoverout == "out")
		{
			if(sImgClass.indexOf(sClass) != -1)
			{
				e[i].style.width = "";
				e[i].style.height = "";
			}
		}
	}
}

