// JavaScript Document

// Mautools v 0.00.02

function $(id){
	return document.getElementById(id);
}
function $hide(id){
	document.getElementById(id).style.display = "none";
}
function $show(id){
	document.getElementById(id).style.display = "block";
}
function $html(id, html){
	document.getElementById(id).innerHTML = html;
}
function $style (id){
	return document.getElementById(id).style;
}
function $value (id){
	return document.getElementById(id).value;
}
function $iover(e, name){
	if (name == null){name = "_over";}
	e.src = e.src.replace(new RegExp("(.)[^.]*$"),name+"."+e.src.substr(e.src.length-3));
}
function $iout(e, name){
	if (name == null){name = "_over";}
	e.src = e.src.replace(name+".",".");
}	

function $shake(id, margin){
	var x_offset = parseInt($(id).offsetLeft - margin);
	var i = 0;
	doMove();
	function doMove() {
	  if (i%2==1){x_offset = x_offset + 4} else {x_offset = x_offset - 4}
	  $(id).style.left = x_offset+"px";
	  i++;
	  if (i<10){
	  	setTimeout(doMove,70);
	  }
	}
}
		

//EVENT HANDLERS
function $addClick(id,fname){document.getElementById(id).onclick = function(){fname(this);}}
function $addOver(id,fname){document.getElementById(id).onmouseover = function(){fname(this);}}
function $addOut(id,fname){document.getElementById(id).onmouseout = function(){fname(this);}}

// AJAX STUFF
function $ajax(url,args,fname){
	if (args == null){args = ""};
	var xmlHttp;
	xmlHttp = null;
	try{xmlHttp=new XMLHttpRequest();}
	catch (e) {
 	 	try {
    			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    		}
  		catch (e){
    			try {
      				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
     			}
    			catch (e) {
     				alert("Your browser does not support AJAX!\nThis site will not function properly...");
      				return false;
      			}
    		}
  	}
	xmlHttp.onreadystatechange=function(){
   		 if(xmlHttp.readyState==4){
     		 	fname(xmlHttp.responseText);
      		}
    	}
  	xmlHttp.open("GET", url+"?"+args, true);
 	xmlHttp.send(null);
}

function $ajaxRespArray (evt, enq1, enq2){
	if (enq1 == null){enq1 = "|";}
	if (enq2 == null){enq2 = "=";}
	var arr = new Array();
	arr = evt.target.data.split(enq1);
	for (var i=0; i<arr.length; i++){
		arr[i] = arr[i].split(enq2);
	}
	return arr;
}

function $ajaxPost (url, args, fname){
	if (args == null){args = ""};
	var xmlHttp;
	xmlHttp = null;
	try{xmlHttp=new XMLHttpRequest();}
	catch (e) {
 	 	try {
    			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    		}
  		catch (e){
    			try {
      				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
     			}
    			catch (e) {
     				alert("Your browser does not support AJAX!\nThis site will not function properly...");
      				return false;
      			}
    		}
  	}
	xmlHttp.onreadystatechange=function(){
   		 if(xmlHttp.readyState==4){
     		 	fname(xmlHttp.responseText);
      		}
    	}
  	xmlHttp.open("POST", url, true);
 	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", args.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(args);
}

function $checkmail (email, message, defmail){
	if (message ==  null){message = "This is not a valid email adres";}
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if ((!filter.test(email)) || (email == defmail)) {
		alert(message);return false;
	} else {
		return true;
	}
}

