function checkEmail(inputvalue){	
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if(pattern.test(inputvalue)){         
		return true;   
    }else{   
		return false; 
    }
}

$(document).ready(function() {

	$('#slideshow').before('<ul id="nav-slide">').cycle({
		fx: 'fade',
		speed: 600,
		timeout: 7000,
		pager: '#nav-slide',
		pagerAnchorBuilder: function(idx, slide) {
			return '<li><a href="#">' + slide.title + '</a></li>';
		}
	});
	
var loader=$('#loader');
	var pollcontainer=$('#pollcontainer');
	loader.fadeIn();
	//Load the poll form
	$.get('poll.php', '', function(data, status){
		pollcontainer.html(data);
		animateResults(pollcontainer);
		pollcontainer.find('#viewresult').click(function(){
			//if user wants to see result
			loader.fadeIn();
			$.get('poll.php', 'result=1', function(data,status){
				pollcontainer.fadeOut(1000, function(){
					$(this).html(data);
					animateResults(this);
				});
				loader.fadeOut();
			});
			//prevent default behavior
			return false;
		}).end()
		.find('#pollform').submit(function(){
			var selected_val=$(this).find('input[name=poll]:checked').val();
			if(selected_val!=''){
				//post data only if a value is selected
				loader.fadeIn();
				$.post('poll.php', $(this).serialize(), function(data, status){
					$('#formcontainer').fadeOut(100, function(){
						$(this).html(data);
						animateResults(this);
						loader.fadeOut();
					});
				});
			}
			//prevent form default behavior
			return false;
		});
		loader.fadeOut();
	});
	
	function animateResults(data){
		$(data).find('.bar').hide().end().fadeIn('slow', function(){
							$(this).find('.bar').each(function(){
								var bar_width=$(this).css('width');
								$(this).css('width', '0').animate({ width: bar_width }, 1000);
							});
						});
	}

	$("div.ttl", $("div.small")).toggle(function(){
		$(this).next(".Wr").slideUp();
	}, function(){
		$(this).next(".Wr").slideDown();
	});
	
	$("div.ttl", $("div#small")).toggle(function(){
		$(this).next(".Wr").slideUp();
	}, function(){
		$(this).next(".Wr").slideDown();
	});
	//-------------------[registerformValidation]--------------------------------
	$("#user_login, #user_login1").change(function(){
		if($(this).val().length < 6){
			alert("طول نام كاربري بايد حداقل 6 كاراكتر باشد");
			$(this).val("");
			$(this).focus();
		}
	});

	$("#user_name").change(function(){
		if($(this).val().length < 3){
			alert("نام كاربر بايد به شكل صحيح وارد شود");
			$(this).val("");
			$(this).focus();
		}
	});
	
	$("#user_pass, #user_pass1").change(function(){
		if($(this).val().length < 6){
			alert("طول پسورد بايد حداقل 6 كاراكتر باشد");
			$(this).val("");
			$(this).focus();
		}
	});
	
	$("#user_mail").change(function(){
		if(!checkEmail($(this).val())){
			alert("شما بايد از يك آدرس ايميل معتبر استفاده كنيد");
			$(this).val("");
			$(this).focus();
		}
	});
	
	$("#user_address").change(function(){
		if($(this).val().length < 15){
			alert("آدرس خود را كامل تر وارد كنيد");
			$(this).val("");
			$(this).focus();
		}
	});

	$("#user_tel").change(function(){
		if($(this).val().length < 8){
			alert("لطفا تلفن خود را كامل و بهمراه كد وارد كنيد");
			$(this).val("");
			$(this).focus();
		}
	});

	$("#user_repass").change(function(){
		if($(this).val().length < 6){
			alert("طول پسورد بايد حداقل 6 كاراكتر باشد");
			$(this).val("");
			$(this).focus();
		}/*else{
			if( $(this).val() !== $("#user_pass").val()){
				alert("رمز عبور و تكرارش مطابقت ندارند");
				$(this).val("");
				$(this).focus();
			}
		}*/
	});
	
	$("#accept").click(function(){
		$(".reg1").slideUp();
		$(".reg2").slideDown();
	});
	
	
	//slides the element with class "menu_body" when mouse is over the paragraph
	$("#firstpane p.menu_head").mouseover(function()
	{
	   $(this).css({backgroundImage:"url(images/down.png)"}).next("div.menu_body").slideDown(500).siblings("div.menu_body").slideUp("slow");
	   $(this).siblings().not(".menu_body").css({backgroundImage:"url(images/left.png)"});
	});
	
	// RSS rotators
	//$jScroller.add(".scroller_container",".scroller","up",1);
	//$jScroller.start();
	
	
});
