function submitForm(action) {
	$("#print").attr("value", 0);
	$("#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").each(function(){
		if(!jQuery.trim(this.value)) {
			alert('لطفا فیلدهای ستاره دار را وارد کنید');
			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) {
			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, "_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 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 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 changeWebsite(site) {
	setCookie('DefaultWebsiteId', site, null, '/');
	document.location.reload();
}

