// rollover code
isLoaded = false;
roll = new csRoll("_over","_out");

// primary object
function csRoll(overSuffix, outSuffix){
	this.overSuffix = overSuffix;
	this.outSuffix= outSuffix;
	this.images = new Object()
	this.initialized = false;
}

// out and over methods
csRoll.prototype.over = csRollOver;
function csRollOver(imgName){
	if(this.initialized){
		this.images[imgName].over();
	}
}

csRoll.prototype.out = csRollOut;
function csRollOut(imgName){
	if(this.initialized){
		this.images[imgName].out();
	}
}		

// initialize roll object by mapping named images
csRoll.prototype.init = csRollInit;
function csRollInit(){
	var imgs = document.getElementsByTagName("img");
	for(var i = 0; i < imgs.length; i++){
		this.mapImage(imgs[i]);
	}			
	this.initialized = true;
}

// map images
csRoll.prototype.mapImage = csRollMapImage;
function csRollMapImage(img){
	if(img.name.indexOf("_ROLL") != -1){
		this.images[img.name.substr(0,img.name.lastIndexOf("_"))] = new csRollImage(img, this.overSuffix, this.outSuffix);
	}		
}

function csRollImage(img,overSuffix, outSuffix){
	this.img = img;
	var lastDotPos = this.img.src.lastIndexOf(".");
	this.baseSuffix = this.img.src.substr(lastDotPos);
	var baseSrc = this.img.src.substr(0,this.img.src.lastIndexOf("_"));
	this.overSrc = baseSrc  + overSuffix + this.baseSuffix;
	this.outSrc = baseSrc  + outSuffix + this.baseSuffix;
	this.preloadOver = new Image(); 
	this.preloadOver.src = this.overSrc; 
	this.preloadOut = new Image();
	this.preloadOut.src = this.outSrc;
}

csRollImage.prototype.over = csRollImageOver
function csRollImageOver(){
	this.img.src = this.preloadOver.src;
}

csRollImage.prototype.out = csRollImageOut
function csRollImageOut(){
	this.img.src = this.preloadOut.src;
}
// windowing
function goHome(sURL) {
	if (this.opener == null) document.location = sURL;
	else self.close();
}
function popFeature(iPicNumber) {
	winFeature = new csWin("popup.asp?id=" + iPicNumber, "Monument", 350, 350);
}
function showInfo(iPlanNumber) {
	//alert(iPlanNumber);
}
function popPlan(iPlanNumber) {
	winFeature = new csWin("popup2.asp?id=" + iPlanNumber, "Monument", 625, 625);
}
function popLPlan(iPlanNumber) {
	winFeature = new csWin("popup2.asp?id=" + iPlanNumber, "Monument", 650, 625);
}
function popSPlan(iPlanNumber) {
	winFeature = new csWin("popup3.asp?id=" + iPlanNumber, "Monument", 625, 625);
}
function csWin(popUrl,popName,w,h,scrollbars,x,y,toolbar,menubar,resizable,status,directories){
	this.popUrl = popUrl;
	this.popName = popName;
	this.w = w ? w : screen.width;
	this.h = h ? h : screen.height;
	this.scrollbars = scrollbars ? scrollbars : 0;
	this.toolbar = toolbar ? toolbar : 0;
	this.menubar = menubar ? menubar : 0;
	this.resizable = resizable ? resizable : 0;
	this.status = status ? status : 0;
	this.directories = directories ? directories : 0;
	var winl = x ? x : ((screen.width - this.w) / 2);
	var wint = y ? y : ((screen.height - this.h) / 2);
	if (wint < 0) wint = 1;
	if (winl < 0) winl = 0;
	this.popWin = window.open(
		this.popUrl,
		this.popName,
		"top=" + wint + "," +
		"left=" + winl + "," +
		"toolbar=" + this.toolbar.toString() + "," +
		"directories=" + this.directories.toString() + "," +
		"status=" + this.status.toString() + "," +
		"menubar=" + this.menubar.toString() + "," +
		"scrollbars=" + this.scrollbars.toString() + "," +
		"resizable=" + this.resizable.toString() + "," +
		"width=" + this.w.toString() + "," +
		"height=" + this.h.toString()
	);
}

function csWinClose() {
	this.popWin.close();
}

csWin.prototype.close = csWinClose;
// form validate
function validateForm(bUnitType, bCurrentResidence, bHowFound, bPriceRange) {
	var bFormOK = true, bProperty = false;
	if (checkString("First Name", "fldFirstName", bFormOK)) bFormOK = false;
	if (checkString("Last Name", "fldLastName", bFormOK)) bFormOK = false;
	if (checkString("Address 1", "fldAddress1", bFormOK)) bFormOK = false;
	if (checkString("Address 2", "fldAddress2", bFormOK, true)) bFormOK = false;
	if (checkString("City", "fldCity", bFormOK)) bFormOK = false;
	if (checkString("State", "fldState", bFormOK)) bFormOK = false;
	if (checkString("Zip", "fldZip", bFormOK)) bFormOK = false;
	if (checkString("Home Phone", "fldHomePhone1", bFormOK)) bFormOK = false;
	if (checkString("Home Phone", "fldHomePhone2", bFormOK)) bFormOK = false;
	if (checkString("Home Phone", "fldHomePhone3", bFormOK)) bFormOK = false;
	if (checkString("Work Phone", "fldWorkPhone1", bFormOK)) bFormOK = false;
	if (checkString("Work Phone", "fldWorkPhone2", bFormOK)) bFormOK = false;
	if (checkString("Work Phone", "fldWorkPhone3", bFormOK)) bFormOK = false;
	if (checkString("Email", "fldEmail", bFormOK)) bFormOK = false;
	if (checkString("Comments", "fldComments", bFormOK, true)) bFormOK = false;
	if (checkDropDown("Unit Type", "fldUnitType", bFormOK, bUnitType)) bFormOK = false;
	if (checkDropDown("Current Residence", "fldCurrentResidence", bFormOK, bCurrentResidence)) bFormOK = false;
	if (checkDropDown("How did you find us", "fldHowFound", bFormOK, bHowFound)) bFormOK = false;
	if (checkDropDown("Price Range", "fldPriceRange", bFormOK, bPriceRange)) bFormOK = false;
	if (bFormOK) document.frmThis.submit();
}
function checkDropDown(sFieldText, sFieldName, bFormOK, bRequired) {
	if (bFormOK) {
		if (eval("document.frmThis." + sFieldName) != undefined) {
			if (eval("document.frmThis." + sFieldName).value == "0" && bRequired) {
				alert(sFieldText + " is a required field");
				eval("document.frmThis." + sFieldName).focus();
				return true;
			}
		}
	}
	return false;
}
function checkString(sFieldText, sFieldName, bFormOK, bBlankOK) {
	if (bFormOK) {
		if (hasScript(eval("document.frmThis." + sFieldName).value)) {
			alert(sFieldText + " contains illegal script text\nthat can cause problems with your group information");
			eval("document.frmThis." + sFieldName).focus();
			return true;
		} else {
			if (!bBlankOK && isWhitespace(eval("document.frmThis." + sFieldName).value)) {
				alert(sFieldText + " is a required field");
				eval("document.frmThis." + sFieldName).focus();
				return true;
			} else {
				return false;
			}
		}
	}
	return false;
}
var sWhitespace = " \t\n\r";

function isEmpty(s){
	return ((s == null) || (s.length == 0))
}

function isWhitespace (s) {
	var i;
	if (isEmpty(s)) return true;
	for (i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if (sWhitespace.indexOf(c) == -1) return false;
	}
	return true;
}
function hasScript (inString) {
	var tmpString = stripWhitespace(inString).toUpperCase();
	if (tmpString.indexOf("<" + "SCRIPT") != -1) return true;
	if (tmpString.indexOf("<" + "/" + "SCRIPT") != -1) return true;
	if (tmpString.indexOf("<" + "%") != -1) return true;
	if (tmpString.indexOf("%" + ">") != -1) return true;
	if (tmpString.indexOf("<" + "?") != -1) return true;
	if (tmpString.indexOf("php" + ">") != -1) return true;
	if (tmpString.indexOf("language=") != -1) return true;
	return false;
}
function stripWhitespace (s) {
	return stripCharsInBag (s, sWhitespace);
}
function stripCharsInBag (s, bag){
	var i;
	var returnString = "";
	for (i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}
