function doClear(theText) {
     if (theText.value == theText.defaultValue) {
         theText.value = "";
		 theText.className = "textfield";
     }
 }
 function doReload(theText) {
     if (theText.value == "") {
         theText.value = theText.defaultValue
	 	theText.className = "textfield";
    }
 }
function chkempty() {
	
	var flag = 0;
	var errmsg = "Please fill in these mandatory fields"
	
	var fields= new Array()
		fields[0]="name";
		fields[1]="email";
		fields[2]="mobile";
		fields[3]="company";
	//alert(fields);
	var presets= new Array()
		presets[0]="Name";
		presets[1]="Email Address";
		presets[2]="Country Code & Phone Number";
		presets[3]="Company";
	//alert(presets);
		for(i=0;i<fields.length;i++){
			if(document.getElementById(fields[i]).value == presets[i]){
				errmsg = errmsg+"\n"+presets[i];
				//alert(errmsg);
				flag = 1;
			}
		}
	
	if (flag == 1 ){
			alert(errmsg);
			return false;
		}
		else if(validmail(document.getElementById('email').value) === false){ return false; }
		else if(ValidateForm() === false){ return false; }
		else{ return true; }
}

function doSubmit() { 
	document.contactFrm.submit();
}

function validmail(str) {
	var status ='';
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(str))
		status=true
		else{
		alert("Please enter a valid email id!")
		status=false
		}
	return (status)
}

/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 7;

function isInteger(s) {   
	var i;
    for (i = 0; i < s.length; i++) {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag) {
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++) {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone) {
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidateForm() {
	var Phone=document.contactFrm.mobile
	
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please enter a valid Phone Number")
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
}
function chkproduct() {
	
	var flag = 0;
	var errmsg = "Please fill in these mandatory fields"
	
	var fields= new Array()
		fields[0]="pro_name";
		fields[1]="emailid";
		fields[2]="market";

	var presets= new Array()
		presets[0]="Name";
		presets[1]="Email Address";
		presets[2]="Select an Option";
		for(i=0;i<fields.length;i++){
			if(document.getElementById(fields[i]).value == ''){
				
			errmsg = errmsg+"\n"+presets[i];
				flag = 1;
			}
		}
	
	if (flag == 1 ){
			alert(errmsg);
			return false;
		}
		else if(validmail(document.getElementById('emailid').value) === false){ return false; }		
		else{ return true; }
}

function doSubmit() { 
	document.productFrm.submit();
}
