var ie=document.all
var ns6=document.getElementById&&!document.all

function switchTabpage(tabId)
{
	if (tabId == 'tabPage1')
	{
		document.getElementById("tabPage2").style.display = "none";
		document.getElementById("tabPage3").style.display = "none";
		document.getElementById("tabPage1").style.display = "block";
		
		var newTab1Src = document.getElementById("tab_1").src.replace("1_0", "1_1");
		document.getElementById("tab_1").src = newTab1Src;
		
		var newTab2Src = document.getElementById("tab_2").src.replace("2_1", "2_0");
		document.getElementById("tab_2").src = newTab2Src;
		
		var newTab3Src = document.getElementById("tab_3").src.replace("3_1", "3_0");
		document.getElementById("tab_3").src = newTab3Src;
	}
	if (tabId == 'tabPage2')
	{
		document.getElementById("tabPage1").style.display = "none";
		document.getElementById("tabPage3").style.display = "none";
		document.getElementById("tabPage2").style.display = "block";
		
		var newTab1Src = document.getElementById("tab_1").src.replace("1_1", "1_0");
		document.getElementById("tab_1").src = newTab1Src;
		
		var newTab2Src = document.getElementById("tab_2").src.replace("2_0", "2_1");
		document.getElementById("tab_2").src = newTab2Src;
		
		var newTab3Src = document.getElementById("tab_3").src.replace("3_1", "3_0");
		document.getElementById("tab_3").src = newTab3Src;
		
	}
	if (tabId == 'tabPage3')
	{
		document.getElementById("tabPage1").style.display = "none";
		document.getElementById("tabPage2").style.display = "none";
		document.getElementById("tabPage3").style.display = "block";
		
		var newTab1Src = document.getElementById("tab_1").src.replace("1_1", "1_0");
		document.getElementById("tab_1").src = newTab1Src;
		
		var newTab2Src = document.getElementById("tab_2").src.replace("2_1", "2_0");
		document.getElementById("tab_2").src = newTab2Src;
		
		var newTab3Src = document.getElementById("tab_3").src.replace("3_0", "3_1");
		document.getElementById("tab_3").src = newTab3Src;
	}
}

function ietruebody()
{
	return (document.compatMode && document.compatMode!="BackCompat" && !window.opera) ? document.documentElement : document.body
}

function submitForm(formname,elementname,element_val)
{
	if (elementname)
	{
		document.forms[formname].elements[elementname].value = ''+element_val;
	}
	document.forms[formname].submit();
}

function msg_window(txt, action)
{
	if (confirm(txt)) 
	{
		eval(action);
		return true;
	}
	else
	{
		return false;
	}
}

function checkContentForm()
{
	if (document.adminForm.title.value.length > 0)
	{
		if (document.adminForm.body.value.length > 0)
		{
			document.adminForm.submit();
		}
		else
		{
			alert("Het veld 'Inhoud' is niet ingevuld.");
		}
	}
	else
	{
		alert("Het veld 'Titel' is niet ingevuld.");
	}
		
}

function enlarge(which, e, position, imgwidth, imgheight)
{
	if (ie||ns6)
	{
		crossobj=document.getElementById? document.getElementById("showimage") : document.all.showimage
		
		if (position=="center")
		{
			pgyoffset=ns6? parseInt(pageYOffset) : parseInt(ietruebody().scrollTop)
			horzpos=ns6? pageXOffset+window.innerWidth/2-imgwidth/2 : ietruebody().scrollLeft+ietruebody().clientWidth/2-imgwidth/2
			vertpos=ns6? pgyoffset+window.innerHeight/2-imgheight/2 : pgyoffset+ietruebody().clientHeight/2-imgheight/2
			
			if (window.opera && window.innerHeight) //compensate for Opera toolbar
			vertpos=pgyoffset+window.innerHeight/2-imgheight/2
			vertpos=Math.max(pgyoffset, vertpos)
		}
		else
		{
			var horzpos=ns6? pageXOffset+e.clientX : ietruebody().scrollLeft+event.clientX
			var vertpos=ns6? pageYOffset+e.clientY : ietruebody().scrollTop+event.clientY
		}

		crossobj.style.left=horzpos+"px"
		crossobj.style.top=vertpos+"px"
		crossobj.innerHTML='<div id="dragbar" style="min-width:' + imgwidth + '" align="right"><span id="closetext" class="content" onClick="closepreview()"><img src="../pit_engine_04/gfx/close_div.gif" width="14" height="14" alt=""></span></div><img src="'+which+'" style="border:solid 1px #CDD0D1;" onClick="closepreview()">'
		crossobj.style.visibility="visible"
		
		
		return false
	}
	else //if NOT IE 4+ or NS 6+, simply display image in full browser window
		return true
}

function get_cookie(Name) {
	var search = Name + "="
	var returnvalue = ""
	if (document.cookie.length > 0) {
	offset = document.cookie.indexOf(search)
	if (offset != -1) {
	offset += search.length
	end = document.cookie.indexOf(";", offset)
	if (end == -1)
	end = document.cookie.length;
	returnvalue=unescape(document.cookie.substring(offset, end))
	}
	}
	return returnvalue;
}

function moviePopup(which, e, position, imgwidth, imgheight)
{
	if (ie||ns6)
	{
		crossobj=document.getElementById? document.getElementById("showimage") : document.all.showimage
		
		if (position=="center")
		{
			pgyoffset=ns6? parseInt(pageYOffset) : parseInt(ietruebody().scrollTop)
			horzpos=ns6? pageXOffset+window.innerWidth/2-imgwidth/2 : ietruebody().scrollLeft+ietruebody().clientWidth/2-imgwidth/2
			vertpos=ns6? pgyoffset+window.innerHeight/2-imgheight/2 : pgyoffset+ietruebody().clientHeight/2-imgheight/2
			
			if (window.opera && window.innerHeight) //compensate for Opera toolbar
			vertpos=pgyoffset+window.innerHeight/2-imgheight/2
			vertpos=Math.max(pgyoffset, vertpos)
		}
		else
		{
			var horzpos=ns6? pageXOffset+e.clientX : ietruebody().scrollLeft+event.clientX
			var vertpos=ns6? pageYOffset+e.clientY : ietruebody().scrollTop+event.clientY
		}

		crossobj.style.left=horzpos+"px"
		crossobj.style.top=vertpos+"px"
		crossobj.innerHTML='<div id="dragbar" style="min-width:' + imgwidth + '" align="right"><span id="closetext" class="content" onClick="document.WinMedia.Stop();closepreview()"><img src="../pit_engine_04/gfx/close_div.gif" width="14" height="14" alt=""></span></div><OBJECT ID="WinMedia" standby="Loading Microsoft Windows Media Player compents..." TYPE="application/x-oleobject"><embed src="'+which+'" loop="false" width="320" height="240" autoStart="true" Controls="console" name="WinMedia" onClick="document.WinMedia.Stop();closepreview()"></OBJECT>'
		crossobj.style.visibility="visible"
		
		
		return false
	}
	else //if NOT IE 4+ or NS 6+, simply display image in full browser window
		return true
}

function setImageForRemove(image)
{
	if (document.getElementById(image + "_del").value == '')
	{
		document.getElementById(image + "_del").value = 'true';
		document.getElementById(image).style.visibility = 'visible';
	}
	else
	{
		document.getElementById(image).style.visibility = 'hidden';
		document.getElementById(image + "_del").value= '';
	}	
}

function aPop(url, width, height, scroll)
{
	if (!width) { var width = 756; }
	if (!height) { var height = 534; }
	if (!scroll) { var scroll = 0; }
	
	l= (screen.availWidth-10 - width) / 2;
  	t = (screen.availHeight-20 - height) / 2;

	features = "width="+width+",height="+height+",left="+l+",top="+t;
	features += ",screenX="+l+",screenY="+t;
	features += ",scrollbars="+scroll+",resizable=0,location=0";
	features += ",menubar=0,toolbar=0,status=1";
	
	aPopup = window.open(url,'aPopup', features);
}

function aPopProc(url)
{
	//alert(url);
	aPopup = window.open('','aPopup','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=yes,width=200,height=1');
	aPopup.document.write('<html><head><title>Processing...</title></head>');
	aPopup.document.write('processing...');
	aPopup.document.write('<iframe src="' + url + '"></iframe>');
	aPopup.document.write('</html>');
	//aPopup.document.close();
}


function closepreview()
{
	crossobj.style.visibility="hidden"
}

function drag_drop(e){
if (ie&&dragapproved){
crossobj.style.left=tempx+event.clientX-offsetx+"px"
crossobj.style.top=tempy+event.clientY-offsety+"px"
}
else if (ns6&&dragapproved){
crossobj.style.left=tempx+e.clientX-offsetx+"px"
crossobj.style.top=tempy+e.clientY-offsety+"px"
}
return false
}

function initializedrag(e){
if (ie&&event.srcElement.id=="dragbar"||ns6&&e.target.id=="dragbar"){
offsetx=ie? event.clientX : e.clientX
offsety=ie? event.clientY : e.clientY

tempx=parseInt(crossobj.style.left)
tempy=parseInt(crossobj.style.top)

dragapproved=true
document.onmousemove=drag_drop
}
}

document.onmousedown=initializedrag
document.onmouseup=new Function("dragapproved=false")
//

function swapImgRestore() {
	var i, x, a = document.sr;
	for ( i=0 ; a && i < a.length && ( x = a[i] ) && x.oSrc ; i++ ) x.src = x.oSrc;
}

function preloadImages() {
	var d=document;
	if (d.images){
		if(!d.p) d.p = new Array();
    var i, j=d.p.length, a=preloadImages.arguments;
		for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){
			d.p[j]=new Image; d.p[j++].src=a[i];
		}
	}
}

function findObj(n, d) {
  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=findObj(n,d.layers[i].document);
	return x;
}

function swapImage() {
	var i, j=0, x, a=swapImage.arguments;
	document.sr=new Array;
	
	for (i=0; i<(a.length-2); i+=3) 
	{
		if ((x=findObj(a[i]))!=null)
		{
			document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src;x.src=a[i+2];
		}
	}
}

function popup(g_src,g_title,g_width,g_height)
{
	enlarge(g_src,event);
}


function checkAll()
{
	if (document.form1.elements[0].checked == false)
	{
		var checkedornot = true;
	}
	else
	{
		var checkedornot = false;
	}
	
	for (i=0;i<document.form1.elements.length;i++)
	{
		document.form1.elements[i].checked = checkedornot;
	}
}

function checkAllBoxes(mode)
{
	if (mode == "on")
	{
		var checkedornot = true;
	}
	else
	{
		var checkedornot = false;
	}
	
	for (i=0;i<document.form1.elements.length;i++)
	{
		document.form1.elements[i].checked = checkedornot;
	}
}

function printWindow(url)
{
	window.open(url,'','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1','','');
}

function flashWindow(url,width,height)
{
	window.open(url,'flasxh','toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width='+width+',height='+height+',left=0,top=0');
}

function msg_window(txt, action)
{
	if (confirm(txt)) 
	{
		eval(action);
		return true;
	}
	else
	{
		return false;
	}
}

function newsletter_check_test()
{
	if (document.getElementById("test").checked !== true)
	{
		if (confirm('Weet u zeker dat u de nieuwsbrief wilt versturen?')) 
		{
			document.forms[0].submit();
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		document.forms[0].submit();
		return true;
	}
}

function gotoUrl(url){
	window.location=url
}

function moveSelect(fbox, tbox, sbox, aantal,numbox )//
{
		var seltel = 0;
		//thastring = fbox.name.substr(0, fbox.name.length-4)
		//hiddenField = document.getElementByName(thastring);
		sbox.value = '';
		numbox.value = '';
		
		for(i = 0; i < fbox.options.length; i++){if (fbox.options[i].selected){seltel++;}}
		if ((tbox.options.length + seltel) > aantal){alert('u mag er slechts ' + aantal + ' kiezen');}
		else { var arrFbox = new Array();var arrTbox = new Array();	var arrLookup = new Array();var i;
			for (i = 0; i < tbox.options.length; i++){arrLookup[tbox.options[i].text] = tbox.options[i].value;
				arrTbox[i] = tbox.options[i].text;
				}
			var fLength = 0;var tLength = arrTbox.length;
			for(i = 0; i < fbox.options.length; i++){arrLookup[fbox.options[i].text] = fbox.options[i].value;
				if (fbox.options[i].selected && fbox.options[i].value != ""){
					var naamoption = fbox.options[i].value;
					arrTbox[tLength] = fbox.options[i].text;tLength++;
				}
				else {
					arrFbox[fLength] = fbox.options[i].text;
					fLength++;
				}
			}
			/*arrFbox.sort();arrTbox.sort();*/fbox.length = 0;tbox.length = 0;
			for(c = 0; c < arrFbox.length; c++){
				if (arrFbox[c] != ''){
				var no = new Option();no.value = arrLookup[arrFbox[c]];no.text = arrFbox[c];
					if (aantal == 99999)
					{	
						//alert(arrFbox[c]);
						sbox.value = sbox.value + ',' + arrFbox[c];
						numbox.value = numbox.value + ',' + no.value;
					}
				fbox[c] = no;}}
				
			for(c = 0; c < arrTbox.length; c++){
				if (arrTbox[c] != '')
				{
					var no = new Option();
					no.value = arrLookup[arrTbox[c]];
					no.text = arrTbox[c];
					tbox[c] = no;
					if (aantal != 99999)
					{	
						//alert(arrTbox[c]);
						sbox.value = sbox.value + ',' + arrTbox[c];
						numbox.value = numbox.value + ',' + no.value;
					}
				}
			}
		}
		sbox.value = sbox.value.substr(1, sbox.value.length).replace(', ','&#44; ');
		//numbox.value = numbox.value.substr(1, numbox.value.length).replace(', ','&#44; ');
		//alert(sbox.value);
}

//------------------------------

var thumb;
var thumb_image;
var imagename = "";
var imagesize = 0;
var waitmsg = 'Please wait...';
var errmsg = 'Browser can\'t open local link.';
var basedir = ".";

function showImage(filename, imgname) 
{
    thumb_image = eval("document."+imgname);
	cleanImagePreview();
    if (filename != "")
    {
        imagename = 'file://' + filename;
        setTimeout('loadImage()', 100);
    }
    return false;
} 

function loadImage()
{
    thumb = new Image();
    thumb.src = imagename;
    checkLoad();
}

function checkLoad()
{
    if (thumb.complete) 
    {
        generateImage();
        return;
    }
    setTimeout('checkLoad()', 100);
}

function generateImage() 
{
    thumb_image.src = basedir + '/images/spacer.gif';
    
    if (thumb.width && thumb.height)
    {
        if (thumb.width > thumb.height)
        {
            thumb_image.width = 100;
            thumb_image.height = Math.round(100 * thumb.height / thumb.width);
        }
        else
        {
            thumb_image.width = Math.round(100 * thumb.width / thumb.height);
            thumb_image.height = 100;
        }

        thumb_image.src = thumb.src;
        
        filename = getFileName(imagename);
        
        if (imagesize) 
            filename = convertToKB(imagesize) + ' KB';
        else
            filename = '';
    }
    else
    {
        thumb_image.width = 100;
        thumb_image.height = 1;
    }
}

function cleanImagePreview() 
{
    thumb_image.src = basedir + "/images/spacer.gif";
    thumb_image.width = 100;
    thumb_image.height = 1;
}

function getFileName(path)
{
    var regex = /.*[\\\/]([^\\\/]*)/;

    regex.exec(path);
    return RegExp.$1;
}
