<!-- Dit bestand bevat FRSWeb common JavaScript functies -->
<!-- copyright 2001 BSL Computer Consultancy -->


// *******************************************************
// Strips a string from its last space to the end
// *******************************************************
function StripToSpace(t)
{
 w = t.lastIndexOf(" ");
 if (w == -1) { Res = t; }
 else { Res = t.substring(0,w+1); }
 return Res;
}


// *******************************************************
// Opens a popup window
// *******************************************************
function popup(Url,winx,winy)
{
  var win_left = (screen.width/2) - (winx/2) // from left
  var win_top  = (screen.height/2) - (winy/2) // from top
  WDef = "status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=no,width=" + winx + ",height=" + winy +",     top =" + win_top + ",left =" + win_left;
  MyDum = window.open(Url , "" , WDef);
}


// *******************************************************
// Opens a popup window for help
// *******************************************************

function popup_scroll(Url,winx,winy)
{
  var win_left = (screen.width/2) - (winx/2) // from left
  var win_top  = (screen.height/2) - (winy/2) // from top
  WDef = "status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,width=" + winx + ",height=" + winy +",     top =" + win_top + ",left =" + win_left;
  MyDum = window.open(Url , "" , WDef);
}

// *******************************************************
// Check if string is valid dateformat
// *******************************************************
function CheckDate(pDate) { // dd-mm-jjjj
  if (pDate.length != 10) { return false; }
  CleanDate = pDate.substring(0,2) + pDate.substring(3,5) + pDate.substring(6,10);
  number = parseInt(CleanDate,10);
  if (!isNaN(number)) {
    if (number > 9999) {
	day = Math.floor(number/1000000);
	month = Math.floor((number-(day*1000000))/10000);
	year = Math.floor(number-(day*1000000)-(month*10000));

	if ((month >= 1) && (month <=12)) {
	  if ((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10) || (month == 12)) {
          maxDay = 31;
	  } else if ((month == 2) || (month == 4) || (month == 6) || (month == 9) || (month == 11)){
	    if (month == 2) {
	      maxDay = 28;
	    } else {
	      maxDay = 30;
	    }
	  }
	  if ((day >= 1) && (day <= maxDay)) {
	    if ((year >= 1000) && (year <=4000)) {
	      return true;
	    }
	  }
	}
    }
  }
  return false;
}


// *******************************************************
// Check if string is valid timeformat
// *******************************************************
function CheckTime(TimeString) { //uumm
  if (TimeString.length != 5) { return false; }
  else
  { UurStr = TimeString.substring(0,2); MinStr = TimeString.substring(3,5);
    Uur = parseInt(UurStr); Min = parseInt(MinStr);
    if (isNaN(Uur) || isNaN(Min)) { return false; }
    if (Uur < 0 || Uur > 23 ) { return false; }
    if (Min < 0 || Min > 59 ) { return false; }
    return true; }
}


//*******************************************************
// Convert pixels & dpi to mm
//*******************************************************
function MilSize(Pixels,Dpi)
{ if ( Dpi != 0 && Dpi != null && Pixels != null)
  { HSizeInch =  Math.floor(Pixels/Dpi);
    HSizeMM = Math.floor(25.4 * HSizeInch);
  } else {
    HSizeMM = -1;
  }
  return HSizeMM;
}



//*******************************************************
// Open a Collection
//*******************************************************
//function OpenColl(lang, resultpage)
//{ 
//  var openurl="open_coll_"+ lang +".jsp?action=skip&resultpage="+ resultpage;
//  popup(openurl,410,385); 
//  return;
//}

//*******************************************************
// Delete a Collection
//*******************************************************
//function DelColl(lang)
//{
//  var delurl="del_coll_" + lang + ".jsp?action=skip";
//  popup(delurl,410,330);
//  return;
//}

// *******************************************************
// Append word A to string B and return string B
// If word A already appears in string B, then word A
// is REMOVED from string B. 
// string B needs to have its elements separated by a
// ', ' (comma + space) divider.
// *******************************************************
function InsertWord(AWord,BString)
{ var RetString = ""; Removed = 0;
  var WordArr = BString.split(", ");
  if (WordArr.length == 0 && BString != "")
  {  WordArr[0] = BString;
  }
  for (nn=0; nn<WordArr.length; nn++)
    { 
	if (WordArr[nn] != AWord)
      { 
	  RetString = RetString + WordArr[nn];
        if (nn < (WordArr.length - 2))
        { 
	    RetString = RetString + ", "; 
 	  }
	}
      else
      { 
	  Removed = 1; 
	}
    }
  if (Removed == 0) { RetString = BString + ", " + AWord; }
  if (RetString.charAt(0) == ",") { RetString = RetString.substring(2); }
  return RetString;
}


// *******************************************************
// Hide a layer on the gallery page
// *******************************************************
function Clear(WhichLayer)
{ if (navigator.appName=="Netscape")
    { document[WhichLayer].visibility="hidden"; }
  else 
    { document.all[WhichLayer].style.visibility="hidden"; }
}
 

// *******************************************************
// Show a layer on the gallery page
// *******************************************************
function Show(Ev,WhichLayer)
{ 
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		mX = Ev.x + document.body.scrollLeft;
		mY = Ev.y + document.body.scrollTop;
		document.all[WhichLayer].style.top = mY;
		document.all[WhichLayer].style.left = mX;
		document.all[WhichLayer].style.visibility="visible";
	}
	else
	{
		mX = Ev.pageX;
		mY = Ev.pageY;
		document[WhichLayer].top = mY;
		document[WhichLayer].left = mX;
		document[WhichLayer].visibility="visible";
	}
}

// *******************************************************
// functions added for FRS-NIOD
// *******************************************************

var wnd0 =null;
var wnd1 =null;
var wnd2 =null;
var wnd3 =null;
var wnd4 =null;

function ShowColl(lang)
{
	if (wnd0)
 	{
 		if (true!=wnd0.closed)
 		{
 			wnd0.close();
 		}
 	}
  	wnd0 = window.open("fr_collectie_" + lang + ".jsp","Collectie", "left=10,top=10,height=420,width=800,channelmode=no,directories=no,status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes");
  	wnd0.focus();
  	return true;
}

function ShowRecht(lang, pagecode)
{
	if (wnd1)
 	{
 		if (true!=wnd1.closed)
 		{
 			wnd1.close();
 		}
 	}
  	wnd1 = window.open("rechten_" + lang + ".jsp?action=RECHTEN&pagecode=" + pagecode,"Rechten", "left=20,top=20,height=420,width=800,channelmode=no,directories=no,status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes");
  	wnd1.focus();
  	return true;
}

function ShowEmail(lang, pagecode)
{
	if (wnd2)
 	{
 		if (true!=wnd2.closed)
 		{
 			wnd2.close();
 		}
 	}
  	wnd2 = window.open("mail_" + lang + ".jsp?pagecode=" + pagecode,"Email", "left=30,top=30,height=420,width=500,channelmode=no,directories=no,status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes");
  	wnd2.focus();
  	return true;
}

function ShowHelp(lang, pagecode)
{
	if (wnd3)
 	{
 		if (true!=wnd3.closed)
 		{
 			wnd3.close();
 		}
 	}
  	wnd3 = window.open("help_" + lang + ".jsp?action=HELP&pagecode=" + pagecode,"Help", "left=40,top=40,height=550,width=600,channelmode=no,directories=no,status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes");
  	wnd3.focus();
  	return true;
}

function ShowBestel(lang)
{
	if (wnd4)
 	{
 		if (true!=wnd4.closed)
 		{
 			wnd4.close();
 		}
 	}
  	wnd4 = window.open("orderlist.jsp","Bestel", "left=0,top=0,height=550,width=600,channelmode=no,directories=no,status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes");
  	wnd4.focus();
  	return true;
}

/**
 * Returns the element in a document which name is the input parameter
 */
function getElement(name)
{
	var ret = null;
	if (document.layers)
	{
		return document.layers[name];
	}
	else if (document.all)
	{
		return document.all[name];
	}
	if (document.getElementsByName)
	{
		var elements = document.getElementsByName(name);
		if (elements.length == 0)
		{
			ret = null;
		}
		else if (elements.length == 1)
		{
			ret = elements[0];
		}
		else
		{
			ret = elements;
		}
	}
	if (ret == null && document.getElementById)
	{
		ret = document.getElementById(name);
	}
	return ret;
}

/**
 * If visible is true, set the display style of elem to "block",
 * otherwise, the display style is set to "none"
 */
function setElemVisibility(elem, visible)
{
	var displaystyle = "none";
	if (visible)
	{
		displaystyle = "block";
	}
	
	if (elem != null && elem.style != null && elem.style.display != null)
	{
		elem.style.display = displaystyle;
	}
}

/**
 * Returns the visibility of the element. 
 * If the element does not exist or the display style of elem to "none", false is returned.
 * Otherwise, the return value is true.
 */
function getElemVisibility(elem)
{
	var ret = false;
	if (elem != null)
	{
		ret = true;
		if (elem.style != null && elem.style.display != null && elem.style.display == "none")
		{
			ret = false;
		}
	}
	return ret;
}
