//default configs that can be altered in $jsFoot
//here for alternative styles
config["body_backgroundColor"] = 'ffffff';
config["STYLE_shadowColor"] = 'f0f0f0';
//--------------------------------------
//for mousePos with js popUps
thisFileTopOffSet = 0;
thisFileLeftOffSet = 0;

function setOffSet(){
	//only ie
	thisFileTopOffSet = document.body.scrollTop;
	thisFileLeftOffSet = document.body.scrollLeft;
}


if( window.captureEvents ){
	window.captureEvents(Event.CLICK|Event.MOUSEOVER|Event.MOUSEOUT);
	window.onclick = getMouseHandler;
	window.onmouseover = getMouseHandler;
	window.onmouseout = getMouseHandler;
	window.event = new Object;
}

function getMouseHandler(e)
{
	window.event.clientX 	= e.pageX;
	window.event.clientY 	= e.pageY;
	window.event.x 			= e.layerX;
	window.event.y			= e.layerY;
	window.event.screenX 	= e.screenX;
	window.event.screenY 	= e.screenY;
	if ( routeEvent(e) == false ) {
		return false;
	} else {
		return true;
	}
}

function spacer(w,h,f,e)
{
	var img = '<img src="';
	img += CORE_IMAGES;
	img += (f)? f:'blind';
	img += '.gif" ';
	img += 'width="';
	img += (w)? w:1;
	img += '" height="';
	img += (h)? h:1;
	img += '" border="0" ';
	if( e ) img += e;
	img += '/>';
	return img;
}

function popUpLayer( id, a, popUp_x, popUp_y, popUp_toLeft )
{
	var popUp,out,out_x,out_y,visb;

	popUp = 'popUp'+id;
	out = 'out'+id;
	popUp = document.getElementById(popUp);
	out = document.getElementById(out);

	if( popUp_toLeft ){
		//use this if left orientation to mouse is needed
		popUp_x = window.event.x;
		popUp_x -= popUp_toLeft;
		popUp_x += thisFileLeftOffSet;
		popUp_x += POPUP_OFFSET_X;//i suspect this should not be here
	}else if( (!popUp_x && popUp_x != 0) || popUp_x == '' ){
		popUp_x = window.event.x - POPUP_OFFSET_X + thisFileLeftOffSet;
	}

	if( (!popUp_y && popUp_y != 0) || popUp_y == '' ){
		popUp_y = window.event.y - POPUP_OFFSET_Y + thisFileTopOffSet;
	}
	if( popUp_x < POPUP_MIN_XY ) popUp_x = POPUP_MIN_XY;
	if( popUp_y < POPUP_MIN_XY ) popUp_y = POPUP_MIN_XY;
	//here also at some stage, checks within window frame
	out_x = popUp_x - OUT_OVERLAP;
	out_y = popUp_y - OUT_OVERLAP;
	popUp.style.left = popUp_x ;
	popUp.style.top = popUp_y ;
	out.style.left = out_x ;
	out.style.top = out_y ;
	if( a ){

		visb = "visible";
	}else{
		visb = "hidden";
	}
	popUp.style.visibility = visb;
	out.style.visibility = visb;
}

function goPage(val,pre,target)
{
	if(val){
		if(!pre) pre=false;
		switch(pre){
			case false:
				pre = FULLURL;
			break;
			case "/":
				pre = ADDR;
			break;
			default:
				pre = ADDR + "/" + pre;
			break;
		}

		if(val != 'FORCE_GOPAGE'){
			val = "/" + val;
		}else{
			val = "";
		}

		if( !target ){
			target = document;
		}else if( target == 'top' ){
			target = top;
		}else if( target == 'parent' ){
			target = parent;
		}else{
			target = parent.frames[target];
		}
		target.location.href = pre + val;
	}
}

var newW = false;
function newWin(url,W,H,S,L,T)
{
	if(newW){
		newW.close();
	}
	if(!W){
		W=450;
	}
	if(!H){
		H=400;
	}
	if(!S)S="yes";
	if(!L){
		L = Math.floor((screen.availWidth - W)/1.5);
	}
	if(!T){
		T = Math.floor((screen.availHeight - H)/5);
	}
	//location=yes,
	newW = window.open(url,"newW","scrollbars="+S+",status=no,resizable=yes,width="+W+",height="+H+",left="+L+",top="+T);
	newW.focus();
}

newImgW = false;
function viewImgWindow(url,W,H,S,L,T,maxW,maxH)
{
	if(newImgW){
		newImgW.close();
	}
	if( !maxW ){
		maxW = config["maxViewImgWinW"];
	}
	if( !maxH ){
		maxH = config["maxViewImgWinH"];
	}
	if(!W){
		W=200;
	}
	if(!H){
		H=200;
	}
	if( W > maxW ){
		W = maxW;
		L = false;//this should then by dynamic
	}
	if( H > maxH ){
		H = maxH;
	}
	if(!S)S="no";
	if(!L){
		( W < screen.availWidth )? L = Math.floor((screen.availWidth - W)/1.5) : L = 0;
	}
	if(!T){
		( H < screen.availHeight )? T = Math.floor((screen.availHeight - H)/5) : T = 0;
	}
	//location=yes,
	newImgW = window.open(url,"newImgW","scrollbars="+S+",status=no,resizable=yes,width="+W+",height="+H+",left="+L+",top="+T);
	newImgW.focus();
}



var uploadW = false;
function uploadWin(url,W,H)
{
	var uploadInProgress = ( document.cookie.search(/uploadInProgress=1/) == -1 )? false : true;
	var goW = true;
	if( uploadInProgress ){//here cookie check
		goW = confirm('Es werden derzeit noch Medien hochgeladen.\nSoll der Hochlade-Vorgang beendet werden?');
		if( goW ){
			if(uploadW)uploadW.close();
			if( document.cookie.search(/uploadInProgress=1/) == -1 ){
				//delete cookie. although it should already have been deleted as uploadW closed
				C = "uploadInProgress=1";
				D = new Date();
				D.setTime( D.getTime() + (-5 * 24 * 60 * 60 * 1000) );
				C += "; expires=" + D.toGMTString();
				C += "; path=/";
				C += "; domain=" + document.domain;
				C += "; 0";
				document.cookie = C;
			}
		}else{
			uploadW.focus();
		}
	}
	if( goW ){
		url += '/_uploadReset';
		if(!W) W = config['uploadWinW'];
		if(!H) H = config['uploadWinH'];
		S="yes";
		L = ( W < screen.availWidth )? Math.floor((screen.availWidth - W)/1.5) : 0;
		T = ( H < screen.availHeight )?  Math.floor((screen.availHeight - H)/5) : 0;
		uploadW = window.open(url,"uploadW","scrollbars="+S+",status=no,resizable=yes,width="+W+",height="+H+",left="+L+",top="+T);
		uploadW.focus();
	}
}

function faqWin(faq,W,H)
{
	url = CORE_ADDR + '/faq';
	if( faq ){
		url += '#' + faq;
	}
	if(!W) W = config['faqWinW'];
	if(!H) H = config['faqWinH'];
	S = 'yes';
	newWin(url,W,H,S);
}

function faqPopUpWin(qid,vars,W,H)
{
	url = CORE_ADDR + '/faq/popUp/QID_' + qid;
	if( vars ){
		url += '/' + vars;
	}

	if(!W) W = config['faqPopUpWinW'];
	if(!H) H = config['faqPopUpWinH'];
	S = 'yes';
	newWin(url,W,H,S);
}

function termsWin(url,W,H)
{
	if(!W) W = config['termsWinW'];
	if(!H) H = config['termsWinH'];
	S = 'yes';
	newWin(url,W,H,S);
}

editW = false;
function editWin(url,W,H)
{
	if(!W) W = config['editWinW'];
	if(!H) H = config['editWinH'];
	S="yes";
	L = ( W < screen.availWidth )? Math.floor((screen.availWidth - W)/1.5) : 0;

	T = ( H < screen.availHeight )?  Math.floor((screen.availHeight - H)/5) : 0;
	editW = window.open(url,"editW","scrollbars="+S+",status=no,resizable=yes,width="+W+",height="+H+",left="+L+",top="+T);
	editW.focus();
}

function editWinFromUpload(url)
{
	myLocation = document.location.href;
	if( myLocation.search(/\/album-(editSet|assign)\//) != -1 ){
		top.location.href = url;
		return true;
	}else{
		editWin(url);
		return false;
	}
}

blankW = false;
function blankWin(url)
//used for pseudo extern links
{
	W = screen.availWidth - 100;
	H = screen.availHeight - 150;
	S="yes";
	L = ( W < screen.availWidth )? Math.floor((screen.availWidth - W)/1.5) : 0;
	T = ( H < screen.availHeight )?  Math.floor((screen.availHeight - H)/15) : 0;
	blankW = window.open(url,"blankW","toolbar=yes,menubar=yes,location=yes,scrollbars=yes,status=yes,resizable=yes,width="+W+",height="+H+",left="+L+",top="+T);
	blankW.focus();
}

function closeNewWin()
{
	if(newW){
		newW.close();
	}
	if(newImgW){
		newImgW.close();
	}
}

function cleanFileName(_this)
{
	var val = _this.value;
	var typ = _this.value.search(/\.[a-z]+$/i);
	if( typ != -1 ){
		typ = _this.value.slice(typ,_this.value.length);
	}else{
		typ = '';
	}
	val = val.replace(/\.[a-z]+$/i, "");
	val = val.replace(/\s/g, "_");
	val = val.replace(/[^a-z0-9_-]/gi, "");
	_this.value = val + typ;
}

function toogleClass(cls,id)
{
	if( !id ) id = cls;
	var a = document.getElementById(id).className;
	a = a.slice( a.length - 1 );
	a = ( a == 0 )? 1 : 0;
	document.getElementById(id).className = cls + a;
	return a;
}

toogleDisplayArr = new Array();
toogleDisplayArr['default'] = new Array('schließen (-)','öffnen (+)');
toogleDisplayArr['mini'] = new Array('(-)','(+)');
//add txtKey to toogleDisplayArr dynamically as required
function toogleDisplay(id,txtKey)
{
	var g = document.getElementById(id).style;
	if( document.getElementById(id+'Button') ){
		var b = document.getElementById(id+'Button');
	}else{
		var b = false;
	}
	if( !txtKey ){
		txtKey = 'default';
	}
	if( g.display == 'none' ){
		g.display  = 'block';
		if( b )b.innerHTML = toogleDisplayArr[txtKey][0];
	}else{
		g.display  = 'none';
		if( b )b.innerHTML = toogleDisplayArr[txtKey][1];
	}
}

function hoverIcon(a,id,cls,fileName,dir)
{
	if( document.getElementById(id) ){
		document.getElementById(id).className = cls + a;
	}
	if( fileName && document.images['n'+id] ){
		fileName = 'icons/' + fileName + a + '.gif';
		if( !dir ) dir = CORE_IMAGES;
		document.images['n'+id].src = dir + fileName;
	}
}

function hoverClass(a,cls,id)
{
	if( !id ) id = cls;
	document.getElementById(id).className = cls + a;
}

function hoverButton(a,name,fileName,typ)
{
	if( !fileName )fileName = name;
	if( !typ ){
		typ = '.gif';
	}else if( typ == 'NO_EXTENTION' ){
		typ = '';
	}
	var filePath = fileName + a + typ;
	document.images[name].src = CORE_IMAGES + filePath;
}

function pleaseWait(id,msg)
{
	if(!id) id = "submitButton";
	if(!msg) msg = '<div class="pleaseWait">Bitte warten...</div>';
	document.getElementById(id).innerHTML = msg;
}

function doSubmit(p)
{
	if( p.onSubmitHandler() ){
		p.F.submit();
	}
}

function setEvalPref(_this,linkTable,pref)
{
	if( _this.checked ){

		for(i=0; i < EvalPrefArr[linkTable].length; i++){
			n = "eP_" + linkTable + "_" + EvalPrefArr[linkTable][i];
			n = document.getElementById(n);
			if( n ){//needed when end levels not offered as option(s)
				if( EvalPrefArr[linkTable][i] == _this.value ){
					n.checked = true;
				}else{
					n.checked = false;
				}
			}
		}
	}else{
		_this.checked = true;// ie cannot uncheck since quasi radioButton
	}
}
