//Global variable
var ContextPath = "";

var DEFAULT_CHECK_WARNING_MODE = 1;// 1 or 2
var DEFAULT_CHECK_WARNING_ICO_SRC="/js/standard_msg_error.gif";
var DEFAULT_CHECK_WARNING_TIMEOUT = 99999999;
var DEFAULT_DATE_PATTERN = "yyyy-M-d"

function LogMJS() {
	this.enableDebug = false;
	this.enableInfo = true;
	this.enableError = true;
	this.enableWarn = true;
}
LogMJS.prototype.debug = function(msg) {
	if(this.enableDebug) {
		this.println(this.getPrefix()+" LogMJS.debug: "+msg);
	}
}
LogMJS.prototype.info = function(msg) {
	if(this.enableInfo) {
		//alert(msg);
		window.status = this.getPrefix()+" LogMJS.info: "+msg;
		window.setTimeout("window.status = window.defaultStatus;",10000);
	}
}
LogMJS.prototype.error = function(msg) {
	if(this.enableError) {
		this.println(this.getPrefix()+" LogMJS.error: "+msg);
	}
}
LogMJS.prototype.warn = function(msg) {
	if(this.enableWarn) {
		this.println(this.getPrefix()+" LogMJS.warn: "+msg);
	}
}
LogMJS.prototype.getPrefix = function() {
	//var d = new Date();
	return "";
}

LogMJS.prototype.println = function(msg) {
  var console = document.getElementById("LogMJS.console");
  if(console == null) {
    console = this.createConsole();
  }
  console.value+=msg+"\n";
}

LogMJS.prototype.clean = function() {
  var console = document.getElementById("LogMJS.console");
  if(console != null) {
	console.value=""
  }
}

LogMJS.prototype.createConsole = function(msg) {
  document.body.insertAdjacentHTML("beforeEnd","<TextArea rows=5 cols=60 id=\"LogMJS.console\" AutoResizeHeight=\"false\"></TextArea>");
  var console = document.getElementById("LogMJS.console");
  return console;
}

var logger = new LogMJS();

/*select the default option
  param objName the object name
  param defaultValue the selected option's value.the default delimiter ","
  param delimiter the default delimiter ","
  param fireEvent if true fire the event
  return true/false
  Company: oaking
  author: cnng
  version 1.1
*/
function selectDefaultValue(objName,defaultValue,delimiter,fireEvent) {

	if(delimiter == null) {
		delimiter = ",";
	}
	if(fireEvent == null) {
		fireEvent = true;
	}else {
		if(fireEvent || fireEvent =="true") {

		}
	}
	defaultValue = defaultValue.toString();
	var defaultValues = defaultValue.split(delimiter);
	var objs = getElementsByFullName(objName);
	var flag = false;

	for(var i = 0;i<objs.length;i++) {
		var oType = objs[i].type;
		if(oType == "checkbox" || oType == "radio") {
			if(isExist(objs[i].value,defaultValues)) {
				objs[i].checked = true;
				if(oType == "radio") {
					break;
				}
				flag = true;
				continue;
			}
		}
	    if(oType == "select-one" || oType =="select-multiple") {
			var options = objs[i].options;
			for(var k = 0;k<options.length;k++) {
				if(isExist(options[k].value,defaultValues)) {
					options[k].selected = true;;
					if(oType =="select-one") {
						break;
					}
					flag = true;
				}
			}
			break;
		}
	}
	return flag;
}

//check if the value exist in values
function isExist(oValue,oValues) {
	if(oValues!=null) {
		for(var i=0;i<oValues.length;i++) {
			if(oValues[i]==oValue) {
				return true;
			}
		}
	}
	return false;
}

//check the domain if it is checked
function isChecked(doMainName,minChecked) {

	if(minChecked==null) {
		minChecked = 1;
	}

	var checkedCount = 0 ;

	var obj = getElementsByFullName(doMainName);
	for(var i=0;i<obj.length;i++) {
		if(obj[i].checked==true) {
			checkedCount++;
			if(checkedCount>=minChecked) {
				return true;
			}
		}
	}
	return false;
}

/*return the selected value, if it is mulitple,then return an array
  param objName the Object name
  param delimiter default ","
  return a string or an array
  Company: oaking
  author: cnng
  version 1.1
*/
function getSelectedValue(objName,delimiter) {
	if(delimiter == null) {
		delimiter = ",";
	}

	var values = "",tmpdelimiter = "";
	var objs = getElementsByFullName(objName);

	for(var i = 0;i<objs.length;i++) {
		var oType = objs[i].type;
		if(oType == "checkbox" || oType == "radio") {
			if(objs[i].checked) {
				values+=tmpdelimiter+objs[i].value;
				if(oType == "radio") {
					break;
				}
				tmpdelimiter = delimiter;
				continue;
			}
		}
	    if(oType == "select-one" || oType =="select-mulitple") {
			var options = objs[i].options;
			for(var k = 0;k<options.length;k++) {
				if(options[k].selected) {
					values+=tmpdelimiter+options[k].value;
					if(oType =="select-one") {
						break;
					}
					tmpdelimiter = delimiter;
				}
			}
			break;
		}
	}

	return values;
}
function getFieldValues(objName) {
	var values = new Array();
	var objs = getElementsByFullName(objName);

	for(var i = 0;i<objs.length;i++) {
		var oType = objs[i].type;
		if (objs[i].disabled==true)
		{
			continue;
		}
		if(oType == "checkbox" || oType == "radio") {
			if(objs[i].checked) {
				values.push(objs[i].value);
				continue;
			}
		}
	    if(oType == "select-one" || oType =="select-mulitple") {
			var options = objs[i].options;
			for(var k = 0;k<options.length;k++) {
				if(options[k].selected) {
					values.push(options[k].value);
				}
			}
		}
	}

	return values;
}

/*
	return a object array
	param: fullName the object full name
	example : getElementsByFullName("form.username")
	version 1.0
*/
function getElementsByFullName(fullName) {
	var objs;

	var pathLen = fullName.lastIndexOf(".");

	if(pathLen<0) {
		objs = document.getElementsByName(fullName);
	} else {
		var elementPath = fullName.substring(0,pathLen);
		var elementName = fullName.substr(pathLen+1);

		objs = new Array();

		var tempObjs = eval(elementPath+".elements");
		for(var i=0;i<tempObjs.length;i++) {
			if(tempObjs[i].name==elementName) {
				objs.push(tempObjs[i]);
			}
		}
	}

	return objs;
}

/* check if it is a number
	param Num the number value
	param maxLen the max length,default -1
	param maxPoint the max length of point,default -1
	author cnng 2005-4-27
	version 2.0
*/
function isNumber(Num,maxLen,maxPoint) {

	if(Num==null) {
		return false;
	}
	var number = Num.toString();
        var l = number.length;
        var i = 0;
        var havePoint = false;
		var haveE = false;
		var nLen = 0;
		var pointLen = 0;
        var c;
        if(l<=0) {
			return false;
		} else {
            switch (number.charAt(0)) {
            case '.':
				nLen++;
                havePoint = true;
            case '-':
            case '+':
                i++;
                break;
            }
            for (; i <l; i++) {
                c = number.charAt(i);
                if(c>='0' && c<='9') {
					if(havePoint) {
						pointLen++;
					}
					nLen++;
                    continue;
                }else if(c=='.' && !havePoint) {
                    havePoint = true;
                    continue;
                }else {
                    return false;
                }
            }
        }
			
		if(maxLen!=null) {
			if(maxLen!=-1) {
				if(nLen>maxLen) {
					return false;
				}
			}
		}
		if(maxPoint!=null) {
			if(maxPoint!=-1) {
				if(havePoint) {
					if((pointLen)>maxPoint) {
						return false;
					}
				}
			}
		}
        return true;
}

//check it is a date
function isDate(date) {

	if(date==null || date=="") {
		return false;
	}

	date = date.toString();

	if(date.match( /^(\d{4})-(\d{1,2})-(\d{1,2})$/)) {
		if(RegExp.$1<=0) return false;
		if(RegExp.$2<=0 || RegExp.$2>12) return false;
		if(RegExp.$3<=0 || RegExp.$3>31) return false;
	}
	else {
		return false;
	}

	return true;

}

//check it is a time
function isTime(time) {
	if(time==null || time=="") {
		return false;
	}

	time = time.toString();

	if(time.match( /^(\d{1,2}):(\d{1,2})$/)) {
		if(RegExp.$1<0 || RegExp.$1>=24) return false;
		if(RegExp.$2<0 || RegExp.$2>=60) return false;
	}
	else {
		return false;
	}

	return true;
}

//check it is a email
function isEmail(email) {

	if(email==null || email=="") {
		return false;
	}

	//email = email.toString();

	if(email.match( /^.+@.+\..+$/)) {
		return true;
	}
	else {
		return false;
	}

	return false;

}

function trim(str) {

	if(str==null || str=="") {
		return str;
	}

	str = str.replace(/^ +/,"");
	str = str.replace(/ +$/,"");
	return str;
}

//check it is empty ("")
function isEmpty(str) {

	if(str == null ) {
		return true;
	}

	if(trim(str)=="") {
		return true;
	}

	return false;
}

/*
 return the offset and resect the domain's value
*/
function exactLen(doMainName,maxLen,minLen) {

	if(minLen==null) {
		minLen=0;
	}

	var obj = getElementsByFullName(doMainName);
	var sLen = 0;
	for(var i=0;i<obj.length;i++) {
		sLen = calclength(obj[i].value);
		if(sLen>maxLen) {
			obj[i].value=subs(obj[i].value,maxLen);
			obj[i].focus();
			return sLen-maxLen;
		}
		if(sLen<minLen) {
			return sLen-minLen;
		}
	}
	return 0;
}

//
function subs(s,len)
{
	var count = 0;
	for (var i=0;i<s.length;i++)
	{
		if (s.charAt(i) >=' ' && s.charAt(i)<= '~')
		{
			count ++;
			if (count == len) {
				return s.substring(0,i+1);
			}
		} else
		{
			if (count >= len -1) {
				return s.substring(0,i);
			}
			count = count +2;

		}
	}
	return s;
}

//
 function calclength(s)
    {
        var count = 0;
        for (var i=0;i<s.length;i++)
        {
            if (s.charAt(i) >=' ' && s.charAt(i)<= '~')
            {
             count ++;
            } else
            {
             count = count +2;
            }
        }
        return count;

}

/*process the form at the background.
   param: formName  the form name,default is current from or first form
   example: <form name="formName" action="save.*" onsubmit="return doBackSubmit();">

   Company: oaking
   author: cnng
   version 1.0
*/
function doBackSubmit(formName) {
	var oForm;
	try {
		if(formName==null) {
			oForm = event.srcElement;
			if(oForm.tagName!="FORM") {
				oForm = document.forms[0];
			}
		} else {
			oForm  = document.forms(formName);
		}

		var processor = document.getElementById("BackGroundSubmit");
		if(processor==null) {
			document.body.insertAdjacentHTML("beforeEnd","<iframe id='BackGroundSubmit' name='BackGroundProcessor' src='about:back' width='0' height='0'></iframe>");
		}
		var oTarget = oForm.target;
		oForm.target = "BackGroundProcessor";
		oForm.submit();
		oForm.target = oTarget;
	}
	catch (e) {
		//window.status="Error in doBackSubmit"+e;
		throw e;
	}
	finally {
		return false;
	}

}

/*
 *uesd to test
 *see doBackSubmit()
*/
function testDoBackSubmit(formName) {
	var oForm;
	try {
		if(formName==null) {
			oForm = event.srcElement;
			if(oForm.tagName!="FORM") {
				oForm = document.forms[0];
			}
		} else {
			oForm  = document.forms(formName);
		}

		var processor = document.getElementById("TestBackGroundSubmit");
		if(processor==null) {
			document.body.insertAdjacentHTML("beforeEnd","<iframe id='TestBackGroundSubmit' name='TestBackGroundProcessor' src='about:back' width='500' height='400'></iframe>");
		}

		var oTarget = oForm.target;
		oForm.target = "TestBackGroundProcessor";
		oForm.submit();
		oForm.target = oTarget;
	}
	catch (e) {
		//window.status="Error in doBackSubmit"+e;
		throw e;
	}
	finally {
		return false;
	}

}

/*
	check the form,default is current from or first form
	author cnng
	version 1.0
*/
function checkForm(formName) {
	var oForm;

	if(formName==null || !formName) {
		try {
			oForm = event.srcElement;
		} catch (e) {};
		if(oForm==null) {
			try {
				oForm = event.target;
			} catch (e) {};
		}
		if(oForm==null || oForm.tagName!="FORM") {
			oForm = document.forms[0];
		}
	} else {
		oForm  = document.forms[formName];
	}
	var fields = oForm.elements;

	var fieldsLen = fields.length;
	for(var i=0;i<fieldsLen;i++) {
		var obj = fields[i];
			if(!obj.disabled) {
				  if(!checkObj(obj)) {
					  return false;
				  }
			}
	}

	return true;
}
//used to test
function testCheckForm(formName) {
	try {
		if(checkForm(formName)) {
			var oForm;
			if(formName==null || !formName) {
				try {
					oForm = event.srcElement;
				} catch (e) {};
				if(oForm==null) {
					try {
						oForm = event.target;
					} catch (e) {};
				}
				if(oForm==null || oForm.tagName!="FORM") {
					oForm = document.forms[0];
				}
			} else {
				oForm  = document.forms[formName];
			}
			fname = oForm.name;
			fname = fname == null?"":fname;
			alert("The form["+fname+"] was passable");
		}
	}
	catch (e){
		alert(e);
	}
	return false;
}

//check it
function checkObj(obj) {
	//check it if return true
	if(checkObjWHere(obj)) {
		return checkObjCheckCode(obj)&&
				checkObjIsNotNull(obj)&&checkObjIsNotEmpty(obj)&&
				checkObjIsInteger(obj)&&checkObjIsNumber(obj)&&
				checkObjIsDate(obj)&&checkObjIsTime(obj)&&
				checkObjIsMoney(obj)&&checkObjIsEmail(obj);
	}
	else {
		return true;
	}
}

//check it but ignore the CheckWHere
function checkObjNoWhere(obj) {

        return checkObjCheckCode(obj)&&
                        checkObjIsNotNull(obj)&&checkObjIsNotEmpty(obj)&&
                        checkObjIsInteger(obj)&&checkObjIsNumber(obj)&&
                        checkObjIsDate(obj)&&checkObjIsTime(obj)&&
                        checkObjIsMoney(obj)&&checkObjIsEmail(obj);

}

/*run the object.CheckCode
  example: <input name="username" type="text" CheckCodeŁ˝"return checkFunction();">
*/
function checkObjCheckCode(obj) {
	var code;
	code = obj.getAttribute("CheckCode");
	if(code!=null) {
              var proxy;
			  var result = null;
              try {
                  eval("proxy = function(source){"+code+"};");
                  result = proxy(obj);
              }catch(e) {
                  alert("Executing specified code error:["+e+"]\n"+code);
                  //throw e;
				  return false;
              }
			  if(result==undefined || result==null) {
				  return true;
			  }else {
				  if(typeof(result)=="string") {
					//return false;
					return showCheckWarning(result,obj);
				  }else if(typeof(result)=="boolean") {
					return result;
				  }else {
					return result;
				  }
			  }
	}
        return true;
}

/*check it is not null,if it's "" return false
  example: <input name="username" type="text" IsNotNull="please input the username!">
*/
function checkObjIsNotNull(obj) {
	var msg;
	msg = obj.getAttribute("IsNotNull");

	if(msg!=null) {
		if(obj.value==null || obj.value=="") {
			return showCheckWarning(msg,obj);
		}
	}

	return true;
}

/*check it is not empty
  example: <input name="username" type="text" IsNotEmpty="please input the username!">
*/
function checkObjIsNotEmpty(obj) {
	var msg;
	msg = obj.getAttribute("IsNotEmpty");

	if(msg!=null) {
		if(isEmpty(obj.value)) {
			return showCheckWarning(msg,obj);
		}
	}

	return true;
}

/*check it is a integer
  example: <input name="username" type="text" IsInteger="please input an integer!">
*/
function checkObjIsInteger(obj) {
	var msg;
	msg = obj.getAttribute("IsInteger");

	if(msg!=null) {
		var maxValue = obj.getAttribute("MaxValue");
		var minValue = obj.getAttribute("MinValue");
		if(maxValue!=null) {
			if(isNaN(maxValue)) {
				logger.debug("Error number of MaxValue: " +maxValue);
				throw "Error number of MaxValue: " +maxValue;
			}
		}
		if(minValue!=null) {
			if(isNaN(minValue)) {
				logger.debug("Error number of MinValue: " +minValue);
				throw "Error number of MinValue: " +minValue;
			}
		}

		if(!isNumber(obj.value,-1,0)) {
			return showCheckWarning(msg,obj);
		}
		if(maxValue!=null) {
			if(Number(obj.value)>Number(maxValue)) {
				return showCheckWarning(msg,obj);
			}
		}
		if(minValue!=null) {
			if(Number(obj.value)<Number(minValue)) {
				return showCheckWarning(msg,obj);
			}
		}
	}

	return true;
}

/*check it is a number
  example: <input name="username" type="text" IsNumber="please input a number!" MaxValue=10 MinValue=1 MaxLen=10 MaxPoint=2>
*/
function checkObjIsNumber(obj) {
	var msg;
	msg = obj.getAttribute("IsNumber");
	if(msg!=null) {
		var maxLen,maxValue,minValue,maxPoint;
		var maxLen = obj.getAttribute("MaxLen");
		var maxValue = obj.getAttribute("MaxValue");
		var minValue = obj.getAttribute("MinValue");
		var maxPoint = obj.getAttribute("MaxPoint");

		if (maxLen==null) {
			maxLen = -1;
		} else {
			if(isNaN(maxLen)) {
				logger.debug("Error number of MaxLen: " +maxLen);
				throw "Error number of MaxLen: " +maxLen;
			}
		}
		if (maxPoint==null) {
			maxPoint = -1;
		} else {
			if(isNaN(maxPoint)) {
				logger.debug("Error number of MaxPoint: " +maxPoint);
				throw "Error number of MaxPoint: " +maxPoint;
			}
		}
		if(maxValue!=null) {
			if(isNaN(maxValue)) {
				logger.debug("Error number of MaxValue: " +maxValue);
				throw "Error number of MaxValue: " +maxValue;
			}
		}
		if(minValue!=null) {
			if(isNaN(minValue)) {
				logger.debug("Error number of MinValue: " +minValue);
				throw "Error number of MinValue: " +minValue;
			}
		}
		if(!isNumber(obj.value,maxLen,maxPoint)) {
			return showCheckWarning(msg,obj);
		}
		if(maxValue!=null) {
			if(Number(obj.value)>Number(maxValue)) {
				return showCheckWarning(msg,obj);
			}
		}
		if(minValue!=null) {
			if(Number(obj.value)<Number(minValue)) {
				return showCheckWarning(msg,obj);
			}
		}
	}

	return true;
}

/*check it is a Date
  example: <input name="username" type="text" IsDate="please input a date!">
*/
function checkObjIsDate(obj) {
	var msg;
	msg = obj.getAttribute("IsDate");

	if(msg!=null) {
		var pattern = obj.getAttribute("Pattern");
		if(pattern==null) {
			pattern = obj.getAttribute("DatePattern");
		}
		if(pattern==null) {
			pattern = DEFAULT_DATE_PATTERN;
		}
		var dateFormat = new DateFormat();
		if(!dateFormat.isDate(obj.value,pattern)) {
			return showCheckWarning(msg,obj);
		}
	}

	return true;
}

/*check it is a Time
  example: <input name="username" type="text" IsTime="please input a time">
*/
function checkObjIsTime(obj) {
	var msg;
	msg = obj.getAttribute("IsTime");

	if(msg!=null) {
		if(!isTime(obj.value)) {
			return showCheckWarning(msg,obj);
		}
	}

	return true;
}

/*check is it a Email
  example: <input name="username" type="text" IsEmail="please input a Eamil">
*/
function checkObjIsEmail(obj) {
	var msg;
	msg = obj.getAttribute("IsEmail");

	if(msg!=null) {
		if(!isEmail(obj.value)) {
			return showCheckWarning(msg,obj);
		}
	}

	return true;
}

/*check it is a money date
  example: <input name="username" type="text" IsMoney="please input a money!">
*/
function checkObjIsMoney(obj) {
	var msg;
	msg = obj.getAttribute("IsMoney");

	if(msg!=null) {
		if(!isNumber(obj.value,-1,2)) {
			return showCheckWarning(msg,obj);
		}
	}

	return true;
}

var mouseOverDefaultCheckWarningBody=false;
var defaultCheckWarningHandle = null;

function setDefaultCheckWarningMode(mode) {
	DEFAULT_CHECK_WARNING_MODE = mode;
}

function hiddenDefaultCheckWarning() {
	var d = new Date();
	var id="";
	id += (d.getMonth() + 1) + ".";
	id += d.getDate() + ".";
	id += d.getYear();
	id +=".checkformwarning";
	var div = document.getElementById(id);
	if(div!=null) {
		if(mouseOverDefaultCheckWarningBody) {
			defaultCheckWarningHandle = window.setTimeout("hiddenDefaultCheckWarning()", DEFAULT_CHECK_WARNING_TIMEOUT);
			return;
		}
		//div.setAttribute("clipHeight",-1);
		//div.style.display = "none";
		//mouseOverDefaultCheckWarningBody=false;
		hiddenDefaultCheckWarning1();
	}
}

function hiddenDefaultCheckWarning1() {
	var d = new Date();
	var id="";
	id += (d.getMonth() + 1) + ".";
	id += d.getDate() + ".";
	id += d.getYear();
	id +=".checkformwarning";
	var div = document.getElementById(id);
	if(div!=null) {
		div.setAttribute("clipShow","false");
		var h = div.offsetHeight;
		var clipHeight = div.getAttribute("clipHeight");
		var top = getElementTop(div);
		if(clipHeight==null || clipHeight==-1) {
			clipHeight = h;
			top = parseInt(div.getAttribute("clipTop"));
		}
		clipHeight = parseInt(clipHeight);
		clipHeight--;

		if(clipHeight>0) {
			div.style.clip = "rect(auto,auto,"+clipHeight+"px,auto)";
			div.style.top =top+1;
			div.setAttribute("clipHeight",clipHeight);
			if(clipHeight==1) {
				window.setTimeout(hiddenDefaultCheckWarning1,20);
			}else {
				window.setTimeout(hiddenDefaultCheckWarning1,2);
			}
		}else {
			mouseOverDefaultCheckWarningBody=false;
			div.style.display = "none";
			div.setAttribute("clipHeight",-1);
		}
	}
}

function showDefaultCheckWarning1() {
   var d = new Date();
	var id="";
	id += (d.getMonth() + 1) + ".";
	id += d.getDate() + ".";
	id += d.getYear();
	id +=".checkformwarning";
	var div = document.getElementById(id);
	if(div!=null && div.style.display!="none") {
		if(div.getAttribute("clipShow")==null || div.getAttribute("clipShow")=="false")
			return;
		var h = div.offsetHeight;
		var clipHeight = div.getAttribute("clipHeight");
		var top = getElementTop(div);
		if(clipHeight==null || clipHeight==-1) {
			clipHeight = 0;
			top = parseInt(div.getAttribute("clipTop"));
			top+=h;
		}
		clipHeight = parseInt(clipHeight);
		clipHeight++;
		if(clipHeight<=h) {
			div.style.clip = "rect(auto,auto,"+clipHeight+"px,auto)";
			div.style.top =top-1;
			div.setAttribute("clipHeight",clipHeight);
			if(clipHeight==1) {
				window.setTimeout(showDefaultCheckWarning1,50);
			}else {
				window.setTimeout(showDefaultCheckWarning1,5);
			}
		}else {
			div.setAttribute("clipHeight",-1);
		}
	}
}

function showDefaultCheckWarning(msg,obj) {
	//try set focus
	try {
	  obj.focus();
	  if(obj.type != "button") {
		obj.select();
	  }
	}catch(e) {	//alert(e);
	}
	if(DEFAULT_CHECK_WARNING_MODE==1) {
		try {		
			var d = new Date();
			var id="";
			id += (d.getMonth() + 1) + ".";
			id += d.getDate() + ".";
			id += d.getYear();
			id +=".checkformwarning";
			var id_msgbody = id+".msg";
			var id_iframe = id+".iframe";
			var div;
			var docu = document;
			div = docu.getElementById(id);
			if(div==null) {
				var cssText = "background-color:#FFEEEE;border:1px solid #ff5e00;z-index:-1;";
				if(DEFAULT_CHECK_WARNING_ICO_SRC!=null && DEFAULT_CHECK_WARNING_ICO_SRC!="") {
					cssText+="background-image:url("+ContextPath+DEFAULT_CHECK_WARNING_ICO_SRC+");";
					cssText+="background-repeat:no-repeat;";
				}
				div = docu.createElement("DIV");
				div.style.cssText = cssText;
				var msgbody = docu.createElement("DIV");
				msgbody.id = id_msgbody;
				div.appendChild(msgbody);
				cssText="padding-left:18px;text-align:left;";
				cssText+="padding-top:2px;";
				msgbody.style.cssText = cssText;
				var t = function(){hiddenDefaultCheckWarning1();};
				var t1 = function(){mouseOverDefaultCheckWarningBody=false;};
				var t2 = function(){mouseOverDefaultCheckWarningBody=true;};
				if(window.addEventListener) {
					div.addEventListener("click",t,false);
					div.addEventListener("mouseout",t1,false);
					div.addEventListener("mouseover",t2,false);
				}else {
					div.attachEvent("onclick",t);
					div.attachEvent("onmouseout",t1);
					div.attachEvent("onmouseover",t2);
				}
				div.style.zIndex = 99999;
				var oiframe = docu.createElement("iframe");
				oiframe.id = id_iframe;
				//oiframe.src = false;
				oiframe.style.position = "absolute";
				oiframe.style.visibility = "inherit";
				oiframe.style.border = "0px"; 
				oiframe.style.top = "0px"; 
				oiframe.style.left = "0px"; 
				oiframe.style.width = "0px"; 
				oiframe.style.height = "0px"; 
				oiframe.style.zIndex = -1;
				oiframe.style.filter = "alpha(opacity=0, finishOpacity=0, style=1, startX=100)";
				
				div.id=id;
				docu.body.appendChild(div);
				div.appendChild(oiframe);
				div.style.position="absolute";
				div.style.display="none";
				div.style.cursor="pointer";
			}
			div.source = obj;
			var textBody = docu.getElementById(id_msgbody);
			var oif = docu.getElementById(id_iframe);
			textBody.innerHTML=msg;
			var bodyWidth = docu.body.scrollWidth;
			var textBodyWidth,x,y;
			div.style.display="block";
			x = getElementLeft(obj);
			y = getElementTop(obj)-div.offsetHeight;
			textBodyWidth = div.offsetWidth;
			if(bodyWidth<x+textBodyWidth) {
				x-=x+textBodyWidth-bodyWidth;
			}
			if(x<0)  {
			    x = 0;
			}
			div.style.left=x;
			div.style.top=y;
			oif.style.width = div.offsetWidth;
			oif.style.height = div.offsetHeight;
			div.setAttribute("clipTop",y);
			div.setAttribute("clipShow","true");
			showDefaultCheckWarning1();
			var bodyHeight = document.body.offsetHeight;
			var srollY = document.body.scrollTop;
			var bottomY = srollY+bodyHeight;
			var eTopY = getElementTop(div);
			var eHeight = div.offsetHeight;
			var eBootomY = eTopY+eHeight;
			if(eTopY<srollY || eTopY>bottomY) {
				div.scrollIntoView(false);
			}
			if(eBootomY<srollY || eBootomY>bottomY) {
				div.scrollIntoView(false);
			}
			//try clean
			try{window.clearTimeout(defaultCheckWarningHandle);}
			catch (e){};			
			defaultCheckWarningHandle = window.setTimeout("hiddenDefaultCheckWarning1()", DEFAULT_CHECK_WARNING_TIMEOUT);
			return false;
		}
		catch (e) {
			alert(e);
		}
	}
	window.status = msg;
	alert(msg);
	window.status = window.defaultStatus;
	return false;
}

//display the warning
function showCheckWarning(msg,obj) {
	//try display the local warning 
	if(typeof(showLocalWarning) == "function") {
		var result;
		result = showLocalWarning(msg,obj);
		if(result == undefined){
			return false;
		}
		return result;
	}
	return showDefaultCheckWarning(msg,obj);
}

function checkObjWHere(source) {
	var where  = source.getAttribute("CheckWhere");
	if(where!=null) {
		where = where.replace("IsNotNull","((source.value!=\"\"))");
		where = where.replace("IsNotEmpty","(!isEmpty(source.value))");
		where = where.replace("IsInteger","(isNumber(source.value,-1,0))");
		where = where.replace("IsNumber","(isNumber(source.value))");
		where = where.replace("IsDate","(isDate(source.value))");
		where = where.replace("IsTime","(isTime(source.value))");
		where = where.replace("IsEmail","(isEmail(source.value))");
		where = where.replace("IsMoney","(isNumber(source.value,-1,2))");
		//alert(where);
		return eval(where);
	}

	return true;
}

/*
 * get the url parameter
 * author cnng 2005-04-26
 */
function getParameter() {

	var argCount = arguments.length;	//
	if ( argCount == 0 ) return null;

	var sParam = arguments[0];		//
	var sSource = "";
	sSource = location.search;

	if(sSource=="") return null;

	sSource = sSource.replace(/^\?/,"");
	var s = sSource.split("&");
	for(var i=0;i<s.length;i++) {
		if(s[i]!=null) {
			if(s[i].indexOf(sParam+"=")==0) {
				var p = s[i].split("=");
				return p[1];
			}
		}
	}

	return null;
}

/**
	automatic resize the iframe's  size
	example:
	<iframe name="ifrm" id="ifrm" src="product/11.htm" width="100%" height="800" frameBorder=0
	scrolling=no onload="resizeIFRAME(obj)" oncontextmenu="return false" maxHeight="1"  maxHeight="2"></iframe>
*/
function resizeIFRAME(ifrm,side,maxWait) {
	try {
		var windowContent = ifrm.contentWindow;
		var height = 0;
		var width = 0;
		if(windowContent !=null) {			
			height = windowContent.document.body.scrollHeight;
			width = windowContent.document.body.scrollWidth;
		}else {
			height = ifrm.document.body.scrollHeight;
			width = ifrm.document.body.scrollWidth;
		}
		var maxHeight = ifrm.getAttribute("maxHeight");
		if(maxHeight!=null) {
			maxHeight = parseInt(maxHeight);
			if(height>maxHeight) {
				height = maxHeight;
			}
		}
		var maxWidth = ifrm.getAttribute("maxWidth");
		if(maxWidth!=null) {
			maxWidth = parseInt(maxWidth);
			if(width>maxWidth) {
				width = maxWidth;
			}
		}
		//height +=ifrm.offsetHeight-ifrm.clientHeight;
		//logger.error(ifrm.id+" width:"+width+" height:"+height+" time:"+ifrm.getAttribute("ResizeIFRAME_WaitTime"));
		//logger.error("i:"+ifrm.sourceIndex);
		if(side==null) side = "all";
		if(!(side == "all" || side == "width" || side == "height")) {
			throw "Param error:"+side
		}
		if(side == "all" && width>0 && height>0) {
			ifrm.height = height;
			ifrm.width = width;
		}else if(side == "width" && width>0) {
			ifrm.width = width;
		}else if(side == "height" && height>0) {
			ifrm.height = height;
		}else {
			if(maxWait == null) {
				maxWait = 1000;
			}
			if(maxWait==-1) {
				window.setTimeout(new callerWrapFunction(resizeIFRAME,ifrm,side,maxWait), 100);
			}else {				
				var waitTime = ifrm.getAttribute("ResizeIFRAME_WaitTime");
				if(waitTime!=null) {
					waitTime = parseInt(waitTime)+1;
				}else {
					waitTime = 1;
				}
				if(waitTime > maxWait) {
					//ifrm.height = height;
					//ifrm.width = width;
					return;
				}else {
					ifrm.setAttribute("ResizeIFRAME_WaitTime",waitTime);
					//document.title = waitTime;
					//window.setTimeout("resizeIFRAMEByindex('"+ifrm.sourceIndex+"')", 100);
					window.setTimeout(new callerWrapFunction(resizeIFRAME,ifrm,side,maxWait), 100);
				}
			}
		}
	} catch(e) {
		//
		//logger.error("err:"+e);
		window.setTimeout(new callerWrapFunction(resizeIFRAME,ifrm,side,maxWait), 100);
	}
}

		/**  
          *     @desc: Call wrapper
          *     @type: private
          *     @param: funcObject - action handler
          *     @param: object - user data
          *     @param: object1 - user data
          *     @param: object2 - user data
		  *     @returns: function handler
		  *     @topic: 0  
          */
function callerWrapFunction(funcObject,object,object1,object2){
	this.handler = function(){
		return funcObject(object,object1,object2);
	};
	return this.handler;
}

function resizeIFRAMEByindex(index,side,maxWait) {
	var ifrm;
	try {
		ifrm =  document.all[parseInt(index)];
		resizeIFRAME(ifrm,side,maxWait);
	}
	catch(e) {
		alert("Could not get Object,sourceIndex:"+index);
	}
}

function getElementLeft(e){
    var l=e.offsetLeft;
	//i don't known
	if(e.tagName=="DIV"){l-=e.scrollLeft};
    while(e=e.offsetParent){
		l+=e.offsetLeft;
	    if(e.tagName=="DIV"){l-=e.scrollLeft};
	};
    return l;
};

function getElementTop(e){
    var t=e.offsetTop;
	if(e.tagName=="DIV"){t-=e.scrollTop};
    while(e=e.offsetParent){
        t+=e.offsetTop;
		if(e.tagName=="DIV"){t-=e.scrollTop;};
    };
    return t;
};

//unite the table's same cells
function uniteSameCells(tableId,subjectIndex) {
  if(subjectIndex==null) {
     subjectIndex=1;
  }
  var oTable = eval(tableId);
  var oTrs = oTable.rows;
  var lTr = oTrs.length;
  var subject = null;
  var subjectTd = null;
  var subjectStartIndex = -1;
  for(var i=0; i<lTr; i++) {
    var oTds = oTrs[i].cells;
    if(oTds.length>=subjectIndex) {
      var tempSubject = oTds[subjectIndex-1].innerText;
      if(subjectStartIndex==-1) {
        subjectTd = oTds[subjectIndex];//
        subject = tempSubject;//
        subjectStartIndex = i;	//
      } else {
        if(subject==tempSubject) {
          //oTds[subjectIndex].innerText="";
          oTds[subjectIndex-1].removeNode(true);
        } else {
          //union the td
          subjectTd.rowSpan = i - subjectStartIndex;
          //
          subjectTd = oTds[subjectIndex-1];
          subject = tempSubject;
          subjectStartIndex = i;
        }
      }
    }
  }

  if(subjectStartIndex = -1) {
    subjectTd.rowSpan = i - subjectStartIndex;
    subjectTd = null;
    subject = null;
    subjectStartIndex = -1;
  }
}

//
function modelessAlert(msg) {
	msg = msg.replace(/\\/g,"\\\\");
	msg = msg.replace(/\n/g,"\\n");
	msg = msg.replace(/\"/g,"\\\"");
	msg = msg.replace(/\'/g,"\\\'");
	window.showModelessDialog("javascript:alert(\""+msg+"\");window.close();","","status:no;resizable:no;help:no;dialogHeight:height:30px;dialogHeight:40px;");
}

function openSelectDept(deptNameElement,deptIDElement,args) {
	this.deptNameElement = deptNameElement;
	this.deptIDElement = deptIDElement;
	this.args = args;
	window.showModalDialog(ContextPath+"/common/showdeptselect.htm", window, "dialogWidth=398px;dialogHeight=475px;scroll=no;status=no;help=no");
}

/*
	example: var v = new Decimal(2);
	var result = v.add(3.11).multiply("0.1");
	alert(result);
	alert((2+3.11)*0.1);
*/	
function Decimal(num) {
	this.value = new Number(num);
}
Decimal.prototype.add = function(n1)  {
	var m=0,s1=n1.toString(),s2=this.value.toString();
	var pos = 0 ;
	if((pos=s1.indexOf('.'))>0) {
		var l = s1.length-pos-1;
		if(l>m)  m=l;
	}
	if((pos=s2.indexOf('.'))>0) {
		var l = s2.length-pos-1;
		if(l>m)  m=l;
	}
	return new Decimal((Number(s1)*Math.pow(10,m)+Number(s2)*Math.pow(10,m))/Math.pow(10,m));
}
Decimal.prototype.subtract = function(n1)  {
	var m=0,s1=n1.toString(),s2=this.value.toString();
	var pos = -1 ;
	if((pos=s1.indexOf('.'))>0) {
		var l = s1.length-pos-1;
		if(l>m)  m=l;
	}
	if((pos=s2.indexOf('.'))>0) {
		var l = s2.length-pos-1;
		if(l>m)  m=l;
	}
	return new Decimal((this.value*Math.pow(10,m)-Number(s1)*Math.pow(10,m))/Math.pow(10,m));
}
Decimal.prototype.multiply = function(n1) {
	var s1=n1.toString(),s2=this.value.toString();
	var m=0;
	try{m+=s1.split(".")[1].length;}catch(e){}
	try{m+=s2.split(".")[1].length;}catch(e){}
	return new Decimal(Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m));
}
Decimal.prototype.divide = function(n1) {
	var m=0,s1=n1.toString(),s2=this.value.toString();
	var pos = -1 ;
	if((pos=s1.indexOf('.'))>0) {
		var l = s1.length-pos-1;
		if(l>m)  m=l;
	}
	if((pos=s2.indexOf('.'))>0) {
		var l = s2.length-pos-1;
		if(l>m)  m=l;
	}
	return new Decimal((Number(s2)*Math.pow(10,m)/Number(s1)*Math.pow(10,m))/Math.pow(10,m*2));
}
Decimal.prototype.toString = function() {
	return (this.value).toString();
}

/*
// initialization hook up

// DOM2
if ( typeof window.addEventListener != "undefined" )
	window.addEventListener( "load", setupAllTabs, false );

// IE
else if ( typeof window.attachEvent != "undefined" ) {
	window.attachEvent( "onload", setupAllTabs );
	window.attachEvent( "onunload", disposeAllTabs );
}

else {
	if ( window.onload != null ) {
		var oldOnload = window.onload;
		window.onload = function ( e ) {
			oldOnload( e );
			setupAllTabs();
		};
	}
	else
		window.onload = setupAllTabs;
}
*/

// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

// HISTORY
// ------------------------------------------------------------------
// July 17, 2008: Added parse function
// May 17, 2003: Fixed bug in parseDate() for dates <1970
// March 11, 2003: Added parseDate() function
// March 11, 2003: Added "NNN" formatting option. Doesn't match up
//                 perfectly with SimpleDateFormat formats, but 
//                 backwards-compatability was required.

// ------------------------------------------------------------------
// These functions use the same 'format' strings as the 
// java.text.SimpleDateFormat class, with minor exceptions.
// The format string consists of the following abbreviations:
// 
// Field        | Full Form          | Short Form
// -------------+--------------------+-----------------------
// Year         | yyyy (4 digits)    | yy (2 digits), y (2 or 4 digits)
// Month        | MMM (name or abbr.)| MM (2 digits), M (1 or 2 digits)
//              | NNN (abbr.)        |
// Day of Month | dd (2 digits)      | d (1 or 2 digits)
// Day of Week  | EE (name)          | E (abbr)
// Hour (1-12)  | hh (2 digits)      | h (1 or 2 digits)
// Hour (0-23)  | HH (2 digits)      | H (1 or 2 digits)
// Hour (0-11)  | KK (2 digits)      | K (1 or 2 digits)
// Hour (1-24)  | kk (2 digits)      | k (1 or 2 digits)
// Minute       | mm (2 digits)      | m (1 or 2 digits)
// Second       | ss (2 digits)      | s (1 or 2 digits)
// AM/PM        | a                  |
//
// NOTE THE DIFFERENCE BETWEEN MM and mm! Month=MM, not mm!
// Examples:
//  "MMM d, y" matches: January 01, 2000
//                      Dec 1, 1900
//                      Nov 20, 00
//  "M/d/yy"   matches: 01/20/00
//                      9/2/00
//  "MMM dd, yyyy hh:mm:ssa" matches: "January 01, 2000 12:30:45AM"
// ------------------------------------------------------------------

function DateFormat() {
	this.MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
	this.DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
}

DateFormat.prototype.LZ = function(x) {return(x<0||x>9?"":"0")+x};

// ------------------------------------------------------------------
// isDate ( date_string, format_string )
// Returns true if date string matches format of format string and
// is a valid date. Else returns false.
// It is recommended that you trim whitespace around the value before
// passing it to this function, as whitespace is NOT ignored!
// ------------------------------------------------------------------
DateFormat.prototype.isDate = function(val,format) {
	var date=this.getDateFromFormat(val,format);
	if (date==0) { return false; }
	return true;
}

// -------------------------------------------------------------------
// compareDates(date1,date1format,date2,date2format)
//   Compare two date strings to see which is greater.
//   Returns:
//   1 if date1 is greater than date2
//   0 if date2 is greater than date1 of if they are the same
//  -1 if either of the dates is in an invalid format
// -------------------------------------------------------------------
DateFormat.prototype.compareDates = function(date1,dateformat1,date2,dateformat2) {
	var d1=this.getDateFromFormat(date1,dateformat1);
	var d2=this.getDateFromFormat(date2,dateformat2);
	if (d1==0 || d2==0) {
		return -1;
		}
	else if (d1 > d2) {
		return 1;
		}
	return 0;
}

// ------------------------------------------------------------------
// formatDate (date_object, format)
// Returns a date in the output format specified.
// The format string uses the same abbreviations as in getDateFromFormat()
// ------------------------------------------------------------------
DateFormat.prototype.formatDate = function(date,format) {
	format=format+"";
	var result="";
	var i_format=0;
	var c="";
	var token="";
	var y=date.getYear()+"";
	var M=date.getMonth()+1;
	var d=date.getDate();
	var E=date.getDay();
	var H=date.getHours();
	var m=date.getMinutes();
	var s=date.getSeconds();
	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
	// Convert real date parts into formatted versions
	var value=new Object();
	if (y.length < 4) {y=""+(y-0+1900);}
	value["y"]=""+y;
	value["yyyy"]=y;
	value["yy"]=y.substring(2,4);
	value["M"]=M;
	value["MM"]=this.LZ(M);
	value["MMM"]=this.MONTH_NAMES[M-1];
	value["NNN"]=this.MONTH_NAMES[M+11];
	value["d"]=d;
	value["dd"]=this.LZ(d);
	value["E"]=this.DAY_NAMES[E+7];
	value["EE"]=this.DAY_NAMES[E];
	value["H"]=H;
	value["HH"]=this.LZ(H);
	if (H==0){value["h"]=12;}
	else if (H>12){value["h"]=H-12;}
	else {value["h"]=H;}
	value["hh"]=this.LZ(value["h"]);
	if (H>11){value["K"]=H-12;} else {value["K"]=H;}
	value["k"]=H+1;
	value["KK"]=this.LZ(value["K"]);
	value["kk"]=this.LZ(value["k"]);
	if (H > 11) { value["a"]="PM"; }
	else { value["a"]="AM"; }
	value["m"]=m;
	value["mm"]=this.LZ(m);
	value["s"]=s;
	value["ss"]=this.LZ(s);
	while (i_format < format.length) {
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		if (value[token] != null) { result=result + value[token]; }
		else { result=result + token; }
		}
	return result;
}
	
// ------------------------------------------------------------------
// Utility functions for parsing in getDateFromFormat()
// ------------------------------------------------------------------
DateFormat.prototype._isInteger = function(val) {
	var digits="1234567890";
	for (var i=0; i < val.length; i++) {
		if (digits.indexOf(val.charAt(i))==-1) { return false; }
		}
	return true;
}
DateFormat.prototype._getInt = function(str,i,minlength,maxlength) {
	for (var x=maxlength; x>=minlength; x--) {
		var token=str.substring(i,i+x);
		if (token.length < minlength) { return null; }
		if (this._isInteger(token)) { return token; }
		}
	return null;
}

DateFormat.prototype.parse = function(val,format) {
	var t = this.getDateFromFormat(val,format);
	if (t==0) {
		return null;
	}else {
		return new Date(t);
	}
}

// ------------------------------------------------------------------
// getDateFromFormat( date_string , format_string )
//
// This function takes a date string and a format string. It matches
// If the date string matches the format string, it returns the 
// getTime() of the date. If it does not match, it returns 0.
// ------------------------------------------------------------------
DateFormat.prototype.getDateFromFormat = function(val,format) {
	val=val+"";
	format=format+"";
	var i_val=0;
	var i_format=0;
	var c="";
	var token="";
	var token2="";
	var x,y;
	var now=new Date();
	var year=now.getYear();
	var month=now.getMonth()+1;
	var date=1;
	var hh=now.getHours();
	var mm=now.getMinutes();
	var ss=now.getSeconds();
	var ampm="";
	
	while (i_format < format.length) {
		// Get next token from format string
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		// Extract contents of value based on format token
		if (token=="yyyy" || token=="yy" || token=="y") {
			if (token=="yyyy") { x=4;y=4; }
			if (token=="yy")   { x=2;y=2; }
			if (token=="y")    { x=2;y=4; }
			year=this._getInt(val,i_val,x,y);
			if (year==null) { return 0; }
			i_val += year.length;
			if (year.length==2) {
				if (year > 70) { year=1900+(year-0); }
				else { year=2000+(year-0); }
				}
			}
		else if (token=="MMM"||token=="NNN"){
			month=0;
			for (var i=0; i<this.MONTH_NAMES.length; i++) {
				var month_name=this.MONTH_NAMES[i];
				if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
					if (token=="MMM"||(token=="NNN"&&i>11)) {
						month=i+1;
						if (month>12) { month -= 12; }
						i_val += month_name.length;
						break;
						}
					}
				}
			if ((month < 1)||(month>12)){return 0;}
			}
		else if (token=="EE"||token=="E"){
			for (var i=0; i<this.DAY_NAMES.length; i++) {
				var day_name=this.DAY_NAMES[i];
				if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
					i_val += day_name.length;
					break;
					}
				}
			}
		else if (token=="MM"||token=="M") {
			month=this._getInt(val,i_val,token.length,2);
			if(month==null||(month<1)||(month>12)){return 0;}
			i_val+=month.length;}
		else if (token=="dd"||token=="d") {
			date=this._getInt(val,i_val,token.length,2);
			if(date==null||(date<1)||(date>31)){return 0;}
			i_val+=date.length;}
		else if (token=="hh"||token=="h") {
			hh=this._getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>12)){return 0;}
			i_val+=hh.length;}
		else if (token=="HH"||token=="H") {
			hh=this._getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>23)){return 0;}
			i_val+=hh.length;}
		else if (token=="KK"||token=="K") {
			hh=this._getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>11)){return 0;}
			i_val+=hh.length;}
		else if (token=="kk"||token=="k") {
			hh=this._getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>24)){return 0;}
			i_val+=hh.length;hh--;}
		else if (token=="mm"||token=="m") {
			mm=this._getInt(val,i_val,token.length,2);
			if(mm==null||(mm<0)||(mm>59)){return 0;}
			i_val+=mm.length;}
		else if (token=="ss"||token=="s") {
			ss=this._getInt(val,i_val,token.length,2);
			if(ss==null||(ss<0)||(ss>59)){return 0;}
			i_val+=ss.length;}
		else if (token=="a") {
			if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
			else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
			else {return 0;}
			i_val+=2;}
		else {
			if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
			else {i_val+=token.length;}
			}
		}
	// If there are any trailing characters left in the value, it doesn't match
	if (i_val != val.length) { return 0; }
	// Is date valid for month?
	if (month==2) {
		// Check for leap year
		if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
			if (date > 29){ return 0; }
			}
		else { if (date > 28) { return 0; } }
		}
	if ((month==4)||(month==6)||(month==9)||(month==11)) {
		if (date > 30) { return 0; }
		}
	// Correct hours value
	if (hh<12 && ampm=="PM") { hh=hh-0+12; }
	else if (hh>11 && ampm=="AM") { hh-=12; }
	var newdate=new Date(year,month-1,date,hh,mm,ss);
	return newdate.getTime();
}

// ------------------------------------------------------------------
// parseDate( date_string [, prefer_euro_format] )
//
// This function takes a date string and tries to match it to a
// number of possible date formats to get the value. It will try to
// match against the following international formats, in this order:
// y-M-d   MMM d, y   MMM d,y   y-MMM-d   d-MMM-y  MMM d
// M/d/y   M-d-y      M.d.y     MMM-d     M/d      M-d
// d/M/y   d-M-y      d.M.y     d-MMM     d/M      d-M
// A second argument may be passed to instruct the method to search
// for formats like d/M/y (european format) before M/d/y (American).
// Returns a Date object or null if no patterns match.
// ------------------------------------------------------------------
DateFormat.prototype.parseDate = function(val) {
	var preferEuro=(arguments.length==2)?arguments[1]:false;
	generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d');
	monthFirst=new Array('M/d/y','M-d-y','M.d.y','MMM-d','M/d','M-d');
	dateFirst =new Array('d/M/y','d-M-y','d.M.y','d-MMM','d/M','d-M');
	var checkList=new Array('generalFormats',preferEuro?'dateFirst':'monthFirst',preferEuro?'monthFirst':'dateFirst');
	var d=null;
	for (var i=0; i<checkList.length; i++) {
		var l=window[checkList[i]];
		for (var j=0; j<l.length; j++) {
			d=this.getDateFromFormat(val,l[j]);
			if (d!=0) { return new Date(d); }
			}
		}
	return null;
}


/**
The TextArea automatic resize
*/
var TEXTAREA_DEFAULT_MIN_HEIGHT = 36;
var TEXTAREA_DEFAULT_MAX_HEIGHT = -1;
function resizeTextAreaHeight(obj) {
		var minHeight = obj.getAttribute("minHeight");
		var maxHeight =  obj.getAttribute("maxHeight");
		if(minHeight==null) {
			minHeight = TEXTAREA_DEFAULT_MIN_HEIGHT;
		}
		if(maxHeight==null) {
			maxHeight = TEXTAREA_DEFAULT_MAX_HEIGHT;
		}
		var objHeight = obj.scrollHeight;
		objHeight +=obj.offsetHeight-obj.clientHeight;
		if(objHeight>obj.clientHeight) {
			//logger.warn("+"+objHeight);
			if(maxHeight==-1) {
				obj.style.height = parseInt(objHeight);
			}else if(maxHeight<objHeight) {
				obj.style.height = parseInt(objHeight);
			}else {
				obj.style.height = maxHeight;
			}
		}else if(objHeight<obj.clientHeight) {
			//logger.warn("-"+objHeight);
			if(minHeight<objHeight) {
				obj.style.height = objHeight;
			}else {
				obj.style.height = minHeight;
			}
		}
}

function AutoResizeTextAreaHeight_Init() {
	var autoResizeTextAreaHeight;

	autoResizeTextAreaHeight = document.body.getAttribute("AutoResizeTextAreaHeight");
	var autoR = true;
	if (autoResizeTextAreaHeight!=null) {
			if(autoResizeTextAreaHeight=="true") {
				autoR = true;
			}else {
				autoR = false;
			}
	}
	var ts = document.getElementsByTagName("TEXTAREA");
	for(var i=0;i<ts.length;i++) {
		var t = ts[i];
		var k = autoR;
		var autoresizeHeight = t.getAttribute("AutoResizeHeight");
		if (autoresizeHeight!=null) {
				if(autoresizeHeight=="true") {
					k = true;
				}else {
					k = false;
				}
		}
		if (k) {
			addObjectEventListener(t,"onkeyup",new callerWrapFunction(resizeTextAreaHeight,t));
			addObjectEventListener(t,"onkeydown",new callerWrapFunction(resizeTextAreaHeight,t));
			addObjectEventListener(t,"onchange",new callerWrapFunction(resizeTextAreaHeight,t));
			t.fireEvent("onkeyup");
		}
	}
}

function addObjectEventListener(obj,eventName,func) {

	// DOM2
	if ( typeof window.addEventListener != "undefined" ) {
		obj.addEventListener( eventName, func, false );

	// IE
	}else if ( typeof window.attachEvent != "undefined" ) {
		obj.attachEvent(eventName, func);
	}
}


function removeObjectEventListener(obj,eventName,func) {

	// DOM2
	if ( typeof window.addEventListener != "undefined" ) {
		obj.removeEventListener( eventName, func, false );

	// IE
	}else if ( typeof window.attachEvent != "undefined" ) {
		obj.detachEvent(eventName, func);
	}
}

addObjectEventListener(window,"onload",AutoResizeTextAreaHeight_Init);

function  allProperties(obj,propertyType) {      
    var   props = "" ; 
    for ( var   p in obj ){
		var t = typeof (obj[p]);
        //method
        if ( t== "function" ){   
			if(propertyType==null || propertyType==t) {
				props += p + "() \t " ; 
			}
        } else { 
            //property
			if(propertyType==null || propertyType=="property" || propertyType==t ) {
				props += p + " = " + obj [ p ] + " \t " ; 
			}
        }
    }
    alert ( props ) ; 
}