// in pixyfoto widely used javascript functions 

// some shortcuts; widely seen in the www
function $(v) { return(document.getElementById(v)); }
function $S(v) { return(document.getElementById(v).style); }
function absPos(e) { var r={x:e.offsetLeft,y:e.offsetTop}; if(e.offsetParent) { var v=absPos(e.offsetParent); r.x+=v.x; r.y+=v.y; } return(r); }
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function isset(v) { return((typeof(v)=='undefined' || v.length==0)?false:true); }
function toggle(i,t,xy) { var v=$S(i); v.display=t?t:(v.display=='none'?'block':'none'); if(xy) { v.top=xy[0]; v.left=xy[1]; } }
function XY(e,v) { var z=agent('msie')?Array(event.clientX+document.body.scrollLeft,event.clientY+document.body.scrollTop):Array(e.pageX,e.pageY); return(v==3?z:z[zero(v)]); }
function XYwin(v) { var z=agent('msie')?[document.body.clientHeight,document.body.clientWidth]:[window.innerHeight,window.innerWidth]; return(isNaN(v)?z:z[v]); }
function zero(v) { v=parseInt(v); return(isNaN(v)?0:v); }

// drag & drop
function PF_startDrag(d,e) {

  function PF_drag(e) { if(!stop) { d.style.top=(tX=XY(e,1)+oY-eY+'px'); d.style.left=(tY=XY(e)+oX-eX+'px'); } }

  var oX=parseInt(d.style.left+0),oY=parseInt(d.style.top+0),eX=XY(e),eY=XY(e,1),tX,tY,stop;
  document.onmousemove=PF_drag; document.onmouseup=function(){ stop=1; document.onmousemove=''; document.onmouseup=''; };

}

function PF_openBrWindow(theURL,winName,features) { //v2.0
	var mywin;
	try {
	  mywin = window.open(theURL,winName,features);
		mywin.focus();
	} catch(e) {
  	var message = "Das angeforderte Fenster konnte leider nicht ge%F6ffnet werden,\n";
  	message += "da bei Ihnen ein sog. PopUp-Blocker aktiv ist.\n\n";
  	message += "Einige Inhalte dieses Webauftritts werden allerdings ausschlie%DFlich\n";
  	message += "in solchen PopUp-Fenstern dargestellt:\n";
  	message += "- Einloggen und Registrieren\n";
  	message += "- Hilfeseiten, Impressum und weitere Informationsseiten\n";
  	message += "- Die Feinkonfiguration eines pixyfotobuches\n\n";
  	message += "Bitte lassen Sie f%FCr www.pixyfoto.de PopUps zu. Wir versichern Ihnen,\n";
  	message += "dass PopUps nur dann ge%F6ffnet werden, wenn es f%FCr Ihr Verst%E4ndnis\n";
  	message += "und das Funktionieren des Webauftritts notwendig ist.\n";
		alert(unescape(message));
		mywin = null;
	}
	return mywin;
}

function PF_switchAndClose(theURL,winName){
	PF_openBrWindow(theURL,winName,'menubar,toolbar,location,directories,status,scrollbars,resizable');
	self.close();
	return false;
}

function PF_closeWithDelay(){
	if ( !window.pf_closing_set ) {
		window.pf_closing_set = true;
		window.setTimeout(PF_closeWithDelay,500);
		return true;
	}
	window.pf_closing_set = false;
	window.close();
}

function PF_writeMailLink(addr1,addr2,display) {
	var start1 = "<a href=\"m";
	var start2 = "ailto:";
	var end1 = "\">";
	var end2 = "</a>";
	
	document.write(start1+start2+addr1+"@"+addr2+end1+display+end2);
}

function PF_createMail(addr1,addr2) {
	var start1 = "mai";
	var start2 = "lto:";
	
	location.href = start1+start2+addr1+"@"+addr2;
}

var fmwMsg = "Keine Nachricht vorhanden";
var fmwWidth = 200;
var fmwHeight = 70; 

function PF_winWidth() {
	if (window.innerWidth) {
		return window.innerWidth
	} else if (document.documentElement && document.documentElement.clientWidth) {
		return document.documentElement.clientWidth
	} else if (document.body) {
		return document.body.clientWidth
	}
	return 0;
}

function PF_winHeight() {
	if (window.innerHeight) {
		return window.innerHeight
	} else if (document.documentElement && document.documentElement.clientHeight) {
		return document.documentElement.clientHeight
	} else if (document.body) {
		return document.body.clientHeight
	}
  return 0;
}

function PF_showFloatingMsg(msg,msgWinWidth,msgWinHeight) {
	fmwMsg = msg;
	fmwWidth = msgWinWidth;
	fmwHeight = msgWinHeight;
	PF_showFloatingMsg2();
}

function PF_showFloatingMsg2() {
	var msgArea = (document.all ? document.all.floating_msg : document.getElementById("floating_msg"));
	if ( msgArea != null ) {
		var ww = PF_winWidth();
		var wh = PF_winHeight();
		var iebody = ( (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body );
		var dsocleft = ( document.all ? iebody.scrollLeft : window.pageXOffset );
		var dsoctop  = ( document.all ? iebody.scrollTop : window.pageYOffset );
		
		var xPos = Math.floor( (ww - fmwWidth) / 2 + 0.5 + dsocleft);
		var yPos = Math.floor( (wh - fmwHeight) / 2 + 0.5 + dsoctop );
		
		if ( xPos < 0 ) xPos = 0;
		if ( yPos < 0 ) yPos = 0;
		
		msgArea.style.left = xPos+"px";
		msgArea.style.top  = yPos+"px";
		msgArea.style.width  = fmwWidth+"px";
		msgArea.style.height  = fmwHeight+"px";
		msgArea.innerHTML = fmwMsg;
		
		msgArea.style.display  = "block";
		
		window.onresize = PF_showFloatingMsg2;
	}
}

function PF_showTooltip(obj,ttTitle,ttText,ttWidth,ttOffsetX,ttOffsetY) {
	// used in conjunction with wz_tooltip.js v. 3.38
	obj.T_BGCOLOR = '#f1f4fa';//'#86a6d5';
	obj.T_BORDERWIDTH = 1;
	obj.T_BORDERCOLOR = '#0053e1'; //'#666666';
	obj.T_DELAY = 250;
	obj.T_FONTFACE = 'Arial, Helvetica, sans-serif';
	obj.T_FONTSIZE = '11px';
	obj.T_FONTCOLOR = '#3f4b57'; //'#333333';
	obj.T_LEFT = true;
	obj.T_ABOVE = true;
	obj.T_PADDING = 5;
	obj.T_OFFSETX = ( ttOffsetX ? ttOffsetX : 10 );
	obj.T_OFFSETY = ( ttOffsetY ? ttOffsetY : 25 );
	obj.T_OPACITY = 100;
	obj.T_SHADOWCOLOR = '#808080'; //'#666666';
	obj.T_SHADOWWIDTH = 1; // 4;
	obj.T_STATIC = true;
	obj.T_STICKY = false;
	obj.T_TEXTALIGN = 'left';
	obj.T_TITLE = ttTitle;
	obj.T_TITLECOLOR = '#FFFFFF';
	obj.T_WIDTH = ttWidth;
		
	return ttText;
}

/*
 *	The following needs library to be included:
 *	<script type="text/javascript" src="static/opacityfunctions.js"></script>
 */

var PF_main_container = null;
var PF_help_container = null;

function PF_ShowHelp(mainContainer,helpContainer) {
	PF_main_container = mainContainer;
	PF_help_container = helpContainer;
	FadeOpacity(PF_main_container, 100, 0, 2000, 10);
	setTimeout("PF_fadeInHelp()",2000);
}
function PF_fadeInHelp() {
	var elem = document.getElementById(PF_main_container);
	elem.style.display = 'none';
	elem = document.getElementById(PF_help_container);
	elem.style.display = 'block';
	FadeOpacity(PF_help_container, 0, 100, 2000, 10);
}
function PF_restoreContent() {
	FadeOpacity(PF_help_container, 100, 0, 2000, 10);
	setTimeout("PF_fadeInMain()",2000);	
}
function PF_fadeInMain() {
	var elem = document.getElementById(PF_help_container);
	elem.style.display = 'none';
	elem = document.getElementById(PF_main_container);
	elem.style.display = 'block';
	FadeOpacity(PF_main_container, 0, 100, 2000, 10);
}

