
//Global XMLHTTP Request object
var XmlHttp;
var childcontrolName;

//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateXmlHttp()
{
	//Creating object of XMLHTTP in IE
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp = null;
		}
	}
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp = new XMLHttpRequest();
	}
}

//Gets called when country combo box selection changes
function CountryListOnChange(AjaxMaincontrol,AjaxChildControl,Ajax_Lookup_Stored_Proc,sm_t_field_id,SM_APP_Code_ID,SM_Client_ID,SM_Entity_ID,ScreenID) 
{
	// var win=window.open("../Include/Add_Options_New.aspx?Control_ID="+Control_ID+"&Field_Name="+Field_Name+"&ID="+ID+"&DST="+DST+"&DID="+DID+"&SID="+SID+"&Field_ID="+Field_ID,'calWin','width=700,height=110,left=250,top=280,resizable');
	childcontrolName=AjaxChildControl;
	//alert(AjaxMaincontrol);
//	alert(childcontrolName);
	var countryList = document.getElementById(AjaxMaincontrol);
//alert(countryList);
	//Getting the selected country from country combo box.
	var selectedCountry = countryList.options[countryList.selectedIndex].value;

	// URL to get states for a given country
	//var requestUrl = AjaxServerPageName + "?code=" + encodeURIComponent(selectedCountry);
	var requestUrl = "../AJAX/AjaxServer.aspx?code="+selectedCountry+"&Proc_Name="+Ajax_Lookup_Stored_Proc+"&ParmSMFieldID="+sm_t_field_id+"&ParmAppCodeID="+SM_APP_Code_ID+"&ParmClientID="+SM_Client_ID+"&ParmEntityID="+SM_Entity_ID+"&ParmScreenID="+ScreenID;
//	alert(requestUrl);

	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleResponse;
		
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		
		//Sends the request to server
		XmlHttp.send(null);		
	}
}


//Gets called when country combo box selection changes
function CityListOnChange(AjaxMaincontrol,AjaxChildControl,Ajax_Lookup_Stored_Proc) 
{
 
	// var win=window.open("../Include/Add_Options_New.aspx?Control_ID="+Control_ID+"&Field_Name="+Field_Name+"&ID="+ID+"&DST="+DST+"&DID="+DID+"&SID="+SID+"&Field_ID="+Field_ID,'calWin','width=700,height=110,left=250,top=280,resizable');
	childcontrolName=AjaxChildControl;
	//alert(AjaxMaincontrol);
//	alert(childcontrolName);
	var StateList = document.getElementById(AjaxMaincontrol);
//alert(StateList);
	//Getting the selected country from country combo box.
	var selectedState = StateList.options[StateList.selectedIndex].value;
		// URL to get states for a given country
	//var requestUrl = AjaxServerPageName + "?code=" + encodeURIComponent(selectedCountry);
	var requestUrl = "../AJAX/AjaxServer.aspx?code="+selectedState+"&Proc_Name="+Ajax_Lookup_Stored_Proc;

//	alert(requestUrl);
	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleResponse;
		
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.

		XmlHttp.open("GET", requestUrl,  true);
		//Sends the request to server
		XmlHttp.send(null);		
	}
}


function check_channel_name(Channel_Url)
{

	
	var requestUrl = "../AJAX/AjaxServer_for_channel_name.aspx?Channel_url="+document.getElementById(Channel_Url).value;
	CreateXmlHttp();
	if(XmlHttp)
	{
		XmlHttp.onreadystatechange = HandleResponse_for_channel;
		XmlHttp.open("GET", requestUrl,  true);
		XmlHttp.send(null);		
	}
}

function open_ajax_child(AjaxMaincontrol,AjaxChildControl)
{

	childcontrolName=AjaxChildControl;
	var Primary_Cat_List = document.getElementById(AjaxMaincontrol);
//alert(StateList);
	//Getting the selected country from country combo box.
	var selectedPrimary_Cat = Primary_Cat_List.options[Primary_Cat_List.selectedIndex].value;

	var requestUrl= "../Ajax/AjaxServer_For_Forum.aspx?pri_cat="+selectedPrimary_Cat;
	CreateXmlHttp();
	if(XmlHttp)
	{
		XmlHttp.onreadystatechange = HandleResponse_for_forum;
		XmlHttp.open("GET", requestUrl,  true);
		XmlHttp.send(null);		
	}
}

//Called when response comes back from server
function HandleResponse_for_channel()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{			
			var Channel_result_xml=XmlHttp.responseXML.documentElement;
			var Channel_result = Channel_result_xml.getElementsByTagName('Result');
			if(GetInnerText(Channel_result[0])=="1")
			{
						document.getElementById("Chl_Not_Avl").style.display="";
						document.getElementById("Chl_Avl").style.display="none";
						document.getElementById("rw_Blnk").style.display="";
						document.getElementById("rw_Blnk_T").style.display="";
						document.getElementById("rw_Blnk_B").style.display="";						
			}
			else
			{
						document.getElementById("Chl_Not_Avl").style.display="none";
						document.getElementById("Chl_Avl").style.display="";
						document.getElementById("rw_Blnk").style.display="";
						document.getElementById("rw_Blnk_T").style.display="";
						document.getElementById("rw_Blnk_B").style.display="";								
			}
			
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}


//Called when response comes back from server
function HandleResponse_for_forum()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{			
			ClearAndSetPrimaryCatListItems(XmlHttp.responseXML.documentElement);
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}

//Clears the contents of state combo box and adds the states of currently selected country
function ClearAndSetPrimaryCatListItems(PrimaryCatNode)
{
   
    var SecondaryCatList = document.getElementById(childcontrolName);
  	//Clears the state combo box contents.
	for (var count = SecondaryCatList.options.length-1; count >-1; count--)
	{
		SecondaryCatList.options[count] = null;
	}


	var stateNodes = PrimaryCatNode.getElementsByTagName('Category_Name');
	var stateNodes1 = PrimaryCatNode.getElementsByTagName('Category_ID');
	var textValue; 
	var textvalue1;
	var optionItem;
	//Add new states list to the state combo box.
	for (var count = 0; count < stateNodes.length; count++)
	{
   		textValue = GetInnerText(stateNodes[count]);
   		textvalue1=GetInnerText(stateNodes1[count]);
		optionItem = new Option( textValue, textvalue1,  false, false);
		SecondaryCatList.options[SecondaryCatList.length] = optionItem;
	}	
}



//Called when response comes back from server
function HandleResponse()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{			
			ClearAndSetStateListItems(XmlHttp.responseXML.documentElement);
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}

//Clears the contents of state combo box and adds the states of currently selected country
function ClearAndSetStateListItems(countryNode)
{
   
    var stateList = document.getElementById(childcontrolName);
  	//Clears the state combo box contents.
	for (var count = stateList.options.length-1; count >-1; count--)
	{
		stateList.options[count] = null;
	}


	var stateNodes = countryNode.getElementsByTagName('Lookup_Name');
	var stateNodes1 = countryNode.getElementsByTagName('Lookup_Id');
	var textValue; 
	var textvalue1;
	var optionItem;
	//Add new states list to the state combo box.
	for (var count = 0; count < stateNodes.length; count++)
	{
   		textValue = GetInnerText(stateNodes[count]);
   		textvalue1=GetInnerText(stateNodes1[count]);
		optionItem = new Option( textValue, textvalue1,  false, false);
		stateList.options[stateList.length] = optionItem;
	}
		
	
        optionItem = new Option( "Others","-2",  false, false);
        stateList.options[stateList.length] = optionItem;
        if(count==0)
        {
            if(document.getElementById("University_TextBox"))
            {
                document.getElementById("University_TextBox").style.display="";
            }
        }
        else
        {
           if(document.getElementById("University_TextBox"))
            {
                document.getElementById("University_TextBox").style.display="none";
            }
        }
 

	
}

//Returns the node text value 
function GetInnerText (node)
{
	 return (node.textContent || node.innerText || node.text) ;
}









