
		var allowed = 'no';
		var myError = document.getElementById('errortext');
		var myError2 = document.getElementById('errortext2');
		


		function ajaxFunction(a,b,c){
		var ajaxRequest;  // The variable that makes Ajax possible!
		
		try{
			// Opera 8.0+, Firefox, Safari
			ajaxRequest = new XMLHttpRequest();
		} catch (e){
			// Internet Explorer Browsers
			try{
				ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try{
					ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){
					// Something went wrong
					alert("Your browser broke!");
					return false;
				}
			}
		}
		// Create a function that will receive data sent from the server
			ajaxRequest.onreadystatechange = function(){
			if(ajaxRequest.readyState == 4){
				var ajaxDisplay = document.getElementById('ajaxDiv');
				//ajaxDisplay.innerHTML = ajaxRequest.responseText;
				allowed = ajaxRequest.responseText;
				if(allowed == 'yes') {
					if (a == 'login' || a == 'signup') { window.location = "index.php" } else { document.getElementById(a).style.display = 'inline'; document.getElementById(b).style.display = 'none'; document.getElementById(c).style.display = 'none';}
				} else if (a == 'signup') { document.getElementById(a).style.display = 'inline'; document.getElementById(b).style.display = 'none'; document.getElementById(c).style.display = 'none'; 
				} 
				else { login(); }
			}
		}

		ajaxRequest.open("GET", "updatesession.php", true);
		ajaxRequest.send(null); 
		}
		
		
		
		
		function loadingbar(){
			var loadingbar = document.getElementById('notice'); loadingbar.innerHTML = 'File Uploading...';
		}
		
		
		function forgot(){
			document.getElementById('forgot').style.display = 'inline'; document.getElementById('login').style.display = 'none'; 
		}
		
		
		
		function killsession(){
		var ajaxRequest;  // The variable that makes Ajax possible!
		
		try{
			// Opera 8.0+, Firefox, Safari
			ajaxRequest = new XMLHttpRequest();
		} catch (e){
			// Internet Explorer Browsers
			try{
				ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try{
					ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){
					// Something went wrong
					alert("Your browser broke!");
					return false;
				}
			}
		}
		// Create a function that will receive data sent from the server
			ajaxRequest.onreadystatechange = function(){
			if(ajaxRequest.readyState == 4){
				var ajaxDisplay = document.getElementById('ajaxDiv');
				//ajaxDisplay.innerHTML = ajaxRequest.responseText;
				allowed = ajaxRequest.responseText;
				window.location = "/"
			}
		}

		ajaxRequest.open("GET", "sessiondone.php", true);
		ajaxRequest.send(null); 
		}
		
		
		
		
		
		
		
		
		
		
		function loggingin(x,y){
			
		
		var ajaxRequest;  // The variable that makes Ajax possible!
		
		try{
			// Opera 8.0+, Firefox, Safari
			ajaxRequest = new XMLHttpRequest();
		} catch (e){
			// Internet Explorer Browsers
			try{
				ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try{
					ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){
					// Something went wrong
					alert("Your browser broke!");
					return false;
				}
			}
		}
		
		
		
		
		
		// Create a function that will receive data sent from the server
			ajaxRequest.onreadystatechange = function(){
			if(ajaxRequest.readyState == 4){
				var nowlogged = ajaxRequest.responseText;
				if(nowlogged == 1)  {
					
					var d = document.getElementById("commentfields2");
					if (d) {
						document.getElementById('commentfields2').style.display = 'inline';
						document.getElementById('commentfields2b').style.display = 'inline';
						document.getElementById('commentfields3').style.display = 'none';
					}
					
					
					document.getElementById('login').style.display = 'none';
					//document.getElementById('upload').style.display = 'inline';
					opacityon('panel');
					opacityon('panels');
					var status = document.getElementById('status');
					status.innerHTML = "<a href='#' onclick='logout();'>LOGOUT</a>";
					var status2 = document.getElementById('status2');
					status2.innerHTML = "<a href='javascript:upload()'><img src='images/upload.jpg' style='vertical-align:middle;' border='0'></a>";
					var status3 = document.getElementById('status3');
					status3.innerHTML = "";
					nowlogged = '';
					
				} else { var myError = document.getElementById('errortext'); myError.innerHTML = 'Username or password incorrect.'; }
				 
			}
		}

		
		
		ajaxRequest.open("GET", "login.php?email="+x+"&password="+y, true);
		ajaxRequest.send(null); 
		}
		
		
		
		
		
		
		function sendpassword(x){
					
		var ajaxRequest3;  // The variable that makes Ajax possible!
		
		try{
			// Opera 8.0+, Firefox, Safari
			ajaxRequest3 = new XMLHttpRequest();
		} catch (e){
			// Internet Explorer Browsers
			try{
				ajaxRequest3 = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try{
					ajaxRequest3 = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){
					// Something went wrong
					return false;
				}
			}
		}
		
		
		// Create a function that will receive data sent from the server
			ajaxRequest3.onreadystatechange = function(){
			if(ajaxRequest3.readyState == 4){
				var sent = ajaxRequest3.responseText;
				if(sent == 1)  { 
					var status3 = document.getElementById('errortext3');
					status3.innerHTML = "An email has been sent.";
					sent = '';
				} else { var myError3 = document.getElementById('errortext3'); myError3.innerHTML = 'Email not found.'; }
				 
			}
		}

		
		
		ajaxRequest3.open("GET", "sendpassword.php?email="+x, true);
		ajaxRequest3.send(null); 
		}





		function signupnow(email,surname,firstname,username,country,password2) {
		var ajaxRequest4;  // The variable that makes Ajax possible!
		
		try{
			// Opera 8.0+, Firefox, Safari
			ajaxRequest4 = new XMLHttpRequest();
		} catch (e){
			// Internet Explorer Browsers
			try{
				ajaxRequest4 = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try{
					ajaxRequest4 = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){
					// Something went wrong
					return false;
				}
			}
		}
		
		//alert('test');
		
		// Create a function that will receive data sent from the server
			ajaxRequest4.onreadystatechange = function(){
			if(ajaxRequest4.readyState == 4){
				var sent = ajaxRequest4.responseText;
				if(sent == 1)  { 
					var myError2 = document.getElementById('errortext2'); myError2.innerHTML = 'Thanks for signing up. Please check<br>your email for login information.';
				}
				if(sent == 2)  { 
					var myError2 = document.getElementById('errortext2'); myError2.innerHTML = 'Email address or username already exist.';
					
				} sent = '';
				
			}
		}

		
		
		ajaxRequest4.open("GET", "signup.php?email="+email+"&firstname="+firstname+"&surname="+surname+"&username2="+username+"&country="+country+"&password2="+password2, true);
		ajaxRequest4.send(null); 
		}
		
		
		
		


	
			function opacity(id){
				if (document.getElementById("panel")) {
				el = document.getElementById(id);
					el.style.opacity = ('.30');
					el.style.MozOpacity = ('.30');
					el.style.KhtmlOpacity = ('.30');
					el.style.filter = "alpha(opacity='10%')";
				}
				if (document.getElementById("panels")) {
				el = document.getElementById(id);
					el.style.opacity = ('.30');
					el.style.MozOpacity = ('.30');
					el.style.KhtmlOpacity = ('.30');
					el.style.filter = "alpha(opacity='10%')";
				}
			}
			
			function opacityon(id){
				if (document.getElementById("panel")) {
				el = document.getElementById(id);
					el.style.opacity = ('1');
					el.style.MozOpacity = ('1');
					el.style.KhtmlOpacity = ('1');
					el.style.filter = "alpha(opacity='100%')";
				}
				if (document.getElementById("panels")) {
				el = document.getElementById(id);
					el.style.opacity = ('1');
					el.style.MozOpacity = ('1');
					el.style.KhtmlOpacity = ('1');
					el.style.filter = "alpha(opacity='100%')";
				}
			}
		
			

		
			function upload() { opacity('panel'); opacity('panels'); document.getElementById('forgot').style.display = 'none';  ajaxFunction('upload','login','signup');  }
			function signup() { opacity('panel'); opacity('panels'); document.getElementById('forgot').style.display = 'none';  ajaxFunction('signup','login','upload'); var myError2 = document.getElementById('errortext2'); myError2.innerHTML = ''; }
			function login() { opacity('panel'); opacity('panels'); document.getElementById('forgot').style.display = 'none';  var myError = document.getElementById('errortext'); myError.innerHTML = ''; var myError2 = document.getElementById('errortext2'); myError2.innerHTML = ''; document.getElementById('upload').style.display = 'none'; document.getElementById('signup').style.display = 'none'; document.getElementById('login').style.display = 'inline'; }
			function logout() { killsession(); }
			function uploadpopup() { opacity('panel'); opacity('panels');  document.getElementById('forgot').style.display = 'none';document.getElementById('upload').style.display = 'none'; var myError = document.getElementById('errortext'); myError.innerHTML = ''; document.getElementById('signup').style.display = 'none'; document.getElementById('login').style.display = 'inline'; }
			
			
			function closeme() { opacityon('panel'); opacityon('panels');  document.getElementById('signup').style.display = 'none';  document.getElementById('forgot').style.display = 'none'; document.getElementById('upload').style.display = 'none'; document.getElementById('login').style.display = 'none'; }
			
		
		
		
		
		
		
		
		
		function validateForm()
		{
		var x=document.forms["myForm"]["fname"].value;
		if (x==null || x=="")
		  {
		  alert("First name must be filled out");
		  return false;
		  }
		}
		
		
		function validateForm3()
		{
		var x=document.forms["forgot"]["email"].value;
		if (x==null || x=="")
		  {
		  var myError3 = document.getElementById('errortext3');
		  myError3.innerHTML = 'Please enter valid email address';
		  } else {sendpassword(x);}
		  return false;
		  
		}
		
		
		
		
		function validateForm(formname)
		{
		var message = '';
		var message = 'Please enter ';
		var myError = document.getElementById('errortext');
		var x=document.forms[formname]["email"].value;
		var y=document.forms[formname]["password"].value;
		var atpos=x.indexOf("@");
		var dotpos=x.lastIndexOf(".");
		  if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
		  {
		  
		  message+= "valid email address";
		  //myError.innerHTML = "Please enter a valid email address.";
		  //return false;
		  }
		  
		  
		  
		  if (y==null || y=="")
		  {
			if (message == 'Please enter valid email address') { message+= " & "; }
			message+= "password";
		  }
		  
		  if (message != 'Please enter ')  { myError.innerHTML = message; return false; }
		  loggingin(x,y);
		  //alert(x);
		  return false;
		}
		
		
		

    
         
		
		
		
		function validateForm2(formname)
		{
			//alert('test');
		var message2 = '';
		var message2 = 'Please enter ';
		var myError2 = document.getElementById('errortext2');
		var x=document.forms[formname]["email"].value;
		var z=document.forms[formname]["surname"].value;
		var y=document.forms[formname]["firstname"].value;
		var d=document.forms[formname]["username"].value;
		var a=document.forms[formname]["country"].value;
		var c=document.forms[formname]["password2"].value;
		var atpos=x.indexOf("@");
		var dotpos=x.lastIndexOf(".");
		  if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
		  {
			message2+= "valid email address";
		  }
		  
		  
		  
		  if (y==null || y=="" || z==null || z=="" || a==null || a=="" || c==null || c=="" || d==null || d=="")
		  {
			if (message2 == 'Please enter valid email address') { message2+= "<Br>& "; }
			message2+= "all required fields.";
		  }
		  
		  if (message2 != 'Please enter ')  { myError2.innerHTML = message2; return false; }
		  //go on to signup.php ajax
		  signupnow(x,z,y,d,a,c);
		  return false;
		}
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
