function newurl(url) {
	
	document.location.href=url;

}

function newwindow(serverurl, request, title, width, height, posX, posY, location, menubar, toolbar, scrollbar, resize, status) {
/*	receives the following parameters:
	(mandatory) string server, string url 
	(optional)  [, string title, int width, int height, 
				int/string X position, int/string Y position,
				boolean location, boolean menubar, boolean toolbar, boolean scrollbar, 
				boolean resizable, boolean status ]
	(note : X position and Y position can be string center)
	
	! beware that IExplorer needs a title without any space
*/
	var x,y;
	var threshold = (document.all)? -100 : 200; //compensate menubar and toolbar in Mozilla
	if (self.screenX) {// all except Explorer, Safari, Opera
		x = self.screenX;
		y = self.screenY;
	} else if (self.screenLeft) { // all other	
		x = self.screenLeft;
		y = self.screenTop;
	}
	if(typeof(posX) == "string") {
		if(posX == "center") posX = x + (document.body.offsetWidth - ((width)? width : 800)) / 2;
		else posX = 800;
	}
	if(typeof(posY) == "string") {
		if(posY == "middle") posY = y + (document.body.offsetHeight - ((height)? height - threshold : 400)) / 2;
		else posY = 600;
	}
	
	var link = serverurl + '?window=new&' + request;		
	newWindow = window.open(link, ((title)? title : "detail"),"width=" + ((width)? width : 800) + ",height=" + ((height)? height : 600) + ",left=" + ((posX)? posX : 100) + ",top=" + ((posY)? posY : 100) + ",location=" + ((location)? location : "no") + ",menubar=" + ((menubar)? menubar : "no") + ",directories=no,toolbar=" + ((toolbar)? toolbar : "no") + ",scrollbars=" + ((scrollbar)? scrollbar : "yes") + ",resizable=" + ((resize)? resize : "yes") + ",status=" + ((status)? status : "no"), true);
	newWindow.focus();

} 

/**
 *	Modify specified get var in url and return new url name
 *
 * @return string modified url
 */
function changeUrl(url, name, value) {


	var getname = name + "=";
	var namelength = name.length;
	
	var pos=url.indexOf(getname);
	
	var ln_pos 	= url.indexOf('#');
	var ln 		= '';
	
	if (ln_pos > 0 ){

		ln	= url.substr(ln_pos, url.length);	
		url = url.substr(0, ln_pos);
		
	}
	
	
	var newurl='';
	
	if (pos>=0) {
	
		var before = url.substr(0, pos);
		var tmp  = url.substr(namelength+pos+1, url.length);
		
		var pos2 = tmp.indexOf('&');
		
		if (pos2 >= 0) {
		
			var after = url.substr(pos2+pos+namelength+1, url.length);
			
		} else {
		
			var after = '';
		}
		
		
		newurl = before + getname + value + after + ln;
		
	} else {

		
		var glue='?';
		if (url.indexOf('?') > 0) glue = '&';

		
		newurl = url + glue + getname + value + ln;
			
	}

	return newurl;

}

/**
 *	Set (or change) the specified get var in current url 
 *  and load resulting url
 */
function setGetVar(name, value) {

	document.location.href=changeUrl(document.location.href, name, value); 
	
}

function setLanguage(id_lang) {
	setGetVar('id_lang',id_lang); 
}

function gotoPage(id_page) {
	setGetVar('id_page', id_page);
}

function gotoURL(url) {
	document.location = url;
}

function setImage(id_image, id_c) {

	var id;	
	if (id_c) {
		id = 'id' + id_c;
	} else {
		//alert('setImage todo');
		//id = 'id' + id_c;
	}
	
	var obj = document.getElementById(id);
	
	if (obj) {
		var url = 'url(./requestMedia.php?id=' + id_image + ')';
		obj.style.backgroundImage = url;
	}
}

function showMedia(id_media, width, height) {
	if (width<10) width=800;
	if (height<10) height=600;
	
	var url = './requestMedia.php?id=' + id_media + '';
	window.open(url, 'showMedia', 'menubar=no,status=no,toolbar=no,resizable=yes,width='+width+",height="+height);
}

