// JavaScript Document

function checkreg() {

if (document.Register.first_name.value=="")
	{alert('Please key your first name');	document.Register.first_name.focus(); return false}

if (document.Register.last_name.value=="")
	{alert('Please key your last name');	document.Register.last_name.focus(); return false}

if (document.Register.phone_1.value=="")
	{alert('Please key your phone number');	document.Register.phone_1.focus(); return false}
	
if (document.Register.user_email.value=="")
	{alert('Please key your email address');	document.Register.user_email.focus(); return false}		
	
	var emailIDM=document.Register.user_email;
	
	if (echeck(emailIDM.value)==false){
		emailIDM.value=""
		emailIDM.focus()
		return false;
	}

if(document.Register.account.value.checked){
	if (document.Register.password_1.value=="")
		{alert('Please enter a password');	document.Register.password_1.focus(); return false}
	
	if (document.Register.password_2.value=="")
		{alert('Please confirm your password');	document.Register.password_2.focus(); return false}
}
str=document.Register.address_1.value;
if (str==""){
	alert('Please key your address');	document.Register.address_1.focus(); return false
}
if (str.indexOf(" ")==-1){
	var address = confirm ("You appear to have entered an incomplete address\n\n Click OK to continue or cancel to change it?\n\n");
	if(!address){
		document.Register.address_1.focus();
		return false;
	}
}

if (document.Register.city.value=="")
	{alert('Please key your city');	document.Register.city.focus(); return false}

if (document.Register.state.value=="")
	{alert('Please key your state');	document.Register.state.focus(); return false}

if (document.Register.zip.value=="")
	{alert('Please key your postcode');	document.Register.zip.focus(); return false}

if (document.Register.country.value=="")
	{alert('Please select your country');	document.Register.country.focus(); return false}


}




function checkmailinglist() {
if (document.mailinglist.fname.value=="" || document.mailinglist.fname.value=="your name")
	{alert('Please key your name');	document.mailinglist.fname.focus(); return false}

if (document.mailinglist.email.value=="")
	{alert('Please key your email address');	document.mailinglist.email.focus(); return false}

	var emailIDM=document.mailinglist.email;
	
	if (echeck(emailIDM.value)==false){
		emailIDM.value=""
		emailIDM.focus()
		return false
	}

alert ("Thankyou, you have been added to our our mailing list");
}


function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (1) {
            curleft+=obj.offsetLeft;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.x) {
        curleft+=obj.x;
    }
    return curleft;
}
function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (1) {
            curtop+=obj.offsetTop;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.y) {
        curtop+=obj.y;
    }
    return curtop;
}

function cleartextbox(text_box){
	text_box.value = "";
}

function restoretextbox(text_box,boxval){
	if (text_box.value == ""){ 
		text_box.value = boxval; 
	}
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Please provide a valid email address.")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please provide a valid email address.")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   alert("Please provide a valid email address.")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   alert("Please provide a valid email address.")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   alert("Please provide a valid email address.")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   alert("Please provide a valid email address.")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   alert("Please provide a valid email address.")
		    return false
		 }

 		 return true					
	}

	function emailPage(page_url){
	win_name= "_ep";
	win_options= "toolbars=no,status=no,left=10,top=10,width=550,height=400,scrollbars=1,resize=yes,resizable";
	window.open(page_url,win_name,win_options);
	}
	
/* used for credit card payment form */	

/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Cyanide_7 |  */
var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
  var keyCode = (isNN) ? e.which : e.keyCode; 
  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
  if(input.value.length >= len && !containsElement(filter,keyCode)) {
    input.value = input.value.slice(0, len);
    input.form[(getIndex(input)+1) % input.form.length].focus();
  }
}

  function containsElement(arr, ele) {
    var found = false, index = 0;
    while(!found && index < arr.length)
    if(arr[index] == ele)
    found = true;
    else
    index++;
    return found;
  }

  function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
    if (input.form[i] == input){
    	index = i;
    }else{
    	i++;
    	return index;
  	}
  	return true;
  }

/* used for image swap on mouse over */
function SimpleSwap(el,which){
        el.src=el.getAttribute(which||"origsrc");
}


/* used for multiple attribute boxes */
function redirect(x){
	for (m=temp.options.length-1;m>0;m--)
	temp.options[m]=null
	for (i=0;i<group[x].length;i++){
	temp.options[i]=new Option(group[x][i].text,group[x][i].value)
	}
	temp.options[0].selected=true
}

function minPurchase(minimum, totalSpend, url,groupname){
	if(totalSpend >= minimum){
		if(url){
			window.location=url;
		}else{
			return true;
		}
	}else{
		if(groupname=="-default-"){
			alert("Sorry, minimum purchase amount is $" + minimum);
		}else{
			alert("Sorry, minimum purchase amount for " + groupname + " customers is $" + minimum);
		}
		return false;
	}

}



/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/* Modified to support Opera */
function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}

/***********************************************/

function hireform() {
	errors = '';
	
	var isChecked = false;
	var box="";
	
	for (var i = 0; i < document.hireenqiry.numprod.value; i++) {
	 	box=eval('document.hireenqiry.c_product'+i);
	   if (box.checked) {
	      isChecked = true;
	   }
	}
	if (isChecked == false)
		errors += '- Please select a product of interest\n';	
	
	if (document.hireenqiry.c_contact_name.value.length == 0)
		errors += '- Contact name\n';
	if (document.hireenqiry.c_email.value.length == 0)
		errors += '- Email\n';
	var emailIDM=document.hireenqiry.c_email;
	if(emailIDM.value.length > 0 ){
		if (echeck(emailIDM.value,"nopop")==false){
			emailIDM.value=""
			errors += '- Email address is invalid\n';
		}
	}
	if (document.hireenqiry.c_phone.value.length == 0)
		errors += '- Phone number\n';
	if (document.hireenqiry.c_town.value.length == 0)
		errors += '- Town / Suburb\n';
	if (document.hireenqiry.c_postcode.value.length == 0)
		errors += '- Postcode\n';
	if (document.hireenqiry.c_date_required.value.length == 0)
		errors += '- Date Required\n';	
	if (errors.length > 0) {
		window.alert('Please complete the following:\n\n'+errors);
		return false;
	} else {
		alert ("Thankyou, a member of our staff will contact you shortly");
		return true;
	}
 
}



function wholesalereg() {
	errors = '';
	
	var isChecked = false;
	var box="";
	
	if (document.Register.company.value.length == 0)
		errors += '- Registered Business Name\n';
	if (document.Register.user_abn.value.length == 0)
		errors += '- ABN / ACN\n';
	if (document.Register.business_type.value.length == 0)
		errors += '- Business Description\n';
	if (document.Register.business_type.value.length == 0)
		errors += '- Business Address\n';
	if (document.Register.title.value.length == 0)
		errors += '- Position\n';
	if (document.Register.first_name.value.length == 0)
		errors += '- First name\n';		
	if (document.Register.last_name.value.length == 0)
		errors += '- Surname\n';
	if (document.Register.phone_1.value.length == 0)
		errors += '- Phone number\n';
	if (document.Register.user_email.value.length == 0)
		errors += '- Email\n';
		
	var emailIDM=Register.user_email;
	if(emailIDM.value.length > 0 ){
		if (echeck(emailIDM.value,"nopop")==false){
			emailIDM.value=""
			errors += '- Email address is invalid\n';
		}
	}
	if (document.Register.address_1.value.length == 0)
		errors += '- Address\n';

	if (document.Register.city.value.length == 0)
		errors += '- Town / Suburb\n';
	if (document.Register.state.value.length == 0)
		errors += '- State\n';
	if (document.Register.zip.value.length == 0)
		errors += '- Postcode\n';

	
	if (errors.length > 0) {
		window.alert('Please complete the following:\n\n'+errors);
		return false;
	} else {
		alert ("Thankyou, you will be contacted you shortly");
		return true;
	}
 
}
	
