//$Revision: 1.1 $
//override ebos js file
function setListener(component, funcname)
{
  if(component != null)
  {
  	//for array
  	if(component.length != null && component.type == null)
  	{
  		for(var i = 0, n = component.length; i < n; i++)
  		{
  			setSingleListener(component[i], funcname);
  		}
  	}
  	else
  	{
  		setSingleListener(component, funcname);
  	}
  }
}

function setSingleListener(component, funcname)
{
  if (component == undefined) return;
  if(component.type == "select-one") {
    if(component.onchange != null && component.onchange != undefined) {
      var oldfunc = component.onchange;
      component.onchange = function(){oldfunc();funcname();};
    }else {
      component.onchange = funcname;
    }   
  }else //if(component.type == "checkbox")
  {
    if(component.onclick != null && component.onclick != undefined) {
      var oldfunc = component.onclick;
      component.onclick = function(){oldfunc();funcname();};
    }else {
      component.onclick = funcname;
    }
  }
}


function Expression(components, expression) {
  var newExp = expression;
  for(var i = 0; i < components.length; i++) {
    var component = components[i];
    if(component.type == "text" | component.type == "password") {
      newExp = newExp.replace("{" + (i + 1) + "}", component.value);
    }else if(component.type == "checkbox") {
      if(component.checked == true) {
        newExp = newExp.replace("{" + (i + 1) + "}", "true");
      }else {
        newExp = newExp.replace("{" + (i + 1) + "}", "false");
      }
    }else {
      newExp = newExp.replace("{" + (i + 1) + "}", component.value);
    }
  }
  return eval(newExp);
}

function constraint(id,message){
	if (message == null) {
		message = "\u6821\u9a8c\u4e0d\u901a\u8fc7";
	}
	//var t1 = document.getElementById(id);
	var t1 = eval("defaultname." + id); //for ie and firefox
	var tp=t1.parentNode;
	var newdiv;
	if(!document.getElementById(id+'div'))
	{
    	newdiv =document.createElement("div");
    	newdiv.innerHTML="<img id=\"" + id + "div_img" + "\" src=\"/mync/images/flash.gif\" alt="+message+" >";
    	newdiv.id=id+'div';
    	newdiv.style.display="";
    	
    	with(newdiv.style)
    	{
    		position = "absolute";
    		width = "20px";
    		height = "20px";
    	}
    	tp.appendChild(newdiv);
	}
	else 
	{
	    newdiv = document.getElementById(id+'div');
		var img = document.getElementById(id+'div_img');	
		img.alt=message;
		newdiv.style.display="";
	}

}

function clearConstraint(id)
{
	var t1 = document.getElementById(id+'div');
	if(t1)
	{
		t1.style.display = "none";
	}	
}


function validateAll()
{
    var component = event.srcElement;
    if (event.type == "mouseout") {
        component = event.fromElement;
    }
	for(var i = 0; i < component.validationList.length; i++)
	{
		var param = component.validationList[i][0];
		param.currentComp = component;
		var validateFunc = component.validationList[i][1];
		if (!validateFunc.call(param)) {
			return true;
		}
	}
	clearConstraint(component.name);
	return true;
		
}

function isArrayEquals(a,b)
{
    if (a == b)
    {
        return true;
    }
    
    if (typeof(a) != typeof(b))
    {
        return false;
    }
    
    if (typeof(a) == "function")
    {
        return a.toString() == b.toString();
    }
    
    if (typeof(a) == "object")
    {
    	if(a.constructor == Array && b.constructor == Array)
    	{
    		if(a.length == b.length)
    		{
    			for(var i =0; i < a.length; i++)
    			{
    				if(!isArrayEquals(a[i],b[i]))
    					return false;
    			}
    			return true;
    		}
    		return false;
    	}
    	if(a.constructor != Array && b.constructor != Array)
    	{
    		if(typeof(a) == "object" && typeof(b) == "object")
    		{
    			return a.equals(b);
    		}
    		else if(typeof(a) != "object" && typeof(b) != "object")
    		{
    		    return a==b;
    		}
    		return false;		
    	}
    }
	return false;
}

function registerConstraint(ui)
{
    //only valid in ie.
    try {
        if(ui.detachEvent)  //for ie
        {
            ui.detachEvent("onmouseout", validateAll);
            ui.attachEvent("onmouseout", validateAll);
        }
        else
        {
            ui.removeEventListener("onmouseout", validateAll, false);
            ui.addEventListener("onmouseout", validateAll, false);
        }
    } catch (e) {}
    try {
        if(ui.detachEvent)  //for ie
        {
            ui.detachEvent("onblur", validateAll);
            ui.attachEvent("onblur", validateAll);
        }
        else
        {
            ui.removeEventListener("onblur", validateAll, false);
            ui.addEventListener("onblur", validateAll, false);
        }
    } catch (e) {}
}
