<!--

/*****************************************************/
/*																	 */
/*					Purpose: Repository of JavaScript				 */
/*									 					    		 */
/*					Written by: Adam Nelson 10/16/01				 */
/*													 				 */
/*****************************************************/


function selectPopup(select, win_width, win_height) {
			 //var page = select.options[select.selectedIndex].value
			 //var win_width = win_width;
			 //var win_height = win_height;
			 //var parameters = "left=0,top=0,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,width=" + win_width + ",height=" + win_height;
			 //if (page == 15) { // the number here accords to the selection foreclosure
  		 		//var newWindow = window.open('/fore.html','name',parameters);
				//newWindow.creator = self;
				//newWindow.focus();
			//}


return true;

}

/* Useless now, but keep the function for any calls I didn't notice */

function validateCounty (theForm) {
  if (isBlank(theForm.szPostalCode)) {
	  theForm.szPostalCode.focus();
		alert ("Please enter a zip code.");
		return false;
  }	
}


function isNumeric(theObject) {
  var refString = "0123456789";
  var checkStr = theObject.value;
  var allValid = true;
  for (i = 0; i < checkStr.length; i++) {
    ch = checkStr.charAt(i);
    if (refString.indexOf(ch, 0) == -1) { return (false); }
  }
  return (true);
}

function isBlank (theObject) {
  if (theObject.value == "") { return true; }
  if (theObject == null)     { return true; }
  return false;
}

function validate (theForm) {
  	// set var radio_choice to false
	var iAccountNumberExists = false;

	if (theForm.iAccountNumber) {
		// Loop from zero to the one minus the number of radio button selections
		for (counter = 0; counter < theForm.iAccountNumber.length; counter++)
		{
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (theForm.iAccountNumber[counter].checked)
		 	 iAccountNumberExists = true;
		}
	
		if (iAccountNumberExists == false) {
		 	 theForm.iAccountNumber[0].focus();
		 	 theForm.iAccountNumber[0].click();
  	 	 alert ("Please select a package type.  I have selected the first option for you.");
		 	 return false;
		}	
	}

	if (isBlank(theForm.szOwnerName)) {
    theForm.szOwnerName.focus();
    alert ("Please enter the homeowner's name.");
    return false;
  }
  if (isBlank(theForm.szPhone1)) {
    theForm.szPhone1.focus();
    alert ("Please enter a contact phone number.");
    return false;
  }
  if (!isEmail(theForm.szEmailAddress.value)) {
	 theForm.szEmailAddress.focus();
   	 theForm.szEmailAddress.select();
	 alert ("I'm sorry, it appears that the email address you entered is not valid.  Please try again.")
     return false;
  }
  
	if (isBlank(theForm.szAddress)) {
    theForm.szAddress.focus();
    alert ("Please enter the property address.");
    return false;
  }
  if (isBlank(theForm.szCity)) {
    theForm.szCity.focus();
    alert ("Please enter the city that this property is in.");
    return false;
  }
  if (theForm.szStateCode.selectedIndex == 0) {
    theForm.szStateCode.focus();
    alert ("Please select the state/province for this property.");
    return false;
  }
  if (theForm.szURL.value == "SB") { //SB is the publisher ID for online only
	  if (isBlank(theForm.szPassword) && (theForm.iAdmin.value == "")) {
    	theForm.szPassword.focus();
    	alert ("Please select a password for this ad.");
    	return false;
  	}
  }
  if (theForm.iPropTypeCode.selectedIndex == 0) {
    theForm.iPropTypeCode.focus();
    alert ("Please select the type of property for sale.");
    return false;
  }
  if (theForm.szURL.value == "SB") { //SB is the publisher ID for online only
  	if (theForm.szPassword.value != theForm.szConfPassword.value) {
    	theForm.szConfPassword.focus();
    	theForm.szConfPassword.select();
    	alert ("Those passwords don't match.");
    	return false;
  	}
  }
  if (isBlank(theForm.iAskingPrice)) {
    theForm.iAskingPrice.focus();
    alert ("Please enter the asking price for this property.");
    return false;
  } 
  if (!isNumeric(theForm.iNumBedrooms)) {
    theForm.iNumBedrooms.focus();
    theForm.iNumBedrooms.select();
    alert ("Please use only the digits 0-9 to enter the number of bedrooms.");
    return false;
  }
  if (!isNumeric(theForm.iNumFloors)) {
    theForm.iNumFloors.focus();
    theForm.iNumFloors.select();
    alert ("Please use only the digits 0-9 to enter the number of floors.");
    return false;
  }
  if (!isNumeric(theForm.iSqFootage)) {
    theForm.iSqFootage.focus();
    theForm.iSqFootage.select();
    alert ("Please use only the digits 0-9 to enter the square footage.");
    return false;
  }
  if (theForm.dEndRun) {
  	if (!formatDate(theForm.dEndRun.value))  {
		theForm.dEndRun.focus();
		theForm.dEndRun.select();
		alert('Date must be in format YYYY-MM-DD');
		return false;
	}
  }
  return true;
}

function verifyInfo(theForm){
	if (!isEmail(theForm.szEmail.value)||(isBlank(theForm.szPhone.value))||(isBlank(theForm.szEmail.value))){
		 alert ("Please enter either a phone numnber or email address where you can be reached, then try again.");
		 return false;
	}
	alert('hey!');
}


function isEmail(email) {
    invalidChars = " ~\'^\`\"*+=\\|][(){}$&!#%/:,;";

    // Check for null
    if (email == "") {
		return true;
    }

    // Check for invalid characters as defined above
    for (i=0; i<invalidChars.length; i++) {
        badChar = invalidChars.charAt(i);
        if (email.indexOf(badChar,0) > -1) {
            return false;
        }
    }
    lengthOfEmail = email.length;
    if ((email.charAt(lengthOfEmail - 1) == ".") || (email.charAt(lengthOfEmail - 2) == ".")) {
        return false;
    }
    Pos = email.indexOf("@",1);
    if (email.charAt(Pos + 1) == ".") {
        return false;
    }
    while ((Pos < lengthOfEmail) && ( Pos != -1)) {
        Pos = email.indexOf(".",Pos);
        if (email.charAt(Pos + 1) == ".") {
            return false;
        }
        if (Pos != -1) {
            Pos++;
        }
    }

    // There must be at least one @ symbol
    atPos = email.indexOf("@",1);
    if (atPos == -1) {
        return false;
    }

    // But only ONE @ symbol
    if (email.indexOf("@",atPos+1) != -1) {
        return false;
    }

    // Also check for at least one period after the @ symbol
    periodPos = email.indexOf(".",atPos);
    if (periodPos == -1) {
        return false;
    }
    if (periodPos+3 > email.length) {
        return false;
    }
    return true;
}

function checkEmail(val) {
		if (isEmail(val)==false) {
			var notValid =  "I'm sorry, " + val + " is not a valid email address";
			alert(notValid);
			return false;
		}
	return true;
	}

function formatDate(date) {

//	with (date.form) { 
		var spot = date.indexOf('-',0)
		//alert(spot);
		if ((spot != 4) || (date.length != 10)) {
		//alert ("I dont think spot is 4");
	//		alert('Date must be in format YYYY-MM-DD'); 
	//		date.form.focus(); 
			return false;
		}				
		var spot = date.indexOf('-',5)
		if (spot != 7) {
		//	alert('Date must be in format YYYY-MM-DD'); 
		//	date.form.focus(); 
			return false;
		}
//	} 
	return true;
}

//functions for slideshow
//written by: scott bice 6/15/02
var timer = null;

function playpauseShow(option) {
	if (option == "play") {
		if (currentImage == imageList.length-1) {
			currentImage=0;
		} else {
			currentImage++;
		}
		document.slideimage.src = imageList[currentImage];
		timer = setTimeout("playpauseShow('play')", 3000);
	} else {
		clearTimeout(timer);
	}
}

function nextImage() {
		if (currentImage == imageList.length-1) {
			currentImage = 0;
		} else {
			currentImage++;
		}
		document.slideimage.src = imageList[currentImage];
}

function prevImage() {
		if (currentImage == 0) {
			currentImage = imageList.length-1;
		} else {
			currentImage--;
		}
		document.slideimage.src = imageList[currentImage];
}
//end of functions for slideshow


var browser = navigator.appName;
var version = navigator.appVersion.substring(0,1);

function redirectTopNav(dest) {
  window.location=dest;
}

function changeFontColor(loc, color) {
  if (browser == "Microsoft Internet Explorer") {
	  window[loc].style.color=color;
	} 
}

function changeBGColor(loc, color) {
  if (browser == "Microsoft Internet Explorer") {
    window[loc].style.backgroundColor=color;
	} 
}

function changeImage(loc, image) {
  if (browser == "Microsoft Internet Explorer") {
	  window[loc].src = image;
	} else if (browser == "Netscape" && version>=5) {
    document.getElementById(loc).src = image;
  }
}


function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num)) num = "0";
	cents = Math.floor((num * 100 + 0.5) % 100);
	num = Math.floor((num * 100 + 0.5) / 100).toString();
	if(cents < 10) cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
	num = num.substring(0,num.length - (4 * i +
3))+','+num.substring(num.length-(4 * i + 3));
	return ("$" + num + "." + cents);
}


function checkChoice(whichbox) {
  with (whichbox.form) {
    if (isNaN(whichbox.value)) { 
      whichbox.value = whichbox.priorval;
      whichbox.focus();
    }
    whichbox.value = Math.abs(whichbox.value);
    var dec = whichbox.value.indexOf('.', 1)
    if (dec > 0) { 
      alert('No decimal places allowed for \"' +whichbox.name +'\" !');
      whichbox.value = whichbox.priorval;
      whichbox.focus();
    }
    hiddentotal.value = eval(hiddentotal.value) - eval(whichbox.price * whichbox.priorval);
    whichbox.priorval = whichbox.value;
    hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.price * whichbox.value);
    return(formatCurrency(hiddentotal.value));
    }
}
