function showpayment(Toggle){
	if (Toggle=="Cheque"){
		document.getElementById("cc").style.display = 'none';
		document.getElementById("chq").style.display = 'block';		
	} else if (Toggle=="Select Payment Type"){
		document.getElementById("cc").style.display = 'none';
		document.getElementById("chq").style.display = 'none';
	} else {
		document.getElementById("cc").style.display = 'block';
		document.getElementById("chq").style.display = 'none';
	}
}
function cardcheck(theForm){

	var cc;
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

	if (theForm.Name.value.toUpperCase()=="TEST USER"){
		return true;
	}

	if(theForm.Name.value.length<5){
		alert("You must enter your name (a minimum of 5 letters required)");
		theForm.Name.focus();
		return false;
	}
	
	if(reg.test(theForm.Email.value)==false||theForm.Email.value.length<5) {
		alert("You must enter a valid email address - an order confirmation will be sent to this address.");
		theForm.Email.focus();
		return false;
	}

	if(theForm.Address.value.length<25){
		alert("You must enter a delivery address (a minimum of 25 letters required)");
		theForm.Address.focus();
		return false;
	}

	if(theForm.PayMethod.options[theForm.PayMethod.selectedIndex].value=="Cheque")
		return true;
	else
		if(theForm.PayMethod.options[theForm.PayMethod.selectedIndex].value=="Select Payment Type"){
			alert("You must select a payment type");
			return false;
		} else {
			if (theForm.CardType.options[theForm.CardType.selectedIndex].value=="Please Select"){
				alert("You must select a Credit/Debit card type");
				theForm.CardType.focus();
				return false;
			}

			if (theForm.CardNumber.value.length!=0){
				cc = parseInt(theForm.CardNumber.value);
			} else {
				alert("You have not filled in your Credit/Debit card number")
				theForm.CardNumber.focus();
				return false;
			}
				
			if (cc!=theForm.CardNumber.value){
				alert("Credit/Debit card number contains unrecognised characters (e.g. should not contain spaces)");
				theForm.CardNumber.focus();
				return false;
			} 
			
			if (theForm.CardNumber.value.length<12||theForm.CardNumber.value.length>19){
				alert("Credit/Debit card number does not appear to be a valid length... please re-enter the long number from the front of your card");
				theForm.CardNumber.focus();
				return false;
			}
					
			if (theForm.CardExpires.value.length!=4){
				alert("Your card expiry date is missing or incorrect.");
				theForm.CardExpires.focus();
				return false;
			}
			
			if (theForm.CardHoldersName.value.length<3){
				alert("The card holder's name is missing or too short (at least 3 letters required)");
				theForm.CardHoldersName.focus();
				return false;
			}
				
			if (theForm.CardSecurityNo.value.length!=3){
				alert("Please re-enter the last 3 numbers from the end of your Credit/Debit card's security strip.");
				theForm.CardSecurityNo.focus();
				return false;
			}
		}	
	return true;
}

function Validate(myform, minQ, multiQ) {
	if(myform.Colour.selectedIndex < 0){	
    alert("Please select one of the \"Colour\" / \"Option\" choices.");
    myform.Colour.focus();
    return(false);
  }
  if(myform.Colour.value == "Make Selection"){
    alert("The first \"Colour\" option is not a valid selection.  Please choose one of the other options.");
    orderform.Colour.focus();
    return(false);
  } 
  if(myform.Quantity.value < minQ){
    alert("The quantity specified is below the minimum quantity of " + minQ + " allowed for this product.");
	myform.Quantity.value = minQ;
    myform.Quantity.focus();
    return(false);
  } 
  if(myform.Quantity.value % multiQ){
	correction = Math.ceil(myform.Quantity.value / multiQ) * multiQ;
    alert("This product can only be ordered in quantities which are valid multiples of " + multiQ +". You will need to order " + correction + " of this product to secure the quantity you had requested. This has been changed for you, please REVIEW and CHANGE if required.");
	myform.Quantity.value = correction;
    myform.Quantity.focus();
    return(false);
  } 
  return(true);
}
function submitorder(myform)
{
    if(myform.onsubmit && !myform.onsubmit())
    {
        return;
    }
 	myform.submit();
}
function trim(str) {
	str.replace(new RegExp("^[\\s]+", "g"), "");
	return str.replace(new RegExp("[\\s]+$", "g"), "");
}

String.prototype.charCount = function () {return this.replace(/[\n\r\n]+/g, '').length}
String.prototype.lineCount = function () {return this.replace(/[\n\r\n]+/g, ' ').length - this.replace(/[\n\r\n]+/g, '').length + 1}

function textCounter(field,charfield,linefield) {

	if ((charfield.value = field.value.charCount()) != 0) {
			tstr = trim(field.value); 
			linefield.value = tstr.lineCount() 
	} else linefield.value = 0
}
