<!--
//=================================================================================================
// Returns true if the passed value is found in the
// array.  Returns false if it is not.
Array.prototype.inArray = function (value) {
    var i;
    for (i=0; i < this.length; i++) {
        // Matches identical (===), not just similar (==).
        if (this[i] === value) {
            return true;
        }
    }
    return false;
}

//=================================================================================================
function passwordConfirm(d){
	if (d.pass1.value != d.pass2.value){
		alert('De ingevulde wachtwoorden komen niet overeen.\n ');
		return false;
	}
	return true;
}
//=================================================================================================
function validateLogin() {
	var username = document.getElementsByName('userName')[0].value;
	var pass = document.getElementsByName('pass')[0].value;
	if(username == '' || username == username.defaultValue || pass == '' || pass == pass.defaultValue){
		alert('U heeft geen gebruikersnaam en wachtwoord opgegeven')
		return false;
	}else{
		return true;
	}
}
//=================================================================================================
function checkClear(input) {
	if (input.name == 'passFake'){
		// Show the real input box
		input.style.display = 'none';
		document.getElementsByName('pass')[0].style.display = '';
		document.getElementsByName('pass')[0].focus();
	}else if (input.value == input.defaultValue) {
		input.value = "";
	}
}
//=================================================================================================
function checkReset(input) {
	if (input.name == 'pass'){
		if (input.value == input.defaultValue){
			// Show the fake input box
			input.style.display = 'none';
			document.getElementsByName('passFake')[0].style.display = '';
		}
	}
	if (input.value == ''){
		input.value = input.defaultValue;
	}
}
//=================================================================================================
// @param name:			name of the cookie
// @paramvalue:			value of the cookie
// @param[expires]:		expiration date of the cookie (defaults to end of current session)
// @param[path]:		path for which the cookie is valid (defaults to path of calling document)
// @param[domain]:		domain for which the cookie is valid (defaults to domain of calling document)
// @param[secure]:		Boolean value indicating if the cookie transmission requires a secure transmission
// An argument defaults when it is assigned null as a placeholder.
// A null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}
//=================================================================================================
// @param name:			name of the desired cookie
// Returns a string containing value of specified cookie or null if cookie does not exist.
function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1){
	begin = dc.indexOf(prefix);
	if (begin != 0) return null;
	}
	else
	begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
	end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}
//=================================================================================================
// Show image in gallery
function displayImage(galleryId, imageId, imageCount, pathToRoot){
	var left =  30;
	imageBrowser = window.open(pathToRoot+'scripts/imagebrowser.php?galleryId='+galleryId+'&imageId='+imageId+'&imageCount='+imageCount, 'browse','height=300,width=300, left='+(left)+',top='+(30)+' toolbar=no,menubar=no,resizable=no,scrollbars=no,location=no,directories=no,status=no');
	imageBrowser.focus();
}
//=================================================================================================
// Show single image
function viewImage (id, pathToRoot) {
	var left =  (screen.availWidth/2)-250;
	var popUpWindow = window.open(pathToRoot+'scripts/viewimage.php?id='+id, 'image','height=20,width=100, left='+(left)+',top='+(200)+' toolbar=no,menubar=no,resizable=yes,scrollbars=no,location=no,directories=no,status=no');
	popUpWindow.focus();
}
//=================================================================================================
function printItem(id, pathToRoot){
	var left =  (screen.availWidth/2)-260;
	printPage = window.open(pathToRoot+'scripts/printitem.php?id='+id, 'print','height=450,width=550, left='+(left)+',top='+(200)+' toolbar=no,menubar=no,resizable=no,scrollbars=no,location=no,directories=no,status=no');
	printPage.focus();
}

// Returns true only if the key pressed is a digit, backspace or dot.
//=================================================================================================
function isDigit(event){
	var evt = window.event == null? event : window.event;
	var key;
	var allowedKeys = Array(8,116,37,38,39,40,45,46);

	if(evt){
		key=(evt.charCode)?evt.charCode: ((evt.keyCode)?evt.keyCode:((evt.which)?evt.which:0));
		//alert(key);
		return ((key >= 48) && (key <= 57) || allowedKeys.inArray(key))
	}
}

// Returns true if passed param is an email adress.
//=================================================================================================
function isEmail(s){
	var reEmail = /^.+\@.+\..+$/
	return reEmail.test(s)
}
// Returns true if passed param is a url.
//=================================================================================================
function isUrl(s){
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}
// Returns true if passed param is an integer.
//=================================================================================================
function isInt (s){
	var i = parseInt(s);
	return isNaN(i) ? false : true;
}
//=================================================================================================
var validationItems = new Array();

function validationItem(type, name, desc, value, vType){
	this.fldType 		= type;
	this.fldName 		= name;
	this.fldDesc  		= desc;
	this.fldValue 		= value;
	this.validationType = vType;
}
//=================================================================================================
function addValidationItem(type, name, desc, value, vType){
	validationItems[validationItems.length] = new validationItem(type, name, desc, value, vType);
}
//=================================================================================================
function validateMailform(frm){
	var valItem;
	for (var i = 0; i < validationItems.length; i++){
		valI = validationItems[i];
		FE = frm.elements[valI.fldName];
		switch (valI.fldType ){
			case 'textinput':
			case 'textarea':
				//if (FE.value.length == 0 || FE.value == valI.fldValue){
				if (FE.value.length == 0){
					alert('U heeft \'' + valI.fldDesc + '\' nog niet ingevuld.');
					FE.focus();
					return false;
				}else{
					// Check type
					switch (valI.validationType){
						case 'email':
							if(!isEmail(FE.value)){
								alert('U heeft geen geldig e-mail adres opgegeven onder \'' + valI.fldDesc + '\'.');
								FE.focus();
								return false;
							}
						break;
						case 'url':
							if(!isUrl(FE.value)){
								alert('U heeft geen geldige url opgegeven onder \'' + valI.fldDesc + '\'.');
								FE.focus();
								return false;
							}
						break;
						case 'int':
							if(!isInt(FE.value)){
								alert('U heeft geen getal opgegeven onder \'' + valI.fldDesc + '\'.');
								FE.focus();
								return false;
							}
						break;
					}
				}
			break;
			case 'checkboxgroup':
			case 'radiogroup':
				var noneChecked = true;
				
				if (FE.length) {
					for (var j = 0; j < FE.length; j++){
						if (FE[j].checked){
							noneChecked	= false;
							break;
						}
					}
				}else {
					noneChecked	= !FE.checked;
				}

				if (noneChecked){
					alert('U dient een keuze te maken onder \'' + valI.fldDesc + '\'.');
					return false;
				}
			break;
			case 'selectbox':
				if (FE.value.length == 0){
					alert('U dient een keuze te maken onder \'' + valI.fldDesc + '\'.');
					return false;
				}
			break;
		}
	}
	return true;
}
//-->
