


//°ÑÈÕÆÚ20070203»»³É2007-02-03ÑùÊ½
function Change_Date(strDate) {
    var str;
    str = strDate.substring(0, 4) + "-" + strDate.substring(4, 6) + "-" + strDate.substring(6, 8);
    return str;
}


function W_Close() {
    this.close();
    return false;
}


function PopUpWindow(url, windowname, width, height) {
    xposition = 0;
    yposition = 0;
    xposition = (screen.width - width) / 2;
    yposition = (screen.height - height) / 2;
    features = "width=" + width + ",height=" + height + ",scrollbars=yes,left=" + xposition + ",top=" + yposition;

    window.open(url, windowname, features);
}

//
function GetCheckBoxListValue(objID) {
    var v = new Array();
    var CheckBoxList = document.getElementById(objID);
    if (CheckBoxList.tagName == "TABLE") {
        for (i = 0; i < CheckBoxList.rows.length; i++) {
            for (j = 0; j < CheckBoxList.rows[i].cells.length; j++) {
                if (CheckBoxList.rows[i].cells[j].childNodes[0]) {
                    if (CheckBoxList.rows[i].cells[j].childNodes[0].checked == true) {
                        v.push(CheckBoxList.rows[i].cells[j].childNodes[1].innerText);
                    }
                }
            }
        }
    }
    if (CheckBoxList.tagName == "SPAN") {
        for (i = 0; i < CheckBoxList.childNodes.length; i++) {
            if (CheckBoxList.childNodes[i].tagName == "INPUT") {
                if (CheckBoxList.childNodes[i].checked == true) {
                    i++;
                    v.push(CheckBoxList.childNodes[i].innerText);
                }
            }
        }
    }
    return v;
}


//Ñ¡ÔñÈ«²¿£¬ÓëÈ¡ÏûÈ«²¿Ñ¡Ôñ¡£
function CheckAll(ischecked, chkAll, chkSingle) {
    var dom = document.all;
    var el = event.srcElement;

    if (el.id.indexOf(chkAll) >= 0 && el.tagName == "INPUT" && el.type.toLowerCase() == "checkbox") {
        for (i = 0; i < dom.length; i++) {
            if (dom[i].id.indexOf(chkSingle) >= 0 && dom[i].tagName == "INPUT" && dom[i].type.toLowerCase() == "checkbox") {
                dom[i].checked = ischecked;
            }
        }
    }
}


function displayDiv(objId) {
    var obj = document.all[objId];
    if (obj.style.display == "none") {
        obj.style.display = "block";
    }
    else {
        obj.style.display = "none";
    }
}



function valid_email(email) {
    if (trim(email) == "")
        return false;

    if (email.match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9]+)+$") == null)
        return false;

    return true;
}

function valid_numeric(number) {
    if (number.match(/\D/) != null)
        return false;
    else
        return true;
}

// trim
function trim(strIn) {
    var strOut = "";

    if (strIn)
        strOut = strIn.replace(/^\s*/, '').replace(/\s*$/, '');

    return strOut;
}

function DoChkAll(sIDPreFix) {
    var chkIdIs = "";

    for (i = 0; i < document.forms[0].length; i++) {
        var objCtrl = document.forms[0][i];

        if (objCtrl.type == "checkbox" && objCtrl.name.indexOf(sIDPreFix) > -1) {
            if (objCtrl.checked)
                objCtrl.checked = false;
            else
                objCtrl.checked = true;
        }
    }
}

function ClipBoardCopy(sTarId) {
    var srcItem = document.getElementById(sTarId);
    ClipBoardCopyAtObj(srcItem);
}
function ErrInputProc(objCont) {
    objCont.focus();
    return false;
}

function GetControlByOtherForm(objDoc, sTarId) {
    for (i = 0; i < objDoc.forms[0].length; i++) {
        if (objDoc.forms[0][i] && objDoc.forms[0][i].name.indexOf(sTarId) > -1) {
            return objDoc.forms[0][i];
        }
    }

    return null;
}
function go_url(url) {
    location.href = url;

}

function floatRound(myFloat, mfNumber) {
    if (mfNumber == 0)
        return Math.round(myFloat);
    else {
        var cutNumber = Math.pow(10, mfNumber);
        return Math.round(myFloat * cutNumber) / cutNumber;
    }
}

function js_convertDate(strDate) {
    if (strDate.length == 1)
        return "0" + strDate;
    else
        return strDate;
}

function GetDaysOfMonth(year, month) {
    var iYear = parseInt(year, 10);
    //ÊÇ·ñÊÇÈòÄê
    var bRN = false;
    if ((iYear % 4 == 0 && iYear % 100 != 0) || iYear % 400 == 0) {
        bRN = true;
    }

    var iMonth = parseInt(month, 10);
    switch (iMonth) {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            return 31;
        case 2:
            if (bRN)
                return 29;
            else
                return 28;
        default:
            return 30;
    }
}

function lrtrim(src) {
    var search = 0

    while (src.charAt(search) == " ") {
        search = search + 1
    }

    src = src.substring(search, (src.length))

    search = src.length - 1

    while (src.charAt(search) == " ") {
        search = search - 1
    }

    return src.substring(0, search + 1)
}



function calPopForCMon(name, target) {
    dateName = target;
    var strDate = lrtrim(name.value);
    var DateYear = "";
    var DateMonth = "";
    var DateDay = "";
    if (strDate == "") {
        callCalPop(name, target);
    }
    else {
        var ArrDate = strDate.split("-");

        DateYear = ArrDate[0];
        DateMonth = ArrDate[1];
        DateDay = ArrDate[2];

        if (!isNumber(DateMonth)) {
            DateMonth = 1;
        }

        if (!isNumber(DateDay)) {
            DateDay = 1;
        }

        if (!isNumber(DateYear)) {
            DateYear = 2005;
        }


        if (DateMonth > 12) {
            DateMonth = 1;
        }

        if (DateDay > 31) {
            DateDay = 1;
        }

        try {
            DateMonth = DateMonth / 1;
        }
        catch (e) {
            DateMonth = 1;
        }

        if (DateMonth < 9) {
            DateMonth = "0" + DateMonth;
        }

        callCalPopForCMon(name, target, DateYear, DateMonth, DateDay);
    }
}


function isNumber(pObj) {
    var obj = pObj;
    strRef = "1234567890";
    for (i = 0; i < obj.length; i++) {
        tempChar = obj.substring(i, i + 1);
        if (strRef.indexOf(tempChar, 0) == -1) {
            return false;
        }
    }
    return true;
}

function setCalDate(targetName, returnStr) {
    eval(targetName).value = returnStr;

    try {
        if (dateName == "setStartDate") {
            frmSchedule.endDate1.value = frmSchedule.startDate1.value;
        }
    }
    catch (e) {
    }
    finally {
        //	if(cTab == "1")
        //	{
        //		resetBlankTime(returnStr);
        //	}
        //	dateName = "";
    }
}

function mOvr(src, clrOver, clrOver1) {
    if (!src.contains(event.fromElement)) {
        src.style.cursor = 'hand'; 
        src.bgColor = clrOver;
        src.style.color = clrOver1;
    }
}
function mOut(src, clrIn, clrIn1) {
    if (!src.contains(event.toElement)) {
        src.style.cursor = 'default'; 
        src.bgColor = clrIn;
        src.style.color = clrIn1;
    }
}
function mClk(src) {
    if (event.srcElement.tagName == 'TD') {
        src.children.tags('A')[0].click();
    }
}

/*this javascript for ldap page */
function DeleOption(objSelectOption) {
    var objLenght = 0;
    var Flag = 0;
    var objDescSelect = document.all[objSelectOption];

    for (i = 0; i < objDescSelect.options.length; i++) {
        if (objDescSelect.options[i].selected) {
            objDescSelect.remove(i);
        }
    }
    for (i = 0; i < objDescSelect.options.length; i++) {
        if (objDescSelect.options[i].selected) {
            objDescSelect.remove(i);
        }
    }
    for (i = 0; i < objDescSelect.options.length; i++) {
        if (objDescSelect.options[i].selected) {
            objDescSelect.remove(i);
        }
    }
    for (i = 0; i < objDescSelect.options.length; i++) {
        if (objDescSelect.options[i].selected) {
            objDescSelect.remove(i);
        }
    }
}

/*this javascript for ldap page */
function DeleParentOption(objSelectOption) {
    var objLenght = 0;
    var Flag = 0;
    var objDescSelect = window.opener.document.all[objSelectOption];

    for (i = 0; i < objDescSelect.options.length; i++) {
        objDescSelect.remove(i);
    }
    for (i = 0; i < objDescSelect.options.length; i++) {
        objDescSelect.remove(i);
    }
    for (i = 0; i < objDescSelect.options.length; i++) {
        objDescSelect.remove(i);
    }
    for (i = 0; i < objDescSelect.options.length; i++) {
        objDescSelect.remove(i);
    }
    for (i = 0; i < objDescSelect.options.length; i++) {
        objDescSelect.remove(i);
    }
    for (i = 0; i < objDescSelect.options.length; i++) {
        objDescSelect.remove(i);
    }
}

function DeleParentOption1(objSelectOption) {
    var objLenght = 0;
    var Flag = 0;
    var objDescSelect = window.parent.window.document.all[objSelectOption];

    for (i = 0; i < objDescSelect.options.length; i++) {
        objDescSelect.remove(i);
    }
    for (i = 0; i < objDescSelect.options.length; i++) {
        objDescSelect.remove(i);
    }
    for (i = 0; i < objDescSelect.options.length; i++) {
        objDescSelect.remove(i);
    }
    for (i = 0; i < objDescSelect.options.length; i++) {
        objDescSelect.remove(i);
    }
    for (i = 0; i < objDescSelect.options.length; i++) {
        objDescSelect.remove(i);
    }
    for (i = 0; i < objDescSelect.options.length; i++) {
        objDescSelect.remove(i);
    }
}

function AutoDeleValueIsNullOption(objSelectOption) {
    var objLenght = 0;
    var Flag = 0;
    var objDescSelect = document.all[objSelectOption];

    var strValue = "";
    for (i = 0; i < objDescSelect.options.length; i++) {
        if (objDescSelect.options[i].value == "") {
            objDescSelect.remove(i);
        }
    }
}

//if double click select,open url
function DBClickOpenURL(objSelectOption) {
    var objDescSelect = document.all[objSelectOption];
    var url = "";
    var name = "";
    for (i = 0; i < objDescSelect.options.length; i++) {
        if (objDescSelect.options[i].selected) {
            url = encodeURI(objDescSelect.options[i].value);
            name = encodeURI(objDescSelect.options[i].text);
            var k = name.lastIndexOf('.');
            var subName = name.substring(k - 14, k);
            name = name.replace(subName, "");
        }
    }

    if (url != "") {
        window.open("/Comm/DownLoadAttach.aspx?FilePath=" + url + "&FileName=" + name);
    }
}

//===================================================================================================
//==CREATED By ChenZhiChao
//==CEEATED Date 2005-07-11
//==Description:ÑéÖ¤ÈÕÆÚµÄÓÐÐ§ÐÔ£¬¿ÉÑéÖ¤ÈóÄê
//===================================================================================================

function isdate(strDate) {
    var m;
    var op = strDate;
    var yearFirstExp = new RegExp("^\\s*((\\d{4})|(\\d{2}))([-/]|\\. ?)(\\d{1,2})\\4(\\d{1,2})\\s*$");
    m = op.match(yearFirstExp);
    var day, month, year;

    if (m == null) {
        return null;
    }
    if (m != null && (m[2].length == 4 || val.dateorder == "ymd")) {
        day = m[6];
        month = m[5];
        year = (m[2].length == 4) ? m[2] : GetFullYear(parseInt(m[3], 10))
    }
    else {
        if (val.dateorder == "ymd") {
            return null;
        }
        var yearLastExp = new RegExp("^\\s*(\\d{1,2})([-/]|\\. ?)(\\d{1,2})\\2((\\d{4})|(\\d{2}))\\s*$");
        m = op.match(yearLastExp);
        if (m == null) {
            return null;
        }
        if (val.dateorder == "mdy") {
            day = m[3];
            month = m[1];
        }
        else {
            day = m[1];
            month = m[3];
        }

        year = (m[5].length == 4) ? m[5] : GetFullYear(parseInt(m[6], 10))
    }
    month -= 1;
    if (year < 1900) {
        return null;
    }
    var date = new Date(year, month, day);
    return (typeof (date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate()) ? date.valueOf() : null;

}
function GetFullYear(year) {
    return (year + parseInt(val.century)) - ((year < val.cutoffyear) ? 0 : 100);
}



function setmin(main) {
    var is_selected = "N";
    document.all["mid"].length = 0;
    document.all["sml"].length = 0;

    for (i = 0; i < xmlObj.childNodes.length; i++) {

        var values = "";
        var lables = "";

        //if (is_selected=="Y") return;
        labels = xmlObj.childNodes(i).getAttribute("name");
        values = xmlObj.childNodes(i).getAttribute("value");
        if (labels == main) {

            is_selected = "Y";

            for (j = 0; j < xmlObj.childNodes(i).childNodes.length; j++) {
                labels = xmlObj.childNodes(i).childNodes(j).getAttribute("name");
                values = xmlObj.childNodes(i).childNodes(j).getAttribute("value");

                if (labels != "") {
                    if (j == 0) {
                        document.all["mid"].add(document.createElement("OPTION"));
                        document.all["mid"].options[0].text = "è¯·é€‰æ‹©";
                        document.all["mid"].options[0].value = "";

                        document.all["mid"].add(document.createElement("OPTION"));
                        document.all["mid"].options[j + 1].text = labels;
                        document.all["mid"].options[j + 1].value = values;
                    }
                    else {
                        document.all["mid"].add(document.createElement("OPTION"));
                        document.all["mid"].options[j + 1].text = labels;
                        document.all["mid"].options[j + 1].value = values;
                    }
                }
            }
        }
    }

}

function setsml(main, voc_type, product_cd) {
    //alert("a");
    //var is_selected="N";
    document.all["sml"].length = 0;

    for (i = 0; i < xmlObj.childNodes.length; i++) {

        var values = "";
        var lables = "";

        //if (is_selected=="Y") return;

        //alert(labels+ " | "+main);
        for (j = 0; j < xmlObj.childNodes(i).childNodes.length; j++) {
            labels = xmlObj.childNodes(i).childNodes(j).getAttribute("name");
            values = xmlObj.childNodes(i).childNodes(j).getAttribute("value");
            if (labels == main) {

                is_selected = "Y";

                for (k = 0; k < xmlObj.childNodes(i).childNodes(j).childNodes.length; k++) {
                    //subclass_name="document.frm.subclass";
                    labels = xmlObj.childNodes(i).childNodes(j).childNodes(k).getAttribute("name");
                    values = xmlObj.childNodes(i).childNodes(j).childNodes(k).getAttribute("value");

                    if (labels != "") {
                        if (k == 0) {
                            document.all["sml"].add(document.createElement("OPTION"));
                            document.all["sml"].options[0].text = "è¯·é€‰æ‹©";
                            document.all["sml"].options[0].value = "";

                            document.all["sml"].add(document.createElement("OPTION"));
                            document.all["sml"].options[k + 1].text = labels;
                            document.all["sml"].options[k + 1].value = values;
                        }
                        else {
                            document.all["sml"].add(document.createElement("OPTION"));
                            document.all["sml"].options[k + 1].text = labels;
                            document.all["sml"].options[k + 1].value = values;
                        }
                    }

                }

            }
        }

    }

    var oSel_ORG = document.all("org");
    var oSel_MID = document.all("mid");


    with (oSel_ORG) {
        org_cd = encodeURI(options[selectedIndex].value);
    }
    with (oSel_MID) {
        mid_cd = encodeURI(options[selectedIndex].value);
    }
    try {

        var odlProd = document.all("dlProd");

        if (product_cd == "" || product_cd == null) {
            if (odlProd.options.selectedIndex == 0) {
                alert("pls choose product list!");
                var oSel_MID = document.all("mid");

                with (oSel_MID) {
                    options.selectedIndex = 0;
                }
                return false;
            }
            with (odlProd) {
                product_cd = encodeURI(options[selectedIndex].value);
            }
        }

    }
    catch (e) {

    }
}


function showval() {
    var oSel_ORG = document.all("org");
    var oSel_MID = document.all("mid");
    var oSel_SML = document.all("sml");
    try {
        if (oSel_ORG != null) {
            with (oSel_ORG) {
                document.all("hidORG").value = options[selectedIndex].value;
            }
        }
        if (oSel_MID != null) {
            with (oSel_MID) {
                document.all("hidMID").value = options[selectedIndex].value;
            }
        }
        if (oSel_SML != null) {
            with (oSel_SML) {
                document.all("hidSML").value = options[selectedIndex].value;
            }
        }
    }
    catch (e) {
    }
}

function setdefaultVal(defaultVal) {
    var pin = 0;
    for (count = 0; count < document.all("org").options.length; count++) {
        if (document.all("org").options[count].text == defaultVal) {
            pin = count;
        }
    }
    document.all("org").options.selectedIndex = pin;
    setmin(defaultVal);
}

function setSelect(val, id) {
    var pin = 0;
    for (count = 0; count < id.options.length; count++) {
        if (id.options[count].value == val) {
            pin = count;
        }
    }

    id.options.selectedIndex = pin;
}


function setcom(parent, item) {
    var num_1 = 1;
    var otherTxt;
    var otherVal;
    var num = 0;

    CompanyItem = item;
    parent.length = 0;
    parent.add(document.createElement("OPTION"));
    parent.options[0].text = "è¯·é€‰æ‹©";
    parent.options[0].value = "";
    //alert("å…¶å®ƒ");
    /*
    for(i=0; i < item.length ; i++)
    {
    if(item[i][0]=="0")
    {
    if(item[i][2] != "å…¶å®ƒ")
    {
    parent.add(document.createElement("OPTION"));
    parent.options[num].text=item[i][2]; 
    parent.options[num].value=item[i][1]; 
    num=num+1;
    }
    else
    {
    otherTxt=item[i][2]; 
    otherVal=item[i][1]; 
    //alert(item[i][2]);
    }
    }
    }
    parent.add(document.createElement("OPTION"));
    parent.options[num].text=otherTxt; 
    parent.options[num].value=otherVal; 
    */

    for (i = 0; i < item.length; i++) {
        if (item[i][0] == "0") {

            parent.add(document.createElement("OPTION"));
            parent.options[num_1].text = item[i][2];
            parent.options[num_1].value = item[i][1];
            num_1 = num_1 + 1;
        }
    }
}
			

