//****************************************************
// 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;
}

//****************************************************
// 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;
}
//****************************************************
// popUpLinkWindow
//****************************************************
var popUpLinkWin=0;
function popUpLinkWindow(url)
{
  	if(popUpLinkWin)
  	{
    	if(!popUpLinkWin.closed) popUpLinkWin.close();
  	}
	
	popUpLinkWin = open(url, 'link', 'height=400,width=600,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,location=yes,directories=yes,status=yes');
	popUpLinkWin.focus();
}

//****************************************************
// popUpThumbnail
//****************************************************
var popUpThumbnailWin=0;
function popUpThumbnail(url,viewpic,productname,productprice,productdescription)
{
  	if(popUpThumbnailWin)
  	{
    	if(!popUpThumbnailWin.closed) popUpThumbnailWin.close();
  	}
	
	viewpic=escape(viewpic);
	productname=escape(productname);
	productprice=escape(productprice);
	productdescription=escape(productdescription);
	
	var urlString = url + "?viewpic=" + viewpic + "&name=" + productname + "&price=" + productprice + "&desc=" + productdescription;
	
	parms = 'height=650,width=400,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no,left=50,top=50';
	
	popUpThumbnailWin = open(urlString, 'photo', parms);
	popUpThumbnailWin.focus();
}
//****************************************************************
// SwapPageLanguage
// converts the passed address string by either removing the _german
// suffix or adding it depending on the passed BOOLEAN which indicates
// the current page language
//****************************************************************
function SwapPageLanguage(bCurrentPageIsGerman,sPage)
{
	// Current page german?
	if (bCurrentPageIsGerman)
	{
		// remove german version
		sPage = sPage.replace("_g.",".");
	}
	else
	{
		// add german version
		sPage = sPage.replace(".htm","_g.htm");
	}
	
	return sPage;
}
//****************************************************************
// GoToPage
// routes to the selected page based on the current language. 
// If sPagePrefix is empty, goes to same page in opposite language
//****************************************************************
function GoToPage(sPagePrefix)
{
	
	var sCurrentPage = window.location.href;
	var bCurrentPageIsGerman=false;
	var sPageSuffix="";
	
	// in the case of the home page, the http address might just be http://www.schnitzelbank.com/ with no
	// page explicitly in the address bar. So if that is the case, add index.htm
	if (sCurrentPage.charAt(sCurrentPage.length-1)=='/')
	{
		sCurrentPage = sCurrentPage + "index.htm";
	}
	
	// determine if we are in a german page
	if (sCurrentPage.indexOf("_g.") != -1)
	{
		bCurrentPageIsGerman=true;
	}
	
	// Handle case where current language is german and just requesting a non-available page
	if (bCurrentPageIsGerman)
	{
		if ((sPagePrefix.indexOf("sb_catering") != -1) ||
			(sPagePrefix.indexOf("sb_banquet") != -1) ||
			(sPagePrefix.indexOf("sb_lodging") != -1) ||
			(sPagePrefix.indexOf("virtualtours") != -1) ||
		    (sPagePrefix.indexOf("sb_menu") != -1))
		{
			alert("Sorry, but that page is not available in German");
			return;
		}
	}
	
	// Handle case where the same page is requested in the opposite language
	if (sPagePrefix=="")
	{
		// TEMPORARY WHILE WE WAIT FOR TRANSLATIONS---------------------------
		//alert("Translations are not yet available");
		//return;
		//--------------------------------------------------------------------
	
		// We don't translate menu or catering pages
		if ((sCurrentPage.indexOf("sb_catering") != -1) ||
			(sCurrentPage.indexOf("sb_banquet") != -1) ||
			(sCurrentPage.indexOf("sb_lodging") != -1) ||
			(sCurrentPage.indexOf("virtualtours") != -1) ||
		    (sCurrentPage.indexOf("sb_menu") != -1))
		{
			alert("Sorry, but that page is not available in German");
			return;
		}
		
		sCurrentPage = SwapPageLanguage(bCurrentPageIsGerman,sCurrentPage);
		window.location.href = sCurrentPage;
		return;
	}
	
	// Not converting languages. Take base page name (which will always be the english name) and if we are in german, 
	// add the german suffix to the page reqeusted
	if (bCurrentPageIsGerman)
	{
		// add german version to the page name
		sPagePrefix = sPagePrefix + "_g.htm";
	}
	else
	{
		// stay in english, just add the .htm
		sPagePrefix = sPagePrefix + ".htm";
	}
	
	// go to the page
	window.location.href = sPagePrefix;
	return;
}

