/**                  
 * functions.js
 *
 * This file profites an general function set! 
 * The functions below are very handy for handling
 * common javascript functionality or Dynamic (X)HTML.
 *
 * @version 	1.0
 * @author	A.J. de Vries	
 * @package	javascript 
 * 
 * Copyright (c) 2005 Malibomba                               
 * IT IS NOT ALLOWED TO USE OR MODIFY ANYTHING OF THIS SITE,  
 * WITHOUT THE PERMISION OF THE AUTHOR.                       
 * Info? Mail to info@malibomba.com                           
 */
//<![CDATA[ 
var xmlhttp = null;
/*@cc_on @*/
/*@if(@_jscript_version >= 5)
	try {
		xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
	} catch(e) {
		try {
			xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
		} catch(e) {
			xmlhttp = false;
		}
	}
@else
	xmlhttp = false;
@end @*/
if(!xmlhttp && document.createElement) {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch(e) {
		xmlhttp = false;
	}
}


/**
 * setCookie(name, value)
 *
 * Set a Cookie with the given name and 
 * given value
 *
 * @version 	1.0
 * @author 	A.J. de Vries
 * @param 	[string] name: the name of the new cookie.
 * @param	[mixed]  the value of the new cookie with the given name.
 * @return	[void]
 */
function setCookie(name, value) {
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}



/**
 * getCookie(name)
 *
 * Get the cookie (value) with the given name.
 *
 * @version 	1.0
 * @author 	A.J. de Vries
 * @param 	[string] name: the name of the cookie.
 * @return	[string] the value of the cookie with the given name
 */
function getCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while(i < clen) {
		var j = i + alen;
		if(document.cookie.substring(i, j) == arg) {
			return getCookieVal(j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if(i == 0) {
			break;
		}
	}
	return null;
}



/**
 * getCookieVal(offset)
 *
 * private function:
 * Is used by getCookie(name) to return the value 
 * of the requested cookie.
 *
 * @version 	1.0
 * @author 	A.J. de Vries
 * @param 	[integer] offset: the offset value of the cookie value.
 * @return	[string]  the value of the cookie with the given name
 */
function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if(endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}



/**
 * getElement(elem)
 *
 * Get the element with the given name (elem)
 * and return a reference (object) to it.
 *
 * @version 	1.0
 * @author 	A.J. de Vries
 * @param 	[string] elem: the name of the element
 * @return	[object] the object that references the element with the given name.
 */
function getElement(elem) {
	if(document.getElementById)
		return document.getElementById(elem);
	if(document.all)
		return document.all[elem];
}




/**
 * addEvent(elem, evt, func)
 *
 * Add an event to the given element (elem)
 *
 * @version 	1.0
 * @author 	A.J. de Vries
 * @param 	[object]   elem: the element(object) on which the event is set to.
 * @param 	[string]   evt:  the name of the event, e.g: 'load', 'focus', 'unload', etc.
 * @param 	[function] func: the function to execute.
 * @return	[void]
 */
function addEvent(elem, evt, func) {
	if(elem.addEventListener)
		elem.addEventListener(evt, func, false);
	else if(elem.attachEvent)
		elem.attachEvent('on'+evt, func);
}


/**
* Disable right click script 
*/

//var message="&copy;";
//function clickIE() {if (document.all) {(message);return false;}}
//function clickNS(e) {if 
//(document.layers||(document.getElementById&&!document.all)) {
//if (e.which==2||e.which==3) {(message);return false;}}}
//if (document.layers) 
//{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
//else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
//document.oncontextmenu=new Function("return false")


//window.onload = function() { 
//		window.defaultStatus='SchilderOnderhoudsPlan || powered by malibomba.com ||';
//	}



/**
* add favorites
*/

function addbookmark()	{
	bookmarkurl="http://www.schilderonderhoudsplan.nl/"
	bookmarktitle="SchilderOnderhoudsPlan"
	if (document.all)
	window.external.AddFavorite(bookmarkurl,bookmarktitle)
}


function checkNEmail(form) {
	if (isBlank(form.email.value) || isBlank(form.name.value) || !isEmailValid(form.email.value) ) 
	{
		alert("Vul een geldige naam en e-mail adres in.\nHet e-mail adres en/of naam die u heeft ingevoerd zijn niet geldig.");
		form.email.focus();
		return false;
	}
	}

function checkEmail(form) {
	if (isBlank(form.email.value) || !isEmailValid(form.email.value) ) {
		alert("Vul een geldig e-mail adres in.\nHet e-mail adres dat u heeft ingevoerd is niet geldig.");
		form.email.focus();
		return false;
	}
return true;

}

function isBlank(fieldValue) {
	var blankSpaces = / /g;
	fieldValue = fieldValue.replace(blankSpaces, "");
	return (fieldValue == "") ? true : false;
}

function isEmailValid(fieldValue) {
	var emailFilter = /^.+@.+\..{2,4}$/;
	var atSignFound = 0;
	for (var i = 0; i <= fieldValue.length; i++)
		if ( fieldValue.charAt(i) == "@" )
			atSignFound++;
	if ( atSignFound > 1 )
		return false;
	else
		return ( emailFilter.test(fieldValue) && !doesEmailHaveInvalidChar(fieldValue) ) ? true : false;
}

function doesEmailHaveInvalidChar(fieldValue) {
	var illegalChars = /[\(\)\<\>\,\;\:\\\/\"\[\] ]/;
	return ( illegalChars.test(fieldValue) ) ? true : false;
}
//  End -->

//]]>