
/***
* START: USER COMMENT STUFF
*/

//var QA_DB_ACCESS = true;

function showBounceFromPageScreen () {
	
	//alert ( " showBounceFromPageScreen called" );
	   showTranslucentPopupOverlay ();
	   showPopUpOverlayContainer ();
	   
	   var bounce_onUnloadDialogUserFeedbackTextField = document.getElementById ( "bounce_onUnloadDialogUserFeedbackTextField" );
	   bounce_onUnloadDialogUserFeedbackTextField.value = "<Please type your feedback into this field.>";
	   
	   var bounce_onUnloadDialog = document.getElementById ( "bounce_onUnloadDialog" );
	   bounce_onUnloadDialog.style.display = "block";
	   
	//alert ( "IS IT SHOWING?: " + bounce_onUnloadDialog );
}

function getDidBounceFromSite () {
	var didNotBounceCookie = getCookie ( "didNotBounce" );
	if ( didNotBounceCookie == null ) {
		return true;
	} else {
		return false;
	}
}

function setDidNotBounceFromSite () {
//alert ( "SET DID NOT BOUNCE" );
	setCookie ( "didNotBounce", true );
}

function setDoNotShowBounceMessageAgain () {
	setCookieWithExpiresInThisManyDays ( "doNotShowBounceMessageAgain", true, 30 );
}

function handleUnloadDialogUserFeedbackChanged () {
	
	var bounce_onUnloadDialogUserFeedbackTextField = document.getElementById ( "bounce_onUnloadDialogUserFeedbackTextField" );
	
   var bounce_onUnloadDialogUserFeedback = document.getElementById ( "bounce_onUnloadDialogUserFeedback" );
   var feedbackValue = bounce_onUnloadDialogUserFeedback.value;
   if ( feedbackValue == "other" ) {
	   bounce_onUnloadDialogUserFeedbackTextField.style.display = "inline";
   } else {
	   bounce_onUnloadDialogUserFeedbackTextField.style.display = "none";
   }
}

var m_everClickedInUnloadDialogUserFeedbackTextField = false;

function handleClickedInUnloadDialogUserFeedbackTextField () {
	if ( m_everClickedInUnloadDialogUserFeedbackTextField == false ) {
		m_everClickedInUnloadDialogUserFeedbackTextField = true;
		var bounce_onUnloadDialogUserFeedbackTextField = document.getElementById ( "bounce_onUnloadDialogUserFeedbackTextField" );
		bounce_onUnloadDialogUserFeedbackTextField.value = "";
	}
}

function storeUserComment ( userComment, commentType  ) {
  try {
   var iframe = document.createElement ( "iframe" );
   var nowObject = new Date(); // '2007-11-30 10:41:47'
   var creationDateTime = nowObject.getFullYear() + "-" + 
      Number(Number(nowObject.getMonth())+Number(1)) + "-" + 
	  Number(Number(nowObject.getDay())+Number(1)) + " " + 
	  nowObject.getHours() + ":" + nowObject.getMinutes();

    // nowObject.year + "-" + nowObject.month + "-" + nowObject.
   var iframeSource = "/videocube/storeUserContent.jsp?userFeedback=" + userComment + "&creationDateTime=" + creationDateTime +
      "&commentType=" + commentType;
	  
 //  if ( QA_DB_ACCESS == true ) {
//	  iframeSource += "&isNotProd=true";
 //  }
   
   iframe.src = iframeSource;
   iframe.setAttribute ( "src", iframeSource );
   iframe.style.width = "1px";
   iframe.style.height = "1px";
   document.body.appendChild(iframe);
  } catch ( exc ) {
	  alert ( "EXC: " + exc );
  }
	
}

function afterBounceDialogProceedToNextPage () {
	//alert ( "GO" );
	//window.history.go(1);
	//alert ( " window.history: " + window.history );
	
   hideTranslucentPopupOverlay ();
   hidePopUpOverlayContainer ();
	   var bounce_onUnloadDialog = document.getElementById ( "bounce_onUnloadDialog" );
	   bounce_onUnloadDialog.style.display = "none";
	
   var bounce_onUnloadDialogUserFeedback = document.getElementById ( "bounce_onUnloadDialogUserFeedback" );
   var feedbackValue = bounce_onUnloadDialogUserFeedback.value;
   
   if ( feedbackValue == "other" ) {
	   	   var bounce_onUnloadDialogUserFeedbackTextField = document.getElementById ( "bounce_onUnloadDialogUserFeedbackTextField" );
	   feedbackValue = bounce_onUnloadDialogUserFeedbackTextField.value;

   }
   
   storeUserComment ( feedbackValue, "bounceComment" );
   
 

}



/**
* END:  USER COMMENT STUFF
*/



function addCommasToNumber ( val ) {
	
	var valWithCommas = val;
	
	if ( val >= 1000 && val < 1000000 ) {
		var thousands = Math.floor(val/1000);
		var ones = Number(val) - Number(thousands * 1000);
		if ( ones < 100 ) {
			if ( ones < 10 ) {
				ones = "00" + ones;
			} else {
				ones = "0" + ones;
			}
		}
		valWithCommas = thousands + "," + ones;
	} else if ( val >= 1000000 ) {
	}
	
	return valWithCommas;
}

// JavaScript Document

function Delegate () {
}

Delegate.create = function ( target, func ) {
	
	return function () {
		
		// alert ( " arguments: " + arguments.length );
		 
		func.apply ( target, arguments );
	}
}


    function isCorrectFlashVersionInstalled () {
		var hasTheVersion = DetectFlashVer ( 9, 0, 0 );
		
		return hasTheVersion;
	}

	

	/**
	* This shows the "spinner" movie within a div.
	*/
    function showSpinner ( spinnerDivId ) {
	
	
	   var swfContentPath = "spinnerAnimation.swf";
	   
	   var so = new SWFObject( swfContentPath, "spinner" + spinnerDivId, "100%", "100%", "9", "#ffffff" ); //, backColor );
	   so.addParam("quality", "high");
       so.addParam("wmode", "transparent" ); 
       so.addParam("allowScriptAccess", "always");
       so.addParam("salign", "tl" ); //tl");
	   so.useExpressInstall('expressinstall.swf');
	   
	 //  alert ( "WRITING TO: " + spinnerDivId );
	   
	   so.write( spinnerDivId );
	}	
	
	function hideSpinner ( spinnerDivId ) {
	   $(spinnerDivId).innerHTML = "";
	}
    
 
    function getWholeCookie ( offset ) {
		var endstr = document.cookie.indexOf ( ";", offset );
		if ( endstr == -1 ) {
			endstr = document.cookie.length;
		}
		return unescape(document.cookie.substring(offset, endstr));
	}
	
    function getCookie ( cookieName ) {
		var arg = cookieName + "=";
		var argLength = arg.length;
		var cookieLength = document.cookie.length;
		var i = 0;
		while ( i < cookieLength ) {
			var j = i + argLength;
			if ( document.cookie.substring(i,j) == arg ) {
				return getWholeCookie(j);
			}
			i = document.cookie.indexOf ( " ", i) + 1;
			if ( i == 0 ) {
				break;
			}
		}
		
		return null;
	}
	
	function setCookieWithExpiresInThisManyDays (c_name,value,expiredays)
	{
	   var exdate=new Date();
	   exdate.setDate(exdate.getDate()+expiredays);
	   document.cookie=c_name+ "=" +escape(value)+
	   ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	}

	function setCookie ( name, value ) {
		document.cookie = name + "=" + escape(value);
	}
	
	function tossCookie ( name ) {
		if ( getCookie(name) ) {
			document.cookie = name + "= null; expires=Thu, 01-Jan-2001 00:00:01 GMT";
		}
	}


    function userIsLoggedIn () {
		var isLoggedIn = getCookie ( "isLoggedIn" );
		
		// alert ( "IS LOGGED IN: " + isLoggedIn );
		
		return ( isLoggedIn == "true" );
	}
	
	function getLoggedInUserId () {
		var isLoggedIn = userIsLoggedIn (); //getCookie ( "isLoggedIn" );
		var userIdString = null;
		
		if ( isLoggedIn ) {
			userIdString =  getCookie ( "userIdString" );
		}
		
		return userIdString;
	}
	
	function setUserIsLoggedIn ( userIdString ) {
		setCookie ( "isLoggedIn", "true" );
		setCookie ( "userIdString", userIdString );
	}
	
	function setUserIsLoggedOut () {
		setCookie ( "isLoggedIn", "false" );
		setCookie ( "userIdString", null );
	}

    function showOrHideLoginForm () {
		
		
		m_currentlyLoggingInOrOut = false;
		
		var loggedInUserId = getLoggedInUserId ();
		
		if ( loggedInUserId != null && loggedInUserId != "null" ) {
			var userId = $("userId");
			userId.value = loggedInUserId;
			hideLogInForm ();
		} else {
			showLogInForm ();
		}
	}
	

    /**
	* This function hides the login form and shows the "you are currently loggen as | Log Out" stuff.
	*/	
	function hideLogInForm () {
	
	    m_currentlyLoggingInOrOut = false;
//alert ( " hideLogInForm called" );

       var logOutForm = $("logOutForm2"); //logOutForm");
	   logOutForm.style.display = "block";
		
	   var logInForm = $("loginform2"); //logInDataForm");
	   logInForm.style.display = "none";
		
       var userId = $("userId");
	   $("userNameLoggedIn").innerHTML = userId.value;		
	   
	   if ( $("registerMenuLink") ) {
	      $("registerMenuLink").style.display = "none";
	   }
	}
	
	/**
	* This function hides the "you are currently loggen as | Log Out" form and shows the "Log In" form.
	*/
	function showLogInForm () {
		
		m_currentlyLoggingInOrOut = false;
		
//alert ( "SHOW LOG IN FORM CALLED" );

	   $("loginform2").style.display = "block";
	   $("logOutForm2").style.display = "none";	
		
	 //  $("logInDataForm").style.display = "block";
	 //  $("logOutForm").style.display = "none";	
	   var password = $("password");
	   password.value = "";
	   
	   if ( $("registerMenuLink") ) {
	      $("registerMenuLink").style.display = "block";
	   }
	}
	
	/**
	* The URL of the "log in" service for VideoJax.com
	*/
	// var loginUrl = "./dummyData/loginResponse.html"; ///videocube/login.htm";
	var loginUrl = "/videocube/login.htm";
	var m_currentlyLoggingInOrOut = false;
	
	
	function showTranslucentPopupOverlay () {
		$("popupOverlayBack").style.display = "block"; //$("popupOverlayBack").className = "overlayVisible";
		if ( this["doReplacePngs"] ) {
			if ( doReplacePngs == true ) {
				var width = document.body.offsetWidth;
				var height = document.body.offsetHeight;
				// alert ( "ADJUSTING" );
				
				$("popupOverlayBack").style.width = width + "px";
				$("popupOverlayBack").style.height = height + "px";
			}
		}
	}
	
	function hideTranslucentPopupOverlay () {
		$("popupOverlayBack").style.display = "none";
	}
	
	
	/*
	 $("popupOverlayContainer").className = "overlayVisible";
	*/
	
	function showPopUpOverlayContainer () {
		$("popupOverlayContainer").style.display = "block";
	}
	
	function hidePopUpOverlayContainer () {
		$("popupOverlayContainer").style.display = "none";
	}	
	
	function showSpinnerLoginDiv () {
		$("spinnerDuringLoginDiv").style.display = "block";
	}
	
	function hideSpinnerLoginDiv () {
		$("spinnerDuringLoginDiv").style.display = "none";
	}
	
	/*
	$("spinnerDuringLoginDiv").className = "overlayVisible";
	*/

	function getLogInPostQueryStringForAvengeLoginPopup () {
	   var userId = $("logInPopupUserId");
	   var password = $("logInPopupPassword");
	   
	   
	   var loginString = "mode=1&player.name=" + userId.value + "&player.password=" + password.value + "&x=99&y=10&player.autoLogin=0";
	   
	   return loginString;
	}

	function doLogInForAvengeGame ( afterLoginCallback ) {
		
//alert ( "VALUE OF FOO: " +  window["m_pjuid"] );

		if ( m_currentlyLoggingInOrOut ) {
			// alert ( "SORRY!!!" );
		} else {
			
			// alert ( "LOGIN CALLED" );
			
			m_currentlyLoggingInOrOut = true;
		
		    showTranslucentPopupOverlay ();
		   //$("popupOverlayBack").className = "overlayVisible";
		   
		  // alert ( "SURVIVED FIRST ONE" );
		   
		   showPopUpOverlayContainer ();
		  // $("popupOverlayContainer").className = "overlayVisible";
		   
 // alert ( " SPIINER DIV: " + $("spinnerDuringLoginDiv") );
		//   alert ( " SHOW SPINNER: " + showSpinner );
		   
		   showSpinnerLoginDiv (); // $("spinnerDuringLoginDiv").className = "overlayVisible";
		   
		   try {
		   showSpinner ( "spinnerDuringLoginDiv" );	   
		   } catch ( exc ) {
			   // alert ( "EXC: " + exc );
		   }
		  
		
	       postLoginFormData ( afterLoginCallback, getLogInPostQueryStringForAvengeLoginPopup );
		}
	}
	

	
	function doLogIn ( afterLoginCallback ) 
	{
		/**** July 2009 - use login panel now...
		
		if ( m_currentlyLoggingInOrOut ) {
		} else {
			
			m_currentlyLoggingInOrOut = true;
		
		    showTranslucentPopupOverlay ();		   
		    showPopUpOverlayContainer ();
		    showSpinnerLoginDiv (); 
		   try {
		   showSpinner ( "spinnerDuringLoginDiv" );	   
		   } catch ( exc ) {
			   // alert ( "EXC: " + exc );
		   }
	       postLoginFormData ( afterLoginCallback, getLogInPostQueryStringFromTopBar );
		}
		****/
		
	    showTranslucentPopupOverlay ();
	    showPopUpOverlayContainer ();
        var popupOverlayBack = document.getElementById ( "popupOverlayBack" );
		popupOverlayBack.onclick = hideNewRegistrationScreen;
		
		var userName = $("userId");
	    var userPass = $("password");
		var remember = $("autologin");
		reg_driveLoginScreen ( userName.value, userPass.value, remember.checked ) ;
	}


	function showNewRegistrationPage () {
		reg_showRegistrationScreen ();
        var popupOverlayBack = document.getElementById ( "popupOverlayBack" );
		popupOverlayBack.onclick = hideNewRegistrationScreen;
	}
	function showNewRegLoginPage () 
	{	
		reg_showRegLoginScreen ();
        var popupOverlayBack = document.getElementById ( "popupOverlayBack" );
		popupOverlayBack.onclick = hideNewRegistrationScreen;
	}
	
	function hideNewRegistrationPage () {
		
		reg_hideRegistrationScreen ();
	}

	function showRegistrationPage () {
		//$("reg_registrationDialog").style.display = "block";
		if ( $("registrationPage") ) {
		   $("registrationPage").style.display = "block";
		} else {
			showNewRegistrationPage ();
		}
	}
	
	function hideRegistrationPage () {
	    if ( $("registrationPage") ) { $("registrationPage").style.display = "none"; }
	}
	function showConfirmPage () {
	    if ( $("confirmPage") ) { $("confirmPage").style.display = "block"; }
	}
	
	function hideConfirmPage () {
		if ( $("confirmPage") ) { $("confirmPage").style.display = "none"; }
	}
	
	function showPrizeRulesPage () {
		if ( $("prizeRulesPage") ) { $("prizeRulesPage").style.display = "block"; }
	}
	
	function hidePrizeRulesPage () {
		if ( $("prizeRulesPage") ) { $("prizeRulesPage").style.display = "none"; }
	}
	
	function showFeedbackPage () {
		$("feedbackPage").style.display = "block";
		$("feedback_contents").style.display = "block";
	    document.feedbackForm.feedbackEmail.focus();
	}
	
	function hideFeedbackPage () {
		$("feedbackPage").style.display = "none";
	}
	function showFeedbackThanks () {
		$("feedbackThanks").style.display = "block";
	}
	
	function hideFeedbackThanks () {
		$("feedbackThanks").style.display = "none";
	}
	/**
	* This does an HTTP POST to the email a question to a friend.
	*/	
	function postEmailFormData ( questionId ) {
		var strURL = "email.htm?sqid=" + questionId + "&src=" + m_emailFromScreenId; // submitQuestion";
				
		strURL += ( "&uniqueCallId=" + getNextUniqueCallId () );
		
		//alert ( " URL: " + strURL );
		
		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() {

			if (self.xmlHttpReq.readyState == 4) {
				
				if ( self.xmlHttpReq.responseText.indexOf ( "class=\"error\"" ) > 0 ) {
				   alert ( "Email sending error!" );
				} else {
					pjuid = null;

				}

			   hideTranslucentPopupOverlay (); //$("popupOverlayBack").className = "overlayHidden";
			   hidePopUpOverlayContainer (); //$("popupOverlayContainer").className = "overlayHidden";
			   //hideRegistrationPage (); //$("registrationPage").className = "overlayHidden";
			   hideSpinnerLoginDiv (); /// $("spinnerDuringLoginDiv").className = "overlayHidden";
			   hideSpinner ( "spinnerDuringLoginDiv" );	   

				m_currentlyLoggingInOrOut = false;
				
				// alert ( " RESP: " + self.xmlHttpReq.responseText );
			}
		}
		self.xmlHttpReq.send(getEmailQuestionDataFromPopUp());		
	}
	
	/**
	* This does an HTTP POST to the login service in order to log the user in.
	*/
	function postLoginFormData(afterLoginCallback, loginDataQueryBuilderFunc ) {
	    var strURL = loginUrl;
		
		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() {

			if (self.xmlHttpReq.readyState == 4) {

				if ( self.xmlHttpReq.responseText.indexOf ( "class=\"error\"" ) > 0 ) {
				   alert ( "User id or password incorrect" );
				   m_currentlyLoggingInOrOut = false;
				} else {
				  //alert ( "YOU ARE NOW LOGGED IN" );
				  
				   try {
					   setUserIsLoggedIn ( $("userId").value );  
					   
						   window["m_pjuserName"] = getCookie ( "userIdString" ); //, userIdString );

					   
					   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" );
					   }
					   
		
						/**
						* <<< 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 ();
					   
					  // alert ( "CALLBACK: " + afterLoginCallback );
					   if ( afterLoginCallback ) {
						   afterLoginCallback (pjuid);
					   } else {
						   alert ( "NO LOGIN CALLBACK" );
					   }
				   } catch ( innerLogin ) {
					   // alert ( "EXC INNER LOGIN: " + innerLogin );
				   }
				}

			   hideTranslucentPopupOverlay (); //$("popupOverlayBack").className = "overlayHidden";
			   hidePopUpOverlayContainer (); //$("popupOverlayContainer").className = "overlayHidden";
			   hideRegistrationPage (); //$("registrationPage").className = "overlayHidden";
			   hideSpinnerLoginDiv (); /// $("spinnerDuringLoginDiv").className = "overlayHidden";
			   hideSpinner ( "spinnerDuringLoginDiv" );	   

				m_currentlyLoggingInOrOut = false;
				
				// alert ( " RESP: " + self.xmlHttpReq.responseText );
			}
		}
		self.xmlHttpReq.send(loginDataQueryBuilderFunc());
	}
	
	/**
	* This returns a URLEncoded string to be HTTP POSTed to the VideoJax.com login service.
	*/
	function getLogInPostQueryStringFromTopBar () 
	{
	   var userId = $("userId");
	   var password = $("password");
		var autologin = $("autologin");
		var autoLoginValue = 0;
		if ( autologin.checked ) {
			autoLoginValue = 1;
		} 
		
	   
	   // NEW!!!
	   reg_pjusername = userId;
	   
	   
	   var loginString = "mode=1&player.name=" + userId.value + "&player.password=" + password.value + "&x=99&y=10&player.autoLogin=" + autoLoginValue; //0";
	   
	   return loginString;
	}
	
	/**
	* The URL of the "log out" service for VideoJax.com
	*/	
	var logOutUrl = "/videocube/home.htm?do=logout";
					
	function handleLogOutFromGameServerComplete () {
	}	
	
	var m_afterLogOutCallback = null;
	/**
	* This sends a "log out" message to VideoJax.com using an HTTP GET.
	*/
	function logOut ( afterLogOutCallback ) {
	
	    
	    if ( m_currentlyLoggingInOrOut ) {
			alert ( "Sorry, we have encountered a problem. Please click your browser's refresh button." );
			return;
		} 
		
		m_afterLogOutCallback = afterLogOutCallback;
		
		logOutFromWebSite ( m_afterLogOutCallback ) ;
		
	}

     
	 function logOutFromWebSite ( afterLogOutCallback ) {

	    m_currentlyLoggingInOrOut = true;
			
	//  alert ( "DO LOG OUT" );
	   
		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");
		}
		
		var uniqueLogOutUrl = logOutUrl + ( "&uniqueCallId=" + getNextUniqueCallId () );
				
		self.xmlHttpReq.open('GET', uniqueLogOutUrl, true);
		self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		self.xmlHttpReq.onreadystatechange = function() {

           if (self.xmlHttpReq.readyState == 4) {
			  		 
			    try {
				   showLogInForm ();
				   setUserIsLoggedOut (); 
				   if ( afterLogOutCallback ) {
					  afterLogOutCallback ();
				   }
				} catch ( excdone ) {
					// alert ( " DONE EXC: " + excdone );
				}
				
				/**
				* Scott 9/25.  Needed to clear value of the logged in user's name.  This is passed into the game when you play it.  If someone logs
				* out then this wasn't being cleared.  So even if they were logged out, the game was passed their name!!!  So it incorrectly appeared to
				* be in the "you are logged in" mode.
				*/
				window["m_pjuserName"] = null;
				
				// SCOTT 9/25.  THIS CAUSED LOG OUT NOT TO WORK... setCookie ( "pjuid", "null" );
			    logOutFromGameServer ( handleLogOutFromGameServerComplete );
				m_currentlyLoggingInOrOut = false;
			}
		}
				
		self.xmlHttpReq.send(null); 	
	}
	
	
    function showPopQuizRulesScreen () {	
	   showTranslucentPopupOverlay ();
	   showPopUpOverlayContainer ();
	   showPopQuizRulesPage ();
	}
	
	function hidePopQuizRulesScreen () {
	   hideTranslucentPopupOverlay (); 
	   hidePopUpOverlayContainer (); 
		hidePopQuizRulesPage ();
		hidePop4RulesPage ();
		hidePopSpinRulesPage ();	
	}		
	
    function showPop4RulesScreen () {	
	   showTranslucentPopupOverlay ();
	   showPopUpOverlayContainer ();
	   showPop4RulesPage ();
	}
	
	function hidePop4RulesScreen () {
	   hideTranslucentPopupOverlay (); 
	   hidePopUpOverlayContainer (); 
		hidePopQuizRulesPage ();
		hidePop4RulesPage ();
		hidePopSpinRulesPage ();	
	}		
	
    function showPopSpinRulesScreen () {	
	   showTranslucentPopupOverlay ();
	   showPopUpOverlayContainer ();
	   showPopSpinRulesPage ();
	}
	
	function hidePopSpinRulesScreen () {
	   hideTranslucentPopupOverlay (); 
	   hidePopUpOverlayContainer (); 
	   
		hidePopQuizRulesPage ();
		hidePop4RulesPage ();
		hidePopSpinRulesPage ();	   
	}		


	function switchFromRulesToRegisterScreen () {
		hidePopQuizRulesPage ();
		hidePop4RulesPage ();
		hidePopSpinRulesPage ();
		showRegistrationPage ();
	}

	
	function showPopQuizRulesPage () {
		$("popQuizRulesOverlay").style.display = "block";
	}
	
	function hidePopQuizRulesPage () {
		$("popQuizRulesOverlay").style.display = "none";
	}	
	
	function showPop4RulesPage () {
		$("pop4RulesOverlay").style.display = "block";
	}
	
	function hidePop4RulesPage () {
		$("pop4RulesOverlay").style.display = "none";
	}	
	
	function showPopSpinRulesPage () {
		$("popSpinRulesOverlay").style.display = "block";
	}
	
	function hidePopSpinRulesPage () {
		$("popSpinRulesOverlay").style.display = "none";
	}	


    /**
	* This function shows the registration screen "overlay" over the contents of the current web page.
	*/
    function showRegistrationScreen () {	

	   showTranslucentPopupOverlay ();
	   showPopUpOverlayContainer ();
	   showRegistrationPage ();
	   
	   setDidNotBounceFromSite ();

	}

    function showNewRegistrationScreen () {	

	   showTranslucentPopupOverlay ();
	   showPopUpOverlayContainer ();
	   showNewRegistrationPage ();
	}
    function showNewRegLoginScreen () {	

	   showTranslucentPopupOverlay ();
	   showPopUpOverlayContainer ();
	   showNewRegLoginPage ();
	}



    function hideNewRegistrationScreen () {	
	
	   hideNewRegistrationPage ();
	   
	   hideTranslucentPopupOverlay ();
	   hidePopUpOverlayContainer ();
	   
	   //var popupOverlayBack = document.getElementById ( "popupOverlayBack" );
	   //delete popupOverlayBack.onclick;
	}

function registerFromPopUpLoginScreen() {
	hideLogInOverlayPage();
	showRegistrationPage();
}
 
 function showRegistrationScreenPrizes () {	
	
	   hidePrizeRulesPage();
	   showTranslucentPopupOverlay ();
	   showPopUpOverlayContainer ();
	   showRegistrationPage ();

	}

 function showNewRegistrationScreenPrizes () {	
	
	   hidePrizeRulesPage();
	   showTranslucentPopupOverlay ();
	   showPopUpOverlayContainer ();
	   showNewRegistrationPage ();

	}

	
	function showPrizeRulesScreen (){
		showTranslucentPopupOverlay ();
	   showPopUpOverlayContainer ();
	   showPrizeRulesPage ();
	}
	
	function hidePrizeRulesScreen (){
		hideTranslucentPopupOverlay ();
	   hidePopUpOverlayContainer ();
	   hidePrizeRulesPage ();
	}
	
	function showConfirmScreen () {	
	
	  var width = document.body.offsetWidth;
		    showTranslucentPopupOverlay ();
	   showPopUpOverlayContainer ();
	   showConfirmPage();

	}
	
	function showFeedbackScreen () {	
		showTranslucentPopupOverlay ();
		showPopUpOverlayContainer ();
	   showFeedbackPage ();
	}
	
	function hideFeedbackScreen () {	
		hideTranslucentPopupOverlay ();
		hidePopUpOverlayContainer ();
	   hideFeedbackThanks ();
	}
	
	function showNewLogInOverlayPage () {
		if ( $("login_loginDialog") ) {
			login_showLoginScreen ();
		   //$("login_loginDialog").style.display = "block";
		}
	}
	
	function hideNewLogInOverlayPage () {
		if ( $("login_loginDialog") ) {
			login_hideLoginScreen ();
		   // $("login_loginDialog").style.display = "none";
		}		
	}
	
	function showLogInOverlayPage () {
		if ( $("logInOverlayPage") ) {
		   $("logInOverlayPage").style.display = "block";
		}
	}
	
	function hideLogInOverlayPage () {
		if ( $("logInOverlayPage") ) {
		   $("logInOverlayPage").style.display = "none";
		}		
	}
	
	function showEmailOverlayPage () {
		if ( $("emailOverlayPage") ) {
			$("emailOverlayPage").style.display = "block";
		}
	}
	
	function hideEmailOverlayPage () {
		if ( $("emailOverlayPage") ) {
			$("emailOverlayPage").style.display = "none";
		}
	}
	

    /**
	* This function shows the pop up login screen "overlay" over the contents of the current web page.
	*/
    function showNewPopUpLoginScreen () {	
       showTranslucentPopupOverlay ();
	   showPopUpOverlayContainer (); 
	   showNewLogInOverlayPage (); 
	}	

    function hideNewPopUpLoginScreen () {
		 hideNewLogInOverlayPage ();
       hideTranslucentPopupOverlay ();
	   hidePopUpOverlayContainer (); 
	    
	}	
	
	
    /**
	* This function shows the pop up login screen "overlay" over the contents of the current web page.
	*/
    function showPopUpLoginScreen () {	
	
		    showTranslucentPopupOverlay ();
		   //$("popupOverlayBack").className = "overlayVisible";
	     showPopUpOverlayContainer (); //$("popupOverlayContainer").className = "overlayVisible";
	     showLogInOverlayPage (); // $("logInOverlayPage").className = "overlayVisible";
	}	
	
	
	  function showPopUpLoginScreenA7x (gameId) {	
	     //window.gameid = gameId;
		 
		    window["m_gameId"] = gameId;
	
		    showTranslucentPopupOverlay ();
		   //$("popupOverlayBack").className = "overlayVisible";
	     showPopUpOverlayContainer (); //$("popupOverlayContainer").className = "overlayVisible";
	     showLogInOverlayPage (); // $("logInOverlayPage").className = "overlayVisible";
		 
		
	}	
	var m_emailFromScreenId = null;
	
    /**
	* This function shows the pop up login screen "overlay" over the contents of the current web page.
	*/
    function showEmailLoginScreen ( _emailFromScreenId, _questionId ) {	
	
	     m_emailFromScreenId = _emailFromScreenId;
		 
	     if ( _questionId ) {
			 m_questionId = _questionId;
		 }
		 
		 // alert ( "FOO" );
		 
		 
		 showTranslucentPopupOverlay ();
		   //$("popupOverlayBack").className = "overlayVisible";
	     showPopUpOverlayContainer (); //$("popupOverlayContainer").className = "overlayVisible";
	     showEmailOverlayPage (); // $("logInOverlayPage").className = "overlayVisible";
	}		
	
	/**
	* Returned in form-encoded format for POST
	*/
	
	
	
	
	function getRegistrationFormData () {
	    
		// var loginString = "mode=1&player.name=" + userId.value + "&player.password=" + password.value + "&x=99&y=10";
		
		var registrationScreenNameValue = $("registrationScreenName").value;
		var registrationPasswordValue = $("registrationPassword").value;
		var registrationRetypePasswordValue = $("registrationRetypePassword").value;
		var registrationEmailValue = $("registrationEmail").value;
				
		var registrationFormData = "mode=2&player.name=" + escape(registrationScreenNameValue);
		registrationFormData += "&player.password=" + escape(registrationPasswordValue);
		registrationFormData += "&password2=" + escape(registrationRetypePasswordValue);
		registrationFormData += "&player.email=" + escape(registrationEmailValue);
		registrationFormData += "&j_captcha_response=blabla&x=38&y=13";
		registrationFormData += "&player.autoLogin=0";
		
	//	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;
	}
	
	function popupEmailDataIsValid () {
		
		var dataIsValid = false;

//alert ("PLACE 1" );

		var overallPopUpEmailError = $("overallPopUpEmailError");
		overallPopUpEmailError.innerHTML = "";
		
	/*
			if ( registrationEmailValue.indexOf ( "@" ) < 0 || registrationEmailValue.indexOf ( "." ) < 0 ) {
		   overallErrorArea.innerHTML = "Invalid email format.  Please enter a valid email address";
		   return dataIsValid;
		}
	*/
	
		//var logInPopupPasswordError = $("logInPopupPasswordError");
		//logInPopupPasswordError.innerHTML = "";
		
		var emailPopupToAddressValue = $("emailPopupToAddress").value;
		var emailPopupMessageValue = $("emailPopupMessage").value;
		

		
		if ( emailPopupToAddressValue == "" ) {
		   overallPopUpEmailError.innerHTML = "Please enter a destination email address";
		   return dataIsValid;
		}
		
		if ( emailPopupToAddressValue.indexOf ( "@" ) < 0 || emailPopupToAddressValue.indexOf ( "." ) < 0 ) {
		   overallPopUpEmailError.innerHTML = "Invalid email format.  Please enter a valid email address";
		   return dataIsValid;
		}	
		
		if ( emailPopupMessageValue == "" ) {
		   overallPopUpEmailError.innerHTML = "Please enter a message";
		   return dataIsValid;
		}		
		
		
		// If we made it this far, the data is all valid!
		dataIsValid = true;
		
		return dataIsValid;
		
	}
	


function doFeedback (){
    var feedback_contents = document.getElementById ( "feedback_contents" );
    feedback_contents.style.display = "none";

	var feedbackThanks = document.getElementById ( "feedbackThanks" );
	feedbackThanks.style.display = "block";
            
	var feedback =  document.getElementById ( "feedback" );
	var feedbackText = feedback.value;
            
	var feedbackEmail =  document.getElementById ( "feedbackEmail" );
	var feedbackEmailText = feedbackEmail.value;

dataService_userFeedback ( handleFeedbackSent, feedbackEmailText, feedbackText );
  }
	


function handleFeedbackSent ( data, xml ) {

                //alert ( "FEEDBACK SENT!" );

}	
	
/**
	* This function validates that the user has entered valid data into the pop up login form.  If the data isn't valid, then
	* this function displays the appropraite error message in the form and returns "false". If all the data is valid, then
	* this function returns "true."
	*/
	function popLogInDataIsValid () {
		var dataIsValid = false;
		
		var overallPopUpLoginError = $("overallPopUpLoginError");
		overallPopUpLoginError.innerHTML = "";
		
		//var logInPopupPasswordError = $("logInPopupPasswordError");
		//logInPopupPasswordError.innerHTML = "";
		
		var logInPopupUserIdValue = $("logInPopupUserId").value;
		var logInPopupPasswordValue = $("logInPopupPassword").value;
		
		if ( logInPopupUserIdValue == "" ) {
		   overallPopUpLoginError.innerHTML = "Please enter a user id";
		   return dataIsValid;
		}
		
		if ( logInPopupPasswordValue == "" ) {
		   overallPopUpLoginError.innerHTML = "Please enter a password";
		   return dataIsValid;
		}
				
		if ( logInPopupPasswordValue.length < 4 || logInPopupPasswordValue.length > 10 ) {
		   overallPopUpLoginError.innerHTML = "Passwords must be between 4 and 10 characters";
		   return dataIsValid;		
		}
		
		// If we made it this far, the data is all valid!
		dataIsValid = true;
		
		return dataIsValid;
		
		
	}
	
	/**
	* This function validates that the user has entered valid data into the registration form.  If the data isn't valid, then
	* this function displays the appropraite error message in the form and returns "false". If all the data is valid, then
	* this function returns "true."
	*/
	function registrationDataIsValid () {
	    var dataIsValid = false;
		
		//var registrationScreenNameError = $("registrationScreenNameError");
		//registrationScreenNameError.innerHTML = "";
		
		//var registrationPasswordError = $("registrationPasswordError");
		//registrationPasswordError.innerHTML = "";
		
		//var registrationRetypePasswordError = $("registrationRetypePasswordError");
		//registrationRetypePasswordError.innerHTML = "";
		
		//var registrationEmailError = $("registrationEmailError");
		//registrationEmailError.innerHTML = "";
		
		var overallErrorArea = $("overallRegistrationError");
		overallErrorArea.innerHTML = "";
		
		var registrationScreenNameValue = $("registrationScreenName").value;
		var registrationPasswordValue = $("registrationPassword").value;
		var registrationRetypePasswordValue = $("registrationRetypePassword").value;
		var registrationEmailValue = $("registrationEmail").value;
		
		if ( registrationScreenNameValue == "" ) {
		   overallErrorArea.innerHTML = "Please enter a screen name";
		   return dataIsValid;
		}
		
		if ( registrationPasswordValue == "" ) {
		   overallErrorArea.innerHTML = "Please enter a password";
		   return dataIsValid;
		}
				
		if ( registrationPasswordValue.length < 4 || registrationPasswordValue.length > 10 ) {
		   overallErrorArea.innerHTML = "Passwords must be between 4 and 10 characters";
		   return dataIsValid;		
		}
		
		if ( registrationRetypePasswordValue == "" ) {
		   overallErrorArea.innerHTML = "Please retype your password in the field above";
		   return dataIsValid;
		}		
		
		if ( registrationPasswordValue != registrationRetypePasswordValue ) {
		   overallErrorArea.innerHTML = "The two passwords you entered do not match";
		   return dataIsValid;
		}				
		
		
		if ( registrationEmailValue == "" ) {
		   overallErrorArea.innerHTML = "Please enter an email address";
		   return dataIsValid;
		}		
		
		if ( registrationEmailValue.indexOf ( "@" ) < 0 || registrationEmailValue.indexOf ( "." ) < 0 ) {
		   overallErrorArea.innerHTML = "Invalid email format.  Please enter a valid email address";
		   return dataIsValid;
		}		
		
		
		// If we made it this far, the data is all valid!
		dataIsValid = true;
		
		return dataIsValid;
	}
	
	/**
	* This is called if the user clicks "Accept" on the registration form.  It first validates that the registration
	* data is valid. If so, then it does an HTTP POST of the registration data to the VideoJax.com back end.
	*/
	function acceptRegistrationTerms ( afterRegistrationCallback ) {
		
		if ( m_currentlyLoggingInOrOut ) {
			// alert ( "SORRY" );
		} else {
	       if ( registrationDataIsValid () ) {
			   hideRegistrationPage (); //$("registrationPage").style.display = "none"; //.className = "overlayHidden";
			   m_currentlyLoggingInOrOut = true;
			   postRegistrationData ();
			   
		   }
		}
	}
	
	function acceptDuranRegistrationTerms ( afterRegistrationCallback ) {
		
		if ( m_currentlyLoggingInOrOut ) {
			// alert ( "SORRY" );
		} else {
	       if ( registrationDataIsValid () ) {
			   hideRegistrationPage (); //$("registrationPage").style.display = "none"; //.className = "overlayHidden";
			   m_currentlyLoggingInOrOut = true;
			   postRegistrationData ();
			 

			  			   
		   }
		}
	}

	
	function emailPopupDoEmail ( questionId ) {
		
		//alert ( "EMAIL THIS QUESTION: " + questionId );
		
		if ( m_currentlyLoggingInOrOut ) {
			// alert ( "SORRY" );
		} else {
			
			// alert ( "ABOUT TO CHECK" );
            if ( popupEmailDataIsValid () ) {
				
				// alert ( "IS VALID" );
				
			   m_currentlyLoggingInOrOut = true;
			  // hideEmailOverlayPage (); 
		       showSpinnerLoginDiv (); 
			   
		       try {
		           showSpinner ( "spinnerDuringLoginDiv" );	   
		       } catch ( exc ) {
			       // alert ( "EXC: " + exc );
		       }

		
	           postEmailFormData ( questionId );

		   }			
		}
		
	}


	function logInPopupDoLogin ( afterLoginCallback ) {
		
		if ( m_currentlyLoggingInOrOut ) {
			// alert ( "SORRY" );
		} else {
            if ( popLogInDataIsValid () ) {
				
				
			   m_currentlyLoggingInOrOut = true;
			   hideLogInOverlayPage (); // $("logInOverlayPage").className = "overlayHidden";
		       showSpinnerLoginDiv (); // $("spinnerDuringLoginDiv").className = "overlayVisible";
			   
		       try {
		           showSpinner ( "spinnerDuringLoginDiv" );	   
		       } catch ( exc ) {
			       // alert ( "EXC: " + exc );
		       }
		  
		//alert ( "CALLBACK SHOUDL BE: " + afterLoginCallback );
		
	           postLoginFormData ( afterLoginCallback, getLogInPostQueryStringFromPopUp );
				window.location.reload();
		
			   /*$("registrationPage").className = "overlayHidden";
			   $("spinnerDuringLoginDiv").className = "overlayVisible";
			   showSpinner ( "spinnerDuringLoginDiv" );
			   m_currentlyLoggingInOrOut = true;
		       postRegistrationData ( afterRegistrationCallback );*/
		   }			
		}
		
	}
	
function logInPopupDoLoginA7x ( afterLoginCallback, gameId, my_pjuid ) {
		
		if ( m_currentlyLoggingInOrOut ) {
			// alert ( "SORRY" );
		} else {
            if ( popLogInDataIsValid () ) {
				
				
			   m_currentlyLoggingInOrOut = true;
			   hideLogInOverlayPage (); // $("logInOverlayPage").className = "overlayHidden";
		       showSpinnerLoginDiv (); // $("spinnerDuringLoginDiv").className = "overlayVisible";
			   
		       try {
		           showSpinner ( "spinnerDuringLoginDiv" );	   
		       } catch ( exc ) {
			       // alert ( "EXC: " + exc );
		       }
		  
		//alert ( "CALLBACK SHOUDL BE: " + afterLoginCallback );
		
	           postLoginFormData ( afterLoginCallback, getLogInPostQueryStringFromPopUp );
				window.location.reload();
		
			   /*$("registrationPage").className = "overlayHidden";
			   $("spinnerDuringLoginDiv").className = "overlayVisible";
			   showSpinner ( "spinnerDuringLoginDiv" );
			   m_currentlyLoggingInOrOut = true;
		       postRegistrationData ( afterRegistrationCallback );*/
		   }			
		}
		
	}
		
	
	
	function getEmailQuestionDataFromPopUp () {
	   var emailPopupToAddress= $("emailPopupToAddress");
	   var emailPopupMessage = $("emailPopupMessage");
	   
	   
	   var emailString = "emailTo=" + emailPopupToAddress.value + "&userText=" + emailPopupMessage.value;
	   
	   return emailString;				
	}
	
	/*
	postLoginFormData
	*/
	
	function getLogInPostQueryStringFromPopUp () {
	   var userId = $("logInPopupUserId");
	   var password = $("logInPopupPassword");
	   
	   

	   var loginString = "mode=1&player.name=" + userId.value + "&player.password=" + password.value + "&x=99&y=10&player.autoLogin=0";
	   
	   return loginString;		
	}
	
	
	/**
	* Called when the user "declines" the registration terms and conditions.  Currently simply removes the
	* registration form and overlay from the screen.
	*/
	function declineRegistrationTerms () {
	   hideTranslucentPopupOverlay (); //$("popupOverlayBack").className = "overlayHidden";
	   hidePopUpOverlayContainer(); //$("popupOverlayContainer").style.display = "none"; //className = "overlayHidden";
	   hideRegistrationPage (); //$("registrationPage").style.display = "none"; //className = "overlayHidden";
       hideSpinnerLoginDiv (); // $("spinnerDuringLoginDiv").className = "overlayHidden";
	   hideSpinner ( "spinnerDuringLoginDiv" );	   
	}
	function cancelFeedbackEntry () {
	   hideTranslucentPopupOverlay (); //$("popupOverlayBack").className = "overlayHidden";
	   hidePopUpOverlayContainer(); //$("popupOverlayContainer").style.display = "none"; //className = "overlayHidden";
	   hideFeedbackPage(); //$("registrationPage").style.display = "none"; //className = "overlayHidden";
       hideSpinnerLoginDiv (); // $("spinnerDuringLoginDiv").className = "overlayHidden";
	   hideSpinner ( "spinnerDuringLoginDiv" );	   
	}
	
	/**
	* Called when the user "cancels" from the pop up login form.  
	*/
	function cancelPopUpLogIn () {
	   hideTranslucentPopupOverlay (); //$("popupOverlayBack").className = "overlayHidden";
	   hidePopUpOverlayContainer (); // $("popupOverlayContainer").className = "overlayHidden";
	   hideLogInOverlayPage (); //$("logInOverlayPage").className = "overlayHidden";
       hideSpinnerLoginDiv (); //$("spinnerDuringLoginDiv").className = "overlayHidden";
	   hideSpinner ( "spinnerDuringLoginDiv" );	   
	}	
	
	/**
	* The URL of the "register" service for VideoJax.com
	*/		
	//var registerUrl = "./dummyData/dummyRegisterResponse.html"; ///videocube/login.htm";
    var 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 postRegistrationData ( afterRegistrationCallback ) {
	
	    var strURL = 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 );
				   
				   $("overallRegistrationError").innerHTML = registrationErrorString;
				   
				   showRegistrationPage (); //$("registrationPage").className = "overlayVisible";
				   hideSpinnerLoginDiv (); // $("spinnerDuringLoginDiv").className = "overlayHidden";
				   hideSpinner ( "spinnerDuringLoginDiv" );
				   
				} else {
				
				//   alert ( "COOL" );
				   
				   try {
					   
	                showTranslucentPopupOverlay (); //$("popupOverlayBack").style.display = "none";// className = "overlayHidden";
	                showPopUpOverlayContainer (); //$("popupOverlayContainer").style.display = "none";//.className = "overlayHidden";	
				    hideRegistrationPage (); // $("registrationPage").style.display = "none";//.className = "overlayHidden";
				    hideSpinnerLoginDiv (); // $("spinnerDuringLoginDiv").style.display = "none";//.className = "overlayHidden";
			       hideSpinner ( "spinnerDuringLoginDiv" );
				   } catch ( exchide ) {
					    // alert ( "EXCHIDE: " + exchide );
				   }
				   showConfirmScreen();
				   var userId = $("userId");
				   var registrationScreenNameValue = $("registrationScreenName").value;
				   userId.value = registrationScreenNameValue;
	  // $("userNameLoggedIn").innerHTML = userId.value;		
	   
	   				hideLogInForm ();
					
				   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) );
				   }					
					
					if ( afterRegistrationCallback ) {
						afterRegistrationCallback (pjuid);
			
					}
					
				 //  alert ( "YOU ARE REGISTERED AND LOGGED IN" );
				   //hideLogInForm ();
			
			if (document.affiliateForm.affiliateOptIn.checked) {
			    storeUserComment (pjuid, "optInToDuranEmailList" );
				//alert (pjuid);
			}		   
				}
				m_currentlyLoggingInOrOut = false;
				
				// alert ( " RESP: " + self.xmlHttpReq.responseText );
			}
		}
		self.xmlHttpReq.send(getRegistrationFormData());
	}
	
	var sURL = unescape(window.location.pathname);
	function _reload_Page()
	{
		// alert ("RELOAD: " + sURL ) ;
		
		if ( typeof window.location.replace == 'function' )    
		  window.location.replace ( sURL );
        else
		  window.location.href = sURL;
	}
	
	function refreshPage ( forceRefresh ) 
	{
		if ( forceRefresh || doReplacePngs ) 
		{	
			_reload_Page();	
		}
	}
	
	function popUpTermsAndConditions () {
		window.open ( 'site/terms.html', 'terms', 'scrollbars=yes, width=600, height=500, resizable=yes, location=no, menubar=no, titlebar=no, toolbar=no' ); 
	}
	
		function popUpContestRules() {
		window.open ( 'site/terms.html#SaQrules', 'terms', 'scrollbars=yes, width=600, height=500, resizable=yes, location=no, menubar=no, titlebar=no, toolbar=no' ); 
	}
		function popUpPrivacyPolicy () {
		window.open ( 'site/privacy.html', 'terms', 'scrollbars=yes, width=600, height=500, resizable=yes, location=no, menubar=no, titlebar=no, toolbar=no' ); 
	}
	
	function getNextUniqueCallId () {
		
	    var uniqueCallId = getCookie ( "uniqueCallId" );
		
		if ( uniqueCallId == null ) {
			uniqueCallId = 1;
		} else {
			uniqueCallId = Number(uniqueCallId) + 1;
		}
		setCookie ( "uniqueCallId", uniqueCallId );
	
	   return uniqueCallId;
	}
 
 
 
 /*******************************************
 Form balloon tooltips
 ********************************************/
 /* adds a smooth, hidden onload event */
 function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
window.onload = function() {
      oldonload();
      func();
    }
  }
}
// Shows/Hides tooltip on input or select focus
function prepareInputsForHints() {
  var inputs = document.getElementsByTagName("input");
  for (var i=0; i<inputs.length; i++){
    if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
      inputs[i].onfocus = function () {
        this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
      }
      inputs[i].onblur = function () {
        this.parentNode.getElementsByTagName("span")[0].style.display = "none";
      }
    }
  }
  var selects = document.getElementsByTagName("select");
  for (var k=0; k<selects.length; k++){
    if (selects[k].parentNode.getElementsByTagName("span")[0]) {
      selects[k].onfocus = function () {
        this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
      }
      selects[k].onblur = function () {
        this.parentNode.getElementsByTagName("span")[0].style.display = "none";
      }
    }
  }
}
addLoadEvent(prepareInputsForHints);

function doMagicMarketingStuff () 
{
	  //get the shim image placed in page3 of the registration process
      var shimImage = document.getElementById("shimSEM");
	  if ( shimImage != null )
	  {
        var shimsem = document.createElement("img");
        shimsem.setAttribute("src",
			"http://www.googleadservices.com/pagead/conversion/1066038405/?label=GEI1CO_QURCF6an8Aw&amp;script=0");
        var imgParent = shimImage.parentNode;
        imgParent.replaceChild(shimsem, shimImage);
        //alert ("Image source has changed!", shimsem.src);
	  }
}

