/*
;(C) picturemaxx AG, München, 2010
;------------------------------------------------------------------------
;$RCSfile: webgate.js,v $
;$Revision: 1.2 $
;$Author: mzelend $
;$Date: 2010/08/10 07:39:11 $
;$Info: main gui jscripts $
;------------------------------------------------------------------------
*/


/**
 * opens popup window
 * @param	string	theurl	url of document in popup window
 * @param	int		width	pixel width
 * @param	int		height	pixel height
 * @param	string	thename	window name
 * @return	void
 */
function openwindow(theurl, width, height, thename){
	var whl = window.open(theurl, thename, 'toolbar=no,width=' + width + ',height=' + height + ',directories=no,location=no,status=no,scrollbars=yes,resizable=yes,menubar=no');
	if(whl){
		// IE7/Vista returns null, @see http://msdn.microsoft.com/en-us/library/ms536651(VS.85).aspx
		whl.focus();
	}
}

/**
 * opens modal popup window
 * @param	string	theurl	url of document in popup window
 * @param	int		width	pixel width
 * @param	int		height	pixel height
 * @param	string	thename	window name
 * @return	void
 */
function openmodwindow(theurl, width, height, thename){
	openwindow(theurl, width, height, thename);
}

/**
 * opens popup window centered on screen
 * @param	string	theurl	url of document in popup window
 * @param	int		width	pixel width
 * @param	int		height	pixel height
 * @param	string	thename	window name
 * @return	void
 */
function opencenterwindow(theurl, width, height, thename){
    var screen_w = 800;
    var screen_h = 600;
    if(document.all || document.layers){
    	screen_w = screen.availWidth;
    	screen_h = screen.availHeight;
    }
    var leftPos = (screen_w - width) / 2;
    var topPos = (screen_h - height) / 2;
	var whl = window.open(theurl, thename, 'toolbar=no,width=' + width + ',height=' + height + ',directories=no,location=no,status=no,scrollbars=yes,resizable=yes,menubar=no,left=' + leftPos + '",top=' + topPos);
	if(whl){
		// IE7/Vista returns null, @see http://msdn.microsoft.com/en-us/library/ms536651(VS.85).aspx
		whl.focus();
	}
}
 
/**
 * close popup on form submit
 */
function submitclose(){
	document.frm.submit();
	window.setTimeout('closewindow()', 1000);
}

/**
 * close popup
 */
function closewindow(){
	window.close();
}

/**
 * show customer link target in parent window
 * @param	string	tmpurl	customer link url
 * @return	void
 */
function showCustomerLink(tmpurl){
	opener.parent.location.href = tmpurl;
}

/**
 * sets focus on button
 */
function focus_onsubmit(){
	document.frm.BUTTON.focus();
}

/**
 * @var	array	id => ressource html text
 */
var js_ressources = new Array();

/**
 * stores a new wg_ressource in the array
 * @param	string	id		ressource id
 * @param	string	text	ressource value
 * @return	void
 */
function storeres(id, text){
	js_ressources[id] = text;
}

/**
 * returns the html text for one ressource
 * @param	string	id	ressource id
 * @return	string	ressource value
 */
function getres(id){
	return js_ressources[id];
}

/**
 * changes the ressource with html id="htmlid" and replaces it with js_ressources[id]
 * @param	string	htmlid	html id attribute
 * @param	string	id		ressource id	
 * @return	void
 */
function modifyres(htmlid,id){
	if(js_ressources[id]) document.getElementById(htmlid).innerHTML = js_ressources[id];
}

/**
 * set new HTML content
 * @param	string	element_id	HTML id of element
 * @param	string	html		new content	
 * @return	void
 */
function setElementHTMLContent(element_id, html){
	var e = document.getElementById(element_id);
	if(e) e.innerHTML = html;
}

//image swapping functions
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
	var d=document;
 	if(d.images){
		if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
		for(i=0; i<a.length; i++){
    		if (a[i].indexOf("#")!=0){
				d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
			}
		}
	}
}
function MM_findObj(n, d) { //v4.01
	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=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments;
	document.MM_sr=new Array;
	for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null) {
		document.MM_sr[j++]=x;
		if(!x.oSrc) x.oSrc=x.src;
		x.src=a[i+2];
	}
}