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

function orderClick(orderby, ordertype, action) {
	$("#orderby").attr("value", orderby);
	$("#ordertype").attr("value", ordertype);
	
	if (action == undefined) {
		action = 'list';
	}
	
	$("#action").attr("value", action);
	
	$("#print").attr("value", 0);

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

function checkForm(form, nosubmit) {
	var response = false;
	$("#" + form + " .requiredField").each(function(){
		if((this.type == 'checkbox' && !this.checked) || !jQuery.trim(this.value)) {
			alert(this.lang ? this.lang : 'لطفا اطلاعات خود را بصورت کامل وارد نمایید');
			this.focus();
			response = false;
			return false;
		}else {
			response = true;
		}
	});
	
	if (!$(".requiredField").length) {
		var response = true;
	}
	
	if(response) {
		if(typeof checkFormLocal == 'function') {
			response = checkFormLocal(form);
		}
		if(response) {
			if (nosubmit) {
				return response;
			}
			form = $("#" + form);
			form.submit()
		}
	}	
}

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 = 'listChk';
	}
	$("."+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 + '?popup=1', "_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();
}

function cancleBubble(event) {
	if (jQuery.browser.msie) {
        event.cancelBubble = true;
    } else {
        event.stopPropagation();
    }
}

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;
    }
}

function setCookie(cName, cValue)
{
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = cName + "=" + escape (cValue) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");	
}

function changeLocation(location) {
	setCookie('DefaultLocation', location, null, '/');
	document.location.reload();
}

function duplicateEl(el, appendto) {
	elements = $('#'+el).clone();
	elements.find('input:text').each(function(){
											  this.value = '';
											  });
	elements.find('input[type=hidden]').remove();
	elements.appendTo($('#'+appendto));
}

function removeEl(el) {
	$(el).parent().parent().remove();
}

function delImg(url) {
	$('#thumbImg').remove();

	$.ajax({
		   type: "GET",
		   url: url,
		   data: 'isajax=1'
	});
}

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


