function delete_agent(img, id, oid)
{
	img.src = 'smart.php?action=delete&id=' + oid + '&' + Math.random();
	img.onload = getstyle('row' + id).display='none';
	
}

function getstyle (layer)
{
	if(document.getElementById)
	{
		return document.getElementById(layer).style
	}
	else if(document.all)
	{
		return document.all[layer].style
	}
	else
	{
		return document[layer]
	}
}


function fetch(id) 
{
	if (document.getElementById)
		return document.getElementById(id);
	else if (document.all)
		return document.all[id];
	else 
		return null;
}

/* POPUP */

/* function launch_popup(site, cat, ID, winwidth, winheight) {

	winleft = (screen.width / 2) - (winwidth / 2);
	wintop = (screen.height / 2) - (winheight / 2) - 20;

	window.open("./"+site+""+cat+""+ID, "", "width="+winwidth+",height="+winheight+",resizable=no,scrollbars=no,left="+winleft+",top="+wintop+",status=yes");
}*/

function launch_popup(site, winwidth, winheight) { //v2.0

	winleft = (screen.width / 2) - (winwidth / 2);
	wintop = (screen.height / 2) - (winheight / 2) - 20;

	return window.open(site, "", "width="+winwidth+",height="+winheight+",resizable=no,scrollbars=no,left="+winleft+",top="+wintop+",status=no");
}

function scroll_popup(site, winwidth, winheight, scroll) {

	winleft = (screen.width / 2) - (winwidth / 2);
	wintop = (screen.height / 2) - (winheight / 2) - 20;

	window.open(site, "", "width="+winwidth+",height="+winheight+",resizable=no,scrollbars="+scroll+",left="+winleft+",top="+wintop+",status=yes");
}

function absolute_popup(site, winwidth, winheight) {

	winleft = (screen.width / 2) - (winwidth / 2);
	wintop = (screen.height / 2) - (winheight / 2) - 20;

	window.open(site, "", "width="+winwidth+",height="+winheight+",resizable=no,scrollbars=no,left="+winleft+",top="+wintop+",status=yes");
}

/* POST ID'S TO A POPUP WINDOW */

function get_cat_id() {
	var value = null;
	var radioButtonOrGroup = document.forms[0].catId;
	
	if (radioButtonOrGroup.length) {
		for (var b = 0; b < radioButtonOrGroup.length; b++)
			if (radioButtonOrGroup[b].checked)
				value = radioButtonOrGroup[b].value;
	}
	else if (radioButtonOrGroup.checked) {
		value = radioButtonOrGroup.value;
	}

	return value;
}

function get_art_id() {
	var value = null;
	var radioButtonOrGroup = document.forms[0].qstId;
	
	if (radioButtonOrGroup.length) {
		for (var b = 0; b < radioButtonOrGroup.length; b++)
			if (radioButtonOrGroup[b].checked)
				value = radioButtonOrGroup[b].value;
	}
	else if (radioButtonOrGroup.checked) {
		value = radioButtonOrGroup.value;
	}
	
	return value;
}

function get_usr_id() {
	var value = null;
	var radioButtonOrGroup = document.forms[0].usrId;
	
	if (radioButtonOrGroup.length) {
		for (var b = 0; b < radioButtonOrGroup.length; b++)
			if (radioButtonOrGroup[b].checked)
				value = radioButtonOrGroup[b].value;
	}
	else if (radioButtonOrGroup.checked) {
		value = radioButtonOrGroup.value;
	}
	
	return value;
}

function get_att_id() {
	var value = null;
	var radioButtonOrGroup = document.forms[0].files;
	
	if (radioButtonOrGroup.length) {
		for (var b = 0; b < radioButtonOrGroup.length; b++)
			if (radioButtonOrGroup[b].checked)
				value = radioButtonOrGroup[b].value;
	}
	else if (radioButtonOrGroup.checked) {
		value = radioButtonOrGroup.value;
	}

	return value;
}

function get_com_id() {
	var value = null;
	var radioButtonOrGroup = document.forms[0].comm;
	
	if (radioButtonOrGroup.length) {
		for (var b = 0; b < radioButtonOrGroup.length; b++)
			if (radioButtonOrGroup[b].checked)
				value = radioButtonOrGroup[b].value;
	}
	else if (radioButtonOrGroup.checked) {
		value = radioButtonOrGroup.value;
	}

	return value;
}

function get_card_id() {
	var value = null;
	var radioButtonOrGroup = document.forms[0].card;
	
	if (radioButtonOrGroup.length) {
		for (var b = 0; b < radioButtonOrGroup.length; b++)
			if (radioButtonOrGroup[b].checked)
				value = radioButtonOrGroup[b].value;
	}
	else if (radioButtonOrGroup.checked) {
		value = radioButtonOrGroup.value;
	}

	return value;
}

function get_delsendcard_id() {
	var value = null;
	var radioButtonOrGroup = document.forms[0].delsendcards;
	
	if (radioButtonOrGroup.length) {
		for (var b = 0; b < radioButtonOrGroup.length; b++)
			if (radioButtonOrGroup[b].checked)
				value = radioButtonOrGroup[b].value;
	}
	else if (radioButtonOrGroup.checked) {
		value = radioButtonOrGroup.value;
	}

	return value;
}

/* CHECK FOR INPUT FIELDS */

function checkform () {
	
	var theForm = document.forms[0];
	var Valid = true;

	for(i=0; i<theForm.elements.length; i++)
	{
		
		if(theForm.elements[i].type == "text" || theForm.elements[i].type == "textarea" || theForm.elements[i].type == "button")
		{
			if ( theForm.elements[i].value == "" )
			{
				alert('Please fill in the required fields.');
				return false;
			}
		}
	}
   	
	if (!Valid) {
	  	alert("Please fill in the required fields.");
	  	return false;
   	}
   	else {
	  	document.forms[0].submit();
   	}
}

/* IMAGE BUTTON FOOTER */

function image_off(imgName) {
	if (document.images)
		this.document[imgName].src= eval(imgName + "1.src");
}
function image_on(imgName) {
	if (document.images)
		this.document[imgName].src= eval(imgName + "2.src");
}

if (document.images) {
	image11= new Image();
	image11.src= "../../images/GIF/home_off_32.gif";
	image12= new Image();
	image12.src= "../../images/GIF/home_32.gif";
  
	image21= new Image();
	image21.src= "../../images/GIF/prefs_off_32.gif";
	image22= new Image();
	image22.src= "../../images/GIF/prefs_32.gif";
  
	image31= new Image();
	image31.src= "../../images/GIF/mail_off_32.gif";
	image32= new Image();
	image32.src= "../../images/GIF/mail_32.gif";
}

/* EXPAND TABLES */

var NS = ((navigator.appName.indexOf("Netscape")>(-1))?true:false);

var old_layer_id = null;
var close_old_layer_on_newlayer = true;
function expand_activity(layer_id)
{
	var active_layer_tr = fetch(layer_id+"x1");
	var active_layer_img = fetch(layer_id+"x2");
	var active_layer_var_td = fetch(layer_id+"x3");
	var active_layer_expantion = fetch(layer_id+"x4");
	
	if (active_layer_tr.className == "primary")
	{
		if (close_old_layer_on_newlayer && (old_layer_id != null) &&
				old_layer_id != layer_id)
			expand_activity(old_layer_id);
		active_layer_tr.className = "secondary";
		active_layer_var_td.className = "secondary";
		active_layer_img.src = "/images/GIF/play_down_16.gif";
		active_layer_expantion.className = "";
		old_layer_id = layer_id;
	}
	else
	{
		if (old_layer_id == layer_id)
		{
			old_layer_id = null;
		}
			
		active_layer_tr.className = "primary";
		active_layer_var_td.className = "primary";
		active_layer_img.src = "/images/GIF/play_16.gif";
		active_layer_expantion.className = "layer_invisible";
	}				
	ns_redraw(0);
}

function ns_redraw(operation)
{
	if (!NS)
		return false; /* IE already redrawed it's stuff */
	if (operation == 0)
	{
		/* Netscape needs a slight pauze.. redrawing
		   immediately won't redraw the iframe.. (lame) */
		setTimeout('ns_redraw(1);', 100); 
	}
	else if (operation == 1)
	{
		/* netscape doesn't redraw it's elements */	
		var main_table = fetch("main_table");
		main_table.style.display = "none";
		main_table.style.display = "block";
	}
}

/* DISABLE RIGHT CLICKING AND SELECT */
/*
function document.oncontextmenu()
{
	var s = event.srcElement.tagName;

	if (s && s != "INPUT" && s != "TEXTAREA" || event.srcElement.disabled || document.selection.createRange().text.length == 0)
	{
		//event.returnValue = false;
	}
}

function document.onselectstart()
{
	var s = event.srcElement.tagName;
	//if (s != "INPUT" && s != "TEXTAREA") event.returnValue = false;
}

function document.ondragstart()
{
	//event.returnValue = false;
}
*/
/* POP-UP AT THE BEGINNING */

function pop_up(url)
{
	winwidth = 800;  winheight = 600; 
	winleft = (screen.width / 2) - (winwidth / 2);
	wintop = (screen.height / 2) - (winheight / 2) - 20;
	
	//return window.showModalDialog("./popup/index.php?operation="+operation+"&id="+activity_id, "popup", "dialogWidth:" + winwidth + "px;dialogHeight:" + winheight + "px;help:0;status:0;scroll:0;center:1");
	pret = window.open(url, "", 
		'width='+winwidth+',height='+winheight+',resizable=no,scrollbars=no,left='+winleft+
		',top='+wintop);
	pret.focus();
}

function popup_get_id(site, get_id, winwidth, winheight) {
	winleft = (screen.width / 2) - (winwidth / 2);
	wintop = (screen.height / 2) - (winheight / 2) - 20;

	window.open(site+""+get_id, "", "width="+winwidth+",height="+winheight+",resizable=no,scrollbars=no,left="+winleft+",top="+wintop+",status=yes");
}


var huisnummer_element;
var postcode_element;

var huisnummer_onblur_org;
var postcode_onblur_org;

var i = 0;

function checkLand(elm)
{
	huisnummer_element	= elm.form.elements.huisnummer;
	postcode_element	= elm.form.elements.postcode;
	i++;
	
	if (i == 1) {
		huisnummer_onblur_org 	= huisnummer_element.onblur;
		postcode_onblur_org 	= postcode_element.onblur;
	}
		
	if (elm.value != 148)
	{
		elm.form.elements.plaats.disabled = false;
		elm.form.elements.adres.disabled = false;
		postcode_element.onblur = "void(0);";
		huisnummer_element.onblur = "void(0);";
//		alert(elm.form.elements.huisnummer.onblur);
	}
	else
	{
		elm.form.elements.plaats.disabled = true;
		elm.form.elements.adres.disabled = true;
		
		CheckAddressElement(this, document.formulier.postcode);	
		
		try {		
				postcode_element.onblur = postcode_onblur_org;
				huisnummer_element.onblur = huisnummer_onblur_org;
		}
		catch (e) {
			//lekker niks
			//alert(e);
		}

//Oud	
//		postcode_element.onblur = FormatPostCode(elm.form.elements.postcode.value, elm.form.elements.postcode); CheckAddressElement(elm.form.elements.postcode, elm.form.elements.huisnummer);
//		huisnummer_element.onblur = "doSetOnblutHuisnummer()";	
//		alert('setting burdingesen');
	}
	
//	alert(elm.value);
}

function doSetOnblutHuisnummer()
{
	
}


function getXmlHttpObject() {
    try {
        var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(ex) {
        try {
            var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(except) {
            var xmlhttp = false;
        }
    }

    // We haven't got an object yet, try for some 'real' support
    if(!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        var xmlhttp = new XMLHttpRequest( );
    }

    return xmlhttp;
}

function addDiscount()
{
	var xmlhttp = getXmlHttpObject();
	 
	try {
		if (xmlhttp) {
			xmlhttp.onreadystatechange = function anonymous() {
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    var responseText = xmlhttp.responseText;

                    var kortingObj 			 = document.getElementById('korting');
					var basisObj 			 = document.getElementById('basis');
					var totaalexObj 		 = document.getElementById('totaalex');
					var btwnlObj			 = document.getElementById('btwnl');
					var btwObj		 		 = document.getElementById('btw');
					var totaalincObj	   	 = document.getElementById('totaalinc');

					if (responseText == "true") {
                    	var korting = 10;
					}else{
						var korting = 0;
					}
					
					var basis				 = basisObj.innerHTML;
					var totaalex 			 = (basis * (100 - korting))/100;
					var btwnl				 = btwnlObj.innerHTML;
					var btw					 = (totaalex * btwnl)/100;
					var totaalinc			 = totaalex + btw;
					
					kortingObj.innerHTML 	 = korting.toFixed(0);
					//basisObj.innerHTML	 = basis.toFixed(2);
					totaalexObj.innerHTML	 = totaalex.toFixed(2);
					//btwnlObj.innerHTML	 = btwnl.toFixed(2);
					btwObj.innerHTML		 = btw.toFixed(2);
					totaalincObj.innerHTML	 = totaalinc.toFixed(2);
				}
            }
            var jobworker = document.getElementById('jobworker');     
            xmlhttp.open("GET", "jobworker.php?id="+jobworker.value, true);
			xmlhttp.send(null);
		}
	} catch(ex) {
		alert(ex);
	}
}

function addDiscountStatic()
{
	var kortingObj 			 = document.getElementById('korting');
	var basisObj 			 = document.getElementById('basis');
	var totaalexObj 		 = document.getElementById('totaalex');
	var btwnlObj			 = document.getElementById('btwnl');
	var btwObj		 		 = document.getElementById('btw');
	var totaalincObj	   	 = document.getElementById('totaalinc');

   	var korting 			 = 10;
	var basis				 = basisObj.innerHTML;
	var totaalex 			 = (basis * (100 - korting))/100;
	var btwnl				 = btwnlObj.innerHTML;
	var btw					 = (totaalex * btwnl)/100;
	var totaalinc			 = totaalex + btw;
	
	kortingObj.innerHTML 	 = korting.toFixed(0);
	//basisObj.innerHTML	 = basis.toFixed(2);
	totaalexObj.innerHTML	 = totaalex.toFixed(2);
	//btwnlObj.innerHTML	 = btwnl.toFixed(2);
	btwObj.innerHTML		 = btw.toFixed(2);
	totaalincObj.innerHTML	 = totaalinc.toFixed(2);
}