// JavaScript Document
//Gets the browser specific XmlHttpRequest Object


function PopUp(ref)
{	
	var strFeatures="toolbar=no,status=no,menubar=no,location=no"
	strFeatures=strFeatures+",scrollbars=yes,resizable=yes,height=560,width=400"
	
	newWin = window.open(ref,"TellObj",strFeatures);

       newWin.opener = top;
}

function goImgWin(myImage,myWidth,myHeight, origLeft,origTop) {

	TheImgWin = window.open(myImage,'image','height=' +
	myHeight + ',width=' + myWidth +
	',toolbar=no,directories=no,status=no,' +
	'menubar=no,scrollbars=no,resizable=no');
	TheImgWin.resizeTo(myWidth+2,myHeight+30);
	TheImgWin.moveTo(origLeft,origTop);
	TheImgWin.focus();
}

		  // JavaScript Document
/////////////////////////////////////////////////////////////////////////////////////////
// Checks whether a string is a valid email address.
/////////////////////////////////////////////////////////////////////////////////////////

function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');     

   if (fld.value == "") {
        error = "You didn't enter a phone number.\n";
        fld.style.background = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
        //fld.style.background = 'Yellow';
    } 
	//else if (!(stripped.length == 10)) {
    //   error = "The phone number is the wrong length. Make sure you included an area code.\n";
    //    fld.style.background = 'Yellow';
    //} 
    return error;
}
function formValidate(){
			if(document.form1.user.value==""){
				alert("Please enter username");
				this.document.form1.user.focus();
				return false;
			}
				else if(document.form1.pass.value==""){
					alert("Please enter password");
					this.document.form1.pass.focus();
					return false;
					}
			else{
			return true;
			}
}
function checkEmail(emailString) {
	splitVal = emailString.split('@');
	if(splitVal.length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	if(splitVal[0].length <= 0 || splitVal[1].length <= 0) {
		alert("Please enter a valid email address");
		return false;
	}
	
	splitDomain = splitVal[1].split('.');
	if(splitDomain.length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	if(splitDomain[0].length <= 0 || splitDomain[1].length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	return true;
}
function checkEnquiry()
{
	name = trimSpaces(document.submitFrm.name.value);
		if(name.length<=0){
		alert("Enter your name");
		document.submitFrm.name.focus();
		return false;
	}
	email = trimSpaces(document.submitFrm.email.value);
	if(email.length<=0){
		alert("Enter the email address");
		document.submitFrm.email.focus();
		return false;
			
	}
	else if(! checkEmail(email)){
		document.submitFrm.email.focus();
		return false;
	}	
	
//	address = trimSpaces(document.submitFrm.address.value);	
//	if(address.length<=0){
	//	alert("Enter your Address");
	//	document.submitFrm.address.focus();
	//	return false;
			
//	}
	
/*	city = trimSpaces(document.submitFrm.city.value);
	if(city.length<=0){
		alert("Enter City name");
		document.submitFrm.city.focus();
		return false;
			
	}
	
	state = trimSpaces(document.submitFrm.state.value);
	if(state.length<=0){
		alert("Enter your State");
		document.submitFrm.state.focus();
		return false;
			
	}
	
	country = trimSpaces(document.submitFrm.country.value);
	if(country.length<=0){
		alert("Enter your Country");
		document.submitFrm.country.focus();
		return false;
			
	}
*/	
	comments = trimSpaces(document.submitFrm.comments.value);
	if(comments.length<=0){
		alert("Enter your comments");
		document.submitFrm.comments.focus();
		return false;
			
	}
	var response = "";

	 //response += validatePhone(document.submitFrm.phone);
		response += checkEmail(document.submitFrm.email);
		//response += validateEmpty(document.submitFrm.address);
		//response += validateEmpty(document.submitFrm.comments);
		//response += validateEmpty(document.submitFrm.city);
		
	  if (response != "") {
				alert("Some fields need correction:\n" + response);
				return false;
			}
	document.submitFrm.frmAction.value="yes";	
	return true;	
}
/////////////////////////////////////////////////////////////////////////////////////////
// Removes the leading and trailing spaces in a strings and returns the trimmed string
/////////////////////////////////////////////////////////////////////////////////////////
function trimSpaces(stringValue) {
	// Checks the first occurance of spaces and removes them
	for(i = 0; i < stringValue.length; i++) {
		if(stringValue.charAt(i) != " ") {
			break;
		}
	}
	if(i > 0) {
		stringValue = stringValue.substring(i);
	}
	
	// Checks the last occurance of spaces and removes them
	strLength = stringValue.length - 1;
	for(i = strLength; i >= 0; i--) {
		if(stringValue.charAt(i) != " ") {
			break;
		}
	}
	if(i < strLength) {
		stringValue = stringValue.substring(0, i + 1);
	}
	// Returns the string after removing leading and trailing spaces.
	return stringValue;
}
