
function validate_frm_get_coupon()
{	
	with (document.frm_get_coupon)
	{

		if(cityname.value == 0 )
		{
			alert("Please select your city");
			cityname.focus();			
			return false;
		}
		
		if(cityname.value=="" && schid.value == "0" || schid.value == "" )
		{
			alert("Please select your school");
			cityname.focus();			
			return false;
		}
		
		
	}
	return true;			
}


function FillSchoolListCombo(CityPkid)
{
	//alert(CityPkid);

	var str_city_name;
	var int_city_pkid;
	var cboSchool;
	
	int_city_pkid=CityPkid;

	if(int_city_pkid == "-1")
	{
		//alert(int_city_pkid);
		document.frm_get_coupon.action="./city_na.php";
		document.frm_get_coupon.method="post";
		document.frm_get_coupon.submit();
	}

	var selectedcityindex = document.frm_get_coupon.cityname.selectedIndex;
	str_city_name=document.frm_get_coupon.cityname[selectedcityindex].text;
	//alert(str_city_name);


	cboSchool=document.getElementById("schid");	

	///-----------------------------------------------------------
	///  Create Ajax Request Object based on browser type
	///-----------------------------------------------------------
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
	  	xmlhttp=new XMLHttpRequest();
	}
	else
	{
		// code for IE6, IE5 etc...
	  	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	///-----------------------------------------------------------
	
	
	///-----------------------------------------------------------
	/// Define fuction what to do when Ajax Request Completed
	///-----------------------------------------------------------
	xmlhttp.onreadystatechange=function()
	{

		if(xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			//alert("test 1");
			// Write operation that needs when Ajax request completed.
			// Return school list format as under
			// Response Text Format: 1|||DePaul University~~2|||Loyola University~~5|||Chicago State University
			// If School not found then Response Text=0
			var str_result=xmlhttp.responseText;

			// If City not found then Response Text=0
			if(str_result==0)
			{
				//alert("test 2");
				cboSchool.options.length=0; // Empty Combo
				cboSchool.options.length=cboSchool.options.length+1; 
				cboSchool.options[0].value=0;
				cboSchool.options[0].text="City not found: "+str_city_name;
				cboSchool.disabled=true;
				cboSchool.className="home_drop_down_list_disable";
				return;					
			}

			// If School not found for a city then Response Text=1
			if(str_result==1)
			{
				cboSchool.options.length=0; // Empty Combo
				cboSchool.options.length=cboSchool.options.length+1; 
				cboSchool.options[0].value=0;
				cboSchool.options[0].text="School not added for: " + str_city_name;
				cboSchool.disabled=true;
				cboSchool.className="home_drop_down_list_disable";
				return;					
			}

			// If School list retunred in results then fillup School combo/listbox
			cboSchool.options.length=0; // Empty Combo
			cboSchool.disabled=false;  // Enable it
			cboSchool.className="home_drop_down_list";  // set class for enable
						
			// Split result with ~~ character
			var arry_result=str_result.split("~~");
			var arry_school_record; 
			for(i=0; i <arry_result.length; i++)
			{
				// Split one record in to SchoolPkid and School Name
				arry_school_record=arry_result[i].split("|||");				

				// Add one School to combo i.e. Add option
				cboSchool.options.length++;
				cboSchool.options[i].value=arry_school_record[0]; // 0 index for SchoolPkid
				cboSchool.options[i].text=arry_school_record[1]; // 1 index for SchoolName

			}

		}

	}
	xmlhttp.open("GET","./home_get_schoolsby_cityname.php?cityid="+int_city_pkid,true);
	xmlhttp.send();			

}

