/*
(C)2002-10 schlomania WebDesign / E-Mail: webdesign@schlomania.com
sWD-Utilities-Pack V4
REQUIREMENTS: sWD-Utilities-Base V3 (file: swdUtilsBase.js)
*/
var ShowDiv="visible", HideDiv="hidden";
if(isLayers) ShowDiv="show",HideDiv="hide";
function chgDiv(divName,divVisi,divX,divY,divIndex) { 
	var divObj;
	if(!divName) return;
	if(divVisi=="0") divVisi=HideDiv; 
	if(divVisi=="1") divVisi=ShowDiv;
	if(dom) divObj=document.getElementById(divName);
	else if(isAll) divObj=document.all[divName];
	else if(isLayers) (!document.layers[divName]) ? divObj=getLayerObj(divName) : divObj=document.layers[divName]; 
	if(typeof divObj=="undefined") return;
    if(isAll||dom) divObj=divObj.style;
	if(divX) { if(!isLayers) divX+="px";
		divObj.left=divX; }
	if(divY) { if(!isLayers) divY+="px";
		divObj.top=divY; }
	if(divIndex) divObj.zIndex=divIndex;
	if(divVisi) divObj.visibility = divVisi;
}
function chgPic(picName,picSrc,picParent) {
    if(document.images) {
		obj=document.images[picName];
		if(typeof picParent=="object") obj=picParent.document.images[picName];
		if(obj) obj.src=picSrc;
	}
}
function chgBg(obj,ColorBg) {
	if(typeof obj!="object") {
		if(dom) obj=document.getElementById(obj);
		else if(isAll) obj=document.all[obj];
		else if(isLayers) (!document.layers[obj]) ? obj=getLayerObj(divName) : obj=document.layers[divName];
	}
    if(isAll||dom) { obj.style.backgroundColor=ColorBg; }
    else if(isLayers) { obj.bgColor=ColorBg; }
}
function chgColor(obj,Color) {
	if(typeof obj!="object") {
		if(dom) obj=document.getElementById(obj);
		else if(isAll) obj=document.all[obj];
		else if(isLayers) (!document.layers[obj]) ? obj=getLayerObj(divName) : obj=document.layers[divName];
	}
    if(isAll||dom) { obj.style.color=Color; }
    else if(isLayers) { obj.color=Color; }
}

function checkDocSize(attr) {
	var ViewWidth,ViewHeight;
    if(window.innerWidth) ViewWidth=window.innerWidth;
    else if(document.body.offsetWidth) ViewWidth=document.body.offsetWidth;
	if(window.innerHeight) ViewHeight=window.innerHeight;
    else if (document.body.offsetHeight) ViewHeight=document.body.offsetHeight;
	if(attr=="width") return ViewWidth;
	else if(attr=="height") return ViewHeight;
	else return true;
}
function getProp(obj,attr) { var Value=null;
	if(typeof obj=="object") obj=obj.id;
	if(dom) obj=document.getElementById(obj);
	else if(isAll) obj=document.all[obj]; 
	else if(isLayers) (!document.layers[obj]) ? obj=getLayerObj(obj) : obj=document.layers[obj]; 
	if(!obj) return false;
	if(attr=="height") (!isLayers) ? Value=obj.offsetHeight : Value=obj.clip.height; 
	else if(attr=="width") (!isLayers) ?  Value=obj.offsetWidth : Value=obj.clip.width;
	else if(attr=="left") (!isLayers) ? Value=obj.offsetLeft : Value=obj.left; 
	else if(attr=="top") (!isLayers) ? Value=obj.offsetTop : Value=obj.top; 
	else Value=obj.attr; 
	return Value;
}
function chgProp(obj,attr,val) { 
	var Value=null;
	if(typeof obj=="object") obj=obj.id;
	if(dom) obj=document.getElementById(obj).style;
	else if(isAll) obj=document.all[obj].style;
	else if(isLayers) (!document.layers[obj]) ? obj=getLayerObj(obj): obj=document.layers[obj];
	if((dom||ie)&&(attr=="width"||attr=="height"||attr=="left"||attr=="top")) val+="px";
	if(attr=="height") { (isLayers) ? obj.clip.height=val : obj.height=val; }
	else if(attr=="width") {  (isLayers) ? obj.clip.width=val : obj.width=val; }
	else obj.attr=val; 
	return true;
}
function getLayerObj(divName, doc) { 
	if(typeof doc == 'undefined') doc = window.document; 
	for(var i=0;i<doc.layers.length;i++) { if(doc.layers[i].id==divName) return doc.layers[i];  }
	for(var i=0;i<doc.layers.length;i++) { return getLayerObj(divName, doc.layers[i].document); }
	return null; 
}
function popUp(Url,X,Y,Opt,Name,W,H) {
	checkDocSize();

	if(W==null||W<0) W=400;
	if(H==null||H<0) H=300;
	if(X==null||X=="") X=parseInt((checkDocSize("width")-W)/2); 
	if(Y==null||Y=="") Y=parseInt((checkDocSize("height")-H)/2);
	if(Opt==null||Opt=="") Opt="dependant=yes,hotkeys=yes,location=no,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=no";
	if(Url=="") Url=window.location.href;
	if(Name=="") Name="PopUp";

	var popUpWindow=window.open(Url,Name,"width="+W+",height="+H+",left="+X+",top="+Y+","+Opt+""); 
}

function printWindow(lang) {
	if((op&&opV<6)||(ie&&ieV<6&&(os=="mac"||os=="macx"))) return;
	else if(ie&&ieV<5) {
		var text=new Array;
		text["de"]="Seite mit Standard-Drucker ausdrucken?";
		text["en"]="Print page with default printer?";
		if(!lang||(lang!="de"&&lang!="en")) lang="en";
		var check=window.confirm(text[lang]);
		if(check==true) {
			self.focus();
			var OLECMDID_PRINT = 6;
			var OLECMDEXECOPT_DONTPROMPTUSER = 2;
			var OLECMDEXECOPT_PROMPTUSER = 1;
			var WebBrowser = '<object id="WebBrowser1" width="0" height="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>';
			document.body.insertAdjacentHTML('beforeEnd',WebBrowser);
			WebBrowser1.ExecWB(OLECMDID_PRINT,OLECMDEXECOPT_DONTPROMPTUSER);
			WebBrowser1.outerHTML = '';
		}
	}
	else { window.print(); }
    
}
var mouseX=0, mouseY=0; 
function mouseMove(e) {
	if(isLayers) var y=e.pageY, x=e.pageX;
	if(isAll) var y=event.y, x=event.x;
	else if(dom) var y=e.clientY, x=e.clientX;
	mouseX=x; mouseY=y;
}
document.onmousemove=mouseMove;
if ((isLayers && !ns4) || (ns4 && nsV>=4.5)) document.captureEvents(Event.MOUSEMOVE);
else if (!isAll && dom) { 
	if (!op && !icab) { window.document.addEventListener("mousemove",mouseMove,true); }
}


function swdBuildOverlay(resize,center) {
	var windowWidth = jQuery(document).width()>jQuery(window).width()?jQuery(document).width():jQuery(window).width();
	var windowHeight = jQuery(document).height()>jQuery(window).height()?jQuery(document).height():jQuery(window).height();
	if(ie) {
		windowWidth = jQuery(window).width()
		//windowHeight = jQuery(window).height();
	}
	var scrollTopPx=0;
	if (self.pageYOffset) {
		scrollTopPx=pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
		scrollTopPx=document.documentElement.scrollTop;
	}
	else if (document.body) {// all other Explorers
		srcollTopPx=document.body.scrollTop;
	}
	//alert(windowWidth);alert(jQuery(document).width()+' / '+jQuery(window).width());
//console.log(windowHeight+' / '+scrollTopPx);	
	jQuery('#docoverlay').css('width',windowWidth+'px');
	jQuery('#docoverlay').css('height',windowHeight+'px');
	jQuery('#docoverlayBg').css('width',windowWidth+'px');
	jQuery('#docoverlayBg').css('height',windowHeight+'px');
	//jQuery('#docoverlayBg').show().fadeTo('fast',0.5);
	//if(ie) { jQuery('body').css('overflow','hidden'); }
	jQuery('#docoverlay').show();
	var boxHeight=jQuery('#docoverlayBox').height();
	if(center) {
		var tmp=((jQuery(window).height()-boxHeight)/2);
		var newPos=scrollTopPx+parseInt(tmp);
	}
	else {
		var newPos=parseInt(mouseY-(boxHeight/2));
		boxHeight=boxHeight+100;
		if(newPos+boxHeight>jQuery(window).height()+scrollTopPx) {
			newPos=(jQuery(window).height()+scrollTopPx)-boxHeight-20;
		}
	}
	if(newPos<50) {
		newPos=50;
	}
	jQuery('#docoverlayBox').css('top',newPos+'px');
	jQuery('#docoverlayBox').css('visibility','visible');
	jQuery('#docoverlayBox').show();
	if(!resize) {
		jQuery('#docoverlayBg').slideDown('fast');
	}
}
