// STANDARD FUNCTIONS

function confirmDelete(){

	var agree=confirm("Weet u zeker dat u dit record wil verwijderen?");
	if (agree)
		return true ;
	else
		return false ;
}

function formatCurrency(num,c) {
 num = num.toString().replace(/\$|\,/g,'');
 if(isNaN(num))
  num = "0";
 sign = (num == (num = Math.abs(num)));
 num = Math.floor(num*100+0.50000000001);
 cents = num%100;
 num = Math.floor(num/100).toString();
 if(cents<10)
  cents = "0" + cents;
 for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
  num = num.substring(0,num.length-(4*i+3))+'.'+
 num.substring(num.length-(4*i+3));
 if(c.length>0)
  c = c + ' ';
 return (((sign)?'':'-') + c + num + ',' + cents);
}
	  
function confirmOrder(){

	var agree=confirm("Zijn alle gegevens correct en gaat u accoord met de bestellings voorwaarden?");
	if (agree)
		return true ;
	else
		return false ;
}

var ie4 = false; if(document.all) { ie4 = true; }

function getObject(id) {
	
	if (ie4) {
		return document.all[id];
	}
	else {
		return document.getElementById(id);
	}
}

function swap(td_name, image) {

	document.getElementById(td_name).style.background=image;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function LOE_popup(url,w,h,id){
	
	if(!id){
		
		var id = "unknown";
	}
	
	var wd = "Console " + id;
	window.status='Click to open ' + wd + '!';
	
	if (!wd.closed && wd.location){
		
		wd.focus();
	}
	else{
		
		wd = window.open( url, id, 'left=' + ( (screen.width/2) - (w/2) ) + ', top=' + ( (screen.height/2) - (h/2) -20 ) + ',width=' + w + ', height=' + h + ', resizable=1, scrollbars=1,toolbar=0,status=1,location=0,directories=0,menubar=0');
		
		if (!wd.opener){
		
			wd.opener = self;
		}
	}
	
	if (window.focus) {
	
		wd.focus();
	}
}
function checkForm(){

	var i, e, t, m, errors = '', args = checkForm.arguments;
	
	for (i=0; i<(args.length-2); i+=3) { 
		
		m = args[i+2];
		t = args[i+1];
		e = MM_findObj(args[i]);
		
		if (t.charAt(0) == 'A'){
			
			t = MM_findObj(t.slice(1,t.length));
			
			if( (t.value != "") && (e.value > test.value) ){
				
				errors += '- ' + m + '\n'; 
			}
		}
		else if (t.charAt(0) == 'B'){
			
			t = MM_findObj(t.slice(1,t.length));
			
		}		
		else if (t.charAt(0) == 'M'){ // Check if value is valid emailaddress
			
			var s_email = e.value;
			
			if((s_email.length < 6) ||
			   (s_email.indexOf('@',0) < 1) ||
			   (s_email.lastIndexOf('@') != s_email.indexOf('@',0)) ||
			   (s_email.lastIndexOf('@') > (s_email.length - 5)) ||
			   (s_email.lastIndexOf('.') > (s_email.length - 3)) ||
			   (s_email.lastIndexOf('.') < (s_email.length - 4)) ||
			   (s_email.indexOf('..',0) > -1) ||
			   (s_email.indexOf('@.',0) > -1) ||
			   (s_email.indexOf('.@',0) > -1) ||
			   (s_email.indexOf(',',0) > -1)){
		
				errors += '- ' + m + '\n'; 
			}
		}
		else if (t.charAt(0) == 'd'){
			
			if((e.value > 31) || e.value == "" || e.value == 'DD'){
				
				errors += '- ' + m + '\n'; 
			}
			
		}		
		else if (t.charAt(0) == 'm'){
			
			if((e.value > 13) || e.value == "" || e.value == 'MM'){
				
				errors += '- ' + m + '\n'; 
			}
			
		}		
		else if (t.charAt(0) == 'P'){
			
			t = MM_findObj(t.slice(1,t.length));
			
			if((t.value.length < 6) || (e.value.length < 6) || (e.value != t.value) ){
				
				errors += '- ' + m + '\n'; 
			}
		}
		else if (t.charAt(0) == 'P'){
			
			t = MM_findObj(t.slice(1,t.length));
			
			if((t.value.length < 6) || (e.value.length < 6) || (e.value != t.value) ){
				
				errors += '- ' + m + '\n'; 
			}
		}
		else if (t.charAt(0) == 'y'){
			
			var d=new Date();
			if((e.value > d.getFullYear()) || e.value == "" || e.value == 'YEAR'){
				
				errors += '- ' + m + '\n'; 
			}
			
		}		
		else if (t.charAt(0) == 'U'){
			
			if(e.value.length < 6 || e.value == ''){
				
				errors += '- ' + m + '\n'; 
			}
			
		}		
		else if (t.charAt(0) == 'T'){
			
			if(e.checked != 1){
				
				errors += '- ' + m + '\n'; 
			}
			
		}		
		else{
			if(e.value == ""){
				
				errors += '- ' + m + '\n'; 
			}
		}
	}
	if(errors) {
		
		alert('De volgende fout(en) is/zijn opgetreden:\n' + errors);
	}
	
	document.returnValue = (errors == '');	
}

// PNGFIX FUNCTIONS

// Function for swapping rollover TDs
function swap(td_name, image) {

	document.getElementById(td_name).style.background=image;
}

//Array containing all PNG images on the page
var PNGimageArray = new Array();
var isPrinting = false;

//Path to the blank image (1x1 transparent)
var blankSrc = "img/spacer.gif";

//Captures print events
window.attachEvent("onbeforeprint", function () { beforePrint(); } );
window.attachEvent("onafterprint", function () { afterPrint(); } );                               
                                                      
//Tests if element is a PNG image, and if so fixes it
function addPngImage(element){
	if (/\.png$/i.test(element.src)) {
		fixImage(element);
		element.attachEvent("onpropertychange", function () { propertyChanged(); } );
		PNGimageArray[PNGimageArray.length] = element;
	}
}

//Applies filter and changes source to blank
function fixImage(element) {
	element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + element.src + "', sizingMethod='scale')";
	element.src = blankSrc;
}

//If property "src" is changed fixs image (not if it is changed to blank though)
function propertyChanged() {
	if (isPrinting) return;
	var element = event.srcElement;
	var pName = event.propertyName;
	if (pName != "src") return;
	if (!new RegExp(blankSrc).test(element.src))
		fixImage(element);

}

//Turns image back to original before print (Explorer can't print filters)
function beforePrint() {
	isPrinting = true;
	var element;
	for(var i = 0; i < PNGimageArray.length; i++){
		element = PNGimageArray[i];
		element.src = element.filters[0].src;
		element.runtimeStyle.filter = "";
	}

}

//Fixes image after print
function afterPrint() {
	isPrinting = false;
	var element;
	
	for(var i = 0; i < PNGimageArray.length; i++){
		element = PNGimageArray[i];
		fixImage(element);
	}
}

function popUp(page,PWidth,PHeight,id) {
 eval("Console"+id+"=window.open('"+page+"','MeerInformatie','toolbar=0,scrollbars=1,location=0,status=0,menubars=0,resizable=1,width="+PWidth+",height="+PHeight+"')")
 eval("Console"+id+".window.moveTo((screen.width/2)-(PWidth/2),(screen.height/2)-(PHeight/2))")
}
