var sList = '1,2,3';
var Array1 = new Array("('--Please Select--','',true,true)",
	"('Alabama',1)",
	"('Alaska',2)",
	"('Arizona',3)",
	"('Arkansas',4)",
	"('California',5)",
	"('Colorado',6)",
	"('Connecticut',7)",
	"('Delaware',8)",
	"('Florida',9)",
	"('Georgia',10)",
	"('Hawaii',11)",
	"('Idaho',12)",
	"('Illinois',13)",
	"('Indiana',14)",
	"('Iowa',15)",
	"('Kansas',16)",
	"('Kentucky',17)",
	"('Louisiana',18)",
	"('Maine',19)",
	"('Maryland',20)",
	"('Massachusetts',21)",
	"('Michigan',22)",
	"('Minnesota',23)",
	"('Mississippi',24)",
	"('Missouri',25)",
	"('Montana',26)",
	"('Nebraska',27)",
	"('Nevada',28)",
	"('New Hampshire',29)",
	"('New Jersey',30)",
	"('New Mexico',31)",
	"('New York',32)",
	"('North Carolina',33)",
	"('North Dakota',34)",
	"('Ohio',35)",
	"('Oklahoma',36)",
	"('Oregon',37)",
	"('Pennsylvania',38)",
	"('Rhode Island',39)",
	"('South Carolina',40)",
	"('South Dakota',41)",
	"('Tennessee',42)",
	"('Texas',43)",
	"('Utah',44)",
	"('Vermont',45)",
	"('Virginia',46)",
	"('Washington',47)",
	"('West Virginia',48)",
	"('Wisconsin',49)",
	"('Wyoming',50)",
	"('Washington, D.C.',51)",
	"('American Samoa',98)",
	"('Armed Forces Americas',99)",
	"('Armed Forces Europe',100)",
	"('Armed Forces Pacific',101)",
	"('Federated Micronesia',102)",
	"('Guam',103)",
	"('Marshall Islands',104)",
	"('N. Mariana Islands',105)",
	"('Palau',106)",
	"('Puerto Rico',107)",
	"('US Virgin Islands',108)");

var Array2 = new Array("('--Please Select--','',true,true)",
	"('Alberta',53)",
	"('British Columbia',54)",
	"('Manitoba',55)",
	"('New Brunswick',56)",
	"('Northwest Territories',57)",
	"('Nova Scotia',58)",
	"('Newfoundland and Labrador',59)",
	"('Yukon',60)",
	"('Saskatchewan',61)",
	"('Ontario',62)",
	"('Quebec',63)",
	"('Prince Edward Island',64)",
	"('Nunavut',65)");

var Array3 = new Array("('--Please Select--','',true,true)",
	"('Aguascalientes',66)",
	"('Baja California Norte',67)",
	"('Baja California Sur',68)",
	"('Campeche',69)",
	"('Chiapas',70)",
	"('Chihuahua',71)",
	"('Coahuila',72)",
	"('Colima',73)",
	"('Distrito Federal',74)",
	"('Durango',75)",
	"('Guanajuato',76)",
	"('Guerrero',77)",
	"('Hidalgo',78)",
	"('Jalisco',79)",
	"('Mexico',80)",
	"('Michoacan',81)",
	"('Morelos',82)",
	"('Nayarit',83)",
	"('Nuevo Leon',84)",
	"('Oaxaca',85)",
	"('Puebla',86)",
	"('Queretaro',87)",
	"('Quintana Roo',88)",
	"('San Luis Potosi',89)",
	"('Sinaloa',90)",
	"('Sonora',91)",
	"('Tabasco',92)",
	"('Tamaulipas',93)",
	"('Tlaxcala',94)",
	"('Veracruz',95)",
	"('Yucatan',96)",
	"('Zacatecas',97)");

HM_IE  = document.all ? true : false;
HM_NS4 = document.layers ? true : false;

function fillStates(frmName,dest,selected,destClear,dflt)
{
	var inList = findValue(sList,selected);
	if(inList==0){selected=0;}
	if (typeof(destClear)=="undefined")destClear=true;

	var obj = HM_IE ? document.all(dest) : document.getElementById(dest);
	if(obj){
		for (var i=(obj.options.length-1); i>=0; i--) {obj.options[i] = null;}
		if(selected==0){
			if(typeof(dflt)!='undefined') obj.options[0]= new Option(dflt,'');
			divStates(dest,destClear,false)
		}
		if (selected!=0){	 
			var selectedArray = eval("Array"+selected);
			var svState=0; //changed state written in a hidden ctrl
			try{svState=document.getElementById(dest+"chg").value;}
			catch (e){}
			if (typeof(dflt)!='undefined'){obj.options[0]=new Option(dflt,'',true,true);}
			else{obj.options[0]=new Option('--Please Select--','',true,true);}
  	
			for (var i=1; i <= selectedArray.length-1; i++){
				obj.options[i]= eval("new Option" + selectedArray[i]);
				if (!destClear && obj.options[i].value==svState) obj.options[i].selected=true;
			}
			divStates(dest,true,true)
		}
	}
}

function divStates(dest,destClear,cbo){
	try{
		var obj = HM_IE ? document.all(dest+"Name") : document.getElementById(dest+"Name");	 //clear StateName ctrl
		if (destClear) obj.value=""; 
	}
	catch (e){}
	try{
		var src = document.getElementById('div'+dest);
		HideShow(src, cbo ? 'show': 'hide');

		var src = document.getElementById('div'+dest+'Name');
		HideShow(src, cbo ? 'hide': 'show');		
	}
	catch (e){}
}

function CopyCtrValues(frm, fromCtrl, toCtrl){
	fillStates(frm,toCtrl+'State',eval("frm." + fromCtrl + "Country.value"));
	var ctrlNames = new Array("Name","ContactName","CompanyName","Address1","Address2","City","State","StateName","Country","County","Zip","Phone","PhoneExt","Fax","Email","WebURL")
	for(i=0; i<ctrlNames.length; i++){
		try{
			eval("frm." + toCtrl + ctrlNames[i] + ".value=frm." + fromCtrl + ctrlNames[i] + ".value;");
		}
		catch(e){}
	}
	if (typeof(g_bIsDirty)!="undefined"){
		g_bIsDirty=true;
		window.status="";
	}
}

// Show/hide object on a form
// we pass as parameter the action to take: show or hide.
function HideShow(obj,sh)
{
	obj.style.display = (sh=="show") ? "block" : "none";
}

function isArray(obj) {
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}

//------------------------------------------------------------------
// findValue()
// search a text input value for a certain value
//------------------------------------------------------------------
function findValue(strContainer,strLookup)
{
	var values = strContainer.split(',');
	for (var i = 0; i < values.length; ++i){
		if(strLookup==values[i]){ return 1; }		
		}
	return 0;
}

function AddrCheck(sPrfx,setFocus){
	var sValidate="";
	if (typeof(setFocus)=='undefined') setFocus=true;
	sValidate=sValidate + checkValue(sPrfx + "Country", sPrfx + "Country",(sValidate=='' && setFocus));

	if(sValidate==''&& parseInt(getValue(sPrfx + 'Country'))>3)
		 sValidate=sValidate + checkValue(sPrfx + "StateName", sPrfx +  "StateName",(sValidate=='' && setFocus));
	else sValidate=sValidate + checkValue(sPrfx + "State",sPrfx + "State",(sValidate=='' && setFocus));

	sValidate=sValidate + checkValue(sPrfx + "Address1", sPrfx + "Address",(sValidate=='' && setFocus));
	sValidate=sValidate + checkValue(sPrfx + "City", sPrfx + "City",(sValidate=='' && setFocus));
	sValidate=sValidate + checkValue(sPrfx + "Zip", sPrfx + "Zip",(sValidate=='' && setFocus));

	return sValidate;
}

function getValue(sCtr){
	var sVal='';
	try	{ sVal=eval("document.all." + sCtr).value; }
	catch (e){ sVal=""; }
	return sVal;
}

function checkValue(sCtr,sValidate,sFocus){
	try	{ 
		oFld=eval("document.all." + sCtr);
		if (oFld.value=="")	{
			sValidate="\n\t" + sValidate;
			if (sFocus==true) oFld.focus();
		}
		else sValidate="";
	}
	catch (e){ sValidate=""; }
	return sValidate;
}

function AddrFocus(frm,sValidate){
	var pos=sValidate.indexOf('\n\t',2);
	if (pos==-1) pos=sValidate.length;
	try
	{
		oFld=eval("document.all." + sValidate.substring(2,pos));
		oFld.focus();
	}
	catch (e){if (typeof(frm.Address1)!='undefined')frm.Address1.focus();}
}

function ReloadStates(country, ctrlTo){
	var obj = document.getElementById(ctrlTo);
	if(!obj){
		obj = document.getElementById('StateID');
	}

	for (var i=(obj.options.length-1); i>=0; i--) {obj.options[i] = null;}
	if(country==0){
		obj.options[0]=new Option('Select country first','',true,true);
	}
	else{
		obj.options[0]=new Option('Please select','',true,true);
		var selectedArray = eval("Array"+country);
		for (var i=1; i <= selectedArray.length-1; i++){
			obj.options[i]= eval("new Option" + selectedArray[i]);
		}
	}
}

