// (c) copyright 2001 VALSPLAT buro voor interactie [ scripting@valsplat.nl ]

	w = window;
	d = document;


	// someone else tries to open the site in a frame: escape!
	if(window != window.parent) window.parent.location = self.location;


	browser = navigator.appName;
	version = parseInt(navigator.appVersion);

	ie = "Microsoft Internet Explorer";
	nn = "Netscape";

	function removeFocus() { 
		for (a in document.links) document.links[a].onfocus = document.links[a].blur;
	}

	if(document.all) document.onmousedown = removeFocus;

	if (browser == ie && version >= 4) {
		document.oncontextmenu 	= function () {
						return false;
					  }
	}

	else if (browser == nn && version == 4) {
		document.captureEvents(Event.MOUSEDOWN);
		document.onmousedown = function (evt) {
						if (evt.which == 3) return false;
				       }
	}

	else if (browser == nn && version == 6) {
		document.onmouseup = function (evt) {
						if (evt.button == 3) event.preventDefault();
				     }
	}







	function myPopup(file,myWindow,width,height,specs) {
		if(height == null) 	height=600;
		if(width == null)	width=500;
		aWindow = open(file,myWindow,'resizable=no,width='+width+',height='+height+','+specs);
		if(aWindow.opener == null) aWindow.opener = self;
		aWindow.focus();
	}

	
	function confirmAction(question,url) {
		if(window.confirm(question)) d.location.href = url;
	}


	function show(objID) {
		if (d.all) {object = eval(objID + '.style') }
		if (d.layers) {object = eval('document.' + objID) }
		object.display = 'block';
	}


	function hide(objID) {
		if (d.all) {object = eval(objID + '.style') }
		if (d.layers) {object = eval('document.' + objID) }
		object.display = 'none';
	}


	function swapImg(img,newsrc) {
		if (d.images[img] && (d.images[img].src.indexOf(newsrc.substring(2,newsrc.length)) == -1 )) {
			d.images[img].src = newsrc;
		}
	}


	function doExpandCollapse(objID) {
		img	= 'img' + objID;
		expand 	= true;
		if (d.images[img].src.indexOf('icon_min.gif') > -1) {expand = false };
		if (expand) {
			newsrc	= d.images[img].src.replace(/add.gif/i,'min.gif');
			swapImg(img,newsrc);
			show(objID);
		} else {
			newsrc	= d.images[img].src.replace(/min.gif/i,'add.gif');
			swapImg(img,newsrc);
			hide(objID);
		}
	}


	bgcolorcache = [];
	function highlight(objID,colorCode,offset) {

		if(d.all) {
			objects = eval(objID + '.cells');
			for(i=offset;i<objects.length;i++) {
				bgcolorcache[i] = objects(i).style.backgroundColor;
				objects(i).style.backgroundColor=colorCode;
			}
		}
	}

	function lowlight(objID,offset) {

		if(d.all) {
			objects = eval(objID + '.cells');
			for(i=offset;i<objects.length;i++) {
				objects(i).style.backgroundColor = bgcolorcache[i];
			}
		}
	}



	function number_format(number,decimals,dec_point,thousands_sep) {

		if(number != '') {
			if(number.indexOf(dec_point)>-1) {
				thousandNums 	= number.substr(0,number.indexOf(dec_point));
				decimalNums	= number.substring(number.indexOf(dec_point)+1,number.length);

				decimalNums	= replace(decimalNums,dec_point,'');
				decimalNums	= decimalNums.substr(0,decimals);
				while(decimalNums.length < decimals) decimalNums += '0';

				thousandNums	= replace(thousandNums,thousands_sep,'');
				thousandNums	= seperateThousands(thousandNums,thousands_sep);
			} else {
				thousandNums	= number;
				thousandNums	= replace(thousandNums,thousands_sep,'');
				thousandNums	= seperateThousands(thousandNums,thousands_sep);

				decimalNums	= '';
				while(decimalNums.length < decimals) decimalNums += '0';
			}

			if(thousandNums=='') thousandNums = '0';

			if(decimals==0) dec_point='';
			result 		= thousandNums + dec_point + decimalNums;

			return result;
		} else return number;
	}

	function seperateThousands(thousandNums,thousands_sep) {

		result = '';
		while(thousandNums.length > 3) {

			thousandGroup	= thousandNums.substr(thousandNums.length-3,3);
			thousandNums	= thousandNums.substr(0,thousandNums.length-3);
			if(thousandNums =='-') {
				result 	= thousandGroup + result;
				break;
			}
			result = thousands_sep + thousandGroup + result;
			
		}
		result = thousandNums + result;
		return result;
	}


	function replace(string,text,by) {
		// Replaces text with by in string
		var strLength = string.length, txtLength = text.length;
		if ((strLength == 0) || (txtLength == 0)) return string;

		var i = string.indexOf(text);
		if ((!i) && (text != string.substring(0,txtLength))) return string;
		if (i == -1) return string;

		var newstr = string.substring(0,i) + by;

		if (i+txtLength < strLength)
		newstr += replace(string.substring(i+txtLength,strLength),text,by);

		return newstr;
	}

	function numField(e,dec_point) {

		var codes 	= [ 35,36,37,39,9,46,8,13,dec_point,45,48,49,50,51,52,53,54,55,56,57,109,189,96,97,98,99,100,101,102,103,104,105 ];

		dec_point 	= dec_point.charCodeAt(0);
		if(dec_point == 44) codes = codes.concat(188);
		if(dec_point == 46) codes = codes.concat(110,190);

		var key 	= e.keyCode;
		if(e.ctrlKey) codes = codes.concat(65,67,80,86,88);
		//alert(key);
		
		result		= false;
		for(i=0;i<codes.length && result==false;i++) {
			if(key == codes[i]) result = true;
		}
		return result;
	}

	function getMediaType(ext) {
		
		if(ext == '.png' || ext == '.gif' || ext == '.jpg') {
			var type = 'image';
		} else if(ext == '.mp3' || ext == '.wav' || ext == '.wma' || ext == '.rm' || ext =='.ram') {	
			var type = 'sound';
		} else {
			var type = 'file';
		}
		return type;
	}

	function mediaURLchanged(mediaNummer) {

		var media_url	= eval('document.form_node.media' + mediaNummer + '_url.value');
		var ext		= media_url.slice(media_url.lastIndexOf('.'));
		var media_img	= eval('document.media' + mediaNummer + '_image');

		switch(getMediaType(ext)) {
			case 'image':
				media_img.src = media_url;
				break;
			case 'sound':
				media_img.src = 'imgs/icon_sound_120x90.gif';
				break;
			case 'file':
				media_img.src = 'imgs/icon_file_120x90.gif';
				break;

		}
	}

	function previewImage(media_url) {

		var ext		= media_url.slice(media_url.lastIndexOf('.'));
		var media_img	= document.preview;

		switch(getMediaType(ext)) {
			case 'image':
				media_img.src = media_url;
				break;
			case 'sound':
				media_img.src = 'imgs/icon_sound_120x90w.gif';
				break;
			case 'file':
				media_img.src = 'imgs/icon_file_120x90w.gif';
				break;

		}

	}









		
