/**
 * @author wangxiangping 2009-7-17
 */
if (!jse) var jse={};
  jse.popwin={
 _win:null,
 _bodyWidth:0,
 login:'',
 _disabledZone:null,
 bodyHeight:function () {
  var cobj = document.body;
  while(cobj.scrollTop == 0 && cobj.parentNode)
  {
   if(cobj.tagName.toLowerCase() == 'html') break;
   cobj = cobj.parentNode;
  }
  return cobj.clientHeight;
 },
 _checkDisabledZone:function(left,top) {
  jse.popwin._disabledZone=document.getElementById("disabledZone");
        if (!jse.popwin._disabledZone) {
            jse.popwin._disabledZone=document.createElement('div');
            jse.popwin._disabledZone.id="disabledZone";
            jse.popwin._disabledZone.style.cssText="-moz-opacity:0.8;filter:alpha(opacity=80);position:absolute;z-Index:9998;left:0px;top:0px;background-color:#e9f3ff; border:2px solid #448feb;display:none";
            document.body.appendChild(jse.popwin._disabledZone); 
			jse.popwin._disabledZone.style.width="123px";
			jse.popwin._disabledZone.style.height="30px";			          
        }
        if(jse.popwin._disabledZone != null)
        {
        	jse.popwin._disabledZone.style.left=''+left+'px';
			jse.popwin._disabledZone.style.top =''+top+'px';
        } 
 },
 init:function(_winId,left,top) 
 {
  jse.popwin._checkDisabledZone(left,top);
  jse.popwin._win=$(_winId);
  jse.popwin._disabledZone.appendChild(jse.popwin._win);  
 },
 show:function() 
 {
  jse.popwin._disabledZone.style.display="block";
  jse.popwin._win.style.display="block";
 },
 
 hide:function() {
 if(jse.popwin._win!=null)
  jse.popwin._win.style.display="none";
  if(jse.popwin._disabledZone!=null)
  jse.popwin._disabledZone.style.display="none";
 }
};

var outObject;
var msx  = '请输入问题答案'; 
String.prototype.trim=function(){
	return this.replace(/(^\s*)|(\s*$)/g, "");
} 
function registerClickEvent()
{
if(!!document.all)
{
	 	document.onkeyup = function()
	 	{	 		
	 		
	 		    if (window.event.keyCode==27)
			{
	 	 		if(outObject)outObject.blur();
				closepopwin();
			}
	 	 }
		document.onclick = function()
		{
			with(window.event)
 		  { 	 	
			
			 closepopwin(srcElement);
 		  }	
		}
}
else
{
	document.addEventListener('click',function(event){
	closepopwin(event.target); 
	 },true);
}
}
registerClickEvent();
 
function checkCompute(_element)
{
	var result = _element.value;	
	var t = $('resultErrorTip0'); 
	var tip1 = $('resultErrorTip1');
	var tip = $('resultErrorTip');
	if(t !=null)
	Element.remove(t);
	if(result == formula.result)
	{	 
		tip.show();
		tip1.hide();
	}
	else
	{
		tip1.show();
		tip.hide();
	}
}

function closepopwin(_element)
 {
 	if(outObject == null||outObject.getAttribute('id') !=_element.id)		  
 	jse.popwin.hide();	 
 }

function getOs() 
{ 
    var OsObject = ""; 
   if(navigator.userAgent.indexOf("MSIE")>0) { 
        return "MSIE"; 
   } 
   if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){ 
        return "Firefox"; 
   } 
   if(isSafari=navigator.userAgent.indexOf("Safari")>0) { 
        return "Safari"; 
   }  
   if(isCamino=navigator.userAgent.indexOf("Camino")>0){ 
        return "Camino"; 
   } 
   if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){ 
        return "Gecko"; 
   } 
   
}
function change(desc)
{
	 
	 $('winForm').update(desc);
	 
} 

function answerCode(_targetElement,event,reCompute)
{
 _targetElement = $(_targetElement); 
 outObject =  _targetElement;  
 var targetElement_X =Position.cumulativeOffset(_targetElement).left;
 var targetElement_Y = Position.cumulativeOffset(_targetElement).top-Element.getDimensions(_targetElement).height-8;
 jse.popwin.init('winForm',targetElement_X,targetElement_Y);
 jse.popwin.show();  
 var version = getOs();  
 if(version == 'Firefox')
 {
 	event.preventDefault(); //停止处理默认行为
 	event.stopPropagation(); //阻止冒泡
 }
 else if(version == 'MSIE')
 {	
   event.returnValue=false;
  	event.cancelBubble=true; 	 
 }
 if(reCompute)
 formula = null;
 createComputeDesc();
 }