// Registration / Updation Form //
function chk_reg() {
	if (document.reg.accountName.value==0) {
		alert("Account name is must");
		document.reg.accountName.focus();
		return false;
	}
	
	var email_check = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if((document.reg.email.value.length >= 0) && (!email_check.test(document.reg.email.value))) {
		alert("Please enter a valid Email ID");
		document.reg.email.focus();
		return false;
	}
	
	if (document.reg.password.value.length < 6) {
		alert("Please enter a valid password [Minimum 6 characters]");
		document.reg.password.focus();
		return false;
	}
	
	if (document.reg.password.value != document.reg.repass.value) {
		alert("Re Password does not match");
		document.reg.repass.focus();
		return false;
	}
	
	if (document.reg.contactNo.value==0) {
		alert("Contact number is must");
		document.reg.contactNo.focus();
		return false;
	}
	
	if (document.reg.contactNo.value.length < 8) {
		alert("Please enter a valid Contact Number");
		document.reg.contactNo.focus();
		return false;
	}
	
	if (document.reg.street.value==0) {
		alert("Street is must");
		document.reg.street.focus();
		return false;
	}
	
	if (document.reg.locality.value==0) {
		alert("Locality is must");
		document.reg.locality.focus();
		return false;
	}
	
	if (document.reg.town.value==0) {
		alert("Town is must");
		document.reg.town.focus();
		return false;
	}
	
	if (document.reg.postCode.value != 0) {
		if (isNaN(document.reg.postCode.value)) {
			alert("Post Code should be Numeric");
			document.reg.postCode.focus();
			return false;
		}
	}
	
	if (document.reg.country.value=="x") {
		alert("Country is must");
		document.reg.country.focus();
		return false;
	}
	
	if (document.reg.security_code.value==0) {
		alert("Security Code is must");
		document.reg.security_code.focus();
		return false;
	}
	
	if (document.reg.security_code.value.length < 5) {
		alert("Invalid Security Code");
		document.reg.security_code.focus();
		return false;
	}	
}

function chk_upd() {
	if (document.edit.mobileNo.value==0) {
		alert("Mobile number is must");
		document.edit.mobileNo.focus();
		return false;
	}
	
	if (document.edit.mobileNo.value.length < 10) {
		alert("Please enter a valid Mobile Number");
		document.edit.mobileNo.focus();
		return false;
	}
	
	if (document.edit.postCode.value != 0) {
		if (isNaN(document.edit.postCode.value)) {
			alert("Post Code should be Numeric");
			document.edit.postCode.focus();
			return false;
		}
	}	
}

function chk_login() {
	if (document.login.accountCode.value==0) {
		alert("Account Name is must");
		document.login.accountCode.focus();
		return false;
	}
	
	if (document.login.password.value == 0) {
		alert("Please enter ypur password");
		document.login.password.focus();
		return false;
	}	
}

function chk_booking() {
	if (document.booking.contactName.value == 0) {
		alert("Contact Name is must");
		document.booking.contactName.focus();
		return false;
	}
	
	if (document.booking.telephone.value == 0) {
		alert("Telephone is must");
		document.booking.telephone.focus();
		return false;
	}
	
	/*
	if (document.booking.orderNo.value == 0) {
		alert("Internet Cost Center is must");
		document.booking.orderNo.focus();
		return false;
	}	
	
	if (document.booking.orderNo.value.length != 15) {
		alert("Internet Cost Center should consist of 15 characters");
		document.booking.orderNo.focus();
		return false;
	}
	
	if (!isNaN(document.booking.orderNo.value)) {
		alert("Internet Cost Center should be Alpha Numeric");
		document.booking.orderNo.focus();
		return false;
	}
	*/
	
	if (document.booking.vehicleType.options[document.booking.vehicleType.selectedIndex].value == "x") {	
		alert("Vehicle Type is must");
		document.booking.vehicleType.focus();
		return false;
	}
	
	if (!document.booking.serviceType[0].checked && !document.booking.serviceType[1].checked && !document.booking.serviceType[2].checked) {	
		alert("Service Type is must");
		document.booking.serviceType[0].focus();
		return false;
	}
	
	if (document.booking.pickupAddress.options[document.booking.pickupAddress.selectedIndex].value == "Non Account Address") {
		
		if (document.booking.pickupStreet.value == 0) {
			alert("Pickup Street is must");
			document.booking.pickupStreet.focus();
			return false;
		}
		
		if (document.booking.pickupLocality.value == 0) {
			alert("Pickup Locality is must");
			document.booking.pickupLocality.focus();
			return false;
		}
		
		if (document.booking.pickupTown.value == 0) {
			alert("Pickup Town is must");
			document.booking.pickupTown.focus();
			return false;
		}
		
		if (document.booking.pickupPostCode.value != 0) {
			if (isNaN(document.booking.pickupPostCode.value)) {
				alert("Post Code should be Numeric");
				document.booking.pickupPostCode.focus();
				return false;
			}
		}
		
		if (document.booking.pickupContactPerson.value == 0) {
			alert("Pickup Contact Person is must");
			document.booking.pickupContactPerson.focus();
			return false;
		}
		
		if (document.booking.pickupTelephone.value == 0) {
			alert("Pickup Telephone is must");
			document.booking.pickupTelephone.focus();
			return false;
		}
	}
	
	if (document.booking.pickupReadyTime.value == 0) {
		alert("Pickup Ready Time is must");
		document.booking.pickupRemark.focus();
		return false;
	}
	else {
		if (!date_compare(document.booking.pickupReadyTime.value)) {
			return false;
		}
	}
	
	if (document.booking.pickupDate.value == 0) {
		alert("Pickup Last Date is must");
		document.booking.pickupRemark.focus();
		return false;
	}
	else {
		if (!date_compare(document.booking.pickupDate.value)) {
			return false;
		}		
	}
	
	if (document.booking.dropCompany.value == 0) {
		alert("Drop Company is must");
		document.booking.dropCompany.focus();
		return false;
	}
	
	if (document.booking.dropAddress.options[document.booking.dropAddress.selectedIndex].value == "Non Account Address") {
		
		
		
		if (document.booking.dropStreet.value == 0) {
			alert("Drop Street is must");
			document.booking.dropStreet.focus();
			return false;
		}
		
		if (document.booking.dropLocality.value == 0) {
			alert("Drop Locality is must");
			document.booking.dropLocality.focus();
			return false;
		}
		
		if (document.booking.dropTown.value == 0) {
			alert("Drop Town is must");
			document.booking.dropTown.focus();
			return false;
		}
		
		if (document.booking.dropPostCode.value != 0) {
			if (isNaN(document.booking.dropPostCode.value)) {
				alert("Post Code should be Numeric");
				document.booking.dropPostCode.focus();
				return false;
			}
		}
		
		if (document.booking.dropContactPerson.value == 0) {
			alert("Drop Contact Person is must");
			document.booking.dropContactPerson.focus();
			return false;
		}
		
		if (document.booking.dropTelephone.value == 0) {
			alert("Drop Telephone is must");
			document.booking.dropTelephone.focus();
			return false;
		}
	}
	
	if ((document.booking.pickupStreet.value == document.booking.dropStreet.value) && (document.booking.pickupLocality.value == document.booking.dropLocality.value) && (document.booking.pickupTown.value == document.booking.dropTown.value) && (document.booking.pickupPostCode.value == document.booking.dropPostCode.value)) {
		alert("Pickup Address can not be same as Drop Address. Please make Updations");
		document.booking.pickupRemark.focus();
		return false;
	}	
}


function chk_booking_admin() {
	if (document.booking_admin.accountCode.value == 0) {
		alert("Account Code is must");
		document.booking_admin.accountCode.focus();
		return false;
	}
	
	if (document.booking_admin.accountName.value == 0) {
		alert("Account Name is must");
		document.booking_admin.accountName.focus();
		return false;
	}
	
	if (document.booking_admin.contactName.value == 0) {
		alert("Contact Name is must");
		document.booking_admin.contactName.focus();
		return false;
	}
	
	if (document.booking_admin.telephone.value == 0) {
		alert("Telephone is must");
		document.booking_admin.telephone.focus();
		return false;
	}
	
	if (document.booking_admin.vehicleType.options[document.booking_admin.vehicleType.selectedIndex].value == "x") {	
		alert("Vehicle Type is must");
		document.booking_admin.vehicleType.focus();
		return false;
	}
	
	if (!document.booking_admin.serviceType[0].checked && !document.booking_admin.serviceType[1].checked && !document.booking_admin.serviceType[2].checked) {	
		alert("Service Type is must");
		document.booking_admin.serviceType[0].focus();
		return false;
	}
	
	if (document.booking_admin.pickupStreet.value == 0) {
		alert("Pickup Street is must");
		document.booking_admin.pickupStreet.focus();
		return false;
	}
	
	if (document.booking_admin.pickupLocality.value == 0) {
		alert("Pickup Locality is must");
		document.booking_admin.pickupLocality.focus();
		return false;
	}
		
	if (document.booking_admin.pickupTown.value == 0) {
		alert("Pickup Town is must");
		document.booking_admin.pickupTown.focus();
		return false;
	}
	
	if (document.booking_admin.pickupPostCode.value != 0) {
		if (isNaN(document.booking_admin.pickupPostCode.value)) {
			alert("Post Code should be Numeric");
			document.booking_admin.pickupPostCode.focus();
			return false;
		}
	}
		
	if (document.booking_admin.pickupContactPerson.value == 0) {
		alert("Pickup Contact Person is must");
		document.booking_admin.pickupContactPerson.focus();
		return false;
	}
	
	if (document.booking_admin.pickupTelephone.value == 0) {
		alert("Pickup Telephone is must");
		document.booking_admin.pickupTelephone.focus();
		return false;
	}	
	
	if (document.booking_admin.pickupReadyTime.value == 0) {
		alert("Pickup Ready Time is must");
		document.booking_admin.pickupRemark.focus();
		return false;
	}
	else {
		if (!date_compare2(document.booking_admin.pickupReadyTime.value)) {
			return false;
		}
	}
	
	if (document.booking_admin.pickupDate.value == 0) {
		alert("Pickup Last Date is must");
		document.booking_admin.pickupRemark.focus();
		return false;
	}
	else {
		if (!date_compare2(document.booking_admin.pickupDate.value)) {
			return false;
		}		
	}
	
	if (document.booking_admin.dropCompany.value == 0) {
		alert("Drop Company is must");
		document.booking_admin.dropCompany.focus();
		return false;
	}
	
	if (document.booking_admin.dropStreet.value == 0) {
		alert("Drop Street is must");
		document.booking_admin.dropStreet.focus();
		return false;
	}
		
	if (document.booking_admin.dropLocality.value == 0) {
		alert("Drop Locality is must");
		document.booking_admin.dropLocality.focus();
		return false;
	}
	
	if (document.booking_admin.dropTown.value == 0) {
		alert("Drop Town is must");
		document.booking_admin.dropTown.focus();
		return false;
	}
	
	if (document.booking_admin.dropPostCode.value != 0) {
		if (isNaN(document.booking_admin.dropPostCode.value)) {
			alert("Post Code should be Numeric");
			document.booking_admin.dropPostCode.focus();
			return false;
		}
	}
	
	if (document.booking_admin.dropContactPerson.value == 0) {
		alert("Drop Contact Person is must");
		document.booking_admin.dropContactPerson.focus();
		return false;
	}
	
	if (document.booking_admin.dropTelephone.value == 0) {
		alert("Drop Telephone is must");
		document.booking_admin.dropTelephone.focus();
		return false;
	}	
	
	if ((document.booking_admin.pickupStreet.value == document.booking_admin.dropStreet.value) && (document.booking_admin.pickupLocality.value == document.booking_admin.dropLocality.value) && (document.booking_admin.pickupTown.value == document.booking_admin.dropTown.value) && (document.booking_admin.pickupPostCode.value == document.booking_admin.dropPostCode.value)) {
		alert("Pickup Address can not be same as Drop Address. Please make Updations");
		document.booking_admin.pickupRemark.focus();
		return false;
	}
	
	if (document.booking_admin.weight.value == 0) {
		alert("Weight Name is must");
		document.booking_admin.weight.focus();
		return false;
	}
	
	if (document.booking_admin.quantity.value == 0) {
		alert("Quantity Name is must");
		document.booking_admin.quantity.focus();
		return false;
	}
	
	if (document.booking_admin.productDetail.value == 0) {
		alert("Product Detail Name is must");
		document.booking_admin.productDetail.focus();
		return false;
	}	
}

function chk_booking1() {
	if (document.booking1.weight.value == 0) {
		alert("Weight Name is must");
		document.booking1.weight.focus();
		return false;
	}
	
	if (document.booking1.quantity.value == 0) {
		alert("Quantity Name is must");
		document.booking1.quantity.focus();
		return false;
	}
	
	if (document.booking1.productDetail.value == 0) {
		alert("Product Detail Name is must");
		document.booking1.productDetail.focus();
		return false;
	}
}

function blankFields(street,locality,town,postcode,country,contactperson,telephone) {
	//alert(street+locality+town+postcode+contactperson);
	if (document.booking.pickupAddress.options[document.booking.pickupAddress.selectedIndex].value == "Non Account Address") {
		document.booking.pickupStreet.value ="";
		document.booking.pickupLocality.value ="";
		document.booking.pickupTown.value ="";
		document.booking.pickupPostCode.value ="";
		document.booking.pickupContactPerson.value ="";
		document.booking.pickupTelephone.value ="";
		
		document.booking.pickupStreet.disabled=false;
		document.booking.pickupLocality.disabled=false;
		document.booking.pickupTown.disabled=false;
		document.booking.pickupPostCode.disabled=false;
		document.booking.pickupCountry.disabled=false;
		document.booking.pickupContactPerson.disabled=false;
		document.booking.pickupTelephone.disabled=false;
	}
	else if (document.booking.pickupAddress.options[document.booking.pickupAddress.selectedIndex].value == "Account Address") {
		document.booking.pickupStreet.disabled=true;
		document.booking.pickupLocality.disabled=true;
		document.booking.pickupTown.disabled=true;
		document.booking.pickupPostCode.disabled=true;
		document.booking.pickupCountry.disabled=true;
		document.booking.pickupContactPerson.disabled=true;
		document.booking.pickupTelephone.disabled=true;
		
		document.booking.pickupStreet.value =street;
		document.booking.pickupLocality.value =locality;
		document.booking.pickupTown.value =town;
		document.booking.pickupPostCode.value =postcode;
		document.booking.pickupContactPerson.value =contactperson;
		document.booking.pickupTelephone.value =telephone;
	}
}

function blankFields1(street,locality,town,postcode,country,contactperson,telephone) {
	if (document.booking.dropAddress.options[document.booking.dropAddress.selectedIndex].value == "Non Account Address") {
		document.booking.dropStreet.value ="";
		document.booking.dropLocality.value ="";
		document.booking.dropTown.value ="";
		document.booking.dropPostCode.value ="";
		document.booking.dropCountry.disabled=false;
		document.booking.dropContactPerson.value ="";
		document.booking.dropTelephone.value ="";
		
		document.booking.dropStreet.disabled=false;
		document.booking.dropLocality.disabled=false;
		document.booking.dropTown.disabled=false;
		document.booking.dropPostCode.disabled=false;
		document.booking.dropCountry.disabled=false;
		document.booking.dropContactPerson.disabled=false;
		document.booking.dropTelephone.disabled=false;
	}
	else if (document.booking.dropAddress.options[document.booking.dropAddress.selectedIndex].value == "Account Address") {
		document.booking.dropStreet.disabled=true;
		document.booking.dropLocality.disabled=true;
		document.booking.dropTown.disabled=true;
		document.booking.dropPostCode.disabled=true;
		document.booking.dropCountry.disabled=true;
		document.booking.dropContactPerson.disabled=true;
		document.booking.dropTelephone.disabled=true;
	
		document.booking.dropStreet.value =street;
		document.booking.dropLocality.value =locality;
		document.booking.dropTown.value =town;
		document.booking.dropPostCode.value =postcode;		
		document.booking.dropContactPerson.value =contactperson;
		document.booking.dropTelephone.value =telephone;
	}
}

function setFields() {
	document.booking.pickupStreet.disabled=true;
	document.booking.pickupLocality.disabled=true;
	document.booking.pickupTown.disabled=true;
	document.booking.pickupPostCode.disabled=true;
	document.booking.pickupCountry.disabled=true;
	document.booking.pickupContactPerson.disabled=true;
	document.booking.pickupTelephone.disabled=true;
	
	document.booking.dropStreet.disabled=true;
	document.booking.dropLocality.disabled=true;
	document.booking.dropTown.disabled=true;
	document.booking.dropPostCode.disabled=true;
	document.booking.dropCountry.disabled=true;
	document.booking.dropContactPerson.disabled=true;
	document.booking.dropTelephone.disabled=true;
}

function chk_testimonials() {
	if (document.testimonials.name.value==0) {
		alert("Name is must");
		document.testimonials.name.focus();
		return false;
	}
		
	var email_check = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if((document.testimonials.email.value.length >= 0) && (!email_check.test(document.testimonials.email.value))) {
		alert("Please enter a valid Email ID");
		document.testimonials.email.focus();
		return false;
	}
	
	if (document.testimonials.place.value==0) {
		alert("Place is must");
		document.testimonials.place.focus();
		return false;
	}
	
	if (document.testimonials.remark.value==0) {
		alert("Comments are must");
		document.testimonials.remark.focus();
		return false;
	}
}

function chk_enq() {
	if (document.enq.name.value==0) {
		alert("Name is must");
		document.enq.name.focus();
		return false;
	}
		
	var email_check = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if((document.enq.email.value.length >= 0) && (!email_check.test(document.enq.email.value))) {
		alert("Please enter a valid Email ID");
		document.enq.email.focus();
		return false;
	}
	
	if (document.enq.telephone.value==0) {
		alert("Telephone is must");
		document.enq.telephone.focus();
		return false;
	}
	
	if (document.enq.remark.value==0) {
		alert("Comment is must");
		document.enq.remark.focus();
		return false;
	}
}

function chk_email() {
	var email_check = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if((document.remind.email.value.length >= 0) && (!email_check.test(document.remind.email.value))) {
		alert("Please enter a valid Email ID");
		document.remind.email.focus();
		return false;
	}	
}

function date_compare(start_date) {
	//var start_date="29-01-2009";
	var cur_dateObj=new Date();
	cur_year=cur_dateObj.getFullYear();
	cur_month=cur_dateObj.getMonth() +	1;
	cur_day=cur_dateObj.getDate();
	var cur_date=cur_day + ":" + cur_month + ":" + cur_year;
	//alert(end_date);
	var seldate1=start_date.split(" ");
	var seldate=seldate1[0].split(":");
	var curdate=cur_date.split(":");
	if(parseInt(seldate[2])<parseInt(curdate[2])) {
		//Year
		alert("Year cannot be less than Current year");
		document.booking.pickupRemark.focus();
		return false;
	}
	if(parseInt(seldate[2])<=parseInt(curdate[2])&&parseInt(seldate[0])<parseInt(curdate[0])) {
		//Day
		alert("Date cannot be less than Current date");
		document.booking.pickupRemark.focus();
		return false;
	}
	if(parseInt(seldate[2])<=parseInt(curdate[2])&&parseInt(seldate[0])<=parseInt(curdate[0])&&parseInt(seldate[1])<parseInt(curdate[1])) {
		//Month
		alert("Month cannot be less than Current month");
		document.booking.pickupRemark.focus();
		return false;
	}
	return true;
}

function date_compare1(start_date) {
	//var start_date="29-01-2009";
	var cur_dateObj=new Date();
	cur_year=cur_dateObj.getFullYear();
	cur_month=cur_dateObj.getMonth() +	1;
	cur_day=cur_dateObj.getDate();
	var cur_date=cur_day + ":" + cur_month + ":" + cur_year;
	//alert(end_date);
	var seldate1=start_date.split(" ");
	var seldate=seldate1[0].split(":");
	var curdate=cur_date.split(":");
	if(parseInt(seldate[2])<parseInt(curdate[2])) {
		//Year
		alert("Year cannot be less than Current year");
		return false;
	}
	if(parseInt(seldate[2])<=parseInt(curdate[2])&&parseInt(seldate[0])<parseInt(curdate[0])) {
		//Day
		alert("Date cannot be less than Current date");
		return false;
	}
	if(parseInt(seldate[2])<=parseInt(curdate[2])&&parseInt(seldate[0])<=parseInt(curdate[0])&&parseInt(seldate[1])<parseInt(curdate[1])) {
		//Month
		alert("Month cannot be less than Current month");
		return false;
	}
	return true;
}

function date_compare2(start_date) {
	//var start_date="29-01-2009";
	var cur_dateObj=new Date();
	cur_year=cur_dateObj.getFullYear();
	cur_month=cur_dateObj.getMonth() +	1;
	cur_day=cur_dateObj.getDate();
	var cur_date=cur_day + ":" + cur_month + ":" + cur_year;
	//alert(end_date);
	var seldate1=start_date.split(" ");
	var seldate=seldate1[0].split(":");
	var curdate=cur_date.split(":");
	if(parseInt(seldate[2])<parseInt(curdate[2])) {
		//Year
		alert("Year cannot be less than Current year");
		document.booking_admin.pickupRemark.focus();
		return false;
	}
	if(parseInt(seldate[2])<=parseInt(curdate[2])&&parseInt(seldate[0])<parseInt(curdate[0])) {
		//Day
		alert("Date cannot be less than Current date");
		document.booking_admin.pickupRemark.focus();
		return false;
	}
	if(parseInt(seldate[2])<=parseInt(curdate[2])&&parseInt(seldate[0])<=parseInt(curdate[0])&&parseInt(seldate[1])<parseInt(curdate[1])) {
		//Month
		alert("Month cannot be less than Current month");
		document.booking_admin.pickupRemark.focus();
		return false;
	}
	return true;
}

function chk_unchk(val, form_name) {
	dml=eval('document.'+form_name);
	len=dml.elements.length;
	var i=0;
	for (i=0; i<len; i++) {
		if (dml.elements[i].type == "checkbox") {
			if (dml.oID.checked==true) { 
				dml.elements[i].checked=true;
			}
			else {
				dml.elements[i].checked=false;
			}
		}
	}
}

function chkdelete(){
	var frm=document.formn;
	count = frm.elements.length;
	var c=0;
	for (i=0; i < count; i++){
		if(frm.elements[i].checked == 1){
			c = 1;
		}
	}
	if(c == 0){
		alert('First select a record to delete.');
		return false;
	}
	if(c!=0){
		 return confirm('Are you sure you want to delete selected record(s)....');
	}
}