﻿// JScript File

// JScript File For EventStaging.aspx Page To Bind the Subcategory Combobox By Using JavaScript And XML
var subCat;
var mobjXMLRequest;

//Creating XML Object
function GetXmlRequest_2()
{
	try
	{
		mobjXMLRequest = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			mobjXMLRequest = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			mobjXMLRequest = null;
		}
	}
	if(!mobjXMLRequest && typeof mobjXMLRequest != "undefined") 
	{
		mobjXMLRequest = new XMLHttpRequest();
	}
	
	
}

//send the request to AjaxReturnDS.aspx page when We Pass The SelectedItem Value of Combo
function SendRequest_2(SelectedId,pagePath)
{

    var lstrURL = pagePath + "?IdPassed=" + SelectedId;
    GetXmlRequest_2();//Get Response From AjaxReturnDS.aspx
             
    if(mobjXMLRequest)
    { 
        mobjXMLRequest.onreadystatechange = OnGettingValues_2;
        mobjXMLRequest.open("GET",lstrURL,true);
        mobjXMLRequest.send(null);
       
    }
    
}
//To send Request to get data as XML
function SendRequestThroughAjax_ddMake(strcat,strsubcat,pagePath,hdName)
{
   
    //set model value to 0
    document.getElementById(hdName).value = 0;
    
    subCat=strsubcat;
    var pobjid = document.getElementById(strcat);
   
    var pobjidvalue = pobjid.value;
    // alert(pobjidvalue);
    if(pobjid.value == '' || pobjid.value == null)
    {
            pobjidvalue = -1; 
    }
       //Setting Model value in Combo when categories is All Categories
    if(pobjid.value == '0')
    {
  
    var ddmodel= document.getElementById('ddModel');
    ddmodel.length=0;
     
    var oOption1 = document.createElement('OPTION');
    oOption1.text = 'All Models';//To add "Select SubCategory" at 0th Index 
    oOption1.value = '0';
    ddmodel.options.add(oOption1);
    ddmodel.value='0';
    }
    if(pobjid.value == 'O')
    {
        pobjidvalue = -1; 
        document.getElementById('txtMake').disabled = false;
        document.getElementById('txtModel').disabled = false;
    }
    SendRequest_2(pobjidvalue,pagePath);
}

//To Get the response of XML
function OnGettingValues_2() 
{
    
      if(mobjXMLRequest.readyState == 4)
     {
        //alert(mobjXMLRequest.status); 
        if(mobjXMLRequest.status == 200)
        {
       
            var DSTag = mobjXMLRequest.responseXML.documentElement;
            TakeAction_2(DSTag,subCat);
        }
    }
}   
  
//To Fill The SubCategory DropDownList
function TakeAction_2(DSTag, subCat)
{    
    //alert(DSTag);
    var lobjCombo = document.getElementById(subCat);
    var ComboTable = DSTag.getElementsByTagName('Table');
    
    lobjCombo.options.length = 0;
    var oOption1 = document.createElement('OPTION');
    oOption1.text = 'All Makes';//To add "Select SubCategory" at 0th Index 
    oOption1.value = '0';
    lobjCombo.options.add(oOption1);
    for(var i=0 ; i < ComboTable.length ; i++)
    {
          var Value = ComboTable[i].getElementsByTagName('MakeId')[0].firstChild.nodeValue;//To set the Value field of Subcategory Combo
          var Text = ComboTable[i].getElementsByTagName('MakeTitle')[0].firstChild.nodeValue;//To set the Text field of Subcategory Combo
                                  
          var oOption = document.createElement('OPTION');
          oOption.text = Text;
          oOption.value = Value;
          lobjCombo.options.add(oOption);
    }
    
//    if(subCat == 'ddlModel')
//    {
//        var oOption2 = document.createElement('OPTION');
//        oOption2.text = 'Other Model';//To add "Select SubCategory" at 0th Index 
//        oOption2.value = 'O';
//        lobjCombo.options.add(oOption2);
//    }
    
}

//function FillHiddenField(ctrName,hdName)
//{
//   document.getElementById(hdName).value =  document.getElementById(ctrName).value;
//   //alert(document.getElementById(hdName).value);
//}






