var reg = new Array();
reg[0] = '**Africa'
reg[1] = '**Asia/South Pacific'
reg[2] = '**Australia'
reg[3] = '**Central and Eastern Europe'
reg[4] = '**Latin America/Caribbean'
reg[5] = '**North America'
//africa countries
reg[6] = '0#Algeria'
reg[7] = '0#Angola'
reg[8] = '0#Benin'
reg[9] = '0#Botswana'
reg[10] = '0#Burundi'
reg[11] = '0#Burkina Faso'
reg[12] = '0#Cameroon'
reg[13] = '0#Cape Verde'
reg[14] = '0#Central African Republic'
reg[15] = '0#Chad'
reg[16] = '0#Comoros'
reg[17] = '0#Congo'
reg[18] = '0#Cote D Ivoire'
reg[19] = '0#Egypt'
reg[20] = '0#Eritrea'
reg[21] = '0#Ethiopia'
reg[22] = '0#Equatorial Guinea'
reg[23] = '0#Gabon'
reg[24] = '0#Gambia'
reg[25] = '0#Ghana'
reg[26] = '0#Guinea'
reg[27] = '0#Guinea-Bissau'
reg[28] = '0#Kenya'
reg[29] = '0#Lesotho'
reg[30] = '0#Libya'
reg[31] = '0#Madagascar'
reg[32] = '0#Malawi'
reg[33] = '0#Mali'
reg[34] = '0#Mauritania'
reg[35] = '0#Morocco'
reg[36] = '0#Mozambique'
reg[37] = '0#Nambia'
reg[38] = '0#Nigeria'
reg[39] = '0#Senegal'
reg[40] = '0#Sierra Leone'
reg[41] = '0#Seychelles'
reg[42] = '0#Sinail'
reg[43] = '0#Somalia'
reg[44] = '0#South Africa'
reg[45] = '0#Sudan'
reg[46] = '0#Swaziland'
reg[47] = '0#Tanzania'
reg[48] = '0#Togo'
reg[49] = '0#Tunisia'
reg[50] = '0#Uganda'
reg[51] = '0#Westem Sahara'
reg[52] = '0#Zaire'
reg[53] = '0#Zambia'
reg[54] = '0#Zimbabwe'
//asia countries
reg[55] = '1#Afghanistan'
reg[56] = '1#Armania'
reg[57] = '1#Azerbaijan'
reg[58] = '1#Bangladesh'
reg[59] = '1#Bhutan'
reg[60] = '1#Brunei Darussalam'
reg[61] = '1#Cambodia'
reg[62] = '1#China'
reg[63] = '1#India'
reg[64] = '1#Indonesia'
reg[65] = '1#Iran'
reg[66] = '1#Iraq'
reg[67] = '1#Israel'
reg[68] = '1#Japan'
reg[69] = '1#Jordan'
reg[70] = '1#Kazakhstan'
reg[71] = '1#Laos'
reg[72] = '1#Lebanon'
reg[73] = '1#Maldives'
reg[74] = '1#Mauritius'
reg[75] = '1#Malaysia'
reg[76] = '1#Mongolia'
reg[77] = '1#Myanmar'
reg[78] = '1#Nepal'
reg[79] = '1#North Korea'
reg[80] = '1#Oman'
reg[81] = '1#Pakistan'
reg[82] = '1#Palau'
reg[83] = '1#Papua New Guinea'
reg[84] = '1#Philippines'
reg[85] = '1#Qatar'
reg[86] = '1#Saudi Arab'
reg[87] = '1#Singapore'
reg[88] = '1#South Korea'
reg[89] = '1#Sri Lanka'
reg[90] = '1#Syria'
reg[91] = '1#Taiwan'
reg[92] = '1#Tajikistan'
reg[93] = '1#Thailand'
reg[94] = '1#Turkmenistan'
reg[95] = '1#Uzbekistan'
reg[96] = '1#United Arab Emirates'
reg[97] = '1#Vietnam'
reg[98] = '1#Yamen'

//australia 
reg[99] = '2#Australia'
reg[100] = '2#New Zealand'

//europe
reg[101] = '3#Albania'
reg[102] = '3#Austria'
reg[103] = '3#Belarus'
reg[104] = '3#Belgium'
reg[105] = '3#Bulgaria'
reg[106] = '3#Bosnia and Herzegovina'
reg[107] = '3#Croatia (Hrvatska)'
reg[108] = '3#Cyprus'
reg[109] = '3#Denmark'
reg[110] = '3#Estonia'
reg[111] = '3#Finland'
reg[112] = '3#France'
reg[113] = '3#Germany'
reg[114] = '3#Georgia'
reg[115] = '3#Gibraltar'
reg[116] = '3#Greece'
reg[117] = '3#Hungry'
reg[118] = '3#Ireland'
reg[119] = '3#Italy'
reg[120] = '3#Latvia'
reg[121] = '3#Lithuania'
reg[122] = '3#Luxembourg'
reg[123] = '3#Malta'
reg[124] = '3#Moldova'
reg[125] = '3#Netharland'
reg[126] = '3#Norway'
reg[127] = '3#Polland'
reg[128] = '3#Portugal'
reg[129] = '3#Romania'
reg[130] = '3#Slovenia'
reg[131] = '3#Switzerland'
reg[132] = '3#Spain'
reg[133] = '3#Turkey'
reg[134] = '3#Vatican City State'
reg[135] = '3#Ukraine'

//latin america

reg[136] = '4#Argentina'
reg[137] = '4#Bolivia'
reg[138] = '4#Brazil'
reg[139] = '4#Chile'
reg[140] = '4#Colombia'
reg[141] = '4#Dominican Republic'
reg[142] = '4#Ecuador'
reg[143] = '4#El Salvador'
reg[144] = '4#Guatemala'
reg[145] = '4#Guyana'
reg[146] = '4#Honduras'
reg[147] = '4#Peru'
reg[148] = '4#Nicaragua'
reg[149] = '4#Suriname'
reg[150] = '4#Venezuela'

//north america

reg[151] = '5#Bahamas'
reg[152] = '5#Canada'
reg[153] = '5#Cuba'
reg[154] = '5#Mexico'
reg[155] = '5#United States'




reg[9] = '63#India|Andhra Pradesh,Arunachal Pradesh,Assam,Bihar,Delhi,Chandigarh,Chattisgarh,Gujrat,Haryana,Himachal Pradesh,Jharkhand,Kerala,Madhya Pradesh,Maharashtra,Manipur,Meghalaya,Mizoram,Orissa,Punjab,Rajasthan,Sikkim,Tamil Nadu,Tripura,Uttaranchal,Uttar Pradesh,West Bengal'
reg[10] = '155#United States|Alabama,Arizona,Arkansas,California,Colorado,Connecticut,Delaware,Florida,Georgia,Hawaii,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky,Louisiana,Maine,Maryland,Massachusetts,Michigan,Minnesota,Mississippi,Missouri,Montana,Nebraska,Nevada,New Hampshire,New Jersey,New Mexico,New York,North Carolina,North Dakota,Ohio,Oklahoma,Oregon,Pennsylvania,Rhode Island,South Carolina,South Dakota,Tennessee,Texas,Utah,Vermont,Virginia,Washington,Washington DC,West Virginia,Wisconsin,Wyoming'

function loadRegion(dval) {
	var opVal=''
	var selIdx = -1;
	var cntr=1
		for (var i=0;i<reg.length;i++) 
		{
			opVal = reg[i];
			if (opVal.indexOf('**')==0) {
				opVal=opVal.substring(2);
				//alert(dval + "." + opVal)
				if (dval==opVal)
				{
					var op = new Option(opVal,opVal,true);
					selIdx=cntr
					alert(selIdx)
				} else {
					var op = new Option(opVal,opVal,false); 
				}
				form1.region.add(op);
				cntr++;
			}
		}
	form1.region.selectedIndex=selIdx; 
	clearList(form1.country)
	clearList(form1.state)
	//form1.country.add(new Option('Select Country','',true))
	//form1.state.add(new Option('Select State','',true))
}

function loadCountry(selCountry) {
		var opVal=''
		//if (form1.region.selectedIndex==0) {
			clearList(form1.country);
			clearList(form1.state);
		//}
		
		if (isObject(form1.country)) 
			form1.country.options[0] = new Option('Select Country','',true)
			else
		if (isObject(form1.state)) 
			form1.state.options[0] = new Option('Select State','',true)

		for (var i=0;i<reg.length;i++) 
		{
			opVal = reg[i];
			if (opVal.indexOf((form1.region.selectedIndex-1) + '#')==0) {
				if (opVal.indexOf('|')>=0)
				{
					opVal=opVal.substring(2,opVal.indexOf('|'));	
				} else {
					opVal=opVal.substring(2);
				}
				if (selCountry==opVal) {
					var op = new Option(opVal,opVal,0,true); 
				} else {
					var op = new Option(opVal,opVal,0,false); 
				}
				form1.country.add(op);
			}
		}
}

function loadState(selState) {
		clearList(form1.state);
		var opVal=''
		var CountryIdx=-1
		for (var i=0;i<reg.length;i++) 
		{
			if (reg[i].indexOf(form1.country.options[form1.country.selectedIndex].value)>=0)
			{
				CountryIdx=i
				break;
			}
		}

		if (CountryIdx==-1)

		{
			clearList(form1.state)
			form1.state.add(new Option('Select State','',true))
		}
		
		opVal = reg[CountryIdx];

		if (opVal.indexOf('|')>=0)	{
			states = opVal.substring(opVal.indexOf('|')+1)
			states = states.split(',')
			i=0;
			clearList(form1.state)
			//form1.state.add(new Option('Select State','',true))
			for (var i=0;i<states.length;i++) 
			{
				if (selState==states[i]) {
					var op = new Option(states[i],states[i],0,true); 
				} else {
					var op = new Option(states[i],states[i],0,false); 
				}
				form1.state.add(op);
			}
		}
}

function clearList(obj) {
	if (!isObject(obj)) 
	return false;
	
	var len=eval(obj.length);
	while(len >0)
	{
		obj.options[len]=null;
		len -= 1;
	}
}
function selValue(obj,val) {
	if (isObject(obj)) {
		for(i=0;i<obj.length;i++){
			if (obj.options[i].value==val) {
				obj.options[i].selected=true;
			}
		}
	}
}

function restoreValue(r,c,s) {
	if (r!='') {
		//Region
		selValue(form1.region,r)		
		if (c!='') {
			//Country
			loadCountry('')
			selValue(form1.country,c)		
			if (s!='') {
				//State
				loadState('')
				selValue(form1.state,s)		
			}		
		}
	}
}

function isArray(a) {
    return isObject(a) && a.constructor == Array;
}

function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}

function isFunction(a) {
    return typeof a == 'function';
}