var miz=' moet ingevuld zijn';
var foto1;

function ShowPic(img)
{
  window.status = '';
  iTry = 0;
  ClosePic();
  ShowPict(img);
}

function ShowPict(img)
{
  window.status = '';
  iTry = iTry + 1;

  foto1= new Image();
  foto1.src=(img);

  if (((foto1.width>50)&&(foto1.height>50)) || foto1.complete)
  {
    e = document.getElementById('thepic');
    e.style.backgroundImage = 'url(' + img + ')';
    e.style.height = foto1.height+2;
    e.style.width = foto1.width+2;
    e.style.visibility = 'visible';
  }
  else
  {
    if (iTry < 5)
    {
      func="ShowPict('"+img+"')";
      interv=setTimeout(func,100);
    }
  }
}

function ClosePic()
{
    e = document.getElementById('thepic');
    e.style.backgroundImage = 'url(none)';
    e.style.height = 0;
    e.style.width = 0;
    e.style.visibility = 'hidden';
}

function Trim(psValue)
{
  if(psValue.length > 0)
  {
    psValue = RTrim(psValue);
    psValue = LTrim(psValue);
  }

  return psValue;
}

function RTrim(psValue)
{
  if(psValue.length > 0)
  {
    var w_space = String.fromCharCode(32);
    var iTemp = psValue.length - 1;

    while(iTemp > -1)
    {
      if (psValue.charAt(iTemp) != w_space)
      {
        psValue = psValue.substring(0, iTemp + 1);
        break;
      }

      iTemp = iTemp - 1;
    }
  }

  return psValue;
}

function LTrim(psValue)
{
  if(psValue.length > 0)
  {
    var w_space = String.fromCharCode(32);
    var iTemp = 0;

    while(iTemp < psValue.length)
    {
      if (psValue.charAt(iTemp) != w_space)
      {
        psValue = psValue.substring(iTemp, psValue.length);
        break;
      }

      iTemp = iTemp + 1;
    }
  }

  return psValue;
}

function CaricaFoto(img)
{
  foto1= new Image();
  foto1.src=(img);
  Control(img);
}

function Control(img)
{
  if (((foto1.width>50)&&(foto1.height>50)) || foto1.complete)
  {
    viewPicture(img, img, foto1.width+7, foto1.height+32);
  }
  else
  {
    func="Control('"+img+"')";
    interv=setTimeout(func,100);
  }
}

function viewPicture(stitle, img, picwidth, picheight)
{
  var picleft, pictop;

  if(navigator.appName == "Microsoft Internet Explorer")
  {
    picleft = ((window.screen.availWidth - picwidth) / 2);
    pictop = ((window.screen.availHeight - picheight) / 2);
  }
  else
  {
    picleft = (((window.outerWidth - picwidth) / 2) - pageXOffset);
    pictop = (((window.outerHeight - picheight) / 2) - pageYOffset);
  }

  winpropjes="width="+picwidth+",height="+picheight+",left="+picleft+",top="+pictop+",titlebar=0";
  newWindow=window.showModalDialog(img, stitle, "dialogHeight: "+picheight+"px; dialogWidth: "+picwidth+"px; dialogTop: px; dialogLeft: px; edge: Raised; center: Yes; help: No; resizable: No; status: No; scroll: No;");
}

function DoSearchParts()
{
  x=document.forms[0];
  sSysKeyMrk = x.SSYSKEY_MRK.value;
  sSysKeyTyp = x.SSYSKEY_TYP.value;
  sSysKeyOdd = x.SSYSKEY_ODD.value;
  sNummerVrd = x.SNUMMER_VRD.value;
  sTypeNoVrd = x.STYPENO_VRD.value;

  sError="";
  submitOK="True";

  if (sSysKeyMrk.length < 1 &&
      sSysKeyTyp.length < 1 &&
      sSysKeyOdd.length < 1 &&
      sNummerVrd.length < 1 &&
      sTypeNoVrd.length < 1 )
  {
    sError=sError + "Vul tenminste één zoekveld in." + unescape("%0D")
    submitOK="False"
  }

  if (submitOK=="True")
  {
    document.forms[0].LSEARCH.value = 1;
    document.forms[0].submit();
  }
  else
  {
    alert(sError)
  }
  return null;
}

function SetOrder(sOrder)
{
  document.vehiclesearch.LSEARCH.value = 1;
  if (document.vehiclesearch.ORDER.value == sOrder)
    sOrder = sOrder.replace(/Asc/g, "Desc");

  document.vehiclesearch.ORDER.value = sOrder;
  document.vehiclesearch.submit();
  return null;
}

function MerkSubmit()
{
  document.forms[0].SSYSKEY_TYP.value = "";
  document.forms[0].submit();
  return null;
}

function GroepSubmit()
{
  document.forms[0].SSYSKEY_ODD.value = "";
  document.forms[0].submit();
  return null;
}

function ShowDetail(psSysKeyVrd)
{
  document.forms[0].SSYSKEY_VRD.value=psSysKeyVrd;
  document.forms[0].ORIGIN.value='vehicledetail';
  document.forms[0].action = 'partdetail.php';
  document.forms[0].submit();
  return null;
}

function ReadjustTable(iHeight)
{
  AnElem = document.getElementById('tablediv');
  if (AnElem != null)
  {
    AnElem.style.height = (document.body.clientHeight - iHeight);

    if (AnElem.style.height < 200)
      AnElem.style.height = 200;
  }
}

function SubmitDetailStock()
{
  document.forms[0].action = 'pricerequest.php';
  document.forms[0].submit();
  return null;
}

function DoRequest()
{
  x=document.forms[0];
  sCompany=x.COMPANY.value
  sContact=x.CONTACT.value
  sAddress=x.ADDRESS.value
  sPostal=x.POSTALCODE.value
  sCity=x.CITY.value
  sPhone=x.PHONE.value
  sFax=x.FAX.value
  sEmail=x.EMAIL.value
  x.REMARKS.value=x.REMARKS.value.substr(0,150)
  sError=""

  submitOK="True"

  if (sContact.length < 1)
  {
    sError=sError + "Contactpersoon" + miz + unescape("%0D")
    submitOK="False"
  }

  if (sEmail.length < 1)
  {
    sError=sError + "'Email adres'" + miz + unescape("%0D")
    submitOK="False"
  }
  else
  {
    at=x.EMAIL.value.indexOf("@")
    if (at==-1)
    {
      sError=sError + "Geen correct Email adres" + unescape("%0D")
      submitOK="False"
    }
    else
    {
    	at=x.EMAIL.value.indexOf(".")
      if (at==-1)
      {
        sError=sError + "Geen correct Email adres" + unescape("%0D")
        submitOK="False"
      }
    }
  }

  if (submitOK=="True")
  {
    document.forms[0].action = 'regpricerequest.php';
    document.forms[0].submit()
  }
  else
  {
    alert(sError)
  }
  return null;
}

function GotoStart()
{
  document.forms[0].action = document.forms[0].ORIGIN.value + '.php';
  document.forms[0].submit();
  return null;
}

function DoSearchVehicles()
{
  document.forms[0].LSEARCH.value = 1;
  document.forms[0].submit();
  return null;
}

function MerkSubmitWkt()
{
  document.forms[0].SSYSKEY_TYP.value = "";
  document.forms[0].submit();
  return null;
}

function ShowDetailWkt(psSysKeyWkt)
{
  document.forms[0].SSYSKEY_WKT.value=psSysKeyWkt;
  document.forms[0].action = 'vehicledetail.php';
  document.forms[0].submit();
  return null;
}

function setPage(iSub)
{
  document.forms[0].SQLPAGE.value = iSub;
  document.forms[0].LSEARCH.value = 1;
  document.forms[0].submit();
  return null;
}

function EditRequest(sSysKeyPrq)
{
  document.forms[0].SSYSKEY_PRQ.value = sSysKeyPrq;
  document.forms[0].ACTION.value = 'edit';
  document.forms[0].submit();
  return null;
}

function DeleteRequest(sSysKeyPrq)
{
  var a = confirm("PRIJSAANVRAAG VERWIJDEREN?", "Ja", "Nee");
  if (a)
  {
    document.forms[0].SSYSKEY_PRQ.value = sSysKeyPrq;
    document.forms[0].ACTION.value = 'delete';
    document.forms[0].submit();
  }
  return null;
}

function RestoreRequest(sSysKeyPrq)
{
  var a = confirm("PRIJSAANVRAAG TERUGZETTEN?", "Ja", "Nee");
  if (a)
  {
    document.forms[0].SSYSKEY_PRQ.value = sSysKeyPrq;
    document.forms[0].ACTION.value = 'restore';
    document.forms[0].submit();
  }
  return null;
}

function AnswerRequest(sSysKeyPrq)
{
  document.forms[0].SSYSKEY_PRQ.value = sSysKeyPrq;
  document.forms[0].ACTION.value = 'answer';
  document.forms[0].action = 'answerrequest.php';
  document.forms[0].submit();
  return null;
}

function SetRemarksLength(iLength)
{
  if (document.forms[0].REMARKS.value.length > iLength)
  {
    document.forms[0].REMARKS.value = Trim(document.forms[0].REMARKS.value);
    document.forms[0].REMARKS.value = document.forms[0].REMARKS.value.substr(0, iLength);
  }
}

