

var JJ = jQuery.noConflict();

var schooltypeid = 2;

var boxes = {};

//boxes['iso2'] = {};
//boxes['iso2']['unload'] = new Array();
//boxes['iso2']['unloadlabel'] = new Array();
//boxes['iso2']['load'] = 'stateid';
//boxes['iso2']['loadlabel'] = 'State';
//boxes['iso2']['loadajax'] = 'ajax/statesget.php';

boxes['countryid'] = {};
boxes['countryid']['unload'] = new Array();
boxes['countryid']['unloadlabel'] = new Array();
boxes['countryid']['load'] = 'regionid';
boxes['countryid']['loadlabel'] = 'State/Prov';
boxes['countryid']['loadajax'] = 'ajax/regionsget.php';

boxes['regionid'] = {};
boxes['regionid']['unload'] = new Array();
boxes['regionid']['unloadlabel'] = new Array();
boxes['regionid']['load'] = 'city';
boxes['regionid']['loadlabel'] = 'City';

boxes['regionid']['loadajax'] = 'ajax/citiesget.php';

boxes['city'] = {};
boxes['city']['unload'] = new Array();
boxes['city']['unloadlabel'] = new Array();


//boxes.iso2.unload[0] = 'stateid';
//boxes.iso2.unload[1] = 'cityid';
//boxes.iso2.unload[2] = 'schoolid';
//boxes.iso2.unloadlabel[0] = 'State';
//boxes.iso2.unloadlabel[1] = 'City';
//boxes.iso2.unloadlabel[2] = 'School';

boxes.countryid.unload[0] = 'regionid';
boxes.countryid.unload[1] = 'city';
boxes.countryid.unloadlabel[0] = 'State/Prov';
boxes.countryid.unloadlabel[1] = 'City';

boxes.regionid.unload[0] = 'city';
boxes.regionid.unloadlabel[0] = 'City';



function unloadForNoRegions(id){


	for (var i = 0; i < boxes[id]['unload'].length ; i++){

		var x = document.getElementById('select_' + boxes[id]['unload'][i]);

		x.innerHTML = '';//'<p><label for="' + boxes[id]['unload'][i] + '">' + boxes[id]['unloadlabel'][i] + '</label></p>';


		
	}
	
	var x = document.getElementById('select_regionid');

	x.innerHTML = '<p><label>City/Town</label> <input type="text" id="city" name="city" size="20" maxlength="32">';
	
	
	
}

function boxChange(id){


	
	
	for (var i = 0; i < boxes[id]['unload'].length ; i++){

		var x = document.getElementById('select_' + boxes[id]['unload'][i]);

		x.innerHTML = '';//'<p><label for="' + boxes[id]['unload'][i] + '">' + boxes[id]['unloadlabel'][i] + '</label></p>';


		
	}

	//var iso2 = document.getElementById('iso2').value;
	var iso2 = '';
	var inID = document.getElementById(id).value;

	var dat = 'inID=' + escape(inID);

	if (inID > 0){	
	
	JJ.ajax({
		type: "GET",
		cache : "no",
		dataType: "json",
		url: boxes[id].loadajax,
		data: dat,
		success: function(json){

			if (json.status == 'success'){

				//var html  = '<p><label for="' + id + '">' + boxes[id]['loadlabel'] + '</label>';

				var html  = '<p><label>' + boxes[id]['loadlabel'] + '</label> ';
				
				
				
				
				// this is just a kludge because classmates uses the name "commin
				//if (id == 'city'){
				//	var boxname = 'communityId';
				//} else {
					var boxname = boxes[id].load;
				//}			
				
				html += '<select name="' + boxname + '" id="' + boxes[id].load + '" onChange="boxChange(\'' + boxes[id].load + '\')" style="width:182px;">';
				for (i = 0; i < json.records.length; i++){

					html += '<option value="' + json.records[i].v + '">' + json.records[i].o + '</option>';

				}

				var divload = document.getElementById('select_' + boxes[id].load);
				divload.innerHTML = html + '</select></p>';

			} else {
				
				unloadForNoRegions('countryid');				

			}

		}
	});
	
	}

	
	//if (id == 'schoolid'){
	//	var SCHOOLID = document.getElementById("schoolid").value;
	//	if (SCHOOLID.length > 0){
	//		location.href = 'http://www.classmates.com/registration/registration.jsp?s=77084&cType=school&communityId=' + escape(SCHOOLID);
	//	}
	//}
	
	

}



