function productInfo(id) {
	var newWindow = window.open("product-info.asp?id=" + id, "info", "height=500,width=350,scrollbars")
}

function checkRegForm(form) {
	var ok = true;
	if (form.userEmail.value == "") {
		ok = false;
		alert( "You must provide an Email address to register!" );
		form.userEmail.focus();
		form.userEmail.select();
	}
 	var FoundAt = form.userEmail.value.indexOf("@",0)
  	if (FoundAt < 1 && ok) {
     		ok = false
     		alert("You must provide a valid Email address to register!")
     		form.userEmail.focus()
     		form.userEmail.select()  
  	}
  	var FoundAt = form.userEmail.value.indexOf(".",0)
  	if (FoundAt < 1 && ok) {
     		ok = false
     		alert("You must provide a valid Email address to register!")
     		form.userEmail.focus()
     		form.userEmail.select()
  	}	
	else if (form.userPassword.value == "" ) {
		ok = false;
		alert( "You must provide a password to protect your details!" );
		form.userPassword.focus();
		form.userPassword.select();
	}
	else if (form.userConfPassword.value == "" ) {
		ok = false;
		alert( "Please confirm the password you have chosen." );
		form.userConfPassword.focus();
		form.userConfPassword.select();
	}
	else if (form.userPassword.value != form.userConfPassword.value) {
		ok = false;
		alert( "Your confirmation password does not match your password. Please re-enter it." );
		form.userConfPassword.focus();
		form.userConfPassword.select();
	}
	
	if (ok) {
		form.submit();
	}
}

function checkRegForm2(form) {
	var ok = true;
	if (form.firstname.value == "") {
		ok = false;
		alert( "You must provide a first name to ensure accurate delivery." )
		form.firstname.focus();
		form.firstname.select();
	}
	else if (form.surname.value == "") {
		ok = false;
		alert( "You must provide a family name to ensure accurate delivery." )
		form.surname.focus();
		form.surname.select();
	}
	else if (form.street.value == "") {
		ok = false;
		alert( "You must provide a street address to ensure accurate delivery." )
		form.street.focus();
		form.street.select();
	}
	else if (form.suburb.value == "") {
		ok = false;
		alert( "You must provide a suburb to ensure accurate delivery." )
		form.suburb.focus();
		form.suburb.select();
	}
	else if (form.postcode.value == "") {
		ok = false;
		alert( "You must provide a post code to ensure accurate delivery." )
		form.postcode.focus();
		form.postcode.select();
	}
	else if (form.postcode.value.length != "4") {
		ok = false;
		alert( "You must provide a valid 4 digit post code to ensure accurate delivery." )
		form.postcode.focus();
		form.postcode.select();
	}
	else if (isNaN(form.postcode.value)) {
		ok = false;
		alert( "You must provide a valid 4 digit post code to ensure accurate delivery." )
		form.postcode.focus();
		form.postcode.select();
	}
	else if (form.phone.value == "") {
		ok = false;
		alert( "You must provide a business hours contact number." )
		form.phone.focus();
		form.phone.select();
	}
	else if (form.dob.value == "") {
		ok = false;
		alert( "You must provide a date of birth." )
		form.dob.focus();
		form.dob.select();
	}	
	
	if (ok == true) {
		form.submit();
	}	
}

function checkRegForm3(form) {
	var ok = true;
	if ( form.ccnumber.value == "" ) {
		ok = false;
		alert( "You must provide a credit card number." )
		form.ccnumber.focus();
		form.ccnumber.select();
	}
	else if ( isNaN( form.ccnumber.value ) ) {
		ok = false
		alert( "You must provide a valid credit card number. Check the card and try again." )
		form.ccnumber.focus();
		form.ccnumber.select();
	}

	var today = new Date()
	var thisYear = today.getYear()
	thisYear = thisYear - 2000
	var formYear = form.ccexpiryy.value
	formYear = parseFloat( formYear )
	var thisMonth = today.getMonth()
	thisMonth = thisMonth + 1
	formMonth = parseFloat( form.ccexpirym.value )
	thisMonth = parseFloat( thisMonth )
	if ( formYear < thisYear ) {
			ok = false
			alert( "That year on the credit card has already passed. Please enter a valid year." )
			form.ccexpiryy.focus()
	}
	else if ( (formYear == thisYear) && ( thisMonth > formMonth ) ) {
			ok = false
			alert( "That date on the credit card has already passed. Please enter a valid date." )
			form.ccexpirym.focus()
	}
	
	/*  Credit card validator. Does Mod 10 Check */
    var isValid
	var cardNumberOnly = form.ccnumber.value.replace(/ /g,"");
	var cardNumberLength = cardNumberOnly.length;
	var numberProduct;
	var numberProductDigitIndex;
	var checkSumTotal = 0;
	
	for ( digitCounter = cardNumberLength - 1; digitCounter >= 0; digitCounter --)
	{
		checkSumTotal += parseInt( cardNumberOnly.charAt( digitCounter ) );
		digitCounter --;
		numberProduct = String( ( cardNumberOnly.charAt( digitCounter ) * 2 ) );
		for ( var productDigitCounter = 0; productDigitCounter < numberProduct.length; productDigitCounter ++ )
		{
			checkSumTotal += parseInt( numberProduct.charAt( productDigitCounter ) );
		}
	}
		
	isValid = ( checkSumTotal % 10 == 0 );
		
	if ( isValid == false )
	{
		ok = false;
		alert( "This is not a valid credit card number. Please check the number on your card and re-enter the digits." )
		form.ccnumber.focus();
		form.ccnumber.select();
	}	
	
	if (form.ccname.value == "" ) {
		ok = false
		alert( "You must provide a name for the credit account." )
		form.ccname.focus()
		form.ccname.select()
	}	
	
	if ( ok == true ) {
		form.submit();
	}
}
	
function Help( topic, section ) {
	var newWindow = window.open( "/con-help.asp?topic=" + topic + "&section=" + section, "help", "height=500,width=350,scrollbars" );
}

function ConfChoice( form, page ) {
	if ( page == "cart" ) {
		if ( confirm( "The Checkout Wizard will now begin.\nAre you sure you want to proceed to the checkout?" ) ) {
			form.submit();
		}
	}
	if ( page == "updatemember" ) {
		if (confirm( "Are you sure you want to change your details?" ) ) {
			form.submit()
		}
	}
}

function RegoWizard() {
	if ( confirm( "The Registration Wizard will now begin.\nBegin Wizard?" ) ) {	
		window.location = "https://www.jimscellars.com/ssl/register.asp?section=0";
	}
}	

function VerifySearch( form ) {
	search = true;
	if ( form.queryStr.value == "" ) {
		search = false;
		alert( "You must enter a value in the search field." );
		form.queryStr.focus();
		form.queryStr.select();
	}
	
	if ( search ) {
		form.submit();
	}
}

function CheckEmail() {
	var flag;
	var str = document.mailingListForm.EmailAddy.value;

	var ok = true;
	if ( str == "" ) {
		ok = false;
		alert( "You must provide an Email address!" );
	}
 	var FoundAt = str.indexOf("@",0)
  	if (FoundAt < 1 && ok) {
     		ok = false
     		alert("You must provide a valid Email address!")
  	}
  	var FoundAt = str.indexOf(".",0)
  	if (FoundAt < 1 && ok) {
     		ok = false
     		alert("You must provide a valid Email address!")
		
		
		//var pattern = /^([a-zA-Z0-9]) + ([\.a-zA-Z0-9_-]) *@ ([a-zA-Z0-9_-]) + (\.[a-zA-Z0-9_-]+)+/;
		//var flag = pattern.test( str );
		//if (!flag)
		//{
		//	alert( "Please Enter a valid Email Address" );
		//	return false;
		//}
		//else
		//{
		//	return true;
		//}
	}
	
	if ( ok )
	{
		return true;
	}
	else
	{
		return false;
	}	
}

function charges() {
	var newWindow = window.open("deliveryCalc.asp", "help", "height=300,width=350,scrollbars");
}

function removeEmail() {
	var newWindow = window.open("removeEmail.asp", "help", "height=300,width=350,scrollbars");
}
