// STANDARD FUNCTIONS

function confirmDelete(){

	var agree=confirm("Weet u zeker dat u dit record wil verwijderen?");
	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 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 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))")
}

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 checkDomain(domain){
 var domain = e.value;			
 if((domain.length < 6) ||
   (domain.indexOf('@',0) > -1) ||
   (domain.lastIndexOf('.') > (domain.length - 3)) ||
   (domain.lastIndexOf('.') < (domain.length - 4)) ||
   (domain.indexOf('..',0) > -1) ||
   (domain.indexOf(',',0) > -1)){
  alert('Dit is geen geldige domeinnaam!');
  return false; 
 }
 else{
  return true;
 }
}

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) == 'C'){
			
			if(e.value.length < 4 || e.value == ''){
				
				errors += '- ' + m + '\n'; 
			}			
		}		
		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) == '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 == '');	
}

// Function for swapping rollover TDs
function swap(td_name, image) {

	document.getElementById(td_name).style.background=image;
}

function swapCheckbox(i){
 var f = document.getElementById(i);
 var c = document.getElementById( i + "_checkbox");
 if(f.value == "checked"){
  f.value = "";
  c.src="img/checkbox_off.gif";	 	
 }
 else{
  f.value = "checked";
  c.src="img/checkbox_checked.gif";	 	
 }
}

// PNGFIX FUNCTIONS
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function fixPNG(myImage){
 if ((version >= 5.5) && (version < 7) && (document.body.filters)){
  var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
  var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
  var imgTitle = (myImage.title) ?  "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
  //var imgWidth = (myImage.width) ?  "width='" + myImage.width  + "' " : ""
  //var imgHeight = (myImage.height) ?  "height='" + myImage.height  + "' : ""
  var imgStyle = "display:inline-block;" + myImage.style.cssText
  var strNewHTML = "<span " + imgID + imgClass + imgTitle
				 + " style=\"" + "width:" + myImage.width
				 + "px; height:" + myImage.height
				 + "px;" + imgStyle + ";"
				 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				 + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
  myImage.outerHTML = strNewHTML
 }
}
// AJAX FUNCTIONS

var xHTTP;

function getHttpObject(handler){
 var xmlhttp;
 /*@cc_on
 @if (@_jscript_version >= 5)
   try {
     xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
     xmlhttp.onreadystatechange=handler;
   } catch (e) {
     try {
       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       xmlhttp.onreadystatechange=handler;
     } catch (E) {
       xmlhttp = false;
     }
   }
 @else
 xmlhttp = false;
 @end @*/
 if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
   try {
     xmlhttp = new XMLHttpRequest();
     xmlhttp.onload=handler;
     xmlhttp.onerror=handler;
   } catch (e) {
     xmlhttp = false;
   }
 }
 return xmlhttp;
}

function subscribeToNews(i, t) {
 var url = "post.php?action=ml_subscribe&ml_email="+i+"&target="+t;
 xHTTP = getHttpObject(handleGetResponse);
 xHTTP.open("GET", url, true);
 xHTTP.send(null);
}

function unSubscribeToNews(i, t) {
 var url = "post.php?action=ml_unsubscribe&ml_email="+i+"&target="+t;
 xHTTP = getHttpObject(handleGetResponse);
 xHTTP.open("GET", url, true);
 xHTTP.send(null);
}

function handleGetResponse() {
 if (xHTTP.readyState == 4) {
  var result = xHTTP.responseText;
  if(result){
   results = xHTTP.responseText.split("<!--SPLIT-->");
   for (var c=0; c<(results.length-2); c+=3){
    // HTML
    if(results[c]=='HTML'){
     var e = document.getElementById(results[c+1]);
     e.innerHTML = results[c+2];
    }       
    // DIV
    else if(results[c]=='DIV'){
     var e = document.getElementById(results[c+1]);
     e.innerHTML = results[c+2];
    }       
    // ELEMENT
    else if(results[c]=='ELEMENT'){
     var e = document.getElementById(results[c+1]);
     e.value = results[c+2];
    }       
    // JAVASCRIPT 
    else if(results[c]=='JS'){
     eval( results[c+1] );
    }      
    else {
     alert(results[c]+""+results[c+1]+""+results[c+1]);
    }
   }
  }
 }
}

function showLoading(i){
 var e = document.getElementById(i);
 e.innerHTML = '<img src=\'img/loading.gif\' style=\'position:relative;left:50%;top:10%;\'>';
}

function loadElement(element, target, type){
 if(type=='' || type == null) type = 'div';
 var v = "?action=loadElement&element=" + element + "&target=" + target + "&type=" + type;
 var url = "ajax.php" + v;
 xHTTP = getHttpObject(handleGetResponse);
 xHTTP.open("GET", url, true);
 xHTTP.send(null);
}

function loadAction(action, value, target, type){
 if(type=='' || type == null) type = 'div';
 if(type=='div') showLoading(target);
 var v = "?action=" + action + "&value=" + value + "&target=" + target + "&type=" + type;
 var url = "ajax.php" + v;
 xHTTP = getHttpObject(handleGetResponse);
 xHTTP.open("GET", url, true);
 xHTTP.send(null);
}
function checkUsername(i, m) {
 var url = "ajax.php?action=checkUsername&username=" + i + "&msg=" + m;
 xHTTP = getHttpObject(handleGetResponse);
 xHTTP.open("GET", url, true);
 xHTTP.send(null);
}
