// Sign up functions

			function trimAll( strValue )
			{
				var objRegExp = /^(\s*)$/;

				if(objRegExp.test(strValue)) {
					strValue = strValue.replace(objRegExp, '');
					if( strValue.length == 0)
					return strValue;
				}
				objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
				if(objRegExp.test(strValue)) {
					strValue = strValue.replace(objRegExp, '$2');
				}
				return strValue;
			}
			function validate_email(field,alerttxt)
			{
				with (field)
				{
					apos=value.indexOf("@")
					dotpos=value.lastIndexOf(".")
					if (apos<1||dotpos-apos<2)
					{alert(alerttxt);field.value="";return false}
					else {return true}
				}
			}
			function submitForm()
			{
				document.customer.firstName.value=trimAll(document.customer.firstName.value)
				document.customer.surname.value=trimAll(document.customer.surname.value)
				document.customer.streetNumber.value=trimAll(document.customer.streetNumber.value)
				document.customer.streetName.value=trimAll(document.customer.streetName.value)
				document.customer.postcode.value=trimAll(document.customer.postcode.value)
				document.customer.homeTelephone.value=trimAll(document.customer.homeTelephone.value)
				document.customer.email1.value=trimAll(document.customer.email1.value)
				document.customer.email2.value=trimAll(document.customer.email2.value)
				document.customer.billingStreetNumber.value=trimAll(document.customer.billingStreetNumber.value)
				document.customer.billingStreetName.value=trimAll(document.customer.billingStreetName.value)
				document.customer.billingPOBoxNumber.value=trimAll(document.customer.billingPOBoxNumber.value)
				document.customer.billingPostcode.value=trimAll(document.customer.billingPostcode.value)
				document.customer.password.value=trimAll(document.customer.password.value)
				document.customer.confirmPassword.value=trimAll(document.customer.confirmPassword.value)

				var checkOk="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
				//var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?0123456789";
				var iChars = "!@#$%^*()+=[]\\\;,./{}|\":<>?0123456789";	
				if(document.customer.firstName.value=="")
				{
					alert('Please enter the first name.');
					document.customer.firstName.focus();
					return false;
				}
				if(document.customer.firstName.value.length > 0)
		    	{
		    		for (var i = 0; i < document.customer.firstName.value.length; i++)
		    		{
		    			if (iChars.indexOf(document.customer.firstName.value.charAt(i)) != -1)
		    			{
		    				alert ("Please enter first name in alphabates.");
		    				document.customer.firstName.focus();
		    				return false;
		    			}
		    		}
		    	}

		    	if(document.customer.surname.value=="")
				{
					alert('Please enter the surname.');
					document.customer.surname.focus();
					return false;
				}
				if(document.customer.surname.value.length > 0)
		    	{
		    		for (var i = 0; i < document.customer.surname.value.length; i++)
		    		{
		    			if (iChars.indexOf(document.customer.surname.value.charAt(i)) != -1)
		    			{
		    				alert ("Please enter surname in alphabates.");
		    				document.customer.surname.focus();
		    				return false;
		    			}
		    		}
		    	}

				if(document.customer.streetNumber.value=="")
				{
					alert('Please enter the street number.');
					document.customer.streetNumber.focus();
					return false;
				}
				if(document.customer.streetName.value=="")
				{
					alert('Please enter the street name.');
					document.customer.streetName.focus();
					return false;
				}
				if(document.customer.country.value==0)
				{
					alert('Please select the country.');
					document.customer.country.focus();
					return false;
				}
				if(document.customer.lstState.value==0)
				{
					alert('Please select the state.');
					document.customer.lstState.focus();
					return false;
				}
				if(document.customer.lstSuburb.value==0)
				{
					alert('Please select the suburb.');
					document.customer.lstSuburb.focus();
					return false;
				}
				if(document.customer.postcode.value=="")
				{
					alert('Please enter the postcode.');
					document.customer.postcode.focus();
					return false;
				}
				if(document.customer.homeTelephone.value=="")
				{
					alert('Please enter the home telephone');
					document.customer.homeTelephone.focus();
					return false;
				}
				if(document.customer.email1.value=="")
				{
					alert('Please enter your email address');
					document.customer.email1.focus();
					return false;
				}
				
				if(document.customer.email2.value=="")
				{
					alert('Please confirm your email address');
					document.customer.email2.focus();
					return false;
				}
				if (validate_email(document.customer.email1,"Not a valid e-mail address!")==false)
				{
					document.customer.email1.focus()
					return false;
				}

				if(document.customer.email1.value != document.customer.email2.value)
				{
					alert('Your email addresses do not match');
					document.customer.email1.focus()
					return false;
				}

				if(document.customer.billingCountry.value==0)
				{
					alert('Please select the billing country.');
					document.customer.billingCountry.focus();
					return false;
				}
				if(document.customer.billingState.value==0)
				{
					alert('Please select the billing state.');
					document.customer.billingState.focus();
					return false;
				}
				if(document.customer.billingSuburb.value==0)
				{
					alert('Please select the billing suburb.');
					document.customer.billingSuburb.focus();
					return false;
				}
				if(document.customer.billingPostcode.value=="")
				{
					alert('Please enter the billing postcode.');
					document.customer.billingPostcode.focus();
					return false;
				}
				if(document.customer.billingPOBoxNumber.value=="")
				{
                    if(document.customer.billingStreetNumber.value=="" || document.customer.billingStreetName.value=="")
				    {
    					alert('Please enter either billing StreetNumber And StreetName or billing PO BOX Number.');
    					document.customer.billingStreetNumber.focus();
    					return false;
    			    }
        		}
				if(document.customer.password.value=="")
				{
					alert('Please enter the password.');
					document.customer.password.select();
					return false;
				}

				if(document.customer.confirmPassword.value=="")
				{
					alert('Please enter the confirm password.');
					document.customer.confirmPassword.select();
					return false;
				}
				if (document.customer.confirmPassword.value != document.customer.password.value)
				{
					alert("Password and confirm password fields do not match.");
					document.customer.confirmPassword.focus();
					return false;
				}
				/*if (document.customer.paymentOption.value==0)
				{
					alert("Please select the payment option.");
					document.customer.paymentOption.focus();
					return false;
				}*/
				else
				{
					document.customer.frmSubmitted.value="yes";
					return true;
				}

			}
			var ajax = new sack();
			function getStates(sel)
			{
				var countryID = sel.options[sel.selectedIndex].value;
				document.customer.lstState.options.length = 0;	// Empty state select list
				document.customer.postcode.value=""
				document.customer.lstSuburb.options.length=0;
				if(countryID.length>0){
					ajax.requestFile = '../getStates.php?countryID='+countryID;	// Specifying which file to get
					ajax.onCompletion = createStates;	// Specify function that will be executed after file has been found
					ajax.runAJAX();		// Execute AJAX function
				}
			}
			function createStates(){
				var obj = document.customer.lstState;
				eval(ajax.response);	// Executing the response from Ajax as Javascript code
			}
			function getStatesBilling(sel)
			{
				//alert(sel);
				var countryID = sel.options[sel.selectedIndex].value;
				document.customer.billingState.options.length = 0;	// Empty state select list
				document.customer.billingSuburb.options.length = 0
				document.customer.billingPostcode.value=""

				if(countryID.length>0){
					ajax.requestFile = '../getStates.php?countryID='+countryID;	// Specifying which file to get
					ajax.onCompletion = createStatesBilling;	// Specify function that will be executed after file has been found
					ajax.runAJAX();		// Execute AJAX function
				}
			}
			function createStatesBilling(){
				var obj = document.customer.billingState;
				eval(ajax.response);	// Executing the response from Ajax as Javascript code
			}

			function getSuburbs(sel)
			{
				var postCode= sel.value;
				document.customer.lstSuburb.options.length = 0;	// Empty state select list
			    if(postCode.length>0){
					ajax.requestFile = '../getSuburbs.php?postCode='+postCode;	// Specifying which file to get
					ajax.onCompletion = createSuburbs;	// Specify function that will be executed after file has been found
					ajax.runAJAX();		// Execute AJAX function
				}
			}
			function createSuburbs(){
				var obj = document.customer.lstSuburb;
				eval(ajax.response);	// Executing the response from Ajax as Javascript code
			}
			function getSuburbsBilling(sel)
			{
				var postCode= sel.value;
				document.customer.billingSuburb.options.length = 0;	// Empty state select list
   				if(postCode.length>0){
					ajax.requestFile = '../getSuburbs.php?postCode='+postCode;	// Specifying which file to get
					ajax.onCompletion = createSuburbsBilling;	// Specify function that will be executed after file has been found
					ajax.runAJAX();		// Execute AJAX function
				}
            }
			function getSuburbsBilling1(sel,val)
			{
            	var postCode= sel.value;
                document.customer.billingSuburb.options.length = 0;	// Empty state select list
               	if(postCode.length > 0)
				{
					ajax.requestFile = '../getSuburbs.php?postCode='+postCode+'&suburbID='+val;	// Specifying which file to get
					ajax.onCompletion = createSuburbsBilling;	// Specify function that will be executed after file has been found
					ajax.runAJAX();		// Execute AJAX function
				}
			}
			function createSuburbsBilling(){
				var obj = document.customer.billingSuburb;
				eval(ajax.response);	// Executing the response from Ajax as Javascript code
			}
			function getPostcode(sel)
			{
				document.customer.postcode.value ="" ;	// Empty state select list
				ajax.requestFile = '../getPostCode.php?id='+sel;	// Specifying which file to get
				ajax.onCompletion = createPostcode;	// Specify function that will be executed after file has been found
				ajax.runAJAX();		// Execute AJAX function

			}
			function createPostcode()
			{
				var obj = document.customer.postcode;
				document.customer.postcode.value=ajax.response
			}
			/*********************************************************/
			function getBillingPostcode(sel)
			{
				document.customer.billingPostcode.value ="" ;	// Empty state select list
				ajax.requestFile = '../getPostCode.php?id='+sel;	// Specifying which file to get
				ajax.onCompletion = createBillingPostcode;	// Specify function that will be executed after file has been found
				ajax.runAJAX();		// Execute AJAX function

			}
			function createBillingPostcode()
			{
				var obj = document.customer.billingPostcode;
				document.customer.billingPostcode.value=ajax.response
			}
			/*************************************************************/
			function verify_first()
			{
				if(document.customer.chkSameAddress.checked==true)
				{
					//document.customer.isSameAddress.value="YES";
					document.customer.billingCountry.value=document.customer.country.value;
					document.customer.billingStreetNumber.value=document.customer.streetNumber.value;
					document.customer.billingStreetName.value=document.customer.streetName.value;
					document.customer.billingState.value=document.customer.lstState.value;
					document.customer.billingPostcode.value=document.customer.postcode.value;
					getSuburbsBilling1(document.customer.postcode,document.customer.lstSuburb.value);

				}
				else if(document.customer.chkSameAddress.checked==false)
				{
					document.customer.billingCountry.value=11;
					document.customer.billingState.value=0;
					document.customer.billingSuburb.value=0;
					document.customer.billingPostcode.value="";
					document.customer.billingStreetNumber.value="";
					document.customer.billingStreetName.value="";
					document.customer.billingSuburb.options.length = 0;
				}
				return true;
			}