// JScript File

function openSubJobNo(pClientID, pClientFABID, pClientDescription, sSelectType){
    document.getElementById(pClientID).focus();
    var lUrl = '..\\..\\SubPages\\JobNos.aspx?JobNoClientID=' + pClientID + '&FABClientID=' + pClientFABID + '&DescriptionClientID=' + pClientDescription + '&SelectType=' + sSelectType ;
    winRef = window.open(lUrl,'JobNosList','width=600,height=500,status=yes,scrollbars=yes');
    winRef.focus();
}
function openSubPageFABID(pClientID, objFABID, objJobNo){
    //alert('openSubPageFABID');
    document.getElementById(pClientID).focus();
    //var lUrl = '..\\..\\SubPages\\FABs.aspx?DialogClientID=' + pClientID + '&FABID=' + objFABID.value+ '&JobNo=' + objJobNo.value;
    var lUrl = '..\\..\\SubPages\\FABs.aspx?DialogClientID=' + pClientID;
    if (objFABID != undefined)  // from TEC/Forms/ProblemResponse.aspx.cs
        lUrl += '&FABID=' + objFABID.value;
    else
        lUrl += '&FABID=';
    if (objJobNo != undefined) // from TEC/Forms/ProblemResponse.aspx.cs
        lUrl += '&JobNo=' + objJobNo.value;
    else
        lUrl += '&JobNo='
    winRef = window.open(lUrl,'FABsList','width=480,height=300,status=yes,scrollbars=yes');
    winRef.focus();
}
function openSubPageToolID(pClientID, objFABID, IsMulitTools){
    //alert('openSubPageToolID');
    document.getElementById(pClientID).focus();
    var lUrl;
    // 080508 : 一個工番可對應多個FAB
    var sFABs = objFABID.value.replace(/\r/g, "").replace(/\n/g, ",");
    lUrl = '..\\..\\SubPages\\Tools.aspx?DialogClientID=' + pClientID + '&FABID=' + sFABs + '&IsMultiTools=' + IsMulitTools;
    winRef = window.open(lUrl,'ToolsList','width=600height=500,status=yes,scrollbars=yes');
    winRef.focus();
}
// 會依工番去找尋所包含的機台
function openSubPageToolIDFromWorkListDetail(pClientID, objFABID, objJobNo){
    document.getElementById(pClientID).focus();
    var lUrl;
    lUrl = '..\\..\\SubPages\\Tools.aspx?DialogClientID=' + pClientID + '&FABID=' + objFABID.value+ '&JobNo=' + objJobNo.value;
    winRef = window.open(lUrl,'ToolsList','width=480,height=300,status=yes,scrollbars=yes');
    winRef.focus();
}
function openSubPageEmployee(pClientID){
//    document.getElementById(pClientID).focus();
    var lUrl = '..\\..\\SubPages\\Employees.aspx?DialogClientID=' + pClientID;
    winRef = window.open(lUrl,'EmployeesList','width=430,height=300,status=yes,scrollbars=yes');
    winRef.focus();
}
function openSubPageCalendar(pClientID){
    document.getElementById(pClientID).focus();
    var lUrl = '..\\..\\SubPages\\Calendar.aspx?DialogClientID=' + pClientID;
    winRef = window.open(lUrl,'Calendar',' width=250,height=230');
    winRef.focus();
}


// WorkListDetail.aspx use
function checkExpectDate(soStartExpect, soEndExpect, bEmptyCheck) {
//alert ( Date.parse(soEndExpect)-Date.parse(soStartExpect));
//return false;
    if (document.getElementById(soStartExpect).value > document.getElementById(soEndExpect).value){
        alert ('StartDate > EndDate');
        return false;
    }
    if  ( bEmptyCheck && (document.getElementById(soStartExpect).value == '' || document.getElementById(soEndExpect).value == '')){
        alert ('StartDate or EndDate is empty');
        return false;
    }    
    return true;
}
function checkResponsibilityValue( oCom){
    if (document.getElementById(oCom).value != "")
        return true;
    else{
        alert('Responsibility is empty');
        return false;
    }
}


// SubPages/Tools.aspx use
function AssignValueToParent(parentID, selectName, IsMultiTools){
    //if ( window.opener.document.location.toString().toUpperCase().indexOf("SEST/MAINTENANCE/TEC/WORKSLISTDETAIL.ASPX") > -1)
    if ( IsMultiTools == 'False'){
        window.opener.document.getElementById(parentID).focus();
        window.opener.document.getElementById(parentID).value = selectName;
    }
    else{
        // 該員已存在
        sParentValue = window.opener.document.getElementById(parentID).value;
        if ( sParentValue.indexOf(selectName) < 0 ){          
            if (window.opener.document.getElementById(parentID).value == "")
                window.opener.document.getElementById(parentID).value = selectName;
            else
                window.opener.document.getElementById(parentID).value += '\r\n' + selectName;
        }
    }
    window.close();
}


// 每增加一個檔案自動給下一個可 upload file 的元件
function addFile(width) { 
    var str = '<INPUT type="file" size="50" NAME="File" style="width:' + width + ';" onchange="addFile(' + width + ')">' 
    document.getElementById('tdMyFiles').insertAdjacentHTML("beforeEnd",str) 
} 
function addFile2(Container, width) { 
    var str = '<INPUT type="file" size="50" NAME="File" style="width:' + width + ';" onchange="addFile2(\'' + Container + '\',' + width + ')">' 
    document.getElementById(Container).insertAdjacentHTML("beforeEnd",str) 
} function addFileAndNavi(width, navigation) { 
    var str = '<INPUT type="file" size="50" NAME="File" style="width:' + width + ';" onchange="addFile(' + width + ')">' ;
    str += '<a href="' + navigation + '" target="_blank"><img src="../../imanges/attachfile.gif" style="border-width:0px;" /></a>';
    document.getElementById('MyFiles').insertAdjacentHTML("beforeEnd",str) 
} 

function addSchedule(width) { 
    var str = '<INPUT type="file" size="50" NAME="File" style="width:' + width + ';" onchange="addFile(' + width + ')">' 
    document.getElementById('tdSchedule').insertAdjacentHTML("beforeEnd",str) 
} 



//OnCall
function AssignOnCallStaff(assignLabel, SourceSelect){
    //document.getElementById(assignLabel).name = document.getElementById(assignLabel).id;
    document.getElementById(assignLabel).innerText = document.getElementById(SourceSelect).options[document.getElementById(SourceSelect).selectedIndex].value;
}



////Assignment 
//function stat(){
//    var a = pageYOffset+window.innerHeight-document.bar.document.height-15
//    document.bar.top = a
//    setTimeout('stat()',2)
//}
//function fix(){
//    nome=navigator.appName
//    if(nome=='Netscape'){
//        stat()
//    }
//    else{
//        var a=document.body.scrollTop+document.body.clientHeight-document.all.bar.offsetHeight+15
//        bar.style.top = a
//    }
//}