
	function getHTTPObject(){
   if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) return new XMLHttpRequest();
   else {
      return null;
   }
}   	
	
	function getFlashMovieObject(movieName){
  if (window.document[movieName]){
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1){
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }else{
    return document.getElementById(movieName);
  }
}

var muted = true;

function setMuteNoAjax(){
	//var data = '';
	var data = getCookie('muted');
	if(!data){
		setCookie('muted', 'false');
		data = getCookie('muted');
	}
	
	//if(data[0] != "true"){
	if(data == "false"){
		mute();
		document.getElementById('mute').innerHTML = '<a href="javascript:mute()"><img src="/images/sound_on.gif" /></a>';
	} else {
		document.getElementById('mute').innerHTML = '<a href="javascript:mute()"><img src="/images/sound_off.gif" /></a>';
	}
}

function setMute(){
  if(httpObject.readyState == 4){
		inntekst = httpObject.responseText; 
		var data = inntekst.split( ";");
		if(data[0] != "true"){
			mute();
		}else{
			document.getElementById('mute').innerHTML = '<a href="javascript:mute()"><img src="/images/sound_off.gif" /></a>';
		}
  }
}

function loadMute(){
	setMuteNoAjax();
	/*
    httpObject = getHTTPObject();
    if (httpObject != null) {
        httpObject.open("GET", "/swf/loadsounds.php", true);
        httpObject.send(null); 
        httpObject.onreadystatechange = setMute;
    }
    */
}

function mute(){
	if(muted == false){
		var flashMovie=getFlashMovieObject("seabattle");
		flashMovie.SetVariable("/:mute", true);
		muted = true;
		document.getElementById('mute').innerHTML = '<a href="javascript:mute()"><img src="/images/sound_off.gif" /></a>';
		setCookie('muted', 'true');
	}else{
		var flashMovie=getFlashMovieObject("seabattle");
		flashMovie.SetVariable("/:mute", false);
		muted = false;
		document.getElementById('mute').innerHTML = '<a href="javascript:mute()"><img src="/images/sound_on.gif" /></a>';
		setCookie('muted', 'false');
	}
	/*
	httpObject = getHTTPObject();
	if (httpObject != null) {
		httpObject.open("GET", "/swf/mute.php?muted="+muted, true);
		httpObject.send(null);
	}*/
}


	var ValidJoinName = false;


	function CheckForValidUsername(username) {
		
		new Ajax.Request('/login/ajax/username_check.php', 
	  { 
		parameters: 'username='+username, 
		method:'get', 
		onSuccess: function(transport){		
	
			if(transport.responseText == '1'){
				alert("Username is currently taken.");	
			}
			
			else {
				try{
			
				$('sign_up_username').value= $('check_username').value;
				}catch(ex){};
				
				show_reg();
			}	
		}
	  });
		
	}
	
	// Cookie Functions
	function setCookie(c_name,value,exdays){
		if(!exdays) exdays = 30;
		var exdate=new Date();
		exdate.setDate(exdate.getDate() + exdays);
		var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
		document.cookie=c_name + "=" + c_value;
	}
	
	function getCookie(c_name){
		var i,x,y,ARRcookies=document.cookie.split(";");
		for (i=0;i<ARRcookies.length;i++){
		  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		  x=x.replace(/^\s+|\s+$/g,"");
		  if (x==c_name){
	    	return unescape(y);
	    }
	  }
	}

	// End Cookie Functions





	function ShowSignup (showpopup) {
		return; // for now, its just bombing because the game is missing CheckUsername()! 
		if (!ValidJoinName) CheckUsername();
		
		if(showpopup==null) 
			showpopup=true; 
		
		if(ValidJoinName|| !showpopup ) {
			try {
				$("username").value = $F("username-join"); 
		 		//$("password").value = $F("password-join");
	 		}
	 		catch(er){}
			$("joinlogin").hide();
			$("signupForms").show();
			
		}
		else if(showpopup){
			if ($F("username-join") == ''){
				//alert(" Username can not be blank. ");
			}else{
				//alert(" Username is currently taken. ");
			}
		}
	}


	
	function ShowError(ErrorDiv) {
		$(ErrorDiv+"_check").update(' X ');
	}

	function HideDetails(ID,me) {
		new Ajax.Request("index.php?ajax=mantis", {
		method: 'get',
		parameters: {'id': ID,'show':'details' },
		onSuccess: function(transport) {
		ancestors = me.ancestors();
		ancestors[0].update("<a href=\"#\" onclick=\"ShowDetails('"+ID+"',this); return false;\" >[+]</a>");
		$("bug_details_"+ID).hide();
		  }
		});
		return false;
	}

	// ensure registration form can only be submitted once for those double clickers out there...
	var submittingreg=0;
	function CheckSubmitReg(){
		if (submittingreg) return false;
		submittingreg=1;
		return true;
	}
	
	
	
	
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////
	// START OF LOGIN HEADER FUNCTIONS
	/////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	
	var firstTime = true;

	function show_reg(){
    document.getElementById('error').style.display = 'block';
    if (firstTime){
      updateABTestEntry();
      firstTime = false;
    }
	}
	
	function show_forgot_email(){
    document.getElementById('forgotemail').style.display = 'block';
    
    if (firstTime)
	    firstTime = false;
	}
	
	function show_changepassMessage(errors){
		if (errors){
    	document.getElementById('changepass').style.display = 'block';
    }
    else 
    	alert('Your password has been reset.');
	}
	
	function show_emailMessage(errors){
		if (errors){
    	document.getElementById('forgotemail').style.display = 'block';
    }
    else 
    	alert('Your email has been sent.');
	}
	
	function show_regMessage(errors){
    document.getElementById('error').style.display = 'block';
    if (errors){
      updateABTestEntry();
    }
	}
	
	function check_reg(post, errors, popuperrors){
		try{
	    if (post == 'signup'){
	    	if(popuperrors == 0)
	        show_regMessage(errors);
			}
	    else if (post == 'forgotpass')
	      show_emailMessage(errors);
	   	else if (post == 'resetpass')
	  		show_changepassMessage(errors);
		}
		catch(e){
			console.log('check_reg() failed.');
		}
	}

	function updateABTestEntry(){
		if(has_absession){
		 	var action = 'update';
	  	new Ajax.Request("login/ajax/ajax_ABtest.php", {
        method: 'get',
        parameters: {'action': action, 'timeStart': time_start, 'ipAddress': ip_address, 'testID': test_id},
        onSuccess: function(transport) {}
      });
			return true;
		}
	}
	
