var miz=' moet ingevuld zijn';
var foto1;
var ns4=document.layers?1:0
var ie=document.all?1:0
var ns6=document.getElementById&&!document.all?1:0


function ShowPic(img)
{
  window.status = '';
  iTry = 0;
  ClosePic();
  ShowPict(img, -1);
}

function ShowPicLeft(img, iLeft)
{
  window.status = '';
  iTry = 0;
  ClosePic();
  ShowPict(img, iLeft);
}

function ShowPict(img, iLeft)
{
  window.status = '';
  iTry = iTry + 1;

  foto1= new Image();
  foto1.src=(img);

  func = "ShowPictt('" + img + "', " + iLeft + ")";
  interv = setTimeout(func, 100);
}

function ShowPictt(img, iLeft)
{
  if (((foto1.width > 50) && (foto1.Height > 50)) || foto1.complete)
  {
    e = document.getElementById('theimage');
    e.src = img;

    e = document.getElementById('thepic');

    if (iLeft > -1)
    {
      e.style.left = iLeft;
      iOffSet = 100;
    }
    else
    {
      iOffSet = 100;
    }

    if(ie)
    {
      e.style.top = (iOffSet + document.body.scrollTop);
    }
    else if (ns4)
    {
      e.style.top = (iOffSet + window.pageYOffset);
    }
    else if (ns6)
    {
      e.style.top = (iOffSet + window.pageYOffset);
    }

/*    iMaxPicHeight = parent.document.getElementById('IFRM').style.height;
    iMaxPicHeight = iMaxPicHeight.substring(0, iMaxPicHeight.length - 2) - 10 - iOffSet;

    if (foto1.height > iMaxPicHeight)
    {
      e.style.height = ((iMaxPicHeight + 2) + 'px');
      e.style.width  = Math.round((foto1.width * iMaxPicHeight / foto1.height) + 2) + 'px';
    }
    else  */
    {
      e.style.height = (foto1.height + 2) + 'px';
      e.style.width = (foto1.width + 2) + 'px';
    }
    e.style.visibility = 'visible';
  }
  else
  {
    if (iTry < 5)
    {
      func="ShowPict('"+img+"', "+iLeft+")";
      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 SetPic(sFileName)
{
  e1 = document.getElementById('pic300');
  e2 = document.getElementById('pic301');
  e3 = document.getElementById('thepic');

  if (e3.style.visibility == 'visible')
    ShowPic(sFileName);
  else
  {
    e1.src  = sFileName;
    e2.href = "javascript:ShowPic('" + sFileName + "')";
  }
}

function trim(stringToTrim)
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function ltrim(stringToTrim)
{
	return stringToTrim.replace(/^\s+/,"");
}

function rtrim(stringToTrim)
{
	return stringToTrim.replace(/\s+$/,"");
}

function DoFreeSearch()
{
  x=document.forms[0];

  if (x.FREESEARCH.value == x.FREESEARCH.hintText)
    sFreeSearch = '';
  else
  {
    x.FREESEARCH.value = trim(x.FREESEARCH.value) + ' ';
    sFreeSearch = x.FREESEARCH.value;

    while (sFreeSearch.indexOf("  ") > -1)
      sFreeSearch = sFreeSearch.replace(/  /gi, " ");

    x.FREESEARCH.value = trim(sFreeSearch);
    sFreeSearch = x.FREESEARCH.value;
  }

  sError = ""
  submitOK = "True"

  if (sFreeSearch.length < 3 )
  {
    sError=sError + "Vul tenminste drie letters/cijfers in." + unescape("%0D")
    submitOK="False"
  }

  if (submitOK=="True")
  {
    document.forms[0].SQLPAGE.value = 1;
    document.forms[0].LSEARCH.value = 1;
    sFreeSearch = sFreeSearch.replace(/ /gi, "/");

    document.forms[0].action = 'http://www.totalparts.nl/zoek/' + sFreeSearch;
    return true;
  }
  else
  {
    alert(sError)
    return false;
  }
}

function GoDetail(sTarget, sSysKeyVrd)
{
  document.forms[0].action = sTarget;
  document.forms[0].SSYSKEY_VRD.value = sSysKeyVrd;
  document.forms[0].submit();
  return null;
}

function SubmitDetailStock()
{
  document.forms[0].action = 'http://www.totalparts.nl/pricerequest.php';
  document.forms[0].submit();
  return null;
}

function GotoStart()
{
  x=document.forms[0];
  document.forms[0].action = 'http://www.totalparts.nl/index.php';

//  alert(document.forms[0].action);
  document.forms[0].submit();
  return null;
}

function GotoDetail()
{
  document.forms[0].action = 'http://www.totalparts.nl/partdetail.php';
  document.forms[0].submit();
  return null;
}

function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
/*  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight ); */

  return myHeight;
}

function ReadjustTable(iHeight, sNumRows)
{
  AnElem = document.getElementById('tablediv');
  if (AnElem != null)
  {
    AnElem.style.height = (alertSize() - iHeight) + 'px';
  }

  AnElem = document.getElementById('sendx');
  AnElem.value = 'Zoek (' + sNumRows + ')';
}

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 < 2)
  {
    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 = 'http://www.totalparts.nl/regpricerequest.php';
    document.forms[0].submit()
  }
  else
  {
    alert(sError)
  }
  return null;
}

function setPage(iSub)
{
  document.forms[0].SQLPAGE.value = iSub;
  document.forms[0].LSEARCH.value = 1;
  document.forms[0].submit();
  return null;
}

