// JavaScript Document
var read_off = new Image(84,28);
read_off.src = 'images/newsBytes_readMoreButton0.gif';
var read_on = new Image(84,28);
read_on.src = 'images/newsBytes_readMoreButton1.gif';


function SwapImage(objectname,objectnewstate) {
	var imageobj = document.getElementById(objectname);
	//alert(typeof(imageobj.isSelected));
	if (typeof(imageobj.isSelected) == "undefined" || !imageobj.isSelected) {
		imageobj.src = this[objectname+"_"+objectnewstate].src;
	}
}


function verifyForm() {
	var theForm = document.getElementById("EnquiryForm");
	var requiredMessage = "";
	var validateMessage = "";
	var fullMessage = "";
	
	if (theForm.name.value == "") {
		requiredMessage += "* Name.\n";
	}
	if (theForm.phone_number.value == "") {
		requiredMessage += "* Phone.\n";
		theForm.phone_number.focus();
	}
	if (theForm.email.value == "") {
		requiredMessage += "* Email.\n";
		theForm.email.focus();
	} else if (!isValidEmail(theForm.email.value)) {
		validateMessage += "* Email.\n";
		theForm.email.focus();
	}
	//if (theForm.zipcode.value == "") {
	//	requiredMessage += "* Zipcode.\n";
	//}
	//if (theForm.country_state.value == "") {
	//	requiredMessage += "* Country State.\n";
	//}
	if (requiredMessage != "") {
		fullMessage += "These fields are required:\n"+requiredMessage;
	}
	if (validateMessage != "") {
		fullMessage += "This field have invalid values:\n"+validateMessage;
	}
	
	if (fullMessage != "") {
		alert(fullMessage);
	} else {
		theForm.submit();
	}
}

function isValidEmail(strEmail){
	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	// search email text for regular exp matches
	if (strEmail.search(validRegExp) == -1) {
		return false;
	} 
	return true; 
}

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   //alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   //alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		//alert("Invalid E-mail ID")
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		//alert("Invalid E-mail ID")
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		//alert("Invalid E-mail ID")
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		//alert("Invalid E-mail ID")
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		//alert("Invalid E-mail ID")
		return false
	 }

	 return true					
}

// function parameters are: field - the string field, count - the field for remaining characters number and max - the maximum number of characters 
function CountLeft(field, count, max) {
// if the length of the string in the input field is greater than the max value, trim it 
if (field.value.length > max)
field.value = field.value.substring(0, max);
else
// calculate the remaining characters 
count.value = max - field.value.length;
}

function includeFlash(areaid,fileName,fWidth,fHeight,bgcolour) {
	//alert(areaid+"::"+fileName+"::"+fWidth+"::"+fHeight+"::"+bgcolour);
	var flashArea = { movie:fileName, width:fWidth, height:fHeight, majorversion:"7", build:"0", xi:"true", bgcolor:bgcolour };
	UFO.create(flashArea,areaid);
}