/*
'****************************************************************************************
'**  Copyright Notice
'**  http://www.sagecomputerservices.com
'**
'**  Copyright 2007-2008 Sage Computer Services. All Rights Reserved.
'**
'**  This program is commercial proprietary software and may not be modified or distributed 
'**  either privately or commercially except under the terms of the License that accompanies 
'**  this software.
'**
'**  All copyright notices must remain intact in all scripts.
'**
'**  You may not redistribute, repackage, or sell the whole or any part of this program even
'**  if it is modified or reverse engineered in whole or in part without express
'**  permission from the author.
'**
'**  This program is distributed WITHOUT ANY WARRANTY; without even the implied warranty of
'**  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR ANY OTHER WARRANTIES WHETHER EXPRESSED OR IMPLIED.
'**
'**  Sage Computer Services
'**  http://www.sagecomputerservices.com
'**  sage@sagecomputerservices.com
'**
'****************************************************************************************     
*/      
var sHttpPrefix="http://";
var bTestSite=false;

var sHttpLocation=window.location.toString().toLowerCase();

// establish test vs live site (7cfe15a64745c93e = test account for sitelevel search)
if ((sHttpLocation.indexOf("minisage.com") > -1) || (sHttpLocation.indexOf("7cfe15a64745c93e") > -1)) 
{
	bTestSite=true;
}
// establish http vs https
if (sHttpLocation.indexOf("https") > -1)
{
	sHttpPrefix = "https://";
}

// set the correct domain based on the domain name the user entered the site with
var sLiveDomainPrefix="www.g2investmentgroup.com/";

// helper current page
var g_sCurrentPage = window.location.toString().toLowerCase();
var nPos = g_sCurrentPage.lastIndexOf("/");
if (nPos != -1)
{
	g_sCurrentPage = g_sCurrentPage.substr(nPos+1);
}

var nSubMenuAdditionalWidthMedium = 150;   	//mfindlay
var nSubMenuAdditionalWidthWide = 200;    	//mfindlay

var nMenuWidth=190;				// width of menus to appear. Set to zero to ignore
var sBaseSite="";
var sNonSSLBaseSite="";

// If test site, just use 1 base site
if (bTestSite) 
{
	sBaseSite = sHttpPrefix + "g2.minisage.com/";
	sNonSSLBaseSite = "http://" + "g2.minisage.com/";
}
else
{
	sNonSSLBaseSite = "http://" + sLiveDomainPrefix;
	
	// live site. If https mode, use safesecureweb address
	if (sHttpPrefix=="https://")
	{
		sBaseSite = sHttpPrefix + sLiveDomainPrefix;
	}
	else
	{
		// non ssl mode, use normal address
		sBaseSite = sHttpPrefix + sLiveDomainPrefix;
	}
} 
//********************************
// DisplayCopyrightYear
//********************************
function DisplayCopyrightYear()
{
	var mydate=new Date();
	var year=mydate.getFullYear();
	
	document.write(year);
}
//********************************
// DDtoDay
//********************************
function DDtoDay(inputDate)
{
  var dateString = new Array('','st','nd','rd','th','th','th','th','th','th','th','th','th','th','th','th','th','th','th','th','th','st','nd','rd','th','th','th','th','th','th','th','st');
  returnDate = '';
  tempDate = parseInt(inputDate);
  if (tempDate >= 1 && tempDate <= 31)
  {
	  returnDate = inputDate + dateString[tempDate];
	}
	return returnDate;
}
//********************************
// DisplayDate
//********************************
function DisplayDate()
{
	var mydate		= new Date();
	var year		= mydate.getFullYear();
	var month		= mydate.getMonth();
	var day			= mydate.getDate();
	var dayofweek	= mydate.getDay();
	
	var MonthArray = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	var DayOfWeekArray = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
	
	document.write(DayOfWeekArray[dayofweek] + ', ' + MonthArray[month] + ' ' + day.toString() + ', ' + year.toString());
}
//****************************************************
// randomNumber
//****************************************************
function randomNumber(limit){
  return (Math.floor(Math.random()*limit).toString());
}
//****************************************************
// ToNumeric
// converts a string to a number as long as the string is > "-999999"
//****************************************************
function ToNumeric(sString)
{
	if (sString.length<1) return 0;
	return Math.max(-99999,sString);
}
//*******************************
// IsValidEmail
//*******************************
function IsValidEmail(sEmail)
{
	return (sEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1);
}
//****************************************************
// IsMac
//****************************************************
function IsMac()
{
  if(navigator.appVersion.indexOf("Win") != -1)
  {
    return false;
  }
  else if(navigator.appVersion.indexOf("Mac") != -1)
  {
    return true;
  }
  else return false;
}
//****************************************************
// AreDatesInSequence
// determines if from date is < = to date
//****************************************************
function AreDatesInSequence(strFROM, strTO)
{
	var dtFrom = new Date(strFROM);
	var dtTo = new Date(strTO);
	
	if (dtFrom.getFullYear() < dtTo.getFullYear()) { return true; }
	
	if (dtFrom.getFullYear() == dtTo.getFullYear()) 
	{
		if (dtFrom.getMonth() < dtTo.getMonth()) { return true; }
	}
	
	if (dtFrom.getFullYear() == dtTo.getFullYear()) 
	{
		if (dtFrom.getMonth() == dtTo.getMonth()) 
		{
			if (dtFrom.getDate() <= dtTo.getDate()) { return true; } 
		}
	}
	
	return false;
}
//****************************************************
// ConvertHTML
// Converts the opening and closing HTML tags to parens
//****************************************************
function ConvertHTML(sInput)
{
	var sOutput = sInput;
    sOutput=sOutput.replace(/</g,"(");
    sOutput=sOutput.replace(/>/g,")");
	return sOutput;
}
//****************************************************
// CleanWordChars
//****************************************************
function CleanWordChars(inputString)
{
	//alert("entry to CleanWords");
	
	var returnString = inputString;
	
	var nLen = returnString.length;
	
	//alert("before: " + returnString);
	
	// clean special MSWord chars
	returnString = returnString.replace(/…/g,"...");  			// replace elipses with ascii ...
	returnString = returnString.replace(/’/g,"'");  			// replace apos with ascii apos
	returnString = returnString.replace(/”/g,"\"");  			// replace ending quotes with ascii ending quotes
	returnString = returnString.replace(/“/g,"\"");  			// replace beginning quotes with ascii ending quotes
	returnString = returnString.replace(/½/g,"1/2");  			// replace ½ with 1/2
	
	//alert("after: " + returnString);

	var c='';
	
	for (var x=0; x<nLen; x++)
	{
		c = returnString.charAt(x);
		
		// standard alpha chars
		if ((c >='a') && (c <='z')) continue;
		if ((c >='A') && (c <='Z')) continue;
		if ((c >='0') && (c <='9')) continue;
		
		// standard keyboard special chars
		switch(c)
		{
			// Allow the < and the > since the calling code takes care of editing it.
			case '>' : continue;	
			case '<' : continue;	
			
			case ' ' : continue;	
			case '.' : continue;	
			case ',' : continue;	
			case '?' : continue;	
			case '!' : continue;	
			case '"' : continue;	
			case '-' : continue;	
			case '@' : continue;	
			case '#' : continue;	
			case '$' : continue;	
			case '%' : continue;	
			case '^' : continue;	
			case '*' : continue;	
			case '&' : continue;	
			case '(' : continue;	
			case ')' : continue;	
			case '_' : continue;	
			case '+' : continue;	
			case '=' : continue;	
			case '[' : continue;	
			case ']' : continue;	
			case '{' : continue;	
			case '}' : continue;	
			case '&' : continue;	
			case '\'' : continue;	
			case ';' : continue;	
			case ':' : continue;	
			case '`' : continue;	
			case '~' : continue;	
			case '/' : continue;	
			case '|' : continue;	
			case '\\' : continue;	
			case '\t' : continue;	
			case '\r' : continue;	
			case '\n' : continue;	
			case '\r\n' : continue;	
		}
		
		//alert("Replacing char: [" + c + "] with space");
		
		// drop this unknown char
		//returnString[x]=' '; 
		returnString = returnString.replace(c," ");  
	}
	
	return returnString;
}

//***********************************************
// FormatCurrency
//***********************************************
function FormatCurrency(num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	
	if (isNaN(num))
	{
		num = "0";
	}
	
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	
	if (cents<10)
	{
		cents = "0" + cents;
	}
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	{
		num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
	}
	
	//return (((sign)?'':'-') + '$' + num + '.' + cents);
	return (((sign)?'':'-') + num + '.' + cents);
}
//****************************************************
// StripStringOfVulnerableChars 
// Removes vulnerable chars from a string
//****************************************************
function StripStringOfVulnerableChars(sString,bStripSpaces)
{
	
	var s = sString.replace(/'/g,"");  	// remove tics from string
	s = s.replace(/;/g,"");  			// remove semicolons from string
	s = s.replace(/\(/g,"");  			// remove lefts paren from string
	s = s.replace(/\)/g,"");  			// remove right parens from string
	s = s.replace(/\*/g,"");  			// remove asterisk from string
	s = s.replace(/"/g,"");  			// remove double quotes from string
	s = s.replace(/--/g,"");  			// remove double dash from string
	s = s.replace(/=/g,"");  			// remove equal signs from string

	//s = s.replace(/#/g,"");  			// remove pound signs from string
	if (bStripSpaces)
	{
		s = s.replace(/ /g,"");  		// remove spaces from string
	}
	return s;
}
//****************************************************
// StripStringOfCommas 
// Removes commas from a string
//****************************************************
function StripStringOfCommas(sString)
{
	
	var s = sString.replace(/,/g,"");  	// remove commas from string

	return s;
}

//****************************************************
// JSTrim
// Removes LEADING and TRAILING spaces ONLY from a string
// optional 3rd and 4th parms: BOOL BOOL
// 3rd parm: BOOL  - strip vulnerable chars
// 4th parm: BOOL  - strip internal spaces as part of strip
//****************************************************
function JSTrim (inputString, removeChar) 
{
	// Clean MSWord chars et al.
	//var returnString = CleanWordChars(inputString);
	// no need to clean word chars in UTF-8 mode
	var returnString = inputString;	
	if (removeChar.length)
	{
	  while(''+returnString.charAt(0)==removeChar)
		{
		  returnString=returnString.substring(1,returnString.length);
		}
		while(''+returnString.charAt(returnString.length-1)==removeChar)
	  {
	    returnString=returnString.substring(0,returnString.length-1);
	  }
	}
	var s = ConvertHTML(returnString);
	
	// check to see if additional parms were passed to tell us to 
	// strip out dangerous security risk chars
	var bCheckForVulnerabilities = (JSTrim.arguments.length > 2) ? JSTrim.arguments[2] : false;
	var bStripSpacesFromString = (JSTrim.arguments.length > 3) ? JSTrim.arguments[3] : false;
	
	// if requested, strip also for vulnerabilities
	if (bCheckForVulnerabilities) 
	{
		s = StripStringOfVulnerableChars(s,bStripSpacesFromString);
	}
	else
	{
		// just clean of all spaces?
		if (bStripSpacesFromString)
		{
			s = s.replace(/ /g,"");  		// remove spaces from string
		}
	}
	
	return s;
}
//****************************************************
// JSTrimSpace
// Removes leading and trailing spaces from a string
// optional 2nd and 3rd parms: BOOL BOOL
// 2nd parm: BOOL  - strip vulnerable chars
// 3rd parm: BOOL  - strip internal spaces as part of strip
//****************************************************
function JSTrimSpace(inputString)
{
	// strip vulnerable chars?
	var bCheckForVulnerabilities = (JSTrimSpace.arguments.length > 1) ? JSTrimSpace.arguments[1] : false;
	var bStripSpacesFromString = (JSTrimSpace.arguments.length > 2) ? JSTrimSpace.arguments[2] : false;

	return JSTrim(inputString,' ',bCheckForVulnerabilities,bStripSpacesFromString);
}
//*******************************
// IsValidCCNumber
//*******************************
function IsValidCCNumber(s) {
	// remove non-numerics
	var v = "0123456789";
	var w = "";
	for (i=0; i < s.length; i++) {
	x = s.charAt(i);
	if (v.indexOf(x,0) != -1)
	w += x;
	}
	// validate number
	j = w.length / 2;
	if (j < 6.5 || j > 8 || j == 7) return false;
	k = Math.floor(j);
	m = Math.ceil(j) - k;
	c = 0;
	for (i=0; i<k; i++) {
	a = w.charAt(i*2+m) * 2;
	c += a > 9 ? Math.floor(a/10 + a%10) : a;
	}
	for (i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;
	return (c%10 == 0);
}
//*******************************
// CleanCCNumber
//*******************************
function CleanCCNumber(s)
{
	// remove non-numerics
	var v = "0123456789";
	var w = "";
	for (i=0; i < s.length; i++) 
	{
		x = s.charAt(i);
		if (v.indexOf(x,0) != -1)
		w += x;
	}
	
	return w;
}
//****************************************************
// CCTrim (credit card trim)
// Removes dashes from a string
// Removes spaces from anywhere within the string
//****************************************************
function CCTrim(sString)
{
	var s = sString.replace(/-/g,"");  // remove dashes from string
	s = s.replace(/ /g,"");  // remove spaces from string
	return s;
}

//****************************************************
// IsPositiveInt
// Returns true if a string >= zero.
//****************************************************
function IsPositiveInt(sString)
{
	if (sString.length < 1) return false;
	
	for (var x=0; x<sString.length; x++)
	{
		// Make sure the tax rates are numeric only, with the exception of the '.'
		if (sString.charAt(x) < "0" || 
			sString.charAt(x) > "9")
		{
			return false;
		}
	}
	return true;
}
//****************************************************
// ValidateNumericInput
//****************************************************
function ValidateNumericInput(nKeyCode)
{
	// allow 0 through 9 on regular keyboard
	if ((nKeyCode >= 48) && (nKeyCode <= 57)) return true;
	// allow 0 through 9 on keypad
	if ((nKeyCode >= 96) && (nKeyCode <= 105)) return true;
	
	// allow backspace
	if (nKeyCode == 8) return true;
	
	// allow delete key
	if (nKeyCode == 46) return true;
	
	// allow tab key
	if (nKeyCode == 9) return true;
	// allow shift key
	//if (nKeyCode == 16) return true;
	// allow decimal point (period)
	//if (nKeyCode == 190) return true;
	//alert(nKeyCode);
	return false;
}
var popUpLinkWin=0;
//****************************************************
// popUpLinkWindow
// optional arguments: width,height,left,top
//****************************************************
function popUpLinkWindow(url,target)
{
  	if(popUpLinkWin)
  	{
    	if(!popUpLinkWin.closed) popUpLinkWin.close();
  	}
	
	var nWidth=600;
	var nHeight=400;
	var nLeft=10;
	var nTop=10;
	
	if (popUpLinkWindow.arguments.length > 2)
	{
		nWidth = parseInt(popUpLinkWindow.arguments[2])
	}
	if (popUpLinkWindow.arguments.length > 3)
	{
		nHeight = parseInt(popUpLinkWindow.arguments[3])
	}
	if (popUpLinkWindow.arguments.length > 4)
	{
		nLeft = parseInt(popUpLinkWindow.arguments[4])
	}
	if (popUpLinkWindow.arguments.length > 5)
	{
		nTop = parseInt(popUpLinkWindow.arguments[5])
	}
	
	popUpLinkWin = open(url, target, 'height=' + nHeight + ',width=' + nWidth + ',left=' + nLeft + ',top=' + nTop + ',toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,location=yes,directories=yes,status=yes');
	popUpLinkWin.focus();
}
//****************************************************
// IsOpera
//****************************************************
function IsOpera()
{
	var sString = navigator.userAgent.toLowerCase();
	if(sString.indexOf("opera") != -1)
	{
		return true;
	}
	return false;
}

//**********************************************************
// Browser Detect  v2.1.6
// documentation: http://www.dithered.com/javascript/browser_detect/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)
//**********************************************************
function BrowserDetect() {
   var ua = navigator.userAgent.toLowerCase(); 

   // browser engine name
   this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

   // browser name
   this.isFirefox     = (ua.indexOf('firefox') != -1);     //mjf
   this.isChrome     = (ua.indexOf('chrome') != -1);     //mjf
   this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
   this.isSafari      = (ua.indexOf('safari') != - 1);
   this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
   this.isOpera       = (ua.indexOf('opera') != -1); 
   this.isIcab        = (ua.indexOf('icab') != -1); 
   this.isAol         = (ua.indexOf('aol') != -1); 
   this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
   this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isFirebird    = (ua.indexOf('firebird/') != -1);
   this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
   
   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
   
   // rendering engine versions
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
   this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
   this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
   
   // browser version
   this.versionMinor = parseFloat(navigator.appVersion); 
   
   // correct version number
   if (this.isGecko && !this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
   }
   else if (this.isOmniweb) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
   }
   else if (this.isOpera) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
   }
   else if (this.isIcab) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
   }
   
   this.versionMajor = parseInt(this.versionMinor); 
   
   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin    = (ua.indexOf('win') != -1);
   this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac    = (ua.indexOf('mac') != -1);
   this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux  = (ua.indexOf('linux') != -1);
   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   
   this.isIE4xMac = (this.isIE4x && this.isMac);
}
var browser = new BrowserDetect();

//---------------------------------------
// GetCSSFilename
// Returns the css file to use based on the user's browser
//---------------------------------------
function GetCSSFilename()
{
	//dim sBrowser
	var sPlatform = (browser.isMac) ? "mac_" : "pc_";
	var sFile="";
	var sBrowser="";
	
	// Determine running IE
	if (browser.isIE)
	{
		sBrowser = "ie";
	}
	
	// Determine running Safari
	if (browser.isSafari)
	{
		sBrowser = "safari";
	}
	
	// Determine running Chrome
	if (browser.isChrome)
	{
		sBrowser = "chrome";
	}
	
	// Determine running Opera
	if (browser.isFirefox)
	{
		sBrowser = "firefox";
	}
	
	// Determine running Opera
	if (browser.isOpera)
	{
		sBrowser = "opera";
	}
	
	// determine if user is on a Netscape 4.xx 
	if (browser.isNS4x)
	{
		sBrowser = "ns4";
	}
	
	// determine if user is on a Netscape 6.xx 
	if (browser.isNS6x)
	{
		sBrowser = "ns6";
	}
	
	// determine if user is on a Netscape 7.xx 
	if (browser.isNS7up)
	{
		sBrowser = "ns7";
	}
	
	// if no browser yet determined, attempt a default
	if (sBrowser=="")
	{
		if (browser.isNS)
		{
			sBrowser="ns7";
		}
	}

	// set the filename
	sFile = sPlatform + sBrowser + ".css";
	
	// build appropriate stylesheet link
	//alert(sBaseSite + "css/" + sFile);
	//alert("<link href=\"" + sBaseSite + "css/" + sFile + "\" rel=\"stylesheet\" type=\"text/css\" />");
	document.writeln("<link href=\"" + sBaseSite + "css/" + sFile + "\" rel=\"stylesheet\" type=\"text/css\" />");
	
	// if test site, set noindex nofollow
	if (bTestSite)
	{
		document.writeln("<meta name='robots' content='noindex,nofollow' />");
	}
}
//**********************************************
// isNumberFloat
//**********************************************
function isNumberFloat(inputString)
{
  return (!isNaN(parseFloat(inputString))) ? true : false;
}
//**********************************************
// isNumberInt
//**********************************************
function isNumberInt(inputString)
{
  return (!isNaN(parseInt(inputString))) ? true : false;
}

//**********************************************
// GetUserLanguage
//**********************************************
function GetUserLanguage()
{
	var sUserLang = '?';
	
	if ( window.navigator.language )
	{
		sUserLang = window.navigator.language.toLowerCase();
	}
	else 
	{
		if ( window.navigator.userLanguage )
		{
			sUserLang = window.navigator.userLanguage.toLowerCase();
		}
	}
		
	// truncate to just the first 2 chars
	if (sUserLang.length > 2)
	{
		sUserLang = sUserLang.substr(0,2);
	}
	
}
//**********************************************
// InitLeftNav
//**********************************************
function InitLeftNav()
{
	var sCurrentPage = window.location.toString().toLowerCase();
	var obj=null;
	
	//================================================
	// Products
	//================================================
	if (sCurrentPage.indexOf('/products/') > -1)
	{
		obj = $("td#topnavlink_products");
		if (obj.length)
		{
			//obj.css({"color":"#e38125"});
			obj.attr("class","topnavitem_selected");
		}
		//MM_findObj('topnavlink_pa').onmouseover='';
		//MM_findObj('topnavlink_pa').onmouseout='';
		
		// Furniture
		if (sCurrentPage.indexOf('/products/products_furniture') > -1)
		{
			obj = $("td#prodfurniture");
			if (obj.length)
			{
				//obj.css({"color":"#e38125"});
				obj.attr("class","leftcolitem_selected");
				obj.unbind();
			}
		}
		// Bath & Bedding
		if (sCurrentPage.indexOf('/products/products_bathandbed') > -1)
		{
			obj = $("td#prodbath");
			if (obj.length)
			{
				//obj.css({"color":"#e38125"});
				obj.attr("class","leftcolitem_selected");
				obj.unbind();
			}
		}
		// Accessories
		if (sCurrentPage.indexOf('/products/products_accessories') > -1)
		{
			obj = $("td#prodaccessories");
			if (obj.length)
			{
				//obj.css({"color":"#e38125"});
				obj.attr("class","leftcolitem_selected");
				obj.unbind();
			}
		}
		// Area Rugs
		if (sCurrentPage.indexOf('/products/products_arearugs') > -1)
		{
			obj = $("td#prodarearugs");
			if (obj.length)
			{
				//obj.css({"color":"#e38125"});
				obj.attr("class","leftcolitem_selected");
				obj.unbind();
			}
		}
		// Lighting
		if (sCurrentPage.indexOf('/products/products_lighting') > -1)
		{
			obj = $("td#prodlighting");
			if (obj.length)
			{
				//obj.css({"color":"#e38125"});
				obj.attr("class","leftcolitem_selected");
				obj.unbind();
			}
		}
		// Tile & Stone
		if (sCurrentPage.indexOf('/products/products_tileandstone') > -1)
		{
			obj = $("td#prodtilestone");
			if (obj.length)
			{
				//obj.css({"color":"#e38125"});
				obj.attr("class","leftcolitem_selected");
				obj.unbind();
			}
		}
		// Fine Art
		if (sCurrentPage.indexOf('/products/products_fineart') > -1)
		{
			obj = $("td#prodfineart");
			if (obj.length)
			{
				//obj.css({"color":"#e38125"});
				obj.attr("class","leftcolitem_selected");
				obj.unbind();
			}
		}
		// Flooring
		if (sCurrentPage.indexOf('/products/products_flooring') > -1)
		{
			obj = $("td#prodflooring");
			if (obj.length)
			{
				//obj.css({"color":"#e38125"});
				obj.attr("class","leftcolitem_selected");
				obj.unbind();
			}
		}
		// Cabinetry
		if (sCurrentPage.indexOf('/products/products_cabinetry') > -1)
		{
			obj = $("td#prodcabinetry");
			if (obj.length)
			{
				//obj.css({"color":"#e38125"});
				obj.attr("class","leftcolitem_selected");
				obj.unbind();
			}
		}
		// Plumbing
		if (sCurrentPage.indexOf('/products/products_plumbing') > -1)
		{
			obj = $("td#prodplumbing");
			if (obj.length)
			{
				//obj.css({"color":"#e38125"});
				obj.attr("class","leftcolitem_selected");
				obj.unbind();
			}
		}
		// Window Coverings
		if (sCurrentPage.indexOf('/products/products_windowcoverings') > -1)
		{
			obj = $("td#prodwindows");
			if (obj.length)
			{
				//obj.css({"color":"#e38125"});
				obj.attr("class","leftcolitem_selected");
				obj.unbind();
			}
		}

	}
	
	//================================================
	// Services
	//================================================
	if (sCurrentPage.indexOf('/services/') > -1)
	{
		obj = $("td#topnavlink_services");
		if (obj.length)
		{
			//obj.css({"color":"#e38125"});
			//obj.attr("class","topnavitem_selected");
		}
		//MM_findObj('topnavlink_res').onmouseover='';
		//MM_findObj('topnavlink_res').onmouseout='';
	}
	
	//================================================
	// Portfolio
	//================================================
	if (sCurrentPage.indexOf('/portfolio/') > -1)
	{
		obj = $("td#topnavlink_portfolio");
		if (obj.length)
		{
			//obj.css({"color":"#e38125"});
			obj.attr("class","topnavitem_selected");
		}
		
		// custom homes
		if (sCurrentPage.indexOf('/portfolio/portfolio_home_') > -1)
		{
			obj = $("td#customhomes");
			if (obj.length)
			{
				//obj.css({"color":"#e38125"});
				obj.attr("class","leftcolitem_selected");
				obj.unbind();
			}
		}
		// custom remodels
		if (sCurrentPage.indexOf('/portfolio/portfolio_remod_') > -1)
		{
			obj = $("td#customremodels");
			if (obj.length)
			{
				//obj.css({"color":"#e38125"});
				obj.attr("class","leftcolitem_selected");
				obj.unbind();
			}
		}
		// interior design
		if (sCurrentPage.indexOf('/portfolio/portfolio_int_') > -1)
		{
			obj = $("td#interiordesigns");
			if (obj.length)
			{
				//obj.css({"color":"#e38125"});
				obj.attr("class","leftcolitem_selected");
				obj.unbind();
			}
		}
		//MM_findObj('topnavlink_about').onmouseover='';
		//MM_findObj('topnavlink_about').onmouseout='';
	}
	
	//==================================================
	// Designer
	//==================================================
	if (sCurrentPage.indexOf('/designer/') > -1)
	{
		obj = $("td#topnavlink_designer");
		if (obj.length)
		{
			//obj.css({"color":"#e38125"});
			//obj.attr("class","topnavitem_selected");
		}
		//MM_findObj('topnavlink_about').onmouseover='';
		//MM_findObj('topnavlink_about').onmouseout='';
	}
	//============================================
	// Sales & Events
	//============================================
	if (sCurrentPage.indexOf('/sales/') > -1)
	{
		obj = $("td#topnavlink_sales");
		if (obj.length)
		{
			//obj.css({"color":"#e38125"});
			obj.attr("class","topnavitem_selected");
		}
		
		// sales / promotions
		if (sCurrentPage.indexOf('/sales/salespromotions') > -1)
		{
			obj = $("td#salestd");
			if (obj.length)
			{
				//obj.css({"color":"#e38125"});
				obj.attr("class","leftcolitem_selected");
				obj.unbind();
			}
		}
		// events
		if (sCurrentPage.indexOf('/sales/events') > -1)
		{
			obj = $("td#eventstd");
			if (obj.length)
			{
				//obj.css({"color":"#e38125"});
				obj.attr("class","leftcolitem_selected");
				obj.unbind();
			}
		}
		// ads
		if (sCurrentPage.indexOf('/sales/ads') > -1)
		{
			obj = $("td#adstd");
			if (obj.length)
			{
				//obj.css({"color":"#e38125"});
				obj.attr("class","leftcolitem_selected");
				obj.unbind();
			}
		}
		// clearance
		if (sCurrentPage.indexOf('/sales/clearance') > -1)
		{
			obj = $("td#clearancetd");
			if (obj.length)
			{
				//obj.css({"color":"#e38125"});
				obj.attr("class","leftcolitem_selected");
				obj.unbind();
			}
		}
		//MM_findObj('topnavlink_about').onmouseover='';
		//MM_findObj('topnavlink_about').onmouseout='';
	}
	
	//============================================
	// About
	//============================================
	if (sCurrentPage.indexOf('/aboutus/') > -1)
	{
		obj = $("td#topnavlink_about");
		if (obj.length)
		{
			//obj.css({"color":"#e38125"});
			obj.attr("class","topnavitem_selected");
		}
		//MM_findObj('topnavlink_about').onmouseover='';
		//MM_findObj('topnavlink_about').onmouseout='';
	}
	
	//==============================================
	// Contact
	//==============================================
	if (sCurrentPage.indexOf('/contactus/') > -1)
	{
		obj = $("td#topnavlink_contact");
		if (obj.length)
		{
			//obj.css({"color":"#e38125"});
			//obj.attr("class","topnavitem_selected");
		}
		
		//MM_findObj('topnavlink_contact').onmouseover='';
		//MM_findObj('topnavlink_contact').onmouseout='';
	}
	
}
//**********************************************
// InitNavTables
//**********************************************
function InitNavTables()
{
	var sHref="";
	var arrSplit = new Array();
	var nLen=0;
	var sClass="";
	var objParent=null;
	var sSection="";
	var sCurrentPath = window.location.toString().toLowerCase();
	
	// g_sCurrentPage contains the name of the current page. Compare it with the nav link and if equal, 
	// set the item class to the "selected" equivalent. 
	// besides searching the page name, if the parent has a section="" value, then if the href is within that section,
	// also change the parent class to its "selected" equivalent.
	$('.navtable a').each(
		  function(nIndex)
		  {
			  	objParent = $(this).parent();
				sHref = $(this).attr("href").toLowerCase();
				arrSplit = sHref.split("/");
				
				nLen = arrSplit.length;
				if (nLen)
				{
					sHref = arrSplit[nLen-1];
				}
	
				//alert("href=" + sHref + " g_sCurrentPage=" + g_sCurrentPage);
				
				// current page?
				if (sHref == g_sCurrentPage)
				{
					objParent = $(this).parent();
					sClass = objParent.attr("class");
					objParent.removeClass(sClass);
					sClass += "_selected";
					objParent.addClass(sClass);
					//alert(sClass);
				} // if (sHref == g_sCurrentPage)
				else
				{
					// see if the parent has a "section" attribute. If so, if we are in that section, 
					// set the parent to selected.
					sSection = objParent.attr("section");
					if (sSection)
					{
						if (sCurrentPath.indexOf(sSection) != -1)
						{
							sClass = objParent.attr("class");
							objParent.removeClass(sClass);
							sClass += "_selected";
							objParent.addClass(sClass);
						}
					}
				}
		  } // function(nIndex)
    ); // $('.navtable a').each(
	
	// set the rollover effect for the top nav items
	$('.navtable td.topnavitem').each(
		  function(nIndex)
		  {
			  	$(this).mouseover(function(){
				  //$(this).removeClass("topnavitem");
				  //$(this).addClass("topnavitem_selected");
				  $(this).attr("class","topnavitem_selected");
				}).mouseout(function(){
				  //$(this).removeClass("topnavitem_selected");
				  //$(this).addClass("topnavitem");
				  $(this).attr("class","topnavitem");
				})
		  } // function(nIndex)
    ); // $('.navtable a').each(	
	
	// set the rollover effect for the left nav items  // leftcolitem_selected
	$('.leftnavtable td.leftcolitem').each(
		  function(nIndex)
		  {
			  	$(this).mouseover(function(){
				  //$(this).removeClass("topnavitem");
				  //$(this).addClass("topnavitem_selected");
				  $(this).attr("class","leftcolitem_selected");
				}).mouseout(function(){
				  //$(this).removeClass("topnavitem_selected");
				  //$(this).addClass("topnavitem");
				  $(this).attr("class","leftcolitem");
				})
		  } // function(nIndex)
    ); // $('.navtable a').each(	
	
	
	// set the left col to be as tall as the page, so the background image will extend all the way down.
	var objLeftColDiv = $("div.leftcoldiv");
	if (objLeftColDiv.length)
	{
		// fetch the bottom nav location
		var objBottomNav = $("td.bottomtag");
		if (objBottomNav.length)
		{
			var objLeftColDivOffset = objLeftColDiv.offset();	
			var objBottomOffset = objBottomNav.offset();	
			//alert("objLeftColDivOffset top=" + objLeftColDivOffset.top);
			//alert("objBottomOffset top=" + objBottomOffset.top);
			
			// calculate new height
			var nNewHeight = objBottomOffset.top - objLeftColDivOffset.top;
			
			//alert("new height = " + nNewHeight);
			// set the new height
			objLeftColDiv.css("height",nNewHeight.toString() + "px");
		}
	}
}

//*********************************************
// InitHomepageSlideshowDimensions
//*********************************************
function InitHomepageSlideshowDimensions()
{
var nMaxHeight=0;
var nMaxWidth=0;

	// get the width and height of the first image in the slideshow
	var objImg = $("#homepage_slideshow img:first-child");
	if (objImg.length)
	{
		nMaxHeight = objImg.height();
		nMaxWidth = objImg.width();
		
		// set the slideshow1 div to the max width
		$('#homepage_slideshow').css("width",nMaxWidth.toString() + "px");
		$('#homepage_slideshow').css("height",nMaxHeight.toString() + "px");
		// set the leftside td text height to the max height
		//$('td.neighborhood_header_lowerleft').css("height",nMaxHeight.toString() + "px");
	}
	
}
//************************
// ValidateEmailSignup
//************************
function ValidateEmailSignup()
{
	var sString="";
	sString = JSTrimSpace(document.emailsignup.fields_email.value);
	document.emailsignup.fields_email.value = sString;
	
	if ((sString.length < 1) || (!IsValidEmail(sString)))
	{
		document.emailsignup.fields_email.focus();
		alert("Please enter a valid email address");
		return false;
	}
	
	//alert(document.emailsignup.fields_email.value);
	
	setTimeout('document.emailsignup.submit()',10);
	
	return true;
}
//************************
// EnsureMainBodyFullVertLine
//************************
// make sure the main body cell is at least as tall as the left nav's dark background cell.
function EnsureMainBodyFullVertLine()
{
	var nContentHeight=0;
	var nLeftNavHeight=0;
	
	// make whichever is the shorter of the 2 divs, the equal of the larger
	var objContent = $("td.cellrightborder");
	if (objContent.length) nContentHeight = objContent.height();
	
	var objLeftNav = $("td.navbg");
	if (objLeftNav.length) nLeftNavHeight = objLeftNav.height();
	
	if ((nContentHeight>0) && (nLeftNavHeight>0))
	{
		if (nLeftNavHeight > nContentHeight)
		{
			objContent.height(nLeftNavHeight);
		}
	}
}
