//<script>

// Opening up a new window 
var objWin;			//hold a refernce to new window

function openWindow()
	{
	objWin = window.open("pop_up_frame.htm","new_win","resizable=yes," +
			 "scrollbars=yes,toolbar=no,location=no,directories=no,status=no," +
			 "menubar=no,width=500,height=300,top=5,left=5");
	objWinTimer = window.setTimeout("closeWindow()",60000);
	objWin.focus();
	}
	
function closeWindow()
	{
	objWin.close();
	}

function bringtofront()
	{
	objWin.focus();
	}
	
function shippers(vl)
	{
	if (isNaN(vl.value))
		{
		alert("Please enter a number");
		return false;
		}
		return true;	
	}		

function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}

function MM_findObj(n, d) { //v4.0
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && document.getElementById) x=document.getElementById(n); return x;
	}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}

	var expireDate = new Date
	expireDate.setMonth(expireDate.getMonth()+6)
	var ScrRes = ""
	if(document.cookie != "")
	{
	ScrRes = document.cookie.split("=")[1]
	}
	ScrRes = screen.availwidth
	document.cookie = "ScrRes="+ScrRes+";expires=" + expireDate.toGMTString()

// Opening up Currency Conversion window
function openWindowS(docref)
	{
	objWinS = window.open(docref,"new_win","resizable=yes," +
			 "scrollbars=no,toolbar=no,location=no,directories=no,status=no," +
			 "menubar=no,width=500,height=540,top=10,left=10");
	/*objWinTimer = window.setTimeout("closeWindowS()",600000);*/
	}

// Opening up CCV Info window
function openWindowC(docref)
	{
	objWinC = window.open(docref,"new_win","resizable=yes," +
			 "scrollbars=no,toolbar=no,location=no,directories=no,status=no," +
			 "menubar=no,width=380,height=430,top=10,left=10");
	}
	
	// Opening up FRInfo window
function openWindowFR()
	{
	var manselected;

	manselected = "http://www.dvdorchard.com.au/FRSignUp.asp";
	objWinFR = window.open(manselected,"new_win","resizable=yes," +
			 "scrollbars=no,toolbar=no,location=no,directories=no,status=no," +
			 "menubar=no,width=900,height=350,top=10,left=10");
	}

// Opening up Terms & Conditions window
function openWindowT(docref)
	{
	objWinC = window.open(docref,"new_win","resizable=yes," +
			 "scrollbars=yes,toolbar=no,location=no,directories=no,status=no," +
			 "menubar=no,width=500,height=500,top=10,left=10");
	}

function datestamp ()
	{
	var now = new Date ();
	var nowstr = new String ( now.toString() );
	var nowarr = nowstr.split (" ");
	return nowarr[2]+"-"+nowarr[1]+"-"+nowarr[nowarr.length-1];
	return "blah";
	}

function dts ()
	{
	var now = new Date ();
	var nowstr = new String ( now.toString() );
	var nowarr = nowstr.split (" ");
	return nowarr[2]+"-"+nowarr[1]+"-"+nowarr[nowarr.length-1]+" "+nowarr[3];
	}

function thisPage_onbeforeserverevent(obj, event )
	{
	if (obj=="btnSendContact")
	{
		if(event=="onclick")
		{
			var contact_name;
			contact_name = document.thisForm.Textbox3.value;
			if (contact_name.length < 1)
			{
				alert("Please enter your name");
			    document.thisForm.Textbox3.select();
				thisPage.cancelEvent = "true";
				return false;
			}
			var contact_details;
			contact_details = document.thisForm.Textbox4.value + document.thisForm.Textbox5.value + document.thisForm.Textbox6.value
			if (contact_details.length < 1)
			{
				alert("How do we get in touch with you?");
			    document.thisForm.Textbox4.select();
				thisPage.cancelEvent = "true";
				return false;
			}
			var email_address;
			email_address = document.thisForm.Textbox4.value;
			if (email_address.length > 1 && !validEmail(document.thisForm.Textbox4.value))
			{
				alert("Invalid E-Mail address characters or format");
				document.thisForm.Textbox4.select();
				thisPage.cancelEvent = "true";
				return false;
			}
			return true;
		}	
	}
	if (obj=="btnSendMailList")
	{
		if(event=="onclick")
		{
			var contact_name;
			contact_name = document.thisForm.Textbox3.value;
			if (contact_name.length < 1){
				alert("Please enter your name");
			    document.thisForm.Textbox3.select();
				thisPage.cancelEvent = "true";
				return false;
			}
			var contact_details;
			contact_details = document.thisForm.Textbox4.value;
				if (contact_details.length < 1){
				alert("Please enter your E-mail address");
			    document.thisForm.Textbox4.select();
				thisPage.cancelEvent = "true";
				return false;
			}
								
			var email_address;
			email_address = document.thisForm.Textbox4.value;
			if (email_address.length < 1){
				alert("Please enter your E-Mail address");
				document.thisForm.Textbox4.select();
				thisPage.cancelEvent = true;
				return false;
			}
			if (!validEmail(document.thisForm.Textbox4.value)){
				alert("Invalid E-Mail address characters or format");
				document.thisForm.Textbox4.select();
				thisPage.cancelEvent = true;
				return false;

			}
			return true;
			}	
		}
	if (obj=="btnUpdateQty")
		{
		window.status='Updating quantities now... Please wait a moment';
		}
	if (obj=="btnLogin")
		{
		window.status='Logging you in now ... Please wait a moment';
		}
	if (obj=="btnSave")
		{
		window.status='Processing your order now ..... Please wait a moment';
		
		if(event=="onclick")
		{
			var tcaccept;
			tcaccept = (document.thisForm.chkAcceptTC.checked);
			if (tcaccept == 0)
			{
				// if true
				alert("You must read and accept the Terms & Conditions prior to submitting this order.  After doing so please check the box above the Submit Order button.");
				document.thisForm.chkAcceptTC.focus();
				thisPage.cancelEvent = "true";
				return false;
			}
			var contact_var;
			contact_var = document.thisForm.firstname.value;
			if (contact_var.length < 1)
			{
				alert("Please enter your first name");
			    document.thisForm.firstname.select();
				thisPage.cancelEvent = "true";
				return false;
			}
			contact_var = document.thisForm.lastname.value;
			if (contact_var.length < 1)
			{
				alert("Please enter your last name");
			    document.thisForm.lastname.select();
				thisPage.cancelEvent = "true";
				return false;
			}
			contact_var = document.thisForm.dateofbirth.value;
			if (contact_var.length < 1)
			{
				alert("Please enter your Date Of Birth");
			    document.thisForm.dateofbirth.select();
				thisPage.cancelEvent = "true";
				return false;
			}
			contact_var = document.thisForm.accountname.value;
			if (contact_var.length < 1)
			{
				alert("Please enter your email address");
			    document.thisForm.accountname.select();
				thisPage.cancelEvent = "true";
				return false;
			}
			if (!validEmail(contact_var))
 			{
				// if false
				alert("Please enter a valid email address");
			    document.thisForm.accountname.select();
				thisPage.cancelEvent = "true";
				return false;
			}
			contact_var = document.thisForm.password.value;
			if (contact_var.length < 1)
			{
				alert("Please enter a password - 6 to 12 characters");
			    document.thisForm.password.select();
				thisPage.cancelEvent = "true";
				return false;
			}
			contact_var = document.thisForm.dayphonenumber.value;
			if (contact_var.length < 1)
			{
				alert("Please enter a day-time contact phone number");
			    document.thisForm.dayphonenumber.select();
				thisPage.cancelEvent = "true";
				return false;
			}
			contact_var = document.thisForm.street1.value;
			if (contact_var.length < 1)
			{
				alert("Please enter the first line of your street or postal address as corresponds to your billing address");
			    document.thisForm.street1.select();
				thisPage.cancelEvent = "true";
				return false;
			}
			contact_var = document.thisForm.city.value;
			if (contact_var.length < 1)
			{
				alert("Please enter the City corresponding to your billing address");
			    document.thisForm.city.select();
				thisPage.cancelEvent = "true";
				return false;
			}
			contact_var = document.thisForm.postcode.value;
			if (contact_var.length < 1)
			{
				alert("Please enter the Postcode or Zipcode corresponding to your billing address");
			    document.thisForm.postcode.select();
				thisPage.cancelEvent = "true";
				return false;
			}
			contact_var = document.thisForm.state.value;
			if (contact_var.length < 1)
			{
				alert("Please enter the State corresponding to your billing address");
			    document.thisForm.state.select();
				thisPage.cancelEvent = "true";
				return false;
			}
			contact_var = document.thisForm.shippingname.value;
			if (contact_var.length > 0)
			{
				// if true
				contact_var = document.thisForm.shippingstreet1.value;
				if (contact_var.length < 1)
				{
					// if true
					alert("As you have populated at least one of the Shipping Address details you now need to populate all the other relevant fields in the group");
					document.thisForm.shippingstreet1.select();
					thisPage.cancelEvent = "true";
					return false;
				}
				contact_var = document.thisForm.shippingcity.value;
				if (contact_var.length < 1)
				{
					// if true
					alert("As you have populated at least one of the Shipping Address details you now need to populate all the other relevant fields in the group");
					document.thisForm.shippingcity.select();
					thisPage.cancelEvent = "true";
					return false;
				}
			}
			var cardtype;
			cardtype = document.thisForm.mnuCreditCardType.value;
			if (cardtype == 0)
			{
				// if true
				alert("Please select the Credit Card type");
				document.thisForm.mnuCreditCardType.focus();
				thisPage.cancelEvent = "true";
				return false;
			}
			var cardnumber;
			cardnumber = document.thisForm.CreditCardNumber.value;
			if (cardnumber.length < 1)
			{
				// if true
				alert("Please enter your Credit Card number using only numbers - no spaces or other characters.");
				document.thisForm.CreditCardNumber.select();
				thisPage.cancelEvent = "true";
				return false;
			}
			if (!allDigits(cardnumber))
 			{
				// if false
				alert("Please re-enter your Credit Card number using only numbers - no spaces or other characters.");
				document.thisForm.CreditCardNumber.focus();
				thisPage.cancelEvent = "true";
				return false;
			}	
			if (!LuhnCheck(cardnumber) || !validateCCNum(cardtype,cardnumber))
			{
				// if false
				alert("The Credit Card number you have provided is invalid.  Please try again using only numbers - no spaces or other characters.");
				document.thisForm.CreditCardNumber.focus();
				thisPage.cancelEvent = "true";
				return false;
			}
			contact_var = document.thisForm.CreditCardValidNo.value;
			if (contact_var.length < 1)
			{
				// if true
				alert("Please enter your Credit Cards verification/security number - click on the links for information about this number if you are unsure.");
				document.thisForm.CreditCardValidNo.select();
				thisPage.cancelEvent = "true";
				return false;
			}
			if (contact_var.length < 3)
			{
				// if true
				alert("Please enter a valid Credit Card verification/security number - click on the links for information about this number if you are unsure.");
				document.thisForm.CreditCardValidNo.focus();
				thisPage.cancelEvent = "true";
				return false;
			}
			if (!allDigits(contact_var))
 			{
				// if false
				alert("Please re-enter your Credit Cards verification/security number using only numbers - 3 or 4 depending on your card. Click on the adjacent links for information about this number if you are unsure.");
				document.thisForm.CreditCardValidNo.focus();
				thisPage.cancelEvent = "true";
				return false;
			}	
			contact_var = document.thisForm.mnuCreditCardExpiryMonth.value;
			if (contact_var == 0)
			{
				// if true
				alert("Please select your Credit Cards expiry MONTH");
				document.thisForm.mnuCreditCardExpiryMonth.focus();
				thisPage.cancelEvent = "true";
				return false;
			}
			contact_var = document.thisForm.mnuCreditCardExpiryYear.value;
			if (contact_var == 0)
			{
				// if true
				alert("Please select your Credit Cards expiry YEAR");
				document.thisForm.mnuCreditCardExpiryYear.focus();
				thisPage.cancelEvent = "true";
				return false;
			}
			contact_var = document.thisForm.CreditCardName.value;
			if (contact_var.length < 1)
			{
				// if true
				alert("Please enter the name on your credit card (not your banks name - your name)");
				document.thisForm.CreditCardName.select();
				thisPage.cancelEvent = "true";
				return false;
			}
			return true;
			}
		}		
	}
	
//reloads the window if Nav4 resized
function MM_reloadPage(init)
	{
	if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
	}
	MM_reloadPage(true);

// Checking format of an e-mail entry
function validEmail(email) {
	var invalidChars, badChar, atPos, periodPos;
	var i;
	invalidChars = " /:,;";
	if (email == ""){
		return false;
	}
	for (i=0; i<invalidChars.length; i++)
		{
		badChar = invalidChars.charAt(i);
		if (email.indexOf(badChar,0) != -1){
			return false;
		}
	}
	atPos = email.indexOf("@",1);
	if (atPos == -1){
		return false;
	}
	if (email.indexOf("@",atPos+1) != -1){
		return false;
	}
	periodPos = email.indexOf(".",atPos);
	if (periodPos == -1){
		return false;
	}
	if (periodPos+3 > email.length){
		return false;
	}
	return true;
	}
	
	// Format Money Value
	var WGdc=".";  var WGgc=",";  var WGnc="(";  var WGcs="$";

function FormatMoneyJS(A,W)
	{
	var N=Math.abs(Math.round(A*100));
	var S=((N<10)?"00":((N<100)?"0":""))+N;
	S=WGcs+((A<0)?WGnc:"")+WGgroup(S.substring(0,(S.length-2)))+WGdc+S.substring((S.length-2),S.length)+((A<0&&WGnc=="(")?")":"");
	return (S.length>W)?"Over":S;
	}
	
function WGgroup(S)
	{
	return (S.length<4)?S:(WGgroup(S.substring(0,S.length-3))+WGgc+S.substring(S.length-3,S.length));
	}	

//Check entry in textbox is a number
function CheckIsNumber(txtbx,msg1,msg2)
	{
	var cin;
	cin = txtbx.value;
	if (cin.length < 1)
		{
		alert(msg1);
	    txtbx.select();
		thisPage.cancelEvent = "true";
		return false;
		}
	for (i=0; i<cin.length; i++)
		{
		if (cin.charAt(i) > "9")
			{
			alert(msg2);
		    txtbx.select();
			thisPage.cancelEvent = "true";
			return false;
			}
		if (cin.charAt(i) < "0")
			{
			alert(msg2);
		    txtbx.select();
			thisPage.cancelEvent = "true";
			return false;
			}
		}
	}

//Check entry in textbox is a number greater than 0
function CheckIsNumbergt0(txtbx,msg1,msg2)
	{
	var cin;
	cin = txtbx.value;
	if (cin.length < 1)
		{
		alert(msg1);
	    txtbx.select();
		thisPage.cancelEvent = "true";
		return false;
		}
	for (i=0; i<cin.length; i++)
		{
		if (cin.charAt(i) > "9")
			{
			alert(msg2);
		    txtbx.select();
			thisPage.cancelEvent = "true";
			return false;
			}
		if (cin.charAt(i) < "1")
			{
			alert(msg2);
		    txtbx.select();
			thisPage.cancelEvent = "true";
			return false;
			}
		}
	}

//Check entry in textbox is a number
function CheckSomething(txtbx,msg1)
	{
	var cin;
	cin = txtbx.value;
	if (cin.length < 1)
		{
		alert(msg1);
	    txtbx.select();
		thisPage.cancelEvent = "true";
		return false;
		}
	}

function AddToFaves_hp()
	{
	var is_4up = parseInt(navigator.appVersion);
	var is_mac   = navigator.userAgent.toLowerCase().indexOf("mac")!=-1;
	var is_ie   = navigator.userAgent.toLowerCase().indexOf("msie")!=-1;
	var thePage = location.href;
	if (thePage.lastIndexOf('#')!=-1)
		thePage = thePage.substring(0,thePage.lastIndexOf('#'));
	if (is_ie && is_4up && !is_mac) 
		window.external.AddFavorite(thePage,document.title);
	else if (is_ie || document.images)
		booker_hp = window.open(thePage,'booker_','menubar,width=325,height=100,left=140,top=60');
	}

function allDigits(str)
	{
	return inValidCharSet(str,"0123456789");
	}

function allDigits2(str)
	{
	return inValidCharSet(str,",0123456789");
	}

function inValidCharSet(str,charset)
	{
	var result = true;
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	return result;
	}

function LuhnCheck(str) 
	{
	var result = true;
	var sum = 0; 
	var mul = 1; 
	var strLen = str.length;
  
	for (i = 0; i < strLen; i++) 
	{
    var digit = str.substring(strLen-i-1,strLen-i);
    var tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
		sum += (tproduct % 10) + 1;
    else
		sum += tproduct;
    if (mul == 1)
		mul++;
    else
		mul--;
	}
	if ((sum % 10) != 0)
		result = false;
		return result;
	}

function GetRadioValue(rArray)
	{
	for (var i=0;i<rArray.length;i++)
		{
		if (rArray[i].checked)
			return rArray[i].value;
		}
	return null;
	}

function validateCCNum(cardtype,cardNum)
	{
	var result = false;
	var cardLen = cardNum.length;
	var firstdig = cardNum.substring(0,1);
	var seconddig = cardNum.substring(1,2);
	var first4digs = cardNum.substring(0,4);

	switch (cardtype)
		{
		case "1":
			result = ((cardLen == 16) || (cardLen == 13)) && (firstdig == "4");
			break;
		case "2":
			var validNums = "12345";
			result = (cardLen == 16) && (firstdig == "5") && (validNums.indexOf(seconddig)>=0);
			break;
		case "3":
			var validNums = "47";
			result = (cardLen == 15) && (firstdig == "3") && (validNums.indexOf(seconddig)>=0);
			break;
		case "4":
			var validNums = "068";
			result = (cardLen == 14) && (firstdig == "3") && (validNums.indexOf(seconddig)>=0);
			break;
		case "5":
			var validNums = "6";
			result = (cardLen == 16) && (firstdig == "5") && (validNums.indexOf(seconddig)>=0);
			break;
		}
	return result;
	}
