//****************************************************
// 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);
}
//*******************************
// IsEmailOK
//*******************************
function IsEmailOK(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;
}
//****************************************************
// 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);

	for (var x=0; x<nLen; x++)
	{
		var 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;
}
//****************************************************
// 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) 
{
	// Clean MSWord chars et al.
	var returnString = CleanWordChars(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);
}

//****************************************************
// 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;
}
//****************************************************
// 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;
}
var popUpLinkWin=0;
//****************************************************
// popUpLinkWindow
// optional arguments: width,height,left,top
//****************************************************
function popUpLinkWindow(url)
{
  	if(popUpLinkWin)
  	{
    	if(!popUpLinkWin.closed) popUpLinkWin.close();
  	}
	
	var nWidth=600;
	var nHeight=400;
	var nLeft=10;
	var nTop=10;
	
	if (popUpLinkWindow.arguments.length > 1)
	{
		nWidth = parseInt(popUpLinkWindow.arguments[1])
	}
	if (popUpLinkWindow.arguments.length > 2)
	{
		nHeight = parseInt(popUpLinkWindow.arguments[2])
	}
	if (popUpLinkWindow.arguments.length > 3)
	{
		nLeft = parseInt(popUpLinkWindow.arguments[3])
	}
	if (popUpLinkWindow.arguments.length > 4)
	{
		nTop = parseInt(popUpLinkWindow.arguments[4])
	}
	
	popUpLinkWin = open(url, 'link', 'height=' + nHeight + ',width=' + nWidth + ',left=' + nLeft + ',top=' + nTop + ',toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,location=yes,directories=yes,status=yes');
	popUpLinkWin.focus();
}
var popUpLinkWin2=0;
//****************************************************
// popUpLinkWindow
// optional arguments: width,height,left,top
//****************************************************
function popUpLinkWindow2(url)
{
  	if(popUpLinkWin2)
  	{
    	if(!popUpLinkWin2.closed) popUpLinkWin2.close();
  	}
	
	var nWidth=600;
	var nHeight=400;
	var nLeft=10;
	var nTop=10;
	
	if (popUpLinkWindow2.arguments.length > 1)
	{
		nWidth = parseInt(popUpLinkWindow2.arguments[1])
	}
	if (popUpLinkWindow2.arguments.length > 2)
	{
		nHeight = parseInt(popUpLinkWindow2.arguments[2])
	}
	if (popUpLinkWindow2.arguments.length > 3)
	{
		nLeft = parseInt(popUpLinkWindow2.arguments[3])
	}
	if (popUpLinkWindow2.arguments.length > 4)
	{
		nTop = parseInt(popUpLinkWindow2.arguments[4])
	}
	
	popUpLinkWin2 = open(url, 'link2', 'height=' + nHeight + ',width=' + nWidth + ',left=' + nLeft + ',top=' + nTop + ',toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,location=yes,directories=yes,status=yes');
	popUpLinkWin2.focus();
}
var popUpLinkWin3=0;
//****************************************************
// popUpLinkWindow3
// optional arguments: width,height,left,top
//****************************************************
function popUpLinkWindow3(url)
{
  	if(popUpLinkWin3)
  	{
    	if(!popUpLinkWin3.closed) popUpLinkWin3.close();
  	}
	
	var nWidth=100;
	var nHeight=100;
	var nLeft=0;
	var nTop=0;
	
	if (popUpLinkWindow3.arguments.length > 1)
	{
		nWidth = parseInt(popUpLinkWindow3.arguments[1])
	}
	if (popUpLinkWindow3.arguments.length > 2)
	{
		nHeight = parseInt(popUpLinkWindow3.arguments[2])
	}
	if (popUpLinkWindow3.arguments.length > 3)
	{
		nLeft = parseInt(popUpLinkWindow3.arguments[3])
	}
	if (popUpLinkWindow3.arguments.length > 4)
	{
		nTop = parseInt(popUpLinkWindow3.arguments[4])
	}
	
	popUpLinkWin3 = open(url, 'link3', 'height=' + nHeight + ',width=' + nWidth + ',left=' + nLeft + ',top=' + nTop + ',toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=no');
	popUpLinkWin3.focus();
}
var popUpLinkWin4=0;
//****************************************************
// popUpLinkWindow4
// optional arguments: width,height,left,top
//****************************************************
function popUpLinkWindow4(url)
{
  	if(popUpLinkWin4)
  	{
    	if(!popUpLinkWin4.closed) popUpLinkWin4.close();
  	}
	
	var nWidth=100;
	var nHeight=100;
	var nLeft=20;
	var nTop=20;
	
	if (popUpLinkWindow4.arguments.length > 1)
	{
		nWidth = parseInt(popUpLinkWindow4.arguments[1])
	}
	if (popUpLinkWindow4.arguments.length > 2)
	{
		nHeight = parseInt(popUpLinkWindow4.arguments[2])
	}
	if (popUpLinkWindow4.arguments.length > 3)
	{
		nLeft = parseInt(popUpLinkWindow4.arguments[3])
	}
	if (popUpLinkWindow4.arguments.length > 4)
	{
		nTop = parseInt(popUpLinkWindow4.arguments[4])
	}
	
	popUpLinkWin4 = open(url, 'link3', 'height=' + nHeight + ',width=' + nWidth + ',left=' + nLeft + ',top=' + nTop + ',toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no');
	popUpLinkWin4.focus();
}
//*************************************************************************************************************************
// BEGIN VIRTUAL TOUR FUNCTIONS PROVIDED BY VENDOR
//*************************************************************************************************************************
var winopts = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=no,height=510,width=510,copyhistory=0,"; 
var winopts2 = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=yes,height=460,width=700,copyhistory=0,"; 
var smallwindow = null;
function setEvent() {
     return false;
}
function historywin(filename) {
    fileURL=filename;
     if (parseInt(navigator.appVersion) < 4) {
        if (smallwindow != null) smallwindow.close();
   }  
    timerID= setTimeout('Opener(fileURL)',100);
                              }
function Opener(winname)
{
	var useopts = winopts;
  	filename = winname;
  
  	// if circlepix, set different window size
  	if (filename.indexOf("circlepix") != -1)
  	{
  		useopts = winopts2;
  	}
  
  	winname = "historywin"
 
  	smallwindow = window.open(filename,winname,useopts)
  
  	if( navigator.appVersion.indexOf("(X11") != -1 || 
  	navigator.appVersion.indexOf("(Mac") != -1)
  	{
       smallwindow = window.open(filename,winname,useopts)
  	}

  	if( navigator.appVersion.indexOf("MSIE") == -1 )
  	{
      smallwindow.mainWin = this;
  	}
    
	WindowFocus();
}

//*********************************************
// WindowFocus
//*********************************************
function WindowFocus()
{
  
	if( navigator.appVersion.indexOf("2.") == -1 &&  navigator.appVersion.indexOf("MSIE") == -1 )
	{
	   smallwindow.focus();
	}
}
//*********************************************
// InitNeighborhoodSlideshowDimensions
//*********************************************
function InitNeighborhoodSlideshowDimensions()
{
var nMaxHeight=0;
var nMaxWidth=0;

	// get the width and height of the first image in the slideshow
	var objImg = $("#neighborhood_slideshow img:first-child");
	if (objImg.length)
	{
		nMaxHeight = objImg.height();
		nMaxWidth = objImg.width();
		
		// set the slideshow1 div to the max width
		$('#neighborhood_slideshow').css("width",nMaxWidth.toString() + "px");
		$('#neighborhood_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");
	}
	
}
//******* END VIRTUAL TOUR FUNCTIONS *************************************************************************


