

/* ------------------------------------------------------------------
 Name:			createCenterNewWindow
 Description:	Opens up a new browser window in the center of the screen 
				regardless of the Screens resolution.
 Input Params:	intPopUpHeight = the height of the new window; 
				intPopUpWidth = the width of the new window; 
				strURL = the URL that should be displayed in the new window
				strWindowName = the name of the new window (cannot have spaces or special characters)
 Output/Return:	N/A
 Create:		5/01/2002
 Developer:		Jamie
------------------------------------------------------------------ */
function createCenterNewWindow( intPopUpWidth, intPopUpHeight, strURL, strWindowName )
{
	var intPopUpXpos, intPopUpYpos, wWnd;

	intPopUpXpos = ((screen.width/2) - (intPopUpWidth/2));

	intPopUpYpos = ((screen.height/2) - (intPopUpHeight/2));

	window.open( strURL, strWindowName , "width=" + intPopUpWidth + ",height=" + intPopUpHeight +  ",top=" + intPopUpYpos + ",left=" + intPopUpXpos + ",toolbar=no,location=no,personalbar=no,scrollbars=yes,alwaysRaised=yes,directories=no,status=no,menubar=no,resize=yes");
}

/* ------------------------------------------------------------------
 Name:			toggleCheckBox
 Description:	Selects or Deselect all checkboxes on a form
 Input Params:	strCheckBoxName = HTML attribute name of the checkboxes
				objHTMLcallcontrol = the HTML form control that the function was called from.
				intFormNumber = index(zero indexed) of the form that contains the checkboxes
					(if there is more than one form ont the page)
 Output/Return:	N/A
 Create:		5/01/2002
 Developer:		Jamie
------------------------------------------------------------------ */
function toggleCheckBox(strCheckBoxName, objHTMLcallcontrol, intFormNumber)
{

	var intNumberOfCheckboxes, strExpression, intCheckboxIndex, blnState;
			
	strExpression = 'document.forms[' + intFormNumber + '].' + strCheckBoxName + '.length'

	intNumberOfCheckboxes = eval(strExpression);
	
	// check if user checked or unchecked the select all check box
	if (objHTMLcallcontrol.checked)
	{
		blnState = true;
	}
	else
	{
		blnState = false
	}

	if (intNumberOfCheckboxes > 0)
	{
		for(intCheckboxIndex = 0; intCheckboxIndex < intNumberOfCheckboxes; intCheckboxIndex++)
		{
				
			eval('document.forms[' + intFormNumber + '].' + strCheckBoxName + '[' + intCheckboxIndex + '].checked = ' + blnState);
					
		}
	}
	else
	{

		eval('document.forms[' + intFormNumber + '].' + strCheckBoxName + '.checked = ' + blnState);
		
	}

	return;
}

/* ------------------------------------------------------------------
 Name:			closePopup
 Description:	closes the pop up window and refreshes the parent window which is the 
				company profile view page.
 Input Params:	intCompanID = company ID of current company
 Output/Return:	N/A
 Create:		5/01/2002
 Developer:		Jamie
------------------------------------------------------------------ */
function closePopup()
{

	window.opener.location.reload(true);

	window.close();
	
}

/* ------------------------------------------------------------------
Function name:    isEmailAddr
Date:             5/01/2002
input:            email adderss
output:           N/A
Return:           true - if succeeds; false - if fails
Description:      Evaluates if the email value of the form object passed into function is a valid email address or not.
 -------------------------------------------------------------------- */
function isEmailAddr(strEmail)
{
  var result = false;
  var theStr = new String(strEmail);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

/* ------------------------------------------------------------------
Function name:    validRequired
Date:             5/01/2002
input:            string 
output:           alert dialog box to screen with error message
Return:           true - if succeeds; false - if fails
Description:      
 -------------------------------------------------------------------- */
function validRequired(formField,fieldLabel)
{
	var i, j;
	var result = true;
	var bolItemSelected = false;
	
	if (formField.type != "text") {
		
		if (formField.type == "select-one") {
		
			// -- go through all options of select list
			for (i = 1; i < formField.length; i++) {
				
				// -- check if an item is selected
				if (formField[i].selected == true || formField[i].selected ) {
				
					// -- if item is selected set flag to be true
					bolItemSelected = true;
				}
				
			}
		
		} else {
		
			// -- go through all options of select list
			for (j = 0; j < formField.length; j++) {
				//window.alert(formField[j].checked);
				// -- check if an item is selected
				if ( formField[j].checked == true || formField[j].checked ) {
				
					// -- if item is selected set flag to be true
					bolItemSelected = true;
				}
				
			}
		
		
		}

		if (bolItemSelected == false)
		{
			alert('Please enter a value for the "' + fieldLabel +'" field.');

			if (formField.type == "select-one" || formField.type == "text") {

				formField.focus();

			}

			result = false;
		}

	
	} else {

		if (trim(formField.value) == "")
		{
			alert('Please enter a value for the "' + fieldLabel +'" field.');
			formField.focus();
			result = false;
		}
	}	
	return result;
}

function trim(str) 
{
    str = str.toString();
    while (1) 
    {
        if (str.substring(0, 1) != " ")
        {
            break;
        }
        str = str.substring(1, str.length);
    }
    while (1) 
    {
        if (str.substring(str.length - 1,str.length) != " ")
        {
            break;
        }
        str = str.substring(0, str.length - 1);
    }
    return str;
}



/* ------------------------------------------------------------------
Function name:    allNums
Date:             5/01/2002
input:            string 
output:           N/A
Return:           true - if succeeds; false - if fails
Description:      
 -------------------------------------------------------------------- */
function allNums(str)
{
	return inValidCharSet(str,"0123456789");
}


/* ------------------------------------------------------------------
Function name:    allPhoneDigits
Date:             5/01/2002
input:            string 
output:           N/A
Return:           true - if succeeds; false - if fails
Description:      
 -------------------------------------------------------------------- */
function allPhoneDigits(str)
{
	return inValidCharSet(str,"0123456789-()+.");
}

/* ------------------------------------------------------------------
Function name:    inValidCharSet(str,charset)
Date:             5/01/2002
input:            string and a character set
output:           N/A
Return:           true - if succeeds; false - if fails
Description:      check if given characters are valid
 -------------------------------------------------------------------- */
function inValidCharSet(str,charset)
{
	var result = true;

	// Note: doesn't use regular expressions to avoid early Mac browser bugs	
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	
	return result;
}

/* ------------------------------------------------------------------
Function name:    validEmail
Date:             5/01/2002
input:            form field, label and if it is a required field
output:           N/A
Return:           true - if succeeds; false - if fails
Description:      validates email
 -------------------------------------------------------------------- */
function validEmail(formField,fieldLabel,required)
{
	var result = true;
	if (required || formField.value.length != 0) {
		if (required && !validRequired(formField,fieldLabel))
			result = false;

		if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
		{
			alert('Please enter a complete email address in the form: yourname@yourdomain.com. For the field:"' + fieldLabel + '"');
			formField.focus();
			result = false;
		}
	}   
  return result;

}

/* ------------------------------------------------------------------
Function name:    validNum
Date:             5/01/2002
input:            form field, label and if it is a required field
output:           N/A
Return:           true - if succeeds; false - if fails
Description:      checks for valid number for a phone #
 -------------------------------------------------------------------- */
function validNum(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		if (!allNums(formField.value))
 		{
 			alert('Please enter only numeric values for the "' + fieldLabel +'" field.');
			formField.focus();		
			result = false;
		}
	} 
	
	return result;
}


/* ------------------------------------------------------------------
Function name:    validLen
Date:             5/01/2002
input:            form field, label and if it is a required field
output:           N/A
Return:           true - if succeeds; false - if fails
Description:      checks for a minimum length of a field value.
 -------------------------------------------------------------------- */
function validLen(formField,fieldLabel,required, intLen)
{
	var result = true;

//	if  ((formField.value.length <= 0) || (formField.value.length < intLen)) {
	if  ((formField.value.length > 0) && (formField.value.length < intLen)) {
 		if ((formField.value.length < intLen))
 		{
 			alert('Please enter the correct amount of numbers for the "' + fieldLabel +'" field.');
			formField.focus();		
			result = false;
		}
	}	 

	return result;
}





/* ------------------------------------------------------------------
Function name:    validPhone
Date:             5/01/2002
input:            form field, label and if it is a required field
output:           N/A
Return:           true - if succeeds; false - if fails
Description:      checks for valid number for a phone #
 -------------------------------------------------------------------- */
function validPhone(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		if (!allPhoneDigits(formField.value))
 		{
 			alert('Please enter a number for the "' + fieldLabel +'" field.');
			formField.focus();		
			result = false;
		}
	} 
	
	return result;
}

/* ------------------------------------------------------------------
Function name:    validZip
Date:             5/01/2002
input:            form field, label and if it is a required field
output:           N/A
Return:           true - if succeeds; false - if fails
Description:      checks for valid number for a zip code
 -------------------------------------------------------------------- */
function validZip(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		if (!allNums(formField.value))
 		{
 			alert('Please enter a number for the "' + fieldLabel +'" field.');
			formField.focus();		
			result = false;
		}
	} 
	
	return result;
}

/* ------------------------------------------------------------------
Function name:    validatePassword
Date:             5/01/2002
input:            form field, label 
output:           N/A
Return:           true - if succeeds; false - if fails and a dialog alert message 
Description:      check that the password entered is not a naturally common word.
 -------------------------------------------------------------------- */
function validatePassword(formField,fieldLabel)
{


	var strLower = new String("abcdefghijklmnopqrstuvwxyz");
	var strUpper = new String("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
	var strNumber = new String("0123456789");
	var chCurrentLower, chCurrentUpper, chCurrentNumber, chCurrentPassValue, i, j;
	var bolHasLower = false, bolHasUpper = false, bolHasNumber = false;
	var strUCMes = "", strLCMes = "" , strNumMes = "";
	
	// -- check length of password.
	if (formField.value.length < 6) {
		window.alert("Password must be at least 6 characters in length.");
		return false;
	}
	
	// -- check if there is atleast 1 lower case letter in password
	for(i=0; i < strLower.length; i++) {
		chCurrentLower = strLower.substring(i,i+1);

		if (formField.value.indexOf(chCurrentLower) >= 0)  {
			bolHasLower = true;
		}
			
	}

	// -- check if there is atleast 1 upper case letter in password
	for(i=0; i < strUpper.length; i++) {
		chCurrentUpper = strUpper.substring(i,i+1);

		if (formField.value.indexOf(chCurrentUpper) >= 0 ) {
			bolHasUpper = true; 
		}
			
	}

	// -- check if there is atleast 1 number in password
	for(i=0; i < strNumber.length; i++) {
		chCurrentNumber = strNumber.substring(i,i+1);

		if (formField.value.indexOf(chCurrentNumber) >= 0 ) {
			bolHasNumber = true; 
		}
			
	}

	// -- check if one of each of the below constraints exist and create message for those that do not exist.
	if (bolHasLower != true) {

		strLCMes = " - a lowercase letter\n";

	}

	if (bolHasUpper != true) {
	
		strUCMes = " - an uppercase letter\n";

	}
	
	if (bolHasNumber != true) {

		strNumMes = " - a number\n";

	}
	
	// -- If there are error messages display them otherwise return true and contine with page processing.
	if ( (strNumMes != "") || (strUCMes != "") || (strLCMes != "") ) {
	
		window.alert("Your password must consist of: \n" + strLCMes + strUCMes + strNumMes + "\n");

		return false;

	} else {
	
		return true;
	}

}


/* ------------------------------------------------------------------
 Name:			getStyleSheet
 Description:	determines which style sheet should be use for a particular
				browser.					
 Input Params:	N/A
 Output/Return:	N/A
 Create:		6/12/2002
 Developer:		Jamie
------------------------------------------------------------------ */
function getStyleSheet() {
		
	var browser=navigator.appName;
	var version=navigator.appVersion;

	// find which browser it is
	if ((browser.indexOf("Netscape") >= 0) && (version.indexOf("Windows") >= 0)) {
		  document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"http://www.furnishedhousing.com/style/general_sm.css\" />');
	}

	if ((browser.indexOf("Microsoft") >= 0) && (version.indexOf("Windows") >= 0)) {
		  document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"http://www.furnishedhousing.com/style/general_sm.css\" />');
	}
		
	if ((browser.indexOf("Netscape") >= 0) && (version.indexOf("Mac") >= 0)) {
		  document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"http://www.furnishedhousing.com/style/general_lg.css\" />');
	}

	if ((browser.indexOf("Microsoft") >= 0) && (version.indexOf("Mac") >= 0)) {
		  document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"http://www.furnishedhousing.com/style/general_sm.css\" />');
	}

	return true;
}

/* ------------------------------------------------------------------
 Name:				popVirtualTour
 Description:		displays a popup window for the virtual tour.
 Input Params:		intPropID
 Output/Return:	N/A
 Create:			6/12/2002
 Developer:		Jamie
------------------------------------------------------------------ */
function popVirtualTour(intPropID)
{
	var strUrl = "/virt_tour/virt_tour.asp?prop_id=" + intPropID
	window.open(strUrl, 'Churchill_VirtualTour', 'resizable=no,menubar=no,status=no,scrollbars=no,width=320,height=400');
}


//-->