﻿function resetControl(item) {
    item.style.background = 'white';
}

//Trim string prototype
String.prototype.trim = function() { 
    return this.replace(/^\s+|\s+$/g, ""); 
};

//Error handling
function throwError(obj,msg) {
    alert(msg);
    obj.focus();
    obj.select();
    return false;
}

//homepage form
var focusBlurZip = function() {
    this.value=(this.value=="Enter Zip") ? "" : (this.value=="") ? "Enter Zip" : this.value;
};

function locationSearch() {
    var zip = document.forms[0].zip;
    var radius = document.forms[0].radius;
    if ((zip.value.trim()=="") || (zip.value.trim()=="Enter Zip")) return throwError(zip,"Please enter a valid zip code.");
}

// master page rollovers
function SimpleSwap(el,over){ 
	if (over) {
		if (el.src.indexOf("Off.gif") > -1) {
			el.src=el.src.split("Off.gif").join("OffHover.gif"); 
		} else {
			el.src=el.src.split("On.gif").join("OnHover.gif"); 
		}
	} else {		
		if (el.src.indexOf("OffHover.gif") > -1) {
			el.src=el.src.split("OffHover.gif").join("Off.gif"); 
		} else {
			el.src=el.src.split("OnHover.gif").join("On.gif"); 
		}
	}
} 

function SimpleSwapSetup(){

	var index = 0;

	for (var i=0;i<hotButtons.length;i++){ 
	
		
		// preload images 
		if (document.images[hotButtons[i]]==undefined) continue;
		document.images[hotButtons[i]].oversrc_img = new Image(); 
		document.images[hotButtons[i]].oversrc_img.src=document.images[hotButtons[i]].src.split("On.gif").join("OnHover.gif"); 
		
		document.images[hotButtons[i]].oversrchover_img = new Image(); 
		document.images[hotButtons[i]].oversrchover_img.src=document.images[hotButtons[i]].src.split("Off.gif").join("OffHover.gif"); 
		
		//MPS 1/29/2007
		//one-off to handle the last item in the 'About Sealy' menu 
		index = 0;
		index = document.images[hotButtons[i]].src.indexOf('globalNav_02On');
		
		if(index > 0)
		{
			document.images[hotButtons[7]].src= '../Assets_Global/slice-images/globalNav_Off_ALT_03.gif'
			//document.images[hotButtons[7]].oversrchover_img.src=document.images[hotButtons[7]].src.split("Off.gif").join("Off_ALT_03.gif"); 
		}
		//end MPS edit
		
		//MOS 2/5/2007
		//one-off to handle multiple button highlight for 'Shop Easily' menu
		
		index = 0;
		index = document.images[hotButtons[i]].src.indexOf('ShopEasilyOn');
		
		if(index > 0)
		{
			document.images[hotButtons[15]].src= '../Assets_Global/slice-images/globalNav_01On.gif'
			document.images[hotButtons[8]].src= '../Assets_Global/slice-images/globalNav_Off_Alt_02.gif'
		}
		
		//End MPS edit
		
		// set event handlers 
		document.images[hotButtons[i]].onmouseover = new Function("SimpleSwap(this,true);"); 
		document.images[hotButtons[i]].onmouseout = new Function("SimpleSwap(this);"); 
	} 
} 
var PreSimpleSwapOnload =(window.onload)? window.onload : function(){}; 
window.onload = function(){
    //Put all onload stuff here
    PreSimpleSwapOnload(); 
    SimpleSwapSetup();
    if (document.forms[0].zip) {
        document.forms[0].zip.onfocus = focusBlurZip;
        document.forms[0].zip.onblur = focusBlurZip;
    }
} 

function sharePage(src, page) {
    document.getElementById("iFrameShare").src=src+"?page="+page;
    document.getElementById("share").style.display='block';
}

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}


function openWindow(name,width,height) {
// Opens a window using best practices-
// href should point to url
// onclick should call this function
// target attribute should match name 
    eval("var " +name+" = window.open('',name,'width='+width+',height='+height+',status=yes,toolbar=no,menubar=no,location=no')");
}

function openWhatsThis() {
    $("#divWhatsThis").dialog('open');
}
$(document).ready(
    function() {        
        $("#divWhatsThis").dialog({
            bgiframe: true,
            autoOpen: false,
            modal: true,
            position: "center"
        });
    });
