
function pc_address_check(){
	$(document).ready(function(){
		try{
		var logged_in = document.getElementById("userinfo").innerHTML;
		if ('standalone' in navigator && !navigator.standalone && (/iphone|ipod|ipad/gi).test(navigator.platform) && (/Safari/i).test(navigator.appVersion)) {
	
		}
		else{
			if ($("#city_fs").length ) {
				$("#city_fs").parent().parent().css('display', 'none');
				var html="<tr><td valign=baseline nowrap align=right class='smalltextnolink'><span id=\"custom_city\" style=\"white-space: wrap;\" class=\"labelSpanEdit smalltextnolink\"><image class='required_icon' title='Required Field' src='/images/chiles/pageTitle/required.png'><A class='smalltextnolink' onmouseover=\"this.className='smalltextnolink'; return true;\" onmouseout=\"this.className='smalltextnolink'; \">Suburb</A>&nbsp;</span></td><td><select class=\"wide\" id=\"custom_suburb_select\"></select></td></tr>"			
				$("#zip_fs").parent().parent().after($("#city_fs").parent().parent())
				$("#zip_fs").parent().parent().after(html);
				$("#city_fs").parent().parent().after($("#dropdownstate_fs").parent().parent())
				
				if ($.browser.msie && $.browser.version < 9) $('select.wide')
	    			.bind('focus mouseover', function() { $(this).addClass('expand').removeClass('clicked'); })
	    			.bind('click', function() { $(this).toggleClass('clicked'); })
	    			.bind('mouseout', function() { if (!$(this).hasClass('clicked')) { $(this).removeClass('expand'); }})
	    			.bind('blur', function() { $(this).removeClass('expand clicked'); 
	    		});
	    	}
	    	
	    	if ($("#zip").length ) {
				var zip = $("#zip").val();
				if(zip!='' && zip!=null){
					var suburb = $("#city").val();
					var upper_suburb = suburb.toUpperCase();
					$("option.suburb_option").remove();
					for(var x=0; x< pc[zip].length; x++){
						var current_suburb = pc[zip][x]['su']
						var option = '<option class="suburb_option" value="'+x+'">'+current_suburb+'</option>'
						//$("#custom_suburb_select").append($(option));
						$("#custom_suburb_select").append($("<option></option>").attr("value", x).text(current_suburb));
		
					}
					//$("#custom_suburb_select").width('240px');
					$("#city").val(pc[zip][0]['su'])
					$("#dropdownstate").val(pc[zip][0]['sta'])
					$("#country").val('AU')
				}
			
				$("#zip").change(function(){
					try{			
						var zip = $("#zip").val();
						var suburb = $("#city").val();
						var upper_suburb = suburb.toUpperCase();
						$("#custom_suburb_select").empty();
						if(zip.length!=null){
							for(var x=0; x< pc[zip].length; x++){
								var current_suburb = pc[zip][x]['su']
								//var option = '<option class="suburb_option" value="'+x+'">'+current_suburb+'</option>'
								//$("#custom_suburb_select").append(option);
								$("#custom_suburb_select").append($("<option ></option>").attr("value", x).text(current_suburb));
								//$("#custom_suburb_select").append(new Option(current_suburb, x)).val(x);
								if(logged_in=='Checkout for Lez Yeoh'){
									alert(x + " " + current_suburb)
									
								}
							}
							//$("#custom_suburb_select").width('240px');
							$("#custom_suburb_select").css('width', 'auto');
							$("#city").val(pc[zip][0]['su'])
							$("#dropdownstate").val(pc[zip][0]['sta'])
							$("#country").val('AU')
							if(logged_in=='Checkout for Lez Yeoh'){
									alert(pc[zip][0]['su'])
									alert(pc[zip][0]['sta'])
									alert(pc[zip][0]['coa'])
									
								}
						}
					}
					catch(e){
						if(logged_in=='Checkout for Lez Yeoh'){
						alert(e);
						}
				}
				});
			
			
				$("#addr1").blur(function(){			
					var address = $("#addr1").val();
					if(address.search(/po box/i) != -1){
						alert('Unfortunately we cannot make deliveries to a PO Box. Please update your shipping address and submit your order.');
					}
					if(address.search(/p o box/i) != -1){
						alert('Unfortunately we cannot make deliveries to a PO Box. Please update your shipping address and submit your order.');
					}
					if(address.search(/p.o box/i) != -1){
						alert('Unfortunately we cannot make deliveries to a PO Box. Please update your shipping address and submit your order.');
					}
					if(address.search(/p.o. box/i) != -1){
						alert('Unfortunately we cannot make deliveries to a PO Box. Please update your shipping address and submit your order.');
					}
				});
			
				$("#addr2").blur(function(){			
					var address = $("#addr2").val();
					if(address.search(/po box/i) != -1){
						alert('Unfortunately we cannot make deliveries to a PO Box. Please update your shipping address and submit your order.');
					}
					if(address.search(/p o box/i) != -1){
						alert('Unfortunately we cannot make deliveries to a PO Box. Please update your shipping address and submit your order.');
					}
					if(address.search(/p.o box/i) != -1){
						alert('Unfortunately we cannot make deliveries to a PO Box. Please update your shipping address and submit your order.');
					}
					if(address.search(/p.o. box/i) != -1){
						alert('Unfortunately we cannot make deliveries to a PO Box. Please update your shipping address and submit your order.');
					}
				});
				
				
				$("#custom_suburb_select").change(function(){
					var suburb = $("#custom_suburb_select").val()
					var zip = $("#zip").val();
					$("#city").val(pc[zip][suburb]['su'])
					$("#dropdownstate").val(pc[zip][suburb]['sta'])
					$("#country").val('AU')
				});
				
				$("#phone").change(function(){			
					var x = $("#phone").val();
					var numeric = /^[0-9]+$/;
					var length = x.length;
					if(x.match(numeric) && length==10){
						return true;
					}
					else{
						if(length!=10){
							alert('Phone number must be 10 digits. Eg: 0411222333 or 0395551111.');
						}
						if(x.match(numeric)==null){
							alert('Phone number must be all numeric.');
						}
					}
				});
				
				$("#custentity_dob").blur(function(){
					var dob = $("#custentity_dob").val();
					if(dob!=null && dob!=''){
						var fields = dob.split('/');
						var js_dob = new Date();
						js_dob.setFullYear(fields[2],parseInt(fields[1])-1, fields[0])
						//alert(js_dob);
						var today = new Date();
						today.setFullYear(today.getFullYear() - 18);
						if(js_dob>today){
							alert('You are required to be 18 years of age to be a customer')
						}
					}
				});
				try{
					$("#custbody1").prepend('<option selected value="">Please Select One</option>');
				}
				catch(e){
				}			
			}
		}
	}
	catch(e){
		
	}
	});
}


function my_account(){
	var logged_in = document.getElementById("userinfo").innerHTML;
	var html = '';
	html +=	'<a href="#"><span id="myaccounttab" style="color:e32528;"> &#8729 MY ACCOUNT </span></a>'
	
	
	if (logged_in != 'not logged in') {
		document.write(html);
	}
	if (logged_in == 'Welcome Catherine Kearey!' || logged_in == 'Welcome Elizabeth Greenaway!' || logged_in == 'Welcome Lez Yeoh!') {
		//alert('working');
		//document.write(html);
	}
}

function test(){
	$(document).ready(function(){
		$('#orders').click(function(){
			$('#div__body').load('/app/site/hosting/scriptlet.nl?script=50&deploy=1');
		});
		$('#details').click(function(){
			$('#div__body').load('/app/site/hosting/scriptlet.nl?script=51&deploy=1');
		});
		$('#query').click(function(){
			$('#div__body').load('/app/site/hosting/scriptlet.nl?script=53&deploy=1');
		});
		$('#myaccount').click(function(){
			$('#div__body').load('/app/site/hosting/scriptlet.nl?script=56&deploy=1');
		});
	});
}

function check_fields(formname) 
    { 
        var returnval=false; 
        var msg=""; 

        if(document.getElementById("shipattention").value=="") 
            msg+="You must fill your name!\n"; 
        if(document.getElementById("shipadd1").value=="") 
            msg+="You must fill your shipping address!\n"; 
        if(document.getElementById("shippostcode").value=="") 
            msg+="You must fill your shipping postcode!\n"; 
        if(document.getElementById("shipsuburb").value=="") 
            msg+="You must fill your suburb!\n"; 
        if(document.getElementById("shipstate").value=="") 
            msg+="You must fill your state!\n"; 
		if(document.getElementById("billattention").value=="") 
            msg+="You must fill your name!\n"; 
        if(document.getElementById("billadd1").value=="") 
            msg+="You must fill your billing address!\n"; 
        if(document.getElementById("billpostcode").value=="") 
            msg+="You must fill your billing postcode!\n"; 
        if(document.getElementById("billsuburb").value=="") 
            msg+="You must fill your billing suburb!\n"; 
        if(document.getElementById("billstate").value=="") 
            msg+="You must fill your billing state!\n"; 
              
        if(msg=="") 
        { 
            returnval=true; 
            return returnval; 
        } 
        else 
        { 
           // alert(msg); 
            return returnval;
        } 
    } 

    function submit_form(formname) 
    { 
        if(check_fields(formname)) 
        { 
        	//document.forms["main_form"].submit();
        	//$("#main_form").submit();
            return true;  
        } 
        else 
        { 
            return false; 
        } 
    }

function populateField(field, id, type){
	//alert(field + id);
	if (field == 'shippostcode' || field == 'billpostcode') {
		try {
			if (type == 'shipping') {
				var currentOptions = document.getElementById('shipsuburb');
			}
			if (type == 'billing') {
				var currentOptions = document.getElementById('billsuburb');
			}
			var i;
			for (i = currentOptions.length - 1; i >= 0; i--) {
				currentOptions.remove(i);
			}
			
			var js_postcode = document.getElementById(field).value;
			//var suburbs = p_array[js_postcode].suburb;
			var suburbs = pc[js_postcode];

			//alert(suburbs.length);
			if (suburbs.length != null) {
				for (var x = 0; x < suburbs.length; x++) {
					if (type == 'shipping') {
						var suburbSelect = document.getElementById('shipsuburb')
					}
					if (type == 'billing') {
						var suburbSelect = document.getElementById('billsuburb')
					}
					
					var newOpt = document.createElement('option');
					newOpt.text = suburbs[x]['su'];
					newOpt.value = suburbs[x]['su'];
					try {
						if(type=='shipping'){	
							$("#shipsuburb").append($("<option></option>").attr("value", suburbs[x]['su']).text(suburbs[x]['su']));

						}
						if(type=='billing'){
							$("#billsuburb").append($("<option></option>").attr("value", suburbs[x]['su']).text(suburbs[x]['su']));
						
						}
						//alert('here');
						if(x==0){
							if (type == 'shipping') {
								document.getElementById('custpage_s_city').value = suburbs[x]['su'];
								document.getElementById('custpage_s_state').value = suburbs[x]['sta'];
								document.getElementById('shipstate').value = suburbs[x]['sta'];
							}
							if (type == 'billing') {
								document.getElementById('custpage_b_city').value = suburbs[x]['su'];
								document.getElementById('custpage_b_state').value = suburbs[x]['sta'];
								document.getElementById('billstate').value = suburbs[x]['sta'];
							}
						}
					} 
					catch (ex) {
						//alert('here1');
						suburbSelect.add(newOpt); // IE only
						
						if(x==0){
							if (type == 'shipping') {
								document.getElementById('custpage_s_state').value = suburbs[x]['sta'];
								document.getElementById('shipstate').value = suburbs[x]['sta'];
							}
							if (type == 'billing') {
								document.getElementById('custpage_b_state').value = suburbs[x]['sta'];
								document.getElementById('billstate').value = suburbs[x]['sta'];
							}
						}
					}
				}
			}
			
			var fieldvalue = document.getElementById(field);
			document.getElementById(id).value = fieldvalue.value;
		} 
		catch (e) {
			//alert('We were unable to find that postcode, please enter a valid postcode.');
		}
		

	}
	else if(field=='shipsuburb' || field=='billsuburb'){
		if (type == 'shipping') {
				var currentOptions = document.getElementById('shipsuburb');
			}
			if (type == 'billing') {
				var currentOptions = document.getElementById('billsuburb');
			}
		
		for (var i = 0; i < currentOptions.length; i++) {
			if (currentOptions.options[i].selected) {
				document.getElementById(id).value = currentOptions.options[i].value;
			}
		}
	}
	else if(field=='phoneoptin' || field=='mailoptin' || field=='emailoptin'){
		var ischecked = document.getElementById(field).checked;
		if (ischecked == true) {
			document.getElementById(id).value = 'T';
			document.getElementById(id).checked = 'T';
		}
		else{
			document.getElementById(id).value = 'F';
		}
	}
	else if(field=='emailone' || field=='emailtwo'){
		var js_email_one = document.getElementById('emailone').value;
		var js_email_two = document.getElementById('emailtwo').value;
		if (js_email_one != js_email_two) {
			document.getElementById('message').style.visibility = 'visible';
		}
		else{
			document.getElementById('message').style.visibility = 'hidden';
			document.getElementById(id).value = js_email_one;
		}
	}
	else {
		var fieldvalue = document.getElementById(field);
		document.getElementById(id).value = fieldvalue.value;
		if(field=='enquirytype'){
			document.getElementById('custpage_subject').value = fieldvalue.options[fieldvalue.value].text;
		}	
	}
	if(check_fields('test')){
		$('#disclaimer').hide();
		$('#submit').attr("disabled", false);
	}
	else{
		$('#disclaimer').show();
		$('#submit').attr("disabled", true);
	}
	
	
	
}


