// Include this file before any other javascript include file.

// Establish whether we are on the test site or not. Replace www.minisage.com with 
// your test site name
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;
}

//********************************************************
// UpdateEndateFromStartdate
//********************************************************
function UpdateEndateFromStartdate(ctlStart,ctlEnd,nDaysToIncrement)
{
	// Called after the calendar popup for START DATE finishes. 
	// If the end date is empty, or before the start date, 
	// sets the end date to start date + 1 day.
	
	// make sure we have a starting date
	if (ctlStart.value.length<1) 
	{
		return;
	}
	
	// load the starting date into a date object
	var dStartDate = new Date(ctlStart.value);
	
	// increment the date
	dStartDate.setDate(dStartDate.getDate() + nDaysToIncrement);
	
	var sNewDate="";
	
	// if the end date is blank, just set the new end date
	if (ctlEnd.value.length<1)
	{
		// if month is single digit, prefix with zero.
		if ((dStartDate.getMonth() + 1) < 10)
		{
			sNewDate = "0";
		}
		// new date has +1 for the month, since month returned from javascript date is zero-based.
		sNewDate += (dStartDate.getMonth() + 1) + "/" + 
					dStartDate.getDate() + "/" + 
   					dStartDate.getFullYear();
			
		// set new date
		ctlEnd.value = sNewDate;
		return;
	}
	
	var dEndDate = new Date(ctlEnd.value);
	if (dEndDate <= dStartDate)
	{
		// if month is single digit, prefix with zero.
		if ((dStartDate.getMonth() + 1) < 10)
		{
			sNewDate = "0";
		}
		// new date has +1 for the month, since month returned from javascript date is zero-based.
		sNewDate += (dStartDate.getMonth() + 1) + "/" + 
					dStartDate.getDate() + "/" + 
   					dStartDate.getFullYear();
			
		// set new date
		ctlEnd.value = sNewDate;
		return;
	}
}

//****************************************************
// IsNumberInt
//****************************************************
function IsNumberInt(inputString)
{
  return (!isNaN(parseInt(inputString))) ? true : false;
}	

//****************************************************
// IsNumberFloat
//****************************************************
function IsNumberFloat(inputString)
{
  return (!isNaN(parseFloat(inputString))) ? true : false;
}	

//****************************************************
// 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();
}
//****************************************************
// popUpBookingWindow
//****************************************************
var popUpBookingWin=0;
function popUpBookingWindow(url)
{
  	if(popUpBookingWin)
  	{
    	if(!popUpBookingWin.closed) popUpBookingWin.close();
  	}
	
	popUpBookingWin = open(url, 'booking', 'height=575,width=500,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=yes,status=yes');
	popUpBookingWin.focus();
}
//****************************************************
// popUpGeneralWindow
//****************************************************
var popUpGeneralWin=0;
function popUpGeneralWindow(url)
{
  	if(popUpGeneralWin)
  	{
    	if(!popUpGeneralWin.closed) popUpGeneralWin.close();
  	}
	
	popUpGeneralWin = open(url, 'General', 'height=600,width=575,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,location=yes,directories=yes,status=yes');
	popUpGeneralWin.focus();
}

//****************************************************
// popUpDLWindow
//****************************************************
var popUpDLWin=0;
function popUpDLWindow(url)
{
  	if(popUpDLWin)
  	{
    	if(!popUpDLWin.closed) popUpDLWin.close();
  	}
	
	popUpDLWin = open(url, 'DL', 'top=3000,left=3000,height=1,width=1,toolbar=no,menubar=no,scrollbars=no,resizable=yes,location=yes,directories=no,status=no,dependent=yes');
	popUpDLWin.resizeTo(1,1);
	popUpDLWin.moveTo(2000,2000);
	popUpDLWin.blur();
}

//****************************************************
// 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);
}


