﻿// JScript File


function Search() {
    $get("trSearchDetails").style.display = "none";
    $get("trErrorSrchDtls").style.display = "";
    $get("ebnCancel").style.display = "";
    return true;
}


function ValidateSearch() {
    try {
        var strType = $get(edlType)[$get(edlType).selectedIndex].value;
        showErrIcon("txtSearchDtls", "", false);
        //alert($get(txtSearchDtls).id);
        if (($get(txtSearchDtls).value == "") || ($get(txtSearchDtls).value == null)) {
            switch (strType) {
                case "BL":
                    alertMessage("Error", "Please Enter Valid Bill of Lading numbers", "OK", null, null, "300px");
                    showErrIcon($get(txtSearchDtls).id, "Please Enter Valid Bill of Lading numbers", true);
                    break;
                case "BKG":
                    alertMessage("Error", "Please Enter Valid Booking numbers", "OK", null, null, "300px");
                    showErrIcon($get(txtSearchDtls).id, "Please Enter Valid Booking numbers", true);
                    break;
                default:
                    alertMessage("Error", "Please Enter Valid Container numbers", "OK", null, null, "300px");
                    showErrIcon($get(txtSearchDtls).id, "Please Enter Valid Container numbers", true);
            }
            return false;
        }
        else
            return true;

    }
    catch (ex) {
        alertMessage("Title", "UpdateHdrDtls:" + ex.message, "OK", null, null, "300px");
        return false;
    }
}

function startUpScript() 
{

    if ($get("hdnNavigator").value == 'N') {
        //$get("trErrorSrchDtls").style.display = "none";
        $get("spSearchResult").style.display = "none";
        //$get("ebnCancel").style.display = "none";
        $get("trErrorSrchDtls").style.display = "none";
        $get("trSearchDetails").style.display = "";
    }
    else {
        $get("hdnNavigator").value = 'N';
        if ($get("hdnInvInputDtls").value == 'N') {
            $get("trErrorSrchDtls").style.display = "none";
            $get("trSearchDetails").style.display = "";
            $get("spSearchResult").style.display = "";
        }
        else if ($get("hdnInvInputDtls").value == 'Y') {
            $get("trErrorSrchDtls").style.display = "";
            $get("trSearchDetails").style.display = "none";
            $get("spSearchResult").style.display = "none";
        }
        else if ($get("hdnInvInputDtls").value == 'E') {
            $get("trErrorSrchDtls").style.display = "none";
            $get("trSearchDetails").style.display = "";
            $get("spSearchResult").style.display = "none";
        }
    }
    UpdateHdrDtls();   
    
    
}


function ConfigureSrchResult() {


    $get("trErrorSrchDtls").style.display = "none";
    $get("spSearchResult").style.display = "none";
    //$get("ebnCancel").style.display = "none";
    if ($get("hdnInvInputDtls").value == 'N') {
        $get("trErrorSrchDtls").style.display = "none";
        $get("trSearchDetails").style.display = "";
        $get("spSearchResult").style.display = "";
    }
    else if ($get("hdnInvInputDtls").value == 'Y') {
        $get("trErrorSrchDtls").style.display = "";
        $get("trSearchDetails").style.display = "none";
        $get("spSearchResult").style.display = "none";
    }
    else if ($get("hdnInvInputDtls").value == 'E') {
        $get("trErrorSrchDtls").style.display = "none";
        $get("trSearchDetails").style.display = "";
        $get("spSearchResult").style.display = "none";
    }
    var strType = $get("edlType")[$get("edlType").selectedIndex].value;
    switch (strType) {
        case "BL":
            if ($get("hdnInvInputDtls").value == 'Y') {
                changeText('txtInvalidSrchDtls', 'L', 'Invalid Bill Of Lading Details#');
                $get("lblValidDtlsHdr").innerHTML = "Bill Of Lading Details#";
            }
            else
                changeText('txtSearchDtls', 'L', 'Bill Of Lading Details#');

            break;
        case "BKG":
            if ($get("hdnInvInputDtls").value == 'Y') {
                changeText('txtInvalidSrchDtls', 'L', 'Invalid Booking Details#');
                $get("lblValidDtlsHdr").innerHTML = "Booking Details#";

            }
            else
                changeText('txtSearchDtls', 'L', 'Booking Details##');

            break;
        default:
            if ($get("hdnInvInputDtls").value == 'Y') {
                changeText('txtInvalidSrchDtls', 'L', 'Invalid Container Details#');
                $get("lblValidDtlsHdr").innerHTML = "Container Details#";
            }
            else
                changeText('txtSearchDtls', 'L', 'Container Details#');
    }
    
}

function CancelError() 
{
    $get("trErrorSrchDtls").style.display = "none";
    $get("spNewSearch").style.display = "";
    $get("spSearchResult").style.display = "none";
    $get("hdnInvInputDtls").value = 'N';


    return false;
}

function SearchResult() {
    //$get("spErrorDtls").style.display="none";
    $get("spSearchResult").style.display = "";
    $get("Label5").style.display = "none";
    return false;
}

function UpdateHdrDtls() {
   
    var strType = $get("edlType")[$get("edlType").selectedIndex].value;
    //alert(strType);
    //alert($get("hdnInvInputDtls").value);
    if ($get("hdnInvInputDtls").value == "N")
    {

        switch (strType) {
            case "BL":
                changeText('txtSearchDtls', 'L', 'Bill Of Lading Details#');
                break;
            case "BKG":
                changeText('txtSearchDtls', 'L', 'Booking Details#');
                break;
            default:
                changeText('txtSearchDtls', 'L', 'Container Details#');
        }
    }

        return false;
}


function PopulateSearchDtls(strRowId, strGridId, introw)
{
   
   var x = $get(strRowId).cells;
   $get("txtSearchDtls").value = x[8].innerHTML;
   $get("hdnInvInputDtls").value = 'N';
   UncheckALLRadioButtons(strGridId);
   objradio=x[0].getElementsByTagName("input");
   objradio[0].checked = true;

   $get("trSearchDetails").style.display = "";
   $get("trErrorSrchDtls").style.display = "none";
   $get("hdnInvInputDtls").value = 'N';
   $get("txtInvalidSrchDtls").value = '';
   $get("lblValidDtls").innerHTML = "";
  
   
    
   switch (x[2].innerHTML) 
   {
       case "BL":
           //$get("lblSearchDescription").innerHTML = "Bill Of Lading Details#";
           changeText('txtSearchDtls', 'L', 'Bill Of Lading Details#');
           $get("edlType").options[1].selected = true;
           break;
       case "BKG":
           //$get("lblSearchDescription").innerHTML = "Booking Details#";
           changeText('txtSearchDtls', 'L', 'Booking Details#');
           $get("edlType").options[2].selected = true;
           break;
       default:
           //$get("lblSearchDescription").innerHTML = "Container Details#";
           changeText('txtSearchDtls', 'L', 'Container Details#');
           $get("edlType").options[0].selected = true;

   }
   __doPostBack('ebnSearch', '');
}

function PopulateSearchSelection(strRowId, strGridId, introw) {

    var x = $get(strRowId).cells;
    $get("txtSearchDtls").value = x[8].innerHTML;
    UncheckALLRadioButtons(strGridId);
    objradio = x[0].getElementsByTagName("input");
    objradio[0].checked = true;
    $get("trErrorSrchDtls").style.display = "none";
    $get("trSearchDetails").style.display = "";
    $get("hdnInvInputDtls").value = 'N';
    $get("txtInvalidSrchDtls").value = '';
    $get("lblValidDtls").innerHTML = "";
    
    
    switch (x[2].innerHTML) {
        case "BL":
            //$get("lblSearchDescription").innerHTML = "Bill Of Lading Details#";
            changeText('txtSearchDtls', 'L', 'Bill Of Lading Details#');
            $get("edlType").options[1].selected = true;
            
            break;
        case "BKG":
            //$get("lblSearchDescription").innerHTML = "Booking Details#";
            changeText('txtSearchDtls', 'L', 'Booking Details#');
            $get("edlType").options[2].selected = true;
            break;
        default:
            //$get("lblSearchDescription").innerHTML = "Container Details#";
            changeText('txtSearchDtls', 'L', 'Container Details#');
            $get("edlType").options[0].selected = true;

    }
}


//function PopulateSearchDtls(strRowId, strGridId, introw) {

//    var x = $get(strRowId).cells;
//    $get("txtSearchDtls").value = x[4].innerHTML;
//    UncheckALLRadioButtons(strGridId);
//    
//    //need to hide the error row.
//    $get("trSearchDetails").style.display = "";
//    $get("trErrorSrchDtls").style.display = "none";    
//    
//    
//    switch (x[2].innerHTML) {
//        case "BL":
//            $get("lblSearchDescription").innerHTML = "Bill Of Lading Details#";
//            $get("edlType").options[1].selected = true;
//            break;
//        case "BKG":
//            $get("lblSearchDescription").innerHTML = "Booking Details#";
//            $get("edlType").options[2].selected = true;
//            break;
//        default:
//            $get("lblSearchDescription").innerHTML = "Container Details#";
//            $get("edlType").options[0].selected = true;

//    }
//}





function UncheckALLRadioButtons(strGridId)
{
    intMaxRows = $get(strGridId).rows.length;
    var Y;
    for(i=1;i<intMaxRows; i++)
    {
        Y=$get(strGridId).rows[i].cells;
        //alert(Y.innerHTML);
        if (Y[0]!=null)
        {
            objInput=Y[0].getElementsByTagName("input");
            objInput[0].checked=false;
        }
        
    }
}

function CancelSrch() {

    $get("trErrorSrchDtls").style.display = "none";
    $get("trSearchDetails").style.display = "";
    $get("txtSearchDtls").value = "";
    $get("txtInvalidSrchDtls").value = "";
    $get("txtSearchDtls").title = "";
    $get("txtInvalidSrchDtls").title = "";
    $get("hdnInvInputDtls").value = "N";
    $get("hdnValidSrchDtls").value = "";
    $get("edlType").options[0].selected = true;
    showErrIcon($get(txtSearchDtls).id, "", false);
    UncheckALLRadioButtons('MRBgvPreviousSearchDtls');
    changeText('txtSearchDtls', 'L', 'Container Details#');
    return false;
}




