// Copyrights © 2007, PearlCreation.com. All right reserved.
// The present javascript code is property of PearlCreation.com.
// This code can only be used inside Internet/Intranet web sites located on *web servers*.
// This code *cannot* be used inside distributable implementations (such as demos, applications or CD-based webs).
// Any unauthorized use, reverse-engineering, alteration, transmission, transformation, facsimile, or copying of any means (electronic or not) is strictly prohibited and will be prosecuted.
// ***Removal of the present copyright notice is strictly prohibited***
function stopError()
{
  return true;
}

window.onerror = stopError;
// 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 >= minDigitsInIPhoneNumber);
}

function validateForm()
{
	var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
	var e=document.quick_contact.email.value
	var returnval=emailfilter.test(e)
	if(document.quick_contact.name.value == "" || document.quick_contact.name.value == "Your Name")
	{
		alert("Please fill-up the 'Name' Field.");
		document.quick_contact.name.value = "";
		document.quick_contact.name.focus();
		return false;
	}
	else
	if(document.quick_contact.email.value == "" || document.quick_contact.email.value == "Your E-Mail")
	{
		alert("Please fill-up the 'E-mail' Field.");
		document.quick_contact.email.value = "";
		document.quick_contact.email.focus();
		return false;
	}
	else
	if (returnval==false)
	{
		alert("Please enter a valid E-mail address.")
		document.quick_contact.email.focus()
		return false;
	}
	else
	if(document.quick_contact.phone.value == "" || document.quick_contact.phone.value == "Your Phone")
	{
		alert("Please fill-up the 'Phone' Field.");
		document.quick_contact.phone.focus();
		return false;
	}
	else
	if (checkInternationalPhone(document.quick_contact.phone.value)==false)
	{
		alert("Please Enter a Valid Phone Number")
		document.quick_contact.phone.focus();
		return false;
	}
	else
	if(document.quick_contact.message.value == "" || document.quick_contact.message.value == "Your Message")
	{
		alert("Please fill-up the 'Message' Field.");
		document.quick_contact.message.value = "";
		document.quick_contact.message.focus();
		return false;
	}
	else
	{
		return true;
	}
}

