/*--------------------------------------------------------------------
Basic Javascript Sheet

Version: 1.0
Copyright: 2008, dicode® VOF - understanding internet
W: www.dicode.nl
E: info@dicode.nl
T: 0570-750680
--------------------------------------------------------------------*/

/* Custom Scripts
--------------------------------------------------------------------*/


/* Global
--------------------------------------------------------------------*/
$(document).ready(function() {
	
	var arr = document.getElementsByTagName('a');
	for(i = 0; i < arr.length; i++)
		arr[i].onfocus = new Function("this.blur()");
	
	var arr = document.getElementsByTagName('input');
	for(i = 0; i < arr.length; i++)
		if(arr[i].className == 'button')
			arr[i].onfocus = new Function("this.blur()");

	$(".popupwindow").each( function(index) {
		$(this).popupwindow({ front : {
			height:768,
			width:1024,
			toolbar:1,
			scrollbars:1,
			status:1,
			resizable:1,
			left:0,
			top:0,
			center:1,
			createnew:0,
			location:1,
			menubar:1
		} });
	});
	
	$.ifixpng(siteurl + 'images/beheer/transparant.gif');
	$('img[src$=png]').ifixpng();
	
	FormElements.init();

});

function redirect( strURL ) {
	window.location = strURL;
}

function getkey(e) {
	if (window.event)
		return window.event.keyCode;
	else if (e)
		return e.which;
	else
		return null;
}

function validChars(e, goods) {
	var key, keychar;
	key = getkey(e);
	if (key == null) 
		return true;

	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	goods = goods.toLowerCase();
	if (goods.indexOf(keychar) != -1)
		return true;

	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		return true;
	
	return false;
}

/**
 * switchDiv
 *
 * Function for displaying or hiding an element.
 *
 * @param strId	The id of the element to hide or display
 */
function switchDiv( strDiv ) {
	if( $(strDiv).style.display == '')
		$(strDiv).style.display = 'none';
	else
		$(strDiv).style.display = '';
}

function checkKeyEnter(e) {
        var key;
        if (window.event)
           key = window.event.keyCode;
        else if (e)
           key = e.which;

        return key == 13;

}

function checkLogin( pfx, e ) {
	
	if( checkKeyEnter(e) ) { 
	
		var frm = $($.sprintf('#frm_%s', pfx));
		
		var f;
		
		if( (f = $("#id_username", frm)).val() == "" ) {
			alert("U dient een gebruikersnaam op te geven");
			f.focus();
			return false;
		} else if( (f = $("#id_password", frm)).val() == "" ) {
			alert("U dient een wachtwoord op te geven");
			f.focus();
			return false;
		}

		frm.submit();
		
	}
}

function limitChars(textid, limit, infodiv) {
	var text = $($.sprintf('#%s', textid)).val(); 
	var textlength = text.length;
	
	if(textlength > limit) {
		$($.sprintf('#%s', textid)).val(text.substr(0,limit));
		return false;
	} else {
		$($.sprintf('#%s', infodiv)).html('Resterend aantal characters: '+ (limit - textlength));
		return true;
	}
}