function createAjaxObj()
{
	var httprequest = false
	
	if (window.XMLHttpRequest)
	{ // if Mozilla, Safari etc  Non-IE browsers
		httprequest=new XMLHttpRequest()
		
		if (httprequest.overrideMimeType)
			httprequest.overrideMimeType('text/xml')
	} 
	else if (window.ActiveXObject)
	{ // if IE
		try 
		{
			httprequest=new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e)
		{
			try
			{
				httprequest=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){}
		}
	}
	return httprequest
}	

/////on country onchange - state names
function sct_country_onchange(type,frm)
{
	//alert("type="+type);
	//alert(document.getElementById("sct_state").value);
	if(document.getElementById("sct_state")!=null)
		document.getElementById("sct_state").options.length = 1 ;
		
	if(document.getElementById("sct_country").selectedIndex>0)
	{
		ajaxinstance = createAjaxObj()
		xmlindicator=(arguments.length>0)?1 : 0
		//alert(frm);
		if (frm == "")
		{
			var parameters="for="+type+"&countryid="+document.getElementById("sct_country").options[document.getElementById("sct_country").selectedIndex].value;
			//alert("parameters="+parameters);
		}
		else
		{
			var parameters="for="+type+"&countryid="+frm;
			//alert("else")	;
		}	
		//alert(parameters);
		ajaxinstance.onreadystatechange=alertcontents
		ajaxinstance.open('GET', "ajax.asp?"+parameters, true)
		ajaxinstance.send(null)
	}
	else
	{
		if (type == "state")
			document.getElementById("sct_state").options.length = 1 ;
	}		
}

/////on state onchange - city names
function sct_state_onchange(type,frm)
{
	//alert("type="+type);
	//alert(document.getElementById("sct_state").value);
	if(document.getElementById("sct_city")!=null)
		document.getElementById("sct_city").options.length = 1 ;
		
	if(document.getElementById("sct_state").selectedIndex>0)
	{
		ajaxinstance = createAjaxObj()
		xmlindicator=(arguments.length>0)?1 : 0
		//alert(frm);
		if (frm == "")
		{
			var parameters="for="+type+"&stateid="+document.getElementById("sct_state").options[document.getElementById("sct_state").selectedIndex].value;
			//alert("parameters="+parameters);
		}
		else
		{
			var parameters="for="+type+"&stateid="+frm;
			//alert("else");
		}	
		//alert(parameters);
		ajaxinstance.onreadystatechange=alertcontents
		ajaxinstance.open('GET', "ajax.asp?"+parameters, true)
		ajaxinstance.send(null)
	}
	else
	{
		if (type == "city")
			document.getElementById("sct_city").options.length = 1 ;
	}		
}

/////on country onchange - state names
function sct_country1_onchange(type,frm)
{
	//alert("type="+type);
	//alert(document.getElementById("sct_state1").value);
	if(document.getElementById("sct_state1")!=null)
		document.getElementById("sct_state1").options.length = 1 ;
		
	if(document.getElementById("sct_country1").selectedIndex>0)
	{
		ajaxinstance = createAjaxObj()
		xmlindicator=(arguments.length>0)?1 : 0
		//alert(frm);
		if (frm == "")
		{
			var parameters="for="+type+"&countryid="+document.getElementById("sct_country1").options[document.getElementById("sct_country1").selectedIndex].value;
			//alert("parameters="+parameters);
		}
		else
		{
			var parameters="for="+type+"&countryid="+frm;
			//alert("else")	;
		}	
		//alert(parameters);
		ajaxinstance.onreadystatechange=alertcontents
		ajaxinstance.open('GET', "ajax.asp?"+parameters, true)
		ajaxinstance.send(null)
	}
	else
	{
		if (type == "state1")
			document.getElementById("sct_state1").options.length = 1 ;
	}		
}

/////on state onchange - city names
function sct_state1_onchange(type,frm)
{
	//alert("type="+type);
	//alert(document.getElementById("sct_state1").value);
	if(document.getElementById("sct_city1")!=null)
		document.getElementById("sct_city1").options.length = 1 ;
		
	if(document.getElementById("sct_state1").selectedIndex>0)
	{
		ajaxinstance = createAjaxObj()
		xmlindicator=(arguments.length>0)?1 : 0
		//alert(frm);
		if (frm == "")
		{
			var parameters="for="+type+"&stateid="+document.getElementById("sct_state1").options[document.getElementById("sct_state1").selectedIndex].value;
			//alert("parameters="+parameters);
		}
		else
		{
			var parameters="for="+type+"&stateid="+frm;
			//alert("else");
		}	
		//alert(parameters);
		ajaxinstance.onreadystatechange=alertcontents
		ajaxinstance.open('GET', "ajax.asp?"+parameters, true)
		ajaxinstance.send(null)
	}
	else
	{
		if (type == "city1")
			document.getElementById("sct_city1").options.length = 1 ;
	}		
}

/////on discipline onchange - subject names
function sct_discipline_onchange(type,frm)
{
	//alert("type="+type);
	//alert(document.getElementById("sct_discipline").value);
	if(document.getElementById("sct_subject")!=null)
		document.getElementById("sct_subject").options.length = 1 ;
		
	if(document.getElementById("sct_discipline").selectedIndex>0)
	{
		ajaxinstance = createAjaxObj()
		xmlindicator=(arguments.length>0)?1 : 0
		//alert(frm);
		if (frm == "")
		{
			var parameters="for="+type+"&subjectid="+document.getElementById("sct_discipline").options[document.getElementById("sct_discipline").selectedIndex].value;
			//alert("parameters="+parameters);
		}
		else
		{
			var parameters="for="+type+"&subjectid="+frm;
			//alert("else");
		}	
		//alert(parameters);
		ajaxinstance.onreadystatechange=alertcontents
		ajaxinstance.open('GET', "ajax.asp?"+parameters, true)
		ajaxinstance.send(null)
	}
	else
	{
		if (type == "subject")
			document.getElementById("sct_subject").options.length = 1 ;
	}		
}

//function to return values
function alertcontents()
{
	var iloop, option1;
	var id, name;
	var ary;
	var txt_arr;
	
	iloop = 0;
	if (ajaxinstance.readyState == 4)
	{ 
		//if request of file completed
		var returndata;
		if (ajaxinstance.status==200)
		{ 
		//	if request was successful
		
		//	if (xmlindicator)
		//	{
		//		//alert(ajaxinstance.responseXML)
		//		mstr_text = ajaxinstance.responseXML
		//	}
		//	else
		//	{
				//alert(ajaxinstance.responseText)
				mstr_text = ajaxinstance.responseText
		//	}
			if (mstr_text.length != 0) 
			{
				txt_arr =  mstr_text.split("^");	//split to check the type
				
				if (txt_arr[0]=="state")
				{
					document.getElementById("sct_state").options.length = 1 ;
				}
				else if (txt_arr[0]=="state1")
				{
					document.getElementById("sct_state1").options.length = 1 ;
				}
				else if (txt_arr[0]=="city")
				{
					document.getElementById("sct_city").options.length = 1 ;
				}
				else if (txt_arr[0]=="city1")
				{
					document.getElementById("sct_city1").options.length = 1 ;
				}
				else if (txt_arr[0]=="subject")
				{
					document.getElementById("sct_subject").options.length = 1 ;
				}
				if (txt_arr[1].length != 0) 
				{
					txt_arr[1] = txt_arr[1].substring(0,txt_arr[1].length-2);	//removing ~#
					returndata = txt_arr[1].split("~#");
					for (iloop = 0 ; iloop < returndata.length ; iloop ++)
					{
						var option = new Option();
						ary = returndata[iloop].split("`#");
						id = ary[0];
						name = ary[1];
						option.value = id;
						option.text =  name;
						if(txt_arr[0]=="state")
						{
							//document.getElementById("sct_state").options.add(option);
							document.getElementById("sct_state").options[iloop+1] = option;
						}
						else if(txt_arr[0]=="state1")
						{
							//document.getElementById("sct_state1").options.add(option);
							document.getElementById("sct_state1").options[iloop+1] = option;
						}
						else if(txt_arr[0]=="city")
						{
							//document.getElementById("sct_city").options.add(option);
							document.getElementById("sct_city").options[iloop+1] = option;
						}	
						else if(txt_arr[0]=="city1")
						{
							//document.getElementById("sct_city1").options.add(option);
							document.getElementById("sct_city1").options[iloop+1] = option;
						}	
						else if(txt_arr[0]=="subject")
						{
							//document.getElementById("sct_subject").options.add(option);
							document.getElementById("sct_subject").options[iloop+1] = option;
						}
					}
				}
			}		
		}
	}
	return false;
}