/* Function to remove the leading & trailing spaces */
function Trim(strInput)
{
	strInput = LTrim(strInput);
	strInput = RTrim(strInput);
	return strInput;
}

/* Function to remove the leading spaces */
function LTrim(strInput)
{
	var intCntr;
	for (intCntr=0; intCntr < strInput.length; intCntr++)
	{
		if (strInput.charAt(intCntr) != " ")
			break;
	}
	return strInput.substr(intCntr, strInput.length);
}

/* Function to remove the trailing spaces */
function RTrim(strInput)
{
	var intCntr;
	for (intCntr=strInput.length-1; intCntr > -1; intCntr--)
	{
		if (strInput.charAt(intCntr) != " ")
			break;
	}
	return strInput.substr(0, intCntr + 1);
}


function IsContact(fld)
   //  check for valid numeric strings
{
   var strValidChars = "0123456789.-+";
   var strChar;
   var blnResult = true;
   var strString= Trim(fld.value);
   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
  }

function isDOB(dateStr, dob) {

//var dob=document.form_in.form_dob;
var datePat = /^(\d{1,2})(\/)(\d{1,2})\2(\d{2}|\d{4})$/;

var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
//alert("Please Enter Date of Birth (dd-mm-yyyy)");
dob.focus();
return false;
}
month = matchArray[3]; // parse date into variables
day = matchArray[1];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
//alert("Please Enter Date of Birth (dd-mm-yyyy)");
dob.focus();
return false;
}
if (day < 1 || day > 31) {
//alert("Please Enter Date of Birth (dd-mm-yyyy)");
dob.focus();
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
//alert("Please Enter Date of Birth (dd-mm-yyyy)");
dob.focus();
return false
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
//alert("Please Enter Date of Birth (dd-mm-yyyy)");
dob.focus();
return false;
   }
}
return true;
}

function ValidateSubmitform1()
{
    var chk =	 true;
    var msg	=	 "";

    if( document.form1.email.value== '' || document.form1.first_choice.value== '' 
        ||document.form1.reason.value== ''||document.form1.telephone.value== ''  )
    {
        msg	   =	'Please complete all required fields and try again\n';
        chk		=	false ;

    }
    
    if( document.form1.email.value!= '')
    {
      var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
      var address = Trim(document.form1.email.value);
      if(reg.test(address) == false) {
          msg	   =	'Please enter valid email address\n';
          chk	   =	false ;
      }
    }

    if( document.form1.telephone.value!= '')
    {
      if(IsContact(document.form1.telephone)==false)
      {
            msg	   ="Please enter valid telephone no\n";
	    chk	   =	false ;
      }
    }
       
    if(chk)
    {
        document.form1.submit();
    }else
    {
        alert(msg);
    }
}


