/*********************************************************************\
*                                                                     *
* FR.js                                         by Limei              *
*                                                                     *
* Provide javascript functions for FR app                             *
*                                                                     *
* 
\*********************************************************************/

 //custom createPolygon
function createPoly(points, colour, width, opacity, fillcolour, fillopacity, bounds, name, description) {
//                GLog.write("createPoly("+colour+","+width+"<"+opacity+","+fillcolour+","+fillopacity+","+name+","+description+")");
       var poly = new GPolygon(points, colour, width, opacity, fillcolour, fillopacity);
       poly.Name = name;
       poly.Description = description;
       var thismap = map;
       map.addOverlay(poly);
       exml.gpolygons.push(poly);
       var html = "<div style='font-weight: bold; font-size: medium; margin-bottom: 0em;  background-color:#C0E4F1; color:#1E194C;'>"+name+"</div>"
             +"<div style='font-family: Arial, sans-serif;font-size: small;width:250px; color:#1E194C;'><br />"+description+"</div>";
         
      GEvent.addListener(poly,"mouseover", function() {          
        thismap.openInfoWindowHtml(bounds.getCenter(),html);
      });
      GEvent.addListener(poly,"mouseout", function() {
        thismap.closeInfoWindow();
      }); 
      GEvent.addListener(poly,"click", function() {
        if (name)
        {    
//                var byWho // 0- County; 1 - Agency            
            CallServer(name+"&"+byWho, "");
        }
       
//            alert("You clicked the " + name+" polygon!" );
      } );
      return poly;
 }
 
 // Create polygon layer for county/agency_all layer.
 function createPoly_bgd(points, colour, width, opacity, fillcolour, fillopacity, bounds, name, description) {
//                GLog.write("createPoly("+colour+","+width+"<"+opacity+","+fillcolour+","+fillopacity+","+name+","+description+")");
       var poly = new GPolygon(points, colour, width, opacity, fillcolour, fillopacity);
       poly.Name = name;
       poly.Description = description;
       var thismap = map;
       map.addOverlay(poly);
       exml.gpolygons.push(poly);
          GEvent.addListener(poly,"mouseover", function() {
            var html = "<div style='font-weight: bold; font-size: medium; margin-bottom: 0em;  background-color:#C0E4F1; color:#1E194C;'>"+name+"</div>"
             +"<div style='font-family: Arial, sans-serif;font-size: small;width:250px; color:#1E194C;'><br />"
             +"There are currently no fire restrictions within "+name+" county.</div>";
            thismap.openInfoWindowHtml(bounds.getCenter(),html);
          });
          GEvent.addListener(poly,"mouseout", function() {
            thismap.closeInfoWindow();
          }); 
         
       return poly;
 }
 
// Receive callback result
function ReceiveServerData(rValue)
{    
// split rValue to an array, 0 for dlCurrentRestrictions, 1 for bltlNoRestArea, 2 for dlCoordInfo
       var prefix = getCrtlPrefix();
       
       var myOutput = new Array();    
       myOutput = rValue.split("++++");
       if (myOutput.length > 0)
       {
            // CurRest_Out
           var objCrtl1 = document.getElementById(prefix + "CurRest_Out");         
           if (objCrtl1)
                objCrtl1.innerHTML = myOutput[0];
                 
           else
                alert(myOutput[0]);                 
                 
            //NoRestArea_Out
            var objCrtl2 = document.getElementById(prefix + "NoRestArea_Out");
              if (objCrtl2)
                objCrtl2.innerHTML = myOutput[1];
                 
           else
                alert(myOutput[1]); 
            
            // CoordInfo_Out
            var objCrtl3 = document.getElementById(prefix + "CoordInfo_Out");
              if (objCrtl3)
                objCrtl3.innerHTML = myOutput[2];
                
           else
                alert(myOutput[2]); 
            
       }   
       
}

// Get the control's prefix ID
function getCrtlPrefix()
{
       var prefix;             
       var    objCrtlPrefix = document.getElementById("ctrlPrefixCR");             

       if (objCrtlPrefix)
             prefix = objCrtlPrefix.value;                 

       return prefix;
}
