// JavaScript Document
// whole form check
function checkBooking(theForm) {
    var why = "";
	why += checkName(theForm.name.value);
	why += checkEmail(theForm.email.value);
	why += checkEmail2(theForm.confirm_email.value, theForm.email.value);
	why += checkPhone(theForm.phone.value);	
	
	for (i=0, n=theForm.availability_checkbox.length; i<n; i++) {
		if (theForm.availability_checkbox[i].checked) {
			var checkLocale = theForm.availability_checkbox[i].value;
			break;
		} 
	}
	why += checkLocation(checkLocale);	
	why += checkComment(theForm.note_narrow.value);
	if (why != "") {
		alert("There was a problem with your booking enquiry:\n\n"+ why);
		return false; 
	}
return true;
}


function checkDownload(theForm) {
		//alert("There was a problem with your booking enquiry:\n\n"+ why);

	var why = "";
	why += checkName(theForm.FullName.value);
	why += checkEmail(theForm.email.value);
	why += checkInstitution(theForm.Institution.value);

	if (why != "") {
		alert("There was a problem with your form:\n\n"+ why);
		return false; 
	}
return true;
}

function checkPurchaseASSORT(theForm) {
		//alert("There was a problem with your booking enquiry:\n\n"+ why);

	var why = "";
	why += checkName(theForm.FullName.value);
	why += checkEmail(theForm.email.value);
	why += checkInstitution(theForm.Institution.value);

		//alert("payment: "+ theForm.payment.value);
	
	// credit card check
//	for (i=0, n=theForm.payment.length; i<n; i++) {
//		if (theForm.payment[i].checked) {
//			var paymentType = theForm.payment[i].value;
//			break;
//		} 
//	}

//	if (paymentType == "credit card") {
//		why += checkCCType(theForm.cc_type.value);
//		why += checkCCName(theForm.cc_name.value);
		//why += checkCCNumber(theForm.cc_num1.value);
//		why += checkCCNumber(theForm.cc_num1.value + theForm.cc_num2.value + theForm.cc_num3.value + theForm.cc_num4.value);
//		why += checkCCExpiry(theForm.cc_exp_mm.value);
//	}
	

	if (why != "") {
		alert("There was a problem with your form:\n\n"+ why);
		return false; 
	}
return true;
}


// individual validation routines
function checkCCExpiry (strng) {
var error = "";
if (strng.length != 2) {
   error = "You must enter the full expiry date of your credit card.\n";
	}
return error;
}

function checkCCNumber (strng) {
var error = "";
if (strng.length != 16) {
   error = "You must enter all of the numbers on your credit card.\n";
	}
return error;
}

function checkCCName (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter the name on your credit card.\n";
	}
return error;
}

function checkCCType (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your credit card type.\n";
	}
return error;
}


function checkName (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your name.\n";
	}
return error;
}


function checkInstitution (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your Institution or company.\n";
	}
return error;
}

function checkEmail (strng) {
var error = "";
var emailFilter=/^.+@.+\..{2,3}$/;
	if (strng =="") {
		error = "You didn't enter an email address.\n";
		return error;
	} 
	if (!(emailFilter.test(strng))) { 
		error = "Please enter a valid email address.\n";
	}
return error;
}

function checkEmail2 (strng, strng2) {
var error = "";
var emailFilter=/^.+@.+\..{2,3}$/;
	if (strng =="") {
		error = "You didn't confirm your email address.\n";
		return error;
	} 
	if (!(strng == strng2)) { 
		error = "Your confirmed email address doesn't match.\n";
	}
return error;
}

function checkLocation(checkvalue)  {
var error = "";
   if (!(checkvalue)) {
       error = "You didn't enter your preferred location.\n";
    }
return error;    
}

function checkComment(checkvalue)  {
var error = "";
   if (checkvalue.length> 250) {
       error = "Please limit your comments to under 250 characters.\n";
    }
return error;    
}

function checkBHPhone(strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your business hours telephone number.\n";
	}
return error;
}

function checkPhone(strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your telephone number.\n";
	}
return error;
}



function total(price)
{
	var orderForm = document.orderForm;
  
	if(price == 0)
	{
        price = 900;
        if(orderForm.radNOPATIENTS[1].checked)
          {
            price = 1850;
          }
        else if(orderForm.radNOPATIENTS[2].checked)
          {
            price = 1300;
          }
        else if(orderForm.radNOPATIENTS[3].checked)
          {
            price = 2250;
          }
        else if(orderForm.radNOPATIENTS[4].checked)
          {
            price = 1550;
          }
        else if(orderForm.radNOPATIENTS[5].checked)
          {
            price = 2500;
          }
	}

    if(orderForm.NoCopies.value != "")
    {
        orderForm.Total.value = parseInt(orderForm.NoCopies.value) * price;
    } else {
        orderForm.Total.value = price;
    }
}

function nextbox(fldobj,nbox) { 
if(fldobj.value.length>3) { 
document.forms[0].elements[nbox].focus() 
} 
} 
