

function check_zip_code_field(cnt, zip) {
	var c_code;
	var zip_error = false;

	if (!zip || zip.value == "")
		return true;

	c_code = '';
	if (cnt) {
		if ((cnt.options.length > 0) && (cnt.selectedIndex < cnt.options.length)) {
			c_code = cnt.options[cnt.selectedIndex].value;
		}
	}

	if(c_code=="GB")
	{
		if(localBFamily != "MSIE")
		{
			test=zip.value;	
			test = test.toUpperCase(); //Change to uppercase
   		   zip.value = test; //write back to form field
		}
		var err=postit_b(zip); 
		if(err==false)
			zip_error= true;
		else
			zip_error=false;
		
		
	}
	else
	{
		if (window.check_zip_code_rules && isset(check_zip_code_rules[c_code])) {
			var rules = check_zip_code_rules[c_code];
	
			if (isset(rules.lens) && !isset(rules.lens[zip.value.length]))
				zip_error = true;
	
			if (isset(rules.re) && zip.value.search(rules.re) != -1)
				zip_error = true;
	
			if (zip_error) {
				if (rules.error && rules.error.length > 0)
					alert(rules.error);
				zip.focus();
				return false;
			}
		}
	}
	return !zip_error;
}

function check_zip_code() {
	return check_zip_code_field(document.forms["registerform"].b_country, document.forms["registerform"].b_zipcode) && check_zip_code_field(document.forms["registerform"].s_country, document.forms["registerform"].s_zipcode); 
}

function postit_b(zip){ //check postcode format is valid

test = zip.value; 
 size = zip.value.length;


 if (size < 6 || size > 8){ //Code length rule
 
    alert(test + " is not a valid postcode - wrong length");
 // document.registerform.b_zipcode.focus();
 	zip.focus();
  return false;
  }
 if (!(isNaN(test.charAt(0)))){ //leftmost character must be alpha character rule
 
   alert(test + " is not a valid postcode - cannot start with a number");
   zip.focus();
   return false;
  }
 if (isNaN(test.charAt(size-3))){ //first character of inward code must be numeric rule
   alert(test + " is not a valid postcode - alpha character in wrong position");
   zip.focus();
   return false;
  }
 if (!(isNaN(test.charAt(size-2)))){ //second character of inward code must be alpha rule
   alert(test + " is not a valid postcode - number in wrong position");
   zip.focus();
   return false;
  }
 if (!(isNaN(test.charAt(size-1)))){ //third character of inward code must be alpha rule
   alert(test + " is not a valid postcode - number in wrong position");
   zip.focus();
   return false;
  }
 if (!(test.charAt(size-4) == " ")){//space in position length-3 rule
   alert(test + " is not a valid postcode - no space or space in wrong position");
   zip.focus();
   return false;
   }
 count1 = test.indexOf(" ");count2 = test.lastIndexOf(" ");
 if (count1 != count2){//only one space rule
   alert(test + " is not a valid postcode - only one space allowed");
   zip.focus();
   return false;
  }
return true;
}
