function mail_validate(){
	if(document.frm_mail.FIRST.value == "")
	{
		alert("Enter the first name");
		document.frm_mail.FIRST.focus();
		return false;
	}
	if(document.frm_mail.LAST.value == "")
	{
		alert("Enter the last name");
		document.frm_mail.LAST.focus();
		return false;
	}
	if(!validateEmail(document.frm_mail.EMAIL.value,1,1))
	{
		document.frm_mail.EMAIL.focus();
		return false;
	}
	if(document.frm_mail.ADDRESS.value == "")
	{
		alert("Enter the address");
		document.frm_mail.ADDRESS.focus();
		return false;
	}
	if(document.frm_mail.CITY.value == "")
	{
		alert("Enter the city");
		document.frm_mail.CITY.focus();
		return false;
	}
	if(document.frm_mail.STATE.value == "")
	{
		alert("Enter the state");
		document.frm_mail.STATE.focus();
		return false;
	}
	
	if(document.frm_mail.ZIP.value == "")
	{
		alert("Enter the zipcode");
		document.frm_mail.ZIP.focus();
		return false;
	}
	if(isNaN(document.frm_mail.ZIP.value))
	{
		alert("Enter the zipcode in numeric value");
		document.frm_mail.ZIP.value="";
		document.frm_mail.ZIP.focus();
		return false;
	}
	
	if(document.frm_mail.PHONE1.value == "")
	{
		alert("Enter the phone number");
		document.frm_mail.PHONE1.focus();
		return false;
	}
	phone = document.frm_mail.PHONE1;
	if (checkInternationalPhone(phone.value)==false){
	alert("Please Enter a Valid Phone Number");
	phone.value="";
	phone.focus();
	return false;
	}
	if(document.frm_mail.PHONE1.value != "")
	{
		if(document.frm_mail.PHONE1_LOCATION.value == "")
		{
		alert("Enter the phone number location");
		document.frm_mail.PHONE1_LOCATION.focus();
		return false;
		}
	}
	if(document.frm_mail.TOTAL.value == "")
	{
		alert("Enter the total amount for unsecured debt");
		document.frm_mail.TOTAL.focus();
		return false;
	}
	if(isNaN(document.frm_mail.TOTAL.value))
	{
		alert("Enter the total amount for unsecured debt in numeric value");
		document.frm_mail.TOTAL.value="";
		document.frm_mail.TOTAL.focus();
		return false;
	}
	if(document.frm_mail.CREDITOR1.value == "")
	{
		alert("Enter the creditor name");
		document.frm_mail.CREDITOR1.focus();
		return false;
	}
	if(document.frm_mail.INT1.value == "" )
	{
		
		alert("Enter the interest");
		document.frm_mail.INT1.focus();
		return false;
	}
	
	if(document.frm_mail.MIN1.value == "")
	{
		
		alert("Enter the payment");
		document.frm_mail.MIN1.focus();
		return false;
	}
	if(document.frm_mail.BEHIND1.value == "")
	{
		alert("Enter the behind");
		document.frm_mail.BEHIND1.focus();
		return false;
	}
	if(document.frm_mail.BALANCE1.value == "")
	{
		alert("Enter the balance");
		document.frm_mail.BALANCE1.focus();
		return false;
	}
	if(document.frm_mail.TYPE1.value == "")
	{
		alert("Choose the type");
		document.frm_mail.TYPE1.focus();
		return false;
	}
/*	if(document.frm_mail.CREDITOR2.value != "" || document.frm_mail.INT2.value != "" || document.frm_mail.MIN2.value != "" || document.frm_mail.BEHIND2.value != "" || document.frm_mail.BALANCE2.value != "" || document.frm_mail.TYPE2.value != "")
	{
		alert("Enter the creditor name2 and their corresponding Interest, Payment,Behind ,Balance and Type.");
		document.frm_mail.CREDITOR2.focus();
		return false;
	}
	if(document.frm_mail.CREDITOR3.value != "" || document.frm_mail.INT3.value != "" || document.frm_mail.MIN3.value != "" || document.frm_mail.BEHIND3.value != "" || document.frm_mail.BALANCE3.value != "" || document.frm_mail.TYPE3.value != "")
	{
		alert("Enter the creditor name3 and their corresponding Interest, Payment,Behind ,Balance and Type.");
		document.frm_mail.CREDITOR3.focus();
		return false;
	}
	if(document.frm_mail.CREDITOR4.value != "" || document.frm_mail.INT4.value != "" || document.frm_mail.MIN4.value != "" || document.frm_mail.BEHIND4.value != "" || document.frm_mail.BALANCE4.value != "" || document.frm_mail.TYPE4.value != "")
	{
		alert("Enter the creditor name4 and their corresponding Interest, Payment,Behind ,Balance and Type.");
		document.frm_mail.CREDITOR4.focus();
		return false;
	}
	if(document.frm_mail.CREDITOR5.value != "" || document.frm_mail.INT5.value != "" || document.frm_mail.MIN5.value != "" || document.frm_mail.BEHIND5.value != "" || document.frm_mail.BALANCE5.value != "" || document.frm_mail.TYPE5.value != "")
	{
		alert("Enter the creditor name5 and their corresponding Interest, Payment,Behind ,Balance and Type.");
		document.frm_mail.CREDITOR5.focus();
		return false;
	}
	if(document.frm_mail.CREDITOR6.value != "" || document.frm_mail.INT6.value != "" || document.frm_mail.MIN6.value != "" || document.frm_mail.BEHIND6.value != "" || document.frm_mail.BALANCE6.value != "" || document.frm_mail.TYPE6.value != "")
	{
		alert("Enter the creditor name6 and their corresponding Interest, Payment,Behind ,Balance and Type.");
		document.frm_mail.CREDITOR6.focus();
		return false;
	}
*/
	//return true;
}


//Email Validation Script
function validateEmail(addr,man,db) {
	if (addr == '' && man) {
	   if (db) alert('Email address is mandatory');
	   return false;
	}
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  if (db) alert('Email address contains invalid characters');
		  return false;
	   }
	}
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  if (db) alert("Email address contains non ascii characters.");
		  return false;
	   }
	}

	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   if (db) alert('Email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   if (db) alert('Email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   if (db) alert('Email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   if (db) alert('Email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   if (db) alert('period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   if (db) alert('period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	   if (db) alert('two periods must not be adjacent in email address');
	   return false;
	}
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   if (db) alert('invalid primary domain in email address');
	   return false;
	}
return true;
}

 //Function phone validation Script
// 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);
}