var xmlHttp = createXmlHttpRequestObject();

function createXmlHttpRequestObject(){
	var xmlHttp;
	
		try{
			xmlHttp = new XMLHttpRequest();
		}
		catch (e){
		    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
											"MSXML2.XMLHTTP.5.0",
											"MSXML2.XMLHTTP.4.0",
											"MSXML2.XMLHTTP.3.0",
											"MSXML2.XMLHTTP",
											"Microsoft.XMLHTTP");
		     for(var i=0; i<XmlHttpVersions.length && !xmlHttp; i++){
			    try{
				 xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
				}
				catch (e){
				}
			 }
		}
		if(!xmlHttp){
		  alert('ajax error');
		}else{
			return xmlHttp;
		}
}
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return ""
}
function set_category(){
	
	var category_id = document.getElementById('product_category').value;
	var product_id = document.getElementById('product_id').value;
    //var url = window.location;
    //var newurl = ''+url+'&cat_id='+category_id;
    //alert(newurl);
	
  if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
	  var count;
	  count = Math.floor(Math.random()*10100);
	 
	  xmlHttp.open("GET", "get_styles.php?&cat_id="+category_id+"&prod_id="+product_id+"&count="+count, true);
	  xmlHttp.onreadystatechange = handleServerResponse;
	  xmlHttp.send(null);
  }else{
      setTimeout('set_category()', 1000);
  }
}
function handleServerResponse(){
	
  if(xmlHttp.readyState == 4){
    if(xmlHttp.status == 200){
	   xmlResponse = xmlHttp.responseText;
	   
	  document.getElementById('check_boxes').innerHTML = '' + xmlResponse + '';
	  
	  
	 
	}
  }else{
     document.getElementById('check_boxes').innerHTML = 'Ajax In Progress Please wait.';
  
  }
}
function get_category(){
	
	var style_name = document.getElementById('style_name').value;
	var category_id = document.getElementById('category_id').value;
	//var style_id = document.getElementById('style_id').value;
    //var url = window.location;
    //var newurl = ''+url+'&cat_id='+category_id;
    //alert(newurl);
	
  if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
	  var count;
	  count = Math.floor(Math.random()*10100);
	 
	  xmlHttp.open("GET", "get_cats.php?&cat_id="+category_id+"&style_name="+style_name+"&count="+count, true);
	  xmlHttp.onreadystatechange = handleServerCat;
	  xmlHttp.send(null);
  }else{
      setTimeout('get_category()', 1000);
  }
}
function handleServerCat(){
	
  if(xmlHttp.readyState == 4){
    if(xmlHttp.status == 200){
	   xmlResponse = xmlHttp.responseText;
	   
	  document.getElementById('data_fields').innerHTML = '' + xmlResponse + '';
	  
	  
	 
	}
  }else{
     document.getElementById('data_fields').innerHTML = 'Ajax In Progress Please wait.';
  
  }
}
