


// JavaScript Document

function isNumeric(pccharinput) {  // 1) this allows the numbers 0-9
	return(pccharinput>="0" && pccharinput<="9")
}

function isAlphabetic(pccharinput) { // 2) this allows the letters A-Z & a-z
	return((pccharinput>="A" && pccharinput<="Z") || 
		(pccharinput>="a" && pccharinput<="z"))
}

function isAlphaNumeric(pccharinput) { //  3) this allows 1) & 2) from above to be put together
	return (isAlphabetic(pccharinput) || isNumeric(pccharinput))
}

function isEmpty(pccharinput) { // checks for any empty fields in the HTML form
	if (pccharinput=="" || pccharinput==" ")
	return true
	else return false
	}


//////////////////////////////////////////////////////////////////////////


function isNameChar(pccharinput) {  // this is all the alphabet and the special characters for the name
	return (isAlphabetic(pccharinput) || isNameSpecialChar(pccharinput))
}

//alert(isNameChar("michelle'hgf"))
function isNameSpecialChar(pccharinput) {  // these are the special characters allowed for the name
	return (pccharinput=="'" || pccharinput=="-" || pccharinput==" ")
}


function isNameString(pcstrInput) {  

	var w, lvintapostrophepos, lvintdashpos, lvintspacepos
	
	lvintapostrophepos=pcstrInput.indexOf("'")
	lvintdashpos=pcstrInput.indexOf("-")
	lvintspacepos=pcstrInput.indexOf(" ")
	
	for (w=0; w<pcstrInput.length; w++) {
	
		if (!isNameChar (pcstrInput.charAt(w)))
		{ 
			return false
		}
	}
	
	if (lvintapostrophepos==0)  // if ' is at postion 0 it's false
		return false
	if (lvintdashpos==0) // if - is at postion 0 it's false
		return false
	if (lvintspacepos==0) // if there is a space at 0 it's wrong
		return false
	if (isEmpty(pcstrInput))  // if the text field is empty it will return false
		return false
	return true
} 

///////////////////////////////////////////////////////////

function isEmailSpecialChar(pccharinput) {
	return (pccharinput=="@" || pccharinput=="-" || pccharinput=="_" || pccharinput==".")
}

function isEmailChar(pccharinput) {  // allows numbers, alphabets and the special email characters from above.
	return (isAlphaNumeric(pccharinput) || isEmailSpecialChar(pccharinput))
}

function isEmailString (pcstrInput) { 

	var w, lvintlength, lvintlastpos, lvintatpos, lvintatlastpos, lvintfirstpos

	lvintlength=pcstrInput.length
	lvintlastpos=pcstrInput.lastIndexOf(".")
	lvintatpos=pcstrInput.indexOf("@")
	lvintfirstpos=pcstrInput.indexOf(".")
	lvintatlastpos=pcstrInput.lastIndexOf("@")
	
	
	for (w=0; w<pcstrInput.length; w++) 
	{ 
		if (!isEmailChar (pcstrInput.charAt(w)))
		{ 
			return false
		} 
	} 	

	if(lvintatpos==0) // if @ is = 0 it's false.
		return false

	if (lvintlastpos==0) // if last . is = 0 it's wrong
		return false

	if (lvintfirstpos==0) // if . is = to 0 it's wrong
		return false

	if (lvintatlastpos==-1) // there is no @ in the email address
		return false

	if (lvintfirstpos==-1) // there is no . in the email address
		return false

	if (pcstrInput.indexOf("@.")!=-1) // this means the @. are not = to -1 (basically if there is @ and. together it returns false.)
		return false
		
	if (pcstrInput.indexOf(".@")!=-1) //there are .@ together
		return false
		
	if (pcstrInput.indexOf("@@")!=-1) // two @@ together
		return false
		
	if (pcstrInput.indexOf("..")!=-1) // this means the two .. are not = to -1 (basically if there are 2 .. it returns false.)
		return false

	if(lvintlength-lvintlastpos<3) // there are not two letters after the last .
		return false
	 
	return true
} 

//////////////////////////////////////////////////////////////////////////////////
function isCurrencyChar(pccharInput) {  // allows numbers and dots in the currency
	return (isNumeric(pccharInput) || pccharInput==".")
}

function isCurrencyString(pcstrInput) { 

	var i
	for (i=0; i<pcstrInput.length; i++) 
	{  
		if (!isCurrencyChar (pcstrInput.charAt(i)))  
		{  
			return false
		}  
	} 
	return true
}  

function isCurrencyFormat(pcstrInput) {   
 	var lvintlength, lvintdotpos
 
 	lvintlength=pcstrInput.length
	lvintdotpos=pcstrInput.lastIndexOf(".")
	
	//if(lvintdotpos!=-1 && lvintlength-lvintdotpos>5) // there can only be 4 numbers after the last dot.
	if (lvintlength-lvintdotpos>3) // there can only be 2 digits after the last decimal place
		//alert("There can only be two digits after the last decimal number")
		return false
	return true
}

function currency(pcstrInput) {  // if it is not isCurrencyString, isCurrencyFormat & isEmpty make this false
 	if (isCurrencyString(pcstrInput) && isCurrencyFormat(pcstrInput) && (!isEmpty(pcstrInput)))
		return true
	else return false
}

//////////////////////////////////////////////////////////////////////////
	
function isSelect(pcobjElem){  // if the dropdown box is at selected index 0 then it returns false (this is only used for the country)
	if(pcobjElem.selectedIndex == 0)
		return false
	else
		return true
}

///////////////////////////////////////////////////////////////////////////////////

function isDateChar(pccharinput) { // checks that only numbers and the - can be used
	return (isNumeric(pccharinput) || pccharinput=="-")
}


function isDateString(pcstrInput) {  

	var i, lvintlength, lvintdashpos, lvintlastdashpos, lvintSpacepos
	
	lvintlength=pcstrInput.length
	lvintdashpos=pcstrInput.indexOf("-")
	lvintlastdashpos=pcstrInput.lastIndexOf("-")
	lvintSpacepos=pcstrInput.indexOf(" ")
	
	for (i=0; i<pcstrInput.length; i++) 
	{  
		if (!isDateChar (pcstrInput.charAt(i)))
		{  
			return false
			
	if(lvintdashpos==-1) {  //there is no - in the text field
		//alert("There is no dash in the feild. Please enter again.")
		return false
		}
	else if (lvintSpacepos!=-1) {  // no spaces are allowed
		//alert("No spaces are allowed. Please try again")
		return false
		}
	
	else if(lvintlastdashpos!=5) {  //There's no - in No. 5 of the date
		return false
		}
		
	else if(lvintdashpos!=2) {  //There's no - in No. 2 of the date
		return false
		}
	}  
} 
	return true
}  				



function isLeapYear(yyyy) {  
	return (yyyy%100!=0 && yyyy%4==0 || yyyy%400==0)
}
	
function isValidDate(pcstrDate) {  
	
	var dd=pcstrDate.substr(0, 2)
	var mm=pcstrDate.substr(3, 2)
	var yyyy=pcstrDate.substr(6, 4)
	var monthAmountArray=new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
	var monthArray=new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
	//var monthNoArray=new Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12") 
	
if (!((mm>=1) && (mm<=12))){  
		alert("There are only 12 months in a year.")						
		return false
		}
else if ((mm==04 || mm==06 || mm==09 || mm==11) && !(dd>=1 && dd<=30)) { 
		alert("There are only 30 days in " + monthArray[mm-1])
		return false
		}
else if ((mm==01 || mm==03 || mm==05 || mm==07 || mm==08 || mm==10 || mm==12) && !(dd>=1 && dd<=31)) {
		alert("There are only 31 days in " + monthArray[mm-1])
		return false
		}
else if (mm==02){
		if (isLeapYear(yyyy)) {
			if(!(dd>=1 && dd<=29)) {
				alert("Feburary has 29 days in the year " + yyyy)
				return false
				}
		}
		else if(!(dd>=1 && dd<=28)) {
			alert("Feburary has 28 days in the year " + yyyy)
			return false
		}
	}
 return true
} 
	
function isDate(pcstrDate) {   // if the text field is empty, is not the datestring and is not the vaild date it's wrong
	
	if (isEmpty(pcstrDate)) {
		return false
	}
	
	else if (!isDateString(pcstrDate)) {
		return false
		}
			
	else if (!isValidDate(pcstrDate)) {
		return false
		}	
	
	else return true
}

//////////////////////////////////////////////////////////////////



/*function isUpdateQty(obj, frm) {
	//alert("here")
	//alert(obj.value)
	if (!isNumeric(obj.value)) {
		alert("Please enter a quantity to continue")
		obj.focus();
		obj.select();
		return false;
	}
	frm.submit()
}
*/



function isAddToCart(obj, frm) {  // this checks there is a number in the qty
	if (!isNumeric(obj.value)) {
		alert("Please enter a number to continue ordering.")
		obj.focus();
		obj.select();
		return false;
	}
}






function isLogin() {
 	if (!isEmailString(document.Login.Username.value)) {
		alert("Please enter a correct email address.")
		document.Login.Username.focus();
		document.Login.Username.select();
		return false;
		}
		
	if (document.Login.Password.value=="") {
		alert("Please enter a password")
		document.Login.Password.focus();
		return false;
		}	
		
 }	
 
function isGiftVoucher() {
	if (document.gift.GiftPrice.value==0) {
		alert("Please enter a price for the gift voucher")
		document.gift.GiftPrice.focus();
		return false;
	}
}

function isAddContact() { 
	if (!isNameString(document.register.FName.value)) {
		alert("Please enter a correct first name.")
		document.register.FName.focus();
		document.register.FName.select();
		return false;
		}

	if (!isNameString(document.register.LName.value)) {
		alert("Please enter a correct last name.")
		document.register.LName.focus();
		document.register.LName.select();
		return false;
		}

	if (!isEmailString(document.register.Email.value)) {
		alert("Please enter a correct email address.")
		document.register.Email.focus();
		document.register.Email.select();
		return false;
		}
}

function isRegisterForm() {


	if (document.register.BillingStreet.value=="") {
		alert("Street address is a required field");
		document.register.BillingStreet.focus();
		return false;
	}

	if (document.register.BillingSuburb.value=="") {
		alert("Suburb is a required field");
		document.register.BillingSuburb.focus();
		return false;
	}
	
	if (document.register.BillingCity.value=="") {
		alert("City is a required field");
		document.register.BillingCity.focus();
		return false;
	}

	if (document.register.BillingCountry.value=="") {
		alert("Country is a required field");
		document.register.BillingCountry.focus();
		return false;
	}
	
	if (document.register.ShippingAddressFName.value=="" && document.register.ShippingAddressLName.value!="") {
		alert("Please enter a first name.");
		document.register.ShippingAddressFName.focus();
		return false;
	}
	
	if (document.register.ShippingAddressFName.value!="" && document.register.ShippingAddressLName.value=="") {
		alert("Please enter a last name.");
		document.register.ShippingAddressLName.focus();
		return false;
	}
}


function isContactForm() {
	if (document.enquiry.name.value=="") {
		alert("Please enter your name.");
		document.enquiry.name.focus();
		return false;
	}
	
	if (!isEmailString(document.enquiry.Email.value)) {
		alert("Please enter a valid email address.");
		document.enquiry.Email.focus();
		document.enquiry.Email.select();
		return false;
	}
	
	if (document.enquiry.comments.value=="") {
		alert("Please enter some comments.");
		document.enquiry.comments.focus();
		return false;
	}
}

function isSubscriber() {
	if (document.newsletter.FName.value=="") {
		alert("Your name is required");
		document.newsletter.FName.focus();
		return false;
	}
	
	if (!isEmailString(document.newsletter.Email.value)) {
		alert("Your email address is required.");
		document.newsletter.Email.focus();
		document.newsletter.Email.select();
		return false;
	}
}

 function isUnsubscribe() {
	
	if (document.Unsubscribe.FName.value=="") {
		alert("Please enter a name")
		document.Unsubscribe.FName.focus();
		return false;
		}
		
	if (document.Unsubscribe.Email.value=="") {
		alert("Please enter an email address")
		document.Unsubscribe.Email.focus();
		return false;
		}
		
	if (!isEmailString(document.Unsubscribe.Email.value)) {
		alert("Please enter a correct email address. This email is invalid.")
		document.Unsubscribe.Email.focus();
		document.Unsubscribe.Email.select();
		return false;
	}
}

function isGiftOption() {
	if (document.giftOption.FName.value=="") {
		alert("Please enter a name")
		document.giftOption.FName.focus();
		return false;
		}
		
	if (document.giftOption.Email.value=="") {
		alert("Please enter an email address")
		document.giftOption.Email.focus();
		return false;
		}
		
	if (!isEmailString(document.giftOption.Email.value)) {
		alert("Please enter a correct email address. This email is invalid.")
		document.giftOption.Email.focus();
		document.giftOption.Email.select();
		return false;
	}
	//alert(document.giftOption.recipient.selectedIndex)
	
	if (document.giftOption.recipient.selectedIndex == 0) {
		alert("Please enter a recipient. If you are unsure about the recipient choose other.")
		document.giftOption.recipient.focus();
		return false;
	}
	
	if (document.giftOption.occasion.value == 0) {
		alert("Please enter an occasion. If you are unsure about the occasion choose other.")
		document.giftOption.occasion.focus();
		return false;
	} 
	
	//rangefrom=priceLow
	//rangeto=priceHigh
	
	//alert("priceLow: "+document.giftOption.priceLow.value)
	//alert("priceHigh: "+document.giftOption.priceHigh.value)
	
	// require that the To Field be greater than or equal to the From Field
	//var priceLow = document.giftOption.priceLow.value;
	//var priceHigh = document.giftOption.priceHigh.value;
	//if (priceLow <= priceHigh){
		//alert("wrong");
		//document.giftOption.priceHigh.focus();
		//return false;
	//}
	
}


function isCustomerForm() {
	 if (document.register.FName.value=="") {
		alert("Please enter your first name.")
		document.register.FName.focus();
		return false;
		}
		
	if (isEmpty(document.register.LName.value)) {
		alert("Please enter your last name.")
		document.register.LName.focus();
		return false;
		}
		
	if (isEmpty(document.register.Email.value)) {
		alert("Please enter an email address.")
		document.register.Email.focus();
		return false;
		}
	
 	if (!isEmailString(document.register.Email.value)) {
		alert("Please enter a correct email address.")
		document.register.Email.focus();
		document.register.Email.select();
		return false;
		}	

	if (document.register.Phone.value=="") {
		alert("Please enter a phone number.")
		document.register.Phone.focus();
		return false;
		}
}




function isAddStep2Details() {
   	
	if (isEmpty(document.updateDetails.AddressFName.value)) {
		alert("Please enter a first name for the recipient.")
		document.updateDetails.AddressFName.focus();
		document.updateDetails.AddressFName.select();
		return false;
		}
		
	if (isEmpty(document.updateDetails.AddressLName.value)) {
		alert("Please enter a last name for the recipient.")
		document.updateDetails.AddressLName.focus();
		document.updateDetails.AddressLName.select();
		return false;
		}
		
	if (isEmpty(document.updateDetails.Phone.value)) {
		alert("Please enter a phone number for the recipient.")
		document.updateDetails.Phone.focus();
		document.updateDetails.Phone.select();
		return false;
		}

	
	if (isEmpty(document.updateDetails.Street.value)) {
		alert("Please enter a street address.")
		document.updateDetails.Street.focus();
		document.updateDetails.Street.select();
		return false;
		}

		
   	if (isEmpty(document.updateDetails.City.value)) {
		alert("Please enter a city.")
		document.updateDetails.City.focus();
		document.updateDetails.City.select();
		return false;
		}
		
   /* 	if (document.updateDetails.Country.value=="") {
		alert("Please enter a country.")
		document.updateDetails.Country.focus();
		return false;
		} */
		
	if (document.updateDetails.FreightRegionId.value==0) {
		alert("Please select a delivery region.")
		document.updateDetails.FreightRegionId.focus();
		return false;
		}
		
	/* if (isEmpty(document.updateDetails.Deliver.value)) {
		alert("Please enter a delivery date.")
		document.updateDetails.Deliver.focus();
		document.updateDetails.Deliver.select();
		return false;
	}
	
	if (!isDate(document.updateDetails.Deliver.value)) {
		alert("Please enter a correct date");
		document.updateDetails.Deliver.focus();
		document.updateDetails.Deliver.select();
		return false;
	}
	
	if (isEmpty(document.updateDetails.message.value)) {
		alert("Please enter your personal message.")
		document.updateDetails.message.focus();
		document.updateDetails.message.select();
		return false;
	} */
	return true;
 }
 

function isupdateStep2Details() {
   if (isEmpty(document.updateDetails.AddressFName.value)) {
		alert("Please enter a first name for the recipient")
		document.updateDetails.AddressFName.focus();
		document.updateDetails.AddressFName.select();
		return false;
		}
		
	if (isEmpty(document.updateDetails.AddressLName.value)) {
		alert("Please enter a last name for the recipient.")
		document.updateDetails.AddressLName.focus();
		document.updateDetails.AddressLName.select();
		return false;
		}
		
	if (isEmpty(document.updateDetails.Phone.value)) {
		alert("Please enter a phone number for the recipient.")
		document.updateDetails.Phone.focus();
		document.updateDetails.Phone.select();
		return false;
		}
   
   if (isEmpty(document.updateDetails.Street.value)) {
		alert("Please enter a street address.")
		document.updateDetails.Street.focus();
		document.updateDetails.Street.select();
		return false;
		}

		
   	if (isEmpty(document.updateDetails.City.value)) {
		alert("Please enter a city.")
		document.updateDetails.City.focus();
		document.updateDetails.City.select();
		return false;
		}
		
   	if (isEmpty(document.updateDetails.Country.value)) {
		alert("Please enter a country.")
		document.updateDetails.Country.focus();
		document.updateDetails.Country.select();
		return false;
		}
		
	if (document.updateDetails.FreightRegionId.value==0) {
		alert("Please choose a region where the gifts will be delivered to.")
		document.updateDetails.FreightRegionId.focus();
		return false;
		}
		
	/*if (isEmpty(document.updateDetails.Deliver.value)) {
		alert("Please enter a delivery date.")
		document.updateDetails.Deliver.focus();
		document.updateDetails.Deliver.select();
		return false;
	}
	
	if (!isDate(document.updateDetails.Deliver.value)) {
		alert("Please enter a correct date");
		document.updateDetails.Deliver.focus();
		document.updateDetails.Deliver.select();
		return false;
	}
	
	if (isEmpty(document.updateDetails.message.value)) {
		alert("Please enter your personal message.")
		document.updateDetails.message.focus();
		document.updateDetails.message.select();
		return false;
	} */
	return true;
 }
 
 function isQuickSearch() {
	 if (isEmpty(document.quickSearch2.SearchText.value)) {
		alert("Please enter some text for the quick search.")
		document.quickSearch2.SearchText.focus();
		return false;
	}
 }
 
 function isValidateGiftVoucher() {
	 if (isEmpty(document.GiftVoucher.Code.value)) {
		alert("Please enter a gift voucher code.")
		document.GiftVoucher.Code.focus();
		return false;
	}
 }
 
 
 


//"Accept terms" form submission- By Dynamic Drive
//For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
//This credit MUST stay intact for use

var checkobj

function agreesubmit(el){
	checkobj=el
	if (document.all||document.getElementById){
		for (i=0;i<checkobj.form.length;i++){  //hunt down submit button
			var tempobj=checkobj.form.elements[i]
			if(tempobj.type.toLowerCase()=="submit")
			tempobj.disabled=!checkobj.checked
			}
		}
}

function defaultagree(el){
	if (!document.all&&!document.getElementById){
	if (window.checkobj&&checkobj.checked)
		return true
		else {
			alert("Please read/accept terms to submit form")
			return false
		}
	}
}

function agreebutton(el){
	checkobj=el
	if (document.all||document.getElementById){
		for (i=0;i<checkobj.form.length;i++){  
			var tempobj=checkobj.form.elements[i]
			if(tempobj.type.toLowerCase()=="button")
			tempobj.disabled=!checkobj.checked
			}
		}
}


function isUpdateQty() {
	for(var i=1; i < document.updateQty.Counter.value+1; i++){
		with(document.updateQty){ 
		
			if(eval("Qty" + i + ".value == ''")){
				alert("Please enter a quantity amount for item number " + i);
				eval("Qty" + i + ".focus()");
				return false;
			}
			
			if (!currency(eval("Qty" + i + ".value"))){
				alert("Please enter a valid number amount for item number " + i);
				eval("Qty" + i + ".focus()");
				eval("Qty" + i + ".select()");
				return false;
			}
		}
	
	}
	return true
}


function confirmRemove(url){
	if(confirm("This item will be deleted from the shopping cart.\n\nAre you sure you want continue?"))
	window.location = url
} 

function region() {
	window.open('includes/regions.cfm','','toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,resizable=yes,width=650,height=400')
}

function isConfirm(message, url){
	if(confirm(message)) location.href = url;
}


function enlargeNewsPhoto(id) {
	window.open("enlarge_news_photo.cfm?newsid=" + id, null, "height=550,width=450,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
} 

function openSalesUsed(id) {
	window.open("open_sales_used.cfm?salesid=" + id, null, "height=550,width=450,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
} 

function openHire(id) {
	window.open("open_hire.cfm?hireid=" + id, null, "height=550,width=450,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
} 


	