//* SlideOutMenu


ypSlideOutMenu.Registry = []
ypSlideOutMenu.aniLen = 250
ypSlideOutMenu.hideDelay = 300
ypSlideOutMenu.minCPUResolution = 10

// constructor
function ypSlideOutMenu(id, dir, left, top, width, height)
{
	this.ie  = document.all ? 1 : 0
	this.ns4 = document.layers ? 1 : 0
	this.dom = document.getElementById ? 1 : 0
	this.css = "";

	if (this.ie || this.ns4 || this.dom) {
		this.id			 = id
		this.dir		 = dir
		this.orientation = dir == "left" || dir == "right" ? "h" : "v"
		this.dirType	 = dir == "right" || dir == "down" ? "-" : "+"
		this.dim		 = this.orientation == "h" ? width : height
		this.hideTimer	 = false
		this.aniTimer	 = false
		this.open		 = false
		this.over		 = false
		this.startTime	 = 0

		// global reference to this object
		this.gRef = "ypSlideOutMenu_"+id
		eval(this.gRef+"=this")

		// add this menu object to an internal list of all menus
		ypSlideOutMenu.Registry[id] = this

		var d = document

		var strCSS = "";
		strCSS += '#' + this.id + 'Container { visibility:hidden; '
		strCSS += 'left:' + left + 'px; '
		strCSS += 'top:' + top + 'px; '
		strCSS += 'overflow:hidden; z-index:10000; }'
		strCSS += '#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; '
		strCSS += 'width:' + width + 'px; '
		strCSS += 'height:' + height + 'px; '
		strCSS += 'clip:rect(0 ' + width + ' ' + height + ' 0); '
		strCSS += '}'

		this.css = strCSS;

		this.load()
	}
}

ypSlideOutMenu.writeCSS = function() {
	document.writeln('<style type="text/css">');

	for (var id in ypSlideOutMenu.Registry) {
		document.writeln(ypSlideOutMenu.Registry[id].css);
	}

	document.writeln('</style>');
}

ypSlideOutMenu.prototype.load = function() {
	var d = document
	var lyrId1 = this.id + "Container"
	var lyrId2 = this.id + "Content"
	var obj1 = this.dom ? d.getElementById(lyrId1) : this.ie ? d.all[lyrId1] : d.layers[lyrId1]
	if (obj1) var obj2 = this.ns4 ? obj1.layers[lyrId2] : this.ie ? d.all[lyrId2] : d.getElementById(lyrId2)
	var temp

	if (!obj1 || !obj2) window.setTimeout(this.gRef + ".load()", 100)
	else {
		this.container	= obj1
		this.menu		= obj2
		this.style		= this.ns4 ? this.menu : this.menu.style
		this.homePos	= eval("0" + this.dirType + this.dim)
		this.outPos		= 0
		this.accelConst	= (this.outPos - this.homePos) / ypSlideOutMenu.aniLen / ypSlideOutMenu.aniLen

		// set event handlers.
		if (this.ns4) this.menu.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
		this.menu.onmouseover = new Function("ypSlideOutMenu.showMenu('" + this.id + "')")
		this.menu.onmouseout = new Function("ypSlideOutMenu.hideMenu('" + this.id + "')")

		//set initial state
		this.endSlide()
	}
}

ypSlideOutMenu.showMenu = function(id)
{
	var reg = ypSlideOutMenu.Registry
	var obj = ypSlideOutMenu.Registry[id]

	if (obj.container) {
		obj.over = true

		// close other menus.
		for (menu in reg) if (id != menu) ypSlideOutMenu.hide(menu)

		// if this menu is scheduled to close, cancel it.
		if (obj.hideTimer) { reg[id].hideTimer = window.clearTimeout(reg[id].hideTimer) }

		// if this menu is closed, open it.
		if (!obj.open && !obj.aniTimer) reg[id].startSlide(true)
	}
}

ypSlideOutMenu.hideMenu = function(id)
{
	// schedules the menu to close after <hideDelay> ms, which
	// gives the user time to cancel the action if they accidentally moused out
	var obj = ypSlideOutMenu.Registry[id]
	if (obj.container) {
		if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
		obj.hideTimer = window.setTimeout("ypSlideOutMenu.hide('" + id + "')", ypSlideOutMenu.hideDelay);
	}
}

ypSlideOutMenu.hideAll = function()
{
	var reg = ypSlideOutMenu.Registry
	for (menu in reg) {
		ypSlideOutMenu.hide(menu);
		if (menu.hideTimer) window.clearTimeout(menu.hideTimer);
	}
}

ypSlideOutMenu.hide = function(id)
{
	var obj = ypSlideOutMenu.Registry[id]
	obj.over = false

	if (obj.hideTimer) window.clearTimeout(obj.hideTimer)

	// flag that this scheduled event has occured.
	obj.hideTimer = 0

	// if this menu is open, close it.
	if (obj.open && !obj.aniTimer) obj.startSlide(false)
}

ypSlideOutMenu.prototype.startSlide = function(open) {
	this[open ? "onactivate" : "ondeactivate"]()
	this.open = open
	if (open) this.setVisibility(true)
	this.startTime = (new Date()).getTime()
	this.aniTimer = window.setInterval(this.gRef + ".slide()", ypSlideOutMenu.minCPUResolution)
}

ypSlideOutMenu.prototype.slide = function() {
	var elapsed = (new Date()).getTime() - this.startTime
	if (elapsed > ypSlideOutMenu.aniLen) this.endSlide()
	else {
		var d = Math.round(Math.pow(ypSlideOutMenu.aniLen-elapsed, 2) * this.accelConst)
		if (this.open && this.dirType == "-")		d = -d
		else if (this.open && this.dirType == "+")	d = -d
		else if (!this.open && this.dirType == "-")	d = -this.dim + d
		else										d = this.dim + d

		this.moveTo(d)
	}
}

ypSlideOutMenu.prototype.endSlide = function() {
	this.aniTimer = window.clearTimeout(this.aniTimer)
	this.moveTo(this.open ? this.outPos : this.homePos)
	if (!this.open) this.setVisibility(false)
	if ((this.open && !this.over) || (!this.open && this.over)) {
		this.startSlide(this.over)
	}
}

ypSlideOutMenu.prototype.setVisibility = function(bShow) {
	var s = this.ns4 ? this.container : this.container.style
	s.visibility = bShow ? "visible" : "hidden"
}
ypSlideOutMenu.prototype.moveTo = function(p) {
	this.style[this.orientation == "h" ? "left" : "top"] = this.ns4 ? p : p + "px"
}
ypSlideOutMenu.prototype.getPos = function(c) {
	return parseInt(this.style[c])
}

// events
ypSlideOutMenu.prototype.onactivate		= function() { }
ypSlideOutMenu.prototype.ondeactivate	= function() { }

// JavaScript Document, Created by Raster Media, www.rastermedia.com

// General Alert Box Confirmation --------------------------------
function confirm_action ( message, action ) {
  input_box = confirm ( message );
  if ( input_box == true ) {
    window.location.href = action;
  }
 }


// General PopUp Window ------------------------------------------
function new_window(url,wx,hx) {
    newwin = window.open(url,"win",'toolbar=0,location=0,directories=0,scrollbars=1,resizable=1,status=1,menubar=0,width='+wx+',height='+hx);
}


// SlideOut Menu Script (id, dir, left, top, width, height)-------
var myMenu1 = new ypSlideOutMenu("menu1", "down", 0, 0, 146, 300)
var myMenu2 = new ypSlideOutMenu("menu2", "down", 0, 0, 150, 300)
var myMenu3 = new ypSlideOutMenu("menu3", "down", 0, 0, 150, 300)
var myMenu4 = new ypSlideOutMenu("menu4", "down", 0, 0, 140, 300)
var myMenu5 = new ypSlideOutMenu("menu5", "down", 0, 0, 105, 300)
var myMenu6 = new ypSlideOutMenu("menu6", "down", 0, 0, 150, 300)
var myMenu7 = new ypSlideOutMenu("menu7", "down", 0, 0, 150, 300)

ypSlideOutMenu.writeCSS();


// clear input box default value on focus ------------------------
function clearText(thefield){
	if (thefield.defaultValue==thefield.value)
	thefield.value = "";
}

// replace default value if they didn't enter anything
function replaceText(thefield){
	if (thefield.value=="")
	thefield.value = thefield.defaultValue;
}
//-----------------------------------------------------------------


function isNum(passedVal) {
	for (i=0; i<passedVal.length; i++) {
		if (passedVal.charAt(i) <"0") {
			return true // return true if not a number
		}

		if (passedVal.charAt(i) >"9") {
			return true // return true if fnot a number
		}
	}
	return false
	}

function validEmail(email) {
	invalidChars = " /:,;"

	if (email == "") {						// cannot be empty
		return false
	}

	for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			return false
		}
	}

	atPos = email.indexOf("@",1)			// there must be one "@" symbol

	if (atPos == -1) {
		return false
	}

	if (email.indexOf("@",atPos+1) != -1) {	// and only one "@" symbol
		return false
	}

	periodPos = email.indexOf(".",atPos)

	if (periodPos == -1) {					// and at least one "." after the "@"
		return false
	}

	if (periodPos+3 > email.length)	{		// must be at least 2 characters after the "."
		return false
	}
	return true
	}

function verForm(f) {
  var msg = "";
  if (f.first_name.value == "") {
    msg = " - First Name is required.\n";
  }

  if (f.last_name.value == "") {
    msg = msg + " - Last Name is required.\n";
  }

  if (f.phone.value == "") {
    msg = msg + " - Phone Number is required.\n";
  }

  if (f.street.value == "") {
    msg = msg + " - Street Address is required.\n";
  }

  if (f.city.value == "") {
    msg = msg + " - City is required.\n";
  }

  if (f.state.value == "") {
    msg = msg + " - State is required.\n";
  }

	if (!validEmail(f.email.value)) {
	  msg = msg + " - Please enter a valid Email Address.\n";
	}

  if (f.zip.value == "" || f.zip.value.length != 5) {
    msg = msg + " - Please enter a valid 5 digit zip code.\n";
  }

  if (f.lead_source.value == "") {
    msg = msg + " - Please tell us how you heard about Streamline Tower.\n";
  }

  //if ( eval("f.00N30000000kauG.value=='';") ) {
  //  msg = msg + " - Unit Location is required.\n";
  //}

  /*
  var sf_fields = new Array(
    Array("00N30000000kauG", " - Unit Location is required.\n"),
    Array("00N30000000kauH", " - Unit Type is required.\n"),
    Array("00N30000000kauK", " - Price Range is required.\n"),
    Array("lead_source", " - Please tell us how you heard about us.\n"),
    Array("00N30000000qSri", " - Please specify whether you own or rent your home.\n"),
    Array("00N30000000qTPn", " - Gross Annual Income is required.\n"),
    Array("00N30000000qTPs", " - Down Payment Amount is required.\n"),
    Array("00N30000000qTAz", " - Current Employer is required.\n"),
    Array("00N30000000kauI", " - Purchase Timeframe is required.\n")
  )

  for(i = 0; i < sf_fields.length; i++) {
    if(eval("f."+sf_fields[i][0]+".value=='';")) {
      msg = msg + sf_fields[i][1];
    }
  }
  */
  if ( msg != "" ) {
    alert("Errors found: \n\n" + msg + "\n Please correct these errors and re-submit.  Thank you.");
    return false;
  }else{
    return true
  }
}

//exit pop-up-------------------------------------------
/*
window.onunload = function () {
	new_window('/exit.php',350,540);
}

/* the following will, once the document is loaded, step through all of the links on the page and set each link, when clicked, to clear the above handler

window.onload = function () {
	for (var i=0; i<document.links.length; i++) {
		document.links[i].onclick = function () {
			window.onunload = function () {
			}
		}
	}
}
*/	
