var xmlHttp;
var text;
var car_id;

// start get car details
function getCar(carid, regionid)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 }
// variable to display the background
car_id = carid;
var url="../quotes/cardetails.php";
url=url+"?car_id="+carid;
url=url+"&region_id="+regionid;
xmlHttp.onreadystatechange=carStateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


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

text=xmlHttp.responseText;

show_car_details(text);

 } 
}
// end get car details



var posx;
var posy;
function capmouse(e){
	// captures the mouse position
	posx = 0; posy = 0;
	if (!e){
		var e = window.event;
	}
	if (e.pageX || e.pageY){
		posx = e.pageX;
		posy = e.pageY;
	} else if (e.clientX || e.clientY){
		posx = e.clientX;
		posy = e.clientY;
	}
}

function show_car_details(text){

	if (navigator.appVersion.indexOf("Windows")!=-1) {
		document.getElementById('cardiv').style.left = posx;
		document.getElementById('cardiv').style.top = posy;
	} else {
		document.getElementById('cardiv').style.left = posx;
		document.getElementById('cardiv').style.top = posy-150;
	}

	build_car_details(text);

	//detect System and Browser
	if (navigator.appVersion.indexOf("Windows")!=-1) {
			document.getElementById('cardiv').style.display = "block";
			document.getElementById('cardiv').style.visibility = "visible";
	} else {
		if (navigator.appVersion.indexOf("MSIE")!=-1 || navigator.userAgent.indexOf("Opera")!=-1) {
			document.getElementById('cardiv').style.visibility = "visible";
		} else {
			document.getElementById('cardiv').style.visibility = "visible";
		}
	}
	document.getElementById('cardiv').style.background='url(\'../madeira/popups/'+ car_id +'.jpg\') no-repeat left top';
}

function build_car_details(text){

	//show car details
	var divObj = document.getElementById('cardiv');

	calendar = "<div id='carclose'><a href='javascript:void(0);' onclick=\"close_car_details();\" style='cursor: hand'>X</a></div>";
	calendar += "<div class='text'>";
	calendar += text;
	calendar += "<center><a href='javascript:void(0);' onclick=\"close_car_details();\" style='cursor: hand'>Close</a></center></div>";

	divObj.innerHTML = calendar;
	calendar = "";
}

function close_car_details(){
	//detect System and Browser
	if (navigator.appVersion.indexOf("Windows")!=-1) {
		if (navigator.appVersion.indexOf("MSIE")!=-1) {
			document.getElementById('cardiv').style.visibility = "hidden";
		} else {
			document.getElementById('cardiv').style.display = "none";
		}
	} else {
		if (navigator.appVersion.indexOf("MSIE")!=-1|| navigator.userAgent.indexOf("Mozilla")!=-1) {
			document.getElementById('cardiv').style.visibility = "hidden";
		} else {
			document.getElementById('cardiv').style.visibility = "none";
		}
	}
}

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;
}



// drag car details div
var ie=document.all;
var nn6=document.getElementById&&!document.all;

var isdrag=false;
var x,y;
var dobj;

function movemouse(e)
{
  if (isdrag)
  {
    dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
    dobj.style.top  = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
    return false;
  }
}

function selectmouse(e) 
{

  var fobj       = nn6 ? e.target : event.srcElement;
  var topelement = nn6 ? "HTML" : "BODY";

  while (fobj.tagName != topelement && fobj.className != "cardiv")
  {
    fobj = nn6 ? fobj.parentNode : fobj.parentElement;
  }
  if (fobj.className=="cardiv")
  {
    isdrag = true;
    dobj = fobj;
    tx = parseInt(dobj.style.left+0);
    ty = parseInt(dobj.style.top+0);
    x = nn6 ? e.clientX : event.clientX;
    y = nn6 ? e.clientY : event.clientY;
    document.onmousemove=movemouse;
    return false;
  }
}

document.onmousedown=selectmouse;
document.onmouseup=new Function("isdrag=false");