/* $Id: f_billandship_address_common.js,v 1.1 2008/06/09 14:57:15 georger Exp $ */

/*
	javascript functions common in:
	-- billing address page
	-- shipping address page
	these functions are:
	- switchErrorImg
	- isValidPhone
	- isIntPostal
	- isValidPostal
	- isValidZip
	- matchPat
	- isValidEmail
	- isCanadaState
	- changeState
	- changeCountry
	- clearErr
*/

<!--
  // flip Required arrows back and forth
  switchErrorImg = function(attr, res) {
  	if (res == 'reset') {
  		var elm = AE_GetElementById(attr);
  	//	elm.src = '/Images/Catalog/redesign07/required_arrow.gif';
  		elm.src = 'https://a248.e.akamai.net/a755bdded7308e72e7fac2eae90715fc.com/Images/Catalog/redesign07/required_arrow.gif';
  	}
  	else {
  		var elm = AE_GetElementById(attr);
  	//	elm.src = '/Images/checkout/buttons/required_arrow_red.gif';
  		elm.src = 'https://a248.e.akamai.net/a755bdded7308e72e7fac2eae90715fc.com/Images/checkout/buttons/required_arrow_red.gif';
  	}
  };//close switchErrorImg()
  
  // Check that a US or Canadian phone number is valid
  isValidPhone = function (area, prefix, suffix) {
  	if (arguments.length == 1) {
  		var num = arguments[0];
  		number = num.replace(/\D/g, '');
  		var length = number.length;
  		if (num.length >= 7) {
  			var area = number.substring(0, length-7);
  			var prefix = number.substring(length-7, length-4);
  			var suffix = number.substring(length-4);
  		}
  		else return false;
  	}
  	else if (arguments.length == 3) {
  		var area = arguments[0];
  		var prefix = arguments[1];
  		var suffix = arguments[2];
  	}
  	else return true;
  	
  	if (area.length != 3 || !isNum(area) || prefix.length != 3 || !isNum(prefix) || suffix.length != 4 || !isNum(suffix)) return false;
  	return true;
  }; // close isValidPhone();
  
  // Check that a string works for international postal code
  isIntPostal = function (str, ignWS) {
  	if (str.search) {
  		if ((ignWS && str.search(/[^\w\s\-]/) != -1) || (!ignWS && str.search(/\W/) != -1)) return false;
  	}
  	return true;
  }; // close isIntPostal();
  
  // Check that a Canadian postal code is valid
  isValidPostal = function (postal, form) {
  	if (postal.search) {
  		postal = removeSpaces(postal);
  		form.Zip1.value = postal;
  		if (postal.length == 6 && postal.search(/^[a-zA-Z]\d[a-zA-Z]\d[a-zA-Z]\d$/) != -1) return true;
  		else if (postal.length == 7 && postal.search(/^[a-zA-Z]\d[a-zA-Z]-\d[a-zA-Z]\d$/) != -1) return true;
  		else return false;
  	}
  	return true;
  }; // close isValidPostal();
  
  // Check that a US zip code is valid
  isValidZip = function (zip, form) {
  	zip = removeSpaces(zip);
  	form.Zip1.value = zip;
  	if (!(zip.length == 5 || zip.length == 9 || zip.length == 10)) return false;
  	if ((zip.length == 5 || zip.length == 9) && !isNum(zip)) return false;
  	if (zip.length == 10 && zip.search && zip.search(/^\d{5}-\d{4}$/) == -1) return false;
  	else return true;
  }; // close isValidZip();
  
  // Compare two strings for equality
  matchPat = function (str, str2) {
  	if (str != str2) return false;
  	else return true;
  }	
  
  // Check that an email address is valid
  isValidEmail = function (str) {
  	if (str.search(/^.+@.+\..{2,4}$/)) return false;
  	else return true;
  };// close isValidEmail();
  
  isCanadaState = function (str) {
  if (str=="AB" || str=="BC" || str=="MB" || str=="NB" || str=="NL" || str=="NT" || str=="NU" || str=="NS" || str=="ON" || str=="PE" || str=="QC" || str=="SK" || str=="YT") return true;
  else return false;
  }	
  
  //ORIGINAL changeState()
  /*function changeState() {
  document.form_one.State1[0].selectedIndex = 0;
  }*/
  
  //MODIFIED changeState() [bandukwala -- 05/13/05]
  function changeState() {
  document.form_one.State1.selectedIndex = 0;
  }
  
  //ORIGINAL changeCountry()
  /*function changeCountry() {
  var StateIndex = document.form_one.State1[0].selectedIndex;
  var SelectedState = document.form_one.State1[0].options[StateIndex].value;
  if (SelectedState=="AB" || SelectedState=="BC" || SelectedState=="MB" || SelectedState=="NB" || SelectedState=="NL" || SelectedState=="NT" || SelectedState=="NU" || SelectedState=="NS" || SelectedState=="ON" || SelectedState=="PE" || SelectedState=="QC" || SelectedState=="SK" || SelectedState=="YT")
  { document.form_one.Country1[0].selectedIndex = 0; }
  else
  { document.form_one.Country1[0].selectedIndex = 1; }
  }*/
  
  //MODIFIED changeCountry() [bandukwala -- 05/13/05]
  //MODIFIED changeCountry() [dixita -- 07/14/05]; Switched selectedIndex values for Country1 to reflect changes in /aeo/util/CountryDropDownUsaCan.properties
  function changeCountry() {
  var StateIndex = document.form_one.State1.selectedIndex;
  var SelectedState = document.form_one.State1.options[StateIndex].value;
  if (SelectedState=="AB" || SelectedState=="BC" || SelectedState=="MB" || SelectedState=="NB" || SelectedState=="NL" || SelectedState=="NT" || SelectedState=="NU" || SelectedState=="NS" || SelectedState=="ON" || SelectedState=="PE" || SelectedState=="QC" || SelectedState=="SK" || SelectedState=="YT")
  { document.form_one.Country1.selectedIndex = 1; }
  else
  { document.form_one.Country1.selectedIndex = 0; }
  }
  
  function clearErr()
  {
	var str1 = "";
	var elm1 = eval('document.getElementById("error")');
	elm1.innerHTML = str1;
	var elm2 = eval('document.getElementById("errorspacer")');
	elm2.innerHTML = str1;
	return true;
  }
//-->