﻿// JScript File
var gbShowErr = false;
var gsMtySpace="";
var gsConstTr="tr";
var gsConstTd="td";
var gsConstEvenTrCls="mrbE";
var gsConstOddTrCls="mrbO";
var gsConstCurrTrCls="mrbS";   
var gsConstRecSep=" / ";
var gsMtySpace="";
var gsBlankSpace=" ";      
var gsDtFmt='DD-MON-YYYY';      
var gsMaxClientSort=50;

// Function on Page load
function startUpRecord()
{
  try
   {
      if (getElemById("hdnQueryType").value=="GEN")
         selTab('Search',0);         
      else if (getElemById("hdnQueryType").value=="BKG")
         selTab('Search By Booking',1);          
      else if (getElemById("hdnQueryType").value=="BL")
         selTab('Search By BL',2);
      else if (getElemById("hdnQueryType").value=="EQP")
         selTab('Search By Equipment',3);
      else
         selTab('My Favorites',4);
   }
   catch(ex)
   {
      if(gbShowErr) alert("startUpRecord :\n" +ex.message);
   }
   finally
   {
   }
}
function ShowBlBkgDiv()
{
  try
   {
      if (getElemById("hdnBlBkgTyp").value=="BL")
      {
         displayOff("divSplitBKG");
         displayOn("divSplitBL");
      }
      else
      {
         displayOn("divSplitBKG");
         displayOff("divSplitBL");
      }
      
   }
    catch(ex)
   {
      if(gbShowErr) alert("ShowBlBkgDiv :\n" +ex.message);
   }
   finally
   {
   }
}
/*
|| Helper function. Redirecting to Split B/L and Booking page .
*/
 
 function displaySplitBl(sBlNo,sTyp)
 {
    var oWin=null;
    var sPage=null;
    var sURL=null;
    var nTop=null;
    var nLeft=null;
    var oWin=null;
    var nConstWidth =700 ;
    var nConstHeight = 300;
    
    try
    {
      sPage="InstaTrackSplitBLBKG.aspx?BLBKGNo="+sBlNo+"&BLBKGType="+sTyp;
      sURL=sPage;
      nTop = (self.screen.height/2)- (nConstHeight/2);
      nLeft = (self.screen.width/2)- (nConstWidth/2);             
      oWin=winOpen(sURL,"SplitBLBKG",nTop,nLeft,nConstHeight,nConstWidth);   
    }
    catch(ex)
    {
      if(gbShowErr) alert("displaySplitBl:\n"+ex.message);
    }
    finally
    {
       sPage=null;
       sURL=null;
    }
 }
// Tab selection

function selTab(sAnchor,sCurrTabIndex)
{  
   try
   {  
      for(nCtr=0;nCtr<=4;nCtr++)
      {
          $get("lblInstaTrack_"+nCtr).className="tabRLO";
          $get("imgInstaTrack_L"+nCtr).style.background="#528dd1";
          $get("imgInstaTrack_R"+nCtr).style.background="#528dd1"; 
      }                 
      $get("lblInstaTrack_"+sCurrTabIndex).className="tabRLS";
      $get("imgInstaTrack_L"+sCurrTabIndex).style.background="#f2f7fb";
      $get("imgInstaTrack_R"+sCurrTabIndex).style.background="#f2f7fb";
      showDiv(sAnchor);
   }
   catch(ex)
   {
      if(gbShowErr) alert("selTab:\n"+ex.message);
   }
   finally
   {
     
   }   
}

// Display/hide the tab.

function showDiv(sValue)
{
   try    
   {  
      
      displayOff("divSearch");
      displayOff("divSearchBkg");
      displayOff("divSearchBL");
      displayOff("divSearchEqp");     
      displayOff("divMyFavorites");
   
      switch(sValue)
      {
         case "Search":
            displayOn("divSearch");
            getElemById("hdnQueryType").value="GEN";            
            break;      
         case "Search By Booking":
            displayOn("divSearchBkg");
            
            getElemById("hdnQueryType").value="BKG";             
            break;
         case "Search By BL":
            displayOn("divSearchBL"); 
            getElemById("hdnQueryType").value="BL";            
            break;        
         case "Search By Equipment":
            displayOn("divSearchEqp");
            getElemById("hdnQueryType").value="EQP"; 
            break;
         case "My Favorites":
            displayOn("divMyFavorites"); 
            getElemById("hdnQueryType").value="";            
            break; 
      }
   }
   catch(ex)
   {
      if(gbShowErr) alert("showDiv:\n"+ex.message);
   }   
}

/*
|| Set the given div to display
*/

function displayOn(divName)
{
   try
   {
      getElemById(divName).style.display="";
   }
   catch (ex)
   {
      if(gbShowErr) alert("displayOn:\n"+divName+ex.message);
   }
}

/*
|| Set the given div's display off
*/
 
function displayOff(divName)
{
   try
   {
      getElemById(divName).style.display="none";
   }
   catch (ex)
   {
      if(gbShowErr) alert("displayOff:\n"+divName+ex.message);
   }
}


/*
|| Validates all the input text elements of the instaTrackSearch prior to submit.
*/

function valInputElems(sTab)
{
   var sConstTxtBox="txtInstaNum";
   var nConstIndex=10;
   var nCtrStart=0;
      
   var bRetStatus=true;      
   var bIsAllNull=true;
   
   var sId=null;   
   var nCtr=null;
   var nInnerCtr=null;
   
   var oCurrElem=null;
   var oPrevElem=null;
   var oHidElem=null;
   
   var sCurrElemValue=null;
   var sPrevElemValue=null;
   
   var oEx=null;
   var sMsg=null;
   
   try
   {
      clearHidFields();
      oHidElem=getElemById("hdnValues");
      switch(sTab)
      {
         case "GEN":
            nCtrStart=1;
            nConstIndex=10;            
            break;      
         case "BKG":
            nCtrStart=11;
            nConstIndex=20;             
            break;
         case "BL":
            nCtrStart=21;
            nConstIndex=30;             
            break;        
         case "EQP":
            nCtrStart=31;
            nConstIndex=40; ;
            break;
        
      }
      for(nCtr=nCtrStart;nCtr<=nConstIndex;nCtr++)
      {
         sId=sConstTxtBox+nCtr;
         oPrevElem=getElemById(sId);
         if(oPrevElem!=null)         
         {
            sPrevElemValue=oPrevElem.value;
            sPrevElemValue=trim(sPrevElemValue);
            sPrevElemValue=sPrevElemValue.toUpperCase();            
         }
         else
            sPrevElemValue=null;  
            
         if(nCtr==nCtrStart)
            oHidElem.value=((isValidStr(sPrevElemValue)) ? sPrevElemValue : gsMtySpace);
         else
            oHidElem.value=oHidElem.value+","+((isValidStr(sPrevElemValue)) ? sPrevElemValue : gsMtySpace);
                         
         if(isValidStr(sPrevElemValue))
         {
            bIsAllNull=false; 
            
            if(containsAlphaNumHyphenOnly(sPrevElemValue))
            {           
               for(nInnerCtr=nCtr+1;nInnerCtr<=nConstIndex;nInnerCtr++)
               {
                  sId=sConstTxtBox+nInnerCtr;
                  oCurrElem=getElemById(sId);
                  if(oCurrElem!=null)
                  {
                     sCurrElemValue=oCurrElem.value;
                     sCurrElemValue=trim(sCurrElemValue);
                     sCurrElemValue=sCurrElemValue.toUpperCase();
                  }
                  else
                     sCurrElemValue=null;
                  
                  if(isValidStr(sCurrElemValue))
                  {
                     if(sPrevElemValue==sCurrElemValue)
                     {  
                        sMsg="TextBox "+(nCtr-(nCtrStart-1))+" and " +"TextBox "+(nInnerCtr-(nCtrStart-1))+" have same value:" + "\'"+sCurrElemValue+"\'.\n Please enter different values.";
                        bRetStatus=false;
                        alert(sMsg);                     
                     }
                  }            
               }
            }
            else
            {
               sMsg="For Booking and B/L numbers, enter the 11-digit numeric portion of the B/L or booking number only, excluding any alpha-prefix. \nFor Container numbers, enter the full 9 or 10-digit container number, including four character alpha prefix, and six or seven digit container number. The final check-digit is optional."; 
               bRetStatus=false;
               alert(sMsg);
               break;
            }
         } 
      }      
      if(bIsAllNull)
      {
         sMsg="Please enter value in one textbox atleast as all the textboxes cannot be empty.";
         alert(sMsg);
         bRetStatus=false;
         oEx=new Error(sMsg);
      }
     
   }
   catch(ex)
   {      
      if(gbShowErr) alert("valInputElems:\n"+ex.message);
   }
   finally
   {
      sConstTxtBox=null;
      nConstIndex=null;
      
      bIsAllNull=true;
       
      sId=null;   
      nCtr=null;
      nInnerCtr=null;
   
      oCurrElem=null;
      oPrevElem=null;
      oHidElem=null;
   
      sCurrElemValue=null;
      sPrevElemValue=null;
   
      oEx=null;
      sMsg=null;       
   }
   return bRetStatus;   
}

/*
|| Resets all the input elements of the instaTrackSearch page besides making the div
|| invisible.
*/

function resetElems(sTab)
{
   var sConstTxtBox="txtInstaNum";
   var nConstIndex=10;
   
   var sId=null;   
   var nCtr=null;
   var nCtrStart;
   var nConstIndex;
   var oPrevElem=null;
   var sPrevElemValue=null;  
   try
   {
      clearHidFields();
      switch(sTab)
      {
         case "GEN":
            nCtrStart=1;
            nConstIndex=10;            
            break;      
         case "BKG":
            nCtrStart=11;
            nConstIndex=20;             
            break;
         case "BL":
            nCtrStart=21;
            nConstIndex=30;             
            break;        
         case "EQP":
            nCtrStart=31;
            nConstIndex=40; ;
            break;
        
      }
      for(nCtr=nCtrStart;nCtr<=nConstIndex;nCtr++)
      {
         sId=sConstTxtBox+nCtr;
         oPrevElem=getElemById(sId);
         if(oPrevElem!=null) oPrevElem.value=gsMtySpace;  
      }      
   }
   catch(ex)
   {
      if(gbShowErr) alert("resetElems:\n"+ex.message);
   }
   finally
   {
      sConstTxtBox=null;
      nConstIndex=null;
             
      sId=null;   
      nCtr=null;
      
      oPrevElem=null;        
      sPrevElemValue=null;
   }
   return;
}

/*
|| Shows error if any in the instaTrackSearch page by making the div
|| visible and according updating the table with error message.
*/

function showSearchError()
{
   var sId=null;
   var oHidElem=null;
   var sErrMsgTxt=null;
   var sInputNos=null;
   var sIsEqpList=null;
   var sColourIndicator=null;
   
   var oTxtNode=null;
   var oTdElem=null;
   var oElem=null;
   
   var sConstTextBox="txtInstaNum";
   var oArrTextBoxesValue=null;
   var oArrColourIndicator=null;
   var sColourValues=null;
   var sTab=null;
   var nCtr=0;
   var nLoopCtr=0;
   try
   {  
      sId="hdnErrMsgTxt";
      oHidElem=getElemById(sId);
      if(oHidElem != null) sErrMsgTxt=oHidElem.value;
            
      if(isValidStr(sErrMsgTxt))
      {  
                  
         sId="divErrorMsg";        
         oHidElem=getElemById(sId);         
         if(oHidElem != null) oHidElem.style.display=gsMtySpace;          
         oTxtNode=document.createTextNode(sErrMsgTxt);
         
         sId="tdErrorImgTxt";
         oTdElem=getElemById(sId);         
         if(oTdElem != null) oTdElem.appendChild(oTxtNode);
         
         sId="hdnColourIndicator";
         oElem=getElemById(sId);
         if(oElem!=null) sColourValues=oElem.value;
         oArrColourIndicator=sColourValues.split(',');
         
         sId="hdnValues";
         oElem=getElemById(sId);
         if(oElem!=null) sInputNos=oElem.value;
         oArrTextBoxesValue=sInputNos.split(',');
         sTab=getElemById("hdnQueryType").value;
         switch(sTab)
         {
            case "GEN":
               nCtrStart=1;
               nConstIndex=10;            
               break;      
            case "BKG":
               nCtrStart=11;
               nConstIndex=20;             
               break;
            case "BL":
               nCtrStart=21;
               nConstIndex=30;             
               break;        
            case "EQP":
               nCtrStart=31;
               nConstIndex=40; ;
               break;
      }
         
         if(oArrColourIndicator.length==oArrTextBoxesValue.length)
         {
            
            for(nLoopCtr=nCtrStart;nLoopCtr<=nConstIndex;nLoopCtr++)
            {
               sId=sConstTextBox+(nLoopCtr);
               oElem=getElemById(sId);
               if (nCtr<oArrTextBoxesValue.length)
               { 
                  if(oElem!=null) oElem.value=oArrTextBoxesValue[nCtr];
                  if(oArrColourIndicator[nCtr]=="Y")
                  {
                     oElem.style.borderStyle="solid";
                     oElem.style.borderColor="red";
                  }
                  nCtr++;
               }
            }
         }
         else
         {
            alert("Indicator is not equal to no. of text boxes:"+oArrColourIndicator.length+"<>"+oArrTextBoxesValue.length);
         }
      }
      else
      {
         clearHidFields();  
      }
   }
   catch(ex)
   {
      if(gbShowErr) alert("showSearchError:\n"+ex.message);
   }
   finally
   {
      sId=null;
      sURL=null;
      sPage=null;
      oHidElem=null;
      sErrMsgTxt=null;
      sInputNos=null;
      sIsEqpList=null;
      sColourIndicator=null;   
      
      oTxtNode=null;
      oTdElem=null;
      oElem=null;
      
      sConstTextBox=null;
      oArrTextBoxesValue=null;
      oArrColourIndicator=null;
      sColourValues=null;
      nCtr=null;
   }
}

/*
|| Called by InstaTrackEqpDetails body prior to finish before loading.
|| Checks for error and if then the control goes to InstaTrackSearch page.
*/

function checkForError(sPageTyp)
{
   var sURL=null;
   var sPage=null;
   var sId=null;
   var oHidElem=null;
   var sErrMsgTxt=null;
   var sInputNos=null;
   var sIsEqpList=null;
   var sQueryType=null;
   var sColourIndicator=null;
  
   try
   {
      
      sId="hdnSearchValues";
      oHidElem=getElemById(sId);
      if(oHidElem != null) sInputNos=oHidElem.value;
      
      sId="hdnIsEqpList";
      oHidElem=getElemById(sId);
      if(oHidElem != null) sIsEqpList=oHidElem.value;
      if(sIsEqpList=="E" || sIsEqpList == "X")
      {
         sId="hdnColourIndicator";
         oHidElem=getElemById(sId);
         if(oHidElem != null) sColourIndicator=oHidElem.value;
      
         sId="hdnErrMsgTxt";
         oHidElem=getElemById(sId);
         if(oHidElem != null) sErrMsgTxt=oHidElem.value;
            
         
         sId="hdnQueryType";
         oHidElem=getElemById(sId);
         if(oHidElem != null) sQueryType=oHidElem.value;
         
         sId="divShowSelect";
         oHidElem=getElemById(sId);
         if(oHidElem != null) oHidElem.style.display="none";
         
         sId="divShowRetun";
         oHidElem=getElemById(sId);
         if(oHidElem != null) oHidElem.style.display="none";
         
         sId="divShowClose";
         oHidElem=getElemById(sId);
         if(oHidElem != null) oHidElem.style.display="none";
         
         if(sPageTyp=='C')
         {
            sPage="InstaTrackSearch.aspx";
            sURL=sPage+"?inputNos="+sInputNos+"&isEqpList="+sIsEqpList+"&colourIndicator="+sColourIndicator+"&errMsgTxt="+sErrMsgTxt+"&QueryType="+sQueryType ;                  
         }
         location.href=sURL;
      }
      else if(sIsEqpList=="Y")
      {
         sId="divShowSelect";
         oHidElem=getElemById(sId);
         if(oHidElem != null) oHidElem.style.display=gsMtySpace;
         
         sId="divShowRetun";
         oHidElem=getElemById(sId);
         if(oHidElem != null) oHidElem.style.display="none";
         
         sId="divShowClose";
         oHidElem=getElemById(sId);
         if(oHidElem != null) oHidElem.style.display="none";
      }
      else
      {
         sId="divShowSelect";
         oHidElem=getElemById(sId);
         if(oHidElem != null) oHidElem.style.display="none";
         
         if(sPageTyp=='C')
         {
            sId="divShowRetun";
            oHidElem=getElemById(sId);
            if(oHidElem != null) oHidElem.style.display=gsMtySpace;
            
            sId="divShowClose";
            oHidElem=getElemById(sId);
            if(oHidElem != null) oHidElem.style.display="none";
         }
         else if(sPageTyp=='B')
         {
            sId="divShowRetun";
            oHidElem=getElemById(sId);
            if(oHidElem != null) oHidElem.style.display="none";
            
            sId="divShowClose";
            oHidElem=getElemById(sId);
            if(oHidElem != null) oHidElem.style.display=gsMtySpace;
         }
         
         
         
      }
   }
   catch(ex)
   {
      if(gbShowErr) alert("checkForError:\n"+ex.message);
   }
   finally
   {
      sId=null;
      sURL=null;
      sPage=null;
      oHidElem=null;
      sErrMsgTxt=null;
      sInputNos=null;
      sIsEqpList=null;
      sColourIndicator=null;   
   }
}
/*
|| select all equipment of equipment list (not logged on multiple container) .
*/

function selectAll()
{
   var sId=null;
   var oHidElem=null;
   var sName=null;
   var sEqpNo=null;
   var sEqpChkd=null;
   var sBkgOrBlValues=null;
   var nCtr=null;
   var nLength=null;
   try
   {
      clearHidFields();
      sName="chkEqpNo";
      nLength=document.forms[0].elements[sName].length;      
      for(nCtr=0;nCtr<nLength;nCtr++)
      {
         document.forms[0].elements[sName][nCtr].checked=true;
         sId="hdnEqpNo"+(nCtr+1);
         oHidElem=getElemById(sId);
         if(oHidElem != null)
         {
            if(sEqpNo==null)            
               sEqpNo=oHidElem.value;
            else
               sEqpNo=sEqpNo+","+oHidElem.value;
         }            
         sId="hdnEqpChkd"+(nCtr+1);
         oHidElem=getElemById(sId);
         if(oHidElem != null)
         {
            if(sEqpChkd==null)
               sEqpChkd=oHidElem.value;
            else
               sEqpChkd=sEqpChkd+","+oHidElem.value;
         }
         
         sId="hdnBlOrBkgNo"+(nCtr+1);
         oHidElem=getElemById(sId);
         if(oHidElem != null)
         {
            if(sBkgOrBlValues==null)            
               sBkgOrBlValues=oHidElem.value;
            else
               sBkgOrBlValues=sBkgOrBlValues+","+oHidElem.value;
         }
                        
      }         
      
      sId="hdnSearchValues";
      oHidElem=getElemById(sId);
      if(oHidElem != null) oHidElem.value=sEqpNo;
      
      sId="hdnEqpChkdValues";
      oHidElem=getElemById(sId);
      if(oHidElem != null) oHidElem.value=sEqpChkd;
      
      sId="hdnBlOrBkgValues";
      oHidElem=getElemById(sId);
      if(oHidElem != null) oHidElem.value=sBkgOrBlValues;
   }
   catch(ex)
   {
      if(gbShowErr) alert("selectAll:\n"+ex.message);
   }
   finally
   {
      sId=null;
      oHidElem=null;
      sName=null;
      sBkgOrBlValues=null;
      sEqpNo=null;
      sEqpChkd=null;
      nCtr=null;
      nLength=null;   
   }
}
/*
|| Unselect all equipment of equipment list (not logged on multiple container) .
*/

function unSelectAll()
{
   var sId=null;
   var oHidElem=null;
   var sName=null;   
   var nCtr=null;
   var nLength=null;
   try
   {
      clearHidFields();
      sName="chkEqpNo";
      nLength=document.forms[0].elements[sName].length;      
      for(nCtr=0;nCtr<nLength;nCtr++)
      {
         if(document.forms[0].elements[sName][nCtr].checked)
         {
            document.forms[0].elements[sName][nCtr].checked=false;                       
         }
      }        
      sId="hdnSearchValues";
      oHidElem=getElemById(sId);         
      if(oHidElem != null) oHidElem.value=gsMtySpace;
      
      sId="hdnEqpChkdValues";
      oHidElem=getElemById(sId);         
      if(oHidElem != null) oHidElem.value=gsMtySpace;
      
      sId="hdnBlOrBkgValues";
      oHidElem=getElemById(sId);         
      if(oHidElem != null)oHidElem.value=gsMtySpace;
   }
   catch(ex)
   {
      if(gbShowErr) alert("unSelectAll:\n"+ex.message);
   }
   finally
   {
      sId=null;
      oHidElem=null;
      sName=null;
      nCtr=null;
      nLength=null;   
   }
}
/*
|| Show Equipment movement of selected equipment list (not logged on multiple container) .
*/
function searchEqp()
{
   var sId=null;
   var oHidElem=null;
   var sName=null;
   var sEqpNo=null;
   var sEqpChkd=null;
   var sBkgOrBlValues=null;
   var nCtr=null;
   var nLength=null;
   var bStatus=true;
   try
   {
      clearHidFields();
      sName="chkEqpNo";
      nLength=document.forms[0].elements[sName].length;            
      for(nCtr=0;nCtr<nLength;nCtr++)
      {
         if(document.forms[0].elements[sName][nCtr].checked)
         {
            sId="hdnEqpNo"+(nCtr+1);
            oHidElem=getElemById(sId);
            if(oHidElem != null)
            {
               if(sEqpNo==null)            
                  sEqpNo=oHidElem.value;
               else
                  sEqpNo=sEqpNo+","+oHidElem.value;               
            }
            
            sId="hdnEqpChkd"+(nCtr+1);
            oHidElem=getElemById(sId);
            if(oHidElem != null)
            {
               if(sEqpChkd==null)
                  sEqpChkd=oHidElem.value;
               else
                  sEqpChkd=sEqpChkd+","+oHidElem.value;
            }
         
            sId="hdnBlOrBkgNo"+(nCtr+1);            
            oHidElem=getElemById(sId);
            if(oHidElem != null)
            {
               if(sBkgOrBlValues==null)            
                  sBkgOrBlValues=oHidElem.value;
               else
                  sBkgOrBlValues=sBkgOrBlValues+","+oHidElem.value;
            }
               
         }       
      }
      if(sEqpNo==null)
      {
         alert("Please select atleast one container.");
         bStatus=false;
      }
      else
      {
         sId="hdnSearchValues";
         oHidElem=getElemById(sId);         
         if(oHidElem != null) oHidElem.value=sEqpNo;
         
         sId="hdnEqpChkdValues";
         oHidElem=getElemById(sId);
         if(oHidElem != null) oHidElem.value=sEqpChkd;
         
         sId="hdnBlOrBkgValues";
         oHidElem=getElemById(sId);
         if(oHidElem != null) oHidElem.value=sBkgOrBlValues;
      }           
   }
   catch(ex)
   {
      if(gbShowErr) alert("searchEqp:\n"+ex.message);
   }
   finally
   {
      sId=null;
      oHidElem=null;
      sName=null;      
      sEqpNo=null;
      sEqpChkd=null;
      sBkgOrBlValues=null;
      nCtr=null;
      nLength=null;   
   }
   return bStatus;
}
/*
|| Open up Custom hold information page.
*/
function displayCustomHold(sBlNoUid, sBlNo, sHoldRsn)
{
   var oWin=null;
   var sPage=null;
   var sURL=null;
   var nTop=null;
   var nLeft=null;
   var nConstHeight = 580;
   var nConstWidth = 460;
        
   try
   { 
     
      nTop = (self.screen.height/2)-(nConstHeight/2);
      nLeft = (self.screen.width/2)-(nConstWidth/2);
      sURL = "../UITracking/CustomHold.aspx?BlBkgNoUid="+sBlNoUid+"&"+"BlNo="+sBlNo+"&"+"HoldRsn="+sHoldRsn+"&"+"CallTyp=B",1,"toolbar=no,scrollbars=yes,fullscreen=no,menubar=no,status=no,directories=no,location=no";
       oWin=winOpen(sURL, "WinCustHold", nTop, nLeft, nConstHeight, nConstWidth); 
   }
   catch(ex)
   {
      if(gbShowErr) alert("displayCustomHold:\n"+ex.message);
   }
   finally
   {
      sPage=null;
      sURL=null;                       
   }
}
/*
|| Open up BL/Booking/Equipment Movement window .
*/
function displayCargo(sBlNo, sEqpNo, sCheckDigit)
{
   var oWin=null;
   var sPage=null;
   var sURL=null;
   try
   { 
      sPage="../UIINSTATrack/InstaTrackEqpDetails.aspx?HdrFtrFlg=N&BlNo="+sBlNo+"&"+"EqpNo="+sEqpNo+"&"+"EqpChkd="+sCheckDigit+"&"+"CallTyp=B",1,"toolbar=no,scrollbars=yes,fullscreen=no,menubar=no,status=no,directories=no,location=no,width=450,height=450,left=0,top=0";
      sURL=sPage; 
      oWin=window.open(sURL);
   }
   catch(ex)
   {
      if(gbShowErr) alert("displayCargo:\n"+ex.message);
   }
   finally
   {
      sPage=null;
      sURL=null;                       
   }
}

/*
|| Popups eqp type page.
*/

function showEqpTypDtls(sEqpTyp)
{
   var sHREF=null;
   var sURL=null;
   var sPage=null;
   var nTop=null;
   var nLeft=null;   
   var oWin=null;
   var nConstWidth=400;
   var nConstHeight=400;
   try
   {  
      if(isValidStr(sEqpTyp))
      {
         sHREF=location.href;         
         sHREF=sHREF.toUpperCase();
         sURL=location.href.substr(0, sHREF.indexOf("UIINSTATRACK"));
         sPage="UIAboutMOL/EquipmentDetails.aspx";      
         sURL+=sPage+'?eqp_typ='+sEqpTyp;
         //alert(sURL);
         nTop = (self.screen.height/2)- (nConstHeight/2);
         nLeft = (self.screen.width/2)- (nConstWidth/2);               
         oWin=winOpen(sURL, "winEqpTypDtls", nTop, nLeft, nConstHeight, nConstWidth);
         
      }
   }
   catch(ex)
   {
      if(gbShowErr) alert("showEqpTypDtls:\n"+ex.message);
   }
   finally
   { 
      sHREF=null;
      sURL=null;
      sPage=null;
      nTop=null;
      nLeft=null;        
      nConstWidth=null;
      nConstHeight=null;   
   }
}

/*
|| Popups vessel page.
*/

function showVslDtls(sVslName)
{
   var sHREF=null;
   var sURL=null;
   var sPage=null;
   var nTop=null;
   var nLeft=null;
   var oWin=null;
   var nConstWidth = 400;
   var nConstHeight = 400;
   try
   {  
      if(isValidStr(sVslName))
      {
         sHREF=location.href;         
         sHREF=sHREF.toUpperCase();
         sURL=location.href.substr(0, sHREF.indexOf("UIINSTATRACK"));
         
         // Ramana Vemula -- made changes for the SATS USWEB090533296
         sPage = "UIAboutMOL/P2PVesselInfo_v2.aspx";
         sURL += sPage + '?Vsl=' + sVslName;
         var nWidth = 1000;
         var nHeight = 600;
         var nLeft = 0;
         var nTop = 0;

         var oWin = window.open(sURL, null,
                    "toolbar=yes,location=yes,scrollbars=yes,resizable=yes,menubar=yes,maximize=yes,width=" +
                    nWidth + ",height=" + nHeight + ",left=" + nLeft + ",top=" + nTop + "");

         oWin.focus();

         /*
         sPage="UIAboutMOL/VesselDetails.aspx";
         sURL += sPage + '?vsl_name=' + sVslName;
         nTop = (self.screen.height/2)- (nConstHeight/2);
         nLeft = (self.screen.width/2)- (nConstWidth/2);                  
         oWin=winOpen(sURL, "winVslDtls", nTop, nLeft, nConstHeight, nConstWidth);*/
      }
   }
   catch(ex)
   {
      if(gbShowErr) alert("showVslDtls:\n"+ex.message);
   }
   finally
   {
      sHREF=null;
      sURL=null;
      sPage=null;
      nTop=null;
      nLeft=null;
      nConstWidth=null;
      nConstHeight=null;
   }
}


function ClickSplitBLBKG(sBlBkgNo,sBlBkgSfx,sExpImp,sType)
{
   var sURL=null;
   var sInput=null;
   try
   {
      sInput = sBlBkgNo + sBlBkgSfx;
      sURL="InstaTrackEqpDetails.aspx?BlNo="+sBlBkgNo+"&BlBkgSfx="+sBlBkgSfx+"&ExpImp="+sExpImp+"&QueryType="+sType+"&CallTyp=C";         
      window.opener.location.href=sURL;
      window.opener.focus();
      window.close();
   }
   catch(ex)
   {
      if(gbShowErr) alert("ClickSplitBLBKG:\n"+ex.message);
   }
   finally
   {
   }
}



/*
|| Popups vessel page.
*/

function showBlDtls(sBlNo)
{   
   var sURL=null;
   var sPage=null;
   var nTop=null;
   var nLeft=null;
   var oWin=null;
   var nConstWidth = 925;
   var nConstHeight = 450;
   try
   {  
      if(isValidStr(sBlNo))
      {           
         sPage="BLSearchResult.aspx?BlNo="+sBlNo+"&FrmBlTyp=M",1,"toolbar=no,fullscreen=no,scrollbars=yes,menubar=no,status=no,directories=no,location=no,width=450,height=450,left=0,top=0";
         sURL=sPage;
         sURL=sPage; 
         oWin=window.open(sURL);
         
      }
   }
   catch(ex)
   {
      if(gbShowErr) alert("showBlDtls:\n"+ex.message);
   }
   finally
   {
      sURL=null;
      sPage=null;
      nTop=null;
      nLeft=null;
      nConstWidth=null;
      nConstHeight=null;
   }
}

function mOver(sMsg)
{
   
   window.status=sMsg;
}

function mOut()
{
   window.status=gsMtySpace;
   
}
//* open up Track Via E-Mail
function ClickTrackViaMail()
{
   var oWin;
   try
   {
      oWin=winOpen("/htm/emailTrack.htm","newPop",250,250,170,500);
   } 
   catch(ex)
   {
      if(gbShowErr) alert("isValidStr:\n"+ex);
   }
   
}

/*
|| Opens the window.
*/

function winOpen(sURL, sName, nTop, nLeft, nHeight, nWidth)
{ 
   var oWin; 

   oWin = window.open(sURL, sName, "modal=yes,dependent=yes,status=yes,toolbars=no,directory=no,scrolling=yes,scrollbars=yes,resizable=no,width="+nWidth +",height="+nHeight +",left="+nLeft+",top=" + nTop +gsMtySpace );
   oWin.focus(); 
   return;
}


/*
|| Helper function. Validates the string.
*/

function isValidStr(sVal)
{
   try
   {
      if( (sVal!=null) && (sVal!=undefined) && (sVal.length > 0) )
      {
         if( ( /[^\t\n\r ]/.test(sVal) ) ) return true;
      }      
   }
   catch(ex)
   {
      if(gbShowErr) alert("isValidStr:\n"+ex);
   }
   return false;
}

/*
|| Helper function. Clears all hidden fields and hid the div of InstaTrackSearch and details page.
*/ 

function clearHidFields()
{   
   var sId=null;
   var oHidElem=null;
   var sConstTextBox="txtInstaNum";
   var nCtr=null;
   var oElem=null;
      
   try
   {
      sId="hdnSearchValues";
      oHidElem=getElemById(sId);
      if(oHidElem != null) oHidElem.value=gsMtySpace;      
      
      sId="hdnEqpChkdValues";
      oHidElem=getElemById(sId);
      if(oHidElem != null) oHidElem.value=gsMtySpace;
         
      sId="hdnBlOrBkgValues";
      oHidElem=getElemById(sId);
      if(oHidElem != null) oHidElem.value=gsMtySpace;
               
      sId="hdnIsEqpList";
      oHidElem=getElemById(sId);
      if(oHidElem != null) oHidElem.value=gsMtySpace;
      
      sId="hdnColourIndicator";
      oHidElem=getElemById(sId);
      if(oHidElem != null) oHidElem.value=gsMtySpace;
      
      sId="hdnErrMsgTxt";
      oHidElem=getElemById(sId);
      if(oHidElem != null) oHidElem.value=gsMtySpace;
      
      sId="divErrorMsg";
      oElem=getElemById(sId);
      if(oElem!=null) getElemById(sId).style.display="None";
      
      for(nCtr=0;nCtr<10;nCtr++)
      {
         sId=sConstTextBox+(nCtr+1);
         if(oElem!=null)
         {
            oElem=getElemById(sId);            
            oElem.style.borderStyle=gsMtySpace;
            oElem.style.borderColor=gsMtySpace;  
         }
      }
   }
   catch(ex)
   {
      if(gbShowErr) alert("clearHidFields:\n"+ex.message);
   }
   finally
   {
      sId=null;       
      oHidElem=null;
      sConstTextBox=null;
      nCtr=null;
      oElem=null;
   }
}



/*
|| Helper function. Get element by ID.
*/

function getElemById(sId)
{
   var oElem=null;   
   try
   {
      oElem=document.getElementById(sId);
   }
   catch(ex)
   {
      if(gbShowErr) alert("getElemById:\n"+ex);
   }
   return oElem;
}

/*
|| Helper function. Trims the string.
*/

function trim(sString)
{
   while (sString.substring(0,1) == ' ')
   {
      sString = sString.substring(1, sString.length);
   }
   
   while (sString.substring(sString.length-1, sString.length) == ' ')
   {
      sString = sString.substring(0,sString.length-1);
   }
   return sString;
}

/*
|| Helper function. Checks and return boolean value for [0-11][a-z] and hypen "-".
*/

function containsAlphaNumHyphenOnly(sValue)
{ 
   var sRegExp=/\d{9,11}[A-Z]?$/;
   try
   {
      if(sRegExp.test(sValue)) //bl_no, bkg_no with suffix
         return true;
      else
      {
         sRegExp=/[A-Z]{4}\d{6}\d?\d?$/;
         if(sRegExp.test(sValue)) //For eqp no with suffix
            return true;
         else
            return false;
      }
   }
   catch(ex)
   {
      if(containsAlphaNumAndHyphen) alert("containsAlphaNumHyphenOnly:\n"+ex.message);
   }
   finally
   {  
      sRegExp=null;                  
   }
}
/*
|| Select/Unselect All the containers.
*/

function ChechUncheck(sId)
{
   var oRow=null;
   var oCol=null;
   var sColTxt;
   var nTotRows;
   var sCtlName=null;
   var sChildCtlName=null;
   try
   {
     oTbl=getElemById(sId);
     sCtlName="chk_"+sId;
     nTotRows = oTbl.getElementsByTagName("tr").length;
     for(Ctr=0;Ctr<nTotRows;Ctr++)               
     {
        oRow = oTbl.getElementsByTagName("tr").item(Ctr);
        oCol=oRow.getElementsByTagName("td").item(0);
        if (getElemById(sCtlName).checked==true) 
           firstChild(oCol).checked =true;      
        else
           firstChild(oCol).checked =false;
     }
   }
   catch(ex)
   {
      if(gbShowErr) alert("ChechUncheck:\n"+ex.message);
   }
   finally
   {
      oRow=null;
      oCol=null;
      sColTxt;
      nTotRows;
      sCtlName=null;
      sChildCtlName=null;
   }
}
/*
|| Redirect selected container to Insta-Track page.
*/

function displaySelEqp(sId)
{
   var oRow=null;
   var oCol=null;
   var sColTxt;
   var nTotRows;
   var sCtlName=null;
   var sEqpNo;
   var sEqpChk;
   var sBlBkgNo;
   var intPos;
   var bStatus=true;
   var sText= new Array();
   
   var sChildCtlName=null;
   try
   {
     oTbl=getElemById(sId);
     sCtlName="chk_"+sId;
     nTotRows = oTbl.getElementsByTagName("tr").length;
     for(Ctr=0;Ctr<nTotRows;Ctr++)               
     {
        oRow = oTbl.getElementsByTagName("tr").item(Ctr);
        oCol=oRow.getElementsByTagName("td").item(0);
        if (firstChild(oCol).checked==true)
        {
           sText=(ValueOf(nodeAfter(firstChild(oCol)))).split(",");           
          
           if(sEqpNo==null)            
              sEqpNo=sText[0];
           else
              sEqpNo=sEqpNo+","+sText[0];
           if(sEqpChk==null)            
              sEqpChk=sText[1];
           else
              sEqpChk=sEqpChk+","+sText[1];
           if(sBlBkgNo==null)            
              sBlBkgNo=sText[2];
           else
              sBlBkgNo=sBlBkgNo+","+sText[2];
        }
     }  
     if(sEqpNo==null)
     {
        alert("Please select atleast one container.");
        bStatus=false;
     }  
     else
     {
        sId="hdnSearchValues";
        oHidElem=getElemById(sId);
        if(oHidElem != null) oHidElem.value=sEqpNo;
      
        sId="hdnEqpChkdValues";
        oHidElem=getElemById(sId);
        if(oHidElem != null) oHidElem.value=sEqpChk;
      
        sId="hdnBlOrBkgValues";
        oHidElem=getElemById(sId);
        if(oHidElem != null) oHidElem.value=sBlBkgNo;
//       document.forms[0].submit();
//       window.location.replace("Instatrackeqpdetails.aspx");
       window.__doPostBack('displaySelEqp', '');
       
     }
   }
   catch(ex)
   {
      if(gbShowErr) alert("displaySelEqp:\n"+ex.message);
   }
   finally
   {
      oRow=null;
      oCol=null;
      sColTxt;
      nTotRows;
      sCtlName=null;
      sChildCtlName=null;
   }
}


/*
|| Redirect all container to Insta-Track equipment movement page(View All).
*/

function displayAll(sId)
{
   var oRow=null;
   var oCol=null;
   var sColTxt;
   var nTotRows;
   var sCtlName=null;
   var sEqpNo;
   var sEqpChk;
   var sBlBkgNo;
   var intPos;
   var bStatus=true;
   var sText= new Array();
   
   var sChildCtlName=null;
   try
   {
      oTbl=getElemById(sId);
      sCtlName="chk_"+sId;
      nTotRows = oTbl.getElementsByTagName("tr").length;
      for(Ctr=0;Ctr<nTotRows;Ctr++)               
      {
         oRow = oTbl.getElementsByTagName("tr").item(Ctr);
         oCol=oRow.getElementsByTagName("td").item(0);
         
         sText=(ValueOf(nodeAfter(firstChild(oCol)))).split(",");           
           
         if(sEqpNo==null)            
            sEqpNo=sText[0];
         else
            sEqpNo=sEqpNo+","+sText[0];
         if(sEqpChk==null)            
            sEqpChk=sText[1];
         else
            sEqpChk=sEqpChk+","+sText[1];
         if(sBlBkgNo==null)            
            sBlBkgNo=sText[2];
         else
            sBlBkgNo=sBlBkgNo+","+sText[2];
      }
      sId="hdnSearchValues";
      oHidElem=getElemById(sId);
      if(oHidElem != null) oHidElem.value=sEqpNo;
      
      sId="hdnEqpChkdValues";
      oHidElem=getElemById(sId);
      if(oHidElem != null) oHidElem.value=sEqpChk;
       
      sId="hdnBlOrBkgValues";
      oHidElem=getElemById(sId);
      if(oHidElem != null) oHidElem.value=sBlBkgNo;
      __doPostBack('displayAll', '');
    
   }
   catch(ex)
   {
      if(gbShowErr) alert("displayAll:\n"+ex.message);
   }
   finally
   {
      oRow=null;
      oCol=null;
      sColTxt;
      nTotRows;
      sCtlName=null;
      sChildCtlName=null;
   }
}

/*
|| Pop-up CLM info window.
*/

function showClmInfo(sEqpNo,sRefNo)
{
   var sURL=null;
   var sPage=null;
   var nTop=null;
   var nLeft=null;
   var oWin=null;
   var sLocalEqpNo=null;
   var sLocalIri=null;
   var sLocalClm=null;
   var sLocalArv=null;
   var sLocalsRefNo=null;
   var sConstNA="N/A";
   try
   {
      (isValidStr(sEqpNo)) ? sLocalEqpNo=sEqpNo : sLocalEqpNo=sConstNA;
        sPage = "http://www.molpower.com/VLCWeb/UITracking/CLMTrackingDtls.aspx?EqpNo="+sLocalEqpNo+"&RefNo="+sRefNo;
        sName = "CLM Info";
      sURL=sPage;         
      oWin = window.open();
      oWin.location.href=sURL;
      oWin.focus();
   }
   catch(ex)
   {
      if(gbShowErr) alert("showClmInfo:\n"+ex.message);
   }
   finally
   {
      sURL=null;
      sPage=null;
      nTop=null;
      nLeft=null;
      nConstWidth=null;
      nConstHeight=null;
   }
}
//* Purpose of this function to select All the items in the INSTA-Track favourite.

function ClickSelAll()
{
   var sId;
   var oHidElem;
   var oTbl=null;
   var oRow=null;
   var oCol=null;
   var oElm=null;
   var sColTxt;
   var nTotRows;
   var Ctr;
   try
   {
      
      sId="hdnSelAllFlg";
      oHidElem=getElemById(sId);
      oTbl= getElemById("grvFavList");
      nTotRows= getElemById("hdngrvFavListRowCount").value;
      for(Ctr=1;Ctr<=nTotRows;Ctr++)               
      {
          oRow = oTbl.getElementsByTagName("tr").item(Ctr);
          oCol=oRow.getElementsByTagName("td").item(0);
          oElm=firstChild(oCol);
         while(oElm.type !="checkbox")
         {
            oElm = firstChild(oElm);
         }
         if (getElemById("chkgrvFavListSelAll").checked ==true)
            oElm.checked =false;
         else
            oElm.checked =true;
      }
   }
   catch(ex)
   {
      if(gbShowErr) alert("ClickSelAll:\n"+ex.message);
   }
   finally
   {
   }
   
}
//* Purpose of this function to select the header when all child items in the INSTA-Track favourite are checked.
function CheckAll(sId)
{
   var oTbl=null;
   var oRow=null;
   var oCol=null;
   var sColTxt;
   var nTotRows;
   var Ctr;
   var sAllChk="Y";
   try
   {
      if (sId.checked==false)
         getElemById("chkgrvFavListSelAll").checked=false;
      else
      {
         oTbl= getElemById("grvFavList");
         nTotRows= getElemById("hdngrvFavListRowCount").value;
         for(Ctr=1;Ctr<nTotRows;Ctr++)               
         {
            oRow = oTbl.getElementsByTagName("tr").item(Ctr);
            oCol=oRow.getElementsByTagName("td").item(0);
            if (firstChild(oCol).checked ==false)
               sAllChk="N";
           
         }
          if (sAllChk=="Y")
               getElemById("chkgrvFavListSelAll").checked=true;
      }
   }
   catch(ex)
   {
      if(gbShowErr) alert("ClickSelAll:\n"+ex.message);
   }
   finally
   {
   }
}
//* Purpose of this function is to select all the split BL/BKG.
function selectAllSplit(sTblName,sCtlName)
{
   var sId;
   var oHidElem;
   var oTbl=null;
   var oRow=null;
   var oCol=null;
   var sColTxt;
   var nTotRows;
   var Ctr;
   try
   {
 
     oTbl= getElemById(sTblName);
     nTotRows = getElemById ("hdngrvRowCount").value;
     for(Ctr=1;Ctr<=nTotRows;Ctr++)               
     {
        oRow = oTbl.getElementsByTagName("tr").item(Ctr);
        oCol=oRow.getElementsByTagName("td").item(0);
        oElm=firstChild(oCol);
        while(oElm.type !="checkbox")
        {
           oElm = firstChild(oElm);
        }
        
        if (getElemById(sCtlName).checked ==true)
           oElm.checked =false;
        else
           oElm.checked =true;
     }
   }
   catch(ex)
   {
      if(gbShowErr) alert("selectAllSplit:\n"+ex.message);
   }
   finally
   {
   }
}
/*
|| Helper function. Checks and return all supplement B/Ls against a B/L number.
*/

function displaySupplBls(sBlNo)
{
   var oWin=null;
   var sPage=null;
   var sURL=null;
   
   try
   { 
      sPage="../UITracking/SupplBL.aspx?BlNo="+sBlNo;
      sURL=sPage;           
      oWin=window.open(sURL);     
   }
   catch(ex)
   {
   }
   finally
   {
      sPage=null;
      sURL=null;                     
   }
 }
 function CheckRemove(sTblName)
 {
    var oTbl=null;
    var oRow=null;
    var oCol=null;
    var sColTxt;
    var sConfirm;
    var nTotRows;
    
    var Ctr;
    var sAllChk="N";
    try
    {
       
       oTbl= getElemById("grvFavList");
       nTotRows= getElemById("hdngrvFavListRowCount").value;
       for(Ctr=1;Ctr<=nTotRows;Ctr++)               
       {
          oRow = oTbl.getElementsByTagName("tr").item(Ctr);
          oCol=oRow.getElementsByTagName("td").item(0);
          oElm=firstChild(oCol);
          while(oElm.type !="checkbox")
          {
             oElm = firstChild(oElm);
          }
          if (oElm.checked ==false)
             sAllChk="N";
          if (oElm.checked ==true)
          {
             sAllChk="Y";
             break;
          }
       }
       if (sAllChk=="Y")
       {
             sConfirm = confirm('Are you sure to remove?')
             if (sConfirm)
                return true;
             else
                return false;
       }
       else
       {
          alert("No row(s) selected");
          return false;
       }
    }
    catch(ex)
    {
       if(gbShowErr) alert("CheckRemove:\n"+ex.message);
    }
    finally
    {
    }
 }
 
/*
|| Redirect selected containers to Insta-Track equipment movement page(View All).
*/

function displaySplitBlBkg(sId,sType)
{
   var oRow=null;
   var oCol=null;
   var sColTxt;
   var oTxtFlg=null;
   var oTbl=null;
   var oParFrm=null;
   var nTotRows;
   var sCtlName=null;
   var sFlg=null;
   var oElm=null;
   var sExpImpflg;
   var sBlBkgsfx;
   var sBlBkgNo;
   var intPos;
   
   var sText= new Array();
   
   var sChildCtlName=null;
   try
   {
      oTbl=getElemById(sId);
      
      nTotRows = getElemById ("hdngrvRowCount").value;
      for(Ctr=1;Ctr<=nTotRows;Ctr++)               
      {
         oRow = oTbl.getElementsByTagName("tr").item(Ctr);
         oCol=oRow.getElementsByTagName("td").item(0);
         oElm=firstChild(oCol);
        while(oElm.type !="checkbox")
        {
           oElm = firstChild(oElm);
        }
         if (oElm.checked ==true)
         {
            sText=(ValueOf(lastChild(oCol))).split(",");           

            if(sBlBkgNo==null)            
               sBlBkgNo=sText[0];
            else
               sBlBkgNo=sBlBkgNo+","+sText[0];
            
            if(sBlBkgsfx==null)            
               sBlBkgsfx=sText[1];
            else
               sBlBkgsfx=sBlBkgsfx+","+sText[1];
            
            if(sExpImpflg==null)            
               sExpImpflg=sText[2];
            else
               sExpImpflg=sExpImpflg+","+sText[2];
         }
      }
      
      if (sBlBkgNo != null && sBlBkgNo!="")
      {
         oParFrm = window.opener.document;
         sFlg="hdnBlOrBkgValues"; 
         getElemByPar(sFlg,oParFrm).value = sBlBkgNo;
      }
      
      if (sBlBkgsfx != null || sBlBkgsfx!="")
      {
         oParFrm = window.opener.document;
         
         sFlg="hdnBLBKGsfx"; 
         getElemByPar(sFlg,oParFrm).value = sBlBkgsfx;
      }      
         
      if (sExpImpflg != null || sExpImpflg!="")
      {
         oParFrm = window.opener.document;
         sFlg="hdnExpImpflg"; 
         getElemByPar(sFlg,oParFrm).value = sExpImpflg;
      } 
      if (sType != null || sType!="")
      {
         oParFrm = window.opener.document;
         
         sFlg="hdnQueryType"; 
         getElemByPar(sFlg,oParFrm).value = sType;
      }       
         
      if (sBlBkgNo==null)
         alert("No values selected");
      else
      {
         window.close();
         window.opener. __doPostBack('__Page', 'displaySplitBLBKG');
      }
     
   }
   catch(ex)
   {
      if(gbShowErr) alert("displaySplitBlBkg:\n"+ex.message);
   }
   finally
   {
      oRow=null;
      oCol=null;
      sColTxt;
      nTotRows;
      sCtlName=null;
      sChildCtlName=null;
   }
}
// Save a particular item to Favourite list of the INSTA-TRACK
function SaveFavouriteOne(sValFav)
{
   var sText= new Array();
   var sNoUid= new Array();
   var sVal= new Array();
   var sType= new Array();
   var sUser=null;
   var sFavDomain=null;
   var Ctr;
   var ArrCtr=0;
   try
   {
     if (getElemById("hdnUser").value !="")
     {
        sText=sValFav.split(",");
     
        sNoUid[0] = sText[0];
        sVal[0] = sText[1];
        sType[0] = sText[2];
    
        sUser = getElemById("hdnUser").value;
        sFavDomain = getElemById("hdnFavDomain").value;
        Client.WebService.InstaTrack.SaveFavList.SaveFavourite(sNoUid,sVal,sType,sFavDomain,sUser,OnComplete, OnError, OnTimeOut);
     }
     else
        alert (" Only logged on user can add item(s) to their favorites");
   }
   catch(ex)
   {
      if(gbShowErr) alert("SaveFavourite:\n"+ex.message);
   }
   finally
   {
   }
}
// Save All the items to the Favourite list of the INSTA-TRACK
function SaveFavouriteAll()
{
   var sText= new Array();
   var sNoUid= new Array();
   var sVal= new Array();
   var sType= new Array();
   var sUser=null;
   var sFavDomain=null;
   var Ctr;
   var ArrCtr=0;
   try
   {
      if (getElemById("hdnUser").value !="")
      {
         sText=getElemById("hdnFavValue").value.split(",");
         for(Ctr=0;Ctr<sText.length;Ctr=Ctr+3)               
         {
            sNoUid[ArrCtr] = sText[Ctr];
            sVal[ArrCtr] = sText[Ctr+1];
            sType[ArrCtr] = sText[Ctr+2];
            ArrCtr++; 
         } 
      
         sUser = getElemById("hdnUser").value;
         sFavDomain = getElemById("hdnFavDomain").value;
         Client.WebService.InstaTrack.SaveFavList.SaveFavourite(sNoUid,sVal,sType,sFavDomain,sUser,OnComplete, OnError, OnTimeOut);
      }
      else
         alert (" Only logged on user can add items to their favorites");
   }
   catch(ex)
   {
      if(gbShowErr) alert("SaveFavourite:\n"+ex.message);
   }
   finally
   {
   }
}
function OnComplete(arg)
{
  alert(arg);
}

function OnTimeOut(arg)
{
  alert("timeOut has occured");
}
function OnError(arg)
{
  alert("error has occured: " + arg._message);
}

function ValueOf(ojbNode)
{
  var sVal = null;
  try
  {
     sVal = ojbNode.value;
  
     // Use ECMA-262 Edition 3 String and RegExp features
  
     sVal = sVal.replace(/[\t\n\r ]+/g, " ");
     if(sVal.charAt(0) == " ")
       sVal = sVal.substring(1, sVal.length);
     if(sVal.charAt(sVal.length - 1) == " ")
       sVal = sVal.substring(0, sVal.length - 1);
  }
  catch(ex)
  {
     if(gbDebug) alert("ValueOf:\n"+ex);
  }
  return sVal;
}