function $(_sId)
{
	return document.getElementById(_sId);
}

function IsDigit(event)
{
  return ((event.keyCode >= 48) && (event.keyCode <= 57));
}

var maskDivId = "maskDiv";
var tipDivId = "tipWindow";

function showTipWindow(bShadow,inHTML)
{			
	var arraySize = getPageSize();
	
	var oTipDiv = $(tipDivId);
	if(oTipDiv===null)
	{
		// create the tip div	
		var oCreateTipDiv = document.createElement("div");	
		oCreateTipDiv.id = tipDivId;	
		document.body.appendChild(oCreateTipDiv);
		
		oTipDiv = $(tipDivId);
	}
				
	oTipDiv.style.zIndex = "100";				
	oTipDiv.style.position = "absolute";
	oTipDiv.innerHTML = inHTML;	
	
	var arrayScroll = getPageScroll();

	oTipDiv.style.left = arraySize[0]/2-160 + arrayScroll[0];
	oTipDiv.style.top =  arraySize[1]/2-100 + arrayScroll[1];
		
	if(bShadow)
	{
		// if bShadow create the mask div
		var oCreateMaskDiv = document.createElement("div");	
		oCreateMaskDiv.id = maskDivId;	
		document.body.appendChild(oCreateMaskDiv);

		var oMaskDiv = $(maskDivId);
		
		oMaskDiv.style.position = "absolute";
		
		oMaskDiv.style.left = 0;
		oMaskDiv.style.top = 0;
		oMaskDiv.style.width = arraySize[2];
		oMaskDiv.style.height = arraySize[3];
		
		oMaskDiv.style.filter = "alpha(opacity=30)";
		oMaskDiv.style.opacity = "0.6";
		oMaskDiv.style.background = "#000000";
		
		oMaskDiv.style.display = "block";		
		oMaskDiv.style.zIndex = "99";
	}	
	
	oTipDiv.style.display = "block";	
}

function showBigWindow(bShadow,inHTML,left,top)
{			
	var arraySize = getPageSize();
	
	var oTipDiv = $(tipDivId);
	if(oTipDiv===null)
	{
		// create the tip div	
		var oCreateTipDiv = document.createElement("div");	
		oCreateTipDiv.id = tipDivId;	
		document.body.appendChild(oCreateTipDiv);
		
		oTipDiv = $(tipDivId);
	}
				
	oTipDiv.style.zIndex = "100";				
	oTipDiv.style.position = "absolute";
	oTipDiv.innerHTML = inHTML;	
	
	var arrayScroll = getPageScroll();

	oTipDiv.style.left = arraySize[0]/2-left + arrayScroll[0];
	oTipDiv.style.top =  arraySize[1]/2-top + arrayScroll[1];
		
	if(bShadow)
	{
		// if bShadow create the mask div
		var oCreateMaskDiv = document.createElement("div");	
		oCreateMaskDiv.id = maskDivId;	
		document.body.appendChild(oCreateMaskDiv);

		var oMaskDiv = $(maskDivId);
		
		oMaskDiv.style.position = "absolute";
		
		oMaskDiv.style.left = 0;
		oMaskDiv.style.top = 0;
		oMaskDiv.style.width = arraySize[2];
		oMaskDiv.style.height = arraySize[3];
		
		oMaskDiv.style.filter = "alpha(opacity=30)";
		oMaskDiv.style.opacity = "0.6";
		oMaskDiv.style.background = "#000000";
		
		oMaskDiv.style.display = "block";		
		oMaskDiv.style.zIndex = "99";
	}	
	
	oTipDiv.style.display = "block";	
}

function closeTipWindow()
{	
	// del mask and tip div
	try
	{
		var oObj = $(tipDivId);
		oObj.style.display = "none";			
		var delObj = oObj.getElementsByTagName("div");	
	  	if(delObj.length>0)
	    	delObj[0].parentNode.removeChild(delObj[0]);
	    	
	    var oMaskObj = $(maskDivId);
	    oMaskObj.style.display = "none";
		var delMask = oMaskObj.getElementsByTagName("div");
	  	if(delMask.length>0)
	    	delMask[0].parentNode.removeChild(delMask[0]);	    
    }
    catch(e)
    {
    } 
}

function moveTipWindow(e)
{
	var oObj = $(tipDivId);	

	var oEvent = window.event ? window.event : e;
 	
 	var scrollArray = getPageScroll();
	var scrollTop = scrollArray[1];
	var scrollLeft = scrollArray[0];
	
	var startX = oEvent.clientX + parseInt(oObj.style.left,10);
	var startY = oEvent.clientY + parseInt(oObj.style.top,10);
 
 	var dragData = {x : startX, y : startY};
  
 	oObj.setCapture ? oObj.setCapture() : function(){};

	oObj.onmousemove = mousemove;
	oObj.onmouseup = mouseup;
 
	function mousemove()
	{
		var oEvent = window.event ? window.event : e;
 		
 		var scrollArray = getPageScroll();
		var scrollTop = scrollArray[1];
		var scrollLeft = scrollArray[0];
			 
		var iLeft = oEvent.clientX + scrollLeft - dragData["x"] + parseInt(oObj.style.left,10);
		var iTop = oEvent.clientY + scrollTop - dragData["y"]+ parseInt(oObj.style.top,10);
	
		oObj.style.left = iLeft;
		oObj.style.top = iTop;
 
		var startX = oEvent.clientX + scrollLeft;
		var startY = oEvent.clientY + scrollTop;
		
		dragData = {x: startX, y: startY};  
	}
   
	function mouseup()
	{
		oObj.onmousemove = null;
		oObj.onmouseup = null;
  	
 		var scrollArray = getPageScroll();
		var scrollTop = scrollArray[1];
		var scrollLeft = scrollArray[0];
				
		if(parseInt(oObj.style.top,10)<scrollTop)
		{
			 oObj.style.top = scrollTop;
		} 
		
		if(parseInt(oObj.style.left,10)<scrollLeft)
		{
			oObj.style.left = scrollLeft; 		
		}	
		
		oObj.releaseCapture ? oObj.releaseCapture() : function(){};	
	}
}

function scrollMoveDiv()
{	
	var arraySize = getPageSize();
	try
	{
		var oTipObj = $(tipDivId);
	
		oTipObj.style.left = arraySize[0] / 2 - 150 ;
		oTipObj.style.top =  arraySize[3] + 200;
		
		setTimeout("scrollMoveDiv('"+tipDivId+"')",1);
	}
	catch(e)
	{
	}
}

function getPageScroll()
{
	var xScroll = document.documentElement.scrollLeft;
	var yScroll = document.documentElement.scrollTop;
	
	var arrayScroll = new Array(xScroll,yScroll);
	return arrayScroll;
}

function getPageSize()
{		
	var	pageWidth = document.documentElement.clientWidth;
	var	pageHeight = document.documentElement.clientHeight;
	
	var windowWidth = document.body.clientWidth;
	var windowHeight = document.body.clientHeight;
				
	// when the page is on the top ,pageWidth=windowWidth and pageHeight=windowHeight
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);

	return arrayPageSize;	
}

///////////////////////////////////////////////the info tip start/////////////////////////////////////////////////

var infoDivId = "infoTip";
var bInfoShow = false;	

function showInfoDiv(content,posX,posY,offsetX,offsetY)
{
	var scrollArray = getPageScroll();
	
	var scrollLeft = scrollArray[0];
	var scrollTop = scrollArray[1];
	
	var pageArray = getPageSize();
	var pageWidth = pageArray[0];
	var pageHeight = pageArray[1];
		
	try
	{	
		var obj = $(infoDivId);	 
		if(obj===null)
		{
			// the obj dos not exist,so create the div on the page 
			var oCreateInfoDiv = document.createElement("div");	
			oCreateInfoDiv.id = infoDivId;	
			document.body.appendChild(oCreateInfoDiv);
			
			obj = $(infoDivId);			
		}
		
	 	obj.style.position = "absolute";	
		obj.innerHTML = content;
		
		var contentWidth = obj.offsetWidth;
		var contentHeight = obj.offsetHeight;
				
		var rightDistance = pageWidth - (posX - scrollLeft);
		var leftDistance = posX - scrollLeft;
		var bottomDistance = pageHeight - (posY - scrollTop);
		var topDistance = posY - scrollTop;
					
		var left;
		var top;
		
		if(rightDistance>=(contentWidth+offsetX))
		{
			left = posX + offsetX;
		}
		else if(leftDistance>=(contentWidth+offsetX))
		{
			left = posX - contentWidth;
		}
		else
		{
			left = posX + offsetX/2;
		}
		
		if(bottomDistance>=(contentHeight+offsetY))
		{
			top = posY + offsetY;
		}
		else if(topDistance>=(contentHeight+offsetY))
		{
			top = posY - contentHeight;
		}
		else
		{
			top = posY + offsetY/2;
		}
		
		obj.style.posLeft = left;
		obj.style.posTop = top;
				
		obj.style.visibility = "visible";
		
		obj.className = "infoitems";
		obj.onmouseover = function(){
			clearHideInfoDiv();
			highlightInfoDiv(window.event,"on");
		}
		obj.onmouseout = function(){
			highlightInfoDiv(window.event,"off");
			dynamicHideInfo(window.event);
		}
		
		bInfoShow = true;
	}
	catch(exception)
	{
		alert(exception);
	}
}

function dynamicHideInfo(e)
{
	e = e?e:window.event;
	var obj = $(infoDivId);	
	if(!obj.contains(e.toElement))
	{
		bInfoShow = false;
		hideInfo();
	}
}

function delayHideInfoDiv()
{
		bInfoShow = false;
		delayhide = setTimeout("hideInfo()",300);
}
function hideInfo()
{
	var obj = $(infoDivId);	 
	if(obj!=null && bInfoShow==false)
	{
		obj.style.visibility = "hidden";
	}
}

function highlightInfoDiv(e,state)
{
	e = e==null?e:window.event;

	if(document.all)
		source_el=event.srcElement;
	else if(document.getElementById)
		source_el=e.target;
	
	source_el.id=(state=="on")? "mouseoverstyle":"";
	/*	
	if (source_el.className=="infoitems")
	{
		source_el.id=(state=="on")? "mouseoverstyle":""
	}
	else
	{
		while(source_el.id!=infoDivId)
		{
			source_el=document.getElementById? source_el.parentNode:source_el.parentElement
			//alert(source_el.className);
			if (source_el.className=="infoitems")
			{
				source_el.id=(state=="on")? "mouseoverstyle":""
			}
		}
	}
	*/
}

function clearHideInfoDiv()
{
	//if (window.delayhide)
	  clearTimeout(delayhide)
}	

///////////////////////////////////////////////////get the obj position on the page /////////////////////////////
function getListFramePos(_sId)
{	
	var listPosition = new Object();
	
	var oContent = top.$(_sId);

	var posContent = getAbsolutePosition(oContent);
	listPosition.x = posContent.x;
	listPosition.y = posContent.y;
		
	return listPosition;
}

function getAbsolutePosition(_sId)
{
	var obj = $(_sId);
	
	var position = new Object();
	position.x = 0;
	position.y = 0;
	
	var tempobj = obj;

	while(tempobj!=null)
	{
		
		position.x += tempobj.offsetLeft + tempobj.clientLeft;
		position.y += tempobj.offsetTop + tempobj.clientTop;
		
		tempobj = tempobj.offsetParent;
	}
	
	position.x += document.body.scrollLeft;
	position.y += document.body.scrollTop;
		
	return position;
}



////////////////////////////////////////////////////////////////////////////////////////////////
function chgLanguage(language)
{
	var showContent ="<table><tr><td><iframe id='languageFrame' src='"+language+"' frameborder='0' scrolling='no' width='0' height='0'></iframe></td></tr></table>";
	showTipWindow(false,showContent);
}

function showLoadingInfo()
{
	var loadContent = "<table width=\"208\"><tr><td widht=\"208\" height=\"32\" align=\"center\"><img src=\"../images/load.gif\" /></td></tr><table>";
	showTipWindow(true,loadContent);
}

function closeLoadingInfo()
{
	closeTipWindow();
}




























