<!--
// FILE NAME:  GLOBAL_FUNCTIONS.JS
// AUTHORS:    FRANK GARAMY, ADAM LANGHALS - marchFIRST
// PURPOSE:    THIS FILE HOLDS COMMON CODE USED BY MOST PAGES IN THE SITE
// MODIFIED:   02/03/01 - Cameron Logan (Envisa) - included condition for
//             detection of NS6 and application of different style sheet than
//             NS 4.x
//Modified:	   5/29/03 - The window.name var was changed to addresses 
//			   issues with netscape compatibility
/******************************************************************************/
// VERSION OF SITE BUILD/WEB ROOT CODE AND FILES
var sitebuild_ver="n/a";

/******************************************************************************/
// Name the browser window so it can be targeted by popup pages
if (window == top) { window.name = "smithnoble"; }	// This replaces the above commented var

/******************************************************************************/
//  BROWSER DETECTION

/*
if(document.all) {
    IE = true;
} else {
    NS = true;
    if (parseInt(navigator.appVersion.substring(0,3)) > 4) {
        NS6 = true;
    }
}

if(navigator.platform.indexOf("Win32") != -1) {
    PC = true;
} else {
    MAC = true;
}
*/

/*******************************************************************************/
// IMAGE SWAP FUNCTIONS

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 MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments;

  document.MM_sr=new Array;

  for(i=0;i<(a.length-2);i+=3)
    if ((x=MM_findObj(a[i]))!=null){
        document.MM_sr[j++]=x;
        if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_nbGroup(event, grpName) { //v6.0
var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])?args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) { img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr) for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}


function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		nr_over = newImage("images/nr-over.gif");
		wb_over = newImage("images/wb-over.gif");
		rs_over = newImage("images/rs-over.gif");
		hc_over = newImage("images/hc-over.gif");
		andmore_over = newImage("images/andmore-over.gif");
		ph_over = newImage("images/ph-over.gif");
		ss_over = newImage("images/ss-over.gif");
		tt_over = newImage("images/tt-over.gif");
		rugs_over = newImage("images/rugs-over.gif");
		basic_over = newImage("images/basic-over.gif");
		preloadFlag = true;
	}
}

/******************************************************************************/
// This code creates a centered pop-up window.
function launchWindow(w,h,windowName,source,scrollbarsYN)
{
    var xobj = null;

    var chasm = screen.availWidth;
    var mount = screen.availHeight;

    xobj = window.open(source,windowName,'width=' + w + ',height=' + h + ',left=' + ((chasm - w - 10) * .5) + ',top=' + ((mount - h - 30) * .5) + ',scrollbars=' + scrollbarsYN + ',resizable=yes,dependent=yes');
    xobj.focus();
}

/******************************************************************************/
// This code creates a centered live chat pop-up window.
function launchChatWindow(windowName,source)
{
    var xobj = null;

    xobj = launchWindow(486,220,windowName,source,'no');
}

/******************************************************************************/
// This code creates a centered swatch sized pop-up window.

function launchSwatchZoom(windowName,source)
{
    var xobj = null;

    xobj = launchWindow(394,470,windowName,source,'no');
}

/******************************************************************************/
// This code creates a centered price chart sized pop-up window.

function launchPriceChart(windowName,source)
{
    var xobj = null;

    xobj = launchWindow(585,490,windowName,source,'yes');
}

/******************************************************************************/
// This code creates a large, scrollable pop-up window.

function launchLargePopUp(windowName,source)
{

    var xobj = null;

    xobj = launchWindow(500,450,windowName,source,'yes');
}

/******************************************************************************/
// This code creates a very large, scrollable pop-up window in which to
// display the measure or installation instruction pages.

function launchInstructions(windowName,source)
{

    var xobj = null;

    xobj = launchWindow(725,500,windowName,source,'yes');
}

/******************************************************************************/
// Creates a pop-up window for the Promotional Ad.

function launchPromo(w,h,windowName,source,scrollbarsYN,posX,posY)
{
    var xobj = null;

    xobj = window.open(source,windowName,'width=' + w + ',height=' + h + ',left=' + posX + ',top=' + posY + ',scrollbars=' + scrollbarsYN + ',resizable=no,dependent=yes');
}

/******************************************************************************/
// This code creates small pop-up window.

function launchSmallPopUp(windowName,source)
{
    var xobj = null;

    xobj = launchWindow(400,200,windowName,source,'no');
}

/******************************************************************************/
// This is for displaying confirmation cancel popup
function confirmCancel(message, target)
{
    if (confirm(message))
    {
        // Must ensure cross-browser functionality.
        window.location.href = target;
    }
    else
    {
        // Do nothing and end function
        return;
    }
}

/******************************************************************************/
// This is for displaying confirmation cancel popup
function confirmCancelSubmit(formname, message, target)
{
    var form;
    form = eval('document.' + formname);

    //alert(form + '\n' + message + '\n' + target);

    if (message.length == 0)
        confirmMessage = true;
    else
        confirmMessage = confirm(message);

    if (confirmMessage)
    {
        // Must ensure cross-browser functionality.
        form.action = target;
        form.submit();
    }
    else
    {
        // Do nothing and end function
        return;
    }
}


/*******************************************************************************/
// This function will populate a selection box with data from an array
// 01/18/01 - Modified to use apostrophes as the part of the string that gets
//            evaluated by "eval" so that double quote charaters in the entries
//            would be fine.

function populateSelect(form, select, array, spacerLine)
{
    // modify form object to be correct based on document object.
/*  
	if (IE)
    {
        form = eval("document.all." + form);
    }
    else
    {
        form = eval("document." + form);
    }

*/
    // first clear out old values
    var arrayLength = (array.length / 2);
    while (arrayLength < select.options.length)
    {
        select.options[(select.options.length - 1)] = null;
    }

    // then set the first value to be the default selected
    var string = "'" + escapeApostrophes(array[0]) + "','" + escapeApostrophes(array[1]) + "',true,true";
    eval('select.options[0] = new Option(' + string + ')');

    // populate select with array data
    var i=2;
    while (i < array.length)
    {
        var string = "'" + escapeApostrophes(array[i]) + "','" + escapeApostrophes(array[i+1]) + "'";
        eval("select.options[i/2] = new Option(" + string + ")");
        i = i + 2;
    }
    eval("select.options[i/2] = new Option('" + spacerLine + "','noselection')");
}

/*******************************************************************************/
// This function will populate a selection box with data from an array

function populateSecondarySelect(form, select1, select2, spacerLine)
{
    // modify form object to be correct based on document object.
 /*
    if (IE)
    {
        form = eval("document.all." + form);
        select1 = eval(form + '.' + select1);
    }
    else
    {
      form = eval("document." + form);
    }
*/

    if (select1.options[select1.selectedIndex].value != "noselection")
    {
        var array = eval(select1.options[select1.selectedIndex].value);
        populateSelect(form, select2, array, spacerLine);
    }
}

/*******************************************************************************/
// This function will populate a selection box with data from an array

function buildSelect(form, select1, select2, type, optionsArray, spacerLine)
{
    if (type == 'single')
    {
        var html = '';

        html +='<select id="' + form + '" name="' + select1 + '">';

        var x = 0;
        while (x < optionsArray.length)
        {
            html += '<option value="' + optionsArray[x] + '">';
            x = x + 1;
            html += optionsArray[x] + '</option>';
            x = x + 1;
        }

        html += '<option value="noselection">' + spacerLine + '</option>';
        html += '</select>';
        document.write (html);
    }

    if (type == 'double')
    {
        var html = '';
        var nMaxArrayLength = 0;

        buildCatSelect(form, select1, select2, optionsArray, spacerLine);

        //html += buildCatSelect();

        html += '<br><img src="/smith_noble/images/spacer.gif" width="1" height="2" border="0"><br>';

        html += '<select name="' + select2 + '">';
        var subCatArray = eval(optionsArray[3]);
        html += "<option value=\"" + subCatArray[1] + "\">" + subCatArray[0] + "</option>";

/*
        if (NS)
        {
            var i=2;
            while (i < optionsArray.length)
            {
                var selectedArray = eval(optionsArray[i + 1]);
                if ((selectedArray.length > (nMaxArrayLength * 2)) && (selectedArray.length > 0))
                {
                    nMaxArrayLength = (selectedArray.length / 2)
                }
            i = i + 2;
            }

            for (var i=0; i < nMaxArrayLength; i++)
            {
                html += '<option value="noselection"> </option>';
            }
        }
*/
        html += '<option value="noselection">' + spacerLine + '</option>';
        html += '</select>';
        document.write (html);
    }
}

/*******************************************************************************/
// This function will populate a selection box with data from an array

function buildCatSelect(form, select1, select2, catArray, spacerLine)
{
    var html;

    html = '<select name="' + select1 + '" onChange="populateSecondarySelect(';
    html += form + ',' + select1 + ',' + select2 + ',\'' + spacerLine + '\')">';
    html += '<option value="' + catArray[1] + '">' + catArray[0] + '</option>';

    var i=2;
    while (i < catArray.length)
    {
        html += '<option value="' + catArray[i + 1] + '">' + catArray[i] + '</option>';
        i = i + 2;
    }

    html += '<option value="noselection">' + spacerLine + '</option>';

    html += '</select>';

    document.write(html);

    //buildCatSelect = html;
}

/*******************************************************************************/
// This function will populate a selection box with data from an array

function submitDropDown(formname, elementname, message)
{
/*
    if (IE)
    {
        frmName = eval(formname);
        frmElement = eval('document.all.' + formname + '.' + elementname);
    }
    else
    {
        frmName = eval('document.' + formname);
        frmElement = eval('document.' + formname + '.' + elementname + '.options[document.' + formname + '.' +  elementname + '.selectedIndex]');
    }
*/
	// V3 change
	var frmName = document.getElementById(formname);
	var frmElement = document.getElementById(elementname);
	
    if (checkMenus(frmElement))
    {
        frmName.submit();
    }
    else
    {
        alert(message);
    }
}

/*******************************************************************************/
// This function will populate a selection box with data from an array

function submitDoubleDropDown(form, select1, select2, message1, message2)
{
	// V3 change
	var frmName = document.getElementById(formname);
	var frmElement1 = document.getElementById(select1);
	var frmElement2 = document.getElementById(select2);

/*
    if (IE)
    {
        frmName = eval(form);
        frmElement1 = eval('document.all.' + form + '.' + select1);
        frmElement2 = eval('document.all.' + form + '.' + select2);
    }
    else
    {
        frmName = eval('document.' + form);
        frmElement1 = eval('document.' + form + '.' + select1 + '.options[document.' + form + '.' +  select1 + '.selectedIndex]');
        frmElement2 = eval('document.' + form + '.' + select2 + '.options[document.' + form + '.' +  select2 + '.selectedIndex]');
    }
*/
    if (checkMenus(frmElement1))
    {
        if (checkMenus(frmElement2))
        {
            frmName.submit();
        }
        else
        {
            alert(message2);
        }
    }
    else
    {
        alert(message1);
    }
}

/*******************************************************************************/
// This function will place backslashes in front of quotes within a given string

function encodeQuotes(inputString)
{
    if (inputString == "" || inputString == null)
    {
        return inputString;
    }
    else
    {
        var matchQuotes = /\"/g;
        return(inputString.replace(matchQuotes,'&quot;'));
    }
}
/*******************************************************************************/
// This function will place backslashes in front of quotes within a given string

function escapeApostrophes(inputString)
{
    if (inputString == "" || inputString == null)
    {
        return inputString;
    }
    else
    {
        var matchApostrophes = /\'/g;
        return(inputString.replace(matchApostrophes,"\\'"));
    }
}
/*******************************************************************************/
// This function will place backslashes in front of quotes within a given string

function encodeSpaces(inputString)
{
    if (inputString == "" || inputString == null)
    {
        return inputString;
    }
    else
    {
        var matchSpaces = /\s/g;
        return(inputString.replace(matchSpaces,'&nbsp;'));
    }
}
/*******************************************************************************/
// This function will place backslashes in front of quotes within a given string

function padSlashes(inputString)
{
    if (inputString == "" || inputString == null)
    {
        return inputString;
    }
    else
    {
        var matchSlashes = /\//g;
        return(inputString.replace(matchSlashes, ' / '));
    }
}
/*******************************************************************************/
function popSlideShow()
{
	var slideshowPopUp = window.open('slideshow.jsp','slideshow','width=527,height=462,scrollbars=no,resizable=yes');
}

/*******************************************************************************/
// [CDF 2006-06-19] Function used to display electronic version of catalog
function popCatalog(ecatLink)
{
	var slideshowPopUp = window.open(ecatLink,'eCatalog','width=740,height=460,scrollbars=no,resizable=yes');
}

/*******************************************************************************/
// [CDF 2006-06-07] Function used to by default to display benefits of My S+N account membership
function showMySNBenefits()
{
	launchWindow(725, 500, 'benefits', 'mysn_benefits_popup.jsp', 'yes');
}

/*******************************************************************************/
function showDesignCenter(prodID)
{
	var slideshowPopUp = window.open('designCenter.jsp?prodID='+prodID,'S+N Design Center','width=800,height=580,scrollbars=no,resizable=yes');
}

/*******************************************************************************/
var preloadFlag = false;
var showTimers = new Array(5);
var hideTimers = new Array(5);
var csIndex = 2;

function changeImages()
{
if (document.images && (preloadFlag)) {
        for (var i=0; i<changeImages.arguments.length; i+=2) {
            document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
        }
    }
}

/*******************************************************************************/
function startHideTimer(idx)
{
    var delayMsec = 200;

    switch (parseInt(idx)) {
        case 2:
            hideTimers[csIndex] = window.setTimeout("changeImages('csImage','/smith_noble/images/custserv.gif');csLayer.hide()", delayMsec);
            break;
        default:
            alert("DEBUG: Did not match any of the layer indexes!");
    }
}

/*******************************************************************************/
function startShowTimer(idx)
{
    var delayMsec = 500;

        switch (idx) {
            case 2:
                showTimers[csIndex] = window.setTimeout("csLayer.show()", delayMsec);
                break;
            default:
                alert("DEBUG: Did not match any of the layer indexes!");
        }
}


/*******************************************************************************/
function stopShowTimer(idx)
{
    window.clearTimeout(showTimers[idx]);
}

/*******************************************************************************/
function stopHideTimer(idx)
{
    window.clearTimeout(hideTimers[idx]);
}

/*******************************************************************************/
// ASK Jeeves code pop-up
function submitAJQuery()
{
	var Q = document.askJeeves.ajQuery.value;
	var ajRedirect = "http://www.smithandnoble.com/sn/ajRedirect.jsp?qString=" + Q;
	
	//var ajRedirect = "http://msuabv19.usi.net/sn/ajRedirect.jsp?qString=" + Q;
	//window.location = location

	launchWindow(800,400,'AskJeevesQuery',ajRedirect,'yes,menubar=yes,location=yes,personalbar=yes,toolbar=yes');
}

/*******************************************************************************/
function encodeUrlMore(s){
	// Replace % first as it defines all encoding
	if(s != null){
		s = s.replace(/\%/g, "%25");

		s = s.replace(/\$/g, "%24");
		s = s.replace(/&/g, "%26");
		s = s.replace(/\+/g, "QQ"); // special use since BV Request obj. won't allow "+" in any way, incl. encoded!
		s = s.replace(/\x2C/g, "%2C"); // comma
		s = s.replace(/\x2F/g, "%2F"); // fwd slash
		s = s.replace(/:/g, "%3A");
		s = s.replace(/\x3B/g, "%3B"); // semi-colon
		s = s.replace(/=/g, "%3D");
		s = s.replace(/\?/g, "%3F");
		s = s.replace(/@/g, "%40");

		// Other
		s = s.replace(/ /g, "%20");
		s = s.replace(/\x22/g, "%22"); // double quote
		s = s.replace(/\x27/g, "%27"); // single quote
		s = s.replace(/\x91/g, "%91"); // left curly single quote
		s = s.replace(/\x92/g, "%92"); // right curly single quote
		s = s.replace(/\x93/g, "%93"); // left curly double quote
		s = s.replace(/\x94/g, "%94"); // right curly double quote
		s = s.replace(/</g, "%3C");
		s = s.replace(/>/g, "%3E");
		s = s.replace(/#/g, "%23");
		s = s.replace(/\{/g, "%7B");
		s = s.replace(/\}/g, "%7D");
		s = s.replace(/\|/g, "%7C");
		s = s.replace(/\\/g, "%5C");
		s = s.replace(/\^/g, "%5E");
		s = s.replace(/~/g, "%7E");
		s = s.replace(/\[/g, "%5B");
		s = s.replace(/\]/g, "%5D");
		s = s.replace(/`/g, "%60");
	}
	return s;
}

/*******************************************************************************/
function decodeUrlMore(s){
	if(s != null){	
		s = s.replace(/\%24/g, "$");
		s = s.replace(/\%26/g, "&");
		s = s.replace(/QQ/g, "+");
		s = s.replace(/\%2C/g, ",");
		s = s.replace(/\%2F/g, "/");
		s = s.replace(/\%3A/g, ":");
		s = s.replace(/\%3B/g, ";");
		s = s.replace(/\%3D/g, "=");
		s = s.replace(/\%3F/g, "?");
		s = s.replace(/\%40/g, "@");

		// Other
		s = s.replace(/\%20/g, " ");
		s = s.replace(/\%22/g, String.fromCharCode(34)); // double quote
		s = s.replace(/\%27/g, String.fromCharCode(39)); // single quote
		s = s.replace(/\%91/g, String.fromCharCode(145)); 
		s = s.replace(/\%92/g, String.fromCharCode(146)); 
		s = s.replace(/\%93/g, String.fromCharCode(147)); 
		s = s.replace(/\%94/g, String.fromCharCode(148)); 
		s = s.replace(/\%3C/g, "<");
		s = s.replace(/\%3E/g, ">");
		s = s.replace(/\%23/g, "#");
		s = s.replace(/\%7B/g, "{");
		s = s.replace(/\%7D/g, "}");
		s = s.replace(/\%7C/g, "|");
		s = s.replace(/\%5C/g, String.fromCharCode(92)); // backslash
		s = s.replace(/\%5E/g, "^");
		s = s.replace(/\%7E/g, "~");
		s = s.replace(/\%5B/g, "[");
		s = s.replace(/\%5D/g, "]");
		s = s.replace(/\%60/g, String.fromCharCode(96)); // accent grave

		s = s.replace(/\%25/g, "%");
	}	
	return s;
}

/*******************************************************************************/
function encodeHTMLmore(s){
	// Replace & first as it is used in encoding
	if(s != null){	
		s = s.replace(/&/g, "&#038;");

		s = s.replace(/\%/g, "&#037;");	
		s = s.replace(/\x2F/g, "&#047;"); // fwd slash
		s = s.replace(/=/g, "&#061;");
		s = s.replace(/\?/g, "&#063;");
		s = s.replace(/@/g, "&#064;");

		// Other
		s = s.replace(/ /g, "&#032;");
		s = s.replace(/\x22/g, "&#034;"); // double quote
		s = s.replace(/</g, "&#060;");
		s = s.replace(/>/g, "&#062;");
		s = s.replace(/\\/g, "&#092;");
		s = s.replace(/`/g, "&#096;");
	}
	return s;
}

/*******************************************************************************/
function decodeHTMLmore(s){
	if(s != null){	
		s = s.replace(/&#037/g, "%");
		s = s.replace(/&#047/g, "/");
		s = s.replace(/&#061/g, "=");
		s = s.replace(/&#063/g, "?");
		s = s.replace(/&#064/g, "@");

		// Other
		s = s.replace(/&#032/g, " ");
		s = s.replace(/&#034/g, String.fromCharCode(34)); // double quote
		s = s.replace(/&#060/g, "<");
		s = s.replace(/&#062/g, ">");
		s = s.replace(/&#092/g, String.fromCharCode(92)); // backslash
		s = s.replace(/&#096/g, String.fromCharCode(96)); // accent grave

		s = s.replace(/&#038/g, "&");
		s = s.replace("&eacute;","é");
	}
	return s;
}

/*
  BROWSER DETECTION FOR SAFARI

 Browser Detection Javascript
 copyright 1 February 2003, by Stephen Chapman, Felgall Pty Ltd

 You have permission to copy and use this javascript provided that
 the content of the script is not changed in any way.
*/

function whichBrs() {
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("opera") != -1) return 'Opera';
if (agt.indexOf("staroffice") != -1) return 'Star Office';
if (agt.indexOf("beonex") != -1) return 'Beonex';
if (agt.indexOf("chimera") != -1) return 'Chimera';
if (agt.indexOf("netpositive") != -1) return 'NetPositive';
if (agt.indexOf("phoenix") != -1) return 'Phoenix';
if (agt.indexOf("firefox") != -1) return 'Firefox';
if (agt.indexOf("safari") != -1) return 'Safari';
if (agt.indexOf("skipstone") != -1) return 'SkipStone';
if (agt.indexOf("msie") != -1) return 'Internet Explorer';
if (agt.indexOf("netscape") != -1) return 'Netscape';
if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
if (agt.indexOf('\/') != -1) {
if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
return navigator.userAgent.substr(0,agt.indexOf('\/'));}
else return 'Netscape';} else if (agt.indexOf(' ') != -1)
return navigator.userAgent.substr(0,agt.indexOf(' '));
else return navigator.userAgent;
}

function eatCookies()	{
	var cookieNameValPairs = document.cookie.split(';');
 	for ( each_cookie in cookieNameValPairs ) 	{
		document.cookie=cookieNameValPairs[each_cookie].replace(/=.+/gi, "") + "=\"\"\; expires=Fri, 02-Jan-1970 00:00:00 GMT\; path=/;";
												}
	location.reload(true);						
						}


function isNumber(number){
	var regexp1 = /^(\d+)$/;
	var regexp2 = /[1-9]/; // has at least one non-zero value
    var isNum = false;
    if (regexp1.test(number) && regexp2.test(number))
		isNum = true;
	return isNum;
}

function checkZipForm(zipcode){

	var err = false;
	var msg = "";
	if ((zipcode == null) || (zipcode.length < 5)){
     
		err = true;
		msg += "Please enter a 5 digit zip code, then click 'Check' to see if Measure and Installation services are available in your area.";
    }
    else
    if (isNumber(zipcode) == false)
    {
		err = true;
        msg = "The zip code must be numeric."
    }
    

    if (err == true)
    {
		alert(msg);
		return false;
    }
    else return true;
}

// remove leading spaces^M
function stringLeftTrim(s)
{
    return (typeof(s) != "string") ? null : s.replace(/^ +/, "");
}

// remove trailing spaces
function stringRightTrim(s) 
{
    return (typeof(s) != "string") ? null : s.replace(/ +$/, "");
}

// remove leading and trailing spaces
function stringTrim(s) 
{
    return stringRightTrim(stringLeftTrim(s));
}



//-->
