/********************************************************/
/* Do money formatting									*/
/********************************************************/

Number.prototype.formatMoney = function(c, d, t){
var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
   return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
 };
 
 
/********************************************************/
/* Dynamic HTML select change 							*/
/********************************************************/

function changeText(BasePrice){
	var a = document.PDFcreateForm.papertype[document.PDFcreateForm.papertype.selectedIndex].id;
	var b = document.PDFcreateForm.amount[document.PDFcreateForm.amount.selectedIndex].id;

    var c = a * b + BasePrice; 

	newText = "&euro; " + c.formatMoney(2, ',', '.');
	
	document.getElementById("textBody").innerHTML = newText;
	document.getElementById("price").innerHTML = '<input type="hidden" name="price" value=\"' + newText + '">'
}

/********************************************************/
/* Tooltips												*/
/********************************************************/

var tooltip=function(){
	var id = 'tt';
	var top = 10;
	var left = 3;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u - h) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();


/********************************************************/
/* Do the tabs											*/
/********************************************************/

last_tab = 'tab1';

function show(layerName) {
	document.getElementById(layerName).style.display = '';
}

function hide(layerName) {
	document.getElementById(layerName).style.display = 'none';
}

function show_next(tab_name) {
	document.getElementById(last_tab).className = 'tab';
	var curr = document.getElementById(tab_name);
	curr.className='tab_hover';
	hide(last_tab+'_data');
	show(tab_name+'_data');
	last_tab=tab_name;
}

/********************************************************/
/* Form validation										*/
/********************************************************/

function validateForm(theform, alertMessage, theTab) {
	if (theTab != null) {
		document.getElementById(theTab).style.display = 'block';
	}
	for (var i=0; i<theform.elements.length; i++) {
		var element = theform.elements[i];
		if (element.className.indexOf("required") !=-1) {
			element.className = "required";
			if (!isFilled(element)) {
				element.focus();
				if (alertMessage != null) {
					alert (alertMessage + '\n(' + element.name + ')');
					return false;
				}
				return false;
			} 
		}
	}
	return true;
}

function isFilled(field) {
	if (field.value.length < 1 || field.value == ' ') {
		return false;
	} else {
		return true;
	}
}

/********************************************************/
/* Required field hints */
/********************************************************/

function prepareInputsForHints() {
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++){
		if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
			inputs[i].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			inputs[i].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}

	var selects = document.getElementsByTagName("select");
	for (var k=0; k<selects.length; k++){
		if (selects[k].parentNode.getElementsByTagName("span")[0]) {
			selects[k].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			selects[k].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
}



/********************************************************/
/* DashBoard dialog overlay */
/********************************************************/

function DashboardDialog()	{
	document.getElementById('DashboardDialog').style.display='block';
}

/* DashBoard overlay */

function makeHttpRequest(url, callback_function, extra_function_properties, return_xml) {
	var http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		alert('Helaas ondersteunt uw browser deze functie niet.');
		return false;
	}
	http_request.onreadystatechange = function() {
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				if (return_xml) {
					eval(callback_function + '(http_request.responseXML)');
				} else {
					extra_function_properties = ', \'' + extra_function_properties + '\'';
					eval(callback_function + '(http_request.responseText' + extra_function_properties + ')');
				}
			} else {
				return;
			}
		} else {
			return;
		}
	}
	http_request.open('GET', url, true);
	http_request.send(null);
}

var DashBoardBlankContent = '<div id="DashBoardContent"></div>';
function DashBoard(url) {
	// Create the DashBoard DIV
	var tipNameSpaceURI = 'http://www.w3.org/1999/xhtml';
	if (!tipContainerID) {
		var tipContainerID = 'DashBoard';
	}
	var tipContainer = document.getElementById(tipContainerID);
	if(!tipContainer) {
		tipContainer = document.createElementNS ? document.createElementNS(tipNameSpaceURI, 'div') : document.createElement('div');
		tipContainer.setAttribute('id', tipContainerID);
		document.getElementsByTagName('body').item(0).appendChild(tipContainer);
		tipContainer.innerHTML = DashBoardBlankContent;
	}
	if (!document.getElementById) return;

	makeHttpRequest(url, 'PrintAJAX', 'DashBoardContent');
	tipContainer.style.display = 'block';
}
function CloseDashBoard() {
	if(document.getElementById('DashBoard')) {
		document.getElementById('DashBoard').style.display = 'none';
		document.getElementById('DashBoard').innerHTML = DashBoardBlankContent;
	}
}

document.onkeydown = function(e) {
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	if(keycode == 27) { // close
		CloseDashBoard();
	}
};

function PrintAJAX(text, box) {
	document.getElementById(box).innerHTML = text;
}


/********************************************************/
/* Onload handler */
/********************************************************/

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



/********************************************************/
/* Scroller */
/********************************************************/

var delayb4scroll=4000 //Specify initial delay before marquee starts to scroll on page (2000=2 seconds)
var marqueespeed=1 //Specify marquee scroll speed (larger is faster 1-10)
var pauseit=1 //Pause marquee onMousever (0=no. 1=yes)?

var copyspeed=marqueespeed
var pausespeed=(pauseit==0)? copyspeed: 0
var actualheight=''

function scrollmarquee(){
	if (parseInt(cross_marquee.style.top)>(actualheight*(-1)+8)) //if scroller hasn't reached the end of its height
	cross_marquee.style.top=parseInt(cross_marquee.style.top)-copyspeed+"px" //move scroller upwards
	else //else, reset to original position
	cross_marquee.style.top=parseInt(marqueeheight)+8+"px"
}

function initializemarquee(){
	cross_marquee=document.getElementById("vmarquee")
	cross_marquee.style.top=0
	marqueeheight=document.getElementById("marqueecontainer").offsetHeight
	actualheight=cross_marquee.offsetHeight //height of marquee content (much of which is hidden from view)
	if (window.opera || navigator.userAgent.indexOf("Netscape/7")!=-1){ //if Opera or Netscape 7x, add scrollbars to scroll and exit
	cross_marquee.style.height=marqueeheight+"px"
	cross_marquee.style.overflow="scroll"
	return
}
setTimeout('lefttime=setInterval("scrollmarquee()",30)', delayb4scroll)
}

if (window.addEventListener)
window.addEventListener("load", initializemarquee, false)
else if (window.attachEvent)
window.attachEvent("onload", initializemarquee)
else if (document.getElementById)
window.onload=initializemarquee


/********************************************************/
/* Add window.load events */
/********************************************************/

addLoadEvent(prepareInputsForHints);


