
/**
 * Require: 
 *      prototype.js
 */

function trim(x) {
   var i = 0;
   var j = x.length - 1;
   while(x.charAt(i) == " ") {
      i++;
   }
   while(x.charAt(j) == " " && j >= i) {
      j--;
   }
   return x.substring(i, j + 1);
}

function strlength(x) {
    var l = x.length;
    var n = l;
    for (var i = 0; i < l; i++) {
        if (x.charCodeAt(i)<0 || x.charCodeAt(i)>255)
            n++;
    }
    return n; 
}

function isEmail(x) {
   var len = x.length;
   if(len<5 && len > 30) {
      return false;
   }
   // var filter = /^\w+@(\w+\.?)+\.[a-zA-Z]{2,3}$/;
   var filter = /^[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]*)*@[a-zA-Z0-9\-]+([\.][a-zA-Z0-9\-]+)+$/;
   if(! filter.test(x)) {
      return false;
   }
   return true;
}

function isEmail2(strg) {
    if(!(strg.indexOf("@") > 1))
        return false;
    if(strg.indexOf("@", strg.indexOf("@") + 1) > 0)
        return false;
    var strarray = new Array("@@", "@.", "..");
    for(i = 0; i < strarray.length; i++) {
        if(strg.indexOf(strarray[i]) > 0) {
            return false;
        }
    }
    for(i = 0; i < strg.length; i++) {
        if(strg.substr(i, 1) <= "," || strg.substr(i, 1) == "/" ||(strg.substr(i, 1) >= "[" && strg.substr(i, 1) <= "") || strg.substr(i, 1) == "`" ||(strg.substr(i, 1) >= ":" && strg.substr(i, 1) <= "?") || strg.substr(i, 1) >= "{") {
            return false;
        }
    }
    return true;
}

function isTelephone(x) {
   var filter = /^[0-9-\/\\]{7,25}$/;
   return filter.test(x);
}

function isMobile(x) {
   var filter = /^1[3-9][0-9]{9}$|^01[3-9][0-9]{9}$/;
   return filter.test(x); 
}

function isZipCode(x) {
   var filter = /[0-9]{6}/;
   return filter.test(x);
}

function isFixedLen(x, lenFst, lenSnd) {
   if(isNaN(lenSnd)) {
      if(x.length != lenFst) {
         return false;
      }
   } else {
      if((x.length < lenFst) ||(x.length > lenSnd)) {
         return false;
      }
   }
   return true;
}

function isValidStr(x) {
   var badChar = "><,[]{}?+=|\\'\":;!@#$%^&()`~";
   var len = x.length;
   for(var i = 0; i < len; i++) {
      if(badChar.indexOf(x.charAt(i)) >= 0)
      return false;
   }
   return true;
}

function isNumeric(x) {
   return x.search(/^(-|\+)?\d+(\.\d+)?$/) >= 0;
}

function isUnsignedNumeric(x) {
   return x.search(/^\d+(\.\d+)?$/) >= 0;
}

function isInteger(x) {
   return x.search(/^(-|\+)?\d+$/) >= 0;
}

function isUnsignedInteger(x) {
   return x.search(/^\d+$/) >= 0;
}

function isMoney(pObj) {
   if(isNaN(pObj))
   return false;
   return true;
}

function OpenWindow(theURL, winName, width, height, flag) {
   window.open(theURL, winName, "fullscreen=" + flag + ",scrollbars=yes,width=" + width + ",height=" + height + "top=0,left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no");
}

function openDialogWindow(theURL, winName, width, height, flag) {
   window.showModalDialog(theURL, winName, "dialogWidth:" + width + ";dialogHeight:" + height + ";center:" + flag);
}

function FormatNumber(str, item) {
   var i = new Number(str.value).toFixed(item);
   str.value = i;
}

function moneywrite(str1) {
   var n, m, k = "";
   var num = str1.value;
   n = num.length;
   for(var i = n; i > 0; i = i - 3) {
      m = num.substring(i - 3, i);
      if(k != "") {
         k = "," + k;
      }
      k = m + k;
   }
   if(k == ".00") {
      str1.value = "0.00";
   }
   else {
      str1.value = k;
   }
}

function String_Replace(srcString, findString, replaceString) {
   return String_ReplaceB(srcString, findString, replaceString, 0);
}

function String_ReplaceB(expression, find, replacewith, start) {
   var index = expression.indexOf(find, start);
   if(index == - 1)
   return expression;
   var findLen = find.length;
   var newexp = "";
   newexp = expression.substring(0, index) +(replacewith) +(expression.substring(index + findLen));
   return String_ReplaceB(newexp, find, replacewith, index + 1 + findLen);
}

function closeit(item) {
   setTimeout("self.close()", item);
}

function selectNum(x) {
   var obj, len, count = 0;
   obj = eval("document.all.item('" + x + "')");
   if(obj != null) {
      len = eval("document.all." + x + ".length");
      if(isNaN(len)) {
         check = eval("document.all." + x + ".checked");
         if(check) count++;
      }
      else {
         for(var i = 0; i < len; i++) {
            check = eval("document.all." + x + "[" + i + "].checked");
            if(check) count++;
         }
      }
   }
   return(count);
}

function selectValue(x) {
   var len, check;
   len = eval("document.all." + x + ".length");
   if(isNaN(len))
   return eval("document.all." + x + ".value");
   else {
      for(var i = 0; i < len; i++) {
         check = eval("document.all." + x + "[" + i + "].checked");
         if(check)
         return eval("document.all." + x + "[" + i + "].value");
      }
   }
}

function selectColsNum(x) {
   var len, check;
   len = eval("document.all." + x + ".length");
   if(isNaN(len))
   return 1;
   else {
      for(var i = 0; i < len; i++) {
         check = eval("document.all." + x + "[" + i + "].checked");
         if(check)
         return i;
      }
   }
}

function moveOne(s1,s2){
    if(s1.selectedIndex!=-1){
        var optionNew;
        optionNew=document.createElement("OPTION");
        optionNew.value=s1.options[s1.selectedIndex].value;
        optionNew.text=s1.options[s1.selectedIndex].text;
        s2.add(optionNew);
        s1.remove(s1.selectedIndex);
    }
}

function moveAll(s1,s2){
    var optionNew;
    while(s1.length>0){
        optionNew=document.createElement("OPTION"); 
        optionNew.value=s1.options[0].value;
        optionNew.text=s1.options[0].text;
        s2.add(optionNew);
        s1.remove(0);
    }
}

function isTime2(dat) {
   var time;
   var szTime, fmTime;
   time = dat.value;

    if(time.length ==4){
        szTime = time.substr(0,1);
        if(isNaN(szTime))
            return false;
        fmTime = time.substr(2,2);
        if(isNaN(fmTime))
            return false;
        if(szTime<0||szTime>9)
            return false;
        if(fmTime<0||fmTime>59)
            return false;
        if(time.substr(1,1)!=":")
            return false;
    }
    if(time.length ==5){
    alert("22");
        szTime = time.substr(0,2);
        if(isNaN(szTime))
            return false;
        fmTime = time.substr(3,2);
        if(isNaN(fmTime))
            return false;
        if(szTime<0||szTime>24)
            return false;
        if(fmTime<0||fmTime>59)
            return false;
        if(time.substr(2,1)!=":")
            return false;
    }
}

function radioNam(idt) {
   var obj, len, count = 0;
   obj = eval("document.all.item('" + idt + "')");
   if(obj != null) {
      len = eval("document.all." + idt + ".length");
      if(isNaN(len))       {
         check = eval("document.all." + idt + ".checked");
      }
   }
   return(count);
}


function formatDate() {
   var d = new Date();
   var s, mm, dd;
   mm = d.getMonth() + 1;
   mm = mm.toString();
   if(mm.length == 1) mm = "0" + mm;
   dd = d.getDate();
   dd = dd.toString();
   if(dd.length == 1) dd = "0" + dd;
   s = d.getYear() + "-" + mm + "-" + dd;
   return s;
}

function saveAS(x) {
    var saveasName=x+".xls";    
    iform1.document.execCommand("saveas","true",saveasName);
}

/*
function openWin(location,width,height,name) {
    var width,height,x,y,name;
    width = width;
    height = height;
    name=name;
    x = (screen.width-width) / 2;
    y = (screen.height-height) / 2;
    tmp=window.open("",name,"fullscreen=1");
    tmp.moveTo(x,y);
    tmp.resizeTo(width,height);
    tmp.focus();
    tmp.location=location;
}
*/

var oldnowid;
oldnowid=-1;
function changecolor(nowid,nowdo)
{
    var a,nowcolor;
    a=eval("nowtr"+nowid);
    if (nowdo=="over") {
        a.style.backgroundColor="#FFF799";
    } else {
        if (oldnowid==nowid) {
            a.style.backgroundColor="#FFF799";
        } else {
            if (nowid%2==0){
                a.style.backgroundColor="#C4D9E9";
            }else{
                a.style.backgroundColor="#ffffff";
            }
        }
    }
}

function changefixtr(nowid)
{
    var a;
    if (oldnowid!=-1)     {
        //a=eval("nowtd"+oldnowid)
        //a.innerHTML="&nbsp;"
        a=eval("nowtr"+oldnowid)
        if (oldnowid%2==0){
            a.style.backgroundColor="#C4D9E9";
        }else{
            a.style.backgroundColor="#ffffff";
        }
    }
    a=eval("nowtr"+nowid);
    a.style.backgroundColor="#ffffff";
    //a=eval("nowtd"+nowid)
    //a.innerHTML="<input NAME=code TYPE=checkbox VALUE="+nowid+">";
    oldnowid=nowid;
}

function showSavingLayer() {
    saving.style.visibility="visible";
    cover.style.height=screen.height;
    cover.style.visibility="visible";
    return true; 
}

function clickCode(url,code) {   
    if (code==null || code=="") 
        return false;   
    var s=form1.searchStr.value;   
    if (isNaN(code)) { 
        if (url.indexOf("?") < 0) {  
            window.location.href=url+"?searchStr="+s;   
        } else {
            window.location.href=url+"&searchStr="+s;   
        }
    } else {   
        if (url.indexOf("?") < 0) {  
            window.location.href=url+"?page=" + code+"&searchStr="+s;   
        }else{
            window.location.href=url+"&page=" + code+"&searchStr="+s;   
        }
    }   
}
 
 function htmlSwitchVisibility(obj) {
    if (typeof(obj) == "string")
        obj = document.all(obj); 
        
    if (obj.style != null) {
        if (obj.style.visibility == "hidden") {
            obj.style.visibility = "visible"; 
        } else {
            obj.style.visibility = "hidden"; 
        }
    }
}

// chk = true, false, 'x'
function selectAll(f, chk) {
    var i; 
    if (f == null) {
        for (i = 0; i < document.forms.length; i++) {
            selectAll(document.forms[i], chk); 
        }
        return; 
    }
    var count = 0;
    for (i = 0; i < f.elements.length; i++) {
        var elm = f.elements[i];
        var t = elm.type.toLowerCase();
        if (t == "checkbox") {
            if (chk == 'x') {
                elm.checked = ! elm.checked; 
            } else {
                elm.checked = chk;
            }
            count++;
        }
    }
    return count; 
}

/*
Object.extend(window.Element, {
    test1: function() {
        alert('hello');
    },
    
    removeAll: function(element) {
        while ($(element).length > 0) {
            $(element).remove(0); 
        }
    }, 
    
    selectAll: function(element, chk) {
    }
});
*/

function ajaxLoadOptions(s, data, ktag, vtag) {
    if (s == null) return 0; 
    
    if (typeof(s) == "string")
        s = $(s); 
    
    if (ktag == null) ktag = "id";
    if (vtag == null) vtag = "name";
    
    if (typeof(data) == "string") {
        data = $XMLDATA(data); 
    }
    
    var count = 0;
    for (var i = 0; i < data.length; i++) {
        var row = data[i];
        var k = row[ktag];
        var v = row[vtag];
        var opt = document.createElement("OPTION"); 
        opt.value = k;
        opt.text = v;
        s.add(opt);
        count++;
    }
    return count;
}

function selectday(thisitem) 
{
   var a, b, returndate;
   a = eval(thisitem);
   returndate = window.showModalDialog('../common/calendar.jsp', a.value, 'status:no;help:no');
   if(returndate)  a.value = returndate;
}

function switchoutlookBar(number)
{
	var i = outlookbar.opentitle;
	outlookbar.opentitle=number;
	var id1,id2,id1b,id2b;
	if (number!=i){		
		id2="outlookdiv"+i;
		id2b="outlookdivin"+i;
		id1="outlookdiv"+number
		id1b="outlookdivin"+number
		smoothout(id1,id2,id1b,id2b);
	}
}

function smoothout(id1,id2,id1b,id2b)
{
		document.all(id1b).style.overflow="auto";
		document.all(id2b).style.overflow="hidden";
		document.all(id1).style.display="";
		document.all(id2).style.display="none";

}

function outlook()
{
	this.opentitle=-1;
}

function menu(openNumber)
{
	var j = k = 0;
	document.write("<table border=0 cellspacing='1' cellpadding='1' valign='top' align='left'>");
	for ( var i = 0; i < arrayMenu[0].length; i ++ ){ 
		if(arrayMenu[2][i] == 0){
			if(i != 0)	document.write("</table></td></tr>");	
			document.write("<tr><td align='left' name='outlooktitle" + i + "' id='outlooktitle" + i + "' align='center' class='grey' nowrap onclick='switchoutlookBar(" + i + ")' style='cursor:hand;'>");
			document.write("<img src='../images/addition.gif' border='0'>&nbsp;" + arrayMenu[1][i] + "</td></tr><tr><td name='outlookdiv" + i + "' valign='top' align='center'  id='outlookdiv" + i + "' style='width:100%;display:");
			if(i != 0) document.write("none");
			document.write(";'><div name='outlookdivin" + i + "' id='outlookdivin" + i + "' style='overflow:auto;width:100%;color:black'><table width='100%' border='0' cellspacing='0' cellpadding='0'>");	
			j=i;
		}else{
			document.write("<tr height='20px;'><td align='left'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src='../images/minus.gif' border='0'>&nbsp;<a href='" + outlooklink + "?id=" + arrayMenu[0][i] + "'>" + arrayMenu[1][i] + "</a></td></tr>");
			if(arrayMenu[0][i] == openNumber) k = j; 
		}
	}
	document.write("</td></tr></table></table>");	
	switchoutlookBar(k);

}

/* 
 * ���棺
 * --------------------------------------------------
 * 
 * ���ļ���ʹ�� ASCII ����� JavaScript ��
 * 
 * ����ļ�����ֻ��Ӣ�ĵ� javascript ����
 * ���к��ֵģ���(ȫ�Ǳ���ŵȵȣ�javascript ��������� 
 *      functions-gen.js 
 * �ļ��С�
 * ���ļ��������ע���⣬����ط�Ҳ����������ע�͡� 
 * 
 */
