/**
	* Display menu in frontend
	* @param {String} menu
	* @param {String} parent_id
*/
function ShowMenuItem(menu, parent_id)
{
	for (var i = 0; i <= 100; i++)
	{
		if (document.getElementById(menu + '_' + i))
		{
			document.getElementById(menu + '_' + i).style.display = 'none';
		}
	}

	if (document.getElementById(menu + '_' + parent_id))
	{
		document.getElementById(menu + '_' + parent_id).style.display = 'block';
	}
}

/**
	* Show/Hide div ID
	* @param {String} id
*/
function ShowHideDiv (id)
{
	var current_status = document.getElementById(id).style.display;
	if (current_status == 'none')
	{
		document.getElementById(id).style.display = '';
	}
	else 
	{
		document.getElementById(id).style.display = 'none';
	}
}

/**
	* Post a form using javascript, the page will redirect
	* @param {String} id
	* @param {Array} values
*/
function postForm (postUrl, values)
{
	var myForm = document.createElement("form");
	myForm.method = "post";
	myForm.action = postUrl;
	for (var postValue in values)
	{
		var myInput = document.createElement("input");
		myInput.setAttribute("name", postValue);
		myInput.setAttribute("value", values[postValue]);
		myForm.appendChild(myInput);
	}
	document.body.appendChild(myForm);
	myForm.submit() ;
	document.body.removeChild(myForm);
}

/**
	* Create a custom xhttp request 
*/
function getXhttp ()
{
	var ajax_request;

	if (window.ActiveXObject)
	{
		var mSoftVersions = ['MSXML2.DOMDocument.5.0', 'MSXML2.DOMDocument.4.0', 'MSXML2.DOMDocument.3.0', 'MSXML2.DOMDocument.2.0', 'MSXML2.DOMDocument',
									'Microsoft.XmlDom', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'];
		for (i = 0; i < mSoftVersions.length; i++)
		{
			try {
					ajax_request = new ActiveXObject (mSoftVersions[i]);
			}
			catch (e)
			{
			}
		}
	}
	else if (!ajax_request && typeof XMLHttpRequest != 'undefined')
	{
		try {
				ajax_request = new XMLHttpRequest;
		}
		catch (e)
		{
		}
	}
	else if (!ajax_request && window.createRequest)
	{
		try {
				ajax_request = window.createRequest;
		}
		catch (e)
		{
		}
	}
	else
	{
		ajax_request = false;
	}
	return ajax_request;
}

/**
	* Post a form using javascript without leavingthe page
	* @param {String} id
	* @param {Array} values
*/
function ajaxPostForm(postUrl, values)
{
	var xml = getXhttp();
	if (!xml)
	{
		return false;
	}

	xml.open('POST', postUrl);
	xml.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xml.send(values);
}
