var _ns4    = (document.layers)? true:false
var _ie4    = (document.all)? true:false
var _ie5    = (document.getElementById)? true:false
var _ns6    = (document.getElementById && !document.all)?true:false;
var vorige  = false;
// we houden deze variabele bij om te zien of we naar een andere pagina gaan
// of de browser gesloten wordt. in het 2e geval moet de login gereleased worden.
var closing = true;


function goToFav(id)
{
	if (id != "-") {
		window.location="/publiek/ReadProduct.do?id="+id;
	}
}

function Show(id, e)
{
	if (!e) e = window.event;
    //x = e.clientX + document.body.scrollLeft + 5;
    //y = e.clientY + document.body.scrollTop;
    var Popup = (_ns4)? document.layers[id] : (_ie4)? document.all[id].style : document.getElementById(id).style;
    Popup.display = "block";
    Popup.left = 710;
    Popup.top = 380;
    
}

function Show2(id, e)
{
	if (!e) e = window.event;
    //x = e.clientX + document.body.scrollLeft + 5;
    //y = e.clientY + document.body.scrollTop - 290;
 	 var Popup = (_ns4)? document.layers[id] : (_ie4)? document.all[id].style : document.getElementById(id).style;
    Popup.display = "block";
    Popup.left = 500;
    Popup.top = 160;
}

function Hide(id)
{
    var Popup = (_ns4)? document.layers[id] : (_ie4)? document.all[id].style : document.getElementById(id).style;
    Popup.display="none";
}

function toggleDivs(id)
{
  //if (vorige&&vorige!=id)
  if (vorige)
  { 
    var styleObj = document.getElementById(vorige).style;
    styleObj.display = "none";
  }

  var styleObj = document.getElementById(id).style;
  if(styleObj.display == "none"){
    styleObj.display = "";
  } else {
    styleObj.display = "none";
  }    
  vorige = id;
}

/* Tonen/Verbergen van een element */
function toggelDiv(sel) {
	if (document.getElementById(sel).style.display == "none") {
		showDiv(sel);
	} else {
		hideDiv(sel);
	}
}

function toggleSpan(id, showVal)
{
	if (document.getElementById(id).innerHTML == showVal) {
    	document.getElementById(id).innerHTML = "*******";
    } else {
        document.getElementById(id).innerHTML = showVal;
    }
}

function showDiv(sel) {
	document.getElementById(sel).style.display="";
}

function hideDiv(sel) {
	document.getElementById(sel).style.display="none";
}

function swapImg(id)
{
	var huidig = document.images[id].src;
	
	if (id.indexOf("plus") > -1)
	{
		// plus en min
		if (huidig.indexOf("plus") > -1)
		{
			regex = /plus\.png/;
			huidig = huidig.replace(regex, "minus.png");
			document.images[id].src = huidig;
		}
		else
		{
			regex = /minus\.png/;
			huidig = huidig.replace(regex, "plus.png");
			document.images[id].src = huidig;
		}
	}
	else
	{
		// pijlen
		if (huidig.indexOf("close") > -1)
		{
			regex = /close\.gif/;
			huidig = huidig.replace(regex, "open.gif");
			document.images[id].src = huidig;
		}
		else
		{
			regex = /open\.gif/;
			huidig = huidig.replace(regex, "close.gif");
			document.images[id].src = huidig;
		}
	}
}

function toggleSearch(which, lang)
{
   if (lang == 1) {
	   var txt_name     = "Vul een deel van de naam in";
	   var txt_cnk      = "Vul een CNK-nummer in";
	   var txt_fulltext = "Vul een deel van de tekst in";
	   var txt_locnr    = "Vul een locatie in, gescheiden door punten";
	   var txt_loctit   = "Vul een locatietitel in";
	   var txt_prdcnt   = "Vul een fabrikant in";
   }
   else {
	   var txt_name     = "Introduire le nom ou une partie du nom";
	   var txt_cnk      = "Introduire le code CNK";
	   var txt_fulltext = "Introduire une partie du texte";
	   var txt_locnr    = "N° de localisation (en partie), sep. par un point";
	   var txt_loctit   = "Introduire le titre de localisation (en partie)";   
	   var txt_prdcnt   = "Introduire un manufacteur";	   
   }
   var searchfld  = document.productSearchForm.searchValue;
   
   if (which == "name" && (searchfld.value == "" || searchfld.value == txt_cnk
   												 || searchfld.value == txt_fulltext
                                                 || searchfld.value == txt_locnr
                                                 || searchfld.value == txt_prdcnt
                                                 || searchfld.value == txt_loctit)) 
   {
      searchfld.value = txt_name;
   }
   if (which == "cnk" && (searchfld.value == "" || searchfld.value == txt_name
									   			|| searchfld.value == txt_fulltext
                                                || searchfld.value == txt_locnr
                                                || searchfld.value == txt_prdcnt
                                                || searchfld.value == txt_loctit)) 
   {
      searchfld.value = txt_cnk;
   }
   if (which == "fulltext" && (searchfld.value == "" || searchfld.value == txt_name
   												|| searchfld.value == txt_cnk
   												|| searchfld.value == txt_locnr
                                                || searchfld.value == txt_prdcnt
                                                || searchfld.value == txt_loctit)) 
   {
      searchfld.value = txt_fulltext;
   }
   if (which == "locnr" && (searchfld.value == "" || searchfld.value == txt_cnk
   												  || searchfld.value == txt_fulltext
                                                  || searchfld.value == txt_name
                                                  || searchfld.value == txt_prdcnt
                                                  || searchfld.value == txt_loctit)) 
   {
      searchfld.value = txt_locnr;
   }
   if (which == "loctitle" && (searchfld.value == "" || searchfld.value == txt_cnk
   													 || searchfld.value == txt_fulltext
                                                     || searchfld.value == txt_locnr
                                                     || searchfld.value == txt_prdcnt
                                                     || searchfld.value == txt_name)) 
   {
      searchfld.value = txt_loctit;
   }
   if (which == "producent" && (searchfld.value == "" || searchfld.value == txt_cnk
   													  || searchfld.value == txt_fulltext
                                                      || searchfld.value == txt_locnr
                                                      || searchfld.value == txt_loctit
                                                      || searchfld.value == txt_name)) 
   {
      searchfld.value = txt_prdcnt;
   }
}

function trim(inputString)
{
   if (typeof inputString != "string")
   {
	return inputString;
   }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ")
   {
      // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ")
   {
      // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1)
   {
      // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue;
}
