function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
    	}
  	}
}

function init() {
	parseLinks(); // XHTML compliant links
	formInputValues();
	
	if ((window.supersleight || false) ) {
		supersleight.init();
		
	}
}

function parseLinks() {
	if (!document.getElementById) return;

	var a = document.getElementsByTagName('a'), i = a.length;
	while (i--) {
		if (a.item(i).getAttribute('rel') == 'external') {
			a.item(i).onclick = function() { window.open(this.href); return false; }
		}
	}
}

var inputObject = function (form, field, defValue) {
	var cForm = document.getElementById(form);

	if (cForm) {
		cForm[field].value = defValue;
		cForm[field].onfocus = function z () {
			if(cForm[field].value == defValue) { caretToStart(this); this.style.color = "#cecbcb"; }
		}
		cForm[field].onkeydown = function z () { 
			if(cForm[field].value == defValue) { this.value = ''; this.style.color = "#393939"; }
		}
		cForm[field].onblur = function z () {
			if(cForm[field].value == '') { this.value = defValue; }
			this.style.color = "#393939";
		}
	}
}

function formInputValues() {
	if (!document.getElementById) return;
	
	var inputValues = {
		'form-zoek-op-site': {
			'query': 'Ik zoek hier...'
		},
		'form-zoek-op-google': {
			'as_q': 'Ik zoek...'
		},
		'form-zoek-op-davindi': {
			'query': 'Ik zoek...'
		},
		'form-webmail': {
			'imapuser': 'Gebruikersnaam',
			'pass': 'Wachtwoord'
		},
		'form-telefoongids': {
			'name': 'Naam',
			'city': 'Plaats'
		}
	};
	
	for (var form in inputValues) {
		for (var field in inputValues[form]) {
			new inputObject(form, field, inputValues[form][field]);
		}
	}
}

function caretToStart (target) {
	if (target.createTextRange) {
    	var range = target.createTextRange();
    	range.collapse(true);
   		range.select();
  	} else if (target.setSelectionRange) {
    	target.focus();
    	target.setSelectionRange(0, 0);
	}
}

function changeLocation(url) {
	window.location.href = url;
}

addLoadEvent(init); // Init scripts
