function submitForm(action) {
	$("#print").attr("value", 0);
	if(action != "" )
		$("#action").attr("value", action);
	
	var form = $("#adminform");
	form.attr('target', '_self');
	form.submit();
}

function orderClick(orderby, ordertype) {
	$("#orderby").attr("value", orderby);
	$("#ordertype").attr("value", ordertype);
	$("#action").attr("value", "list");
	
	$("#print").attr("value", 0);

	var form = $("#adminform");
	form.attr('target', '_self');
	form.submit();	
}

function checkForm(form) {
	var response = false;
	form = $("#" + form);
	$(".requiredField" , form ).each(function(){
		if(!jQuery.trim(this.value)) {
			alert('لطفا فیلدهای ستاره دار را وارد کنید');
			this.focus();
			response = false;
			return false;
		}else {
			response = true;
		}
	});
	if (!$(".requiredField", form ).length) {
		var response = true;
	}
	
	if(response) {
		if(typeof checkFormLocal == 'function') {
			response = checkFormLocal(form);
		}
		if(response) {
			return true;
		}
	}
	return response;
}

function setLoading(id, top) {
	if (typeof(top) == 'undefined') {
		top = "0px";
	}else {
		top = top + "px";
	}
	$("#"+id).html("<img style='padding-top:"+top+"' src='/images/admin/loading.gif' alt='در حال بارگذاری...' title='در حال بارگذاری...'>");
}

function checkAll(value, classname) {
	if (classname = 'undefined') {
		classname = 'checkAll';
	}
	$("."+classname).each(function(){
		this.checked = value;
	});
}

function popupWin(url, popW, popH) {
	popW = (popW == null) ? 400 : popW;
	popH = (popH == null) ? 400 : popH;

	var left = (screen.width/2)-(popW/2);
	var top = (screen.height/2)-(popH/2);

	window.open(url, "_blank", "scrollbars=yes,menubar=no,resizable=no,toolbar=no,top="+top+",left="+left+",width="+popW+",height="+popH);
}

function printForm() {
	$("#action").attr("value", 'list');
	$("#print").attr("value", 1);
	
	var form = $("#adminform");
	form.attr('target', '_blank');
	form.submit();
}

