// Agent 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 submitForm()
			{
				
				document.agent.companyName.value=trimAll(document.agent.companyName.value)
				document.agent.firstName.value=trimAll(document.agent.firstName.value)
				document.agent.surname.value=trimAll(document.agent.surname.value)
				document.agent.streetNumber.value=trimAll(document.agent.streetNumber.value)
				document.agent.streetName.value=trimAll(document.agent.streetName.value)
				document.agent.postcode.value=trimAll(document.agent.postcode.value)
				document.agent.homeTelephone.value=trimAll(document.agent.homeTelephone.value)
				document.agent.email1.value=trimAll(document.agent.email1.value)
				document.agent.email2.value=trimAll(document.agent.email2.value)
				document.agent.billingStreetNumber.value=trimAll(document.agent.billingStreetNumber.value)
				document.agent.billingStreetName.value=trimAll(document.agent.billingStreetName.value)
				document.agent.billingPOBoxNumber.value=trimAll(document.agent.billingPOBoxNumber.value)
				document.agent.billingPostcode.value=trimAll(document.agent.billingPostcode.value)
				document.agent.website.value=trimAll(document.agent.website.value)
				document.agent.repeatWebsite.value=trimAll(document.agent.repeatWebsite.value)
				document.agent.acn.value=trimAll(document.agent.acn.value)
				document.agent.brn.value=trimAll(document.agent.brn.value)
				document.agent.abn.value=trimAll(document.agent.abn.value)
				document.agent.agentRegistrationNumber.value=trimAll(document.agent.agentRegistrationNumber.value)
				document.agent.password.value=trimAll(document.agent.password.value)
				document.agent.confirmPassword.value=trimAll(document.agent.confirmPassword.value)
				
				var checkOk="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
				var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?0123456789";
				
				if(document.agent.companyName.value=="")
				{
					alert('Please enter the company name.');
					document.agent.companyName.focus();
					return false;
				}
								
				if(document.agent.firstName.value=="")
				{
					alert('Please enter the first name.');
					document.agent.firstName.focus();
					return false;
				}
				
				if(document.agent.firstName.value.length > 0)
		    	{
		    		for (var i = 0; i < document.agent.firstName.value.length; i++)
		    		{
		    			if (iChars.indexOf(document.agent.firstName.value.charAt(i)) != -1)
		    			{
		    				alert ("Please enter first name in alphabates.");
		    				document.agent.firstName.focus();
		    				return false;
		    			}
		    		}
		    	}
		    	
		    	if(document.agent.firstName.value.length > 0)
		    	{
		    		for(var j=0;j<document.agent.firstName.value.length;j++)
		    		{
		    			if(checkOk.indexOf(document.agent.firstName.value.charAt(j)) ==-1)
		    			{
		    				alert('Please enter valid first name.');
		    				document.agent.firstName.value="";
		    				document.agent.firstName.focus();
		    				return false;
		    				break;
		    			}
		    		}
		    	}
		    	
				if(document.agent.surname.value=="")
				{
					alert('Please enter the surname.');
					document.agent.surname.focus();
					return false;
				}
				
				if(document.agent.surname.value.length > 0)
		    	{
		    		for (var i = 0; i < document.agent.surname.value.length; i++)
		    		{
		    			if (iChars.indexOf(document.agent.surname.value.charAt(i)) != -1)
		    			{
		    				alert ("Please enter surname name in alphabates.");
		    				document.agent.surname.focus();
		    				return false;
		    			}
		    		}
		    	}
		    	
		    	if(document.agent.surname.value.length > 0)
		    	{
		    		for(var j=0;j<document.agent.surname.value.length;j++)
		    		{
		    			if(checkOk.indexOf(document.agent.surname.value.charAt(j)) ==-1)
		    			{
		    				alert('Please enter valid surname name.');
		    				document.agent.surname.value="";
		    				document.agent.surname.focus();
		    				return false;
		    				break;
		    			}
		    		}
		    	}
		    	
				if(document.agent.streetNumber.value=="")
				{
					alert('Please enter the street number.');
					document.agent.streetNumber.focus();
					return false;
				}
				if(document.agent.streetName.value=="")
				{
					alert('Please enter the street name.');
					document.agent.streetName.focus();
					return false;
				}
				if(document.agent.country.value==0)
				{
					alert('Please Select the Country.');
					document.agent.country.focus();
					return false;
				}
				if(document.agent.lstState.value==0)
				{
					alert('Please select the state.');
					document.agent.lstState.focus();
					return false;
				}
				if(document.agent.lstSuburb.value==0)
				{
					alert('Please select the suburb.');
					document.agent.lstSuburb.focus();
					return false;
				}
				if(document.agent.postcode.value=="")
				{
					alert('Please enter the postcode.');
					document.agent.postcode.focus();
					return false;
				}
				if(document.agent.homeTelephone.value=="")
				{
					alert('Please enter the home telephone.');
					document.agent.homeTelephone.focus();
					return false;
				}
				if(document.agent.email1.value=="")
				{
					alert('Please enter your email address');
					document.agent.email1.focus();
					return false;
				}
				if(document.agent.email2.value=="")
				{
					alert('Please confirm your email address');
					document.agent.email2.focus();
					return false;
				}
				if(document.agent.email1.value != document.agent.email2.value)
				{
					alert('Your email addresses do not match');
					document.agent.email2.focus();
					return false;
				}
				
				if( (document.agent.email1.value != "") && ((document.agent.email1.value.indexOf('@') < 0) || ((document.agent.email1.value.charAt(document.agent.email1.value.length-4) != '.') && (document.agent.email1.value.charAt(document.agent.email1.value.length-3) != '.'))))
				{
					alert("You have entered an invalid email address. Please try again.");
					document.agent.email1.select();
					return false;					
				}
				if( (document.agent.email2.value != "") && ((document.agent.email2.value.indexOf('@') < 0) || ((document.agent.email2.value.charAt(document.agent.email2.value.length-4) != '.') && (document.agent.email2.value.charAt(document.agent.email2.value.length-3) != '.'))))
				{
					alert("You have entered an invalid email address. Please try again.");
					document.agent.email2.select();
					return false;					
				}
				if(document.agent.billingCountry.value==0)
				{
					alert('Please select the billing country.');
					document.agent.billingCountry.focus();
					return false;
				}
				if(document.agent.billingState.value==0)
				{
					alert('Please select the billing state.');
					document.agent.billingState.focus();
					return false;
				}
				if(document.agent.billingSuburb.value==0)
				{
					alert('Please select the billing suburb.');
					document.agent.billingSuburb.focus();
					return false;
				}
				if(document.agent.billingPostcode.value=="")
				{
					alert('Please enter the billing postcode.');
					document.agent.billingPostcode.focus();
					return false;
				}
				if(document.agent.billingPostcode.value=="")
				{
					alert('Please select the billing postcode.');
					document.agent.billingPostcode.focus();
					return false;
				}
				if(document.agent.billingPOBoxNumber.value=="")
				{
                    if(document.agent.billingStreetNumber.value=="" || document.agent.billingStreetName.value=="")
				    {
    					alert('Please enter either billing StreetNumber And StreetName or billing PO BOX Number.');
    					document.agent.billingStreetNumber.focus();
    					return false;
    			    }
        		}
				if(document.agent.agentLogo.value=="")
				{
					alert('Please Upload the Logo.');
					//document.agent.agentLogo.focus();
					return false;
				}
				if(document.agent.website.value=="")
				{
					alert('Please enter the website.');
					document.agent.website.select();
					return false;
				}
				if(document.agent.repeatWebsite.value=="")
				{
					alert('Please enter the repeat website.');
					document.agent.repeatWebsite.select();
					return false;
				}				
				if (document.agent.repeatWebsite.value != document.agent.website.value)				
				{
					alert("Website and repeat website fields do not match.");
					document.agent.repeatWebsite.focus();
					return false;
				}
				if(document.agent.agentRegistrationNumber.value=="")
				{
					alert('Please enter agent registration number.');
					document.agent.agentRegistrationNumber.focus();
					return false;
				}
				
				if(document.agent.password.value=="")
				{
					alert('Please enter the password.');
					document.agent.password.select();
					return false;
				}
				if(document.agent.password.value.length < 4)
				{
					alert('Please enter password of 4-12 character.');
					document.agent.password.select();
					return false;
				}
				if(document.agent.confirmPassword.value=="")
				{
					alert('Please enter the confirm password.');
					document.agent.confirmPassword.select();
					return false;
				}				
				if (document.agent.confirmPassword.value != document.agent.password.value)				
				{
					alert("Password and confirm password fields do not match.");
					document.agent.confirmPassword.focus();
					return false;
				}	
				
								
				document.agent.frmSubmitted.value="yes";
				return true;
			}
			
			var ajax = new sack();
			
			function getStates(sel)
			{
				var countryID = sel.options[sel.selectedIndex].value;
				document.agent.lstState.options.length = 0;	// Empty state select list
				document.agent.lstSuburb.options.length = 0
				document.agent.postcode.value =""
				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.agent.lstState;
				eval(ajax.response);	// Executing the response from Ajax as Javascript code	
			}
			
			function getStatesBilling(sel)
			{
				var countryID = sel.options[sel.selectedIndex].value;
				document.agent.billingState.options.length = 0;	// Empty state select list
				document.agent.billingSuburb.options.length = 0;
				document.agent.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.agent.billingState;
				eval(ajax.response);	// Executing the response from Ajax as Javascript code	
			}
			
			function getSuburbs(sel)
			{
				var postCode= sel.value;
				//document.agent.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.agent.lstSuburb;
				obj.length=0;
				eval(ajax.response);	// Executing the response from Ajax as Javascript code	
			}
			
			function getSuburbsBilling(sel)
			{
				var postCode= sel.value;
				document.agent.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 stateID = sel.options[sel.selectedIndex].value;
			   	document.agent.billingSuburb.options.length = 0;	// Empty state select list				
				document.agent.billingPostcode.value=""
				
				if(stateID.length>0)
				{
					ajax.requestFile = '../getSuburbs.php?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.agent.billingSuburb;
				eval(ajax.response);	// Executing the response from Ajax as Javascript code	
			}
			
			/*********************************************************/
			/*function getPostcode(sel)
			{
				document.agent.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.agent.postcode;
				document.agent.postcode.value=ajax.response				
			}
						
			function getBillingPostcode(sel)
			{
				document.agent.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.agent.billingPostcode;
				document.agent.billingPostcode.value=ajax.response				
			}
			
			function verify_first()			
			{			
				if(document.agent.chkSameAddress.checked==true)
				{
					//document.agent.isSameAddress.value="YES";
					document.agent.billingCountry.value=document.agent.country.value;
					document.agent.billingState.value=document.agent.lstState.value;
					document.agent.billingSuburb.value=document.agent.lstSuburb.value;
					getSuburbsBilling1(document.agent.lstState,document.agent.lstSuburb.value);
					document.agent.billingPostcode.value=document.agent.postcode.value;
					document.agent.billingStreetNumber.value=document.agent.streetNumber.value;
					document.agent.billingStreetName.value=document.agent.streetName.value;
					
				}
				else if(document.agent.chkSameAddress.checked==false)
				{
					document.agent.billingCountry.value=0;
					document.agent.billingState.value=0;
					document.agent.billingSuburb.value=0;
					document.agent.billingPostcode.value="";
					document.agent.billingStreetNumber.value="";
					document.agent.billingStreetName.value="";
					document.agent.billingSuburb.options.length = 0;
				}
				return true;			
			}
			
			function checkImage()
			{
				window.open("../uploadUserImages.php","image","location=no,width=400,height=150,top=300,bottom=200,left=300,right=300,status=1,scrollbars=0")	
			}
			
			function setval(str,path)
			{
				document.agent.agentLogo.value=str;	
				document.agent['imgAgent'].src = "../"+path+str;
			}			