
/*** Print ***/

function printPage(){
	window.print();
}

/*** Target change External links ***/

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank";
	}
}

/*** Set focus on first form element ***/

function setFocusFirstEl( frm ){
	for(var x=0; x < frm.elements.length; x++){
		var el = frm.elements[x];
		if( (el.type == 'text' || el.type == 'textarrea') && !(el.disabled) ){
			el.focus();
			break;
		}
	}
}

/*** functions IE :hover effects ***/

function setChildNodes(root, tag, bHover, bFocus){
		for (var i=0; i<root.childNodes.length; i++) {
			node = root.childNodes[i];

			if ((node.nodeName==tag)) {
				if( bHover == true ){
					emouseover=function() {
						this.className+=" hover";
					}
					emouseout=function() {
						this.className=this.className.replace(" hover", "");
					}
					node.onmouseover=emouseover;
					node.onmouseout=emouseout;
				}

				if( bFocus == true ){
					efocus=function() {
						this.className+=" focus";
					}
					eblur=function() {
						this.className=this.className.replace(" focus", "");
					}
					node.onfocus=efocus;
					node.onblur=eblur;
				}
			}

			setChildNodes(node, tag, bHover, bFocus);
		}
}

function setIEHover(id, tag, setfocus) {
	var bBrowser = (BrowserDetect.browser == 'Explorer') ? true : false ;
	var bVersion7 = (BrowserDetect.version > 6) ? true : false ;

	if( bBrowser && !(bVersion7 && !setfocus ) ){
		setChildNodes(document.getElementById(id), tag, !bVersion7, setfocus );
	}

}

/*** function Shop ***/

function addToCart( o_amount ){
	var amount = o_amount.value;
	if( parseInt(amount).toString() != amount || amount < 1 ){
		alert('Het veld "Aantal" moet een positief, geheel getal bevatten.');
		o_amount.focus();
		return false;
	}
	return true;
}

function initPage(){
	externalLinks();

	// if thers a form then set iehover and focus on first element
	if( document.forms.length > 0 ){
		for( var x=0; x<document.forms.length; x++ ){
			var frm = document.forms[x];
			setIEHover(frm.id, 'INPUT', true);
			setIEHover(frm.id, 'TEXTAREA', true);
			setIEHover(frm.id, 'LABEL', false);
		}
		setFocusFirstEl( frm );
	}

	// page specific
	var page = document.body.id;
}
window.onload = initPage;
