// Generic Display Fiunctions

// Generic Form Fiunctions
	function trapSQL(theForm) {
		with (eval("document." + theForm)) {
		}
		return(false);
	}

// Pop-Up Window Calls

	// Global Pop-Ups
	function show_quicktips(dir) {
		var theURL = String(dir) + "QuickTips.html";
		var thePageName = "QuickTips";
		window.open(theURL,thePageName,'width=400,height=400,menubar=no,resizable=no,scrollbars=yes,toolbar=no');
		return(true);
	}

	function popup_noreturn(theURL) {
		var thePageName = "Notes";
		window.open(theURL,thePageName,'width=776,menubar=no,resizable=yes,scrollbars=yes,toolbar=no');
	}

	function show_note(noteContext,noteTo) {
		var theURL = "/Notes.asp?noteMode=View&noteContext=" + String(noteContext) + "&noteTo=" + String(noteTo);
		var thePageName = "Notes";
		window.open(theURL,thePageName,'width=776,menubar=no,resizable=yes,scrollbars=yes,toolbar=no');
		return(true);
	}

	function show_thisnote(noteID) {
		var theURL = "/Notes.asp?noteID=" + String(noteID);
		var thePageName = "Notes";
		window.open(theURL,thePageName,'width=776,menubar=no,resizable=yes,scrollbars=yes,toolbar=no');
		return(true);
	}

	function add_note(noteContext,noteTo) {
		var theURL = "/Notes.asp?noteMode=Add&noteContext=" + String(noteContext) + "&noteTo=" + String(noteTo);
		var thePageName = "Notes";
		window.open(theURL,thePageName,'width=776,menubar=no,resizable=yes,scrollbars=yes,toolbar=no');
		return(true);
	}


	// Product Sign-Up Pop-Ups
	function start_signup(dir,address) {
		theDevRE = /1028/i;
		theStagingRE = /8080/i;
		if (theDevRE.test(document.referrer) | theStagingRE.test(document.referrer)) {
			var theURL = "/signup/" + String(dir) + "/default.asp?email=" + String(address);
		} else {
			var theURL = "http://www.reo.com/signup/" + String(dir) + "/default.asp?email=" + String(address);
		}
		var thePageName = "SignUp";
		window.open(theURL,thePageName,'width=776,menubar=no,resizable=no,scrollbars=yes,toolbar=no');
		return(true);
	}
	
	// Product Sign-Up Pop-Ups
	function start_signup_promo(dir,address) {
		var theURL = "/signup/agent/default.asp?promotion=" + String(dir) + "&email=" + String(address);
		var thePageName = "SignUp";
		window.open(theURL,thePageName,'width=776,menubar=no,resizable=no,scrollbars=yes,toolbar=no');
		return(true);
	}

	// Property Profile Pop-Ups
	function create_offer(propid) {
		var theURL = "/oms/OfferCreate.asp?PropertyID=" + String(propid);
		var thePageName = "Offer";
		window.open(theURL,thePageName,'width=776,menubar=no,resizable=no,scrollbars=yes,toolbar=no');
		return(true);
	}
	function create_offerII(propid) {
		var theURL = "/omsII/CAForm/OfferCreate.asp?PropertyID=" + String(propid);
		var thePageName = "Offer";
		window.open(theURL,thePageName,'width=776,menubar=no,resizable=no,scrollbars=yes,toolbar=no');
		return(true);
	}
	function create_offer2(propid) {
		var theURL = "/oms/OfferCreate.asp?PropertyID=" + String(propid);
		var thePageName = "Offer";
		window.open(theURL,thePageName,'width=776,menubar=no,resizable=no,scrollbars=yes,toolbar=no');
		return(true);
	}
	function create_quickoffer(propid) {
		var theURL = "/oms/OfferQuick.asp?PropertyID=" + String(propid);
		var thePageName = "Offer";
		window.open(theURL,thePageName,'width=776,menubar=no,resizable=no,scrollbars=yes,toolbar=no');
		return(true);
	}
	function create_offerworksheet(propid,propstatus) {
		var theConfirmation = true;
		if (propstatus != 1) {
			theConfirmation = confirm("You are about to submit an offer on an inactive property. This property may or may not be ready for sale and depending on the policies of the seller your offer may not get considered at this time. We suggest that you first verify with the seller that this is an approved procedure before submitting this offer. Click OK if you still want to submit this offer now.");
		}
		if (theConfirmation == true) {
				var theURL = "/ra/oms_jump.asp?PropertyID=" + String(propid);
				var thePageName = "Offer";
				window.open(theURL,thePageName,'width=776,menubar=no,resizable=yes,scrollbars=yes,toolbar=no');
				return(true);
		}
		return(false);
	}
	function email_listing(propid) {
			var theURL = "HomeProfileEmail.asp?PropertyID=" + String(propid);
			var thePageName = "EmailListing";
			window.open(theURL,thePageName,'width=760,height=600,menubar=no,resizable=no,toolbar=no');
		return(true);
	}	
	function print_flyer(propid) {
		var theURL = "HomeProfileFlyer.asp?PropertyID=" + String(propid);
		var thePageName = "Flyer";
		window.open(theURL,thePageName,'width=716,menubar=no,resizable=no,scrollbars=yes,toolbar=no');
		return(true);
	}
	function home_tour(propid) {
		var theURL = "morephotos.asp?PropertyID=" + String(propid);
		var thePageName = "HomeTour";
		window.open(theURL,thePageName,'width=395,height=330,menubar=no,resizable=no,scrollbars=no,toolbar=no');
		return(true);
	}
	function virtual_tour() {
		var theURL = "http://demoIM3.imagemaker360.com/View.asp?ID=1513";
		var thePageName = "VirtualTour";
		window.open(theURL,thePageName,'width=535,height=385,menubar=no,resizable=no,scrollbars=no,toolbar=no');
		return(true);
	}
	function map_listing(street,city,state,zip) {
		var theURL = "http://www.mapquest.com/maps/map.adp?country=USA&address=" + String(street) + "&city=" + String(city) + "&state=" + String(state) + "&zipcode=" + String(zip) + "&homesubmit.x=0&homesubmit.y=0";
		var thePageName = "MapListing";
		window.open(theURL,thePageName,'width=800,menubar=no,resizable=no,scrollbars=yes,toolbar=no');
		return(true);
	}	
	function calculator1() {
		var theURL = "http://www.financialpowertools.com/rent_vs_buy.html";
		var thePageName = "calculator1";
		window.open(theURL,thePageName,'width=600,height=400,menubar=no,resizable=no,scrollbars=yes,toolbar=no');
		return(true);
	}
	function calculator2() {
		var theURL = "http://www.financialpowertools.com/refinancing_calculator.html";
		var thePageName = "calculator2";
		window.open(theURL,thePageName,'width=600,height=400,menubar=no,resizable=no,scrollbars=yes,toolbar=no');
		return(true);
	}
	function calculator3() {
		var theURL = "http://www.financialpowertools.com/loan_comparison.html";
		var thePageName = "calculator3";
		window.open(theURL,thePageName,'width=600,height=400,menubar=no,resizable=no,scrollbars=yes,toolbar=no');
		return(true);
	}
	function calculator4() {
		var theURL = "http://www.financialpowertools.com/mortgage_calculator/index.html";
		var thePageName = "calculator4";
		window.open(theURL,thePageName,'width=600,height=400,menubar=no,resizable=no,scrollbars=yes,toolbar=no');
		return(true);
	}
	
// Common RDBMS Functions

	// Connection Routines
	
	// SQLInsertion Filters
	function filterSQL(theForm,theField,theFieldType,theFieldMinLength,theFieldMaxLength,theAlertText,theUpdateFlag) {
		with (eval("document." + theForm)) {
			theString = new String(eval(theField + ".value"));
			if (theFieldType == "num") {
				theRE = eval("/^[0-9\.]{" + theFieldMinLength + "," + theFieldMaxLength + "}$/");
			}
			if (theFieldType == "str") {
				theRE = eval("/^[0-9a-z\.\\s]{" + theFieldMinLength + "," + theFieldMaxLength + "}$/i");
			}
			if (theFieldType == "txt") {
				theRE = eval("/^[0-9a-z\\s\.\,\?\:\/\!\@\#\$\*\(\)\_]{" + theFieldMinLength + "," + theFieldMaxLength + "}$/i");
			}
			if (theFieldType == "zip") {
				theRE = eval("/^[0-9]{" + theFieldMinLength + "," + theFieldMaxLength + "}$|^[0-9]{5}\-[0-9]{4}$/");
			}
			if (theFieldType == "doc") {
				theEXT = /\.doc$|\.txt$|\.pdf$|\.wav$/i;
				if (theEXT.test(theString)) {
					theRE = eval("/^[0-9a-z\\s\.\,\?\:\/\!\@\#\$\*\(\)\_\\]{" + theFieldMinLength + "," + theFieldMaxLength + "}$/i");
				} else {
					theRE = /^.{0}$/;
				}
			}
			if (theFieldType == "img") {
				theEXT = /\.jpeg|\.jpg$|\.gif$/i;
				if (theEXT.test(theString)) {
					theRE = eval("/^[0-9a-z\\s\.\,\?\:\/\!\@\#\$\*\(\)\_\\]{" + theFieldMinLength + "," + theFieldMaxLength + "}$/i");
				} else {
					theRE = /^.{0}$/;
				}
			}
			if (theFieldType == "date") {
				theRE = eval("/^[0-9\/]{" + theFieldMinLength + "," + theFieldMaxLength + "}$/");
			}
			if (theRE.test(theString)) {
			} else {
				if (theAlertText != "") {
					alert(theAlertText);
				} else {
					alert("Field Format Error!\nContact Customer Service if you need assistance with this form.");
				}
				if (theUpdateFlag > 0) {
					eval(theField + ".value = " + theField + "_original.value");
				} else {
					if (theFieldType == "img" | theFieldType == "doc") {
						reset();
					} else {
						eval(theField + ".value = ''");
					}
				}
				return(false);
			}
		}
		return(true);
	}

function trapLogin(theForm,theField) {
	retVal = 1;
	with (eval("document." + theForm)) {
		theFieldValue = new String(eval(theField + ".value"));
		// First again email filters
		theRE = eval("/^$|^[a-z0-9_\.-]+[@]{1}[a-z0-9_-]+\.[a-z]{2,4}$|^[a-z0-9_\.-]+[@]{1}[a-z0-9_-]+\.[a-z0-9_-]+\.[a-z]{2,4}$/i");
		if (theRE.test(theFieldValue)) {
		} else {
			// OK, so login is not an email address, check against SQL Insertion filters
			theRE = eval("/^[0-9a-z_\.\\s]{0,50}$/i");
			if (theRE.test(theFieldValue)) {
			} else {
				alert("Special characters cannot be used as part of your login\nunless your username is an email address, in which case\nyou need to enter the entire address.");
				eval(theField + ".value = ''");
				retVal = 0;
			}
		}
	}
	if (retVal) {
		return(true);
	} else {
		return(false);
	}
}


function trapEmail(theForm,theField,theFlag) {
	retVal = 1;
	with (eval("document." + theForm)) {
		theFieldValue = new String(eval(theField + ".value"));
		if (theFlag) {
			// Required Entry
			theRE = eval("/^[a-z0-9_\.-]+[@]{1}[a-z0-9_-]+\.[a-z]{2,4}$|^[a-z0-9_\.-]+[@]{1}[a-z0-9_-]+\.[a-z0-9_-]+\.[a-z]{2,4}$/i");
		} else {
			theRE = eval("/^$|^[a-z0-9_\.-]+[@]{1}[a-z0-9_-]+\.[a-z]{2,4}$|^[a-z0-9_\.-]+[@]{1}[a-z0-9_-]+\.[a-z0-9_-]+\.[a-z]{2,4}$/i");
		}
		if (theRE.test(theFieldValue)) {
		} else {
			alert("Please use the complete email address (eg. me@mymailbox.com).");
			eval(theField + ".value = ''");
			retVal = 0;
		}
	}
	if (retVal) {
		return(true);
	} else {
		return(false);
	}
}

	// Rowset Routines
	// Recordset Routines
	// Insert Routines
	// Update Routines
	// Delete Routines	
