
	$(document).ready(function(){
        document.body.onunload = "GUnload()";
        $("#side_bar li").each(function(){
          this.style.display="block";
          this.removeAttribute("style");
        });

		// Enable this to remove temporarily the map from the page
		//$("#main_content table").css("display","none");
		//$("#main_content p").css("display","none");
		//$("#main_content h1").after('<p style="color: red;">The outage map is currently unavailable. To find out about outages in your area, please call our Customer Service Center at 1-800-743-5000. <br />To report an outage, call 1-800-743-5002.</p>');
    });

	function popuptip(){
		var popup = window.open('/mybusiness/customerservice/energystatus/outagemap/popup/tips.shtml','Map', 'width=600,height=600');
	}

	function search(t){
		var key = t.value.toString().toLowerCase();
		var x = 0;
		var empty = true;
		$("#side_bar li").each(function(){
		  var nodeText = this.childNodes[0].childNodes[0].nodeValue.toString().toLowerCase();
		  nodeText = nodeText.substr(0,key.length);
		  if (nodeText==key){
        this.style.display="block";
        this.removeAttribute("style");
        empty = false;
		  } else {  
			  this.style.display = "none"; 
			}
		});
		if(empty){
      $("#side_bar p").remove();
      var noOutageMsg = "No outage reported for this location.";
      var msgEle = document.createElement("p");
      msgEle.appendChild(document.createTextNode(noOutageMsg));
      document.getElementById("side_bar").appendChild(msgEle);
		}
		else {
      $("#side_bar p").remove();
		}
	}
	
	
	function old_causeCode(id){
    switch (id){
      case "Awaiting Investigation":
        return "Awaiting investigation";
      case "EQUIPM+T FAIL":
        return "Caused by damaged equipment";
      case "TREES":
        return "Trees falling on the power line";
      case "BRKN POLE":
        return "Broken power pole";
      case "CAR POLE ACC":
        return "Car knocking down a power pole";
      case "FIRE":
        return "Caused by a fire";
      case "WIRE DOWN":
        return "Fallen wires";
      case "TRFMR FAIL":
        return "Caused by a damaged transformer";
      case "PATROLLING":
        return "Unknown";
      case "PLNND SHUTDOWN":
        return "Your area is undergoing scheduled maintenance";
      case "CB/LR LOCKOUT":
        return "Unknown";
      case "BLOWN FUSE":
        return "Unknown";
      case "EXPLOSION":
        return "Unknown";
      case "SUBSTN EQUIP":
        return "Unknown";
      case "STORM":
        return "Result of current storm or emergency conditions";
      case "ROTATING BLOCK":
        return "Interrupted due to high electric demand";
      case "DEBRIS":
        return "Damage on the power line";
      case "NOT OUTAGE":
        return "Electrical emergency - No outage";
      default:
        return "Unknown";
    }
  }
  
	function causeCode(id){
		switch (id){
			case "":
				return "PG&E will be assessing the cause of your outage.";
			case "Unknown":
				return "PG&E will be assessing the cause of your outage.";
			case "PATROLLING":
				return "PG&E is investigating the cause of your outage.";
			case "CB/LR OPN":
				return "There is a widespread outage in your area and PG&E is investigating.";
			case "FU BLWN BRKN":
				return "There is a widespread outage in your area and PG&E is investigating.";
			case "REPAIR WIRE DWN":
				return "Field personnel have found a power line down.";
			case "TREE CONTACT":
				return "Trees are causing outages in your area.";
			case "BRKN POLE EQUIPMNT":
				return "Found damaged equipment on a power pole in your area.";
			case "BRKN POLE":
				return "Found a broken pole in your area.";
			case "REPLCE TXFMR":
				return "A transformer needs to be replaced.";
			case "DAMGE UG CABLE":
				return "Found damage to an underground power cable.";
			case "BRKN UG EQUIPMNT":
				return "Found damage to underground equipment in your area.";
			case "FOREIGN OBJ":
				return "A foreign object has been identified as the cause of your outage.";
			case "NG CONNECTION":
				return "Field personnel have found a connection that needs to be repaired.";
			case "REPLCE SRVC":
				return "Field personnel have found damage on the service line to your premise(s).";
			case "CAR POLE":
				return "A vehicle has hit a power pole in your vicinity.";
			case "FIRE":
				return "Fire in area, causing outages.";
			case "POLE FIRE":
				return "Found damage to a pole in your area.";
			case "OVRLD TXFMR":
				return "Your outage has been caused by a problem with a transformer.";
			case "THRD PARTY":
				return "Damage to PG&E equipment has caused an outage in your area.";
			case "PLNND SHUTDOWN":
				return "Your outage is due to planned maintenance work that we are performing in your area.";
			case "TRNSMISSN OR SUBSTN":
				return "Interruption to a main transmission lines or substations causing widespread outage.";
			case "FLOOD":
				return "Flooding is limiting our ability to safely assess damage and restore power.";
			case "LGHTNING":
				return "Lightning caused outages.";
			case "SNOW":
				return "Your outage has been caused by snow conditions.";
			case "EMERG REPAIRS":
				return "Unplanned, necessary emergency work is being performed.";
			case "STORM HEAT":
				return "Heat related conditions are causing outages in your area.";
			case "STORM WIND RAIN":
				return "The current storm or emergency procedures are causing multiple outages in your area.";
			case "STORM SNOW":
				return "Snow conditions are limiting our ability to safely assess damage and restore power.";
			case "ROTATING BLOCK":
				return "During this emergency, electric service is being temporarily interrupted to your area.";
			case "NOT OUTAGE":
				return "This outage was caused by a test or is an erroneous outage.";
			case "EXPLOSION":
				return "Damage to PG&E equipment has caused an outage in your area.";
			default:
				return "PG&E will be assessing the cause of your outage.";
		}
	}
  
  
  function statusCode(id){
    switch (id){
      case "Awaiting T-Man":
        return "Awaiting assessment";
      case "T-Man Enroute":
        return "Crew en route";
      case "T-Man On Site":
        return "Assessment in progress";
      case "Awaiting repair crew":
        return "Awaiting repair crew";
      case "Crew Enroute":
        return "Awaiting repair crew";
      case "Crew On Site":
        return "Repair crew onsite";
      case "No Access":
        return "Unable to access equipment";
      default:
        return "Awaiting assessment";
    }
  }
  
  /*************************
    Descriptions:
    Receives numeric parameter 'c' and returns the range info in string format.
  *************************/
  function getRange(c){
    if (c>=1 && c<50) return "<strong>1</strong> to <strong>49</strong>";
    else if (c>=50 && c<500)  return "<strong>50</strong> to <strong>499</strong>";
    else if (c>=500 && c<5000)  return "<strong>500</strong> to <strong>4999</strong>";
    else if (c>=5000) return "<strong>5000+</strong>";
    else return "<strong>unknown</strong>";
  }
  
//determine the icon to be shown, based on the number of affected customers 
	function calcIcon(custNum) {
			if (custNum < 50) {	
				return 'green';
			} else if (custNum < 500) {
				return 'yellow';
			} else if (custNum < 5000) {
				return 'orange';
			} else return 'red';			
			
	}
	
	function moveto(loc){

	var agent=navigator.userAgent.toLowerCase();
	var is_iphone = (agent.indexOf('iphone')!=-1);
	var is_iPhoneApp = (is_iphone && window.location.search.substring(1).split("?")[0] == "app");

   	var cloc = window.location.toString();
	var newloc = "/myhome/customerservice/energystatus/outagemap/";
	if (cloc.indexOf("myhome")>=0){
		newloc = "/myhome/customerservice/energystatus/outagemap/";
	}
	else if (cloc.indexOf("mybusiness")>=0){
		newloc = "/mybusiness/customerservice/energystatus/outagemap/";
	}
	else if (cloc.indexOf("about")>=0){
		newloc = "/about/news/outagestatus/outagemap/";
	}

    if (loc.toLowerCase() == "city")
    { newloc = newloc+"index.shtml"; }
    else if (loc.toLowerCase() == "county")
    { newloc = newloc+"om_county.shtml"; }
    else if (loc.toLowerCase() == "zip")
    { newloc = newloc+"zip.shtml"; }

	if (is_iPhoneApp) {
		newloc = newloc + "?app";
	}

    window.location = newloc;
   }
   
   
