function clearBox(box) 
{
	if(box.value==box.defaultValue) 
   {
		box.value = "";
   }
}

function validate_fullname(str)
{
	var i;
	var s=khuramtrim(str);
    for (i = 0; i < s.length-1; i++)
    {   
		
        // Check that current character is number.
        var c = s.charAt(i);
        if (c==" ") return true;
    }
    // All characters are numbers.
    return false;
}
function khuramtrim(str) { 
    if (str != null) {
        var i; 
        for (i=0; i<str.length; i++) {
            if (str.charAt(i)!=" ") {
                str=str.substring(i,str.length); 
                break;
            } 
        } 
    
        for (i=str.length-1; i>=0; i--) {
            if (str.charAt(i)!=" ") {
                str=str.substring(0,i+1); 
                break;
            } 
        } 
        
        if (str.charAt(0)==" ") {
            return ""; 
        } else {
            return str; 
        }
    }
}
function validate_required(field,alerttxt)
{
	with (field)
	{
	if(value==null||value=="")
		  {
			  alert(alerttxt);return false
		  }
	else if(validate_fullname(value)==false)
		{
			alert("Full Name must contain first name and last name seperated with space" + "|" );
			value=khuramtrim(value)+ " ";
			focus();
			return false;
		}
		else 
		  {
			  return true
		  }
	}
}

function validate_form(contact_form)
{
	with (contact_form)
	{
		if (validate_required(Name, "Name must be filled out!")==false)
		  {Name.focus();return false}
		if (validate_phone(Phone, "Not a valid Phone Number!")==false)
		  {Phone.focus();return false}
		if (validate_Email(Email, "Not a valid e-mail address!")==false)
		  {Email.focus();return false}
	}
}
function validate_Email(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@")
dotpos=value.lastIndexOf(".")
if (apos<1||dotpos-apos<2) 
  {alert(alerttxt);return false}
else {return true}
}
}


// 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 = 10;

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 >= 10);
}
function validate_phone(field, alerttxt) 
{
with (field)
{
	if ((value==null)||(value=="")){
		alert("Please Enter your Phone Number")
		focus()
		return false
	}
	if (checkInternationalPhone(value)==false){
		alert("Please Enter a Valid Phone Number")
		value=""
		focus()
		return false
	}
	return true
}
}