
   var reg_pjusername = null;

	function reg_handleEnterKeyInPasswordField (e)
	{
	   try {
	   
		  var keynum;
		  var keychar;
		  var numcheck;
	
		  if(window.event) { // IE
			 keynum = e.keyCode;
		  } else if(e.which) { // Netscape/Firefox/Opera
			 keynum = e.which;
		  }
		  
		  /**
		  * If the user hit the enter key, log them in.
		  */
		  if ( keynum == 13 ) {
			  reg_registrationGetWebMailContacts ();
			 //doLogIn( afterLoginCallback );
		  }
	  } catch ( excHide ) {
		 // Do nothing in case all this crud breaks in some browser.
	  }
	  return true;
	}


   function reg_showDiv ( divId ) {
	   var div = document.getElementById ( divId );
	   if ( div ) {
		   div.style.display = "block";
	   }
   }

   function reg_hideDiv ( divId ) {
	   var div = document.getElementById ( divId );
	   if ( div ) {
		   div.style.display = "none";
	   }
   }

function reg_showRegistrationScreen () {
	   
	   
	   var login_loginDialog = document.getElementById ("login_loginDialog");
	   if (  login_loginDialog ) {
	      login_loginDialog.style.display = "none";
	   }
	   
	   
	   var reg_registrationDialog = document.getElementById ("reg_registrationDialog");
	   reg_registrationDialog.style.display = "block";
	   
	   reg_showDiv ( "reg_registrationPage1" );
	   reg_hideDiv ( "reg_registrationInvitePage" );
	   reg_hideDiv ( "reg_registrationCompletePage" );
	   urchinTracker('/show_reg/step1.html');
	   
	  // alert ( "SHOWING?" );
   }

   function reg_hideRegistrationScreen () {

	   var reg_registrationDialog = document.getElementById ("reg_registrationDialog");
	   reg_registrationDialog.style.display = "none";
	   
	   
   }

   function login_showLoginScreen () {
	   
	  // alert ( "SHOW REG CALLED" );
	   
	 //  var dialogBoxesDiv = document.getElementById ( "dialogBoxesDiv" );
	 //  dialogBoxesDiv.style.display = "block";
	 //  dialogBoxesDiv.style.backgroundColor = "#ff0000";
       //dialogBoxesDiv.style.overflow = "visible";
	   
	   var reg_registrationDialog = document.getElementById ("reg_registrationDialog");
	   reg_registrationDialog.style.display = "none";
	   
	   var login_loginDialog = document.getElementById ("login_loginDialog");
	   login_loginDialog.style.display = "block";
	   
	  // alert ( "SHOWING?" );
   }

   function login_hideLoginScreen () {
	   
	   var login_loginDialog = document.getElementById ("login_loginDialog");
	   login_loginDialog.style.display = "none";
	   
	 //  var dialogBoxesDiv = document.getElementById ( "dialogBoxesDiv" );
	 //  dialogBoxesDiv.style.display = "none";

   }

   
   function _private_reg_stringIsBlank ( str ) {
		var blankRE=/^[\s]+$/
		if ( str == "" || blankRE.test(str) ) {
			return true;
		} else {
			return false;
		}
   }
   
   function _private_reg_isEmailValid ( _email ) {
		
		var isValid = false;
		
		var containsAt = (_email.indexOf ( "@" ) > 0);
		var containsDot = (_email.indexOf ( "." ) > 0);
		var idxEndOfEmailPart = _email.lastIndexOf( "." );
		var idxOfAt = _email.indexOf( "@" );
		
		if ( containsAt && containsDot && ( idxOfAt < (idxEndOfEmailPart - 1) ) && idxEndOfEmailPart < ( _email.length - 1 ) ) {
			isValid = true;
		}
		
		return isValid;
   }   

   var m_reg_spinnerDiv = null;

   function _private_reg_showSpinner () {
		
	   _private_reg_hideSpinner
	   
	   var spinnerDiv = document.createElement ( "div" );
	   spinnerDiv.style.width = "60px";
	   spinnerDiv.style.height = "60px";
	   //toolTipDiv.style.backgroundColor = "#ff0000";
	   spinnerDiv.style.position = "absolute";
	   spinnerDiv.style.top = 150 + "px";
	   spinnerDiv.style.left = 370 + "px";
	   spinnerDiv.id = "spinnerDiv";
	   spinnerDiv.setAttribute ( "id", "spinnerDiv" );
	   
	   var parentPage = document.getElementById ( "reg_registrationPodContainer" );
	   parentPage.appendChild ( spinnerDiv );
	   
	   m_reg_spinnerDiv = spinnerDiv;
	   
		
	
	   var swfContentPath = "spinnerAnimation.swf"; 
	   
	   var so = new SWFObject( swfContentPath, "reg_spinner", "100%", "100%", "9" ); //, backColor );
	   so.addParam("quality", "high");
       so.addParam("wmode", "transparent" ); 
       so.addParam("allowScriptAccess", "always");
       so.addParam("salign", "tl" ); //tl");
	   so.write( "spinnerDiv" );
	   	
	}  
	
   
   function _private_reg_hideSpinner () {
	  if ( m_reg_spinnerDiv ) {
	     m_reg_spinnerDiv.parentNode.removeChild(m_reg_spinnerDiv);
		 m_reg_spinnerDiv = null;
	  }
   }
	

   function reg_sendUserRegistrationUserToBackEnd () {
	   _private_reg_showSpinner ();
	   
	   try {
	      reg_postRegistrationData ();
	   } catch ( exc ) {
		    alert ( "EXC: " + exc );
	   }
	   
	   //setTimeout ( reg_registrationComplete, 2000 );
   }

   function reg_handleRegistrationError ( errorString ) {
	   
	   _private_reg_hideSpinner ();
	   
	   reg_showNewRegistrationFormError ( errorString );
	   
	   //alert ( "REG ERROR: " + errorString );
   }
 
   function reg_handleRegistrationWithBackEndComplete ( pjuid ) {
	   
	   _private_reg_hideSpinner ();
	   
	   var newUserEmail = document.getElementById ( "reg_registrationEmail" );
	   var webEmail = document.getElementById ( "reg_registrationInviteWebMailAddress" );
	   
	   webEmail.value = newUserEmail.value;
	   
         var reg_registrationPage1 = document.getElementById ( "reg_registrationPage1" );
	     reg_registrationPage1.style.display = "none";

       if ( pjuid != null && pjuid != "null" && pjuid != "undefined" ) {
          var reg_registrationInvitePage = document.getElementById ( "reg_registrationInvitePage" );
	      reg_registrationInvitePage.style.display = "block";
	   } else {
		   var reg_registrationCompletePage = document.getElementById ( "reg_registrationCompletePage" );
		   reg_registrationCompletePage.style.display = "block";
	   }
	   
	    if ( m_reg_afterRegistrationCallback  ) {
			m_reg_afterRegistrationCallback  (pjuid);
		}

   }
   
   function reg_registerNewUserAndShowInvitePage () {
	   
	  toolTips_hideToolTip ();
	   
	  if ( reg_validateNewUserInformation () ) {
	      var reg_page1RegistrationFormError = document.getElementById ( "reg_page1RegistrationFormError" );
	      reg_page1RegistrationFormError.style.display = "none";
		  
		  reg_sendUserRegistrationUserToBackEnd ();
	  }
   }
   
   function reg_validateNewUserInformation () {
	   
	   var userName = document.getElementById ( "reg_registrationUserName" );
	   var password = document.getElementById ( "reg_registrationPassword" ); 
	   var retypePassword = document.getElementById ( "reg_registrationReTypePassword" );
	   var email = document.getElementById ( "reg_registrationEmail" );
	   
	   if ( _private_reg_stringIsBlank ( userName.value ) ) {
		   reg_showNewRegistrationFormError ( "Please enter a user name." );
		   return false;
	   }
	   
	   if ( userName.value.length < 2 ) {
		   reg_showNewRegistrationFormError ( "Your user name must be at least 2 characters." );
		   return false;
	   }
	   
	   if ( _private_reg_stringIsBlank ( password.value ) ) {
		   reg_showNewRegistrationFormError ( "Please enter a password." );
		   return false;
	   }
	   
	   if ( password.value.length < 4 ) {
		   reg_showNewRegistrationFormError ( "Your password must be at least 4 characters." );
		   return false;
	   }
	   
	   if ( _private_reg_stringIsBlank ( retypePassword.value ) ) {
		   reg_showNewRegistrationFormError ( "Please re-type your password." );
		   return false;
	   }
	   	   
	   if ( password.value != retypePassword.value ) {
		   reg_showNewRegistrationFormError ( "Your passwords do not match." );
		   return false;
	   }
	   
	   if ( _private_reg_stringIsBlank ( email.value ) ) {
		   reg_showNewRegistrationFormError ( "Please enter an email address." );
		   return false;
	   }
	   
	   if ( !_private_reg_isEmailValid ( email.value ) ) {
		   reg_showNewRegistrationFormError ( "Please enter a valid email address." );
		   return false;
	   }
	   
	   return true;
   }
   
   function reg_showNewRegistrationFormError ( errorText ) {
	   var reg_page1RegistrationFormError = document.getElementById ( "reg_page1RegistrationFormError" );
	   reg_page1RegistrationFormError.style.display = "block";
	   reg_page1RegistrationFormError.innerHTML = errorText;
   }
   
   // reg_page1RegistrationFormError
   
   function reg_validateWebMailInformation () {
	   
	   
	   var email = document.getElementById ( "reg_registrationInviteWebMailAddress" );
	   var password = document.getElementById ( "reg_registrationInviteWebMailPassword" ); 
	   
	   if ( _private_reg_stringIsBlank ( email.value ) ) {
		   reg_showWebMailFormError ( "Please enter you web email address." );
		   return false;
	   }
	   
	   if ( !_private_reg_isEmailValid ( email.value ) ) {
		   reg_showWebMailFormError ( "Please enter a valid web email address." );
		   return false;
	   }
	   
	   if ( _private_reg_stringIsBlank ( password.value ) ) {
		   reg_showWebMailFormError ( "Please enter your web email password." );
		   return false;
	   }
	   
	   
	   
	   return true;
   }
   
   function reg_showWebMailFormError ( errorText ) {
	   var reg_webEmailFormError = document.getElementById ( "reg_webEmailFormError" );
	   reg_webEmailFormError.style.display = "block";
	   reg_webEmailFormError.innerHTML = errorText;
   }
   
   
   function reg_getWebMailContactsFromBackEnd () {
	   _private_reg_showSpinner ();
	   
	   setTimeout ( reg_webContactsAvailable, 2000 );
   }
   
   function reg_webContactsAvailable () {
	   
	   _private_reg_hideSpinner ();
	
      var reg_registrationWebMailDiv = document.getElementById ( "reg_registrationWebMailDiv" );
	  reg_registrationWebMailDiv.style.display = "none";
	  
	  var reg_registrationWebMailContactsDiv = document.getElementById ( "reg_registrationWebMailContactsDiv" );
	  reg_registrationWebMailContactsDiv.style.display = "block";
	  
	  var data = new Object ();
	  data.contacts = new Object ();
	  data.contacts.contacts = m_dummyContacts;
	  
	  try {
	  reg_handleContactsFetched ( data, null );
	  } catch ( exc ) {
	     alert ( "EXC: " + exc );
	  }
	
/*	   
         var reg_registrationPage1 = document.getElementById ( "reg_registrationPage1" );
	     reg_registrationPage1.style.display = "none";

         var reg_registrationInvitePage = document.getElementById ( "reg_registrationInvitePage" );
	     reg_registrationInvitePage.style.display = "block";
*/	   
   }
   
   /*
   function reg_sendInviteFriendsMessageToBackEnd () {
	   _private_reg_showSpinner ();
	   
	  // setTimeout ( reg_inviteFriendsServiceCallComplete, 2000 );
   }
   */


/**
* START OF INSERTED STUFF TO HANDLE INVITE EMAILS
**/


   function reg_createEmailListArray ( originalEmailFieldValue ) {
        var addressesArray = null;
		
		if ( originalEmailFieldValue.indexOf ( ";" ) > 0 ) {
			addressesArray = originalEmailFieldValue.split (";");
			// addressesArray = addresses.
		} else if ( originalEmailFieldValue.indexOf ( "," ) > 0 ) {
			addressesArray = originalEmailFieldValue.split (",");
		} else {
			addressesArray = originalEmailFieldValue.split (" ");
		}
	
		return addressesArray;
   }


	function reg_createCommaSeparatedEmailList ( originalEmailFieldValue ) {
	
	//alert ( "create comma sep email list input: " + originalEmailFieldValue );
	
	   var addresses = null;
	   
	   var addressesArray = reg_createEmailListArray ( originalEmailFieldValue );
			
		addresses = addressesArray.join ( ", " );
		
		return addresses;
	}


/// reg_registrationInviteEmailsList,   m_reg_contactsList


    var m_reg_landingPageUrl = "http://www.popjax.com";
	
	function reg_setEmailInviteLandingPageUrl ( _url ) {
		m_reg_landingPageUrl = _url;
	}

    function reg_sendInviteFriendsMessageToBackEnd () {
		
	   _private_reg_showSpinner ();	  // alert ( "share question" );

	   var sendQuestionToEmail = document.getElementById ( "reg_registrationInviteEmailsList" );

	   var sendQuestionToEmailValue = sendQuestionToEmail.value;

	   var toEmailValueEnteredByHand = "";
	   var anyToAddressesEnteredByHand = false;
	   var anyWebEmailAddresses = false;
	   
       if ( !_private_reg_stringIsBlank(sendQuestionToEmailValue) ) {
		   toEmailValueEnteredByHand = reg_createCommaSeparatedEmailList (sendQuestionToEmailValue);
		   anyToAddressesEnteredByHand = true;
	   }

       var arraySelectedWebMailContacts = new Array ();
	   
	   for ( var idx = 0; idx < m_reg_contactsList.length; idx++ ) {
		   var contactObject = m_reg_contactsList[idx];
		   if ( contactObject.isSelected == true ) {
			  anyWebEmailAddresses = true;
              arraySelectedWebMailContacts.push(contactObject.contact.emailAddress);
		   }
	   }
	   
	   var allToAddresses = sendQuestionToEmailValue;
	   var webMailToAddresses = "";
	   if ( arraySelectedWebMailContacts.length > 0 ) {
		   webMailToAddresses = arraySelectedWebMailContacts.join("," );
		   if ( anyToAddressesEnteredByHand ) {
			   allToAddresses += ", " + webMailToAddresses;
		   } else {
			   allToAddresses = webMailToAddresses;
		   }
	   }
    //   alert ( "from: " + fromEmailValue );
	//   alert ( "allToAddresses: " + allToAddresses );
	
	   try {
		  // DataServiceBackEnd.DUMMY_DATA = true;
		   
          var origin = "site";
		  
        //  DataServiceBackEnd.DUMMY_DATA = true;
		
		  if ( anyToAddressesEnteredByHand || anyWebEmailAddresses ) {
		     dataService_emailInvites ( reg_inviteFriendsServiceCallComplete, m_pjuid, reg_pjusername, origin, allToAddresses, "", m_reg_landingPageUrl );
		  } else {
			 // alert ( "SKIPPING THE SEND" );
			  reg_inviteFriendsServiceCallComplete ( null, null );			  
		  }
		//  DataServiceBackEnd.DUMMY_DATA = false;

       } catch ( excData ) {
		   alert ( "DATA ERROR: " + excData );
		   _private_reg_hideSpinner ();
	   }
	   /*
	   	var sendQuestionMessageValue = document.getElementById ( "sendQuestionMessage" ).value;

   sendQuestionMessageValue 
   
    dataService_emailQuestion ( handleQuestionSentToFriend, m_currentQuestionObject.id, sendQuestionFromEmailValue, 
	   sendQuestionToEmailValue, sendQuestionMessageValue ); 

	   */
   }
   


/**
* END OF INSERTED STUFF TO HANDLE INVITE EMAILS
**/

   function reg_inviteFriendsServiceCallComplete ( data, xml ) {
	   
	   _private_reg_hideSpinner ();
	   
      var reg_registrationInvitePage = document.getElementById ( "reg_registrationInvitePage" );
	  reg_registrationInvitePage.style.display = "none";

      var reg_registrationCompletePage = document.getElementById ( "reg_registrationCompletePage" );
	  reg_registrationCompletePage.style.display = "block";
	   
   }

   function reg_registerDoInvite () {
	
	   toolTips_hideToolTip  ();
	  urchinTracker('/show_reg/step3.html');
	   try {
      reg_sendInviteFriendsMessageToBackEnd ();
	   } catch ( exc ) {
		   alert ( "EXC: " + exc );
	   }
	  
   }
   
   function reg_handleRegistrationEmailProviderSelected () {
      var reg_registrationInviteEmailProvider = document.getElementById ( "reg_registrationInviteEmailProvider" );
	  var selectedProvider = reg_registrationInviteEmailProvider.value;
	  //alert ( "SELECTED: " + selectedProvider );
	  
	  var reg_registrationInvitePageEmailMessage = document.getElementById ( "reg_registrationInvitePageEmailMessage" );
	  var reg_registrationInviteWebMailPasswordLabel = document.getElementById ( "reg_registrationInviteWebMailPasswordLabel" );
	  
	  switch ( selectedProvider ) {
	     case "yahoo":
		    reg_registrationInvitePageEmailMessage.innerHTML = 
			   "Enter your Yahoo details below.  Then click \"Get Contacts\" to chooser from your Yahoo email contacts.";
			reg_registrationInviteWebMailPasswordLabel.innerHTML = "Yahoo password:";
		    break;
	
	     case "hotmail":
		    reg_registrationInvitePageEmailMessage.innerHTML = 
			   "Enter your Hotmail details below.  Then click \"Get Contacts\" to chooser from your Hotmail email contacts.";
			   reg_registrationInviteWebMailPasswordLabel.innerHTML = "Hotmail password:";
		    break;
			
	     case "gmail":
		    reg_registrationInvitePageEmailMessage.innerHTML = 
			   "Enter your Gmail details below.  Then click \"Get Contacts\" to chooser from your Gmail email contacts.";
			   reg_registrationInviteWebMailPasswordLabel.innerHTML = "Gmail password:";
		    break;
			
		 case "aol":
		    reg_registrationInvitePageEmailMessage.innerHTML = 
			   "Enter your AOL details below.  Then click \"Get Contacts\" to chooser from your AOL email contacts.";
			   reg_registrationInviteWebMailPasswordLabel.innerHTML = "AOL password:";
		    break;

		 case "other":
		    reg_registrationInvitePageEmailMessage.innerHTML = 
			   "Enter your web email details below.  Then click \"Get Contacts\" to chooser from your web email contacts.";
			   reg_registrationInviteWebMailPasswordLabel.innerHTML = "Email password:";
		    break;
			
	     
	  }
   }
   
   /**
   * This fetches the contacts list from the user's web email.
   */
   function reg_fetchContactList () {
    //  return;
	
	//alert ( "CALELD reg_fetchContactList: " );
	
      var youWebEmailAddress = document.getElementById ( "reg_registrationInviteWebMailAddress" );
	  var youWebEmailAddressValue = youWebEmailAddress.value;
	  
	  var youWebEmailPassword = document.getElementById ( "reg_registrationInviteWebMailPassword" );
	  var youWebEmailPasswordValue = youWebEmailPassword.value;
	  
	 // alert ( "ABOUT TO CALL BACK END" );
	  try {
	     getEmailContactList ( reg_handleContactsFetched, youWebEmailAddressValue, youWebEmailPasswordValue ); 
	  } catch ( exc ) {
	    alert ( "EXC: " + exc );
	  } 
	 //alert ( "youWebEmailAddress: " + youWebEmailAddressValue + "  youWebEmailPasswordValue: " + youWebEmailPasswordValue );
   }
   
   var m_reg_contactsList = Array ();
   
   function reg_toggleCheckBox ( idx ) {
   
  // alert ( "TOGGLE" );
   
      var contactObject = m_reg_contactsList[Number(idx)];
      var checkBoxId = "checkbox" + idx;
      var checkbox = document.getElementById ( checkBoxId );
	  if ( checkbox.checked ) {
	     checkbox.checked = false;
	  } else {
	     checkbox.checked = true;
	  }
	  if ( checkbox.checked ) {
	     contactObject.isSelected = true;
	  } else {
	     contactObject.isSelected = false;
	  }
	  
   }
   
   function reg_handleCheckBoxChanged ( idx ) {
      var contactObject = m_reg_contactsList[Number(idx)];
      var checkBoxId = "checkbox" + idx;
      var checkbox = document.getElementById ( checkBoxId );
	  if ( checkbox.checked ) {
	     contactObject.isSelected = true;
	  } else {
	     contactObject.isSelected = false;
	  }
	//  alert ( "NOW IS CHECKED: " + checkbox.checked );
   }
   
   function reg_deselectAllContacts () {
      for ( var idx = 0; idx < m_reg_contactsList.length; idx++ ) {
	     var contactObject = m_reg_contactsList[idx];
		 contactObject.isSelected = false;
		 var checkBoxId = "checkbox" + idx;
		 var checkbox = document.getElementById ( checkBoxId );
		 checkbox.checked = false;
	  }
   }
   
   function reg_selectAllContacts () {
      for ( var idx = 0; idx < m_reg_contactsList.length; idx++ ) {
	     var contactObject = m_reg_contactsList[idx];
		 contactObject.isSelected = true;
		 var checkBoxId = "checkbox" + idx;
		 var checkbox = document.getElementById ( checkBoxId );
		 checkbox.checked = true;
	  }
   }
   
   
   var m_dummyContacts = [
      { contactName:"arnie", emailAddress:"arnie@aol.com" },
      { contactName:"Aardvark", emailAddress:"Aardvark@yahoo.com" },
      { contactName:"April", emailAddress:"April@yahoo.com" },
      { contactName:"Aziz", emailAddress:"Aziz@yahoo.com" },
      { contactName:"Barney", emailAddress:"Barney@yahoo.com" },
      { contactName:"betty", emailAddress:"betty@yahoo.com" },
      { contactName:"bill", emailAddress:"bill@yahoo.com" },
      { contactName:"carrie", emailAddress:"carrie@yahoo.com" },
      { contactName:"catherine", emailAddress:"catherine@yahoo.com" },
      { contactName:"candice", emailAddress:"candice@yahoo.com" },
      { contactName:"canola_oil", emailAddress:"canola_oil@yahoo.com" },
      { contactName:"david", emailAddress:"david@yahoo.com" },
      { contactName:"derick", emailAddress:"derick@yahoo.com" }
   ];
   

  
   function reg_handleContactsFetched ( data, xml ) {
	  
	// alert ( "FETCHED" );
	// alert ( "FETCHED data: " + data );
	  
	  if ( data.code == "GET_EMAIL_CONTACT_LIST_ERROR" ) {
		    _private_reg_hideSpinner ();
		  //alert ( " ERROR: " + data.errorMessage );
		  reg_showWebMailFormError ( data.errorMessage  );
		  return;
	  }
	  
	  var reg_registrationWebMailContactsDiv = document.getElementById ( "reg_registrationWebMailContactsDiv" );
	  
	  var contacts = data.contacts.contacts;
	  
	  reg_registrationWebMailContactsDiv.innerHTML = contacts.length + " Contacts Found";
	  
	  m_reg_contactsList = new Array ();
	  var strHTML = "";
	  
	  
	  if ( contacts.length > 0 ) {
		  
	  strHTML += "<div style='padding:4px; padding-top:10px; margin-bottom:2px;'><a style='color:#222222;' href='JavaScript:reg_selectAllContacts()'/>Select All</a>&nbsp;&nbsp;<a style='color:#222222;' href='JavaScript:reg_deselectAllContacts()'/>Deselect All</a></div>";
		  
	     for ( var idx = 0; idx < contacts.length; idx++ ) {
		    var contact = contacts[idx];
			var contactObject = new Object ();
			contactObject.contact = contact;
			contactObject.isSelected = true;
			m_reg_contactsList.push(contactObject);
		
		    var checkboxId = "checkbox" + idx;
			
		    var contactHTML = "<div style='padding:4px; margin-bottom:2px;'><input id='" + checkboxId + "' onclick=\"reg_handleCheckBoxChanged('" + idx + "')\" type='checkbox' checked='true' style='padding:0; margin:0;' /> <span style='padding:10px; cursor:pointer;' onclick=\"reg_toggleCheckBox('" + idx + "')\" >" + contact.contactName + " - " + contact.emailAddress + "</span></div>";
			strHTML += 	contactHTML;
		 }
		 
		 
		 strHTML += "<div style='padding:4px; padding-top:10px; margin-bottom:2px;'><a style='color:#222222;' href='JavaScript:reg_selectAllContacts()'/>Select All</div>";
	  }
	  
	  reg_registrationWebMailContactsDiv.innerHTML = strHTML;
	  
	   _private_reg_hideSpinner ();
	
      var reg_registrationWebMailDiv = document.getElementById ( "reg_registrationWebMailDiv" );
	  reg_registrationWebMailDiv.style.display = "none";
	  
	  var reg_registrationWebMailContactsDiv = document.getElementById ( "reg_registrationWebMailContactsDiv" );
	  reg_registrationWebMailContactsDiv.style.display = "block";
	  	  
   }
   

   
   function reg_registrationGetWebMailContacts () {
	   
	   
//alert ( " reg_registrationGetWebMailContacts called" );


	   toolTips_hideToolTip  ();
	   
	  // alert ( " reg_registrationGetWebMailContacts called" );
	   
	   try {
	  if ( reg_validateWebMailInformation () ) {
		  
		//  alert ( "GET ERROR: " );
		  
	      var reg_webEmailFormError = document.getElementById ( "reg_webEmailFormError" );
		  
		 // alert ( " reg_webEmailFormError: " + reg_webEmailFormError );
		  
	      reg_webEmailFormError.style.display = "none";
		  
		  try {
			  _private_reg_showSpinner ();
		  reg_fetchContactList ();
		  } catch ( exc ) {
			   alert ( "EXC: " + exc );
		  }
		  //reg_getWebMailContactsFromBackEnd ();
	  }
	   } catch ( excouter ) {
		    alert ( "EXCOUTER: " + excouter );
	   }
/*	   
      var reg_registrationWebMailDiv = document.getElementById ( "reg_registrationWebMailDiv" );
	  reg_registrationWebMailDiv.style.display = "none";
	  
	  var reg_registrationWebMailContactsDiv = document.getElementById ( "reg_registrationWebMailContactsDiv" );
	  reg_registrationWebMailContactsDiv.style.display = "block";
	  
	  var data = new Object ();
	  data.contacts = new Object ();
	  data.contacts.contacts = m_dummyContacts;
	  
	  try {
	  reg_handleContactsFetched ( data, null );
	  } catch ( exc ) {
	     alert ( "EXC: " + exc );
	  }
*/	  
   }
   
   function reg_initRegistrationPage () {
      reg_initToolTips ();
   }
   
   function reg_initToolTips () {
      var reg_registrationUserName = document.getElementById ( "reg_registrationUserName" );
	  reg_registrationUserName.onmouseover = function () { 
	     toolTips_showToolTip ( "reg_registrationPage1", "reg_registrationUserName", 
		    "Your user name is your nickname on the site.  It must be at least 2 characters (letters and/or numbers).  No spaces please!",
			 664, -70 );
	  }
	  reg_registrationUserName.onmouseout = toolTips_hideToolTip;
	 // reg_registrationUserName.onclick = toolTips_hideToolTip;
	  
      var reg_registrationPassword = document.getElementById ( "reg_registrationPassword" );
	  reg_registrationPassword.onmouseover = function () { 
	     toolTips_showToolTip ( "reg_registrationPage1", "reg_registrationPassword", 
		    "You need a password to log in.  It must be at least 4 characters and have no spaces.",
			 664, -20 );
	  }
	  reg_registrationPassword.onmouseout = toolTips_hideToolTip;
	 // reg_registrationPassword.onclick = toolTips_hideToolTip;
	  
	  
	  var reg_registrationReTypePassword = document.getElementById ( "reg_registrationReTypePassword" );
	  reg_registrationReTypePassword.onmouseover = function () { 
	     toolTips_showToolTip ( "reg_registrationPage1", "reg_registrationReTypePassword", 
		    "Please re-enter your password.",
			 664, 30 );
	  }
	  reg_registrationReTypePassword.onmouseout = toolTips_hideToolTip;
	 // reg_registrationReTypePassword.onclick = toolTips_hideToolTip;
	  
	  
	  var reg_registrationEmail = document.getElementById ( "reg_registrationEmail" );
	  reg_registrationEmail.onmouseover = function () { 
	     toolTips_showToolTip ( "reg_registrationPage1", "reg_registrationEmail", 
		    "We need your real email address so we can notify you for prizes.  We won't spam you or sell your info to anyone.",
			 664, 84 );
	  }
	  reg_registrationEmail.onmouseout = toolTips_hideToolTip;
	 // reg_registrationEmail.onclick = toolTips_hideToolTip;
	  
	  var reg_registrationInviteWebMailAddress = document.getElementById ( "reg_registrationInviteWebMailAddress" );
	  reg_registrationInviteWebMailAddress.onmouseover = function () { 
	     toolTips_showToolTip ( "reg_registrationInvitePage", "reg_registrationInviteWebMailAddress", 
		    "We need to use this email address to access your web mail contacts.  We don't store this address.",
			 396, 30 );
	  }
	  reg_registrationInviteWebMailAddress.onmouseout = toolTips_hideToolTip;
	 // reg_registrationInviteWebMailAddress.onclick = toolTips_hideToolTip;
	  
	  var reg_registrationInviteWebMailPassword = document.getElementById ( "reg_registrationInviteWebMailPassword" );
	  reg_registrationInviteWebMailPassword.onmouseover = function () { 
	     toolTips_showToolTip ( "reg_registrationInvitePage", "reg_registrationInviteWebMailPassword", 
		    "We need to temporarily use this password to access your web mail contacts.  We don't store this password.",
			 396, 60 );
	  }
	  reg_registrationInviteWebMailPassword.onmouseout = toolTips_hideToolTip;
	 // reg_registrationInviteWebMailPassword.onclick = toolTips_hideToolTip;
	  
	  var reg_registrationInviteEmailsList = document.getElementById ( "reg_registrationInviteEmailsList" );
	  reg_registrationInviteEmailsList.onmouseover = function () { 
	     toolTips_showToolTip ( "reg_registrationInvitePage", "reg_registrationInviteEmailsList", 
		    "If you would like, you can enter your friends' email addresses into this field.  Comma-delimited please!",
			 740, 220 );
	  }
	  reg_registrationInviteEmailsList.onmouseout = toolTips_hideToolTip;
	  //reg_registrationInviteEmailsList.onclick = toolTips_hideToolTip;
	  
	  
	  
   }
   
   var m_reg_afterRegistrationCallback = null;
   
   function reg_setAfterRegistrationCallback ( _callback ) {
	   m_reg_afterRegistrationCallback = _callback;
   }
   
	/**
	* The URL of the "register" service for popjax.com
	*/		
	//var registerUrl = "./dummyData/dummyRegisterResponse.html"; ///videocube/login.htm";
    var m_reg_registerUrl = "/videocube/login.htm";

	/**
	* Sends the registration data to the popjax.com back end using an HTTP POST.  If there is an error returned by the
	* back end, it will be displayed in the registration form.  If no error is returned, then the registration form will go
	* away and the user will be "logged in" and the "You are logged in as ..." form will show in the upper right of the screen.
	*/
	function reg_postRegistrationData () {
	
	    var strURL = m_reg_registerUrl;
		
		//strURL += ( "&uniqueCallId=" + getNextUniqueCallId () );
		
		var xmlHttpReq = false;
		var self = this;
		// Mozilla/Safari
		if (window.XMLHttpRequest) {
			self.xmlHttpReq = new XMLHttpRequest();
		}
		// IE
		else if (window.ActiveXObject) {
			self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
		}
		self.xmlHttpReq.open('POST', strURL, true);
		self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		self.xmlHttpReq.onreadystatechange = function() {
		   // alert ( "READY STATE CHANGED HTTP STATUS: " + self.xmlHttpReq.status );
			//if ( self.xmlHttpReq.status == 302 ) {
			///   alert ( " status 302 " + " READY STATE: " + self.xmlHttpReq.readyState );
			//   
			//}
			if (self.xmlHttpReq.readyState == 4) {
				//alert ( "READY STATE 4" );
				if ( self.xmlHttpReq.responseText.indexOf ( "class=\"error\"" ) > 0 ) {
				   var indexOfErrorDiv = self.xmlHttpReq.responseText.indexOf ( "class=\"error\"" );
				   var indexOfLiStart =  self.xmlHttpReq.responseText.indexOf ( "<li>", indexOfErrorDiv );
				   var indexOfLiEnd =  self.xmlHttpReq.responseText.indexOf ( "</li>", indexOfLiStart );
				   
				   var registrationErrorString = self.xmlHttpReq.responseText.substring(indexOfLiStart + 4,indexOfLiEnd);
				   // stringObject.indexOf(searchvalue,fromindex)
				 //  alert ( "User id or password incorrect LI START: " + indexOfLiStart + " END: " + indexOfLiEnd + " ERR: " + registrationErrorString );
				   
				   reg_handleRegistrationError ( registrationErrorString );
				   
				  // errorCallback( registrationErrorString );
				   
				   //$("overallRegistrationError").innerHTML = registrationErrorString;
				   
				  // showRegistrationPage (); //$("registrationPage").className = "overlayVisible";
				  // hideSpinnerLoginDiv (); // $("spinnerDuringLoginDiv").className = "overlayHidden";
				  // hideSpinner ( "spinnerDuringLoginDiv" );
				   
				} else {
				
		//		   alert ( "COOL" );
				   


                   var userId = $("userId");
				   var registrationScreenNameValue = $("reg_registrationUserName").value;
				   reg_pjusername = registrationScreenNameValue;
				   
				   userId.value = registrationScreenNameValue;

	  // $("userNameLoggedIn").innerHTML = userId.value;		
	   
	               // Hides login form on main page!???
	   			   hideLogInForm ();
				   
				//   alert ( "After hide log in" );
					
				   var pjuid = null;
				   var pjuidIdxStart = self.xmlHttpReq.responseText.indexOf ("EASY_TO_FIND_PJUID=");
				   
				   if ( pjuidIdxStart >= 0 ) {
				      pjuidIdxStart += "EASY_TO_FIND_PJUID=\"".length;
				      var pjuidIdxEnd = self.xmlHttpReq.responseText.indexOf ("\"", pjuidIdxStart+1);
				      pjuid = self.xmlHttpReq.responseText.substr(pjuidIdxStart, (pjuidIdxEnd - pjuidIdxStart) );
				   }					

                   reg_handleRegistrationWithBackEndComplete (pjuid);
/*
					if ( m_reg_afterRegistrationCallback  ) {
						m_reg_afterRegistrationCallback  (pjuid);
					}
	*/
	
				//   alert ( "YOU ARE REGISTERED AND LOGGED IN" );
				   //hideLogInForm ();
				}
				//m_currentlyLoggingInOrOut = false;
				
				// alert ( " RESP: " + self.xmlHttpReq.responseText );
			}
		}
		self.xmlHttpReq.send(reg_getRegistrationFormData());
	}
	
	function reg_getRegistrationFormData () {
		var registrationScreenNameValue = $("reg_registrationUserName").value;
		var registrationPasswordValue = $("reg_registrationPassword").value;
		//var registrationRetypePasswordValue = $("registrationRetypePassword").value;
		var registrationEmailValue = $("reg_registrationEmail").value;
				
		var autologin = $("reg_registrationRememberMe");
		var autoLoginValue = 0;
		if ( autologin.checked ) {
			autoLoginValue = 1;
		} 
		
		var registrationFormData = "mode=2&player.name=" + escape(registrationScreenNameValue);
		registrationFormData += "&player.password=" + escape(registrationPasswordValue);
		registrationFormData += "&password2=" + escape(registrationPasswordValue);
		registrationFormData += "&player.email=" + escape(registrationEmailValue);
		registrationFormData += "&j_captcha_response=blabla&x=38&y=13";
		registrationFormData += "&player.autoLogin=" + autoLoginValue;
		
	//	alert ( " registrationFormData: " + registrationFormData );
		
		// mode=2&player.name=scooby&player.password=dooo&password2=dooo&player.email=scooby%40aol.com&j_captcha_response=&x=38&y=13
		
		
		return registrationFormData;
		
	}
	

/*********************************************************************************
*
*                              POP UP LOGIN FORM STUFF

**********************************************************************************/

   function login_initLoginPage () {
      login_initToolTips ();
   }


   function login_initToolTips () {
	   
/*	   
      var reg_registrationUserName = document.getElementById ( "reg_registrationUserName" );
	  reg_registrationUserName.onmouseover = function () { 
	     toolTips_showToolTip ( "reg_registrationPage1", "reg_registrationUserName", 
		    "Your user name is your nickname on the site.  It must be at least 2 characters (letters and/or numbers).  No spaces please!",
			 664, -70 );
	  }
	  reg_registrationUserName.onmouseout = toolTips_hideToolTip;
	 // reg_registrationUserName.onclick = toolTips_hideToolTip;
	  
**/	  
	  
   }
   
   var m_login_afterLoginCallback = null;
   
   function login_setAfterLoginCallback ( _callback ) {
	   m_login_afterLoginCallback = _callback;
   }
   
   function login_showLoginFormError ( errorText ) {
	   var login_formError = document.getElementById ( "login_formError" );
	   login_formError.style.display = "block";
	   login_formError.innerHTML = errorText;
   }

   function login_hideLoginFormError () {
	   var login_formError = document.getElementById ( "login_formError" );
	   login_formError.style.display = "none";
   }


	/**
	* The URL of the "log in" service for popjax.com
	*/
	// var loginUrl = "./dummyData/loginResponse.html"; ///videocube/login.htm";
	var m_login_loginUrl = "/videocube/login.htm";
	
	function login_handleLoginWithBackEndComplete (pjuid) {	
	
	   hideNewPopUpLoginScreen ();
	   hideSpinnerLoginDiv (); /// $("spinnerDuringLoginDiv").className = "overlayHidden";
	   hideSpinner ( "spinnerDuringLoginDiv" );	   

	  // alert ( "CALLBACK: " + afterLoginCallback );
	   if ( m_login_afterLoginCallback ) {
		   m_login_afterLoginCallback (pjuid);
	   } else {
		  // alert ( "NO LOGIN CALLBACK" );
	   }
	}

	function login_getLogInPostQueryStringFromPopUp () {
	   var userId = $("login_userName");
	   var password = $("login_password");
	   reg_pjusername = userId;
	   
	   var loginString = "mode=1&player.name=" + userId.value + "&player.password=" + password.value + "&x=99&y=10";
	   
	   return loginString;		
	}

	/**
	* This does an HTTP POST to the login service in order to log the user in.
	*/
	function login_postLoginFormData() {
	    var strURL = m_login_loginUrl;
		
		login_hideLoginFormError ();
		
		//strURL += ( "?uniqueCallId=" + getNextUniqueCallId () );
		
		var xmlHttpReq = false;
		var self = this;
		// Mozilla/Safari
		if (window.XMLHttpRequest) {
			self.xmlHttpReq = new XMLHttpRequest();
		}
		// IE
		else if (window.ActiveXObject) {
			self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
		}
		self.xmlHttpReq.open('POST', strURL, true);
		self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		self.xmlHttpReq.onreadystatechange = function() {
		   // alert ( "READY STATE CHANGED HTTP STATUS: " + self.xmlHttpReq.status );
			//if ( self.xmlHttpReq.status == 302 ) {
			///   alert ( " status 302 " + " READY STATE: " + self.xmlHttpReq.readyState );
			//   
			//}
			if (self.xmlHttpReq.readyState == 4) {
				
				
				
				//alert ( "READY STATE 4" );
				if ( self.xmlHttpReq.responseText.indexOf ( "class=\"error\"" ) > 0 ) {
					login_showLoginFormError ( "User id or password incorrect" );
				  // alert ( "User id or password incorrect" );
				} else {
				  //alert ( "YOU ARE NOW LOGGED IN" );
				  
				   try {
					   setUserIsLoggedIn ( $("userId").value );  
					   
					   //if ( window["m_pjuserName"] ) {
						   window["m_pjuserName"] = getCookie ( "userIdString" ); //, userIdString );
					   //}
					   //alert  ( " USER IS: " + window["m_pjuserName"] );

                       var userId = $("userId");
				       var login_userNameValue = $("login_userName").value;
				   // <<< START OF NEW CODE TO ALWAYS SHOW User name not email if log in withemail    userId.value = login_userNameValue; END >>>

					   var pjuid = null;
					   var pjuidIdxStart = self.xmlHttpReq.responseText.indexOf ("EASY_TO_FIND_PJUID=");
					   
					   if ( pjuidIdxStart >= 0 ) {
						  pjuidIdxStart += "EASY_TO_FIND_PJUID=\"".length;
						  var pjuidIdxEnd = self.xmlHttpReq.responseText.indexOf ("\"", pjuidIdxStart+1);
						  pjuid = self.xmlHttpReq.responseText.substr(pjuidIdxStart, (pjuidIdxEnd - pjuidIdxStart) );
					   } else {
						   //alert ( "COULD NOT FIND PJUID" );
					   }
					   
//alert ( "HI SCOTT" );

						/**
						* <<< START OF NEW CODE TO SHOW USER NAME WHETHER LOG IN WITH NAME OR EMAIL ADDRESS >>>
						*/
					   var userName = null;
					   var userNameStart = self.xmlHttpReq.responseText.indexOf ("EASY_TO_FINE_PJUSER_NAME=");
					   if ( userNameStart >= 0 ) {
						  userNameStart += "EASY_TO_FINE_PJUSER_NAME=\"".length;
						  var userNameEnd = self.xmlHttpReq.responseText.indexOf ("\"", userNameStart+1);
						  userName = self.xmlHttpReq.responseText.substr(userNameStart, (userNameEnd - userNameStart) );
					   } else {
						   //alert ( "COULD NOT FIND PJUID" );
					   }
						if ( userName != null ) {
							var userIdField = document.getElementById ( "userId" );
							userIdField.value = userName;
						}
						/**
						* <<< END OF NEW CODE TO SHOW USER NAME WHETHER LOG IN WITH NAME OR EMAIL ADDRESS >>>
						*/
						
					  // SCOTT 9/25.  THIS CAUSED LOG OUT NOT TO WORK setCookie ( "pjuid", pjuid );
					   
					   window["m_pjuid"] = pjuid;
					   
	
					   hideLogInForm ();
					   
					   login_handleLoginWithBackEndComplete (pjuid);
					   
				   } catch ( innerLogin ) {
					   // alert ( "EXC INNER LOGIN: " + innerLogin );
				   }
				}

				
				// alert ( " RESP: " + self.xmlHttpReq.responseText );
			}
		}
		self.xmlHttpReq.send(login_getLogInPostQueryStringFromPopUp());
	}
