// can be used to populate a drop down menu when all countries are needed
var allCountries = {"SELE":"Please select a country","AFG":"Afghanistan", "ALB":"Albania", "DZA":"Algeria", "ASM":"American Samoa", "AND":"Andorra", "AGO":"Angola", "AIA":"Anguilla", "ATG":"Antigua and Barbuda", "ARG":"Argentina", "ARM":"Armenia", "ABW":"Aruba", "AUS":"Australia", "AUT":"Austria", "AZE":"Azerbaijan", "BHS":"Bahamas", "BHR":"Bahrain", "BGD":"Bangladesh", "BRB":"Barbados", "BLR":"Belarus", "BEL":"Belgium", "BLZ":"Belize", "BEN":"Benin", "BMU":"Bermuda", "BTN":"Bhutan", "BOL":"Bolivia", "BIH":"Bosnia and Herzegovina", "BWA":"Botswana", "BRA":"Brazil", "VGB":"British Virgin Islands", "BRN":"Brunei Darussalam", "BGR":"Bulgaria", "BFA":"Burkina Faso", "BDI":"Burundi", "KHM":"Cambodia", "CMR":"Cameroon", "CAN":"Canada", "CPV":"Cape Verde", "CYM":"Cayman Islands", "CAF":"Central African Republic", "TCD":"Chad", "CHL":"Chile", "CHN":"China", "COL":"Colombia", "COM":"Comoros", "COG":"Congo", "COK":"Cook Islands", "CRI":"Costa Rica", "CIV":"Cote d'Ivoire", "HRV":"Croatia", "CUB":"Cuba", "CYP":"Cyprus", "CZE":"Czech Republic", "PRK":"Democratic People's Republic of Korea", "COD":"Democratic Republic of the Congo", "DNK":"Denmark", "DJI":"Djibouti", "DMA":"Dominica", "DOM":"Dominican Republic", "ECU":"Ecuador", "EGY":"Egypt", "SLV":"El Salvador", "GNQ":"Equatorial Guinea", "ERI":"Eritrea", "EST":"Estonia", "ETH":"Ethiopia", "FRO":"Faeroe Islands", "FLK":"Falkland Islands (Malvinas)", "FJI":"Fiji", "FIN":"Finland", "FRA":"France", "GUF":"French Guiana", "PYF":"French Polynesia", "GAB":"Gabon", "GMB":"Gambia", "GEO":"Georgia", "DEU":"Germany", "GHA":"Ghana", "GIB":"Gibraltar", "GRC":"Greece", "GRL":"Greenland", "GRD":"Grenada", "GLP":"Guadeloupe", "GUM":"Guam", "GTM":"Guatemala","GGY":"Guernsey", "GIN":"Guinea", "GNB":"Guinea-Bissau", "GUY":"Guyana", "HTI":"Haiti", "VAT":"Holy See", "HND":"Honduras", "HKG":"Hong Kong Special Administrative Region of China", "HUN":"Hungary", "ISL":"Iceland", "IND":"India", "IDN":"Indonesia", "IRN":"Iran (Islamic Republic of)", "IRQ":"Iraq", "IRL":"Ireland","IMN":"Isle of Man", "ISR":"Israel", "ITA":"Italy", "JAM":"Jamaica", "JPN":"Japan","JEY":"Jersey", "JOR":"Jordan", "KAZ":"Kazakhstan", "KEN":"Kenya", "KIR":"Kiribati", "KWT":"Kuwait", "KGZ":"Kyrgyzstan", "LAO":"Lao People's Democratic Republic", "LVA":"Latvia", "LBN":"Lebanon", "LSO":"Lesotho", "LBR":"Liberia", "LBY":"Libyan Arab Jamahiriya", "LIE":"Liechtenstein", "LTU":"Lithuania", "LUX":"Luxembourg", "MAC":"Macao Special Administrative Region of China", "MDG":"Madagascar", "MWI":"Malawi", "MYS":"Malaysia", "MDV":"Maldives", "MLI":"Mali", "MLT":"Malta", "MHL":"Marshall Islands", "MTQ":"Martinique", "MRT":"Mauritania", "MUS":"Mauritius", "MYT":"Mayotte", "MEX":"Mexico", "FSM":"Micronesia (Federated States of)", "MCO":"Monaco", "MNG":"Mongolia", "MSR":"Montserrat", "MAR":"Morocco", "MOZ":"Mozambique", "MMR":"Myanmar", "NAM":"Namibia", "NRU":"Nauru", "NPL":"Nepal", "NLD":"Netherlands", "ANT":"Netherlands Antilles", "NCL":"New Caledonia", "NZL":"New Zealand", "NIC":"Nicaragua", "NER":"Niger", "NGA":"Nigeria", "NIU":"Niue", "NFK":"Norfolk Island", "MNP":"Northern Mariana Islands", "NOR":"Norway", "PSE":"Occupied Palestinian Territory", "OMN":"Oman", "PAK":"Pakistan", "PLW":"Palau", "PAN":"Panama", "PNG":"Papua New Guinea", "PRY":"Paraguay", "PER":"Peru", "PHL":"Philippines", "PCN":"Pitcairn", "POL":"Poland", "PRT":"Portugal", "PRI":"Puerto Rico", "QAT":"Qatar", "KOR":"Republic of Korea", "MDA":"Republic of Moldova", "REU":"Reunion", "ROU":"Romania", "RUS":"Russian Federation", "RWA":"Rwanda", "SHN":"Saint Helena", "KNA":"Saint Kitts and Nevis", "LCA":"Saint Lucia", "SPM":"Saint Pierre and Miquelon", "VCT":"Saint Vincent and the Grenadines", "WSM":"Samoa", "SMR":"San Marino", "STP":"Sao Tome and Principe", "SAU":"Saudi Arabia", "SEN":"Senegal", "YUG":"Serbia and Montenegro", "SYC":"Seychelles", "SLE":"Sierra Leone", "SGP":"Singapore", "SVK":"Slovakia", "SVN":"Slovenia", "SLB":"Solomon Islands", "SOM":"Somalia", "ZAF":"South Africa", "ESP":"Spain", "LKA":"Sri Lanka", "SDN":"Sudan", "SUR":"Suriname", "SJM":"Svalbard and Jan Mayen Islands", "SWZ":"Swaziland", "SWE":"Sweden", "CHE":"Switzerland", "SYR":"Syrian Arab Republic", "TWN":"Taiwan Province of China", "TJK":"Tajikistan", "THA":"Thailand", "MKD":"The former Yugoslav Republic of Macedonia", "TLS":"Timor-Leste", "TGO":"Togo", "TKL":"Tokelau", "TON":"Tonga", "TTO":"Trinidad and Tobago", "TUN":"Tunisia", "TUR":"Turkey", "TKM":"Turkmenistan", "TCA":"Turks and Caicos Islands", "TUV":"Tuvalu", "UGA":"Uganda", "UKR":"Ukraine", "ARE":"United Arab Emirates", "TZA":"United Republic of Tanzania", "UK":"United Kingdom", "VIR":"United States Virgin Islands", "USA":"United States of America","URY":"Uruguay", "UZB":"Uzbekistan", "VUT":"Vanuatu", "VEN":"Venezuela", "VNM":"Viet Nam", "WLF":"Wallis and Futuna Islands", "ESH":"Western Sahara", "YEM":"Yemen", "ZMB":"Zambia", "ZWE":"Zimbabwe"};

// to populate list of countries in country dropdown
var mCountryArrayWithCodes = { "0000" : "United States", "0001" : "Canada", "1072" : "United Kingdom", "1007" : "Australia" };

// for to display only Country DropDown in jsp pages to populate Shipping countries in country dropdown
var mShippingCountryArrayWithCodes = {"SELE":"Please select a country","AFG":"Afghanistan", "ALB":"Albania", "DZA":"Algeria", "ASM":"American Samoa", "AND":"Andorra", "AGO":"Angola", "AIA":"Anguilla", "ATG":"Antigua and Barbuda", "ARG":"Argentina", "ARM":"Armenia", "ABW":"Aruba", "AUS":"Australia", "AUT":"Austria", "AZE":"Azerbaijan", "BHS":"Bahamas", "BHR":"Bahrain", "BGD":"Bangladesh", "BRB":"Barbados", "BLR":"Belarus", "BEL":"Belgium", "BLZ":"Belize", "BEN":"Benin", "BMU":"Bermuda", "BTN":"Bhutan", "BOL":"Bolivia", "BIH":"Bosnia and Herzegovina", "BWA":"Botswana", "BRA":"Brazil", "VGB":"British Virgin Islands", "BRN":"Brunei Darussalam", "BGR":"Bulgaria", "BFA":"Burkina Faso", "BDI":"Burundi", "KHM":"Cambodia", "CMR":"Cameroon", "CPV":"Cape Verde", "CYM":"Cayman Islands", "CAF":"Central African Republic", "TCD":"Chad", "CHL":"Chile", "CHN":"China", "COL":"Colombia", "COM":"Comoros", "COG":"Congo", "COK":"Cook Islands", "CRI":"Costa Rica", "CIV":"Cote d'Ivoire", "HRV":"Croatia", "CUB":"Cuba", "CYP":"Cyprus", "CZE":"Czech Republic", "PRK":"Democratic People's Republic of Korea", "COD":"Democratic Republic of the Congo", "DNK":"Denmark", "DJI":"Djibouti", "DMA":"Dominica", "DOM":"Dominican Republic", "ECU":"Ecuador", "EGY":"Egypt", "SLV":"El Salvador", "GNQ":"Equatorial Guinea", "ERI":"Eritrea", "EST":"Estonia", "ETH":"Ethiopia", "FRO":"Faeroe Islands", "FLK":"Falkland Islands (Malvinas)", "FJI":"Fiji", "FIN":"Finland", "FRA":"France", "GUF":"French Guiana", "PYF":"French Polynesia", "GAB":"Gabon", "GMB":"Gambia", "GEO":"Georgia", "DEU":"Germany", "GHA":"Ghana", "GIB":"Gibraltar", "GRC":"Greece", "GRL":"Greenland", "GRD":"Grenada", "GLP":"Guadeloupe", "GUM":"Guam", "GTM":"Guatemala","GGY":"Guernsey", "GIN":"Guinea", "GNB":"Guinea-Bissau", "GUY":"Guyana", "HTI":"Haiti", "VAT":"Holy See", "HND":"Honduras", "HKG":"Hong Kong Special Administrative Region of China", "HUN":"Hungary", "ISL":"Iceland", "IND":"India", "IDN":"Indonesia", "IRN":"Iran (Islamic Republic of)", "IRQ":"Iraq", "IRL":"Ireland","IMN":"Isle of Man", "ISR":"Israel", "ITA":"Italy", "JAM":"Jamaica", "JPN":"Japan","JEY":"Jersey", "JOR":"Jordan", "KAZ":"Kazakhstan", "KEN":"Kenya", "KIR":"Kiribati", "KWT":"Kuwait", "KGZ":"Kyrgyzstan", "LAO":"Lao People's Democratic Republic", "LVA":"Latvia", "LBN":"Lebanon", "LSO":"Lesotho", "LBR":"Liberia", "LBY":"Libyan Arab Jamahiriya", "LIE":"Liechtenstein", "LTU":"Lithuania", "LUX":"Luxembourg", "MAC":"Macao Special Administrative Region of China", "MDG":"Madagascar", "MWI":"Malawi", "MYS":"Malaysia", "MDV":"Maldives", "MLI":"Mali", "MLT":"Malta", "MHL":"Marshall Islands", "MTQ":"Martinique", "MRT":"Mauritania", "MUS":"Mauritius", "MYT":"Mayotte", "MEX":"Mexico", "FSM":"Micronesia (Federated States of)", "MCO":"Monaco", "MNG":"Mongolia", "MSR":"Montserrat", "MAR":"Morocco", "MOZ":"Mozambique", "MMR":"Myanmar", "NAM":"Namibia", "NRU":"Nauru", "NPL":"Nepal", "NLD":"Netherlands", "ANT":"Netherlands Antilles", "NCL":"New Caledonia", "NZL":"New Zealand", "NIC":"Nicaragua", "NER":"Niger", "NGA":"Nigeria", "NIU":"Niue", "NFK":"Norfolk Island", "MNP":"Northern Mariana Islands", "NOR":"Norway", "PSE":"Occupied Palestinian Territory", "OMN":"Oman", "PAK":"Pakistan", "PLW":"Palau", "PAN":"Panama", "PNG":"Papua New Guinea", "PRY":"Paraguay", "PER":"Peru", "PHL":"Philippines", "PCN":"Pitcairn", "POL":"Poland", "PRT":"Portugal", "PRI":"Puerto Rico", "QAT":"Qatar", "KOR":"Republic of Korea", "MDA":"Republic of Moldova", "REU":"Reunion", "ROU":"Romania", "RUS":"Russian Federation", "RWA":"Rwanda", "SHN":"Saint Helena", "KNA":"Saint Kitts and Nevis", "LCA":"Saint Lucia", "SPM":"Saint Pierre and Miquelon", "VCT":"Saint Vincent and the Grenadines", "WSM":"Samoa", "SMR":"San Marino", "STP":"Sao Tome and Principe", "SAU":"Saudi Arabia", "SEN":"Senegal", "YUG":"Serbia and Montenegro", "SYC":"Seychelles", "SLE":"Sierra Leone", "SGP":"Singapore", "SVK":"Slovakia", "SVN":"Slovenia", "SLB":"Solomon Islands", "SOM":"Somalia", "ZAF":"South Africa", "ESP":"Spain", "LKA":"Sri Lanka", "SDN":"Sudan", "SUR":"Suriname", "SJM":"Svalbard and Jan Mayen Islands", "SWZ":"Swaziland", "SWE":"Sweden", "CHE":"Switzerland", "SYR":"Syrian Arab Republic", "TWN":"Taiwan Province of China", "TJK":"Tajikistan", "THA":"Thailand", "MKD":"The former Yugoslav Republic of Macedonia", "TLS":"Timor-Leste", "TGO":"Togo", "TKL":"Tokelau", "TON":"Tonga", "TTO":"Trinidad and Tobago", "TUN":"Tunisia", "TUR":"Turkey", "TKM":"Turkmenistan", "TCA":"Turks and Caicos Islands", "TUV":"Tuvalu", "UGA":"Uganda", "UKR":"Ukraine", "ARE":"United Arab Emirates", "TZA":"United Republic of Tanzania", "VIR":"United States Virgin Islands", "URY":"Uruguay", "UZB":"Uzbekistan", "VUT":"Vanuatu", "VEN":"Venezuela", "VNM":"Viet Nam", "WLF":"Wallis and Futuna Islands", "ESH":"Western Sahara", "YEM":"Yemen", "ZMB":"Zambia", "ZWE":"Zimbabwe"};

//mCountryArrayWithCodesForCatalog has added to hide United Kingdom country from dropdown in Request Catalog page.
var mCountryArrayWithCodesForCatalog = {"0000" : "United States", "0001" : "Canada"};

// state codes and names corresponding to available country codes
var mStatesArrayWithCodes = {
    // United States
	"0000" : {
        "AK" : "AK - Alaska",
        "AL" : "AL - Alabama",
        "AZ" : "AZ - Arizona",
        "AR" : "AR - Arkansas",
        "CA" : "CA - California",
        "CO" : "CO - Colorado",
        "CT" : "CT - Connecticut",
        "DE" : "DE - Delaware",
        "DC" : "DC - District of Columbia",
        "FL" : "FL - Florida",
        "GA" : "GA - Georgia",
        "HI" : "HI - Hawaii",
        "ID" : "ID - Idaho",
        "IL" : "IL - Illinois",
        "IN" : "IN - Indiana",
        "IA" : "IA - Iowa",
        "KS" : "KS - Kansas",
        "KY" : "KY - Kentucky",
        "LA" : "LA - Louisiana",
        "ME" : "ME - Maine",
        "MD" : "MD - Maryland",
        "MA" : "MA - Massachusetts",
        "MI" : "MI - Michigan",
        "MN" : "MN - Minnesota",
        "MS" : "MS - Mississippi",
        "MO" : "MO - Missouri",
        "MT" : "MT - Montana",
        "NE" : "NE - Nebraska",
        "NV" : "NV - Nevada",
        "NH" : "NH - New Hampshire",
        "NJ" : "NJ - New Jersey",
        "NM" : "NM - New Mexico",
        "NY" : "NY - New York",
        "NC" : "NC - North Carolina",
        "ND" : "ND - North Dakota",
        "OH" : "OH - Ohio",
        "OK" : "OK - Oklahoma",
        "OR" : "OR - Oregon",
        "PA" : "PA - Pennsylvania",
        "RI" : "RI - Rhode Island",
        "SC" : "SC - South Carolina",
        "SD" : "SD - South Dakota",
        "TN" : "TN - Tennessee",
        "TX" : "TX - Texas",
        "UT" : "UT - Utah",
        "VT" : "VT - Vermont",
        "VA" : "VA - Virginia",
        "WA" : "WA - Washington",
        "WV" : "WV - West Virginia",
        "WI" : "WI - Wisconsin",
        "WY" : "WY - Wyoming",
        "AA" : "AA - Armed Forces - America",
        "AE" : "AE - Armed Forces - Europe",
        "AP" : "AP - Armed Forces - Pacific",
        "AS" : "AS - American Samoa",
        "FM" : "FM - Fed. States of Micronesia",
        "GU" : "GU - Guam",
        "MH" : "MH - Marshall Islands",
        "MP" : "MP - Northern Mariana Islands",
        "PW" : "PW - Palau",
        "PR" : "PR - Puerto Rico",
        "VI" : "VI - Virgin Islands" 
    },
	// Canada
    "0001" : {
        "AB" : "AB - Alberta",
        "BC" : "BC - British Columbia",
        "MB" : "MB - Manitoba",
        "NB" : "NB - New Brunswick",
        "NL" : "NL - Newfoundland and Labrador",
        "NT" : "NT - Northwest Territories",
        "NS" : "NS - Nova Scotia",
        "NU" : "NU - Nunavut",
        "ON" : "ON - Ontario",
        "PE" : "PE - Prince Edward Islands",
        "QC" : "QC - Quebec",
        "SK" : "SK - Saskatchewan",
        "YT" : "YT - Yukon Territory" 
    },
    // Australia
	"1007" : {
        "ACT" : "ACT - Australian Capital Territory",
        "NSW" : "NSW - New South Wales",
        "NT" : "NT - Northern Territory",
        "QLD" : "QLD - Queensland",
        "SA" : "SA - South Australia",
        "TAS" : "TAS - Tasmania",
        "VIC" : "VIC - Victoria",
        "WA" : "WA - Western Australia" 
    },
	// UK
	"1072" : { 
		"FN" : "FN - Foreign Nations"
	}
}


/* UTILITY FUNCTIONS */
// Sort associative array by keys
function sortAssociativeArray(aInput) {
	var aTemp = [];
	for (var sKey in aInput)
	aTemp.push([sKey, aInput[sKey]]);
	aTemp.sort(function () {return arguments[0][1] < arguments[1][1]});
	
	var aOutput = [];
	for (var nIndex = aTemp.length-1; nIndex >=0; nIndex--)
	aOutput[aTemp[nIndex][0]] = aTemp[nIndex][1];
	
	return aOutput;
}

// re-sort the list
function reSortList(menuId, selected) {		
    var menuObj = $(menuId);
    if (menuObj) {
	    var arrTexts = new Array();
	    var arrValues = new Array();
	    for(i=0; i<menuObj.length; i++)  {
		    var txt = menuObj.options[i].text;
		    var val = menuObj.options[i].value;
		    arrTexts.push(txt);
		    arrValues[txt] = val;
	    }
	    arrTexts.sort();
	    var selectedIndex;
	    for(i=0; i<menuObj.length; i++)  {	    	
            menuObj.options[i].text = arrTexts[i];
            menuObj.options[i].value = arrValues[menuObj.options[i].text];              
            if (selected != null) {
    		    if (menuObj.options[i].value == selected) {    	    		    	
    		    	menuObj.options[i].setAttribute('selected','selected');
    		    	selectedIndex = i;    		    	
    	   	 	}
    	   	}
	    }	   
	    // We have to set the selection twice because of some refresh issue
	    // in the shipping and billing pages
	    menuObj.options[selectedIndex].setAttribute('selected','selected');
    }   
}


// add options to drop down menu
function addSelectOptions(val, txt, menuID, selected) {
	var menuObj = $(menuID);
	if (menuObj) {
	  	var opt = document.createElement("option");
	   	opt.text = txt;
	    opt.value = val;
	    if (selected != null) {
		    if (opt.value == selected) {
		    	opt.setAttribute('selected','selected');
	   	 	}
	   	}	
	    try {
	    	menuObj.add(opt, null); // standards compliant; doesn't work in IE
	    } catch(e) {
	    	menuObj.add(opt); // IE only
	    }	  
	}    
}
// reset options for drop down
function resetSelectOptions(menuID) {
	var menuObj = $(menuID);
	if (menuObj) {
		while(menuObj.length != 0) {
			menuObj.options[menuObj.length-1] = null;
		}
	}
}


/* INITIALIZE COUNTRY AND STATES DROP DOWN MENUS */
function initialize(pCountry, pState, countryArr, statesArr) {	
	// Fix IE6 onload bug
	if (navigator.userAgent.indexOf("MSIE 6") > 0) {
		Event.observe(window,'load', function() {
			callInit(pCountry, pState, countryArr, statesArr);
			resetDisplayAttributes($("countries"), 'states');
		});
	} else {
		callInit(pCountry, pState, countryArr, statesArr);
	}	
}
function callInit(pCountry, pState, countryArr, statesArr) {
	// check array to use to populate drop down menu
	if (countryArr == null) {
		// default array to use
		countryArr = mCountryArrayWithCodes;
	} else {
		// override the default with the values passed in
		mCountryArrayWithCodes = countryArr;
	}	
	
	if (statesArr == null) {
		// default array to use
		statesArr = mStatesArrayWithCodes;
	} else {
		// override the default with the values passed in
		mStatesArrayWithCodes = statesArr;
	}	
	
	// check values and ensure that they are not null
	if (pCountry != null && pState != null) {
		// get available countries and populate drop down menu
		initializeCountry('countries', pCountry, countryArr);		
		initializeStates(pCountry, 'states', pState);			 	
	} else {
		// error! pCountry and/or pState == null	
	}
}


/* COUNTRIES */
function initializeCountry(pCountryElem, pSelected, countryArr) {
	// verify pCountryElem exists
	if ($(pCountryElem)) {
		// check pSelected key
		if (pSelected == null || pSelected == '') {
			// default country : United States
			pSelected = "0000";
		}		
		
		// loop through keys and values to add to drop down menu
		for (i in countryArr) {							
			var val = i;						
			var txt = countryArr[i];			
			if (txt.length > 1) {
				addSelectOptions(val, txt, 'countries', pSelected);
			}
		}
		//Start Of Trac 4527 to sort the contries in alphabetical order in IE9.Will work for all browsers
		reSortList("countries", pSelected);
		//End Of Trac 4527
		// Re-sort select menu to fix the Chrome bug where-in it re-sorts the array by keys
		// Need to remove this logic along with the reSortList function 
		// after the Chrome bug is fixed
		//Start Of Trac 4527
		//Commented here and calling 'reSortList' method to the all the browsers instead of Only 'Chrome'
		/*
        if (navigator.userAgent.indexOf("Chrome") > 0) {
        	reSortList("countries", pSelected);
        }
        */
		//End Of Trac 4527
	} else {
		// error! pCountryElem does not exist
		
	}
}


/* STATES */
function initializeStates(pCountry, pStateElem, pState){
	// verify pStateElem exists
	if ($(pStateElem)) {		
		// check pState key	
		if (pState == null) {
			pState = '';
		}
		
		// loop through keys and values to add to drop down menu
		if (mStatesArrayWithCodes[pCountry]) {
			// reset states menu
			resetSelectOptions('states');						
			var states = mStatesArrayWithCodes[pCountry][0];			
			for (i in states) {				
				var txt = states[i];
				//Start of trac 4527
				if(txt == "FN - Foreign Nations"){
					txt = document.getElementById("alternateState").value;
					if(txt != ''){
						txt ='';
					}					
				}
				//End of trac 4527
				if (txt.length > 1) {
					addSelectOptions(i, txt, 'states', pState);
				}				
			}
			
			var territories = mStatesArrayWithCodes[pCountry][1];			
			for (j in territories) {				
				var txt = territories[j];
				if (txt.length > 1) {
					addSelectOptions(j, txt, 'states', pState);
				}				
			}
		} 
	} else {
		// error! pStateElem does not exist		
	}
}
// re-populate states menu based on newly selected country
function changeState(pCountry, pElem) {	
	// check if pCountry exists
	if ($(pCountry)) {
		// re-initialize states based on newly selected country		
		initializeStates($(pCountry).options[$(pCountry).options.selectedIndex].value, 'states', '');
		
		// reset the display attributes (like zip code length etc.,)
		resetDisplayAttributes($("countries"), 'states');
		
		//Start Trac-4527.
    	// Calling the resetStateAttributes() function to get the state select Field in IE9 browser.
        var countryCode = $(pCountry).options[$(pCountry).options.selectedIndex].value;
        resetStateAttributes(countryCode);
		//End Trac-4527.

		// reset the state field
		resetStateField($("countries"), 'states');
		
		//post the form to refresh the shipping methods
		updateState('refreshShipMethods');		
	} else {
		// error! pCountry does not exist
	}
}
 
 
/* FORM SUBMIT FUNCTIONS */
function updateState(actionval)
{
	if (document.shippingForm) {
		document.shippingForm.formAction.value=actionval;
		document.shippingForm.submit();
	}
}

function setUsingprofileAddress(){
	if (document.shippingForm) {
		if(document.shippingForm.isUsingPA != undefined) {
  			document.shippingForm.isUsingPA.value="false";
		}
	}
}

function movetobilling(action){
	if (document.shippingForm) {
		document.shippingForm.formAction.value=action;
		document.shippingForm.submit();
	}
}

function updateaddress(actionval){
	if (document.shippingForm) {
		if(document.shippingForm.isUsingPA != undefined) {
			document.shippingForm.isUsingPA.value="true";
			document.shippingForm.formAction.value=actionval;
			document.shippingForm.submit();
		}
	}
}

function giftoptioncheck(){
	if (document.shippingForm) {
		if (document.shippingForm.giftcheck.checked) {
			document.shippingForm.elements["/uo/commerce/order/purchase/ShippingFormHandler.moveToBillingSuccessURL"].value="../checkout_giftoptions.jsp";
		} else {
			document.shippingForm.elements["/uo/commerce/order/purchase/ShippingFormHandler.moveToBillingSuccessURL"].value="../billing.jsp";
		}
	}
}

//Trac- 4527 changes started
/* Function added to populate the states select field  in IE9 Browser.*/
function resetStateAttributes(pCountryCode) {
	if (pCountryCode == 0000 || pCountryCode == 0001 || pCountryCode == 1007) {
		if (document.getElementById("ProvinceReqd")) {
			document.getElementById("ProvinceReqd").style.display = "";
		}
		if (document.getElementById("Province")) {
			document.getElementById("Province").style.display = "none";
		}
		if (document.getElementById("states")) {
			document.getElementById("states").style.display = "";
		}
		if (document.getElementById("alternateState")) {
			document.getElementById("alternateState").style.display = "none";
		}
	} else {
		if (document.getElementById("ProvinceReqd")) {
			document.getElementById("ProvinceReqd").style.display = "none";
		}
		if (document.getElementById("Province")) {
			document.getElementById("Province").style.display = "";
		}
		if (document.getElementById("states")) {
			document.getElementById("states").style.display = "none";
			document.getElementById("states").value = "AK";
		}
		if (document.getElementById("alternateState")) {
			document.getElementById("alternateState").style.display = "";
		}
	}
}
//Trac- 4527 changes Ended.
