
	jQuery.expr[":"].containsNoCase = function(el, i, m) {

			var search = m[3];
			if (!search) returnfalse;
			return eval("/" + search + "/i").test($(el).text());
	};

	
	$(document).ready(function(){

        document.body.onunload = "GUnload()";
        
		$("#side_bar li").each(function(){
			this.style.display="block";
			this.removeAttribute("style");
        });

		// remove the cancel search image
		jQuery('#imgSearch').hide();

		// clear the textbox
		jQuery('#txtSearch').val('');

		// reset the search when the cancel image is clicked
		jQuery('#imgSearch').click(function(){
			resetSearch();
		});

		// execute the search
		jQuery('#txtSearch').keyup(function(){

			// only search when there are 3 or more characters in the textbox
			if (jQuery('#txtSearch').val().length >= 1){

				// hide all rows
				jQuery('#tblSearch tr').hide();

				// show the header row
				jQuery('#tblSearch tr:first').show();

				// show the matching rows (using the containsNoCase from Rick Strahl)
				jQuery('#tblSearch tr td:containsNoCase(\'' + jQuery('#txtSearch').val() + '\')').parent().show();

				// show the cancel search image
				jQuery('#imgSearch').show();

			} 
			
			if (jQuery('#txtSearch').val().length == 0){
				// if the user removed all of the text, reset the search
				resetSearch();
			}

			// if there were no matching rows, tell the user
			if (jQuery('#tblSearch tr:visible').length == 1){

				// remove the norecords row if it already exists
				jQuery('.norecords').remove();

				// add the norecords row
				jQuery('#tblSearch').append('<tr class="norecords"><td colspan="2" class="Normal">No outage reported for this location/no.</td></tr>');
			}

		});


    }); // end of jQuery function.



	function resetSearch() {
		// clear the textbox
		jQuery('#txtSearch').val('');

		// show all table rows
		jQuery('#tblSearch tr').show();

		// remove any no records rows
		jQuery('.norecords').remove();

		// remove the cancel search image
		jQuery('#imgSearch').hide();

		// make sure we re-focus on the textbox for usability
		jQuery('#txtSearch').focus();

	}



	function popuptip() {
		var popup = window.open('popup.html','Map', 'width=900,height=500');
	}

	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 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 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 cloc = window.location.toString();
		//alert('cloc : '+cloc);
//	    if (loc.toLowerCase() == "city") { 
	//    	newloc = "nisource_city_map.html"; 
	  ///  } else if (loc.toLowerCase() == "zip") { 
	  //  	newloc = "nisource_zip_map.html"; 
	  //  }
	    var newloc = "outagemap.html?action="+loc;
	    window.location = newloc;
   	}