﻿function doBlink() 
{
    // Blink, Blink, Blink...
    var blink = document.all.tags("blink")
    
    for (var i=0; i < blink.length; i++)
    {
        if (blink[i].style.visibility != "hidden")
            blink[i].style.visibility = "hidden";
        else
            blink[i].style.visibility ="visible";
       // blink[i].style.visibility = blink[i].style.visibility == "inline" ? "hidden" : "inline" 
    }
}  
                 
function startBlink(miliSeconds) 
{                                      
    if (document.all)
        setInterval( "doBlink()",  miliSeconds)
}

function doOnLoad() 
{
    hideHiddenTextFields();
//    if (navigator.appName != "Microsoft Internet Explorer")
//    {
//        document.getElementById("imgNew").style.display="none"
//        document.getElementById("lnkMap").style.display="none"
//    }
    
    ShowYomanMasa();
     window.focus();
    //clearAllBusy(); 
} 


function hideTableColumns(objId, columnsIndex) 
{
    if(columnsIndex)  
    {   
//        if (navigator.appName != "Microsoft Internet Explorer")
//            columnsIndex += "12|" ; //HIde Map column if not EI
          
        var wTable = document.getElementById(objId);
        
        if(wTable!=null)
        {
           var arr = columnsIndex.split("|");  
           
           for(i=0 ; i < wTable.rows.length ; i++)
           {
              if(wTable.rows[i].cells.length > 1) /* TO MAKE SURE IT IS NOT THE FOOTER */
              {
                for(j=0 ; j<arr.length - 1 ; j++)
                    wTable.rows[i].cells[parseInt(arr[j])].style.display = "none";
              }
           }
        }  
    }
}

function GetValuesFromRow(GridName, sCollsInex, rowIndex)
{
   var tbl = document.getElementById(GridName); 
 
   if(tbl != null)
   {    
        var arrColls = sCollsInex.split("|")
        var arrRetValues =new Array(arrColls.length);
        var isIE = true
        
        if (navigator.appName != "Microsoft Internet Explorer" )       
            isIE = false
        
         if(rowIndex != null)
         {
            for (n=0; n < arrColls.length ; n++)
                { 
                    if (isIE)
                        arrRetValues[n] = tbl.rows[rowIndex].cells[parseInt(arrColls[n])].innerText;
                    else
                        arrRetValues[n] = tbl.rows[rowIndex].cells[parseInt(arrColls[n])].textContent;
                }
               
                return arrRetValues;
         }
         
         for(i=0; i < tbl.rows.length; i++)
         {
            
            if (tbl.rows[i].style.backgroundColor.toLowerCase() == "lightgreen" || tbl.rows[i].style.background =="#90ee90")
            {   
                for (n=0; n < arrColls.length ; n++)
                {
                    if (isIE)
                        arrRetValues[n] = tbl.rows[i].cells[parseInt(arrColls[n])].innerText;
                    else
                        arrRetValues[n] = tbl.rows[i].cells[parseInt(arrColls[n])].textContent;
                }
               
                return arrRetValues;
               
            }
         }
         return null;
   }

}

var win; 
var MapWindow;
//var sMapFileName = "BusStops.aspx" ;  
//var sPathToMapServer = "http://mslworld.egged.co.il/map/"; 
var sMapFileName = "MapTachanot.aspx";   
var sPathToMapServer = "http://" + window.location.host + "/MapXtr/";


function GridRowWasClicked(hidField, row)
{
    showBusy();//);
    document.getElementById(hidField).value = row;   
    document.getElementById("btnRowClicked").click();
}

        
function hideHiddenTextFields()
{
    //document.getElementById("hidGvLuzSrcClicked").style.display="none";
    //document.getElementById("hidGvSolution1Clicked").style.display="none";
    //document.getElementById("hidGvSolution2Clicked").style.display="none";
    document.getElementById("btnRowClicked").style.display="none";
}

function hideRadioDirection()
{
    var check;
    check = document.getElementById("chkLeft")

    var divRadios;
    divRadios = document.getElementById("divRadioBtns");
     
    if(check!=null)
    {    
        if(check.checked == true)
            divRadios.style.visibility = "visible"; 
        else
            divRadios.style.visibility = "hidden"; 
     } 
 }
        
function OpenTahanot(str, gridName, rowIndex) 
{ 
    if(win==null)
    {
        var winName="Station";
	    myString = new String(str)
	    // CHANGING THE + BY $ BECAUSE THE + IS NOT PASSED CORRECTLY
	    // IN THE SERVER SIDE WE ALTER IT AGAIN FROM $ TO +
	  
	    str = str.replace("+", "$");
	    str = escape(str);		   
	    str += "&width=" + screen.width
	    
	   var WinSettings = "width=720, height=540, top=50, left=50, scrollbars=yes";

	    if (getParam("language") == 'en')
	        WinSettings = "width=940, height=560, top=30, left=30, scrollbars=yes";
	       
//	    var lnkMap = document.getElementById("lnkMap")
	    
//	    if (navigator.appName == "Microsoft Internet Explorer"  && lnkMap != null)
//	    {
//	        var arr = GetValuesFromRow( gridName ,'10|15|26|27|1|17', rowIndex);
//	                
//            var sParams = unescape(getParam("DateTokef")) + "~" + arr[0] + "~" + escape(arr[1]) + "~" + arr[2] + "~" + arr[3] + "~" + arr[4] + "~" + arr[5];
//              
//            var FileName = "BusStops";
//            if (getParam("language") == 'en')
//                FileName = "BusStops_en";
//    
//            MapWindow = window.open("http://mslworld.egged.co.il/map/" + FileName + ".htm?Params=" + sParams ,'my_window','left=20, top=20, width=940, height=650, resizable=yes, scrollbars=1');
//            MapWindow.focus();
//	          
//	    }
//	    else
//	    {
	        win = window.open('wfrmTahanot.aspx?TAHANOT=' + str + "&taavura=" + getParam("taavura") + "&language=" + getParam("language") + "&company=" + getParam("company"), winName, WinSettings);
//	    }
	    
    }
    else
    {
	    win.close();
	    win=null;
	    OpenTahanot(str, gridName, rowIndex);
    }
}

        
function CloseChild()
{
    if(win)
        win.close();
    if (MapWindow)
        MapWindow.close();
       
}   
             
function ShowYomanMasa()
{ 
    
    var oDivYomanMasa = document.getElementById("divYomanMasa")
    
    if( oDivYomanMasa.innerHTML != "")
    {   
        oDivYomanMasa.style.display="inline";
        
//        if (navigator.appName != "Microsoft Internet Explorer")
//        {
//            document.getElementById("imgNew2").style.display="none"
//            document.getElementById("lnkMap2").style.display="none"
//        }
        
        var Language = getParam("language")
       
        if((!document.getElementById("gvSolution2")) && (!document.getElementById("gvSolution1")))
        {//Direct
            if (Language=="he")
            {
                oDivYomanMasa.style.height = "290px";
                oDivYomanMasa.style.width = "400px";
             }
            else{
                oDivYomanMasa.style.height = "350px";
                oDivYomanMasa.style.width = "430px";
            }    
        }
        else
            if((document.getElementById("gvSolution1")) && (!document.getElementById("gvSolution2")))
            {//Two routes
                if (Language=="he")
                   oDivYomanMasa.style.width = "580px";
                else
                   oDivYomanMasa.style.width = "580px"; 
                
                oDivYomanMasa.style.height = "420px";
            }
            else
            {//three routes
                 var width 
                    width = screen.width;//getParam("width");            
       
                if (width >= 1024)
                    width = 1024;
                else
                    width = 800;
                
                var cblCaption = document.getElementById("lblGvSolution2TitleFrom")
                
                
                if (width == 1024 )
                {
                    oDivYomanMasa.style.width = "640px";
                    oDivYomanMasa.style.height = "545px";
                    if (cblCaption.innerText.length > 50 )
                    {
                        oDivYomanMasa.style.height = "525px";
                        oDivYomanMasa.style.top="135px"
                    }
                }
                else
                {
                    oDivYomanMasa.style.width = "540px";
                    oDivYomanMasa.style.height = "520px";
                
                }
            }
    }    
}
         
function closewindows()
{
   alert("נתוני המערכת התעדכנו ,אנא שלח את בקשתך שוב");
   window.close();
   opener.location.href = "../index.aspx?taavura=" + getParam("taavura") + "&company=" + getParam("company");
}
		    
function printLuz()
{
    document.getElementById("divAssumedHour").style.display="none";
    
    if(document.getElementById("divYomanMasa").style.display=="")
    {
        document.getElementById("divYomanMasa").style.display="none";
        printMe();
        document.getElementById("divYomanMasa").style.display="inline";
    }    
    else
        printMe();
}

function printMe()
{
    if(!(document.getElementById("gvSolution1")) && !document.getElementById("gvSolution2"))
    {
        getPrintParams();
    }
    else
        self.print();
}

function getPrintParams()
{
    /*
    var ddlFrom = document.getElementById("fromHour");
    var ddlTo = document.getElementById("toHour");
    var len = document.getElementById("ddlGvLuzSrcHoursFilter").options.length;
    for(i=1 ; i<len ; i++)
    {    
        
        optFrom = document.createElement('option');
        optTo = document.createElement('option');
        
        optFrom.text = document.getElementById("ddlGvLuzSrcHoursFilter").options[i].text+":00";
        optTo.text = document.getElementById("ddlGvLuzSrcHoursFilter").options[i].text+":00";
        
        optFrom.value = document.getElementById("ddlGvLuzSrcHoursFilter").options[i].value+":00";
        optTo.value = document.getElementById("ddlGvLuzSrcHoursFilter").options[i].value+":00";
        
        ddlFrom.options.add(optFrom);
        ddlTo.options.add(optTo);  
        
        ddlTo.value = optTo.value;       
    }*/
    document.getElementById("divPrintParam").style.display="inline";
}

function showDivAssumedHour(str, gridId)
{
    var xCoord;
    switch(gridId)
    {
        case "gvLuzSrc":
            if(screen.width=="800")
                if(document.getElementById("gvSolution2")) /* 2 החלפות */
                    xCoord = "500";              
                else       	                    
                    if(document.getElementById("gvSolution1")) /* החלפה 1 */
                        xCoord = "300";              
                    else       	                    
                        xCoord = "100";  /* פתרונות ישירים */            
            else /* 1024 or more */
                if(document.getElementById("gvSolution2")) /* 2 החלפות */
                    xCoord = "550";              
                else       	                    
                    if(document.getElementById("gvSolution1")) /* החלפה 1 */
                        xCoord = "300";              
                    else       	                    
                        xCoord = "100";  /* פתרונות ישירים */   
            break;
        case "gvSolution1":
            if(screen.width=="800")
                if(document.getElementById("gvSolution2")) /* 2 החלפות */
                    xCoord = "250";              
                else       	         
                    xCoord = "50";              
            else /* 1024 or more */
                if(document.getElementById("gvSolution2")) /* 2 החלפות */
                    xCoord = "280";              
                else       	         
                    xCoord = "30";   
            break;
        case "gvSolution2":
            if(screen.width=="800")
                xCoord = "30";              
            else
                xCoord = "30";
            break;
    }
    
    document.getElementById("divAssumedHour").style.width = "280";
    document.getElementById("divAssumedHour").style.height = "25";
    document.getElementById("divAssumedHour").style.left = xCoord;
    //document.getElementById("divAssumedHour").style.display="";
    //document.getElementById("divAssumedHour").innerHTML="<table width='100%'><tr><td>"+str+"</td><td align='left'><img src='../Images/Forms/close.jpg' onclick='hideDivAssumedHour()'></td></tr></table>";
    var str = "<table width='100%'><tr><td>"+str+"</td><td align='left'><img src='../Images/Forms/close.jpg' onclick='hideDivAssumedHour()'></td></tr></table>";
    if(screen.width=="800")
        showDivMoreDetails(str, "divAssumedHour",event.clientY+65);
    else
        showDivMoreDetails(str, "divAssumedHour",event.clientY+65);
}


function hideDivAssumedHour()
{
    document.getElementById("divAssumedHour").style.display="none";
}


function printYomanMasa()
{
    var innerHTML = ""; /* THE ORIGIN YOMAN MASA HTML */
    var ind; /* GET THE PLACE OF THE FIRST '</TR>' IN innerHTML -> WE WANT TO CUT THE FIRST ROW 
                SINCE IT CONTAINS BUTTONS THAT WE DON'T WANT TO PRINT */ 
    var title = "";
    var strHTML = ""; /* TO CONTAIN FINAL HTML FOR PRINTING */
    
    innerHTML = document.getElementById("divYomanMasa").innerHTML;
    ind = innerHTML.toUpperCase().indexOf("</TR>");
    ind = ind+5;
    title = "<table>";
    title += "  <tr>";
    title += "      <td>";
    title += "          <u><label>פירוט הנסיעות שנבחרו</label></u>";
    title += "      </td>";		    
    title += "  </tr>";
    strHTML = title;
    strHTML += innerHTML.substr(ind, innerHTML.length-ind);
    
    printInnerFrame(strHTML);
}

function printAllDay(html)
{
    printInnerFrame(html);	    
}

function printInnerFrame(html)
{
    try
    {
        /*var iHTML = "";
        iHTML += "<div id='divPrint' dir='rtl'>";    
        iHTML += html;
        iHTML += "</div>";
        */
        //var obj = document.getElementById("innerFrame").innerHTML;
        //self.frames[0].document.src="print.htm?shtml="+html;
        //self.frames[0].window.location="print.htm?shtml='"+html+"'";
        //document.getElementById("innerFrame").innerHTML);
    }
    catch(err)
    {
        //alert(err);
    }
    
    try
    {
        self.frames[0].document.getElementById("divPrint").innerHTML = html;
        //alert(self.frames[0].document.getElementById("body").innerHTML);
        //self.frames[0].document.src = ";
        //self.document.src = "print.htm?shtml="+html;
        self.frames[0].focus();
        self.frames[0].print();
    }
    catch(err)
    {
        alert(err);
        //alert("שגיאה בהדפסה");
    }		        
}

function showBusy()
{document.getElementById("divBusy").style.display="inline";}

//function clearAllBusy()
//    {
//        if(document.getElementById("divBusy"))
//        {
//            document.getElementById("divBusy").style.display="none";
//            
//        }            
//    }

function FinalPrintLuz()
{
    //evt.srcElement.style.display='none';
    //document.getElementById("btnPrintLuz").style.display='none';
   // document.getElementById("btnBack").style.display='none';
   // document.getElementById("btnClose").style.display='none';
    
    self.focus();
    self.print();
    backToLuz();
    
    //evt.srcElement.style.display='inline';
   // document.getElementById("btnPrintLuz").style.display='none';
   // document.getElementById("btnBack").style.display='inline';
   // document.getElementById("btnClose").style.display='inline';
    //self.close();
}

function backToLuz()
{   
    try
    {
        self.location.href = self.location.href;
    }
    catch(err)
    {
        //alert(err);
    }
    //self.close();
    //alert(top.innerHTML);
    //self.innerHTML=top.innerHTML
 
}

function OpenGoogleMap(iNumOfTransfers) 
{ 
    var sDate = getParam("DateTokef")
    var sParams = ""  
   
    for (var i = 0; i <= iNumOfTransfers; i++ )
    {    
        var sTblName;
        
        switch(i)
        {
            case 0:
                sTblName = "gvLuzSrc"
                break;
            case 1:
                sTblName = "gvSolution1"
                break;
            case 2:
                sTblName = "gvSolution2"
                break;
        
        }
        
        var arr = GetValuesFromRow(sTblName,'10|16|27|28|1|18')  
        //10-Makat | 16-Halufa | 27-MozaId | 28-YaadI |1- shilut| 18 - OriginTime   /// 2-Time tahana Motza
      
        if (arr == null)
        { 
            if (getParam("language") == "he")
                document.getElementById("lblError").innerHTML = "בחר נסיעה בלוח הזמנים וחזור על בקשתך";
            else
                document.getElementById("lblError").innerHTML = "Select the appropriate travel and repeat on your request";
                
            return;
        }
        
        sParams += unescape(sDate) + "~" + arr[0] + "~" + escape(arr[1]) + "~" + arr[2] + "~" + arr[3] + "~" + arr[4] + "~" + arr[5] + "|";
    }
    
    //Cut off last "|"
    sParams = sParams.substring(0, sParams.length-1)
    
    if (getParam("language") == 'en')
        sParams += "&lang=en"
    else
        sParams += "&lang=he";
        
    //MapWindow = window.open("http://tlv15/map/" + FileName + ".htm?Params=" + sParams ,'my_window','left=20, top=20, width=940, height=650, resizable=yes, scrollbars=1');   
    MapWindow = window.open(sPathToMapServer + sMapFileName + "?params=" + sParams ,'my_window','left=20, top=20, width=940, height=650, resizable=yes, scrollbars=1,toolbar=yes');
    MapWindow.focus();
    
}   

function OpenMapFromGrid(str, gridName, rowIndex) 
{ 
    if(MapWindow == null)
    {
        var winName="Station";
	    myString = new String(str)
	    // CHANGING THE + BY $ BECAUSE THE + IS NOT PASSED CORRECTLY
	    // IN THE SERVER SIDE WE ALTER IT AGAIN FROM $ TO +
	  
	    str = str.replace("+", "$");
	    str = escape(str);		   
	    str += "&width=" + screen.width
	    
	   var WinSettings = "width=720, height=540, top=50, left=50, scrollbars=0, toolbar=yes";

	    if (getParam("language") == 'en')
	        WinSettings = "width=940, height=540, top=30, left=30, scrollbars=0,toolbar=yes";
	       
	    var lnkMap = document.getElementById("lnkMap")
	    
//	    if (navigator.appName == "Microsoft Internet Explorer"  )
//	    {          
                                            
	        var arr = GetValuesFromRow( gridName ,'10|16|27|28|1|18', rowIndex);      
	         //10-Makat | 16-Halufa | 27-MozaId | 28-YaadI |1- shilut| 18 - OriginTime   /// 2-Time tahana Motza
            var sParams = unescape(getParam("DateTokef")) + "~" + arr[0] + "~" + escape(arr[1]) + "~" + arr[2] + "~" + arr[3] + "~" + arr[4] + "~" + arr[5];
              
            
            if (getParam("language") == 'en')
            {
                sParams += "&lang=en"
            }
            else
                sParams += "&lang=he";
            
            
            MapWindow = window.open(sPathToMapServer + sMapFileName + "?params=" + sParams ,'my_window','left=20, top=20, width=940, height=650, resizable=yes, scrollbars=1, toolbar=yes');
            MapWindow.focus();
	          
	    //}	    
    }
    else
    {
	    MapWindow.close();
	    MapWindow = null;
	    OpenMapFromGrid(str, gridName, rowIndex);
    }
}

function hideYomanMasa()
{
    document.getElementById('divYomanMasa').style.display='none';
}