window.uaVersion = parseFloat((navigator.userAgent.toLowerCase().match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1]);
window.ie = (document.all && !window.opera);
window.safari = /Safari/.test(navigator.userAgent);
window.geckoMac = /Macintosh.+rv:1\.[0-8].+Gecko/.test(navigator.userAgent);


function getPositionX(obj){
	var PositionX = 0;
	if(obj.offsetParent)
		PositionX = getPositionX(obj.offsetParent);
	return PositionX + obj.offsetLeft;
}

function getPositionY(obj){
	var PositionY = 0;
	if(obj.offsetParent)
		PositionY = getPositionY(obj.offsetParent);
	return PositionY + obj.offsetTop;
}
/*
function callIframe(url,width,height){
	var oFrame = document.getElementById("frame");
	var oIframe = document.getElementById("iframe");
	bodyBlur("closeIframe()");
	oIframe.src = url;
	oIframe.style.width = width+'px';
	oIframe.style.height = height+'px';
	oFrame.style.width = (width+10)+'px';
	oFrame.style.height = (height+20)+'px';
	newLeft = (screen.width/2)-((width+10)/2)+document.documentElement.scrollLeft;
	newTop = (screen.height/2)-((height+10)/2)+document.documentElement.scrollTop-100;
	oFrame.style.left = newLeft+"px";
	oFrame.style.top = newTop+"px";
	fadeIn("frame", 0, 100, 10);
}

function closeIframe(){
	var oFrame = document.getElementById("frame");
	var oIframe = document.getElementById("iframe");
	oIframe.src = 'about:blank';
	bodyFocus();
	oFrame.style.display = "none";
}
*/
//Fade control.........
window.fadeInT = new Array();
window.fadeOutT = new Array();

function fadeIn(sEle, iSrc, iTarget, iGap, bLoop){
	if(iSrc > iTarget)
		return false;
	if(window.fadeOutT[sEle]){
		clearTimeout(window.fadeOutT[sEle]);
	}
	var oEle = document.getElementById(sEle);
	oEle.style.display = "block";
	if(iSrc < iTarget){
		iSrc+=iGap;
		if(iSrc > iTarget)
			iSrc = iTarget;
		oEle.style.filter = "alpha(opacity="+iSrc+")";
		oEle.style.MozOpacity = iSrc/100;
		window.fadeInT[sEle] = setTimeout("fadeIn(\""+sEle+"\", "+iSrc+", "+iTarget+", "+iGap+");",1);
		return true;
	}
	else
		window.fadeInT[sEle] = 0;
	return true;
}
function fadeOut(sEle, iSrc, iTarget, iGap, bLoop){
	if(iSrc < iTarget)
		return false;
	if(window.fadeInT[sEle]){
		clearTimeout(window.fadeInT[sEle]);
	}
	var oEle = document.getElementById(sEle);
	if(iSrc > iTarget){
		iSrc-=iGap;
		if(iSrc < iTarget)
			iSrc = iTarget;
		oEle.style.filter = "alpha(opacity="+iSrc+")";
		oEle.style.MozOpacity = iSrc/100;
		window.fadeOutT[sEle] = setTimeout("fadeOut(\""+sEle+"\", "+iSrc+", "+iTarget+", "+iGap+");",1);
		return true;
	}
	else
		window.fadeOutT[sEle] = 0;
	oEle.style.display = "none";
	return true;
}
function zoomIn(sEle){
	if(window.zoomOutT){
		clearTimeout(zoomOutT);
	}
	var oEle = document.getElementById(sEle);
	oEle.style.display = "block";
	if(window.opacity < 100){
		window.zoom+=5;
		if(window.zoom > 100)
			window.zoom = 100;
		oEle.style.zoom = window.zoom+"%";
		window.zoomInT = setTimeout("zoomIn(\""+sEle+"\");",1);
	}
	return true;
}
function zoomOut(sEle){
	if(window.zoomInT){
		clearTimeout(zoomInT);
	}
	var oEle = document.getElementById(sEle);
	oEle.style.display = "block";
	if(window.opacity > 0){
		window.zoom-=5;
		if(window.zoom < 0)
			window.zoom = 0;
		oEle.style.zoom = window.zoom+"%";
		window.zoomOutT = setTimeout("zoomOut(\""+sEle+"\");",1);
	}
	return true;
}

function msgInfo(sMsg, iSize){
	//iSize must be either 16, 32 or 64;
	if(!iSize) iSize = 32; //32 is default;
	document.write("<br /><center><div style=\"background-color: #ffffff; padding: 5px; border: 1px solid #222222; font-weight: bold; width: 80%;\"><table cellspacing=\"0\" width=\"100%\"><td width=\"32px\"><img src=\"/images/icons/info"+iSize+".jpg\" /></td><td style=\"vertical-align: middle; color: #000000;\">"+sMsg+"</td></table></div></center><br />");
}
function msgAlert(sMsg, iSize){
	//iSize must be either 16, 32 or 64;
	if(!iSize) iSize = 32; //32 is default;
	document.write("<br /><center><div style=\"background-color: #ffffef; padding: 5px; border: 1px solid #ffff22; font-weight: bold; width: 80%;\"><table cellspacing=\"0\" width=\"100%\"><td width=\"32px\"><img src=\"/images/icons/alert"+iSize+".jpg\" /></td><td style=\"vertical-align: middle; color: #000000;\">"+sMsg+"</td></table></div></center><br />");
}
function msgError(sMsg, iSize){
	//iSize must be either 16, 32 or 64;
	if(!iSize) iSize = 32; //32 is default;
	document.write("<br /><center><div style=\"background-color: #ffefef; padding: 5px; border: 1px solid #ff2222; font-weight: bold; width: 80%;\"><table cellspacing=\"0\" width=\"100%\"><td width=\"32px\"><img src=\"/images/icons/error"+iSize+".jpg\" /></td><td style=\"vertical-align: middle; color: #000000;\">"+sMsg+"</td></table></div></center><br />");
}
function msgOk(sMsg, iSize){
	//iSize must be either 16, 32 or 64;
	if(!iSize) iSize = 32; //32 is default;
	document.write("<br /><center><div style=\"background-color: #efffef; padding: 5px; border: 1px solid #22ff22; font-weight: bold; width: 80%;\"><table cellspacing=\"0\" width=\"100%\"><td width=\"32px\"><img src=\"/images/icons/ok"+iSize+".jpg\" /></td><td style=\"vertical-align: middle; color: #000000;\">"+sMsg+"</td></table></div></center><br />");
}
function toggleView(iItem){
	var oEle = document.getElementById(iItem);
	if(oEle.style.display == "block" || !oEle.style.display) oEle.style.display = "none";
	else oEle.style.display = "block";
}

function getPageSize() {
	var d = document, w = window, iebody = d.compatMode && d.compatMode != 'BackCompat' 
		? d.documentElement : d.body;	
	
	var b = d.body;
	var xScroll = (w.innerWidth && w.scrollMaxX) 
			? w.innerWidth + w.scrollMaxX : Math.max(b.scrollWidth, b.offsetWidth),
		yScroll = (w.innerHeight && w.scrollMaxY) 
			? w.innerHeight + w.scrollMaxY : Math.max(b.scrollHeight, b.offsetHeight),
		pageWidth = w.ie ? iebody.scrollWidth :
			(d.documentElement.clientWidth || self.innerWidth),
      	pageHeight = w.ie ? Math.max(iebody.scrollHeight, iebody.clientHeight) : 
			(d.documentElement.clientHeight || self.innerHeight);
	
	var width = w.ie ? iebody.clientWidth : 
			(d.documentElement.clientWidth || self.innerWidth),
		height = w.ie ? iebody.clientHeight : self.innerHeight;
	
	return {
		pageWidth: Math.max(pageWidth, xScroll),
		pageHeight: Math.max(pageHeight, yScroll),
		width: width,
		height: height,		
		scrollLeft: w.ie ? iebody.scrollLeft : pageXOffset,
		scrollTop: w.ie ? iebody.scrollTop : pageYOffset
	}
}

function showHelp(id){
	var hlpDiv = document.getElementById("hlpDiv"),
		content = document.getElementById("hlpContent-"+id).innerHTML,
		hlpCont = document.getElementById("hlpConteiner");
	bodyBlur("closeHelp()");
	hlpCont.innerHTML = content;
	var page = getPageSize();
	hlpDiv.style.left = page['width']/2+page['scrollLeft']-288+"px";
	hlpDiv.style.top = page['height']/2+page['scrollTop']-218+"px";
	fadeIn("hlpDiv", 0, 100, 10);
}

function closeHelp(){
	var hlpCont = document.getElementById("hlpConteiner");
	fadeOut("hlpDiv", 100, 0, 10);
	hlpCont.innerHTML = "";
	bodyFocus();
}

function bodyBlur(evt){
	var oBlur = document.getElementById("blur");
	blurDivResize();
	oBlur.onclick = function onclick(event){ bodyFocus(evt); };
	fadeIn("blur", 0, 80, 10);
	return;
}

function bodyFocus(evt){
	if(evt)
		eval(evt);
	fadeOut("blur", 80, 0, 10);
	return;
}

function blurDivResize(){
	var oBlur = document.getElementById("blur");
	oBlur.style.width = getPageSize()['pageWidth']+"px";
	oBlur.style.height = getPageSize()['pageHeight']+"px";
	return;
}

function addEvent(ele, event, func){
	try {
		ele.addEventListener(event, func, false);
	} catch (e) {
		try {
			ele.detachEvent('on'+ event, func);
			ele.attachEvent('on'+ event, func);
		} catch (e) {
			ele['on'+ event] = func;
		}
	} 
}

function rearrangeBannerDiv(){
	var outbanner = document.getElementById("outbanner");
	var maintbl = document.getElementById("main-tbl");
	outbanner.style.top = getPositionY(maintbl)+5+"px";
	outbanner.style.left = getPositionX(maintbl)+790+"px";
	outbanner.style.display = "block";
	return;
}

function init(){
	addEvent(window, "resize", blurDivResize);
	addEvent(window, "resize", rearrangeBannerDiv);
	rearrangeBannerDiv(); //arrange banner
	return;
}