function isWorkshopSelected() {
  for (i=0;i<document.myForm.workshopID.length;i++) {
    if (document.myForm.workshopID[i].checked) { return true; }
  }
  if(document.myForm.workshopID.checked)
      return true;
  return false;  
}
function step0()
{
	$("signup1").style.display="block";
	$("signup2").style.display="none";
	$("signup3").style.display="none";
  $("videobox").style.display="block";
}
function step1(city)
{  
  document.getElementById("selectedCity").value = city;
  myRand=parseInt(Math.random()*99999999); 
  param = 'city='+city;
  new Ajax.Request('getWorkshopInfo.asp',{method: 'get', parameters: param, onComplete: showWorkshops } ); 
  urchinTracker("3rc/signup2");
}
function step2(hotel, wsDate)
{
  if (isWorkshopSelected()) {
    $("selectedDate").innerHTML = wsDate;
    $("selectedLocation").innerHTML = hotel;
  	$("signup1").style.display="none";
  	$("signup2").style.display="none";
  	$("signup3").style.display="block";
  	$("firstname").focus();
  	urchinTracker("3rc/signup3");
  } else {
    alert("Please select a workshop."); 
  }
}

function showWorkshops(originalRequest) 
{  
  if (originalRequest.responseText == 0) {
    document.location = "ftk.asp";
  } else {        
    $("signup2").innerHTML = originalRequest.responseText;
    $("videobox").style.display="none";
  	$("signup1").style.display="none";
  	$("signup2").style.display="block";
  	$("signup3").style.display="none";  	
  }
}
function showBlurb(blurb)
{
	closeBlurb(); // Clear any existing blurb
	$("blurbsNav").style.display="none";
	$("blurbsBox"+blurb).style.display="block";
	for(i=1;i<=3;i++){
		if(i!=blurb) $("blurbsImg"+i).className="grayed";
	}
}
function closeBlurb(blurb)
{
	$("blurbsNav").style.display="block";
	$("blurbsBox1").style.display="none";
	$("blurbsBox2").style.display="none";
	$("blurbsBox3").style.display="none";
	$("blurbsImg1").className="";
	$("blurbsImg2").className="";
	$("blurbsImg3").className="";
}
//function $(id) { return document.getElementById(id) }


  
  function set_location(location, workshopID)
	{
		location = location.replace('&apos;', "'");
		location = location.replace('&apos;', "'");
		$('location').innerHTML = location;
    $('workshopID').value = workshopID;
    //new Effect.ScrollTo('location', {offset: -20});
  }
  function set_location2(location, workshopID)
	{
		location = location.replace('&apos;', "'");
		location = location.replace('&apos;', "'");
		//$('location').innerHTML = location;
    $('workshopID').value = workshopID;
    //new Effect.ScrollTo('location', {offset: -20});
  }
  
  function get_zip(zip)
  {
    //The purpose of myRand is to prevent browser caching of the update_form_ajax.asp by having 
    //the url passed to it be different everytime, therefore tricking the browser
    myRand=parseInt(Math.random()*99999999); 
    param = 'zip='+zip+'&random='+myRand;
    //The ajax object is created and calls the update_form_ajax.asp page 
    //and passes it the param variable using a get request
    //When the function completes it calls the show_response function passing it the output from the 
    //update_form_ajax.asp page
    new Ajax.Request('get_city_state_ajax.asp',{method: 'get', parameters: param, onComplete: show_response_city_state } )
  }
  
  function show_response_city_state(originalRequest)
	{
		//Splits the response text and updates the associated form elements
    parsed_string = originalRequest.responseText.split("|");
    
    if(parsed_string[0] == $('zip_show').value && parsed_string[0] != "")
    {
      $('zip').value = parsed_string[0];
      $('city').value = parsed_string[1];
      $('state').value = parsed_string[2];
      $('zip_show').value = parsed_string[0] + "("+parsed_string[1]+", "+parsed_string[2]+")";
    }
    else
    {
      $('zip').value = "";
      $('city').value = "";
      $('state').value = "";
      $('zip_show').value = "";
    }
  }
function isValidEmail(str) {  
  if (str != "" )
  {	  
	  var testValue=false;
	  // older browsers can't use this RegExp syntax
	  if (window.RegExp) {    
	    var filter=/^[a-zA-Z0-9._&-]+@([a-zA-Z0-9.&-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	    testValue = filter.test(str);
	  } else {
	    if(str.indexOf("@") >= 0) {
	      testValue=true;
	    } else {
	      testValue=false;
	    }     
	  }  
	  if (!testValue) {		  
		  return false;
    }
  }
  return testValue;
}


function validateRegisterForm(f) 
{
  firstname = f.firstname.value;
  lastname = f.lastname.value;
  address = f.address.value;
  city = f.city.value;
  state = f.state.value;
  email = f.email.value;
  phone = f.phone.value;
  zip = f.zip.value;
  source = f.source.value;
    
  if(firstname == ""){
    alert("Please enter your first name.");
    return false;
  }  
  else if(lastname == ""){
    alert("Please enter your last name.");
    return false;
  }
  else if(address == ""){
    alert("Please enter your street address.");
    return false;
  }
  else if(city == ""){
    alert("Please enter your city.");
    return false;
  }
  else if(state == ""){
    alert("Please enter your state.");
    return false;
  }
  else if(zip == ""){
    alert("Please enter your zip.");
    return false;
  }
  else if(!isValidEmail(email)){
    alert("Please enter a valid email.");
    return false;
  }  
  else if(phone == ""){
    alert("Please enter your phone number.");
    return false;
  }
  else if(source == ""){
    alert("Please select how you heard about this workshop.");
    return false;
  }
  else
  {
    return true;
  }
}

function lookupzip(z) {
  if (z == "" || z == "Enter Zip Code") {
    //alert("Please enter your zip code.");
    $('lookupmsg').innerHTML = "<span style=\"color: red;\">Please enter your zip code</span>";
  } else {
    myRand=parseInt(Math.random()*99999999); 
    param = 'zip='+z;
    new Ajax.Request('getWorkshopInfo.asp',{method: 'get', parameters: param, onComplete: showWorkshops } ) 
  	urchinTracker("3rc/signup2");    
  }
}

function checkEnter(e){ //e is event object passed from function invocation
var characterCode // literal character code will be stored in this variable

if(e && e.which){ //if which property of event object is supported (NN4)
e = e
characterCode = e.which //character code is contained in NN4's which property
}
else{
e = event
characterCode = e.keyCode //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
lookupzip($('ziplookup').value)
return false 
}
else{
return true 
}

}



function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}