function trim(str)//trim string
{
   return str.replace(/^\s+|\s+$/g,'');
}


$(function(){

	//opening and closing up of search panel	
	/*$("div#searchtoggle").toggle(
	function(){
		$("div#searchpanel").hide("slow");
		//$("a#togglea").html("Search &darr;");
		
	},function(){
			$("div#searchpanel").show("slow");
			//$("a#togglea").html("Search");		
	});*/

	
	
	
	//opening and closing up of user panel	
	$("div#userpaneltoggle").toggle(
	function(){
		$("div#userpanel").hide("slow");
		//$("a#toggleb").html("Profile &darr;");
		
	},function(){
			$("div#userpanel").show("slow");
			//$("a#toggleb").html("Profile");		
	});

	
	})
	

	
	

function RegCheck(){//checking registration form
	
	//clearing up errors which were shown before
	$("div#arterr").html("");
	$("div#logerr").html("");
	$("div#pass1err").html("");
	$("div#pass2err").html("");
	$("div#emailerr").html("");
	
	
	//checking if artist name is there
	if (trim($("input#artist_name").val())=="")
	{
		$("div#arterr").html("artist name required");
		return false;
	}
	
	//checking if login is there
	if (trim($("input#login").val())=="")
	{
		$("div#logerr").html("login required");
		return false;
	}
	
	//if password is 6 or more symbols
	if($("input#pass1").val().length<6){
		$("div#pass1err").html("password should be at least 6 symbols, max 20");
		$("input#pass1").val("");
		$("input#pass2").val("");
		return false;
	}
	
	
	//if retyped password is the same
	if ($("input#pass1").val()!=$("input#pass2").val())
	{
		$("div#pass1err").html("password doesn't match!");
		$("div#pass2err").html("password doesn't match!");
		$("input#pass1").val("");
		$("input#pass2").val("");
		return false;
	}
	
		//checking if email is there
	/*if ($("input#email").val()=="")
	{
		$("div#emailerr").html("email required");
		return false;
	}*/
	
	
	var regex =/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	//var mailtest=;
	
	if(!(regex.test($("input#email").val()))) {
		$("div#emailerr").html("valid email required");	
		return false;
	}
	
}


function PassCheck(){//checking registration form
	
	//clearing up errors which were shown before
	$("div#pass1err").html("");
	$("div#pass2err").html("");
	
	
	//if password is 6 or more symbols
	if($("input#passnew").val().length<6){
		$("div#pass1err").html("password should be at least 6 symbols, max 20");
		$("input#passnew").val("");
		$("input#passnewrepeat").val("");
		return false;
	}
	
	
	//if retyped password is the same
	if ($("input#passnew").val()!=$("input#passnewrepeat").val())
	{
		$("div#pass1err").html("password doesn't match!");
		$("div#pass2err").html("password doesn't match!");
		$("input#passnew").val("");
		$("input#passnewrepeat").val("");
		return false;
	}
	
}