
// open window
function WindowOpen(width,height,url) {
	window.open(url,"","toolbar=0,location=0,status=1,menubar=0,scrollbars=1,resizable=0,width=" +width+ ",height=" +height);
}

// add bookmark
function AddBookmark(url, title) {
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url, "");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite(url, title);
	} else if(window.opera && window.print) { // Opera Hotlist
		return true;
	}
}

//this function is used for mouseovers
function AddStringToFileName(file_object, string_to_add) {
	last_dot   = file_object.src.lastIndexOf('.');
	file_ext   = file_object.src.slice(last_dot, file_object.src.length); // eg: .gif
	file_path  = file_object.src.slice(0, last_dot); // eg: /shared/custom/images/header
	string_len = string_to_add.length;
	
	//exit if the filename already contains the string to add
	if(file_path.slice(file_path.length - string_len, file_path.length) == string_to_add)
		return;
	
	//add the string to add to the src
	file_object.src = file_path + string_to_add + file_ext;
}

function RemoveStringFromFileName(file_object, string_to_remove) {
	last_dot   = file_object.src.lastIndexOf('.');
	file_ext   = file_object.src.slice(last_dot, file_object.src.length); // eg: .gif
	file_path  = file_object.src.slice(0, last_dot); // eg: /shared/custom/images/header
	string_len = string_to_remove.length;
	
	//only remove the string if filename contains the string
	if(file_path.slice(file_path.length - string_len, file_path.length) == string_to_remove)
		file_object.src = file_path.slice(0, file_path.length - string_len) + file_ext;
}

function CheckContactForm() {
	// FORM
	var f = document.contact_form;
	
	// MESSAGE
	var header = 'De volgende velden zijn niet correct ingevuld:\n\n';
	
	// CHECK FIELDS
	var message = '';
	message += CheckField(f.naam, 'Naam');
	message += CheckEmail(f.email, 'Email adres');
	message += CheckField(f.vraag, 'Vraag');
	
  	if (message != "") {
		alert(header+''+message);
		return false
	}
}

function SetFFStyle(el, status) {
	if (status == 'Bad') {
		// Backup current classname in cookie
		if (el.className != 'FormCheckBad') {
			var expires = CookieExpires();
			Set_Cookie("ContactClassName", el.className,expires);
		}
		
		// Change classname to bad
		el.className = 'FormCheckBad';
	} else {
		// Get classname from cookie
		var ContactClassName = Get_Cookie("ContactClassName");
		
		if (ContactClassName != 'FormCheckBad' && ContactClassName != '') {
			// Restore classname from cookie
			el.className = ContactClassName;
		} else {
			// Restore to default class
			el.className = 'FormCheckGood';
		}
	}
}

function CheckField(fieldname, message) {
	if(fieldname) {
		if (fieldname.value == "") {
			SetFFStyle(fieldname, 'Bad');
			message = '- '+message+'\n';
			return message;
		} else {
			SetFFStyle(fieldname, 'Good');
			return '';
		}
	} else {
		return '';
	}
}

function CheckCheckbox(fieldname, message) {
	if(fieldname) {
		if (fieldname.checked != true) {
			message = '- '+message+'\n';
			return message;
		} else {
			return '';
		}
	} else {
		return '';
	}
}

function CheckEmail(fieldname, message) {
	if(fieldname) {
		if (fieldname.value == "") {
			SetFFStyle(fieldname, 'Bad');
			message = '- '+message+'\n';
			return message;
		} else if (IsEmail(fieldname.value) == false) {
			SetFFStyle(fieldname, 'Bad');
			message = '- '+message+' is geen geldig e-mailadres !\n';
			return message;
		} else {
			SetFFStyle(fieldname, 'Good');
			return '';
		}
	} else {
		return '';
	}
}

function IsEmail(str) {
	// are regular expressions supported?
	var supported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported)
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}


