function login(){
			if($F('passlogin') == '' || $F('userlogin') == '')
			{
				alert("Silahkan masukan username dan password dengan benar !.");
				return;
			}
			//AJAX request options
			var opt = {
			method:'post', 
			postBody:'m=login&username=' + $F('userlogin') + '&password=' + $F('passlogin'),
			onSuccess: function(t) { /* check on success */ checkLogin(t); },
			onLoading: function() { /* Disable login button with message */$('login_button').value = 'Proses...'; $('login_button').disabled = true;}
			}
			//Send request
			new Ajax.Request('ajax.php', opt);
		}
function checkLogin(t){ 
			//t object is automatically passed
			if(t.responseText == "1")
			{
				//Show main screen				
				window.location = 'index.php';				
			}
			else
			{
				//Give a error message, reenable login button
				$('response').innerHTML = 'username atau password anda salah!';
				Element.show('response');
				$('login_button').value = 'Login'; 
				$('login_button').disabled = false;
			}
		}

		
function check_value(var_n, field_n)
		{
			var opt = {
				method:'post', 
				postBody:'m=check&type=' + var_n + '&value=' + $F(field_n),
				onSuccess: function (t) { update_check(t, field_n); },
				onLoading: function() {}
				}
				new Ajax.Request('ajax.php', opt);
		}
		
		function update_check(t, field_n)
		{
			if(t.responseText == "0")
			{
				//The name already exists, show message
				$(field_n  + '_check').innerHTML = '&nbsp;<img src="./icons/respo.gif"/> Sudah ada dan digunakan!';
				$(field_n).style.border = '1px red solid';
				$(field_n).focus();
			}
			else
			{
				//Good to go!
				$(field_n  + '_check').innerHTML = '';
				$(field_n).style.border = '1px green solid';
			}
		}	

function register(){
			//Basic error checking
			if($F('email') == '' || $F('name') == '' || $F('confirm_password') == '' || $F('password') == '' || $F('username') == '' || $F('code_string') == '')
			{
				alert("Please fill in all fields.");
				return;
			}
			else if($F('password') !== $F('confirm_password'))
			{
				alert("Please ensure your passwords match!");
				$F('confirm_password').focus();
			}												
			else
			{
				//Construct the AJAX object, add all form fields in the register_form to the paramaters
				var opt = {
				method:'post', 
				postBody:'m=register&' + Form.serialize('register_form'),
				onSuccess: function(t) { $('register_button').value = "register";  $('register_button').disabled = false; handle_register(t); },
				onLoading: function() { $('register_button').value = "Working..."; $('register_button').disabled = true; }
				}
				new Ajax.Request('ajax.php', opt);
			}
}
		
function handle_register(t){
			var data = t.responseText.split("|");
			//Give either the success or error message.  
			if(data[0] == "0")
			{
				$('register_message').innerHTML = data[1];
			}
			else
			{
				$('register_main').innerHTML = data[1];
			}
}

function poll(){
			
		var opt = {
		method:'post', 
		postBody:'m=polling&' + Form.serialize('poll_form'),
		onSuccess: function(t) { $('poll_button').value = "Pilih...";  $('poll_button').disabled = false; handle_poll(t); },
		onLoading: function() { $('poll_button').value = "Proses..."; $('poll_button').disabled = true; }
		}		
		new Ajax.Request('ajax.php', opt);		
		
}

function handle_poll(t){
			
		var data = t.responseText.split("|");
		//Give either the success or error message. 
		 
		if(data[0] == "0"){
			
			$('poll_message').innerHTML = data[1];
		}
		else{
			
			$('poll_message').innerHTML = data[1];
			
			window.location = 'index.php';	
		}
}

function posting(){

	if($F('email') == '' || $F('username') == ''){
		
		alert("Please login ... !.");
		return;
		
	}
	else if($F('title') == '' || $F('message') == ''){
		
		alert("Please fill in all fields!");
		$F('title').focus();
		
	}
	else {
	
	var opt = {
		method:'post', 
		postBody:'m=posting&' + Form.serialize('posting_form'),
		onSuccess: function(t) { $('posting_button').value = "Posting";  $('posting_button').disabled = false; handle_posting(t); },
		onLoading: function() { $('posting_button').value = "Proses..."; $('posting_button').disabled = true; }
	}
			
	new Ajax.Request('ajax.php', opt);	
	
	}
}

function handle_posting(t){
			
		var data = t.responseText.split("|");
		//Give either the success or error message. 
		 
		if(data[0] == "0"){
			
			$('posting_message').innerHTML = data[1];
		}
		else{
			
			$('posting_main').innerHTML = data[1];
			
			//window.location = 'index.php';	
		}
}

function posting2(){

	if($F('email') == '' || $F('username') == ''){
		
		alert("Please login ... !.");
		return;
		
	}
	else if($F('title') == '' || $F('message') == ''){
		
		alert("Please fill in all fields!");
		$F('title').focus();
		
	}
	else {
	
	var opt = {
		method:'post', 
		postBody:'m=posting2&' + Form.serialize('posting_form'),
		onSuccess: function(t) { $('posting_button').value = "Posting";  $('posting_button').disabled = false; handle_posting2(t); },
		onLoading: function() { $('posting_button').value = "Proses..."; $('posting_button').disabled = true; }
	}
			
	new Ajax.Request('ajax.php', opt);	
	
	}
}

function handle_posting2(t){
			
		var data = t.responseText.split("|");
		//Give either the success or error message. 
		 
		if(data[0] == "0"){
			
			$('posting_message').innerHTML = data[1];
		}
		else{
			
			$('posting_main').innerHTML = data[1];
			
			//window.location = 'index.php';	
		}
}

function guestbook(){
	
	if($F('email') == '' || $F('name') == '' || $F('comment') == '' || $F('code_string') == ''){
		alert("Silahkan semua field di isi.");
		return;
	}
	else{
		
	var opt = {
		method:'post', 
		postBody:'m=guestbook&' + Form.serialize('guestbook_form'),
		onSuccess: function(t) { $('guestbook_button').value = "Kirim";  $('guestbook_button').disabled = false; handle_guestbook(t); },
		onLoading: function() { $('guestbook_button').value = "Proses..."; $('guestbook_button').disabled = true; }
		}		
		new Ajax.Request('ajax.php', opt);
	}
}

function handle_guestbook(t){

		var data = t.responseText.split("|");
		//Give either the success or error message. 
		 
		if(data[0] == "0"){
			
			$('guestbook_message').innerHTML = data[1];
		}
		else{
			
			$('guestbook_main').innerHTML = data[1];
			
			//window.location = 'index.php';	
		}
}

function contact(){
	
	if($F('email') == '' || $F('name') == '' || $F('comment') == '' || $F('code_string') == ''){
		alert("Silahkan semua field di isi.");
		return;
	}
	else{
		
	var opt = {
		method:'post', 
		postBody:'m=contact&' + Form.serialize('contact_form'),
		onSuccess: function(t) { $('contact_button').value = "Kirim";  $('contact_button').disabled = false; handle_contact(t); },
		onLoading: function() { $('contact_button').value = "Proses..."; $('contact_button').disabled = true; }
		}		
		new Ajax.Request('ajax.php', opt);
	}
}

function handle_contact(t){

		var data = t.responseText.split("|");
		//Give either the success or error message. 
		 
		if(data[0] == "0"){
			
			$('contact_message').innerHTML = data[1];
		}
		else{
			
			$('contact_main').innerHTML = data[1];
			
			//window.location = 'index.php';	
		}
}

function iklan(){
	
	if($F('email') == ''){
		alert("Silahkan login dulu!.");
		return;
	}
	else if($F('title') == '' || $F('content') == '' || $F('profile') == ''){
		alert("Silahkan semua field di isi.");
		return;
	}
	else{
		
	var opt = {
		method:'post', 
		postBody:'m=iklan&' + Form.serialize('iklan_form'),
		onSuccess: function(t) { $('iklan_button').value = "Kirim";  $('iklan_button').disabled = false; handle_iklan(t); },
		onLoading: function() { $('iklan_button').value = "Proses..."; $('iklan_button').disabled = true; }
		}		
		new Ajax.Request('ajax.php', opt);
	}
}

function handle_iklan(t){

		var data = t.responseText.split("|");
		//Give either the success or error message. 
		 
		if(data[0] == "0"){
			
			$('iklan_message').innerHTML = data[1];
		}
		else{
			
			$('iklan_main').innerHTML = data[1];
			
			//window.location = 'index.php';	
		}
}

function message(){
	
	window.location = 'index.php?gate=message';	

}

function message_send(){
//	var s = Form.serialize('message_form');
//	alert(s);
	
	if($F('nama') == ''){
		alert("Masukan nama lengkap anda!.");
		return;
	}
	else if($F('message') == ''){
		alert("Masukan komentar anda!.");
		return;
	}
	else if($F('string_message') == ''){
		alert("Masukan kode Anti-Spam!.");
		return;
	}
	
	else{
		
	var opt = {
		method:'post', 
		postBody:'m=sms&' + Form.serialize('message_form'),
		onSuccess: function(t) { 
			var data = t.responseText.split("|");
			window.location = 'index.php?gate=home';	
		},
		onLoading: function() { }
		}		
		new Ajax.Request('ajax.php', opt);
	}	

}

function contact_send(){
//	var s = Form.serialize('message_form');
//	alert(s);
	
	if($F('nama') == ''){
		alert("Masukan nama lengkap anda!.");
		return;
	}
	else if($F('email') == ''){
		alert("Masukan email anda!.");
		return;
	}
	else if($F('message') == ''){
		alert("Masukan pertanyaan anda!.");
		return;
	}
	else if($F('string_contact') == ''){
		alert("Masukan kode Anti-Spam!.");
		return;
	}
	
	else{
		
	var opt = {
		method:'post', 
		postBody:'m=contact&' + Form.serialize('contact_form'),
		onSuccess: function(t) { 
			var data = t.responseText.split("|");
			window.location = 'index.php?gate=home';	
		},
		onLoading: function() { }
		}		
		new Ajax.Request('ajax.php', opt);
	}	

}

function search(){
//	var s = Form.serialize('message_form');
//	alert(s);
	
	if($F('searchText') == ''){
		alert("Masukan keyword pencarian anda !.");
		return;
	}
	else{
	
		window.location = 'index.php?gate=search&key='+$F('searchText');
		
	}	

}

function mail_login(){
//	var s = Form.serialize('message_form');
//	alert(s);
	
	if($F('user') == ''){
		alert("Masukan username anda !.");
		return;
	}
	else if($F('password') == ''){
		alert("Masukan password anda !.");
		return;
	}
	
	else{
		var q = '&u='+$F('user')+'&p='+$F('password'); 
		window.location = 'http://mail.perselafootball.com/';
		
	}	

}

function archive(){
	
	var s = Form.serialize('scalform');
	//alert(s);	
	window.location = 'index.php?gate=archive&task=result&'+s;	

}