var base_icon_url = plugin_url+"/icons/";
var problem_icon = base_icon_url+"problem-icon.png";
var construction_icon = base_icon_url+"construction-icon.png";
var info_icon = base_icon_url+"info-icon.png";

function $_GET(q,s) {
   s = (s) ? s : window.location.search;
   var re = new RegExp('&'+q+'=([^&]*)','i');
   return (s=s.replace(/^\?/,'&').match(re)) ? s=s[1] : s='';
}

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function get_icon_url(report_type)
{
    var icon_name;
    if (report_type == "p") icon_name = problem_icon;
    else if (report_type == "c") icon_name = construction_icon;
    else if (report_type == "i") icon_name = info_icon;
    else icon_name = problem_icon; 
    return icon_name;
}

function icon_set_type(report_type)
{
    var icon_name=get_icon_url(report_type);
    var icon = new google.maps.MarkerImage(icon_name);
    return icon;
}

function report_types_create(id,include_callback,include_all) 
{
   var obj=document.getElementById(id);
   if (obj==null) { return;}

   var html = "<select name=\"report_types\"";

   if (include_callback) 
          html+=' onChange=report_type_click(this)';
   html+=">";

   if (include_all) 
       html+='<option value="a">All report types</option>';

   for (var i=0;i<report_types.length;i++) {
       html+='<option value="'+report_types[i].acronym+'"';
       html+='>'+ report_types[i].title+'</option>';
   }
   html+="</select>";
   obj.innerHTML=html;
}

function masks_create(id,type,mask) 
{
   var obj=document.getElementById(id);
   if (obj==null) { return;}

   var html = "";
   var my_masks = masks[type];
   for (var i=0;i<my_masks.length;i++) {

       html+='<input type="checkbox" name="mask" id="'+(i+1)+'"';

       // Figure out if it is checked or not
       var value=1<<i;
       if (value & mask)
           html+=' checked="true"';

       html+= ' onClick="maskclick(this,\''+(i+1)+'\')">'+
         my_masks[i]+'<br>';
   }
   obj.innerHTML=html;
}

