
//function for the lang selection
function chkpdt() {
	text = "";
	frmpdt.cat.value = frmpdt.tcat.value
	str=frmpdt.cat.value 
	 text = str.substring(0, 1)
	 txtlength=str.length
	 if (text=="-") {		
		go=str.substring(1, str.length)
		frmpdt.action="subcategory.asp"
	 }
	 else {
		frmpdt.action="category.asp"
	}

	frmpdt.tcat.value=0
	frmpdt.submit()
} // chkpdt


//function to validate the fields in contactus page
function validatecontact() {
	//Validating the company/school
	if (trim(frmcontact.company.value) == "") {
		alert("Please enter your company/school name.")
		frmcontact.company.focus();
		return false;
	}

	if (trim(frmcontact.tel.value)==""){
		alert("Please enter your contact number.");
		frmcontact.tel.focus();
		return false;
	}

	if (trim(frmcontact.tel.value) != "") {
		if (!chknumber(frmcontact.tel.value)) {
			alert("Please enter a valid contact number.");
			frmcontact.tel.focus();
			return false;
		}
	}

	//Validating the contactperson's email
	if (trim(frmcontact.email.value) == "") {
		alert("Please enter your E-mail address.")
		frmcontact.email.focus();
		return false;
	}

	if (frmcontact.email.value != "") {
		if (!chkmail(frmcontact.email.value)) {
			alert("Please enter a valid E-mail address.");
			frmcontact.email.focus();
			return false;
		}
	}

	//Validating the subjct
	if (trim(frmcontact.subject.value) == "") {
		alert("Please enter your subject.")
		frmcontact.subject.focus();
		return false;
	}

	//Validating the message
	if (trim(frmcontact.enquiry.value) == "") {
		alert("Please enter your enquiry.")
		frmcontact.enquiry.focus();
		return false;
	}

}// validatecontact function

//function to validate the customer login registration
function registervalidate() {

	if (frmregister.gender[0].checked==false && frmregister.gender[1].checked==false){
		alert("Please select your gender.")
		//frmregister.gender.focus();
		return;
	}

	if (trim(frmregister.firstname.value) == "") {
		alert("Please enter your firstname.")
		frmregister.firstname.focus();
		return;
	}

	if (trim(frmregister.lastname.value) == "") {
		alert("Please enter your lastname.")
		frmregister.lastname.focus();
		return;
	}
		
	//STARTING DATE OF BIRTH VALIDATION
	var leap = 0;

	var dday = frmregister.DateBD.value
	var mmonth = frmregister.MonthBD.value
	var yyear = frmregister.YearBD.value	
	
	if (dday=="0"){
		alert("Please select your Birth Day.");
		frmregister.DateBD.focus();
		return;
	}

	if (mmonth=="0"){
		alert("Please select your Birth Month.");
		frmregister.MonthBD.focus();
		return;
	}
	
	if (yyear=="0"){
		alert("Please select your Birth Year.");
		frmregister.YearBD.focus();
		return;
	}

	/* Validation of other months with day 31 */
	 if ((dday > 30) && ((mmonth == 4) || (mmonth == 6) || (mmonth == 9) || (mmonth == 11))) {
		 alert("Please enter a valid Date of Birth.")
		 frmregister.DateBD.focus();
		 return;
	}
		
	/* Validation leap-year / february / day */
	if ((yyear % 4 == 0) || (yyear % 100 == 0) || (yyear % 400 == 0)) {
		 leap = 1;
	 }

	if ((mmonth == 2) && (leap == 1) && (dday > 29)) {
		alert("Please select a valid Date of Birth, February's leap year does not have day "+dday+".");
		frmregister.DateBD.focus();
		return;
	 }

	 if ((mmonth == 2) && (leap != 1) && (dday > 28)) {
			alert("Please select a valid Date of Birth, February does not have day "+dday+".");
			frmregister.DateBD.focus();
			return;
	 }
	//END OF DATE OF BIRTH VALIDATION
	
	//ensure the email field is not empty
	if (trim(frmregister.email.value) == "") {
		alert("Please enter your email address.")
		frmregister.email.focus();
		return;
	}

	if (trim(frmregister.email.value) != "") {
		if (!chkmail(frmregister.email.value)) {
			alert("Please enter a valid email address.");
			frmregister.email.focus();
			return;
		}
	}

	if (trim(frmregister.address.value) == "") {
		alert("Please enter your address.")
		frmregister.address.focus();
		return;
	}

	if (trim(frmregister.postalcode.value) == "") {
		alert("Please enter your postalcode.")
		frmregister.postalcode.focus();
		return;
	}

	if (!chknumber(frmregister.postalcode.value)) {
		alert("Please enter only digits in the postalcode.")
		frmregister.postalcode.focus();
		return;
	}

	if (trim(frmregister.city.value) == "") {
		alert("Please enter your city.")
		frmregister.city.focus();
		return;
	}

	if (frmregister.country.value == "0") {
		alert("Please select your country.")
		frmregister.country.focus();
		return;
	}

	if (trim(frmregister.tel.value)==""){
		alert("Please enter your telephone number.");
		frmregister.tel.focus();
		return;
	}
	
	if (trim(frmregister.tel.value) != "") {
		if (!chknumber(frmregister.tel.value)) {
			alert("Please enter a valid telephone number.")
			frmregister.tel.focus();
			return;
		}
	}

	inputtel = frmregister.tel.value;
	if(inputtel.length < 8){
		alert("Please enter a proper telephone number.");
		frmregister.tel.focus();
		return;
	}

	if (trim(frmregister.fax.value) != "") {
		if (!chknumber(frmregister.fax.value)) {
			alert("Please enter a valid fax number.")
			frmregister.fax.focus();
			return;
		}

		inputfax = frmregister.fax.value;
		if(inputfax.length < 8){
			alert("Please enter a proper fax number.");
			frmregister.fax.focus();
			return;
		}
	}

	if (trim(frmregister.mobile.value) != "") {
		if (!chknumber(frmregister.mobile.value)) {
			alert("Please enter a valid mobile number.")
			frmregister.mobile.focus();
			return;
		}

		inputmobile= frmregister.mobile.value;
		if(inputmobile.length < 8){
			alert("Please enter a proper mobile number.");
			frmregister.mobile.focus();
			return;
		}
	}
	
	//PASSWORD CHECK
	if (trim(frmregister.password.value) == "") {
		alert("Please enter your password.")
		frmregister.password.focus();
		return;
	}

	if (trim(frmregister.confirmpassword.value) == "") {
		alert("Please enter your password again to confirm.")
		frmregister.confirmpassword.focus();
		return;
	}

	if (trim(frmregister.password.value) != trim(frmregister.confirmpassword.value) ) {
		alert("Your password and confimation password are different. Please key in again.")
		frmregister.confirmpassword.focus();
		return;
	}
	
	frmregister.submit();
}// registervalidate

//function to validate the fields in shipping and payment page
function paymentvalidate() {

	//ensure a shipping/delivery method is selected
	if (frmPay.delivery[0].checked==false && frmPay.delivery[1].checked==false && frmPay.delivery[2].checked==false){
		alert("Please select your preferred shipping/delivery type.")
		return;	
	}

	//ensure a payment method is selected
	if (frmPay.payment[0].checked==false && frmPay.payment[1].checked==false && frmPay.payment[2].checked==false){
		alert("Please select your preferred payment method.")
		return;	
	}

	//for localselfcollect delivery, no registeredjmail
	if (frmPay.delivery[1].checked==true){
		if (frmPay.Requestregisteredmail.checked==true ){
			alert("For local self collect, there is no registered mail option")
			frmPay.Requestregisteredmail.checked=false;
			return;	
		}
	}

	//for foreign delivery, no cash
	if (frmPay.delivery[2].checked==true){
		if (frmPay.payment[1].checked==true ){
			alert("You are not able to provide cash on delivery for foreign deliveries. Please select one of the other two payment options")
			return;	
		}
	}


	
	//for creditcards
	if (frmPay.payment[0].checked==true) {
		if (trim(frmPay.cc_owner.value) == "") {
			alert("Please enter the card owner's name.")
			frmPay.cc_owner.focus();
			return;
		}
	}
	//for creditcards
	if (frmPay.payment[0].checked==true) {
		if (trim(frmPay.cc_number.value) == "") {
			alert("Please enter the creditcard number.")
			frmPay.cc_number.focus();
			return;
		}	
	}
	
	if (frmPay.payment[0].checked==true) {
		//VALIDATING CREDIT CARD

		var TodaysDate = new Date();  // fill this variable with todays date by using TodaysDate.GetMonth(), GetYear() etc..
		nowmonth =  (TodaysDate.getMonth() +1)
		nowyear =  TodaysDate.getYear()
			
		//for the CREDIT CARD EXPIRY date:

		mmonth = frmPay.cc_expires_month.value
		yyear = frmPay.cc_expires_year.value	
		
		if (mmonth <= nowmonth && yyear == nowyear) {
			alert("Please enter a valid credit card expiry date")
			frmPay.cc_expires_month.focus();
			return;
		}				
		
	}

	frmPay.submit();

}// paymentvalidate function

//validate login form
function validatelogin(){
	if (trim(frmlogin.email.value)==""){
		alert("Please enter in your email addess to log-in.");
		frmlogin.email.focus();
		return;
	}

	if (trim(frmlogin.email.value) != "") {
		if (!chkmail(frmlogin.email.value)) {
			alert("Please enter a valid email address to log-in.");
			frmlogin.email.focus();
			return;
		}
	}

	if (trim(frmlogin.password.value)==""){
		alert("Please enter in your password to log-in.");
		frmlogin.password.focus();
		return;
	}
	
	frmlogin.submit();
}//validatelogin

//function to validate the delivery address info
function deliveryvalidate() {

	if (trim(frmdelivery.address.value) == "") {
		alert("Please enter your address.")
		frmdelivery.address.focus();
		return;
	}

	if (trim(frmdelivery.postalcode.value) == "") {
		alert("Please enter your postalcode.")
		frmdelivery.postalcode.focus();
		return;
	}

	if (!chknumber(frmdelivery.postalcode.value)) {
		alert("Please enter only digits in the postalcode.")
		frmdelivery.postalcode.focus();
		return;
	}

	if (trim(frmdelivery.city.value) == "") {
		alert("Please enter your city.")
		frmdelivery.city.focus();
		return;
	}

	if (frmdelivery.country.value == "0") {
		alert("Please select your country.")
		frmdelivery.country.focus();
		return;
	}
	
	frmdelivery.submit();
}//deliveryvalidate


//function to validate email to send forgotten password
function passwordvalidate() {
	
	//Validating the contactperson's email
	if (trim(frmpassword.email.value) == "") {
		alert("Please enter your E-mail address.")
		frmpassword.email.focus();
		return;
	}

	if (trim(frmpassword.email.value) != "") {
		if (!chkmail(frmpassword.email.value)) {
			alert("Please enter a valid email address.");
			frmpassword.email.focus();
			return;
		}
	}

	frmpassword.submit();

}//passwordvalidate

//function to validate the contact form
function contactvalidate() {

	if (frmcontact.gender[0].checked==false && frmcontact.gender[1].checked==false){
		alert("Please select your gender.")
		//frmregister.gender.focus();
		return;
	}

	if (trim(frmcontact.firstname.value) == "") {
		alert("Please enter your firstname.")
		frmcontact.firstname.focus();
		return;
	}

	if (trim(frmcontact.lastname.value) == "") {
		alert("Please enter your lastname.")
		frmcontact.lastname.focus();
		return;
	}
		
	//STARTING DATE OF BIRTH VALIDATION
	var leap = 0;

	var dday = frmcontact.DateBD.value
	var mmonth = frmcontact.MonthBD.value
	var yyear = frmcontact.YearBD.value	
	
	if (dday=="0"){
		alert("Please select your Birth Day.");
		frmcontact.DateBD.focus();
		return;
	}

	if (mmonth=="0"){
		alert("Please select your Birth Month.");
		frmcontact.MonthBD.focus();
		return;
	}
	
	if (yyear=="0"){
		alert("Please select your Birth Year.");
		frmcontact.YearBD.focus();
		return;
	}


	/* Validation of other months with day 31 */
	 if ((dday > 30) && ((mmonth == 4) || (mmonth == 6) || (mmonth == 9) || (mmonth == 11))) {
		 alert("Please enter a valid Date of Birth.")
		 frmcontact.DateBD.focus();
		 return;
	}
		
	/* Validation leap-year / february / day */
	if ((yyear % 4 == 0) || (yyear % 100 == 0) || (yyear % 400 == 0)) {
		 leap = 1;
	 }

	if ((mmonth == 2) && (leap == 1) && (dday > 29)) {
		alert("Please select a valid Date of Birth, February's leap year does not have day "+dday+".");
		frmcontact.DateBD.focus();
		return;
	 }

	 if ((mmonth == 2) && (leap != 1) && (dday > 28)) {
			alert("Please select a valid Date of Birth, February does not have day "+dday+".");
			frmcontact.DateBD.focus();
			return;
	 }
	//END OF DATE OF BIRTH VALIDATION
	
	//ensure the email field is not empty
	if (trim(frmcontact.email.value) == "") {
		alert("Please enter your email address.")
		frmcontact.email.focus();
		return;
	}

	if (trim(frmcontact.email.value) != "") {
		if (!chkmail(frmcontact.email.value)) {
			alert("Please enter a valid email address.");
			frmcontact.email.focus();
			return;
		}
	}

	if (trim(frmcontact.address.value) == "") {
		alert("Please enter your address.")
		frmcontact.address.focus();
		return;
	}

	if (trim(frmcontact.postalcode.value) == "") {
		alert("Please enter your postalcode.")
		frmcontact.postalcode.focus();
		return;
	}

	if (!chknumber(frmcontact.postalcode.value)) {
		alert("Please enter only digits in the postalcode.")
		frmcontact.postalcode.focus();
		return;
	}

	if (trim(frmcontact.city.value) == "") {
		alert("Please enter your city.")
		frmcontact.city.focus();
		return;
	}

	if (trim(frmcontact.state.value) == "") {
		alert("Please enter your state.")
		frmcontact.state.focus();
		return;
	}

	if (frmcontact.country.value == "0") {
		alert("Please select your country.")
		frmcontact.country.focus();
		return;
	}

	if (trim(frmcontact.tel.value)==""){
		alert("Please enter your contact number.");
		frmcontact.tel.focus();
		return;
	}

	if (trim(frmcontact.fax.value) != "") {
		if (!chknumber(frmcontact.fax.value)) {
			alert("Please enter a valid fax number.")
			frmcontact.fax.focus();
			return;
		}
	}

	if (trim(frmcontact.mobile.value) != "") {
		if (!chknumber(frmcontact.mobile.value)) {
			alert("Please enter a valid mobile number.")
			frmcontact.mobile.focus();
			return;
		}
	}

	if (!chknumber(frmcontact.tel.value)) {
		alert("Please enter a valid contact number.");
		frmcontact.tel.focus();
		return;
	}
	
	frmcontact.submit();
}


function chksearch()	{

	if (trim(frmsearch.search.value) == "") {
		alert("Please enter title or author/publisher you like to search for.")
		frmsearch.search.focus();
		return;
	}

	frmsearch.submit();

}