$(function() {

	$('a.media').media();

	$('#getupload').click(function() {

   		$('#getsearch').removeClass('selectedSearch');
   		$(this).addClass('selectedUpload');

        $('#searchform').slideUp('slow');
     	$('#uploadform').slideDown('slow');
	});


  	$("#filegrid tr").mouseenter(function() {
    	$(this).css("background-color","#f3f7fd");
    	$(this).css("border","1px #bbd8fb solid");
  	}).mouseleave(function() {
    	$(this).css("background-color","white");
    	$(this).css("border","0px white solid");
	 });


	$('#getsearch').click(function() {

   		$('#getupload').removeClass('selectedUpload');
   		$(this).addClass('selectedSearch');

        $('#uploadform').slideUp('slow');
     	$('#searchform').slideDown('slow');
	});


	$('#cancelLogin').click(function() {
		$.unblockUI();
   		return false;
	});

	$('#cancelAdd').click(function() {
		$.unblockUI();
   		return false;
	});

	$('.cancelerror').click(function() {
		$.unblockUI();
   		return false;
	});

	$('#displayLogin').click(function()
	{

		$.blockUI({
			message: $('#loginForm') ,
			css: {
				border:'none', padding:'15px', size:'12.0pt',
				backgroundColor:'#e1dfdf', color:'#fff',
				'-webkit-border-radius': '5px','-moz-border-radius': '5px',
				width:'455px',height:'190px',
				cursor:'default'
				}
		});

	});

});

function getErrorMsg (errorID)
{
 	var errorID;

	$.blockUI({
		message: $('#' + errorID) ,
		css: {
				border:'none', padding:'15px', size:'12.0pt',
				backgroundColor:'#ffece6', color:'red',
				border:'1px #ff936f solid',
				'-webkit-border-radius': '5px','-moz-border-radius': '5px',
				width:'455px',
				cursor:'default'
			}
	});

}

function FileWaiting ()
{

	if(timer > 0)
	{
		$('#waiting').html("<h1 style='font-size:22px;'>" + timer +'</h1>');
		timer = timer - 1;
		setTimeout("FileWaiting()", 1000)
	}
	else
	{
		var urldata = $('#filecode').html();
		$('#waiting').html(urldata);

	}


}


function rateFile (type,id)
{
	var type;
	var id ;
	var nowrate;
	var newrate;

	nowrate = $('#ratevalue').html();
	nowrate = parseInt(nowrate);



	$.ajax({
		type: "POST",
		url: "view.php?action=ratefile",
		data: { type: type, id: id},
		success: function(theResponse)
		{
           if(type == 1)
           {
              newrate =  nowrate + 1;
              $('#ratevalue').html(newrate);
           }
           else
           {
           	 newrate =  nowrate - 1;
			 $('#ratevalue').html(newrate);
           }

		  	$("#ratevalue").fadeOut(100);
			$("#ratevalue").fadeIn(500);
		  	$("#ratevalue").fadeOut(100);
			$("#ratevalue").fadeIn(500);
		}
	});

}


function alertMsg (msg,color)
{
	var msg;
	var color;

	  $.blockUI({
	  message: msg ,
	  css: {
	       border: 'none',
	       padding: '15px',
	       backgroundColor: color,
	       '-webkit-border-radius': '10px',
	       '-moz-border-radius': '10px',
	       opacity: .8,
	       color: '#ffffff'
	 		}

	 });

	 setTimeout($.unblockUI, 2000);

}



function addcomment ()
{
	var commentname  = $("#commentname").val();
	var commentemail = $("#commentemail").val();
	var comment 	 = $("#comment").val();
	var fileid 		 = $("#fileid").val();
	var listcomments = $("#listcomments").html();

	if(commentname == '' || commentemail == '' || comment == '' )
	{
	      alertMsg('ببوره‌ هه‌موو خانه‌كان داواكراون','#C00114');
	}
	else
	{

		jQuery.ajax(
		{
			async :true,
			type :"POST",
			url :"addcomment.php?method=add&rand=" + Math.random(),
			data: "commentname=" + commentname + "&commentemail=" + commentemail + "&comment=" + comment + "&fileid=" + fileid,

			success : function(data)
			{

				var selectedIndex = 0;

				$('#waitingadd').slideToggle('slow');
				$('#addcommentarea').show('slow');

				if(data == 0)
				{
					alertMsg('ببوره‌ تۆ ناتوانیت سه‌رنج بنووسیت','#C00114');
				}
				else if(data == 1)
				{
					alertMsg('ببوره‌ هه‌موو خانه‌كان داواكراوه‌','#C00114');
				}
				else if(data == 2)
				{
					alertMsg('ببوره‌ پۆستی ئه‌لكترۆنی دروست نیه‌','#C00114');
				}
				else if(data == 3)
				{
					alertMsg('ببوره‌ سه‌ره‌نجه‌كه‌ت زۆر كورته‌','#C00114');
				}
				else
				{
                    $("#listcomments").html( listcomments + '<div class="comment"><div class="commentIcon" ></div><div class="usercomment"><div class="commentAuthor">' + commentname +'</div> '+ comment +' </div></div>');
					alertMsg('سه‌رنجه‌كه‌ت به‌سه‌ركه‌وتووی نێردرا','green');
					$('#addcommentarea').html('<div style="text-align:center;">سه‌رنجه‌كه‌ت به‌سه‌ركه‌وتووی نێردرا</div>');
				}


			},
			beforeSend : function(data)
			{
				$('#addcommentarea').slideToggle('slow');
				$('#waitingadd').show('slow');
			},
			error : function()
			{
					alertMsg('ببوره‌ هه‌ڵه‌یه‌ك هه‌یه‌','#C00114');
					$('#addcommentarea').slideToggle('slow');
					$('#waitingadd').hide('slow');
					return true;
			}

			});




	}



}

function addFolder ()
{
		$.blockUI({
			message: $('#addFolder') ,
			css: {
				border:'none', padding:'15px', size:'12.0pt',
				backgroundColor:'#e1dfdf', color:'#fff',
				'-webkit-border-radius': '5px','-moz-border-radius': '5px',
				width:'455px',height:'190px',
				cursor:'default'
				}
		});
}

function moveFile  (filecode)
{
		var filecode ;
		$('#filecode').val(filecode);

		$.blockUI({
			message: $('#MoveFile') ,
			css: {
				border:'none', padding:'15px', size:'12.0pt',
				backgroundColor:'#e1dfdf', color:'#fff',
				'-webkit-border-radius': '5px','-moz-border-radius': '5px',
				width:'455px',height:'190px',
				cursor:'default'
				}
		});
}


function submitFolder ()
{
	var foldername  = $("#foldername").val();
	var addprivate  = $("#addprivate").val();

    $.unblockUI();


	if(foldername == '')
	{
	      alertMsg('ببوره‌ هه‌موو خانه‌كان داواكراوه‌','#C00114');
	}
	else
	{

		jQuery.ajax(
		{
			async :true,
			type :"POST",
			url :"cp.php?do=addfolder&rand=" + Math.random(),
			data: "foldername=" + foldername + "&addprivate=" + addprivate ,

			success : function(data)
			{
				var selectedIndex = 0;
				if(data != 0)
				{
     				window.setTimeout('location.reload()', 1000);
				}
				else
				{
					alertMsg('ببوره‌ هه‌ڵه‌یه‌ك هه‌یه‌','#C00114');
				}
			},
			beforeSend : function(data)
			{
				alertMsg('تكایه‌ چاوه‌ڕوانبه‌ ..','green');
			},
			error : function()
			{
					alertMsg('ببوره‌ هه‌ڵه‌یه‌ك هه‌یه‌','#C00114');
					return true;
			}

			});




	}

}

function confirmation(confirmation_message)
{
	var ht = document.getElementsByTagName("html")[0];
	ht.style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
	if (confirm(confirmation_message))
	{
		return true;
	}
	else
	{
		ht.style.filter = "";
		return false;
	}
}

