var poped = false
var popedLogin = false


function getIEVersionNumber() {
    var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf("MSIE ");
    
    if (MSIEOffset == -1) {
        return 0;
    } else {
        return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
    }
}


function prepareBackgroundPNG()
{
	var ieVersion =  getIEVersionNumber();
	if (ieVersion < 1 || ieVersion > 6)
		return;
	
	var s1pix = "/images/pix.gif"
	var obj = null;
	var sResult = "";

	for( var i = 0; i < document.all.length; i++)
	{
		obj = document.all[i];
		
//		if ( false && obj.background && obj.background.match(/\.png$/) != null ) 
//		{
//			if ( obj.sizingMethod == undefined ) // crop, image, scale
//				obj.sizingMethod = "crop"; 
//			obj.style.background = "";
//			obj.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + obj.background + "', sizingMethod='" + obj.sizingMethod +"');";
//			obj.background = "";
//
//		}w
		if ( (obj.tagName == "IMG" || obj.tagName == "INPUT") && obj.src.match(/\.png$/) != null ) 
		{
			if ( obj.sizingMethod == undefined ) // crop, image, scale
				obj.sizingMethod = "image"; 
			obj.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + obj.src + "', sizingMethod='" + obj.sizingMethod +"');";
			obj.src = s1pix;
		} 
	}
}


function getWindowInfo()
{
	var scrOfX = 0, 	scrOfY = 0;
	var myWidth = 0, 	myHeight = 0;
	var myAbsWidth = 0, myAbsHeight = 0;
	
	if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		  //IE6 standards compliant mode
		  scrOfY = document.documentElement.scrollTop;
		  scrOfX = document.documentElement.scrollLeft;
	}
	else if( typeof( window.pageYOffset ) == 'number' ) {
	  //Netscape compliant
	  scrOfY = window.pageYOffset;
	  scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	  //DOM compliant
	  scrOfY = document.body.scrollTop;
	  scrOfX = document.body.scrollLeft;
	}  

	if(document.documentElement)
	{
		myAbsWidth = document.getElementsByTagName("body")[0].scrollWidth;
   		myAbsHeight = document.getElementsByTagName("body")[0].scrollHeight;
	}else if(document.body  && document.body.scrollWidth)
	{
		myAbsWidth = document.body.scrollWidth;
	   	myAbsHeight = document.body.scrollHeight;
	}
			
			
	if( typeof( window.innerWidth ) == 'number' )
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;

	} 
  	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
  	{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;

	}

	return {
		scrollX: 			scrOfX,
		scrollY: 			scrOfY,
		visibleWidth: 		myWidth,
		visibleHeight: 		myHeight,
		absHeight:			myAbsHeight,
		absWidth:			myAbsWidth,
		mouseX:				document.MouseX,
		mouseY:				document.MouseY	
	};

}


function popUp(templateName,queryVars)
{
	var addQuery = '';
	if( queryVars )
		for(var k in queryVars)
			addQuery += '&'+ escape(k)+'='+escape(queryVars[k]);
	closePopUp();
	var windowInfo = getWindowInfo();

	document.getElementById("popUp").src = "/mosaik/popUp.php?templateName="+templateName+addQuery;
	
	document.getElementById("register_PopUp").style.display 	= "block";
	popedLogin = poped = true;	
	checkRegisterInner();

}

function closePopUp(){
	
	var windowInfo = getWindowInfo();	
	document.getElementById('register_PopUp').style.display='none'
	//document.getElementById("popUp").src = "about:blank";
	document.getElementById("register_PopUp").style.height = windowInfo.absHeight +"px";
	document.getElementById("popUp").style.height = "70px";
	popedLogin = poped = false;

}


var onPopUpLoaded = function()
{
	var h;
	var iFrame 				= document.getElementById("popUp");
	var cntrlDiv 			= document.getElementById("register_PopUp");
	var lastDisplayStauts 	= cntrlDiv.style.display;
	
	if( iFrame.src == "about:blank")
		return;
	
	iFrame.style.height = "0px";	
	
	cntrlDiv.style.display = "block";
	
	if(iFrame.contentDocument) 											// DOM
		h = iFrame.contentDocument.body.scrollHeight;
	else if (iFrame.contentWindow && iFrame.contentWindow.document) 	// IE5.5+ windows
	{
		h = iFrame.contentWindow.document.body.scrollHeight;
	}
	
	cntrlDiv.style.display = lastDisplayStauts;
	
	iFrame.style.height = h + "px";

	var windowInfo = getWindowInfo();
	document.getElementById("register_PopUp").style.height 	= windowInfo.absHeight; //  getScrollXY()[1] + 
	document.getElementById("registerInner").style.top 		= parseInt(windowInfo.scrollY-((document.getElementById("registerInner").offsetHeight-windowInfo.visibleHeight)/2)) + "px";

}

function getGlobalCoord(e)
{
	var e;

	if (!e)	{
		document.MouseX = parseInt(event.clientX + document.body.scrollLeft);
		document.MouseY = parseInt(event.clientY + document.body.scrollTop);	
	} else {
		document.MouseX = parseInt(e.pageX);
		document.MouseY = parseInt(e.pageY);	
	}
	if(window.onaftermousemove)
	{
		window.onaftermousemove(document.MouseX,document.MouseY);
	}
	return ;
}

function checkRegisterInner(){
	if(!poped)
		return;
	var windowInfo = getWindowInfo();
	document.getElementById("registerInner").style.top 		= parseInt(windowInfo.scrollY-((document.getElementById("registerInner").offsetHeight-windowInfo.visibleHeight)/2)) + "px";
}

window.addEvent("scroll",checkRegisterInner);
window.addEvent("resize",checkRegisterInner);
//window.addEvent("load",prepareBackgroundPNG);
window.addEvent("mousemove",getGlobalCoord);