var xmlHttp;

//**********************************************
// general Ajax function to do the InnerHtml !
//**********************************************


function stateChanged(divname)
{
//  alert ("readystate"+xmlHttp.readyState);
//        alert (xmlHttp.responseText);
   if (xmlHttp.readyState == 4) {
      if (xmlHttp.status == 200) {
        document.getElementById(divname).innerHTML = xmlHttp.responseText;
      } else {
          alert("HTTP error " + xmlHttp.status + ": " + xmlHttp.statusText);
      }
  }
}

function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
   {
   // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
//    xmlHttp.overrideMimeType('text/plain; charset=ISO-8859-1');
   }
  catch (e)
   {
   //Internet Explorer
   try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
   catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
   }
   }
  return xmlHttp;

}



function _not_used_post_example()
{
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null){
    alert ("Browser does not support HTTP Request");
    return;
  }
    var url="shop/basket.php";
    var contentType = "application/x-www-form-urlencoded; charset=UTF-32";
    var params = "action=refreshbasket&Qt7852892975564=100";
    xmlHttp.open("POST", url, true);
    //Send the proper header information along with the request
    xmlHttp.setRequestHeader('User-Agent','XMLHTTP/1.0');
    xmlHttp.setRequestHeader("Content-Type", contentType);
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    //Call a function when the state changes.
    xmlHttp.onreadystatechange = stateChanged('');
    xmlHttp.send(params);
}



//**********************************************
//******* checkout Ajax ************************
//**********************************************
function setFocus(field)
{
document.getElementById(field).focus();
}



function show_reseller(ShowIt)
{
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null){
    alert ("Browser does not support HTTP Request");
    return;
  }
    var contentType = "application/x-www-form-urlencoded; charset=ISO-8859-1";

  if (ShowIt)
    var url="shop/checkout_details.php?action=checkout&internalaction=selectreseller";
  else
    var url="shop/checkout_details.php?action=checkout&internalaction=selectclient";

  xmlHttp.open("GET", url, false);
 xmlHttp.send(null);

  xmlHttp.onreadystatechange = stateChanged('checkout_details');
//
}



function show_reseller2(ShowIt)
{
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null){
    alert ("Browser does not support HTTP Request");
    return;
  }

  var url="shop/checkout_details.php";
  var contentType = "application/x-www-form-urlencoded; charset=ISO-8859-1";

  if (ShowIt)
    var params="action=checkout&internalaction=selectreseller";
  else
    var params="action=checkout&internalaction=selectclient";
alert("1");
  xmlHttp.open("POST", url, true);
  //Send the proper header information along with the request
  xmlHttp.setRequestHeader("Content-Type", contentType);
  xmlHttp.setRequestHeader("Content-length", params.length);
  xmlHttp.setRequestHeader("Connection", "close");
alert("2");
  //Call a function when the state changes.
  xmlHttp.onreadystatechange = stateChanged('checkout_details');
  xmlHttp.send(params);

alert(params);
//
}

function selectInvoiceType(LocType)
{
//  alert(document.getElementById(adr_isclient).value);
//  alert("1");
  if (LocType==0){
    show_reseller(false);

    protectDiv("adr_name1", false);
    protectDiv("adr_name2", false);
    protectDiv("adr_email1", false);
    protectDiv("adr_city", false);
    protectDiv("adr_postalcode", false);
    protectDiv("adr_region", false);
    protectDiv("adr_street", false);
    protectDiv("adr_street2", false);
    protectDiv("adr_telefon1", false);
    protectDiv("adr_mobil1", false);

    setFocus("adr_name1");
  }
  else{
    show_reseller(true);
//    protectDiv("adr_name1", true);
//    protectDiv("adr_firma", true);
//    protectDiv("adr_email1", true);
//    protectDiv("adr_city", true);
//    protectDiv("adr_postalcode", true);
//    protectDiv("adr_region", true);
//    protectDiv("adr_street", true);
//    protectDiv("adr_street2", true);
//    protectDiv("adr_telefon1", true);
//    protectDiv("adr_mobil1", true);
//
    setFocus("adr_code");

  }
}



function LoadClient(IsClient, ClientID)
{
  if (!ClientID) return;

  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null){
    alert ("Browser does not support HTTP Request");
    return;
  }

  if (IsClient)
    var url="shop/checkout_details.php?action=checkout&internalaction=loadclient&clientid="+ClientID;
  else
    var url="shop/checkout_details.php?action=checkout&internalaction=loadreseller&clientid="+ClientID;

  xmlHttp.open("GET", url, false);
  xmlHttp.send(null);

  xmlHttp.onreadystatechange = stateChanged('checkout_details');

  if (IsClient){
    protectDiv("adr_name1", false);
    protectDiv("adr_name2", false);
    protectDiv("adr_email1", false);
    protectDiv("adr_city", false);
    protectDiv("adr_postalcode", false);
    protectDiv("adr_region", false);
    protectDiv("adr_street", false);
    protectDiv("adr_street2", false);
    protectDiv("adr_telefon1", false);
    protectDiv("adr_mobil1", false);
  }
  else{
//    protectDiv("adr_name1", true);
//    protectDiv("adr_firma", true);
//    protectDiv("adr_email1", true);
//    protectDiv("adr_city", true);
//    protectDiv("adr_postalcode", true);
//    protectDiv("adr_region", true);
//    protectDiv("adr_street", true);
//    protectDiv("adr_street2", true);
//    protectDiv("adr_telefon1", true);
//    protectDiv("adr_mobil1", true);
  }


//
}
