// 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, 150, 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, 150, 300)
var myMenu5 = new ypSlideOutMenu("menu5", "down", 0, 0, 150, 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 () {
			}
		}
	}
}
*/	