﻿

function page_onload(page_name)
   { 
     if(screen.width == 1280)
        {
          if (page_name == "jo2")
            {
                   if (navigator.appName == "Netscape")
                     {
                       document.getElementById("page_holder").style.width = "1248px";
                     }
                   else
                     {
                       document.getElementById("page_holder").style.width = "1259px";
                     }
                   document.getElementById("jo2_header").style.width = "1225px";
                   document.getElementById("jo2_header_trans").style.width = "1209px";  
                   document.getElementById("jo2_header_amman").style.left = "700px";
                   document.getElementById("jo2_but_holder").style.left = "600px";
                   document.getElementById("jo2_icons_holder").style.left = "300px"; 
                   document.getElementById("jo2_search_trans").style.left = "1005px"; 
                   document.getElementById("jo2_search_trans").style.top = "120px"; 
                   document.getElementById("footer_link").style.width = "550px";              
            }
          else if (page_name == "jo1")
            {
               if (navigator.appName == "Netscape")
                  {
                     document.getElementById("page_holder").style.width = "1248px";
                  }
               else
                  {
                    document.getElementById("page_holder").style.width = "1259px";
                  }
               document.getElementById("page_holder").style.width = "1259px";
               document.getElementById("footer_link").style.width = "550px";
               document.getElementById("jo1_icons_holder").style.left = "150px";
               document.getElementById("jo1_button_holder").style.left = "280px";
            }
       }
      if (page_name == "jo2")
        float_footer1();
      else
        float_footer();
   }
function jo1_max_min(obj,type,name,option)
  {
     if (type == "max")
       {
         obj.parentNode.className = "jo1_open_close jo1_open";
         obj.title = "Minimize";
         document.getElementById("c_" + name + "_holder").style.display = "block";
         obj.onclick = function () {jo1_max_min(this,'min',name,option);};
         if (option == "jo2")
           {
              document.getElementById("jo2_layers_back").style.height = document.getElementById("jo2_layers_con").offsetHeight + 1 + "px";
              document.getElementById("jo2_layers_con").style.marginTop = - document.getElementById("jo2_layers_con").offsetHeight + "px"
           }
       }
     else
       {
         obj.parentNode.className = "jo1_open_close";
         obj.title = "Maximize";
         document.getElementById("c_" + name + "_holder").style.display = "none";
         obj.onclick = function () {jo1_max_min(this,'max',name,option);};
         if (option == "jo2")
           {
              document.getElementById("jo2_layers_back").style.height = document.getElementById("jo2_layers_con").offsetHeight + 1 + "px";
              document.getElementById("jo2_layers_con").style.marginTop = - document.getElementById("jo2_layers_con").offsetHeight + "px"
           }
       }
  }
  
function jo1_open_close(obj,type)
 {  
    if (type == "close")
      {
        document.getElementById("jo1_float").style.display = "none";
        document.getElementById("jo1_seach_close").style.display = "none";
        floating_pane("close",10);
      }
    else
      {
        floating_pane("open",10);
      }
 }

var t_float = 0;
function floating_pane(type,step)
  {
     var temp_width = document.getElementById("jo1_float_holder").style.width;
     temp_width = temp_width.substring(0,temp_width.indexOf("px"));
     if (type == "close")
       {
         if (temp_width > 35)
           {
             temp_width = temp_width*1 - step;
             document.getElementById("jo1_float_holder").style.width = temp_width + "px";
             t_float = setTimeout(function (){floating_pane(type,step)},20);
           }
         else
           {
             clearTimeout(t_float);
             document.getElementById("jo1_float").style.display = "none";
             document.getElementById("jo1_search_title").style.visibility = "hidden";
             document.getElementById("jo1_layers_title").style.visibility = "hidden";
             document.getElementById("jo1_search_open").style.display = "block";
           }
       }
    if (type == "open")
       {
         if (temp_width < 225)
           {
             temp_width = temp_width*1 + step;
             document.getElementById("jo1_float_holder").style.width = temp_width + "px";
             t_float = setTimeout(function (){floating_pane(type,step)},20);
           }
         else
           {
             clearTimeout(t_float);
             document.getElementById("jo1_float").style.display = "block";
             document.getElementById("jo1_search_title").style.visibility = "visible";
             document.getElementById("jo1_layers_title").style.visibility = "visible";
             document.getElementById("jo1_search_open").style.display = "none";
             document.getElementById("jo1_float").style.display = "block";
             document.getElementById("jo1_seach_close").style.display = "block";
           }
       }
  }
  
 function home_login(obj,title,input_type)
  {
    obj.value = obj.value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
    if (title == "focus")
      {
         if (input_type == "pass" && obj.value == "password")
           {
             obj.value = "";
             replace_input(obj,"password")
           }
         else if (input_type == "user" && obj.value == "username")
           {
             obj.value = "";
             obj.style.color = "#000000";
             obj.focus();
           }
      }
    else
      {
         var temp_value = obj.value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
         if (temp_value == "")
           {
              if (input_type == "pass")
               {
                  obj.value = "";
                  replace_input(obj,"text")
               }
              else 
               {
                 obj.style.color ="#BABABA";
                 obj.value = " username";
               }
           }
      }
  }
  
 function replace_input(old_object,new_type)
   {
      var newObject = document.createElement('input');
      newObject.type = new_type;
      if(old_object.id) newObject.id = old_object.id;
      if(old_object.className) newObject.className = old_object.className;
      if(old_object.onblur) newObject.onblur = old_object.onblur;
      if(old_object.onfocus) newObject.onfocus = old_object.onfocus;
      old_object.parentNode.replaceChild(newObject,old_object);
      newObject.value = "";
      if (new_type == "password")
        {
          newObject.style.color = "#000000";
          newObject.focus();
        }
      else
        {
          newObject.value = "password";
        }
   }
   
 function jo2_move(obj)
   {
     offset_left = document.getElementById('jo2_search_trans').offsetLeft + document.getElementById('jo2_search_trans').parentNode.offsetLeft;
     //left_limit = (temp_width - 1003)/2;
     //right_limit =  left_limit + 1003;
     document.getElementById('page_holder').onmousemove = getMouseXY;
   }
   
var offset_left = 0;
var hor_holder = 0;
var ver_holder = 0;
var first_time = 0;
function getMouseXY(e)
 {
    var gen_holder = document.getElementById('jo2_search_trans');
   // var fill_star_pos = comment_items_holder.offsetLeft + comment_items_holder.parentNode.parentNode.offsetLeft + comment_items_holder.parentNode.parentNode.parentNode.offsetLeft + 3;
  //  var fill_width = 0;
    var IE = document.all?true:false;
    if (!IE) document.captureEvents(Event.MOUSEMOVE);
    if (IE) 
      { // grab the x-y pos.s if browser is IE
        tempX = event.clientX + document.body.scrollLeft;
        tempY = event.clientY + document.body.scrollTop;
    //    fill_width = tempX - fill_star_pos;
      }
    else 
      { // grab the x-y pos.s if browser is NS
        tempX = e.pageX;
        tempY = e.pageY;
      }  
    if (tempX < 0){tempX = 0;}
    if (tempY < 0){tempY = 0;} 
    if (hor_holder != 0 || ver_holder != 0)
      { 
        var temp_left =  tempX - hor_holder;
        var temp_pos_left = gen_holder.style.left;
        gen_holder.style.left = temp_pos_left.substring(0,temp_pos_left.indexOf("px"))*1 + temp_left*1 + "px";
        var temp_top = tempY - ver_holder;
        var temp_pos_top = gen_holder.style.top;
        gen_holder.style.top = temp_pos_top.substring(0,temp_pos_top.indexOf("px"))*1 + temp_top*1 + "px";
      }
    //document.getElementById('test').innerHTML = "left:" + tempX + " top:" + tempY + " " + hor_holder;
    hor_holder = tempX;
    ver_holder = tempY;
 }
 
function jo2_not_move(obj)
  {
    document.getElementById('page_holder').onmousemove = function (){first_time = 0;hor_holder = 0;ver_holder = 0;};
  }
  
function jo2_min_max(obj,type,block_name)
  {
     if (type == "min")
       {
          clearTimeout(t_max);
          obj.className = "jo2_mini";
          if (block_name == "search")
            {
              document.getElementById('jo2_search_con').style.display = "none"; 
              min_max('jo2_search_back',"min",5,0,0,block_name);
              obj.onclick = function () {jo2_min_max(this,'max',"search");};;
              document.getElementById('jo2_search_img').style.display = "none"; 
              document.getElementById('jo2_search_img_max').style.display = "block"; 
              obj.title = "Maximize";
            }
          else if (block_name == "layers")
            {
              document.getElementById('jo2_layers_con').style.display = "none"; 
              min_max('jo2_layers_back',"min",5,0,0,block_name);
              obj.onclick = function () {jo2_min_max(this,'max',"layers");};
              document.getElementById('jo2_layers_img').style.display = "none"; 
              document.getElementById('jo2_layers_img_max').style.display = "block"; 
              obj.title = "Maximize";
            }
       }
     else if (type == "max")
       {
          clearTimeout(t_min);
          if (block_name == "search")
            { 
              document.getElementById('jo2_search_con').style.visibility = "hidden";
              document.getElementById('jo2_search_con').style.display = "block";
              min_max('jo2_search_back',"max",5,0,0,block_name);
              obj.onclick = function () {jo2_min_max(this,'min',"search");};
              document.getElementById('jo2_search_img').style.display = "block"; 
              document.getElementById('jo2_search_img_max').style.display = "none"; 
              obj.title = "Minimize";
            }
          else if (block_name == "layers")
            {
              document.getElementById('jo2_layers_con').style.visibility = "hidden";
              document.getElementById('jo2_layers_con').style.display = "block";
              min_max('jo2_layers_back',"max",5,0,0,block_name);
              obj.onclick = function () {jo2_min_max(this,'min',"layers");};
              document.getElementById('jo2_layers_img').style.display = "block"; 
              document.getElementById('jo2_layers_img_max').style.display = "none"; 
              obj.title = "Minimize";
            }
       }
  }
  
  
 var t_min = 0;
  var t_max = 0;
function min_max(obj_name,type,step,down_limit,upper_limit,block_name)
  {
     var temp_height = document.getElementById(obj_name).style.height;
     temp_height = temp_height.substring(0,temp_height.indexOf("px"));
     var temp_margin = document.getElementById(obj_name).style.marginBottom;
     temp_margin = temp_margin.substring(0,temp_margin.indexOf("px"));
     if (type == "min")
       {
         clearTimeout(t_max);
         if (Math.abs(temp_height) > 0)
           {
             temp_height = temp_height*1 - step;
             document.getElementById(obj_name).style.height = temp_height + "px";
             t_min = setTimeout(function (){min_max(obj_name,type,step,down_limit,upper_limit,block_name)},0.2);
           }
         else
           {
             clearTimeout(t_min);
             if  (block_name == "search")
               {
                 document.getElementById(obj_name).style.height = (temp_height*1 + 1) + "px";
               }
           }
       }
    else if (type == "max")
       {
         var name_holder = "";
         name_holder = "jo2_layers_con";
         if  (block_name == "search")
               {
                 name_holder = "jo2_search_con";
               }
         if (temp_height < document.getElementById(name_holder).offsetHeight)
           {
             temp_height = temp_height*1 + step;
             document.getElementById(obj_name).style.height = temp_height + "px";
             t_max = setTimeout(function (){min_max(obj_name,type,step,down_limit,upper_limit,block_name)},0.2);
           }
         else
           {
             clearTimeout(t_max);
             document.getElementById(name_holder).style.visibility = "visible";
           }
       }
  }
  
  var t_footer = 0;
  function float_footer()
    {
      document.getElementById("jo1_footer").style.top = alertSize() + get_window_scroll() - 65 + "px";
      t_footer = setTimeout(function (){float_footer()},0.2);
    }
    
    
   var t_footer1 = 0;
  function float_footer1()
    {
      document.getElementById("jo1_footer").style.top = alertSize() + get_window_scroll() - 37 + "px";
      t_footer1 = setTimeout(function (){float_footer1()},0.2);
    }
 
 
 /*---------------------------*/
 /*---------------------------*/
 
 function get_window_scroll() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfY;
}

function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
 // window.alert( 'Height = ' + myHeight );
 return myHeight;
}
////////////////////////////////////////////////*

 var map, queryTask, query, click;
      function init() {
       map = new esri.Map("mapDiv");
        //map.addLayer(new esri.layers.ArcGISTiledMapServiceLayer("http://gis-datastorage/ok/rest/services/mapjo/MapServer"));
        map.addLayer(new esri.layers.ArcGISDynamicMapServiceLayer("http://194.165.147.5/ok/rest/services/mapjo/MapServer", { opacity:0.4 }));
        dojo.connect(map, "onClick", doQuery);
        queryTask = new esri.tasks.QueryTask("http://194.165.147.5/ok/rest/services/mapjo/MapServer/0");
        dojo.connect(queryTask, "onComplete", getChart);
        //dojo.connect(map.infoWindow, "onHide", function() {map.graphics.clear();});
        query = new esri.tasks.Query();
        query.outFields = ["WEBSITE"];
        query.returnGeometry = true;
        query.where ="WEBSITE=WEBSITE" ;
        dojo.connect(map, "onLoad", initFunctionality);
       
        ///////////////////////////////////////////////
        findTask = new esri.tasks.FindTask("http://194.165.147.5/ok/rest/services/mapjo/MapServer");
 
          findParams = new esri.tasks.FindParameters();
          findParams.returnGeometry = true;
          findParams.layerIds = [0];
          findParams.searchFields = ["WEBSITE"];
       
      }
      function go(searchText)
      {
          window.location="http://" + searchText;
      }
      function execute(searchText) {
        //set the search text to find parameters
        findParams.searchText = searchText;
        findTask.execute(findParams,showResults);
      }
       function showResults(results) {
        //find results return an array of findResult.
        map.graphics.clear();
        //var dataForGrid = [];

        for (var i=0, il=results.length; i<il; i++) {
          var curFeature = results[i];
          var graphic = curFeature.feature;
          //var layerName = curFeature.layerName;
          //var layerId = curFeature.layerId;
          //var foundFieldName = curFeature.foundFieldName;
         // var foundFieldValue = graphic.attributes[foundFieldName];

      //    var attValues = [layerName,layerId,foundFieldName,foundFieldValue];
       //   dataForGrid.push(attValues);

          switch (graphic.geometry.type) {
            case "point":
              var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 1), new dojo.Color([0,255,0,0.25]));
              break;
            case "polyline":
              var symbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASH, new dojo.Color([255,0,0]), 1);
              break;
            case "polygon":
             var highlightSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([247,148,30,1]), 1),new dojo.Color([247,148,30,1]));
              var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([247,148,30,1]), 1),new dojo.Color([247,148,30,0]));
              break;
          }
          graphic.setSymbol(highlightSymbol);
          map.graphics.add(graphic);
        }

    //    var model = new dojox.grid.data.Table(null, dataForGrid);

     //   var view1 = {
     ///     cells: [
        //    [{name: 'Layer Name'},{name: 'Layer ID'},{name: 'Found Field Name'},{name: 'Found Field Value'}]
          //]
     //   };

     //   var layout = [ view1 ];
//gridWidget.setModel(model);
     //   gridWidget.setStructure(layout);

      }

function doQuery(evt) {
        click = query.geometry = evt.mapPoint;
        queryTask.execute(query);
      }

      function initFunctionality(map) {
        //build query task
        var queryTask = new esri.tasks.QueryTask("http://194.165.147.5/ok/rest/services/mapjo/MapServer/0");

        //build query filter
        var query = new esri.tasks.Query();
        query.returnGeometry = true;
        query.outFields = ["WEBSITE"];
        query.where ="WEBSITE=WEBSITE" ;

       // map.infoWindow.resize(245,125);

        //Can listen for onComplete event to process results or can use the callback option in the queryTask.execute method.

        dojo.connect(queryTask, "onComplete", function(featureSet) {
            map.graphics.clear();
            //var highlightSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 3), new dojo.Color([125,125,125,0.35]));
            //var highlightSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([247,148,30,1]), 3);
            var highlightSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([247, 148, 30, 1]), 1), new dojo.Color([247, 148, 30, 1]));
            var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([247, 148, 30, 1]), 1), new dojo.Color([247, 148, 30, 0]));

            var countiesGraphicsLayer = new esri.layers.GraphicsLayer();
            //QueryTask returns a featureSet.  Loop through features in the featureSet and add them to the map.
            for (var i = 0, il = featureSet.features.length; i < il; i++) {
                //Get the current feature from the featureSet.
                //Feature is a graphic
                var graphic = featureSet.features[i];
                graphic.setSymbol(symbol);
                //graphic.setInfoTemplate(infoTemplate);

                //Add graphic to the counties graphics layer.
                countiesGraphicsLayer.add(graphic);
            }
            map.addLayer(countiesGraphicsLayer);
            map.graphics.enableMouseEvents();
            //listen for when the onMouseOver event fires on the countiesGraphicsLayer
            //when fired, create a new graphic with the geometry from the event.graphic and add it to the maps graphics layer
            dojo.connect(countiesGraphicsLayer, "onMouseOver", function(evt) {
                //attributes = {...}  WEBSITE = "www.Mafraq.mapjo.com"
                map.graphics.clear();  //use the maps graphics layer as the highlight layer
                var ddd = evt.graphic.attributes.WEBSITE;

                //GOV_EN = "Madaba"
                //  var content = evt.graphic.getContent();
                //   map.infoWindow.setContent(content);
                //   var title = evt.graphic.getTitle();
                //    map.infoWindow.setTitle(title);
                var highlightGraphic = new esri.Graphic(evt.graphic.geometry, highlightSymbol);
                var yy = dojo.byId('community');
                var i = 0;
                var name;
                map.graphics.add(highlightGraphic);
                for (i; i < yy.length; i++) {

                    if (yy[i].value == ddd) {
                        document.getElementById("community").selectedIndex = i;
                        name = yy[i].text;
                        break;
                    }


                }
           //     document.getElementById("TitelDiv").innerHTML = name;
                //////    TitelDiv

                //    map.infoWindow.show(evt.screenPoint,map.getInfoWindowAnchor(evt.screenPoint));
            });
            //listen for when map.graphics onMouseOut event is fired and then clear the highlight graphic
            //and hide the info window
            dojo.connect(map.graphics, "onMouseOut", function(evt) {
                map.graphics.clear();
                map.infoWindow.hide();
            });

        });

        queryTask.execute(query);
      }
         function getChart(featureSet) {
        map.graphics.clear();

        var features = featureSet.features;
        var feature, attributes;
        for (var i=0; i<features.length; i++)
         {
          feature = features[i];
          attributes = feature.attributes;
          
window.open("http://"+attributes["WEBSITE"],"_self");
                }
      }
       
     
  




