function validateCommercialDetails(){
	var newPolicy	= document.getElementById("NewPolicy");
	var reNewPolicy = document.getElementById("ReNewPolicy");
	var rto			= document.getElementById("rto");
	var manufacture	= document.getElementById("manufacture");
	var modelName	= document.getElementById("modelName");
	var yearManu	= document.getElementById("yearManu");
	var firstName	= document.getElementById("firstName");
	var emailId		= document.getElementById("emailId");
	var mobile		= document.getElementById("mobile");
	var stdCode		= document.getElementById("stdCode");
	var telephoneNo	= document.getElementById("telephoneNo");

	//validation for policy type
	if(!newPolicy.checked && !reNewPolicy.checked){
		alert("Please select policy type");
		return false;
	}
	
	//validation for rto
	if(rto.value.length > 0){
		if(rto.value.length > 50){
			alert("RTO name cannot be greater than 50 characters");
			rto.focus();
			rto.select();
			return false;
		}else if(isAlphabetic(rto.value)==false){
			alert("Invalid RTO name");
			rto.focus();
			rto.select();
			return false;
		}
	}

	//validation for manufacturer name
	if(manufacture.value.trim().length == 0){
		alert("Please enter Manufacturer Name");
		manufacture.focus();
		manufacture.select();
		return false;
	}else if(manufacture.value.length > 100 ){
		alert("Manufacturer Name cannot be greater than 100 characters");
		manufacture.focus();
		manufacture.select();
		return false;
	}

	//validation for model name
	if(modelName.value.trim().length == 0){
		alert("Please enter Model Name");
		modelName.focus();
		modelName.select();
		return false;
	}else if(modelName.value.length > 200 ){
		alert("Model Name cannot be greater than 200 characters");
		modelName.focus();
		modelName.select();
		return false;
	}

	//validation for year
	if(yearManu.value.length > 0){
		
		var currentDate=new Date(document.getElementById("carServerDate").value);
		if(yearManu.value > currentDate.getFullYear()){
			alert("Year of Manufacture cannot be greater than current year");
			yearManu.focus();
			yearManu.select();
			return false;
		}

		if(yearManu.value.length > 4 ){
			alert("Manufacturer Year cannot be greater than 4 characters");
			yearManu.focus();
			yearManu.select();
			return false;
		}else if(isInteger(yearManu.value)==false){
			alert("Please enter only numbers in the Manufacture year field");
			yearManu.focus();
			yearManu.select();
			return false;
		}
	
	}

	//validation for name
	if(firstName.value.trim().length ==0){
		alert("Please enter your name");
		firstName.focus();
		firstName.select();
		return false;
	}else if(firstName.value.length > 50){
		alert("Name cannot be greater than 50 characters");
		firstName.focus();
		firstName.select();
		return false;
	}else if(isFirstName(firstName.value)==false){
		alert("Invalid name");
		firstName.focus();
		firstName.select();
		return false;
	}

	//validation for email
	if(emailId.value.length > 0){
		if(emailId.value.length > 100){
			alert("Email Id cannot be greater than 100 characters");
			emailId.focus();
			emailId.select();
			return false;
		}else if(isEmail(emailId.value)==false){
			alert("Invalid Email Id");
			emailId.focus();
			emailId.select();
			return false;
		}
	}

//	This method is to check Telephone No or MobileNo field, any one is mandatory
	if((telephoneNo.value.trim().length==0) && (mobile.value.trim().length==0)){
    	alert("Among the telephone number & mobile number, one is mandatory");
		telephoneNo.focus();
		telephoneNo.select();
		return false;
	}else if((stdCode.value.length > 0) || (telephoneNo.value.length > 0)  ){
		if(isInteger(stdCode.value)==false){
			alert("Enter valid Telephone Area Code");
			stdCode.focus();
			stdCode.select();
			return false;
		}
		if(stdCode.value.length > 5){
			alert("Enter Telephone Area Code within 5 digits");
			stdCode.focus();
			stdCode.select();
			return false;
		}
		if(stdCode.value.length > 0 && telephoneNo.value.trim().length==0){
			alert("Enter Telephone Number within 10 digits");
			telephoneNo.focus();
			telephoneNo.select();
			return false;
		}
		if(stdCode.value.trim().length==0 && telephoneNo.value.length > 0){
			alert("Enter Telephone Area Code within 5 digits");
			stdCode.focus();
			stdCode.select();
			return false;
		}
		if(isInteger(telephoneNo.value)==false){
			alert("Enter valid Telephone Number");
			telephoneNo.focus();
			telephoneNo.select();
			return false;
		}
		if(telephoneNo.value.length > 10 ){
			alert("Enter Telephone Number within 10 digits");
			telephoneNo.focus();
			telephoneNo.select();
			return false;
		}
	}

	//validation for mobile number
	if((mobile.value.length > 0)){
		if(isInteger(mobile.value) == false){
    		alert("Enter valid Mobile Number");
			mobile.focus();
			mobile.select();
			return false;
		}else if(mobile.value.length > 10){
    		alert("Enter Mobile Number within 10 digits");
			mobile.focus();
			mobile.select();
			return false;
		}else if(mobile.value.length < 10){
    		alert("Mobile Number cannot be less than 10 digits");
			mobile.focus();
			mobile.select();
			return false;
		}
	}

}

String.prototype.trim = function() {
// Strip leading and trailing white-space
return this.replace(/^\s*|\s*$/g, "");
}

var reAlphabetic = /^[a-zA-Z][ \,\-\.\'a-zA-Z]+[a-zA-Z \.\,]$/


var defaultEmptyOK = false

function isEmpty(s){ 
	return ((s == null) || (s.length == 0))
}

function isAlphabetic (s){
	
	var i;

    if (isEmpty(s)) 
       if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphabetic.arguments[1] == true);

    else {
		return reAlphabetic.test(s)
    }
}

//VALIDATION FOR NUMBER
//var reInteger = /^\d+$/
var reInteger = /^[0-9]*$/
function isInteger(s){
	var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    return reInteger.test(s)
}

var reFirstName = /^[A-Za-z]+[ \'\.\-A-Za-z]+[A-Za-z \.]*$/

function isFirstName (s){
	
	var i;

    if (isEmpty(s)) 
       if (isFirstName.arguments.length == 1) return defaultEmptyOK;
       else return (isFirstName.arguments[1] == true);

    else {
		return reFirstName.test(s)
    }
}

//VALIDATION FOR CHECK E-MAIL
var reEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
function isEmail(s){  
	if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
    else {
       return reEmail.test(s)
    }
}
