function submitbutton(action)
{
	document.getElementById('cmd').value = action;
	document.adminForm.submit();
	return false;
}

function redirect(url)
{
	window.location = url;
	return false;
}

function updateAction(url)
{
	if(!hasCheck())
	{
		alert("You shoud select one item to edit");
		return false;
	}
	var id = getFirstCheck();
	url += "?id="+id;
	window.location = url;
	return false;
}

function deleteAction()
{
	if(!hasCheck())
	{
		alert("You shoud select one item to delete");
		return false;
	}
	
	if(!confirm("Do you want to delete all selected items?"))
	{
		return false;
	}
	submitbutton('delete');
}

function showFiles(url)
{
	if(!hasCheck())
	{
		alert("You shoud select one user to show files");
		return false;
	}
	var id = getFirstCheck();
	url += "?id="+id;
	window.location = url;
	return false;
}

function showURL(url)
{	
	window.location = url;
	return false;
}

function saveAction()
{
	if($("#adminForm").valid())
	{
		submitbutton('save');
	}
}

function cancelAction(url)
{
	window.location = url;
	return false;
}

function uploadAction()
{
	if($("#php_file").val() == '')
	{
		alert('Please select file to upload');
	}
	else
	{
		submitbutton('upload');
	}
}

function getFirstCheck()
{
	return $(".chkBox:checked").eq(0).val();
}

function hasCheck()
{
	return ($(".chkBox:checked").size() > 0);
}

function checkAll()
{
	if($(".chkBox:checked").size() == $(".chkBox").size())
		$(".chkBox").attr("checked",false);
	else
		$(".chkBox").attr("checked",true);
}

function sort(orderBy,orderDirection)
{
	$("#params").val(orderBy+";"+orderDirection);
	submitbutton('sort');
}

function searchAction()
{
	submitbutton('search');
}

function changePage()
{
	submitbutton('search');
}

function publish(status,id)
{
	$("#params").val(status+";"+id);
	submitbutton('publish');
}

function enable(status,id,productType)
{
	$("#params").val(status+";"+id+";"+productType);
	submitbutton('enable');
}


function saveOrders()
{
	var params= "";
	for(var i=0; i< $(".chkBox").size(); i++)
	{		
		var idItem = $(".chkBox").eq(i).val();
		var orderItem = $(".order").eq(i).val();
		params += idItem + "," + orderItem + ";";
	}
	$("#params").val(params);
	submitbutton('saveOrders');
}

function changeOrder(id1, id2)
{
	if(id1 == id2)return false;
	$("#params").val(id1 + ";" +id2);
	submitbutton('saveorders');
}

function moveUp(count)
{
	var id = $("#item"+count).val();
	count --;
	var oid = $("#item"+count).val();
	if(oid == null)return;
	$("#params").val(id + ";" +oid);
	submitbutton('changeOrder');
}

function moveDown(count)
{
	var id = $("#item"+count).val();
	count ++;
	var oid = $("#item"+count).val();
	if(oid == null)return;
	$("#params").val(id + ";" +oid);
	submitbutton('changeOrder');
}

function changeCategory()
{
	submitbutton('changeCategory');
}

function ajaxPage(url)
{
	$('#message').show();
	$.get(url, function(data) {
		
		$('#message').hide();
		$('#body').html(data);
	});
}

function wait()
{
	setTimeOut(wait,1);
}


function expire(bool){

	if(bool){

		document.getElementById("txtexpiredate").disabled = "";

		document.getElementById("txtexpiremessage").disabled = "";

	}else{

		document.getElementById("txtexpiredate").disabled = "disabled";

		document.getElementById("txtexpiremessage").disabled = "disabled";

	}

}

function validhost(bool){

	if(bool){

		document.getElementById("txtvalidhosts").disabled = "";

		document.getElementById("txtvalidhostsmessage").disabled = "";

	}else{

		document.getElementById("txtvalidhosts").disabled = "disabled";

		document.getElementById("txtvalidhostsmessage").disabled = "disabled";

	}

}
