function init()
{		
	var as, popfun;
	as=document.getElementsByTagName('a');
	for (var i=0; i<as.length; i++) {
		if(as[i].target && as[i].target=='popup') {
			var width = as[i].getAttribute('popwidth') ? as[i].getAttribute('popwidth') : 500;
			var height = as[i].getAttribute('popheight') ? as[i].getAttribute('popheight') : 440;
			var left = (screen.width - width) / 3;
			var top = (screen.height - height) / 3;
			var windowAttributes = 'width='+width+',height='+height+',left='+left+',top='+top+',scrollbars=yes,location=no,toolbar=no, resizable=yes';
			
			popfun=function(){
				var theWindow = window.open(this.href,this.target,windowAttributes);
				theWindow.focus();
				return false;
			}			
			as[i].onclick=popfun;
		}
	}
}

addEvent(window, "load", init);


function translate(language) {
	var url=location.href;
	
	if (url.indexOf('translate_c')) {
		// This page is already being translated, so get the 'u' querystring variable
		var qs=url.substring(url.indexOf('?')+1, url.length);
		var vars = qs.split("&");
		for (var i=0;i<vars.length;i++) {
			var pair = vars[i].split("=");
			if (pair[0]=='u') url=pair[1];
		}
	}
	
	if (language=='en') { 
		window.top.location.href=url;
	} else {
		window.top.location.href='http://translate.google.com/translate?u='+escape(url)+'&hl='+language+'&langpair=en|'+language+'&tbb=1';
	}
}

function addEvent(elm, evType, fn, useCapture) {
	// cross-browser event handling for IE5+, NS6 and Mozilla
	// By Scott Andrew
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	} else {
		elm['on' + evType] = fn;
	}}


function browseImages(target) {
  textbox = target;
  window.open('/admin/browsers/image.aspx', "imagebrowser", "menubar=no,width=700,height=500,toolbar=no,scrollbars=yes");
}

function browseFiles(target) {
  textbox = target;
  window.open('/admin/browsers/files.aspx', "imagebrowser", "menubar=no,width=700,height=500,toolbar=no,scrollbars=yes");
}


function SetUrl(url) {
  document.getElementById(textbox).val(url.substring(url.lastIndexOf('/') + 1));
}

function InsertDate(target) {
  var now = new Date();
  var date = ((now.getDate() < 10) ? "0" : "") + now.getDate();
  var month = ((now.getMonth() + 1 < 10) ? "0" : "") + (now.getMonth() + 1);
  var year = (now.getYear() < 1000) ? now.getYear() + 1900 : now.getYear();
  $(target).value = date + '/' + month + '/' + year;
}