function checkCookie2()
{
	laptopBrandIndex=getCookie('userlaptopbrand')
	
	if (laptopBrandIndex!=null && laptopBrandIndex!="")
	{
		$("#pLaptopBrand").val(laptopBrandIndex);
		
		$.post("/functions/ajax_laptop_model.php", { brand: $('#pLaptopBrand').val() },
			function(data){
				$("#laptopmodels").html(data);  

				laptopModelIndex=getCookie('userlaptopmodel')
				
				if (laptopModelIndex!=null && laptopModelIndex!="")
				{
					$("#pLaptop").val(laptopModelIndex);
				}
		});
		
	}

} // end function



function checkCookie()
{
	laptopBrandIndex=getCookie('userlaptopbrand')
	
	if (laptopBrandIndex!=null && laptopBrandIndex!="")
	{
		document.getElementById("pLaptopBrand").value = laptopBrandIndex;
		laptopBrand = document.getElementById("pLaptopBrand").value;
		get_models(laptopBrand)
		
	}
}


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 setCookie( name, value, expires, path, domain, secure ) 
{
	//alert('setting '+name+' value of '+value)

	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );

}




/***************************************************************/

function get_models(str)
{

	if (str.length==0)
	{ 
		document.getElementById("laptopmodels").innerHTML=""
		return
	}

	document.getElementById("dimensions").innerHTML=""
	  
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 

	setCookie( 'userlaptopbrand', str, '365', '/', '', '' );
	 
	var url="/laptop-bags/laptop_bag_search.php"
	url=url+"?brand="+str
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
} 


function get_dimensions(str)
{

	if (str.length==0)
	{ 
		document.getElementById("dimensions").innerHTML=""
		return
	}
	  
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 

	setCookie( 'userlaptopmodel', str, '365', '/', '', '' );

	var url="/laptop-bags/laptop_bag_search.php"
	url=url+"?model="+str
	url=url+"&product="+document.getElementById("productid").value
	url=url+"&sa="+document.getElementById("sa").value
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedDim
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)

}
 

/***************************************************************/
function stateChanged() 
{ 

	if (xmlHttp.readyState==1 || xmlHttp.readyState==2 || xmlHttp.readyState==3)
	{
		document.getElementById("laptopmodels").innerHTML = "<img src=\"/site/image/loading_tiny.gif\" valign=\"top\" >";
	}


	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("laptopmodels").innerHTML=xmlHttp.responseText;
		
		laptopModelIndex=getCookie('userlaptopmodel')
			
		if (laptopModelIndex!=null && laptopModelIndex!="")
		{
			if (document.getElementById("pLaptop") != null)
			{
				document.getElementById("pLaptop").value = laptopModelIndex;
				laptopid = document.getElementById("pLaptop").value;
				get_dimensions(laptopid)
			}
		}

	} 
}


function stateChangedDim() 
{ 

	if (xmlHttp.readyState==1 || xmlHttp.readyState==2 || xmlHttp.readyState==3)
	{
		document.getElementById("dimensions").innerHTML = "<img src=\"/site/image/loading_tiny.gif\">";
	}


	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 

		document.getElementById("dimensions").innerHTML=xmlHttp.responseText;

	} 
}


/***************************************************************/
function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}


