
/* site function part */
var gMovedRight = false;
var gTopOffset = 90;
var gAlignedX = 0;
var gMarginRight = 110; 
var gMarginLeft = 10; 
var gDone = false;
var gDocAll = document.all ? true : false;
var rootElem = document.documentElement || document.body;
var gAligned = false;
//var gMaxWidth = 1535;
var gMaxWidth = 1486;
var ua = navigator.userAgent.toLowerCase();

var IE7 = ua.indexOf("msie 7.0") != -1;
var IE6 = ua.indexOf("msie 6.0") != -1;
var safari = ua.indexOf("safari") != -1;
/** begin IE7 zoom **/
//var timerIE;
var msie = null;
var gZoomCo = 1;

function first_view()
{
url = new String(window.location);
var reg = /&MovedRight=true/g;
gMovedRight = reg.test(url) ? false : true;
doAlign();
}

function launchOnResize() {
/*
	if ( timerIE ) 
	{
		clearTimeout(  timerIE );
		delete timerIE;
	}
	
	timerIE = setTimeout(calcZoom, 0);
*/
		msie = new Msie;
		msie.Init();
		msie.AlignCenter();
		gZoomCo = msie.zoomCo;
};


/** end IE zoom **/

window.onresize=function() {
	gMovedRight = false;
	doAlign();
	if ( IE7 ) launchOnResize();
};

window.onload=function() {

	if ( IE7 ) launchOnResize();

	if (ua.indexOf("chrome") != -1) 
		{
		rootElem = document.body;
		var div = document.getElementById("login-group_1");
		if (div)
			{div.style.top = "29px";}
		}
	if (safari)
		{
		var div = document.getElementById("login-group_1");
		if (div)
			{div.style.top = "29px";}
		}
/*	rootElem.scrollLeft = gAlignedX;*/
	rootElem.style.overflowX = "hidden";
		
	first_view();

	if (jQuery.browser.opera)
		{
		jQuery('#flash_pass').css("top", "-38px") ;
		jQuery('#input-submit_o').css("top", "7px");
		}
};

document.onmousemove = function(e) {
	var x,y;
	var clientWidth = msie ? msie.clientWidth : document.body.clientWidth;
	
	if ( clientWidth >= gMaxWidth ) return;
		
	if (gDocAll)
		{ 
			x = window.event.clientX; 
			y = window.event.clientY; 
		}
	else
		{ 
			x = e.clientX; 
			y = e.clientY; 
		}
	
	var div = document.getElementById("onmousemoved");
	if ( ! div ) return;
	var pics = div.getElementsByTagName('img');
	if ( ! pics ) return;
	
	if ( ! gMovedRight )
		{
			if ( x > clientWidth + gAlignedX - gMarginRight 
										&& x < document.body.clientWidth + gAlignedX - gMarginLeft )
				{
					div.style.visibility = "visible";
					pics[0].style.visibility = "hidden";
					pics[1].style.visibility = "visible";
					div.style.left = (clientWidth - parseInt(div.offsetWidth)) + "px";
					div.style.top  = Math.round((rootElem.scrollTop + y - gTopOffset) * gZoomCo) + "px";
				}
			else
				{
					div.style.visibility = "hidden";
					pics[0].style.visibility = "hidden";
					pics[1].style.visibility = "hidden";
				}
		}
	else
		{
			if (x < gMarginRight /*&& x > gMarginLeft*/)
				{
					div.style.visibility = "visible";
					pics[0].style.visibility = "visible";
					pics[1].style.visibility = "hidden";
					div.style.left = 0;	
					div.style.top  = Math.round((rootElem.scrollTop + y - gTopOffset) * gZoomCo) + "px";
				}
			else
				{
					div.style.visibility = "hidden";
					pics[0].style.visibility = "hidden";
					pics[1].style.visibility = "hidden";
				}
		}

};

function doAlign()
{
	var div = document.getElementById("onmousemoved");
	var pics = div.getElementsByTagName('img');
	var table = document.getElementById("right-content");
	var right_table = document.getElementById("right-menu");
	var right_table_hrefs = right_table.getElementsByTagName('a');
	var hrefs = table.getElementsByTagName('a');
	var reg = /&MovedRight=true/g;
	if ( ! gMovedRight )
		{
			gMovedRight = true;
			gTopOffset = 30;
			if (hrefs.length>0)
				{
				for (var i=0 ; i<hrefs.length; i++)
					{
					hrefs[i].href = hrefs[i].href + "&MovedRight=" + gMovedRight;
					}
				}
			if (right_table_hrefs.length>0)
				{
				for (var i=0 ; i<right_table_hrefs.length; i++)
					{
					right_table_hrefs[i].href = right_table_hrefs[i].href + "&MovedRight=" + gMovedRight;
					}
				}
		}
	else
		{
			gMovedRight = false;
			gTopOffset = 90;
			if (hrefs.length>0)
				{
				for (var i=0 ; i<hrefs.length; i++)
					{
					hrefs[i].href = hrefs[i].href.replace(reg,"");
					}
				}
			if (right_table_hrefs.length>0)
				{
				for (var i=0 ; i<right_table_hrefs.length; i++)
					{
					right_table_hrefs[i].href = right_table_hrefs[i].href.replace(reg,"");
					}
				}				
		}
	div.style.visibility = "hidden";
	pics[0].style.visibility = "hidden";
	pics[1].style.visibility = "hidden";
	
	doAlignImpl();
}

function doAlignImpl()
{
		if ( gMovedRight )
			document.getElementById("parent").scrollLeft = gAlignedX = gMaxWidth - rootElem.clientWidth;
		else
			document.getElementById("parent").scrollLeft = gAlignedX = 0;
		
		//IE6 - 7 position relative scroll bug fixes
		if ( IE7 || IE6)
			document.getElementById("parent").innerHTML = document.getElementById("parent").innerHTML;

}

function Msie()
{
	this.zoomBefore = 100;
	
	this.Init = function() { 
			var rect = document.body.getBoundingClientRect();
			this.zoomCo = document.body.clientWidth / (rect.right-rect.left); 
			this.zoom = Math.round ( (rect.right-rect.left) / document.body.clientWidth * 100);
			this.marginLeft = Math.round(gMarginLeft * this.zoomCo);
			this.marginRight = Math.round(gMarginRight * this.zoomCo);
			this.clientWidth = Math.round(document.body.clientWidth * this.zoomCo);
	}
	
	this.AlignCenter = function() 
		{
			var tempp = Math.round(document.getElementById("top").offsetWidth+(this.marginRight/2)+this.marginLeft);
			if (!document.getElementById("top").offsetWidth) return;
			if (gMovedRight)
				doAlign();
				
			var divArray = new Array("top", "stretch", "bottom", "second_bottom");
							
			for ( var i = 0; i < divArray.length; i++)
			{ 
			var divObj = document.getElementById(divArray[i]);
			if ( this.clientWidth > tempp )
				{
				var left = Math.round( ( (this.clientWidth - divObj.offsetWidth) / 2 ) /  this.zoomCo );
				divObj.style.left = left + "px";
				} 
			else
				{
				divObj.style.left = this.marginLeft + "px";
				}
			
			}

		}
}

function newWin(goL,id,ww,wh)
{
ww=ww||screen.width*.9
wh=wh||screen.height*.9
var wbx=Math.round((screen.width-ww)/2)*.45
var wby=Math.round((screen.height-wh)/2)*.45
var pos=(document.all)?'left='+wbx+',top='+wby+',':'screenX='+wbx+',screenY='+wby+','
var nw=window.open(goL,'Win'+id,'width='+ww+',height='+wh+','+pos+'toolbar=0,scrollbars=0,resizable=1,status=0')
nw.moveTo(0,0)
nw.resizeTo(screen.availWidth, screen.availHeight)
}
