/*
//////////////////////////////////////////////////
///////////// PARSIZABANAN Institut //////////////
/////////////////// SARIR cms ////////////////////
////////////// www.parsizabanan.com //////////////
//////////////////////////////////////////////////
*/

var loc = 'http://www.iyqa.ir/action/';

$(document).ready(function()
{
	$("#status_area").hide();
	$("#status_area").click(function()				
	{
		$(this).fadeOut("fast");
	});

	panel();
	$(".bigblack").hide();
	
	setTimeout("aye_on()",1000);
	setTimeout("aye_off()",30000);
});

function wait()
{
	$(".status").html('لطفا صبر کنید...');
	$("#status_area").fadeIn("slow");
}
function status_area(msg)
{
	$("#status_area").show();
	$("#status_area").html(msg);
}
function aye_on()
{
	$("#aye").animate({right: '+=200'}, 4000);
}
function aye_off()
{
	$("#aye").animate({right: '-=213'}, 1000);
}
function swich(element)
{
	if( $("#"+element).is(":visible") )
		$("#"+element).fadeOut();
	else
		$("#"+element).fadeIn();
}
function swich2(element)
{
	$("#"+element).slideToggle("slow");
}
function combo()
{
	$("#ayecombo").html('ان الله مع الصابرین...');
	$.post(loc+'combo.php', {sure:$("#sure").val()}, function(i) {
	  $('#ayecombo').html(i);
	});

}
function SelectAll(element)
{
	$("#"+element).focus();
	$("#"+element).select();
}
function sendform(formid,task,cat)
{
	$(".bigblack").show();
	data = '';
	$("#"+formid+" input, #"+formid+" textarea, #"+formid+" select").each(function(){
		if( $(this).attr("name") != '' )
			data += $(this).attr("name") + '=' + $(this).val() + "&";
	});
	$.ajax({
	type: "POST",
	url: loc+cat+".php?"+task,
	data: data,
		success: function(i){
			$(".bigblack").fadeOut("fast");
			status_area(i);
		}
	});
}
function user(aid)
{
	$(".black").show();
	
	data = '';
	$("#form_login input:text, #form_login input:password").each(function(){
		if( $(this).attr("name") != '' )
			data += $(this).attr("name") + '=' + $(this).val() + "&";
	});

	$.ajax({
	type: "POST",
	url: loc+"user.php?aid="+aid,
	data: data,
		success: function(i){
			panel();
			status_area(i);
		}
	});
}

function panel(){
	$(".black").show();
	$.get(loc+'user.php', {aid:'panel'}, function(i){
		$(".black").fadeOut("fast");
		$("#user_panel").html(i);
	});
}

function mail(cat,to){
	$.post(loc+'user.php', {aid:cat,id:to}, function(i){
	  $("#message_area").html(i);
	  $(".black").fadeOut('fast');
	});
}
function showmail(id,up){
	$.post(loc+'user.php', {aid:'showmail',id:id,up:up}, function(i){
	  $("#mail_area").html(i);
	  $(".black").fadeOut('fast');
	});
}
function deleteone(id)
{
	if (confirm('آیا میخواهید حذف کنید؟'))
	{
		$.post(loc+'user.php',{aid:'delete',id:id},function(i){
			$("#del_"+id).fadeOut("slow");
		});
	}
}


// BEGIN UPLOAD //

BYMIR = {
//  AJAX IFRAME METHOD (AIM)  http://www.webtoolkit.info
	frame : function(c) {

		var n = 'f' + Math.floor(Math.random() * 99999);
		var d = document.createElement('DIV');
		d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="BYMIR.loaded(\''+n+'\')"></iframe>';
		document.body.appendChild(d);

		var i = document.getElementById(n);
		if (c && typeof(c.onComplete) == 'function') {
			i.onComplete = c.onComplete;
		}

		return n;
	},

	form : function(f, name) {
		f.setAttribute('target', name);
	},

	submit : function(f, c) {
		BYMIR.form(f, BYMIR.frame(c));
		if (c && typeof(c.onStart) == 'function') {
			return c.onStart();
		} else {
			return true;
		}
	},

	loaded : function(id) {
		var i = document.getElementById(id);
		if (i.contentDocument) {
			var d = i.contentDocument;
		} else if (i.contentWindow) {
			var d = i.contentWindow.document;
		} else {
			var d = window.frames[id].document;
		}
		if (d.location.href == "about:blank") {
			return;
		}

		if (typeof(i.onComplete) == 'function') {
			i.onComplete(d.body.innerHTML);
		}
	}

}

function upload_start()
{
	$('#uploadstatus').text('در حال آپلود فایل...');
	return true;
}

function upload_end(response)
{
	if (response == 'rename')
		$('#uploadstatus').text('نام فایل تکراری است!');
	else if (response == 'type')
		$('#uploadstatus').text('این نوع فایل مجاز نیست!');
	else if (response == 'error')
		$('#uploadstatus').text('فایل آپلود نشد!');
	else
		$('#uploadstatus').text('فایل با موفقیت آپلود شد.');
}

function upload(formid)
{
	$('#'+formid).attr('onsubmit','return BYMIR.submit(this, {\'onStart\' : upload_start, \'onComplete\' : upload_end})');
	$('#'+formid).submit();
}

// ENDOF UPLOAD //
