// Include this file before any other javascript include file.

// Establish whether we are on the test site or not. If the test site changes, change
// the www.minisage.com to whatever the new test site is.
var bTestSite=false;
if (window.location.toString().toLowerCase().indexOf("www.minisage.com") > -1)
{
	bTestSite=true;
}

//****************************************************
// IsMac
//****************************************************
function IsMac()
{
  if(navigator.appVersion.indexOf("Win") != -1)
  {
    return false;
  }
  else if(navigator.appVersion.indexOf("Mac") != -1)
  {
    return true;
  }
  else return false;
}
//**************************
// addToFavorites
//**************************
function addToFavorites(urlAddress,pageName) 
{ 
	if (window.external) 
	{ 
		window.external.AddFavorite(urlAddress,pageName); 
	} 
	else 
	{ 
		alert("We're sorry, your browser doesn't support this function."); 
	} 
} 
//****************************************************
// IsValidPhoneNumber
//****************************************************
function IsValidPhoneNumber(sString)
{
	var x=0;
	var nLen=0;
	var nCount=0;
	
	sString = sString.toString();
	nLen = sString.length;
	
	// examine each char
	for (x=0; x<nLen; x++)
	{
		//alert(sString[x]);
		if ((sString.charAt(x) >= '0') && (sString.charAt(x) <= '9'))
		{
			nCount++;
		}
	}
	
	// must be greater than 7 chars.
	return nCount > 7;
}
//****************************************************
// popUpLinkWindow
//****************************************************
var popUpLinkWin=0;
function popUpLinkWindow(url)
{
  	if(popUpLinkWin)
  	{
    	if(!popUpLinkWin.closed) popUpLinkWin.close();
  	}
	
	popUpLinkWin = open(url, 'link', 'height=675,width=650,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,location=yes,directories=yes,status=yes');
	popUpLinkWin.focus();
}
//****************************************************
// popUpContactWindow
//****************************************************
var popUpContactWin=0;
function popUpContactWindow(url)
{
  	if(popUpContactWin)
  	{
    	if(!popUpContactWin.closed) popUpContactWin.close();
  	}
	
	popUpContactWin = open(url, 'link', 'scrollbars=yes,resizable=no,width=400,height=500');
	popUpContactWin.focus();
}
//****************************************************
// popUpWizardWindow
//****************************************************
var popUpWizardWin=0;
function popUpWizardWindow(url)
{
  	if(popUpWizardWin)
  	{
    	if(!popUpWizardWin.closed) popUpWizardWin.close();
  	}
	
	popUpWizardWin = open(url, 'link', 'scrollbars=yes,resizable=yes,width=1024,height=600');
	popUpWizardWin.focus();
}
//****************************************************
// popUpAppWindow
//****************************************************
var popUpAppWin=0;
function popUpAppWindow(url)
{
  	if(popUpAppWin)
  	{
    	if(!popUpAppWin.closed) popUpAppWin.close();
  	}
	
	popUpAppWin = open(url, 'link', 'scrollbars=yes,resizable=no,width=580,height=570');
	popUpAppWin.focus();
}
//****************************************************
// 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;
}
//****************************************************
// StripCommasAndDollarSigns
//****************************************************
function StripCommasAndDollarSigns(sInput)
{
	var sOutput = sInput;
    sOutput=sOutput.replace(/,/g,"");
    sOutput=sOutput.replace(/\$/g,"");
	return sOutput;
}
//****************************************************
// 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;
}

//****************************************************
// 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) 
{
	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);
}

