
//Global XMLHTTP Request object
var XmlHttp;
var optcnt; 
//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();
	}
}


function MyCheckOnChange(chk) 
{
    document.getElementById("ctl00_ContentPlaceHolder1_HiddenField1").value="";
    document.getElementById("ctl00_ContentPlaceHolder1_HiddenField2").value="";
    document.getElementById("ctl00_ContentPlaceHolder1_HiddenField3").value="";
    document.getElementById("ctl00_ContentPlaceHolder1_HiddenField4").value="";
    
    var turncnt=document.getElementById("ctl00_ContentPlaceHolder1_Total").value;
    var i=0;
    while(i<=turncnt) 
    {
          opt=document.getElementById('chk_'+i);
          optval=opt.checked;
          //alert(optval);
          if(optval==true)
          {
            var turn=opt;
            if(i==0)
                document.getElementById("ctl00_ContentPlaceHolder1_HiddenField1").value=opt.value;
            else if(i==1)
                document.getElementById("ctl00_ContentPlaceHolder1_HiddenField2").value=opt.value;
            else if(i==2)
                document.getElementById("ctl00_ContentPlaceHolder1_HiddenField3").value=opt.value;
            else if(i==3)
                document.getElementById("ctl00_ContentPlaceHolder1_HiddenField4").value=opt.value;
          }
          i=i+1; 
    }
}

//Gets called when country combo box selection changes
function CountryListOnChange() 
{
	var countryList = document.getElementById("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 + "?SelectedCountry=" + encodeURIComponent(selectedCountry);
	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 MyParamOnChange(chk) 
{
	var	turncnt= document.getElementById("total_turn").value;


	var Qty = document.getElementById("quantity_lst");
	var Size = document.getElementById("size_lst");
	var Color = document.getElementById("color_lst");
	var proof = document.getElementById("proof_lst");
	
	//var turn = document.getElementById("total_turn");
var product=document.getElementById("hproductid");
var turn = document.getElementById("turnchk");
	//Getting the selected country from country combo box.
	var selectedQty = Qty.options[Qty.selectedIndex].value;
	var selectedSize = Size.options[Size.selectedIndex].value;
	var selectedColor = Color.options[Color.selectedIndex].value;
	optcnt= document.getElementById("optcnt1").value;

	var selectedproof = proof.options[proof.selectedIndex].value;
	var productid = product.value;
	var opt,optval;
	//var selectedSize = Size.options[Size.selectedIndex].value;
  var i=1;
  var optparam="";
  while(i<=optcnt) 
  {
  opt=document.getElementById('optlst_'+i);
  optval=opt.options[opt.selectedIndex].value;
    optparam = optparam + "&optlst_"+i +"=" +  optval;
   i=i+1; 
  }
  i=1;
  while(i<=turncnt) 
  {
  opt=document.getElementById('turn_'+i);
  optval=opt.checked;
if(optval==true)
{
	var turn = opt;
chk=opt.value
alert(chk);
}
else
{
}
   i=i+1; 
  }
  
	// URL to get states for a given country
	var requestUrl = AjaxServerPageName + "?optcnt1="+ optcnt+ "&trial=1&productid="+ productid +"&selectedQty=" + selectedQty + "&selectedSize=" + selectedSize + "&selectedColor=" + selectedColor + optparam +  "&selectedproof=" + selectedproof +"&selectedturn=" +chk;
	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 Reply(chk)
{
    //alert(chk);
    var msg=document.getElementById('Reply_'+chk).value;
    //alert(msg);
	var requestUrl = AjaxServerPageName + "?fun=1&msg="+ msg;
	//alert(requestUrl);
	CreateXmlHttp();
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleResponse4;
		
		//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 DelMsg(chk)
{
    //alert(chk);
    var msg=document.getElementById('chk_'+chk).value;
    //alert(msg);
	var requestUrl = AjaxServerPageName + "?fun=2&msg="+ msg;
	//alert(requestUrl);
	CreateXmlHttp();
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleResponse3;
		
		//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 OnBrokerSelect(chk)
{
var temp = new Array();
tmp=chk.split('$');
document.getElementById("txtRefName").text =  tmp[1];
//alert(document.getElementById("txtRefName").text);
document.getElementById("txtrefno").value = tmp[0];
//alert(document.getElementById("txtrefno").value);

	var requestUrl = AjaxServerPageName + "?trial=3&id="+ tmp[0] +"&Name=" + tmp[1];
	CreateXmlHttp();
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{

		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleResponse1;
		
		//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);		
	}
}

//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)
		{		
		var i;
            var doc = XmlHttp.responseXML.documentElement;
        		//alert(doc.getElementsByTagName("proofprice1")[0].childNodes[0].nodeValue);
   document.getElementById("Subtotal1").innerHTML = doc.getElementsByTagName("subtot")[0].childNodes[0].nodeValue;
  document.getElementById("turnprice").innerHTML=doc.getElementsByTagName("turnprice")[0].childNodes[0].nodeValue;
   document.getElementById("baseprice").innerHTML = doc.getElementsByTagName("baseprice")[0].childNodes[0].nodeValue;
   document.getElementById("unitcost").innerHTML = doc.getElementsByTagName("unitcost")[0].childNodes[0].nodeValue;
     document.getElementById("proofprice").innerHTML = doc.getElementsByTagName("proofprice1")[0].childNodes[0].nodeValue;

  // document.getElementById("baseprice").innerHTML = doc.getElementsByTagName("subtot")[0].childNodes[0].nodeValue;
  //alert(optcnt);
for (i=1; i <= optcnt; i++)
{
var j = i-1;
   //alert(document.getElementById("param1_" + j).innerHTML);
    // alert(doc.getElementsByTagName("optlst_" + i)[0].childNodes[0].nodeValue);
   document.getElementById("param1_" + j).innerHTML = doc.getElementsByTagName("optlst_" + i)[0].childNodes[0].nodeValue;
}
	
//{
//alert(document.getElementById("param1_" + i).innerHTML +" = " + doc.getElementsByTagName("optlst" + i)[0].childNodes[0].nodeValue);
//   document.getElementById("param1_" + i).innerHTML = doc.getElementsByTagName("optlst" + i)[0].childNodes[0].nodeValue)
//}
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}

}


function HandleResponse1()
{

	// 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)
		{		
			//alert("3");

		var i;
              var doc = XmlHttp.responseXML.documentElement;
              document.getElementById("txtRefName").value = doc.getElementsByTagName("name")[0].childNodes[0].nodeValue;
              document.getElementById("txtrefno").value=doc.getElementsByTagName("id")[0].childNodes[0].nodeValue;
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}

}

function ChangeTypes()
{
    var cat = document.getElementById("DDLCat");
    for (var count = cat.options.length-1; count >-1; count--)
	{
		cat.options[count] = null;		
	}
    var make=document.getElementById("DDLMake");
    for (var count1 = make.options.length-1; count1 >-1; count1--)
	{
		make.options[count1] = null;		
	}
    var type1 = document.getElementById("DDLType");
//alert(type1);
	//Getting the selected country from country combo box.
	var id = type1.options[type1.selectedIndex].value;
	document.getElementById("HiddenField2").value=id;
	//alert(id);
	// URL to get states for a given country
	var requestUrl = AjaxServerPageName + "?fun=3&id=" + id;
	CreateXmlHttp();
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = TypeResponse;
		
		//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 ChangeCity()
{
    var mod=document.getElementById("ctl00_ContentPlaceHolder1_DDLCity");
    for (var count1 = mod.options.length-1; count1 >-1; count1--)
	{
		mod.options[count1] = null;		
	}
    var state1 = document.getElementById("ctl00_ContentPlaceHolder1_DDLState");
    var state = state1.options[state1.selectedIndex].value;
    document.getElementById("ctl00_ContentPlaceHolder1_HiddenField6").value=state1.options[state1.selectedIndex].text;
    //alert(state);
    var requestUrl = AjaxServerPageName + "?fun=6&state=" + state;
    //alert(requestUrl);
	CreateXmlHttp();
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = CityResponse;
		
		//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 ChangeCity1()
{
    //alert('dd');
    var mod=document.getElementById("ctl00_ContentPlaceHolder1_DDLCity");
    for (var count1 = mod.options.length-1; count1 >-1; count1--)
	{
		mod.options[count1] = null;		
	}
    var state1 = document.getElementById("ctl00_ContentPlaceHolder1_DDLState");
    var state = state1.options[state1.selectedIndex].value;
    //document.getElementById("ctl00_ContentPlaceHolder1_HiddenField6").value=state;
    //alert(state);
    var requestUrl = AjaxServerPageName + "?fun=6&state=" + state;
    //alert(requestUrl);
	CreateXmlHttp();
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = CityResponse;
		
		//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 CityResponse()
{
	if(XmlHttp.readyState == 4)
	{
//alert(XmlHttp.status);
		if(XmlHttp.status == 200)
		{		
              var doc = XmlHttp.responseXML.documentElement;
              var i = doc.getElementsByTagName("i")[0].childNodes[0].nodeValue; 
              //alert(i);
              var type2 =document.getElementById("ctl00_ContentPlaceHolder1_DDLCity");      
              type2.options[0]=new Option("--Select--",0);        
              //type2.options[1]=new Option("Other",1); 
              for (var j= 1;j<=i;j++)
              {
              type2.options[j]=new Option(doc.getElementsByTagName("Data_"+j)[0].childNodes[0].nodeValue,doc.getElementsByTagName("value_"+j)[0].childNodes[0].nodeValue);
                //var opt=document.createElement("option");
                //type2.options.add(opt);
              //opt.text=doc.getElementsByTagName("Data_"+j)[0].childNodes[0].nodeValue;
              //opt.value=doc.getElementsByTagName("value_"+j)[0].childNodes[0].nodeValue;
              }
           type2.SelectedIndex=0;
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}

}
function ChangeVTypes()
{
    var cat = document.getElementById("ctl00_ContentPlaceHolder1_DDLCat");
    for (var count = cat.options.length-1; count >-1; count--)
	{
		cat.options[count] = null;		
	}
    var make=document.getElementById("ctl00_ContentPlaceHolder1_DDLMake");
    for (var count1 = make.options.length-1; count1 >-1; count1--)
	{
		make.options[count1] = null;		
	}
    var type1 = document.getElementById("ctl00_ContentPlaceHolder1_DDLType");
//alert(type1);
	//Getting the selected country from country combo box.
	var id = type1.options[type1.selectedIndex].value;
	document.getElementById("ctl00_ContentPlaceHolder1_HiddenField2").value=id;
	//alert(id);
	// URL to get states for a given country
	var requestUrl = AjaxServerPageName + "?fun=3&id=" + id;
	CreateXmlHttp();
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = TypeResponse1;
		
		//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 Go()
{
    //alert('Hello');
    var type1 = document.getElementById("DDLType");
    var cat1=document.getElementById("DDLCat");
    var make1=document.getElementById("DDLMake");
    var type2=document.getElementById("DDLCar");
    var mod1=document.getElementById("DDLModel");
    var state1=document.getElementById("DDLState");
    
    var vtype = type1.options[type1.selectedIndex].value;
	var cat=cat1.options[cat1.selectedIndex].value;
	var make=make1.options[make1.selectedIndex].value;
	var type6 = type2.options[type2.selectedIndex].value;
	var mod=mod1.options[mod1.selectedIndex].value;
	var state=state1.options[state1.selectedIndex].value;
	alert(vtype+" "+cat+" "+make+" "+type6+" "+mod+" "+state);
	
	
	
	if(vtype!=0 && cat!=0 && type6!=0)
	{
	    var requestUrl = AjaxServerPageName + "?fun=5&vtype=" + vtype+"&cat="+cat+"&make="+make+"&type="+type6+"&mod="+mod+"&state="+state;
	    alert(requestUrl);
	    CreateXmlHttp();
	    // If browser supports XMLHTTPRequest object
	    if(XmlHttp)
	    {
		    //Setting the event handler for the response
		    XmlHttp.onreadystatechange = HandleSearch;
    		
		    //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 HandleSearch()
{
alert(XmlHttp.readyState);
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
        alert(XmlHttp.status);
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{		
              var doc = XmlHttp.responseXML.documentElement;
              var tmp=doc.getElementsByTagName("value")[0].childNodes[0].nodeValue;   
              //alert(tmp);
              window.location="UsedSearch.aspx";
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}

}

function ChangeModel()
{
    var mod=document.getElementById("DDLModel");
    for (var count1 = mod.options.length-1; count1 >-1; count1--)
	{
		mod.options[count1] = null;		
	}
    var type1 = document.getElementById("DDLType");
    var cat1=document.getElementById("DDLCat");
    var make1=document.getElementById("DDLMake");
	//Getting the selected country from country combo box.
	var vtype = type1.options[type1.selectedIndex].value;
	var cat=cat1.options[cat1.selectedIndex].value;
	var make=make1.options[make1.selectedIndex].value;
	document.getElementById("HiddenField3").value=cat;
    document.getElementById("HiddenField4").value=make;
	//alert(vtype+" "+cat+" "+make);
	// URL to get states for a given country
	if(vtype!=0 && cat!=0 && make!=0)
	{
	    var requestUrl = AjaxServerPageName + "?fun=4&vtype=" + vtype+"&cat="+cat+"&make="+make;
	    //alert(requestUrl);
	    CreateXmlHttp();
	    // If browser supports XMLHTTPRequest object
	    if(XmlHttp)
	    {
		    //Setting the event handler for the response
		    XmlHttp.onreadystatechange = ModelResponse;
    		
		    //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 ChangeModel1()
{
    var mod=document.getElementById("ctl00_ContentPlaceHolder1_DDLModel");
    for (var count1 = mod.options.length-1; count1 >-1; count1--)
	{
		mod.options[count1] = null;		
	}
    var type1 = document.getElementById("ctl00_ContentPlaceHolder1_DDLType");
    var cat1=document.getElementById("ctl00_ContentPlaceHolder1_DDLCat");
    var make1=document.getElementById("ctl00_ContentPlaceHolder1_DDLMake");
    
	//Getting the selected country from country combo box.
	var vtype = type1.options[type1.selectedIndex].value;
	var cat=cat1.options[cat1.selectedIndex].value;
	var make=make1.options[make1.selectedIndex].value;
	document.getElementById("ctl00_ContentPlaceHolder1_HiddenField3").value=cat;
    document.getElementById("ctl00_ContentPlaceHolder1_HiddenField4").value=make;
	//alert(vtype+" "+cat+" "+make);
	// URL to get states for a given country
	if(vtype!=0 && cat!=0 && make!=0)
	{
	    var requestUrl = AjaxServerPageName + "?fun=4&vtype=" + vtype+"&cat="+cat+"&make="+make;
	    //alert(requestUrl);
	    CreateXmlHttp();
	    // If browser supports XMLHTTPRequest object
	    if(XmlHttp)
	    {
		    //Setting the event handler for the response
		    XmlHttp.onreadystatechange = ModelResponse1;
    		
		    //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 ModelResponse1()
{
	if(XmlHttp.readyState == 4)
	{
//alert(XmlHttp.status);
		if(XmlHttp.status == 200)
		{		
              var doc = XmlHttp.responseXML.documentElement;
              var i = doc.getElementsByTagName("i")[0].childNodes[0].nodeValue; 
              //alert(i);
              var type2 =document.getElementById("ctl00_ContentPlaceHolder1_DDLModel");      
              type2.options[0]=new Option("--Select--",0);        
              for (var j= 1;j<=i;j++)
              {
              type2.options[j]=new Option(doc.getElementsByTagName("Data_"+j)[0].childNodes[0].nodeValue,doc.getElementsByTagName("value_"+j)[0].childNodes[0].nodeValue);
                //var opt=document.createElement("option");
                //type2.options.add(opt);
              //opt.text=doc.getElementsByTagName("Data_"+j)[0].childNodes[0].nodeValue;
              //opt.value=doc.getElementsByTagName("value_"+j)[0].childNodes[0].nodeValue;
              }
           type2.SelectedIndex=0;
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}

}
function ModelResponse()
{
	if(XmlHttp.readyState == 4)
	{
//alert(XmlHttp.status);
		if(XmlHttp.status == 200)
		{		
              var doc = XmlHttp.responseXML.documentElement;
              var i = doc.getElementsByTagName("i")[0].childNodes[0].nodeValue; 
              //alert(i);
              var type2 =document.getElementById("DDLModel");      
              type2.options[0]=new Option("--Select--",0);        
              for (var j= 1;j<=i;j++)
              {
              type2.options[j]=new Option(doc.getElementsByTagName("Data_"+j)[0].childNodes[0].nodeValue,doc.getElementsByTagName("value_"+j)[0].childNodes[0].nodeValue);
                //var opt=document.createElement("option");
                //type2.options.add(opt);
              //opt.text=doc.getElementsByTagName("Data_"+j)[0].childNodes[0].nodeValue;
              //opt.value=doc.getElementsByTagName("value_"+j)[0].childNodes[0].nodeValue;
              }
           type2.SelectedIndex=0;
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}

}
function TypeResponse1()
{
	if(XmlHttp.readyState == 4)
	{
//alert(XmlHttp.status);
		if(XmlHttp.status == 200)
		{		
			//alert("3");

              var doc = XmlHttp.responseXML.documentElement;
              //alert(doc.xml);
              var i = doc.getElementsByTagName("i")[0].childNodes[0].nodeValue; 
              //alert(i);
              var type2 =document.getElementById("ctl00_ContentPlaceHolder1_DDLCat");      
              type2.options[0]=new Option("--Select--",0);        
              //alert(type2);                           
//              type2.options[0]=new Option("ABC","1");
              
//              type2.options.add(opt);
//              opt.text="a";
//              opt.value="1";
              //alert(type2);
              for (var j= 1;j<=i;j++)
              {
              type2.options[j]=new Option(doc.getElementsByTagName("Data_"+j)[0].childNodes[0].nodeValue,doc.getElementsByTagName("value_"+j)[0].childNodes[0].nodeValue);
                var opt=document.createElement("option");
                //type2.options.add(opt);
              //opt.text=doc.getElementsByTagName("Data_"+j)[0].childNodes[0].nodeValue;
              //opt.value=doc.getElementsByTagName("value_"+j)[0].childNodes[0].nodeValue;
              }
              type2.SelectedIndex=0;
              
              var type1 =document.getElementById("ctl00_ContentPlaceHolder1_DDLMake");
              type1.options[0]=new Option("--Select--",0);
              //alert(doc.getElementsByTagName("k")[0].childNodes[0].nodeValue);
              var k = doc.getElementsByTagName("k")[0].childNodes[0].nodeValue;
              for (var j= 1;j<=k;j++)
              {
              type1.options[j]=new Option(doc.getElementsByTagName("MAKE_"+j)[0].childNodes[0].nodeValue,doc.getElementsByTagName("MID_"+j)[0].childNodes[0].nodeValue);
//                var opt=document.createElement("option");
//                type1.options.add(opt);
//              opt.text=doc.getElementsByTagName("MAKE_"+j)[0].childNodes[0].nodeValue;
//              opt.value=doc.getElementsByTagName("MID_"+j)[0].childNodes[0].nodeValue;
              }
           type1.SelectedIndex=0;
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}

}
function TypeResponse()
{
	if(XmlHttp.readyState == 4)
	{
//alert(XmlHttp.status);
		if(XmlHttp.status == 200)
		{		
			//alert("3");

              var doc = XmlHttp.responseXML.documentElement;
              //alert(doc.xml);
              var i = doc.getElementsByTagName("i")[0].childNodes[0].nodeValue; 
              //alert(i);
              var type2 =document.getElementById("DDLCat");  
              //type2.items=""; 
              type2.options[0]=new Option("--Select--",0);        
              //alert(type2);                           
//              type2.options[0]=new Option("ABC","1");
              
//              type2.options.add(opt);
//              opt.text="a";
//              opt.value="1";
              //alert(type2);
              for (var j= 1;j<=i;j++)
              {
              type2.options[j]=new Option(doc.getElementsByTagName("Data_"+j)[0].childNodes[0].nodeValue,doc.getElementsByTagName("value_"+j)[0].childNodes[0].nodeValue);
                var opt=document.createElement("option");
                //type2.options.add(opt);
              //opt.text=doc.getElementsByTagName("Data_"+j)[0].childNodes[0].nodeValue;
              //opt.value=doc.getElementsByTagName("value_"+j)[0].childNodes[0].nodeValue;
              }
              type2.SelectedIndex=0;
              
              var type1 =document.getElementById("DDLMake");
              type1.options[0]=new Option("--Select--",0);
              //alert(doc.getElementsByTagName("k")[0].childNodes[0].nodeValue);
              var k = doc.getElementsByTagName("k")[0].childNodes[0].nodeValue;
              for (var j= 1;j<=k;j++)
              {
              type1.options[j]=new Option(doc.getElementsByTagName("MAKE_"+j)[0].childNodes[0].nodeValue,doc.getElementsByTagName("MID_"+j)[0].childNodes[0].nodeValue);
//                var opt=document.createElement("option");
//                type1.options.add(opt);
//              opt.text=doc.getElementsByTagName("MAKE_"+j)[0].childNodes[0].nodeValue;
//              opt.value=doc.getElementsByTagName("MID_"+j)[0].childNodes[0].nodeValue;
              }
           type1.SelectedIndex=0;
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}

}




//function HandleResponsestate()
//{

//	if(XmlHttp.readyState == 4)
//	{
//		if(XmlHttp.status == 200)
//		{		
//		var i,j;
//		var city = document.getElementById("ddlcities").value;
//              var doc = XmlHttp.responseXML.documentElement;
//              i = doc.getElementsByTagName("i")[0].childNodes[0].nodeValue;
//              for(j=0;j<i;j++)
//              
//              city.add(doc.getElementsByTagName("Val_"+j)[0].childNodes[0].nodeValue;
//		}
//		else
//		{
//			alert("There was a problem retrieving data from the server." );
//		}
//	}

//}

function HandleResponse3()
{

	// 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 i;
              var doc = XmlHttp.responseXML.documentElement;
              var tmp=doc.getElementsByTagName("value")[0].childNodes[0].nodeValue;             
                      
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}

}
function HandleResponse4()
{

	// 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 i;
              var doc = XmlHttp.responseXML.documentElement;
              var tmp=doc.getElementsByTagName("USER")[0].childNodes[0].nodeValue;     
              var tmp1=doc.getElementsByTagName("SELLER")[0].childNodes[0].nodeValue; 
              window.open("Reply.aspx",'name','height=150,width=500');
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}

}


function HandleResponse2()
{

	// 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 i;
              var doc = XmlHttp.responseXML.documentElement;
//              var tmp=
             //alert( doc.getElementsByTagName("value")[0].childNodes[0].nodeValue + " Loggin");
             var tmp=doc.getElementsByTagName("value")[0].childNodes[0].nodeValue;
             //alert(tmp)
             if(tmp == "Buyer")
             {
                 //alert("3");
                 window.location="Buyer.aspx";
             }
             if(tmp == "Seller")
             {
                window.location="Seller.aspx";
             }
             if(tmp == "Dealer")
             {
                window.location="Dealer.aspx";
             }
             if(tmp=="Buyer" || tmp=="Seller" || tmp=="Dealer")
             {                
                //<%Session["name"]=%> = "1";
                //<%session["stringName"] = document.getElementById('Hid').value%>
             }
             else
             {
                //alert('Login Failed!');
                //<%Session("name")=%> = 0;
                //<%= Session["User"].ToString() %>=0;
                //document.getElementById('Hid').value=0;
                //alert("0");                
             }                        
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}

}

//function StateChanged()
//{
//    var state = document.getElementById("ddlstate");
//    var stateid=state.selectedvalue;
//    var requestUrl = AjaxServerPageName + "?fun=2&Stateid="+stateid;
//	CreateXmlHttp();
//	if(XmlHttp)
//	{
//		XmlHttp.onreadystatechange = HandleResponsestate;
//		XmlHttp.open("GET", requestUrl,  true);
//		XmlHttp.send(null);		
//	}
//}


//Clears the contents of state combo box and adds the states of currently selected country
function ClearAndSetStateListItems(countryNode)
{
alert("in ClearAndSetStateListItems funtion");
    var stateList = document.getElementById("stateList");
var countryList = document.getElementById("countryList");
	//Clears the state combo box contents.
	for (var count = stateList.options.length-1; count >-1; count--)
	{
		stateList.options[count] = null;
		
	}

	var stateNodes = countryNode.getElementsByTagName('state');
	var textValue; 
	var optionItem;
	//Add new states list to the state combo box.
	for (var count = 0; count < stateNodes.length; count++)
	{
   		textValue = GetInnerText(stateNodes[count]);
		optionItem = new Option( textValue, textValue,  false, false);
		stateList.options[stateList.length] = optionItem;
	}
	    document.getElementById("Label1").innerHTML  = "The Country is " + countryList.options[countryList.selectedIndex].value  + ", The first state in the list is " + stateList.options[0].value;

}

//Returns the node text value 
function GetInnerText (node)
{
	 return (node.textContent || node.innerText || node.text) ;
}

function selectBroker(chk)
{
alert(chk);
    //window.open("../selectBroker.aspx");
}







