﻿var VIRTUAL_DIRECTORY;
var MGE_BASIC_TOOLS_VIRTUAL_DIRECTORY = "/MGEBasicTools/"

// JScript File
if(window.location.pathname.split("/")[0].toString() != "")
    VIRTUAL_DIRECTORY = "/" + window.location.pathname.split("/")[0] + "/";//if use window.showModalDialog('window.location.pathname' returns path without first slash)
else
    VIRTUAL_DIRECTORY = "/" + window.location.pathname.split("/")[1] + "/";//if use window.open('window.location.pathname' returns path with first slash)

var bIsCheckBoxsSelected = true;

var LAYER_NAME_MYLAYER_POINT_ITEM = "MY_POINT";
var KEY_NAME_MYLAYER_POINT_ITEM = "FID";

var LAYER_NAME_MYLAYER_LINE_ITEM = "MY_LINE";
var KEY_NAME_MYLAYER_LINE_ITEM = "FID";

var LAYER_NAME_MYLAYER_POLYGON_ITEM = "MY_POLYGON";
var KEY_NAME_MYLAYER_POLYGON_ITEM = "FID";

var LAYER_NAME_MYLAYER_TEXT_ITEM = "MY_TEXT";
var KEY_NAME_MYLAYER_TEXT_ITEM = "FID";

function GetMapFrame()
{
  var oFrame = top.frames("Map");

  if(oFrame) 
    return oFrame;
  else
    return null;
}

function GetMainWindow()
{
  try
  {
    var wnd = window.top;
    if(wnd.opener)
    {
      var bRun = true;
      wnd = wnd.opener.top;
      while(bRun)
      {
        if(wnd.opener)
          wnd = wnd.opener.top;
        else
          bRun = false;
      }
    } 
    
    return wnd;
  } catch (ex) {
      return top;
  }
}


function OpenCal(sControl,SelectedDate,level)
{
	var retval=null;
	retval = window.showModalDialog(VIRTUAL_DIRECTORY + "Calendar/calendar_main.aspx?SelectedDate="+SelectedDate,window,
										"center:yes;dialogWidth:215px;dialogHeight:210px;status:no")
	if (retval != null) {
	    //var controlId = Control.id;
		document.getElementById(sControl).value = retval 									
	}	
	return retval;
}

function OpenCalendar(obj,level)
{
   var paramsArr = obj.getAttribute("params").split(",");
   //OpenCal(eval(paramsArr[0]),document.getElementById(eval(paramsArr[0])).value,level);
   OpenCal(eval(paramsArr[0]),document.getElementById(eval(paramsArr[0])).value,level);
}

function IsURLValid(val)
{
  //var exp = /^^((ht|f)tp(s?)\:\/\/|~/|/)?([\w]+:\w+@)?(([a-zA-Z]{1}([\w\-]+\.?)*(\.[\w]{2,5})?)(:[\d]{1,5})?)?((/?\w+/)+|/?)(\w+\.[\w]{3,4})?([,]\w+)*((\?\w+=\w+)?(&\w+=\w+)*([,]\w*)*)? $/;
  var regex = new RegExp(exp);
  var result;

  if (val.length > 0)
  {
        result = regex.test(val);
        if (result == false)
        {
              alert("Please enter a valid url format.\ni.e. http://www.address.com or www.address.com");
              return false;
        }
  }
  return true;
}

function OpenOrderCard(id,tabid,traff_comm_id,come_from)
{
	var prop = "dialogWidth:710px;dialogHeight:500px;status:no;";
	window.showModalDialog(VIRTUAL_DIRECTORY + "Signs/OrderCard.aspx?Id="+id+
	                                                    "&TabIndex=" + tabid +
	                                                    "&TraffCommId=" + traff_comm_id +
	                                                    "&CameFrom=" + come_from,window,prop);
	                                                    
	
	/*window.open(VIRTUAL_DIRECTORY + "Signs/OrderCard.aspx?Id="+id+
	                                "&TabIndex="+tabid+
	                                "&TraffCommId=" + traff_comm_id + 
	                                "&CameFrom=" + come_from,"");*/
	
}

function SetWindowPosition(x,y,width,height)
{
	window.moveTo(x,y);
	window.resizeTo(width,height);
	window.focus();
}


function ManageTrafficCommittee(traffCommId)
{
    //alert(traffCommId);
	//var prop = "dialogWidth:400px;dialogHeight:440px;status:no;";
    //window.showModalDialog(GetMainWindow().MainHttp + "Signs/ModalDetails/ManageTrafficCommittee.aspx",null,prop);
	window.open(VIRTUAL_DIRECTORY + "Signs/ModalDetails/ManageTrafficCommittee.aspx?TraffCommIdToSelect="+traffCommId,"ManageTrafficCommittee","height=500,width=640,status=no,toolbar=no,menubar=no,resizable=yes");
}


function CloseModalWindow()
{
    window.close();
}

function IsNumber(num){
	
	var val = new String(num);
	var NewNum = new String();
	var i = 0;
	while (i < val.length){
		if (val.charAt(i) != ","){
			NewNum = NewNum + val.charAt(i);	
		}	
		i = i + 1;
	}
		
	// return true if is number else return false
	val = new String(NewNum)
	
	if ((isNaN(val)) || (val.substr(0,1)== " "))  {
		return false;
	}	
	return true;
}

function MarkAll()
{
    var allInp = document.body.getElementsByTagName("input");
    if(allInp)
    {
        if(allInp.length > 0)
        {
            for(var i=0;i < allInp.length; i++)
            {
                var inpType = allInp.item(i).getAttribute("type");
                if(inpType.toString() == "checkbox")
                    allInp.item(i).checked = bIsCheckBoxsSelected;
            }
        }
    }
    bIsCheckBoxsSelected = !bIsCheckBoxsSelected;
}

function OpenReportModal (reportUrl,bShowExcelButton, bIsPrintDisabled)
{
	var retVal ;
	var sModalLocation;
	sModalLocation = VIRTUAL_DIRECTORY + "General/Print/PrintContainer.aspx?DocumentUrl=" + encodeURIComponent(reportUrl) ;
	
	if (bShowExcelButton)
		sModalLocation = sModalLocation + "&EnableExcelExport=1";
	if (bIsPrintDisabled)
		sModalLocation = sModalLocation + "&IsPrintDisabled=1";
		
	//retVal = window.showModalDialog (sModalLocation ,window, "dialogWidth:1000px;dialogHeight:600px;center=yes;status=0;help=0");
	//alert (sModalLocation);
	window.open(sModalLocation,"","toolbar=no,menubar=no,resizable=yes,scrollbars=auto,width=900,height=500;");
}

function GetProtocol()
{
	return window.location.protocol;
}

function GetHost()
{
    return document.location.host;
}

function addEvent(obj, evType, fn)
{ 
     if (obj.addEventListener)
     { 
       obj.addEventListener(evType, fn, false); 
       return true; 
     } else if (obj.attachEvent){ 
       var r = obj.attachEvent("on"+evType, fn); 
       return r; 
     } else { 
       return false; 
     } 
}

function ShowWaitMessage(sMessage ,oParentObjectForDisplay)
{
	var iDialogWidth;
	var iDialogHeight;
 	document.body.style.cursor="wait";
 	if (sMessage == "") 
 		sMessage = "אנא המתן...";
 	
	oWaitPopup = window.createPopup();
	
    var oPopupBody = oWaitPopup.document.body;
	oPopupBody.style.backgroundColor = "lightyellow";
	oPopupBody.style.border = "solid black 1px";
	
    oPopupBody.innerHTML = "<div valign=middle align=center dir=rtl style=\"font-size:15pt;font-family: Arial;\" class='clsTDTableList'>" + sMessage + "</div>";
    
    iDialogWidth = oParentObjectForDisplay.clientWidth //window.dialogWidth.substr(0,window.dialogWidth.length-2);
    iDialogHeight = oParentObjectForDisplay.clientHeight // window.dialogHeight.substr(0,window.dialogHeight.length-2);
    
    oWaitPopup.show((iDialogWidth / 2 )- 175,(iDialogHeight / 2) - 12,350, 35, oParentObjectForDisplay);   
}

function HideWaitMessage()
{
	if (oWaitPopup != null)
		oWaitPopup.hide();
	oWaitPopup = null;
	
	document.body.style.cursor="";
}
function ShowWaitMessageHardCoded(sMessage,iDialogWidth ,iDialogHeight)
{
	if(iDialogWidth == -1)
	 iDialogWidth = screen.width;
	if(iDialogHeight == -1)
	 iDialogHeight = screen.height;
 	document.body.style.cursor="wait";
 	if (sMessage == "") 
 		sMessage = "אנא המתן...";
 	
	oWaitPopup = window.createPopup();
	
    var oPopupBody = oWaitPopup.document.body;
	oPopupBody.style.backgroundColor = "lightyellow";
	oPopupBody.style.border = "solid black 1px";
	
    oPopupBody.innerHTML = "<div valign=middle align=center dir=rtl style=\"font-size:15pt;font-family: Arial;\" class='clsTDTableList'>" + sMessage + "</div>";
    
    //iDialogWidth = oParentObjectForDisplay.clientWidth //window.dialogWidth.substr(0,window.dialogWidth.length-2);
    //iDialogHeight = oParentObjectForDisplay.clientHeight // window.dialogHeight.substr(0,window.dialogHeight.length-2);
    
   oWaitPopup.show((iDialogWidth / 2 )- 175,(iDialogHeight / 2) - 12,350, 35,null);   
}


function LoadMGEBasicToolsWindow(lft,tp,hgt,wdt,sAction,sTarget,frmName)
{
    var winOpt = "resizable=yes,toolbar=no,menubar=no,status=no,left=" + lft +",top=" + tp + ",height=" + hgt + ",width=" + wdt;
	window.open(MGE_BASIC_TOOLS_VIRTUAL_DIRECTORY + "General/Loader.htm",sTarget,winOpt);

    document.all.item(frmName).action = MGE_BASIC_TOOLS_VIRTUAL_DIRECTORY + sAction;
    document.all.item(frmName).target= sTarget;
    document.all.item(frmName).method = "post";
    document.all.item(frmName).submit();
}


