﻿function callPage(page)
{
	var Ajax = new AjaxEngine();
	Ajax.method = 'POST';
	Ajax.target = 'siteMain';
	Ajax.loader = 'siteLoader';
	Ajax.url = SiteVPath+'action.php?action=call_page&page='+page;
	Ajax.responseType = 'txt';
	Ajax.Request();
}

function inArray(value, array)
{
	var i;
	for (i=0; i < array.length; i++) 
	{
		if (array[i] == value) 
		{
			return true;
		}
	}
	return false;
}

function goAction(actionName)
{
	document.forms[0].action=SiteVPath+'action.php?action='+actionName;
	document.forms[0].submit();
}

function goActionID(actionName, ID)
{
	document.forms[0].action=SiteVPath+'action.php?action='+actionName+'&id='+ID;
	document.forms[0].submit();
}

function goPage(menu, page, url)
{
	if(url != '')
	{
		window.location.href='admin.php?menu='+menu+'&page='+page+'&'+url;
	}
	else
	{
		window.location.href='admin.php?menu='+menu+'&page='+page;
	}
}

//GRID ДЭЭРЭЭС ЭЛЕМЕНТҮҮДИЙН УТГУУДЫГ STRING БОЛГОН БУЦААХ
function getIDS(element)
{
	var id = new Array();
	var idString;
	
	if(element.length != null)
	{
		for(i=0; i<=(element.length-1); i++)
		{
			if(element[i].checked)
			{
				id.push(element[i].value);
			}
		}
	}
	else
	{
		if(element.checked)
		{
			id.push(element.value);
		}		
	}
	
	idString = id.join(",");
	return idString;	
}

function editItem(menu, page, url)
{
	id = getIDS(document.forms[0].elements['gridCheckRow']);
	if(id!=0 && id!="")
	{
		if(url != '')
		{
			window.location.href='admin.php?menu='+menu+'&page='+page+'&id='+id+'&'+url;
		}
		else
		{
			window.location.href='admin.php?menu='+menu+'&page='+page+'&id='+id;
		}
	}
	else
	{
		alert("Please, choose one item!");
	}
}

function deleteItem(actionName)
{
	id = getIDS(document.forms[0].elements['gridCheckRow']);	
	if(id!=0 && id!="")
	{
		if(confirm("Are you sure want to delete?"))	
		{
			document.forms[0].action=SiteVPath+'action.php?action='+actionName+'&id='+id;
			document.forms[0].submit();
		}
	}
	else
	{
		alert("Please, choose one item!");
	}
}
