﻿// JScript File
/////globals for all application 

var WndPlansForm = null;
var WndSignsForm = null;
var WndAgendaForm = null;
var WndTromVaadaForm = null;
var WndProtocolForm = null;
var OrderCardHandler = null;
var DynamicQueryWinHandler = null;
var DynamicQueryWinHandlerChild = null;
var ReportWinHandler = null;
var WndSignLabelsForm = null;
var bZoomedOnStart = true;
var iTimeOut=0;
var isFirstTime = true;
var WetInfraSectionWndHandler = null;
var MyLayerWinHandler = null;
var ArrZoomXY = null;

function PageLoad()
{
    
    if(sModulScript != "") 
    {
        eval(sModulScript);
        if(IsStartSearch == "0")  StartSubSystem();
    }

    if(sXYZoom != "") ArrZoomXY = sXYZoom.split(";");    

    window.setInterval("KeepSession()",600000,"javascript");

    ViewMenu();
}

function Add2favorites()
{
    window.external.AddFavorite(MainHttp, Session_Project_header);
} 

function GoServiceHelper(errId)
{
    top.frames("assistFrame").location.href = "http://" + MainHost + "/ServiceHelper/Default.aspx?ErrId=" + errId;
    //document.getElementById("MapLoadingDiv").style.display = "none";
    
    document.getElementById("MapErrorDiv").style.display = "";
    document.getElementById("MapError").innerHTML = "עקב עומס יתר על שירות המפות <br>" + "יתכן עיכוב בהצגת המפה <br>" + "אנא סבלנותכם , עמכם הסליחה";
}

function RunServiceHelper(ServNum)
{
    if(IsManager == "True")
    {
        top.frames("assistFrame").location.href = "http://" + MainHost + "/ServiceHelper/Default.aspx?Services=" + ServNum;
        document.getElementById("MapErrorDiv").style.display = "";
        document.getElementById("MapError").innerHTML = "לפי בקשתך מרפרש שירות המפות <br>" + "אנא המתן לרענון המפה"
    }
}

function HideLoderImg()
{
    document.getElementById("MapLoadingDiv").style.display = "none";
}

function KeepSession()
{
    top.frames("assistFrame").location.href = "Tools/KeepSesion.aspx"
}

function ViewMenu()
{
    document.getElementById("tdMenuContent").style.visibility="visible";
    
    if(document.getElementById("txtComeFrom").value == "asset")
        document.getElementById("trApplicHeader").style.visibility="hidden";
}
////////////////

function InitMapFrame()
{
    oFrame = GetMapFrame();
    if(oFrame && oFrame.document.getElementById("MapFrameArea") && oFrame.isMapLoaded)
    {
        oFrame.document.getElementById("MapFrameArea").cols="*,0px";
        if(bZoomedOnStart) window.setTimeout("ZoomOnStart();",1000);
        
    }
    else
    {
        window.setTimeout("InitMapFrame();",1000);
    }
}

function ZoomOnStart()
{
    if(ArrZoomXY)
        top.Map.Zoom2XYScale(parseFloat(ArrZoomXY[0]),parseFloat(ArrZoomXY[1]),ZoomScale,ZoomReshet);
    else if(ZoomLayerName)
    {
        if(ZoomLayerName != "-1")
            top.Map.Zoom2Feature(ZoomLayerName , ZoomWhr);
        else
            alert("פרמטרים שגויים לחיפוש , לא ניתן להתמקד");
    }
    bZoomedOnStart = false;        
}

function StartSearch() 
{
  top.Map.donotResize = true;
  document.getElementById("TabSearch").className = "tabActive"; 
  document.getElementById("TabSubSystem").className = "tabNotActive";
  document.getElementById("TabGeneral").className = "tabNotActive"; 

  document.getElementById("Search").style.display = ""; 
  document.getElementById("SubSystem").style.display = "none";
  document.getElementById("General").style.display = "none";
  
  document.getElementById("MainTabFrames").style.display = "";
  document.getElementById("LogoFrame").style.display = "";
  document.getElementById("tdMap").rowSpan = "2";
  
  InitMapFrame();
  setTimeout(EnableResizing,1000);    
}

function StartSubSystem()
{
  top.Map.donotResize = true;
  document.getElementById("TabSearch").className = "tabNotActive";
  document.getElementById("TabSubSystem").className = "tabActive";
  document.getElementById("TabGeneral").className = "tabNotActive";
  
  document.getElementById("MainTabIcons").width = document.getElementById("MainTabFrames").width + "px";
  
  document.getElementById("Search").style.display = "none"; 
  document.getElementById("SubSystem").style.display = "";
  document.getElementById("General").style.display = "none";
  
  document.getElementById("MainTabFrames").style.display = "";
  document.getElementById("LogoFrame").style.display = "";
  document.getElementById("tdMap").rowSpan = "2"; 
  
  InitMapFrame();
  setTimeout(EnableResizing,1000);  

}

function StartGeneral()
{
  document.getElementById("TabSearch").className = "tabNotActive"; 
  if(document.getElementById("TabSubSystem")) document.getElementById("TabSubSystem").className = "tabNotActive";
  document.getElementById("TabGeneral").className = "tabActive";

  document.getElementById("Search").style.display = "none"; 
  if(document.getElementById("SubSystem")) document.getElementById("SubSystem").style.display = "none";
  document.getElementById("General").style.display = "";
  
  showMapTaskArea();
}

function showMapTaskArea()
{
  if(document.getElementById("MainTabFrames").style.display == "none") return;
  
  var oFrame = GetMapFrame();
  if(oFrame)
  {
    oFrame.donotResize = true;
    
    document.getElementById("MainTabFrames").style.display = "none";
    document.getElementById("LogoFrame").style.display = "none";
    document.getElementById("tdMap").rowSpan = "1";
    var swidth = document.getElementById("MainTabFrames").width + "px";    
    oFrame.document.getElementById("MapFrameArea").cols="*,"+ swidth;
    
    setTimeout(EnableResizing,1000);
  } 
}

function OpenUserManager()
{
    var winOpt = "resizable=yes,toolbar=no,menubar=no,status=no,left=50,top=50,height=800,width=950";
    window.open(VIRTUAL_DIRECTORY + "Tools/Users.aspx", "UserManager", winOpt);
}

function OpenSubSystem(sname)
{
  document.getElementById("TabSubSystem").innerText = sname;
  document.getElementById("TabSubSystem").style.display = "";
  if(sname=="ייעודי קרקע")
		document.getElementById("SubSystem").src = VIRTUAL_DIRECTORY + "landuse/search.aspx";
  else if(sname=="ועדות תנועה")
		document.getElementById("SubSystem").src = VIRTUAL_DIRECTORY + "signs/search.aspx";
//  else if(sname=="נכסים")
//        document.getElementById("SubSystem").src = VIRTUAL_DIRECTORY + "assets/frmTabs.aspx";
  else if(sname=="מאור")
        document.getElementById("SubSystem").src = VIRTUAL_DIRECTORY + "Lighting/frmTabs.aspx";
  else if(sname == "ועדות תנועה ")      
        document.getElementById("SubSystem").src = VIRTUAL_DIRECTORY + "SignsLight/search.aspx";
  else if(sname == "תשתיות רטובות")      
        document.getElementById("SubSystem").src = VIRTUAL_DIRECTORY + "WetInfra/frmTabs.aspx";

  if(isFirstTime==false) 
    StartSubSystem();
  else
  {
    StartSearch();
    document.getElementById("MainTabIcons").width = document.getElementById("MainTabFrames").width + "px";
  }
  isFirstTime = false;
}


function OpenAssets()
{
    var winOpt = "resizable=yes,toolbar=no,menubar=no,status=yes";
	window.open(document.getElementById("txtAssetsUrl").value,"Assets",winOpt);		
}

function OpenReportDefinition()
{
    StartGeneral();
    top.Map.ExecuteLinkCommand();
    top.Map.taskFrame.document.location.href = MGE_BASIC_TOOLS_VIRTUAL_DIRECTORY + "General/Loader.htm";
    document.all.item("frmReport").action = MGE_BASIC_TOOLS_VIRTUAL_DIRECTORY + "DynamicQueries/ReportFilterDefinition.aspx";
    document.all.item("frmReport").target = "taskFrame";
    document.all.item("frmReport").method = "post";
    document.all.item("frmReport").submit();
}

function GetLogin()
{
    self.location.href = "UserLogin.aspx";
}

function GetHomePage()
{
    self.location.href = "Default.aspx";
}

function OpenLinks(sname)
{
    StartGeneral();
    top.Map.ExecuteLinkCommand();
    top.Map.taskFrame.document.location.href = VIRTUAL_DIRECTORY + "General/Links.aspx";
}

function SaveJustImage()
{
  top.Map.SaveJustImage();
}

function SaveMapImage()
{
  top.Map.SaveMapImage();
}

function SaveDwfFile()
{
  top.Map.SaveDwfFile();
}

function PrintMap()
{
    top.Map.PrintMap();
}

function OpenHideScalePanel()
{
    top.Map.OpenHideScalePanel();
}

function OpenHideLayerInfoPanel()
{
    top.Map.OpenHideLayerInfoPanel();
}


function OpenMapOverview()
{
    top.Map.OpenMapOverview();
}

function OpenLinkManage()
{
    LoadMGEBasicToolsWindow("100","100","350","700","Assist/LinksList.aspx","LinksList","frmReport");        
}

function OpenTableManage()
{
    LoadMGEBasicToolsWindow("100","100","600","950","Assist/ManageSystemTables.aspx","EditSystemTables","frmReport");        
}

function OpenMessagesManage()
{
    LoadMGEBasicToolsWindow("100","100","450","900","Assist/MessagesList.aspx","MessagesList","frmReport");        
}

function OpenDynamicQueriesWin()
{
    LoadMGEBasicToolsWindow("100","100","470","600","DynamicQueries/DynamicQueriesDefinition.aspx","DynamicQueriesDefinition","frmReport");        
}

function ViewQueryDefinitions()
{
    LoadMGEBasicToolsWindow("100","100","800","1000","DynamicQueries/QryManage.aspx","QueryDefinitionsWindow","frmReport");
}

function OpenLayerManageWindow()
{
    LoadMGEBasicToolsWindow("100","100","600","950","LayerManage/LayerManage.aspx","LayerManageWindow","frmReport");    
}

function OpenMenuManage()
{
    LoadMGEBasicToolsWindow("100","100","430","500","Assist/MenuManage.aspx","MenuManage","frmReport");        
}

function OpenStaticQueriesWin()
{
    StartGeneral();
    
    top.Map.ExecuteLinkCommand();
    
    top.Map.taskFrame.document.location.href = MGE_BASIC_TOOLS_VIRTUAL_DIRECTORY + "General/Loader.htm";
    document.all.item("frmReport").action = MGE_BASIC_TOOLS_VIRTUAL_DIRECTORY + "DynamicQueries/Queries.aspx";
    document.all.item("frmReport").target= "taskFrame";
    document.all.item("frmReport").method = "post";
    document.all.item("frmReport").submit();
}

//map project call this function 
//from getreport function 
function OpenReportFromMap(myTheme, mySubject,g_myFilter,g_myFilterDesc,g_myFilterVal,SQLWHR)
{
    document.getElementById("txtThemeId").value = myTheme;
    document.getElementById("txtSubjectId").value = mySubject;
    document.getElementById("txtFilter").value = g_myFilter;
    document.getElementById("txtFilterDesc").value = g_myFilterDesc;
    document.getElementById("txtFilterVal").value = g_myFilterVal;
    document.getElementById("txtOpenedFrom").value = "Report";
    
    document.getElementById("txtAddSql").value = "1";
    document.getElementById("txtSqlTermsToShow").value = SQLWHR;
    document.getElementById("txtSortFieldName").value="";
                                                                            
    LoadMGEBasicToolsWindow("100","100","600","900","DynamicQueries/ModalDetails/DynamicQueryReport.aspx" ,"DynamicQueryReportWindow","frmReport");
    
    top.ReportWinHandler.document.getElementById("btnGetReport").disabled = false;
    top.ReportWinHandler.document.getElementById("btnGetReport").className = "clsshortbutton";
    top.ReportWinHandler.document.getElementById("lblStatus").style.visibility = "hidden";
}

function OpenLayerManage()
{
    top.Map.GetMapLayers(document.getElementById("txtSessionId").value,1);
}

function RefreshPlanForm()
{
    if(top.WndPlansForm && !top.WndPlansForm.closed)
    {
        top.WndPlansForm.OnPlanChanged();
    }
}

function RefreshSignsForm(sKey)
{
    var sParams = "";
    var paramCnt = 0;
    var arrParams = new Array();
    var i=0;
    var doSubmit = 0;
    if(top.WndSignsForm && !top.WndSignsForm.closed)
    {
        if(parseInt(sKey)==0)
        {
            alert("התמרור נמחק בהצלחה");
            top.WndSignsForm.close();
            return;
        }
        top.WndSignsForm.document.getElementById("SignId").value = sKey;
        arrParams[paramCnt] = "SignId=" + sKey;
        paramCnt++;
        if(top.WndSignsForm.document.getElementById("hdOrderId").value !="")
        {
            arrParams[paramCnt] = "OrderId=" + top.WndSignsForm.document.getElementById("hdOrderId").value;
            paramCnt++;
        }
        if(top.WndSignsForm.document.getElementById("hdParagraphId").value !="")
        {
            doSubmit = 1;
            arrParams[paramCnt] = "ParagraphId=" + top.WndSignsForm.document.getElementById("hdParagraphId").value;
            paramCnt++;
        }
        if(top.WndSignsForm.document.getElementById("hdSignType").value !="")
        {
            arrParams[paramCnt] = "LinkSignType=" + top.WndSignsForm.document.getElementById("hdSignType").value;
            paramCnt++;
        }
        if(top.WndSignsForm.document.getElementById("hdsignTypeGroup").value !="")
        {
            arrParams[paramCnt] = "signTypeGroup=" + top.WndSignsForm.document.getElementById("hdsignTypeGroup").value;
            paramCnt++;
        }
        if(top.WndSignsForm.document.getElementById("hdsignStreetCode1").value !="")
        {
            arrParams[paramCnt] = "signStreetCode1=" + top.WndSignsForm.document.getElementById("hdsignStreetCode1").value;
            paramCnt++;
        }
        if(top.WndSignsForm.document.getElementById("hdsignHouse1").value !="")
        {
            arrParams[paramCnt] = "signHouse1=" + top.WndSignsForm.document.getElementById("hdsignHouse1").value;
            paramCnt++;
        }
        if(top.WndSignsForm.document.getElementById("hdsignStreetCode2").value !="")
        {
            arrParams[paramCnt] = "signStreetCode2=" + top.WndSignsForm.document.getElementById("hdsignStreetCode2").value;
            paramCnt++;
        }
        if(top.WndSignsForm.document.getElementById("hdsignHouse2").value !="")
        {
            arrParams[paramCnt] = "signHouse2=" + top.WndSignsForm.document.getElementById("hdsignHouse2").value;
            paramCnt++;
        }
        sParams = "?" + arrParams[0];
	    for (i=1; i < paramCnt; i++)
	    {
		    sParams = sParams + "&" + arrParams[i];
	    }
	    sParams = sParams + "&doSubmit=" + doSubmit;
        top.WndSignsForm.document.location = VIRTUAL_DIRECTORY + "Signs/SignsForm.aspx" + sParams;
    }
}

function ShowSelectedSigns(sSignIds)
{
    //alert(sSignIds);
    top.SubSystem.document.getElementById("searchResult").style.display="none";
    var param = "SearchResult.aspx?SearchType=7&txtFirst=" + sSignIds ;
    top.SubSystem.document.getElementById("searchResult").src = param;    
}

function ShowSelectedSignLabels(sSignIds)
{
    top.SubSystem.document.getElementById("ifrLabelSearchResult").style.display="none";
    top.SubSystem.document.getElementById("ifrLabelActionButtons").style.display="none";
    var param = "SearchResult.aspx?SearchType=8&txtFirst=" + sSignIds ;
    top.SubSystem.document.getElementById("ifrLabelSearchResult").src = param;    
}

function ShowSelectedLots(sVal1,sVal2,sVal3)
{
    var SearchType = top.SubSystem.document.getElementById("searchtype").value;
    top.SubSystem.document.getElementById("txtFirst").value = sVal1;
    top.SubSystem.document.getElementById("txtSecond").value = sVal2;
    if(parseInt(SearchType) == 2)
    {
        top.SubSystem.document.getElementById("Setllement").value = sVal3;
    }
    top.SubSystem.bZoomAfterShow = false;
    top.SubSystem.document.getElementById("checkDate").checked=false;
    top.SubSystem.ShowLuData();
}

function ShowAgendaForm()
{
    if(top.WndAgendaForm && !top.WndAgendaForm.closed)
    {
        top.WndAgendaForm.focus();
    }
}

function ShowTromVaadaForm()
{
    if(top.WndTromVaadaForm && !top.WndTromVaadaForm.closed)
    {
        top.WndTromVaadaForm.focus();
    }
}

function ShowProtocolForm()
{
    if(top.WndProtocolForm && !top.WndProtocolForm.closed)
    {
        top.WndProtocolForm.focus();
    }
}

function ShowOrderCard()
{
    if(top.WndTromVaadaForm)
    {
        ShowTromVaadaForm();
    }
    
    if(top.WndAgendaForm)
    {
        ShowAgendaForm();
    }
    
    if(top.WndProtocolForm)
    {
        ShowProtocolForm();
    }
    
    if(top.WndTromVaadaForm || top.WndAgendaForm || top.WndProtocolForm)
    {
   	    var tbl = top.OrderCardHandler.document.getElementById('TamParagraphSignsContent');
        var oRow = tbl.rows[0];
        top.OrderCardHandler.selectParagraph(oRow);
        top.OrderCardHandler.GetSigns4Paragraph(oRow);
        top.OrderCardHandler.parentHandler.ShowTrafficCommData();
    }
}

function OpenDynamicQueriesAddLayersWindow()
{
    top.DynamicQueryWinHandler.OpenAddLayersWindow();
}

function OpenWinToSetSdfFieldsData()
{
    top.DynamicQueryWinHandlerChild.OpenWinToSetSdfLayerFields();
}

function ViewOdot()
{
    var winOpt = "resizable=yes,toolbar=no,menubar=no,status=no,left=50,top=50,height=350,width=550";
    window.open(VIRTUAL_DIRECTORY + "Tools/Odot.aspx", "Odot", winOpt);
}

function StaticMenuMouseOver(obj)
{
   obj.style.color="#B50027";
}

function StaticMenuMouseOut(obj)
{
   obj.style.color="Black";
}
///////////////////

function EnableResizing()
{
    top.Map.donotResize = false;
}
function DisableResizing()
{
   top.Map.donotResize = true;
   
}
function ReportFromMapHandler()
{
    top.ReportWinHandler.document.getElementById("btnGetReport").disabled = false;
    top.ReportWinHandler.document.getElementById("btnGetReport").className = "clsShortButton";
    top.ReportWinHandler.document.getElementById("lblStatus").style.visibility = "hidden";
}
function DynamicQueriesWinHandler()
{
    top.ReportWinHandler.document.getElementById("btnMap").disabled = false;
    top.ReportWinHandler.document.getElementById("btnMap").className = "clsShortButton";
    top.ReportWinHandler.document.getElementById("lblStatus").style.visibility = "hidden";
}

function OpenMT()
{
    alert("יש להצביע על המפה");
	
    if(top.Map)
	    top.Map.GetDigitizedPoint("MultiVision",top);
    else
	    top.MainFrameSet.document.frames.frame_map.Map.GetDigitizedPoint("MultiVision",top.MainFrameSet.document.frames.frame_map);

}



function OpenSV()
{
    alert("יש להצביע על המפה");
    top.Map.GetDigitizedPoint("SiteVision");
}

function OpenSiteVision(x , y)
{
     var winOpt = "resizable=yes,toolbar=no,menubar=no,status=no,left=50,top=50,height=700,width=800";
    window.open(VIRTUAL_DIRECTORY + "SiteVision/SVision.aspx?X=" + x + "&Y=" + y, "SiteVision", winOpt);
}
function OpenHelp()
{
    var winOpt = "resizable=yes,toolbar=no,menubar=no,status=no,left=50,top=50,height=550,width=550";
    //window.open(VIRTUAL_DIRECTORY + "General/UnderConstruct.htm", "UnderConstruction", winOpt);
    window.open(VIRTUAL_DIRECTORY + "Help/HELP_" + document.getElementById("ProjectId").value + ".pdf", "Help", winOpt);
}

function OpenMaorEntityForm(TabCode,ObjectId,entityId)
{
    top.document.getElementById("SubSystem").contentWindow.document.getElementById("ifrEntityCard").src = VIRTUAL_DIRECTORY + "Entity/EntityFrames.aspx?TabCode=" + TabCode + "&EntityId=" + entityId + "&ObjectId=" + ObjectId;
    top.document.getElementById("SubSystem").contentWindow.ShowObjectCard();
}
function CloseMaorEntityForm()
{
    top.document.getElementById("SubSystem").contentWindow.ShowSearchTab();
}

function ShowSelectEntities(KEYS,cameFrom)
{
    if(cameFrom==1) //חיפוש כללי
    {
        top.Search.SearchFrame.document.frmMapSearch.all("search_id").value = top.Search.SearchFrame.document.frmSearches.all("lstSearches").value;
        top.Search.SearchFrame.document.frmMapSearch.all("origin_key_value").value = KEYS;
	    top.Search.SearchFrame.document.frmMapSearch.submit();
    }
    else if(cameFrom==2 || cameFrom==3 || cameFrom==4)  //מאור רחובות    ,נכסים    ,תשתיות רטובות
    {
        top.document.getElementById("SubSystem").contentWindow.document.getElementById("ifrSearch").contentWindow.ViewSearchResultFromMap(KEYS);
    }
//    else if(cameFrom==5)  //תשתיות רטובות
//    {
//        top.document.getElementById("SubSystem").contentWindow.document.getElementById("ifrSearch").contentWindow.ViewSearchResultFromMap(KEYS);
//        top.Map.WetInfra_ShowLenCrossection(KEYS);
//    }
}

function OpenRequestManage()
{
    var winOpt = "resizable=yes,toolbar=no,menubar=no,status=no,left=50,top=50,height=450,width=700";
    window.open(VIRTUAL_DIRECTORY + "Tools/RequestSearch.aspx", "RequestSearch", winOpt);
}

function OpenScannedPlans(sPath)
{
    var winOpt = "resizable=yes,toolbar=no,menubar=no,status=no,left=50,top=50,height=450,width=700";
    window.open(sPath, "ScannedPlans", winOpt);
}

function OpenRishuiBniya(sPath)
{
    var winOpt = "resizable=yes,toolbar=no,menubar=no,status=no,left=50,top=50,height=450,width=700";
    window.open(sPath, "RishuiBniya", winOpt);
}
function OpenMeydaHandasi(sPath)
{
    window.open(sPath,"MeydaHandasi");
}

function CallMapZoom2Feature(layer_name, sql_where)
{
    top.Map.Zoom2Feature(layer_name, sql_where);
}
function OpenLanduseFilter()
{
    StartGeneral();
    top.Map.ExecuteLinkCommand();    
    top.Map.taskFrame.document.location.href = VIRTUAL_DIRECTORY + "LandUse/LandUseFilter.aspx";
}

function OpenMyLayer()
{
    StartGeneral();
    top.Map.ExecuteLinkCommand();
    top.Map.taskFrame.document.location.href =  VIRTUAL_DIRECTORY + "MyLayer/frmTabs.aspx";
}
function MyLayer_UpdateItemData(itemId)
{
    MyLayerWinHandler.document.getElementById("txtItemId").value = itemId;
    MyLayerWinHandler.document.getElementById("cboDrawType").disabled = true;
    MyLayerWinHandler.document.getElementById("btnDelete").disabled = false;
}

function MyLayer_CleanDeletedItemData()
{
    MyLayerWinHandler.Clean();
}
