var xmlHttp2 = null;
var req;

function add_to_vg(vin,ckid) {   
	var url = '/mygarage/add_vehicle.asp?vin=' + vin + '&ckid=' + ckid;
	req = false;
	if(window.XMLHttpRequest){
		try { req = new XMLHttpRequest(); }
		catch(e) { req = false;	}
	} 
	else if(window.ActiveXObject) {
		try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch(e) {
			try { req = new ActiveXObject("Microsoft.XMLHTTP");	}
			catch(e) { req = false; }
		}
	}
	if(req) {
		req.onreadystatechange = function(){
			if (req.readyState == 4){
				if (req.status == 200){	
					if (req.responseText == "success") {
						document.getElementById('addVg').innerHTML = 'Vehicle Added to MyGarage';
						document.getElementById('addVg').onclick = "goToVg();";
						document.getElementById('minivg').innerHTML = populateVgPanel();
					}
					else {
						alert(req.responseText);
						document.getElementById('addVg').onClick = "";
					}
				}else{
					alert("There was a problem processing the command:\n" + req.statusText);
				}
			}
		}
		req.open("GET", url, true);
		req.send(null);
	}
}

function populateVgPanel()
{ 

xmlHttp2 = GetXmlHttpObject2();
if (xmlHttp2==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 

var url2="/mygarage/minigarage.asp";
xmlHttp2.onreadystatechange = stateChanged;
xmlHttp2.open("GET",url2,true);
xmlHttp2.send(null);
return "<img src='/mygarage/images/loader.gif' style='padding-top:50px;padding-left:90px;'>";
}

function stateChanged() 
{ 
	if (xmlHttp2.readyState == 4)
	{ 
		document.getElementById('minivg').innerHTML = xmlHttp2.responseText;
	}
}

function GetXmlHttpObject2()
{
//var xmlHttp2=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp2=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp2=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp2;
}

function populateVgDetails() {
	document.getElementById('minivg').innerHTML = populateVgPanel();
}

function goToVg() {
	location = '/mygarage/virtual_garage.asp';
}
