/***************************************************************************************/
// General functions
/***************************************************************************************/
/////////////////////////////////////////////////////////////////////////////////////////
// Checks whether a string is a valid email address.
/////////////////////////////////////////////////////////////////////////////////////////

function LeapYear(year) 
{
    if ((year/4)   != Math.floor(year/4))   return false;
    if ((year/100) != Math.floor(year/100)) return true;
    if ((year/400) != Math.floor(year/400)) return false;
    return true;
}
function getDaysofMonth(month,year)
{
	daysofmonth   = new Array( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	daysofmonthLY = new Array( 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	arryindx=parseInt(month)-1;
	if (LeapYear(year))
	{
  		daysofmonth = daysofmonthLY;
	}
	return daysofmonth[arryindx];
}
function checkEmail(emailString) {
	splitVal = emailString.split('@');
	
	if(splitVal.length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	if(splitVal[0].length <= 0 || splitVal[1].length <= 0) {
		alert("Please enter a valid email address");
		return false;
	}
	
	splitDomain = splitVal[1].split('.');
	if(splitDomain.length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	if(splitDomain[0].length <= 0 || splitDomain[1].length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	return true;
}

/////////////////////////////////////////////////////////////////////////////////////////
// Removes the leading and trailing spaces in a strings and returns the trimmed string
/////////////////////////////////////////////////////////////////////////////////////////
function trimSpaces(stringValue) {
	
	// Checks the first occurance of spaces and removes them
for(i = 0; i < stringValue.length; i++) {
		if(stringValue.charAt(i) != " ") {
			break;
		}
	}
	if(i > 0) {
		stringValue = stringValue.substring(i);
	}
	
	// Checks the last occurance of spaces and removes them
	strLength = stringValue.length - 1;
	for(i = strLength; i >= 0; i--) {
		if(stringValue.charAt(i) != " ") {
			break;
		}
	}
	if(i < strLength) {
		stringValue = stringValue.substring(0, i + 1);
	}
	// Returns the string after removing leading and trailing spaces.
	return stringValue;
}
function formatCheck(dateStr) 
{
	dateSplit = dateStr.split("/");
	if(dateSplit.length != 3) 
	{
		alert("Invalid Date");
		return false;
	}
	if (isNaN(dateSplit[0])==true || isNaN(dateSplit[1])==true || isNaN(dateSplit[2])==true)
	{
		alert("Invalid Date");
		return false;
	}
		
	if(trimSpaces(dateSplit[0]).length <= 0 || parseInt(trimSpaces(dateSplit[0])) > 12 || parseInt(trimSpaces(dateSplit[0])) == 0)
	{
		alert("Invalid Month for Date");
		return false;
	}
	
	if(trimSpaces(dateSplit[1]).length <= 0)
	{
		alert("Invalid Day for Date");
		return false;
	}
	if(parseInt(dateSplit[1]) > getDaysofMonth(dateSplit[0],dateSplit[2]))
	{
		alert("Invalid Day for Month");
		return false;
	}
	if(trimSpaces(dateSplit[2]).length <= 3) 
	{
		alert("Invalid Year for Date");
		return false;
	}
	return true;
}
function CheckPhoneNumber(TheNumber) {
	
	if (TheNumber.length==1){
	if (TheNumber.charAt(0)==0) return false;
	}
	if (TheNumber.length<7) return false;
	var valid = 1
	var GoodChars = "0123456789-+/ ,"
	var i = 0
	for (i =0; i <= TheNumber.length -1; i++) {
	 if (GoodChars.indexOf(TheNumber.charAt(i)) == -1) {
	  valid = 0
	 } // End if statement
	} // End for loop
	return valid
}// End of Check
function isDigit (c) {
  return ( (c >= '0') && (c <=  '9') )
}
function frmSubmit(){
		
	if(trimSpaces(document.form1.txtUsername.value)==""){
		alert("Enter the user name");
		document.form1.txtUsername.value="";
		document.form1.txtUsername.focus();
		return false;
	}
	
	if(trimSpaces(document.form1.txtPwd.value)==""){
		alert("Enter the password");
		document.form1.txtPwd.value="";
		document.form1.txtPwd.focus();
		return false;
	}else{
		if(document.form1.txtPwd.value!=document.form1.txtPwd1.value){
			alert("Password mismatch");
			document.form1.txtPwd.focus();
			return false;
		}
	}
	if(trimSpaces(document.form1.txtName.value)==""){
		alert("Enter the name");
		document.form1.txtName.value="";
		document.form1.txtName.focus();
		return false;
	}
	if(trimSpaces(document.form1.txtfName.value)==""){
		alert("Enter the Father Name");
		document.form1.txtfName.value="";
		document.form1.txtfName.focus();
		return false;
	}
	if(trimSpaces(document.form1.txtAdr1.value)==""){
		alert("Enter the address");
		document.form1.txtAdr1.value="";
		document.form1.txtAdr1.focus();
		return false;
	}
	if(trimSpaces(document.form1.txtCity.value)==""){
		alert("Enter the District");
		document.form1.txtCity.value="";
		document.form1.txtCity.focus();
		return false;
	}
		if(trimSpaces(document.form1.txtpc.value)==""){
		alert("Enter the phone number");
		document.form1.txtpc.value="";
		document.form1.txtpc.focus();
		return false;
	}else{
		if(CheckPhoneNumber(document.form1.txtpc.value)==0){
			alert("Enter a valid  Pincode");
			document.form1.txtpc.value="";
			document.form1.txtpc.focus();
			return false;
		}
	}
		if(trimSpaces(document.form1.txtpc.value)==""){
		alert("Enter the Pincode");
		document.form1.txtpc.value="";
		document.form1.txtpc.focus();
		return false;
	}else{
		if(CheckPhoneNumber(document.form1.txtpc.value)==0){
			alert("Enter a valid  phone number");
			document.form1.txtpc.value="";
			document.form1.txtpc.focus();
			return false;
		}
	}
	if(document.form1.checkbox.checked==false){
		alert( " Please check the terms and condition " );
		document.form1.checkbox.focus();
		return false;
		}
	
	
	
	
	
}
