

// Regex function to see if an input value has been entered at all -----------------------------------------------------------
function IsEmpty(inputStr) {
	var re = /.+/;
	if (!inputStr.match(re)) {
	  return true;
	}
	return false;
}

// Regex function to see if an input value is an integer ---------------------------------------------------------------------
function IsNumber(inputStr) {
	var re = /.[a-zA-Z]/;
	if (!inputStr.match(re)) {
	  return true;
	}
	return false;		
}



// Regex function used on STCN titles to render italic and supersscript ------------------------------------------------------
function StcnReplace(strInput)
{
	strInput=strInput.replace(/`IT`/g,"\<span class=\"italicize\"\>");	
	strInput=strInput.replace(/`SUP`/g,"\<span class=\"superscript\"\>");		
	strInput=strInput.replace(/`LO`/g,"<\/span>");
	strInput=strInput.replace(/&#65056;/g,"&#967;");	
	document.write(strInput);
}

// Regex function general input replacement ----------------------------------------------------------------------------------
function EscapeChar(strInput)
{
  strInput=strInput.replace(/&/g,"&amp;"); 
  strInput=strInput.replace(/</g,"&lt;");	
  strInput=strInput.replace(/>/g,"&gt;");
  strInput=strInput.replace(/\"/g,"&quot;");
  strInput=strInput.replace(/\'/g,"&apos;");	
  strInput=strInput.replace(/\[/g,"&#91;");	
  strInput=strInput.replace(/\]/g,"&#93;");
  strInput=strInput.replace(/\\/g,"&#92;");	
  strInput=strInput.replace(/\:/g,"&#58;");  
  return(strInput);
}

// Regex function to remove unwanted characters to prevent script inserts via search form --------------------------------
function Sanitizer(strInput){
	strInput=strInput.replace(/</g,""); //tag open
	strInput=strInput.replace(/>/g,""); //tag close 
	strInput=strInput.replace(/%/g,""); // percent sign - asp script delimeter
	return(strInput);
}

// Toggle function for div visibility ----------------------------------------------------------------------------------------
function ToggleDiv(oName){
	var s = document.getElementById(oName);
	var cdiv = (s.style.display == 'block') ? 'none' : 'block';
	s.style.display = cdiv;
}

// Regex Email validation ----------------------------------------------------------------------------------------------------
var testresults = false;
function CheckEmail(theForm, theField){
	var str = document.getElementById(theField).value;
	if (str == '') {
		alert("U moet nog een emailadres invullen!");
		testresults = false; }
	else {
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(str))
			testresults = true;
		else {
			alert("U moet een geldig emailadres invullen!")
			testresults = false;
		}
	}
	
	return (testresults)
}


// Cookie Functions ---------------------------------------------------------------------------------------------------------


function DeleteCookie(name) {
  if (ReadCookie(name) != null) {
	document.cookie = name + "=; expires=Thu, 01-Jan-70	00:00:01 GMT; path=/";
  }
}

function CreateCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function ReadCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

// Stylesheet switch (www.alistapart.com) -----------------------------------------------------------------------------------

function SetActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function GetActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function GetPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

window.onload = function(e) {
  var cookie = ReadCookie("style");
  var title = cookie ? cookie : GetPreferredStyleSheet();
  SetActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = GetActiveStyleSheet();
  CreateCookie("style", title, 365);
}

var cookie = ReadCookie("style");
var title = cookie ? cookie : GetPreferredStyleSheet();
SetActiveStyleSheet(title);

// ---------------------------------------------------------------------------------------------------------------------------

function WriteToForm(oValue, oKey, doSubmit){
	var toForm = parent.document.getElementById('searchForm');
	if (!IsEmpty(toForm.searchTerm1.value) && !IsEmpty(toForm.searchTerm2.value) && !IsEmpty(toForm.searchTerm3.value)) {
	alert("alle velden zijn in gebruik");
	} else {
			var indexToFill = Array("searchKey1","searchKey2","searchKey3");
			var fieldToFill = Array("searchTerm1","searchTerm2","searchTerm3");
			for (var i = 0; i <= indexToFill.length ; i++ ){
				var objIndex = toForm.elements[indexToFill[i]];
				var objField = toForm.elements[fieldToFill[i]];
					if (objField.value == "" || objField.value == "undefined") {
						objIndex.selectedIndex = oKey;
						objField.value = oValue;
						objField.style.backgroundColor = '#FFFF80';
						break;
					}
			}
			if (doSubmit != null){
					toForm.stylesheet.value = "shortTitlePresentation.xslt";
					toForm.addHistory.value = 1;
					toForm.frmQuery.value = getLongKey(oKey) +"=" +oValue;
					toForm.tab.value = "list"
					toForm.submit();
			} 			
		}
}

function getLongKey(keynr){
	switch (keynr) {
		case 0: return "pica.all"; break;
		case 1: return "pica.aut"; break;
		case 2: return "pica.ttl"; break;
		case 3: return "pica.gtr"; break;
		case 4: return "pica.pao"; break;
		case 5: return "pica.bcl"; break;
		case 6: return "pica.peg"; break;
		case 7: return "pica.icb"; break;
		case 8: return "pica.isn"; break;
		case 9: return "pica.taa"; break;
		case 10: return "pica.ppn"; break;
		default: return "pica.all"; break;
	}
}

// MacroMedia Functions --- always handy to have around ---------------------------------------------------------------------

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


// Disable window status ----------------------------------------------------------------------------------------------------
/*
document.onmouseover = function ( e ) 
{   
	if ( !e ) e = window.event;   
	var el = e.target ? e.target : e.srcElement;   
	while ( el != null && el.tagName != "A" ) el = el.parentNode;   
	if ( el == null ) return;   
	if ( e.preventDefault ) e.preventDefault();   
	else e.returnValue = true;
};
*/

// Get window width and height ------------------------------------------------------------------------

function getWinWidth(){
	var windowWidth=0;
	if (typeof(window.innerWidth)=='number') {
		windowWidth=window.innerWidth;
	}
	else {
		if (document.documentElement&&document.documentElement.clientWidth) {
			windowWidth=document.documentElement.clientWidth+4; //+4 to equal moz innerWidth
		}
		else {
			if (document.body&&document.body.clientWidth) {
				windowWidth=document.body.clientWidth+4;
			}
		}
	}
	return windowWidth;
}

function getWinHeight(){
	var windowHeight=0;
	if (typeof(window.innerHeight)=='number') {
		windowHeight=window.innerHeight;
	}
	else {
		if (document.documentElement&&document.documentElement.clientHeight) {
			windowHeight=document.documentElement.clientHeight;
		}
		else {
			if (document.body&&document.body.clientHeight) {
				windowHeight=document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}