
function shareGame_createEmailListArray ( originalEmailFieldValue ) {

  
 //alert ( " shareGame_createEmailListArray" );
 
   var addressesArray = null;
		
	if ( originalEmailFieldValue.indexOf ( ";" ) > 0 ) {
		addressesArray = originalEmailFieldValue.split (";");
		// addressesArray = addresses.
	} else if ( originalEmailFieldValue.indexOf ( "," ) > 0 ) {
		addressesArray = originalEmailFieldValue.split (",");
	} else if ( originalEmailFieldValue.indexOf ( "\n" ) > 0 ) {
		addressesArray = originalEmailFieldValue.split ("\n");		
	} else {
		addressesArray = originalEmailFieldValue.split (" ");
	}

	
	
	return addressesArray;
}


function shareGame_createCommaSeparatedEmailList ( originalEmailFieldValue ) {

//alert ( "create comma sep email list input: " + originalEmailFieldValue );

   var addresses = null;
   
   var addressesArray = shareGame_createEmailListArray ( originalEmailFieldValue );
		
	addresses = addressesArray.join ( ", " );
	
	return addresses;
}

function shareGame_validateSendGameToFriend () {
	
	try {
		var sendGameToEmail = document.getElementById ( "shareGame_shareQuestionInviteEmailsList" );
		var sendGameFromEmail = document.getElementById ( "shareGame_fromEmailAddress" );
		//var sendGameMessage = document.getElementById ( "sendGameMessage" );
		//var sendGameFormError = document.getElementById ( "sendGameFormError" );
		
		//sendGameToEmail.className = "dialogField";
		//sendGameFromEmail.className = "dialogField";
		
		var sendGameToEmailValue = sendGameToEmail.value;
		var sendGameFromEmailValue = sendGameFromEmail.value;
		//var sendGameMessageValue = sendGameMessage.value;

        if ( !_private_shareGame_stringIsBlank(sendGameToEmailValue) ) {
			var toEmailAddresses = shareGame_createEmailListArray ( sendGameToEmailValue );
			
			for ( var idx = 0; idx < toEmailAddresses.length; idx++ ) { 
			   var oneEmailAddress = toEmailAddresses[idx];
			  // alert ( " oneEmailAddress: " + oneEmailAddress );
			   if ( !_private_shareGame_isEmailValid ( oneEmailAddress ) ) {
				   shareGame_showOverallError ( "One of the hand-entered email addresses is invalid" );
				  //sendGameToEmail.className = "dialogFieldError";
				  //sendGameFormError.innerHTML = "To email address is invalid.";
				  return false;
			   }
			}
		}
	
	//alert ( " sendGameFromEmailValue: " + sendGameFromEmailValue );
	
	    if ( !_private_shareGame_stringIsBlank(sendGameFromEmailValue) ) {
			if ( !_private_shareGame_isEmailValid ( sendGameFromEmailValue ) ) {
				shareGame_showOverallError ( "From email address is invalid" );
				//sendGameFromEmail.className = "dialogFieldError";
				//sendGameFormError.innerHTML = "From email address is invalid.";
				
		//alert ( "THINKS IS INVALID" );
		
				return false;
			}
			
		}
		
		
	} catch ( exc ) {
		alert ( "EXC: " + exc );
	}

	return true;
}


/**
* START OF GAME-SPECIFIC STUFF
*/

   function shareGame_showShareQuestionScreen () {
	   
	  // alert ( "SHOW REG CALLED" );
	   
	   var dialogBoxesDiv = document.getElementById ( "dialogBoxesDiv" );
	   dialogBoxesDiv.style.display = "block";
	 //  dialogBoxesDiv.style.backgroundColor = "#ff0000";
       //dialogBoxesDiv.style.overflow = "visible";
	   

//shareGame_registrationInvitePage

       var shareGame_shareQuestionInvitePage = document.getElementById ("shareGame_shareQuestionInvitePage");
	   shareGame_shareQuestionInvitePage.style.display = "block";

       var shareGame_shareQuestionCompletePage = document.getElementById ("shareGame_shareQuestionCompletePage");
	   shareGame_shareQuestionCompletePage.style.display = "none";

       var shareGame_selectAndContinueButton = document.getElementById ("shareGame_selectAndContinueButton");
	   shareGame_selectAndContinueButton.style.display = "block";
	   
/*
getPlayerEmailAddress
shareGame_fromEmailAddress
shareGame_shareQuestionInviteWebMailAddress
*/
        var loggedInUserEmailAddress = getPlayerEmailAddress ();
		
		if ( loggedInUserEmailAddress != null ) {
           var shareGame_fromEmailAddress = document.getElementById ("shareGame_fromEmailAddress");
		   shareGame_fromEmailAddress.value = loggedInUserEmailAddress;
		   
           var shareGame_shareQuestionInviteWebMailAddress = document.getElementById ("shareGame_shareQuestionInviteWebMailAddress");
		   shareGame_shareQuestionInviteWebMailAddress.value = loggedInUserEmailAddress;		   
		}
		

//shareGame_registrationCompletePage

	   var shareGame_shareQuestionDialog = document.getElementById ("shareGame_shareQuestionDialog");
	   shareGame_shareQuestionDialog.style.display = "block";
	   
	  // alert ( "SHOWING?" );
   }

   function shareGame_hideShareQuestionScreen () {
	   var dialogBoxesDiv = document.getElementById ( "dialogBoxesDiv" );
	   dialogBoxesDiv.style.display = "none";

	   var shareGame_shareQuestionDialog = document.getElementById ("shareGame_shareQuestionDialog");
	   shareGame_shareQuestionDialog.style.display = "none";
   }

/**
* END OF GAME-SPECIFIC STUFF
*/
   
   function _private_shareGame_stringIsBlank ( str ) {
		var blankRE=/^[\s]+$/
		if ( str == "" || blankRE.test(str) ) {
			return true;
		} else {
			return false;
		}
   }
   
   function _private_shareGame_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_shareGame_spinnerDiv = null;

   function _private_shareGame_showSpinner () {
		
	   _private_shareGame_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 = 290 + "px";
	   spinnerDiv.id = "spinnerDiv";
	   spinnerDiv.setAttribute ( "id", "spinnerDiv" );
	   
	   var parentPage = document.getElementById ( "shareGame_shareQuestionPodContainer" );
	   parentPage.appendChild ( spinnerDiv );
	   
	   m_shareGame_spinnerDiv = spinnerDiv;
	   
		
	
	   var swfContentPath = "spinnerAnimation.swf"; 
	   
	   var so = new SWFObject( swfContentPath, "shareGame_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_shareGame_hideSpinner () {
	  if ( m_shareGame_spinnerDiv ) {
	     m_shareGame_spinnerDiv.parentNode.removeChild(m_shareGame_spinnerDiv);
		 m_shareGame_spinnerDiv = null;
	  }
   }
	

   
   
   
   // shareGame_page1RegistrationFormError
   
   function shareGame_validateWebMailInformation () {
	   
	   
	   var email = document.getElementById ( "shareGame_shareQuestionInviteWebMailAddress" );
	   var password = document.getElementById ( "shareGame_shareQuestionInviteWebMailPassword" ); 
	   
	   if ( _private_shareGame_stringIsBlank ( email.value ) ) {
		   shareGame_showOverallError ( "Please enter you web email address." );
		   return false;
	   }
	   
	   if ( !_private_shareGame_isEmailValid ( email.value ) ) {
		   shareGame_showOverallError ( "Please enter a valid web email address." );
		   return false;
	   }
	   
	   if ( _private_shareGame_stringIsBlank ( password.value ) ) {
		   shareGame_showOverallError ( "Please enter your web email password." );
		   return false;
	   }
	   
	   
	   
	   return true;
   }
   
   function shareGame_showWebMailFormError ( errorText ) {
	   var shareGame_webEmailFormError = document.getElementById ( "shareGame_webEmailFormError" );
	   shareGame_webEmailFormError.style.display = "block";
	   shareGame_webEmailFormError.innerHTML = errorText;
   }

   function shareGame_showOverallError ( errorText ) {
	   var shareGame_overallShareError = document.getElementById ( "shareGame_overallShareError" );
	   shareGame_overallShareError.style.display = "block";
	   shareGame_overallShareError.innerHTML = errorText;
   }

   function shareGame_hideOverallError () {
	   var shareGame_overallShareError = document.getElementById ( "shareGame_overallShareError" );
	   shareGame_overallShareError.style.display = "none";
   }
   
   function shareGame_getWebMailContactsFromBackEnd () {
	   _private_shareGame_showSpinner ();
	   
	   setTimeout ( shareGame_webContactsAvailable, 2000 );
   }
   
   function shareGame_webContactsAvailable () {
	   
	   _private_shareGame_hideSpinner ();
	
      var shareGame_shareQuestionWebMailDiv = document.getElementById ( "shareGame_shareQuestionWebMailDiv" );
	  shareGame_shareQuestionWebMailDiv.style.display = "none";
	  
	  var shareGame_shareQuestionWebMailContactsDiv = document.getElementById ( "shareGame_shareQuestionWebMailContactsDiv" );
	  shareGame_shareQuestionWebMailContactsDiv.style.display = "block";
	  
	  var data = new Object ();
	  data.contacts = new Object ();
	  data.contacts.contacts = m_dummyContacts;
	  
	  try {
	  shareGame_handleContactsFetched ( data, null );
	  } catch ( exc ) {
	     alert ( "EXC: " + exc );
	  }
	
/*	   
         var shareGame_registrationPage1 = document.getElementById ( "shareGame_registrationPage1" );
	     shareGame_registrationPage1.style.display = "none";

         var shareGame_registrationInvitePage = document.getElementById ( "shareGame_registrationInvitePage" );
	     shareGame_registrationInvitePage.style.display = "block";
*/	   
   }
   
   function shareGame_sendInviteFriendsMessageToBackEnd () {
	   _private_shareGame_showSpinner ();
	   
	   setTimeout ( shareGame_inviteFriendsServiceCallComplete, 2000 );
   }

   function shareGame_inviteFriendsServiceCallComplete () {
	   
	   _private_shareGame_hideSpinner ();
	   
      var shareGame_shareQuestionInvitePage = document.getElementById ( "shareGame_shareQuestionInvitePage" );
	  shareGame_shareQuestionInvitePage.style.display = "none";

      var shareGame_shareQuestionCompletePage = document.getElementById ( "shareGame_shareQuestionCompletePage" );
	  shareGame_shareQuestionCompletePage.style.display = "block";
	   
   }

   function shareGame_registerDoInvite () {
	
	   toolTips_hideToolTip  ();
       shareGame_hideOverallError ();

       var shareGame_selectAndContinueButton = document.getElementById ("shareGame_selectAndContinueButton");
	   
	   

	   if ( shareGame_validateSendGameToFriend () ) {
		   try {
			   _private_shareGame_showSpinner ();
			   shareGame_selectAndContinueButton.style.display = "none";
		      shareGame_sendShareQuestionMessageToBackEnd ();
		   } catch (exc ) {
			   alert ( "EXC: " + exc );
			   shareGame_selectAndContinueButton.style.display = "block";
			    _private_shareGame_hideSpinner ();
		   }
	   }
      //shareGame_sendInviteFriendsMessageToBackEnd ();
	  
   }
   
   function shareGame_sendShareQuestionMessageToBackEnd () {
	  // alert ( "share question" );

	   var sendQuestionToEmail = document.getElementById ( "shareGame_shareQuestionInviteEmailsList" );
	   var sendQuestionFromEmail = document.getElementById ( "shareGame_fromEmailAddress" );
	   var sendQuestionMessage = document.getElementById ( "shareGame_shareQuestionOptionalMessage" );

	   var sendQuestionToEmailValue = sendQuestionToEmail.value;
	   var sendQuestionFromEmailValue = sendQuestionFromEmail.value;
	   var sendQuestionMessageValue = sendQuestionMessage.value;

       var fromEmailValue = ""; 
	   var toEmailValueEnteredByHand = "";
	   var anyToAddressesEnteredByHand = false;
	   
       if ( !_private_shareGame_stringIsBlank(sendQuestionFromEmailValue) ) {
		   fromEmailValue = sendQuestionFromEmailValue;
	   }

       if ( !_private_shareGame_stringIsBlank(sendQuestionToEmailValue) ) {
		   toEmailValueEnteredByHand = shareGame_createCommaSeparatedEmailList (sendQuestionToEmailValue);
		   anyToAddressesEnteredByHand = true;
	   }

       var arraySelectedWebMailContacts = new Array ();
	   
	   for ( var idx = 0; idx < m_shareGame_contactsList.length; idx++ ) {
		   var contactObject = m_shareGame_contactsList[idx];
		   if ( contactObject.isSelected == 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 gameType = m_currentGameType;
    if ( gameType != "HIT" ) {
	   gameType = "player";
    }
   
    var origin = "site";
   
//try {   
//    dataService_emailGame ( handleGameSentToFriend, m_gameId, m_pjuid, gameType, origin, sendGameFromEmailValue, 
//		sendGameToEmailValue, sendGameMessageValue, null );
		   //DataServiceBackEnd.DUMMY_DATA = true;
		   dataService_emailGame ( shareGame_handleShareQuestionCompleted, m_gameId, m_pjuid, gameType, origin, fromEmailValue, allToAddresses, sendQuestionMessageValue, null );
		  //  DataServiceBackEnd.DUMMY_DATA = false;
	   } catch ( excData ) {
		   alert ( "DATA ERROR: " + excData );
		   _private_shareGame_hideSpinner ();
	   }
	   /*
	   	var sendQuestionMessageValue = document.getElementById ( "sendQuestionMessage" ).value;

   sendQuestionMessageValue 
   
    dataService_emailQuestion ( handleQuestionSentToFriend, m_currentQuestionObject.id, sendQuestionFromEmailValue, 
	   sendQuestionToEmailValue, sendQuestionMessageValue ); 

	   */
   }
   
   function shareGame_handleShareQuestionCompleted ( data, xml ) {
	   //alert ( "GAME CHALLENGE SENT" );
	   
	 //  alert ( "SPINNER SHOWING DONE" );
	   
	   _private_shareGame_hideSpinner ();
	   
	   var shareGame_shareQuestionInvitePage = document.getElementById ( "shareGame_shareQuestionInvitePage" );
	   shareGame_shareQuestionInvitePage.style.display = "none";

	   var shareGame_shareQuestionCompletePage = document.getElementById ( "shareGame_shareQuestionCompletePage" );
	   shareGame_shareQuestionCompletePage.style.display = "block";

   }
   
   
 /** START SEND GAME FROM END PAGE **/
 
   function shareGame_getSendQuestionMessage ( gameName ) {
		return "You have been sent a challenge to play the [" + gameName + "] game!";
	}
	
	
   function shareGame_sendGameChallengeFromEndGamePage ( fromEmailAddress, gameName ) {
	   
//alert ( " shareGame_sendGameChallengeFromEndGamePage entered " );

	   var sendQuestionToEmail = document.getElementById ( "endGameEmailAddresses" );

	   var sendQuestionToEmailValue = sendQuestionToEmail.value;
	
	   var sendQuestionMessageValue = "";
	   if ( gameName ) {
		   sendQuestionMessageValue = shareGame_getSendQuestionMessage ( gameName ); //"You have been sent a challenge to play the [" + gameName + "] game!";
	   }
	   
       var fromEmailValue = fromEmailAddress; // Passed in to function.
	   
	   var toEmailValueEnteredByHand = "";
	   var anyToAddressesEnteredByHand = false;
	   

       if ( !_private_shareGame_stringIsBlank(sendQuestionToEmailValue) ) {
		   toEmailValueEnteredByHand = shareGame_createCommaSeparatedEmailList (sendQuestionToEmailValue);
		   anyToAddressesEnteredByHand = true;
	   }

	   var allToAddresses = toEmailValueEnteredByHand; //sendQuestionToEmailValue;
	
	   try {
		  // DataServiceBackEnd.DUMMY_DATA = true;
		   
		    if ( m_clickedInEndGameChallengeAddressList && anyToAddressesEnteredByHand ) {
				
			   var gameType = m_currentGameType;
			   if ( gameType != "HIT" ) {
			      gameType = "player";
			   }
		   
			   var origin = "site";
   
		      dataService_emailGame ( shareGame_handleSendGameChallengeFromEndGamePageCompleted, m_gameId, m_pjuid, gameType, origin, 
			      fromEmailValue, allToAddresses, sendQuestionMessageValue, null );
			}
			
	   } catch ( excData ) {
		   alert ( "DATA ERROR: " + excData );
		   _private_shareGame_hideSpinner ();
	   }
   }
   
   function shareGame_handleSendGameChallengeFromEndGamePageCompleted ( data, xml ) {
	   
	   var endGameEmailAddresses = document.getElementById ( "endGameEmailAddresses" );
	   endGameEmailAddresses.value = "Challenge Sent!";
	   endGameEmailAddresses.style.backgroundColor = "#ffcc00";
	   endGameEmailAddresses.style.color = "#ff0000";
	   endGameEmailAddresses.style.fontWeight = "bold";
	   endGameEmailAddresses.style.fontSize = "14px";
	   m_clickedInEndGameChallengeAddressList = false;
	   
   }


 /** END SEND GAME FROM END PAGE **/
 
   function shareGame_handleRegistrationEmailProviderSelected () {
      var shareGame_shareQuestionInviteEmailProvider = document.getElementById ( "shareGame_shareQuestionInviteEmailProvider" );
	  var selectedProvider = shareGame_shareQuestionInviteEmailProvider.value;
	  //alert ( "SELECTED: " + selectedProvider );
	  
	  var shareGame_shareQuestionInvitePageEmailMessage = document.getElementById ( "shareGame_shareQuestionInvitePageEmailMessage" );
	  var shareGame_shareQuestionInviteWebMailPasswordLabel = document.getElementById ( "shareGame_shareQuestionInviteWebMailPasswordLabel" );
	  
	  switch ( selectedProvider ) {
	     case "yahoo":
		    shareGame_shareQuestionInvitePageEmailMessage.innerHTML = 
			   "Enter your Yahoo details below.  Then click \"Get Contacts\" to chooser from your Yahoo email contacts.";
			shareGame_shareQuestionInviteWebMailPasswordLabel.innerHTML = "Yahoo password:";
		    break;
	
	     case "hotmail":
		    shareGame_shareQuestionInvitePageEmailMessage.innerHTML = 
			   "Enter your Hotmail details below.  Then click \"Get Contacts\" to chooser from your Hotmail email contacts.";
			   shareGame_shareQuestionInviteWebMailPasswordLabel.innerHTML = "Hotmail password:";
		    break;
			
	     case "gmail":
		    shareGame_shareQuestionInvitePageEmailMessage.innerHTML = 
			   "Enter your Gmail details below.  Then click \"Get Contacts\" to chooser from your Gmail email contacts.";
			   shareGame_shareQuestionInviteWebMailPasswordLabel.innerHTML = "Gmail password:";
		    break;
			
		 case "aol":
		    shareGame_shareQuestionInvitePageEmailMessage.innerHTML = 
			   "Enter your AOL details below.  Then click \"Get Contacts\" to chooser from your AOL email contacts.";
			   shareGame_shareQuestionInviteWebMailPasswordLabel.innerHTML = "AOL password:";
		    break;

		 case "other":
		    shareGame_shareQuestionInvitePageEmailMessage.innerHTML = 
			   "Enter your web email details below.  Then click \"Get Contacts\" to chooser from your web email contacts.";
			   shareGame_shareQuestionInviteWebMailPasswordLabel.innerHTML = "Email password:";
		    break;
			
	     
	  }
   }
   
   /**
   * This fetches the contacts list from the user's web email.
   */
   function shareGame_fetchContactList () {
    //  return;
	
	//alert ( "CALELD shareGame_fetchContactList: " );
	
      var youWebEmailAddress = document.getElementById ( "shareGame_shareQuestionInviteWebMailAddress" );
	  var youWebEmailAddressValue = youWebEmailAddress.value;
	  
	  var youWebEmailPassword = document.getElementById ( "shareGame_shareQuestionInviteWebMailPassword" );
	  var youWebEmailPasswordValue = youWebEmailPassword.value;
	  
	 // alert ( "ABOUT TO CALL BACK END" );
	  try {
	     getEmailContactList ( shareGame_handleContactsFetched, youWebEmailAddressValue, youWebEmailPasswordValue ); 
	  } catch ( exc ) {
	    alert ( "EXC: " + exc );
	  } 
	 //alert ( "youWebEmailAddress: " + youWebEmailAddressValue + "  youWebEmailPasswordValue: " + youWebEmailPasswordValue );
   }
   
   var m_shareGame_contactsList = Array ();
   
   function shareGame_toggleCheckBox ( idx ) {
   
  // alert ( "TOGGLE" );
   
      var contactObject = m_shareGame_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 shareGame_handleCheckBoxChanged ( idx ) {
      var contactObject = m_shareGame_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 shareGame_deselectAllContacts () {
      for ( var idx = 0; idx < m_shareGame_contactsList.length; idx++ ) {
	     var contactObject = m_shareGame_contactsList[idx];
		 contactObject.isSelected = false;
		 var checkBoxId = "checkbox" + idx;
		 var checkbox = document.getElementById ( checkBoxId );
		 checkbox.checked = false;
	  }
   }
   
   function shareGame_selectAllContacts () {
      for ( var idx = 0; idx < m_shareGame_contactsList.length; idx++ ) {
	     var contactObject = m_shareGame_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 shareGame_handleContactsFetched ( data, xml ) {
	  
	 // alert ( "FETCHED" );
	 // alert ( "data: " + data );
	  
	  if ( data.code == "GET_EMAIL_CONTACT_LIST_ERROR" ) {
		    _private_shareGame_hideSpinner ();
		  //alert ( " ERROR: " + data.errorMessage );
		  shareGame_showOverallError ( data.errorMessage  );
		  return;
	  }
	  
	  var shareGame_shareQuestionWebMailContactsDiv = document.getElementById ( "shareGame_shareQuestionWebMailContactsDiv" );
	  
	  var contacts = data.contacts.contacts;
	  
	  shareGame_shareQuestionWebMailContactsDiv.innerHTML = contacts.length + " Contacts Found";
	  
	  m_shareGame_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:shareGame_selectAllContacts()'/>Select All</a>&nbsp;&nbsp;<a style='color:#222222;' href='JavaScript:shareGame_deselectAllContacts()'/>De-Select 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_shareGame_contactsList.push(contactObject);
		
		    var checkboxId = "checkbox" + idx;
			
		    var contactHTML = "<div style='padding:4px; margin-bottom:2px;'><input id='" + checkboxId + "' onclick=\"shareGame_handleCheckBoxChanged('" + idx + "')\" type='checkbox' checked='true' style='padding:0; margin:0;' /> <span style='padding:10px; cursor:pointer;' onclick=\"shareGame_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:shareGame_selectAllContacts()'/>Select All</div>";
	  }
	  
	  shareGame_shareQuestionWebMailContactsDiv.innerHTML = strHTML;
	  
	   _private_shareGame_hideSpinner ();
	
      var shareGame_shareQuestionWebMailDiv = document.getElementById ( "shareGame_shareQuestionWebMailDiv" );
	  shareGame_shareQuestionWebMailDiv.style.display = "none";
	  
	  var shareGame_shareQuestionWebMailContactsDiv = document.getElementById ( "shareGame_shareQuestionWebMailContactsDiv" );
	  shareGame_shareQuestionWebMailContactsDiv.style.display = "block";
	  	  
   }
   

   
   function shareGame_shareQuestionGetWebMailContacts () {
	   
	   toolTips_hideToolTip  ();
	   
	  // alert ( " shareGame_shareQuestionGetWebMailContacts called" );
	   
	   try {
	  if ( shareGame_validateWebMailInformation () ) {
		  
		//  alert ( "GET ERROR: " );
		  
		   shareGame_hideOverallError ();
		   
	      //var shareGame_webEmailFormError = document.getElementById ( "shareGame_webEmailFormError" );
		  
		 // alert ( " shareGame_webEmailFormError: " + shareGame_webEmailFormError );
		  
	      //shareGame_webEmailFormError.style.display = "none";
		  
		  try {
			  _private_shareGame_showSpinner ();
		  shareGame_fetchContactList ();
		  } catch ( exc ) {
			   alert ( "EXC: " + exc );
		  }
		  //shareGame_getWebMailContactsFromBackEnd ();
	  }
	   } catch ( excouter ) {
		    alert ( "EXCOUTER: " + excouter );
	   }
/*	   
      var shareGame_shareQuestionWebMailDiv = document.getElementById ( "shareGame_registrationWebMailDiv" );
	  shareGame_registrationWebMailDiv.style.display = "none";
	  
	  var shareGame_registrationWebMailContactsDiv = document.getElementById ( "shareGame_registrationWebMailContactsDiv" );
	  shareGame_registrationWebMailContactsDiv.style.display = "block";
	  
	  var data = new Object ();
	  data.contacts = new Object ();
	  data.contacts.contacts = m_dummyContacts;
	  
	  try {
	  shareGame_handleContactsFetched ( data, null );
	  } catch ( exc ) {
	     alert ( "EXC: " + exc );
	  }
*/	  
   }
   
   function shareGame_initRegistrationPage () {
	   
//alert ( "INIT REG PAGE CALLED" );
try {
      shareGame_initToolTips ();
} catch ( exc ) {
	alert ( "EXC: " + exc );
}
   }
   
   function shareGame_initToolTips () {

/*
	  var shareGame_fromEmailAddress = document.getElementById ( "shareGame_fromEmailAddress" );
	  shareGame_fromEmailAddress.onmouseover = function () { 
	     toolTips_showToolTip ( "shareGame_shareQuestionInvitePage", "shareGame_fromEmailAddress", 
		    "Please enter your email address here so that people know who is challenging them.",
			 420, -60 );
	  }
	  shareGame_fromEmailAddress.onmouseout = toolTips_hideToolTip;
*/

	  
	  var shareGame_shareQuestionInviteWebMailAddress = document.getElementById ( "shareGame_shareQuestionInviteWebMailAddress" );
	  shareGame_shareQuestionInviteWebMailAddress.onmouseover = function () { 
	     toolTips_showToolTip ( "shareGame_shareQuestionInvitePage", "shareGame_shareQuestionInviteWebMailAddress", 
		    "We need to use this email address to access your web mail contacts.  We don't store this address.",
			 420, 20 );
	  }
	  shareGame_shareQuestionInviteWebMailAddress.onmouseout = toolTips_hideToolTip;
	 // shareGame_shareQuestionInviteWebMailAddress.onclick = toolTips_hideToolTip;
	  
	  var shareGame_shareQuestionInviteWebMailPassword = document.getElementById ( "shareGame_shareQuestionInviteWebMailPassword" );
	  shareGame_shareQuestionInviteWebMailPassword.onmouseover = function () { 
	     toolTips_showToolTip ( "shareGame_shareQuestionInvitePage", "shareGame_shareQuestionInviteWebMailPassword", 
		    "We need to temporarily use this password to access your web mail contacts.  We don't store this password.",
			 420, 50 );
	  }
	  shareGame_shareQuestionInviteWebMailPassword.onmouseout = toolTips_hideToolTip;
	 // shareGame_shareQuestionInviteWebMailPassword.onclick = toolTips_hideToolTip;
	  
	  var shareGame_shareQuestionInviteEmailsList = document.getElementById ( "shareGame_shareQuestionInviteEmailsList" );
	  shareGame_shareQuestionInviteEmailsList.onmouseover = function () { 
	     toolTips_showToolTip ( "shareGame_shareQuestionInvitePage", "shareGame_shareQuestionInviteEmailsList", 
		    "If you would like, you can enter your friends' email addresses into this field.  Comma-delimited please!",
			 600, 120 );
	  }
	  shareGame_shareQuestionInviteEmailsList.onmouseout = toolTips_hideToolTip;
	  
	  var shareGame_shareQuestionOptionalMessage = document.getElementById ( "shareGame_shareQuestionOptionalMessage" );
	  shareGame_shareQuestionOptionalMessage.onmouseover = function () { 
	     toolTips_showToolTip ( "shareGame_shareQuestionInvitePage", "shareGame_shareQuestionOptionalMessage", 
		    "You can enter your own message here to be sent along with the challenge.",
			 600, 220 );
	  }
	  shareGame_shareQuestionOptionalMessage.onmouseout = toolTips_hideToolTip;


	  //shareGame_shareQuestionInviteEmailsList.onclick = toolTips_hideToolTip;
  
	  
	  
   }
   
   var m_shareGame_afterRegistrationCallback = null;
   
   function shareGame_setAfterRegistrationCallback ( _callback ) {
	   m_shareGame_afterRegistrationCallback = _callback;
   }
   
	/**
	* The URL of the "register" service for VideoJax.com
	*/		
	//var registerUrl = "./dummyData/dummyRegisterResponse.html"; ///videocube/login.htm";
    var m_shareGame_registerUrl = "/videocube/login.htm";

	/**
	* Sends the registration data to the VideoJax.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 shareGame_postRegistrationData () {
	
	    var strURL = m_shareGame_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 );
				   
				   shareGame_handleRegistrationError ( registrationErrorString );
				   
				  // errorCallback( registrationErrorString );
				   
				   //$("overallRegistrationError").innerHTML = registrationErrorString;
				   
				  // showRegistrationPage (); //$("registrationPage").className = "overlayVisible";
				  // hideSpinnerLoginDiv (); // $("spinnerDuringLoginDiv").className = "overlayHidden";
				  // hideSpinner ( "spinnerDuringLoginDiv" );
				   
				} else {
				
		//		   alert ( "COOL" );
				   

                   /**
				    NO, NOT IN GAME FOR NOW...
                   var userId = $("userId");
				   var registrationScreenNameValue = $("shareGame_registrationUserName").value;
				   userId.value = registrationScreenNameValue;
                   **/
				   
	  // $("userNameLoggedIn").innerHTML = userId.value;		
	   
	               // Hides login form on main page!???
	
	               // NO. NOT IN GAME FOR NOW. 
				   /**
				   * 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) );
				   }					

                   shareGame_handleRegistrationWithBackEndComplete (pjuid);
/*
					if ( m_shareGame_afterRegistrationCallback  ) {
						m_shareGame_afterRegistrationCallback  (pjuid);
					}
	*/
	
				//   alert ( "YOU ARE REGISTERED AND LOGGED IN" );
				   //hideLogInForm ();
				}
				//m_currentlyLoggingInOrOut = false;
				
				// alert ( " RESP: " + self.xmlHttpReq.responseText );
			}
		}
		self.xmlHttpReq.send(shareGame_getRegistrationFormData());
	}
	
	

