/* iPhone viewport setup by Jeff Held */
var theBrowser = window.navigator.userAgent;

if (theBrowser.indexOf("iPhone") != -1) {
	window.innerWidth = 751;		
}

/* QueryString Link Builder by Jeff Held */

function buildLink(theURL) {
var currentURL = String(document.location);
var arr = currentURL.split('?');
var newURL = "";
if (arr[1] != null) {
	newURL = theURL + "?" + arr[1];
	} else {
	newURL = theURL;
	}
document.location = newURL;
}

function buildString(theURL) {
var currentURL = String(document.location);
var arr = currentURL.split('?');
var newURL = "";
if (arr[1] != null) {
	newURL = theURL + "?" + arr[1];
	} else {
	newURL = theURL;
	}
return newURL;
}


/* Primary nav img rollover func, by B. Hyslop */
	// arg[0]=img id, arg[1]=change status to */
function swap(){
var args=swap.arguments;
var path='/includes/images/nav/';
var rollArray = new Array("navhome","your_home","navbiz","your_biz","navcustsvc","cust_svc","navrebates","rebates","navsafety","safety","navfield","field_work","navaboutus","aboutus");

	imgID=rollArray[args[0]*2];
	imgFile=rollArray[args[0]*2+1];
	document.images[imgID].src=''+path+imgFile+'_'+args[1]+'.gif';
} // end


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function popWin()
{
	var args;
	args=popSite.arguments;
	window.open(args[0],args[1],'height=460,width=640,left=20,top=20,screenX=20,screenY=20,toolbar,location,scrollbars,menubar,resizable,status');
}

function popOpen(URL) {
	window.open(URL,"pop","height=300,width=420,left=20,top=20,screenX=20,screenY=20,scrollbars");
}

function popSite()
{
	var args;
	args=popSite.arguments;
	window.open(args[0],args[1],'height=460,width=640,left=20,top=20,screenX=20,screenY=20,toolbar,location,scrollbars,menubar,resizable,status');
}


function loadinparent(url, closeSelf){ // used by popups
	self.opener.location = url;
	if(closeSelf) self.close();
	}

// ************ added poll functions  - Jeff Held (j0hg) & Long A. Huynh (lahy) 1/3/2004 ***************

var doThePoll = false;

function doPoll () {
	// called onload on all pages -- empty function so site need not be regenerated
}

// launch script for survey JEFF HELD (j0hg) 10/2003 --
	
	function launch() {
	    if(doThePoll){
			if (!getCookie("PollQuestion")) {
	    		if (!(navigator.userAgent.indexOf("PGE") != -1)) {
					if (rightGuest()) {
	    	 			window.open('/ask_survey.html', 'Survey', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=300,height=250'); 
	    			}
				}
			}
	    }
	}
	
	// name to search for is: PollQuestion
	var bites = document.cookie.split("; "); // break cookie into array of bites
	function getCookie(name) { // use: getCookie("name");
	   for (var i=0; i < bites.length; i++) {
	     nextbite = bites[i].split("="); // break into name and value
	     if (nextbite[0] == name) // if name matches
	       return true; // return true
	   }
	// if there is no match
	   return false;
	}
	
	function rightGuest () {
		var numGuests = 10 // set the number of guests on average to poll, must be a positive integer (every 10th guest)
		var theNumber = Math.round(Math.random()*(numGuests-1));
		if (theNumber == 0) {
			return true;
		} else {
			return false;
		}
	}
	
// ************ end poll code ***************************************************************************
	
// this variable added 1/9/2004 to allow the obsolete browser message to be displayed without appearing in the search engine results.
// (Which is what was happening when the message was inside the body of the HTML page.) Added by Jeff Held (j0hg).
var global_browser_message = "<strong>Please note:</strong> You are browsing the unformatted pge.com because your browser may not support Web standards. These standards allow us to deliver a more efficient, accessible site while ensuring its compatibility with both current and future browsers. If you wish to display the site as it was designed, please <a href='/help/'>upgrade your browser</a>";

// function that upsize and downsize the text within the "container" div tag.
// added 4/30/2004 by Jeff Held (j0hg)

		function upSize(){
			var increment = 2; // increment font grows in pixels
			var ptags = document.getElementById("content").getElementsByTagName("*");
			for (var i = 0; i < ptags.length; i++){
				var p = ptags[i];		
				var size = p.style.fontSize;
				var sizeInt = parseInt(getSize(size));
				var sizeUp = sizeInt + increment;
				p.style.fontSize = sizeUp + "px";			
			}
			// this keeps the title the same size
			var ttags = document.getElementById("content").getElementsByTagName("h1");
			for (var i = 0; i < ttags.length; i++){
				var t = ttags[i];		
				t.style.fontSize = "18px";			
			}
		
		}
		function downSize(){
			var increment = 2; // increment font shrinks in pixels
			var ptags = document.getElementById("content").getElementsByTagName("*");
			for (var i = 0; i < ptags.length; i++){
				var p = ptags[i];		
				var size = p.style.fontSize;
				var sizeInt = parseInt(getSize(size));
				var sizeUp = sizeInt - increment;
				if (sizeUp < 11){
					p.style.fontSize = "11px";
				} else {
					p.style.fontSize = sizeUp + "px";
				}			
			}
			// this keeps the title the same size
			var ttags = document.getElementById("content").getElementsByTagName("h1");
			for (var i = 0; i < ttags.length; i++){
				var t = ttags[i];		
				t.style.fontSize = "18px";			
			}
		
		}
		function getSize(size) {
			var theSizeInt = 11;
			if (size != "") {
				var sizeString = size;
			} else {
				var sizeString = theSizeInt + "px";
			}
			var sizeParts = sizeString.split("p");
			theSizeInt = parseInt(sizeParts[0]);
			return theSizeInt;
		}
// end increment code
/*
	----------------------------------------------------------------------------------
	Table sort function by Roman Koch rewritten/adapted 
	to be ECMA compliant for PGE.com by Jeff Held (j0hg).
	----------------------------------------------------------------------------------
	This code allows table data to be sorted. clicking once sorts ascending, clicking a second time sorts descending.
	This script is dynamic, your table can have any combination of columns and rows
	Use a table calling the function in the table head with a link:
	<table>
		<thead>
			<tr>
				<th><a href="#" onclick="TableSort('tableName',0,'a');">LanID</a></th>
			</tr>
		</thead>
		<tbody id="tableName">
			<tr>
				<td>j0hg</td>
			</tr>
			<tr>
				<td>dpw8</td>
			</tr>
		</tbody>
	</table>
	
	Note that the function call is the same as the id of the table body:
	TableSort('(id of table body)',column number (0 is first),'method of sort')
	method of sort is as follows:
	a - compare alphabetically
	ai - compare alphabetically ignoreing case
	d - sort by date (date must be a valid date)
	n - sort numerically
	
	*/
	
	var currentCol = 0
	var previousCol = -1
	
	function CompareAlpha(a, b) {
		if (a[currentCol] < b[currentCol]) { return -1; }
		if (a[currentCol] > b[currentCol]) { return 1; }
		return 0;
	}
	
	function CompareAlphaIgnore(a, b) {
		strA = a[currentCol].toLowerCase();
		strB = b[currentCol].toLowerCase();
		if (strA < strB) { return -1; }
		else {
			if (strA > strB) { return 1; }
			else { return 0; }
		}
	}
	
	/* to allow for columns which start with links...we don't want to match
		the URLs since quite often they won't match the labels.
	*/
	function CompareAlphaIgnoreTags(a, b) {
		strA = a[currentCol].toLowerCase();
		strB = b[currentCol].toLowerCase();
		tags = "/<([^>]*)>/ig";
		
		strA = strA.replace(/<([^>]*)>/ig,"");
		strB = strB.replace(/<([^>]*)>/ig,"");
		
		if ( strA < strB ){ return -1; }
		else if ( strA > strB ){ return 1; }
		else { return 0; }
	}
	
	function CompareDate(a, b) {
		// this one works with date formats conforming to Javascript specifications, e.g. m/d/yyyy
		datA = new Date(a[currentCol]);
		datB = new Date(b[currentCol]);
		if (datA < datB) { return -1; }
		else {
			if (datA > datB) { return 1; }
			else { return 0; }
		}
	}
	
	function CompareNumeric(a, b) {
		//window.alert ("CompareNumeric");
		numA = a[currentCol]
		numB = b[currentCol]
		if (isNaN(numA)) { return 0;}
		else {
			if (isNaN(numB)) { return 0; }
			else { return numA - numB; }
		}
	}
	
	function TableSort(myTable, myCol, myType) {
	
		// Create a two-dimensional array and fill it with the table's content
		var mySource = document.getElementById(myTable);
		var myRows = mySource.rows.length;
		var myCols = mySource.rows[0].cells.length;
		currentCol = myCol
		myArray = new Array(myRows)
		for (i=0; i < myRows; i++) { // row 0 is the table head
			myArray[i] = new Array(myCols)
			for (j=0; j < myCols; j++) {
				myArray[i][j] = document.getElementById(myTable).rows[i].cells[j].innerHTML;
			}
		}
	
		if (myCol == previousCol) {
			myArray.reverse(); // clicked the same column as previously - reverse the sort
		}
		else { // clicked on a new column - sort as indicated
			switch (myType) {
				case "a":
					myArray.sort(CompareAlpha);
					break;
				case "ai":
					myArray.sort(CompareAlphaIgnore);
					break;
				case "ait":
					myArray.sort(CompareAlphaIgnoreTags);
					break;
				case "d":
					myArray.sort(CompareDate);
					break;
				case "n":
					myArray.sort(CompareNumeric);
					break;
				default:
					myArray.sort()
			}
		}
		// Re-write the table contents
	for (i=0; i < myRows; i++) {
		for (j=0; j < myCols; j++) {
			mySource.rows[i].cells[j].innerHTML = myArray[i][j];
		}
	}
		previousCol = myCol; // remember the current sort column for the next pass
		// return 0;
	}
	
	/*
	-------------------------------------------------------------------------------
									End Table sort code
	-------------------------------------------------------------------------------	
	*/
	
	// function to pop media player window
	
	function popMedia (MovieName) {
		if (MovieName == "") {
			alert ("Invalid URL - Movie Name must be specified.");
		} else {
			var URL = "/media.jsp?movie=" + MovieName;
			var win = window.open(URL, "Media", "width=590,height=346,top=10,left=10");
		}
	
	
	}

	/* Creating a "Back to Top" link if content is greater than 500px */
	/* To be called in the window.onload event */

	function backtotop() {
		var content = document.getElementById("content");
		var btt = document.getElementById("backtotop");

		if (content.offsetHeight>500){
			btt.innerHTML = "<a href='#secondarynav' class='back2top'>back to top</a>\n";
			btt.style.display = "block";
		}
	}