function ajx_set_Msg_Read(id)
{
        var xmlHTTP = createXMLHttp();
	    xmlHTTP.open("GET", "/inventory/ajax/MsgMarkRead.aspx?id="+id, false) ;
 	    xmlHTTP.setRequestHeader("Content-Type", "text/html; charset=utf-8" ) ;

	    xmlHTTP.send("");
}


function ajx_get_OVE_Status(id, vin, autoID)
{
        var xmlHTTP = createXMLHttp();
	    xmlHTTP.open("GET", "/inventory/ajax/CheckOVE.aspx?id="+id+"&vin="+vin, false) ;
 	    xmlHTTP.setRequestHeader("Content-Type", "text/html; charset=utf-8" ) ;

	    xmlHTTP.send("");

        var pointer = document.getElementById("checkBlock");

        if (xmlHTTP.responseText == 1)
        {
            document.form1.action = 'process_option_buy.asp?autoID='+autoID;
	    	document.form1.submit()
        }
        else
        {
            pointer.innerHTML = '<span style="color: red; font-weight: bold;">Unfortunately the vehicle you requested to Buy Now has been removed from the auction by the seller.</span>';
        }
}


function ajx_get_OVE_Status_Old(id, validUser, autoIDEncoded)
{
        var xmlHTTP = createXMLHttp();
	    xmlHTTP.open("GET", "/inventory/ajax/CheckOVE.aspx?id="+id, false) ;
 	    xmlHTTP.setRequestHeader("Content-Type", "text/html; charset=utf-8" ) ;

	    xmlHTTP.send("");

        var pointer = document.getElementById("button");

        if (xmlHTTP.responseText == 1)
        {
          if (validUser == 1)
          {
             pointer.innerHTML = '<a href="/inventory/option_buy.asp?autoID='+ autoIDEncoded + '" target="_blank"><img border="0" src="/images/buy_btn_up.png" onmouseup="this.src=buy_btn_up.src" onmouseout="this.src=buy_btn_up.src" onmousedown="this.src=buy_btn_down.src" style="cursor: hand; cursor: pointer;" /></a>';
          }
          else
          {
             pointer.innerHTML = '<a href="/login.asp"><img border="0" src="/images/buy_btn_up.png" onmouseup="this.src=buy_btn_up.src" onmouseout="this.src=buy_btn_up.src" onmousedown="this.src=buy_btn_down.src" style="cursor: hand; cursor: pointer;" /></a>';
          }
        }
        else
        {
          pointer.innerHTML = '<div style=" border: 1px solid silver; padding: 10px;" align="center"><span style="color: red; font-weight: bold;">Sorry, this vehicle<br/> is no longer exists at auction.</span></div>';
        }

}

function portselekt(page)
{
	if (document.getElementById("country").value!="0")

	{
	    var xmlHTTP = createXMLHttp();
	    xmlHTTP.open("GET", "/inventory/ajax/get_port.asp?country="+document.getElementById("country").value, false) ;
 	    xmlHTTP.setRequestHeader("Content-Type", "text/html; charset=utf-8" ) ;

	    xmlHTTP.send("");
	    document.getElementById("div_port").innerHTML = xmlHTTP.responseText;

        shippingcost('');
    }
}


function supergroupselect()
{
	if (document.getElementById("automake").value!="0")

	{
	    var xmlHTTP = createXMLHttp();
	    xmlHTTP.open("GET", "/inventory/ajax/get_supergroups.asp?make="+document.getElementById("automake").value, false);
 	    xmlHTTP.setRequestHeader("Content-Type", "text/html; charset=utf-8");
	    xmlHTTP.send("");
	    document.getElementById("div_supergroup").innerHTML = xmlHTTP.responseText;
    }
}

function supergroupselectV2()
{
	if (document.getElementById("supergroup").value!="0")

	{
	    var xmlHTTP = createXMLHttp();
	    xmlHTTP.open("GET", "/inventory/ajax/get_groupsSG.asp?supergroup="+document.getElementById("supergroup").value+"&automake="+document.getElementById("automake").value, false) ;
 	    xmlHTTP.setRequestHeader("Content-Type", "text/html; charset=utf-8" ) ;

	    xmlHTTP.send("");
	    document.getElementById("div_make").innerHTML = xmlHTTP.responseText;
    }
    else
    {
        groupselektV2('search', '1');
    }
}



function groupselekt(page)
{
	if (document.getElementById("automake").value!="0")

	{
	    var xmlHTTP = createXMLHttp();
	    xmlHTTP.open("GET", "/inventory/ajax/get_groups.asp?make="+document.getElementById("automake").value+"&page="+page, false) ;
 	    xmlHTTP.setRequestHeader("Content-Type", "text/html; charset=utf-8" ) ;

	    xmlHTTP.send("");
	    document.getElementById("div_make").innerHTML = xmlHTTP.responseText;
    }
}

function groupselektV2(page, status)
{
	if (document.getElementById("automake").value!="0")

	{
	    var xmlHTTP = createXMLHttp();
	    xmlHTTP.open("GET", "/inventory/ajax/get_groupsv2.asp?make="+document.getElementById("automake").value+"&page="+page +"&status="+ status, false) ;
 	    xmlHTTP.setRequestHeader("Content-Type", "text/html; charset=utf-8" ) ;

	    xmlHTTP.send("");
	    document.getElementById("div_make").innerHTML = xmlHTTP.responseText;
    }
}

function groupselektV3(page, status, group)
{
	if (document.getElementById("automake").value!="0")

	{
	    var xmlHTTP = createXMLHttp();
	    xmlHTTP.open("GET", "/inventory/ajax/get_groupsv3.asp?make="+document.getElementById("automake").value+"&group="+ group +"&page="+page +"&status="+ status, false) ;
 	    xmlHTTP.setRequestHeader("Content-Type", "text/html; charset=utf-8" ) ;

	    xmlHTTP.send("");
	    document.getElementById("div_make").innerHTML = xmlHTTP.responseText;
    }
}

function groupselektV4(page, status)
{
	if (document.getElementById("automake").value!="0")

	{
	    var xmlHTTP = createXMLHttp();
	    xmlHTTP.open("GET", "/inventory/ajax/get_groupsv4.asp?make="+document.getElementById("automake").value+"&page="+page +"&status="+ status, false) ;
 	    xmlHTTP.setRequestHeader("Content-Type", "text/html; charset=utf-8" ) ;

	    xmlHTTP.send("");
	    document.getElementById("div_make").innerHTML = xmlHTTP.responseText;
    }
}

function groupSelectSaleStats(GroupName)
{
    if (document.getElementById("automake").value!="0")

	{
	    var xmlHTTP = createXMLHttp();
	    xmlHTTP.open("GET", "/inventory/ajax/groupSelectSaleStats.asp?make="+document.getElementById("automake").value+"&GroupName="+GroupName, false) ;
 	    xmlHTTP.setRequestHeader("Content-Type", "text/html; charset=utf-8" ) ;

	    xmlHTTP.send("");
	    document.getElementById("div_make").innerHTML = xmlHTTP.responseText;
    }
}

function modelselekt(page)
{
	if (document.getElementById("automake").value!="0")

	{
	    var xmlHTTP = createXMLHttp();
	    xmlHTTP.open("GET", "/inventory/ajax/get_models.asp?make="+document.getElementById("automake").value+"&page="+page , false) ;
 	    xmlHTTP.setRequestHeader("Content-Type", "text/html; charset=utf-8" ) ;

	    xmlHTTP.send("");
	    document.getElementById("div_make").innerHTML = xmlHTTP.responseText;
    }
}

var ship_cost=0;

function calc_shippingcost()
{

    var tmp=document.getElementById("qty").value;
    if (tmp==999999)
        tmp=1;

     var price="$" + Number(ship_cost*tmp);
     if (price=="$0")
        price="Call";
     document.getElementById("ship_price").innerHTML = price;
}

function shippingcost(page)
{

	    var xmlHTTP = createXMLHttp();
	    xmlHTTP.open("GET", "/inventory/ajax/get_shippingcost.asp?port="+document.getElementById("port").value+"&from="+document.getElementById("from").value+"&page="+page , false) ;
 	    xmlHTTP.setRequestHeader("Content-Type", "text/html; charset=utf-8" ) ;

	    xmlHTTP.send("");
	    var tmp = xmlHTTP.responseText;
        if (!isNaN(tmp))
          ship_cost= Number(tmp);

        calc_shippingcost();

        if (document.getElementById("qty").value==999999)
            calc_TOTAL_shippingcost();
}

var ltcost=0;

function landtransportationcost(autoid)
{
	    var xmlHTTP = createXMLHttp();
	    xmlHTTP.open("GET", "/inventory/ajax/get_landtransportationcost.asp?autoid="+autoid+"&from="+document.getElementById("from").value , false) ;
 	    xmlHTTP.setRequestHeader("Content-Type", "text/html; charset=utf-8" ) ;

	    xmlHTTP.send("");
	    var tmp = xmlHTTP.responseText;
        if (!isNaN(tmp))
          ltcost= Number(tmp);

          if (ltcost==0)
             document.getElementById("land_price").innerHTML="Call"
          else
            document.getElementById("land_price").innerHTML="$" + ltcost;

          calc_TOTAL_shippingcost();

}

function landtransportationcostbt(autoid)
{

        var xmlHTTP = createXMLHttp();
	    xmlHTTP.open("GET", "/inventory/ajax/get_landtransportationcostBt.asp?autoid="+autoid+"&from="+document.getElementById("from").value , false) ;
 	    xmlHTTP.setRequestHeader("Content-Type", "text/html; charset=utf-8" ) ;

	    xmlHTTP.send("");
	    var tmp = xmlHTTP.responseText;
        if (!isNaN(tmp))
          ltcost= Number(tmp);

          if (ltcost==0)
             document.getElementById("land_price").innerHTML="Call"
          else
            document.getElementById("land_price").innerHTML="$" + ltcost;

          calc_TOTAL_shippingcost();

}


function Add2Watch(autoID, userID)
{
        var xmlHTTP = createXMLHttp();
        xmlHTTP.open("GET", "/inventory/ajax/add_2_watch.asp?autoID="+autoID+"&userID="+userID);
 	    xmlHTTP.setRequestHeader("Content-Type", "text/html; charset=utf-8" );

        xmlHTTP.send("");

        var tmp = xmlHTTP.responseText;

        if (!isNaN(tmp))
            result = Number(tmp);

            if (result == 0)
            {
             document.getElementById("Add2WatchBtn").innerHTML="";
             document.getElementById("add2watch_result").innerHTML="<table><tr><td style='vertical-align: top;'><input type='checkbox' checked></td><td>This vehicle has been added to your watchlist.</td></tr></table>";
            }

}

function GetMessage(mesgID)
{
    var xmlHTTP = createXMLHttp();
    xmlHTTP.open("GET", "/includes/ajax/get_Subject.asp?mesgID="+mesgID, false);
 	xmlHTTP.setRequestHeader("Content-Type", "text/html; charset=utf-8");

    xmlHTTP.send("");

    document.getElementById("Subject").value = xmlHTTP.responseText;

    xmlHTTP.open("GET", "/includes/ajax/get_Body.asp?mesgID="+mesgID, false);
 	xmlHTTP.setRequestHeader("Content-Type", "text/html; charset=utf-8");

    xmlHTTP.send("");

    document.getElementById("Body").value = xmlHTTP.responseText;

}

function calc_TOTAL_shippingcost()
{
  var msg="";
  var price='';
  if ((ltcost==0) && (ship_cost==0))
  {
      document.getElementById("total_price").innerHTML = '$0';
      return;
  }
  if (ltcost==0)
      {
        price=ship_cost;
        msg="* includes only Ocean Transportation.<br>Please call us for the Total Shipping Cost";
      }

   if (ship_cost==0)
      {
        price=ltcost;
        msg="* includes only Land Transportation.<br>Please call us for the Total Shipping Cost";
      }
   price=ship_cost +  ltcost;

   price="$" + price;
   if (msg!="")
        price=price + "*";

   document.getElementById("total_price").innerHTML=price;
   return;
}

function createXMLHttp() {

    if (window.ActiveXObject) {
      var aVersions = [ "MSXML2.XMLHttp.6.0",
        "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp","Microsoft.XMLHttp"
      ];

      for (var i = 0; i < aVersions.length; i++) {
        try {
            var oXmlHttp = new ActiveXObject(aVersions[i]);
            return oXmlHttp;
        } catch (oError) {
            //Do nothing
        }
      }
    }else if (typeof XMLHttpRequest != "undefined") {
        return new XMLHttpRequest();
    }
    throw new Error("XMLHttp object could be created.");
}
