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 broad_onchange(type,frm)
{
	//alert("type="+type);
	//alert(document.getElementById("sct_state").value);
	if(document.getElementById("sct_detailedsubject")!=null)
		document.getElementById("sct_detailedsubject").options.length = 1 ;
	
	if(document.getElementById("sct_broadsubject").selectedIndex>0)
	{
		ajaxinstance = createAjaxObj()
		xmlindicator=(arguments.length>0)?1 : 0
		//alert(frm);
		if (frm == "")
		{
			var parameters="for="+type+"&broadsubjectid="+document.getElementById("sct_broadsubject").options[document.getElementById("sct_broadsubject").selectedIndex].value;
			//alert("parameters="+parameters);
		}
		else
		{
			var parameters="for="+type+"&broadsubjectid="+frm;
			//alert("else");
		}	
		//alert(parameters);
		ajaxinstance.onreadystatechange=alertcontents
		ajaxinstance.open('GET', "ajax.asp?"+parameters, false)
		ajaxinstance.send(null)
		//alert("hi");
	}
	else
	{
		if ((type == "detail"))
			document.getElementById("sct_detailedsubject").options.length = 1 ;
	}		
}

/////on publisher onchange - imprint names
function sct_publisher_onchange(type,frm)
{
	//alert("type="+type);
	//alert(document.getElementById("sct_state").value);
	if(document.getElementById("sct_imprint")!=null)
		document.getElementById("sct_imprint").options.length = 1 ;
	
	if(document.getElementById("sct_publisher").selectedIndex>0)
	{
		ajaxinstance = createAjaxObj()
		xmlindicator=(arguments.length>0)?1 : 0
		//alert(frm);
		if (frm == "")
		{
			var parameters="for="+type+"&pubid="+document.getElementById("sct_publisher").options[document.getElementById("sct_publisher").selectedIndex].value;
			//alert("parameters="+parameters);
		}
		else
		{
			var parameters="for="+type+"&pubid="+frm;
			//alert("else");
		}	
		//alert(parameters);
		ajaxinstance.onreadystatechange=alertcontents
		ajaxinstance.open('GET', "ajax.asp?"+parameters, false)
		ajaxinstance.send(null)
		//alert("hi");
	}
	else
	{
		if ((type == "detail"))
			document.getElementById("sct_imprint").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]=="detail")
				{
					document.getElementById("sct_detailedsubject").options.length = 1 ;
				}
				else if (txt_arr[0]=="imprint")
				{
					document.getElementById("sct_imprint").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]=="detail")
						{
							document.getElementById("sct_detailedsubject").options.add(option);
						}
						else if(txt_arr[0]=="imprint")
						{
							document.getElementById("sct_imprint").options.add(option);
						}
					}
				}
			}		
		}
	}
	return false;
}