function user_login(){
		$("#login").attr({disabled: 'disabled'});
		var login = $("#login_f").val();
		var pass = $("#pass_f").val();
		$.ajax({
		   type: "GET",
		   url: "login_functions.php",
		   data: "action=login&login="+login+"&pass="+pass,
		   success: function(msg){
			 if(msg=="success"){
			 	redirect("index.php");
			 }
			 else{
			 	$(".loginMessage").html(msg);
			 	$("#login").attr({disabled: ''});
			 }
		   }
		 });
	}
	function redirect(url){
		window.location.href = url;
	}

function user_register(){
		var password = $("#r_password input").val(); 
		var cpassword = $("#r_cpassword input").val(); 
		var email = $("#r_email input").val(); 
		var name = $("#r_name input").val(); 
		var gender = $("#gender").val();
		var dob = $("#day").val()+"/"+$("#month").val()+"/"+$("#year").val();
		var postcode = $("#r_postcode input").val();

		if(password!=cpassword){
			$(".reg_loading_error").html("The entered passwords do not match");
			return false;
		}
		else if(password=="" || cpassword=="" || name=="" || postcode==""){
			$(".reg_loading_error").html("Please fill in all required fields");
			show_icons("r_password");
			show_icons("r_cpassword");
			show_icons("r_email");
			show_icons("r_name");
			show_icons("r_postcode");
			return false;	
		}
		else if(validateEmail(email)==false){         
			 $(".reg_loading_error").html("E-mail is incorrect");
			 return false; 
		}
		else{
			$("#reg_loading").html('<img src="images/login_check_preloader.gif" />');
			$.ajax({
			   type: "POST",
			   url: "login_functions.php",
			   data: "action=register&password="+password+"&email="+email+"&name="+name+"&gender="+gender+"&dob="+dob+"&postcode="+postcode,
			   success: function(msg){
			   	if(msg=="success"){
				 	$("#register_form").remove();
					$(".main_body").append('<div class="reg_complete"><br />Thank you for the registration and welcome to the Voxpopuk.com website!<br />You can now login using your e-mail and password.</div>');
				}
				else{
					$(".reg_loading_error").html(msg);
					$("#reg_loading").html('<input type="image" src="images/reg_but.jpg" id="reg_button_big" />');
				}
			   }
			 });
		}
	}
	function validateEmail(elementValue){
		var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; 
		return emailPattern.test(elementValue); 
	}
	function show_icons(el){
		if($("#"+el+" input").val()==""){
			$("#"+el+" .reg_checker").html('<img src="images/iconz/cross.jpg" />');
		}
		else{
			$("#"+el+" .reg_checker").html('<img src="images/iconz/tick.jpg" />');
		}
	}
	
	function login_change(field, str){
		var new_s = $("#"+field).val();
		if(new_s==str){
			$("#"+field).val("");
		}
	}
	function login_back_change(field, str){
		var new_s = $("#"+field).val();
		if(new_s==""){
			$("#"+field).val(str);
		}
	}
	function sendForm(){
	var fields= new Array(4) 
	fields[0] =$("#name").val();
	fields[1] = $("#e-mail").val();
	fields[2] = $("#subject").val();
	fields[3] = $("#message").val();
	
	var not_ok = new Array('name', 'e-mail', 'subject', 'message');
	
	//for e-mail check
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	for (var i=0; i<fields.length; i++){
		if(fields[i]==not_ok[i]){
			 $("#error_s").html("Please enter \""+not_ok[i]+"\"!");
			return false;
		}
		if(i==1){
			if (!filter.test(fields[i])) {
				$("#error_s").html("\"E-mail\" is not valid!");
				return false;
			}
		}
	}
	$("#error_s").html("");
	var query = "name="+fields[0]+"&email="+fields[1]+"&subject="+fields[2]+"&message="+fields[3];
	$("#send_form").html("");
	$("#error_s").html("Sending...");
	$.ajax({
	   type: "POST",
	   url: "send.php",
	   data: query,
	   success: function(msg){	
	   		if(msg=="<b>Thank You! Message has been sent.</b>"){ 
				
				
				
				$("#error_s").html(msg);
			}
			else{
				$("#error_s").html(msg);
				//$("#send_form").html("SEND");
			}
			
	   }
	 });
}
function checkemail(){
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test($("#new_email").val())) {
		$("#em_error").html(" E-mail is invalid!");
		return false;
	}
	return true;
}

function makeemails() {
	var contentHolder  = document.getElementById("mainbox");
	var myString = contentHolder.innerHTML.toString();
	myString = myString.replace(/ {at} /g, '@');
	myString = myString.replace(/\s([A-Za-z0-9\.-]*?@voxpopuk\.com)/g,' <a href="mailto:$1">$1</a>');
	contentHolder.innerHTML = myString;	
}


function init() {
	makeemails();	
}

function formvalidation()
{
	/*if (value of first field is or isn't something)
	{
		// something is wrong
		alert('There is a problem with the first field');
		return false;
	}
	else if (value of next field is or isn't something)
	{
		// something else is wrong
		alert('There is a problem with...');
		return false;
	}
	// If the script gets this far through all of your fields
	// without problems, it's ok and you can submit the form*/
	alert ('hui vam');
	return false;
}



