 function numbersOnly(el)
   {
   el.value = el.value.replace(/[^0-9]/g, "");
   }

//phone validation
// 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);
}
//end phone validation


function chkvalid()
{
	if(document.contactForm.fname.value == "")
	{
		alert("Please Enter First Name");
		document.contactForm.fname.focus();
		return false;
	}
	if(document.contactForm.lname.value == "")
	{
		alert("Please Enter Last Name");
		document.contactForm.lname.focus();
		return false;
	}
	//phone
	if(document.contactForm.phone1.value == "")
	{
		alert("Please enter first three numbers of your phone number.");
		document.contactForm.phone1.focus();
		return false;
	}
	if(document.contactForm.phone1.value.length != 3)
	{
		alert("Please enter first three numbers of your phone number.");
		document.contactForm.phone1.focus();
		return false;
	}
	if(document.contactForm.phone2.value == "")
	{
		alert("Please enter second set of three numbers of your phone number.");
		document.contactForm.phone2.focus();
		return false;
	}
	if(document.contactForm.phone2.value.length != 3)
	{
		alert("Please enter second set of three numbers of your phone number.");
		document.contactForm.phone2.focus();
		return false;
	}
	if(document.contactForm.phone3.value == "")
	{
		alert("Please enter third set of your phone number.");
		document.contactForm.phone3.focus();
		return false;
	}
	if(document.contactForm.phone3.value.length != 4)
	{
		alert("Please enter third set of your phone number.");
		document.contactForm.phone3.focus();
		return false;
	}
	//end phone
	//wphone
	if(document.contactForm.wphone1.value == "")
	{
		alert("Please enter first three numbers of your work number.");
		document.contactForm.wphone1.focus();
		return false;
	}
	if(document.contactForm.wphone1.value.length != 3)
	{
		alert("Please enter first three numbers of your work phone number.");
		document.contactForm.wphone1.focus();
		return false;
	}
	if(document.contactForm.wphone2.value == "")
	{
		alert("Please enter second set of three numbers of your work phone number.");
		document.contactForm.wphone2.focus();
		return false;
	}
	if(document.contactForm.wphone2.value.length != 3)
	{
		alert("Please enter second set of three numbers of your work phone number.");
		document.contactForm.wphone2.focus();
		return false;
	}
	if(document.contactForm.wphone3.value == "")
	{
		alert("Please enter third set of your work phone number.");
		document.contactForm.wphone3.focus();
		return false;
	}
	if(document.contactForm.wphone3.value.length != 4)
	{
		alert("Please enter third set of your work phone number.");
		document.contactForm.wphone3.focus();
		return false;
	}
	//end phone
	if(document.contactForm.state.value == "")
	{
		alert("Please select your state.");
		document.contactForm.state.focus();
		return false;
	}
	if(document.contactForm.postal_code.value == "")
	{
		alert("Please enter your postal code.");
		document.contactForm.postal_code.focus();
		return false;
	}
	if(document.contactForm.email.value == "")
	{
		alert("Please Enter Your Contact Email");
		document.contactForm.email.focus();
		return false;
	}
		// Start Email Validation
	if(document.contactForm.email.value != "")
	{
		var i;
		var input = document.contactForm.email.value ;
		var lenth = input.length ;
		var ctr=0 ;
	
		if ( ( document.contactForm.email.value.charAt(i) == '!' ) || ( 	document.contactForm.email.value.charAt(i) == '#' ) )
	    {
		  alert("Please enter a proper email address") ;
		  document.contactForm.email.focus();
	      return false;
	    }
		if (input =="")
		{
			alert("Please enter email address") ;
		    document.contactForm.email.focus();
			return false ;
		}
		if(input.length == 40)
		{
			alert("Please enter a proper email address") ;
		    document.contactForm.email.focus();
			return false ;
		}
	
		for ( i=0; i < lenth; i++ )
		{
			var oneChar = input.charAt(i) ;
			if(oneChar == "@")
			{
				ctr = ctr+1 ;
			}
			if ( (i == 0 && oneChar == "@") || (i == 0 && oneChar == ".") || 
				( oneChar == " " ) )
			{
				alert ( "This does not seem to be a proper email address" ) ;
		        document.contactForm.email.focus();
				return false ;
			}
			if ( (oneChar == "@" && input.charAt(i+1) == ".") || 
				(oneChar == "." && input.charAt(i+1) == "@") ||
				(oneChar == "." && input.charAt(i+1) == ".") )
			{
				alert ( "This does not seem to be a proper email address" ) ;
		        document.contactForm.email.focus();
				return false ;
			}
			if( input.indexOf("@") < 2 )
			{
				alert ( "This does not seem to be a proper email address" ) ;
		        document.contactForm.email.focus();
				return false ;
			}
			if(input.indexOf(".")<1)
			{
				alert ( "This does not seem to be a proper email address" ) ;
		        document.contactForm.email.focus();
				return false ;
			}
			if (ctr > 1)
			{
				alert ( "This does not seem to be a proper email address" ) ;
		        document.contactForm.email.focus();
				return false ;
			}
		}
	}	
	// End Email Validation Script
	
	
	if(document.contactForm.best_time.value == "")
	{
		alert("Please select the best time for us to contact you.");
		document.contactForm.best_time.focus();
		return false;
	}
	if(document.contactForm.unsecure_debt.value == "")
	{
		alert("Please select the closest number to describe your unsecure debt.");
		document.contactForm.unsecure_debt.focus();
		return false;
	}	
	if(document.contactForm.payment_status.value == "")
	{
		alert("Please select your payment status.");
		document.contactForm.payment_status.focus();
		return false;
	}	
	
	document.getElementById('continue_p1').disabled=true; 
	
}