//****************************************************
// 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);
}

//****************************************************
// 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;
}
//****************************************************
// JSTrim
// Removes leading and trailing spaces from a string
//****************************************************
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);
	  }
	}
	return ConvertHTML(returnString);
}

//****************************************************
// 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;
}

//****************************************************
// IsMoney
// Returns true or false. Checks that a string has only numbers or the '.'
//****************************************************
function IsMoney(sString)
{
	if (sString.length < 1) return false;
	
	for (var x=0; x<sString.length; x++)
	{
		if (sString.charAt(x) == ".")
		{
			continue; // period ok
		}
		
		// 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;
}
//****************************************************
// 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;
}
//****************************************************
// IsMac
//****************************************************
function IsMac()
{
  if(navigator.appVersion.indexOf("Win") != -1)
  {
    return false;
  }
  else if(navigator.appVersion.indexOf("Mac") != -1)
  {
    return true;
  }
  else return false;
}
//****************************************************
// popUpGeneralWindow
//****************************************************
var popUpGeneralWin=0;
function popUpGeneralWindow(url)
{
  	if(popUpGeneralWin)
  	{
    	if(!popUpGeneralWin.closed) popUpGeneralWin.close();
  	}
	
	popUpGeneralWin = open(url, 'general', 'height=500,width=600,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,location=yes,directories=no,status=yes');
	popUpGeneralWin.focus();
}
var popUpPictureWin=0;
//****************************************************
// popUpPictureWindow
//****************************************************
function popUpPictureWindow(imagepath)
{
  	if(popUpPictureWin)
  	{
    	if(!popUpPictureWin.closed) popUpPictureWin.close();
  	}
	
	// this to tell our popup that it's being called from within the site
	var url = "popup_picture.htm" + "?image=" + imagepath;
	
	if (IsMac())
	{
  		popUpPictureWin = open(url, 'Picture', 'left=50,top=50,height=600,width=429,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no');
	}
	else
	{
		popUpPictureWin = open(url, 'Picture', 'left=50,top=50,height=600,width=459,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no');
	}
	
	popUpPictureWin.focus();
}
