// JAVASCRIPT SOURCE CODE

/** Creates the basic object that implements
*
* the Advanced JavaScripting And eXtensible Markup
* language web development and communications
* technique.
*
* @param 	Void
* @return 	Object Ajax XMLHttpRequest
* (False otherwise)
*/
function initAjax()
{
	// MAIN PROCESS
	var o = false;

	if (!o && (undefined != typeof XMLHttpRequest))
	{
		try {o = new XMLHttpRequest();}
		catch (e) {o = false;}
	}
	if (!o)
	{
		try {o = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e)
		{
			try {o = new ActiveXObject("Microsoft.XMLHTTP");}
			catch (E) {o = FALSE;}
		}
	}
	return o;
}



/** Performs a HTTP set & request using ajax.
*
* Used to make post/get requests to the specified
* uri. The ajax object may be modified by this
* function, thus the output of this function must
* be used for further AJAX activities.
*
* @param 	Object XMLHttpRequest
* @param 	String Request URI
* @param	String HTML Injection Object ID
* @param	String Request Method [Default: GET]
* @return	Object Modified XMLHttpRequest Object
* (False otherwise on Error)
*/
function ajax(uri, id, meth, asyn)
{

	/* SANITISATION */
	if (undefined == asyn)  asyn = true;
	if (undefined == uri)   return false;
	if (undefined == meth)  meth = 'GET';

	if( null != id)
	{
		o = document.getElementById(id).innerHTML;
		if(undefined == o) return false;
	}
	aj = initAjax();
	if (!aj){
		return false;
	}

	/* MAIN PROCESS */
	if (null != id)
	{
	   	aj.onreadystatechange = function()
	   	{
	   		if ((4 == aj.readyState) && (200 == aj.status))
				document.getElementById(id).innerHTML = aj.responseText;
	   		else if(undefined != aj.responseStatus)
	   			document.getElementById(id).innerHTML = aj.responseStatus;
			return true;
	   	};
   	}
	aj.open(meth, uri, asyn);
	aj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    aj.send(null);
    return aj;
}


/** For class.menu.php use only.
* Do not use this method for your personal code, it
* is handled by the menuset object.
*
*  @author 	Christian A.Kanakis / CYB
*  @param 	Object 	Callee
*  @param 	String 	Callee related uri
*  @return 	Boolean Operation Outcome
*/
function genmenu(o, uri, lang)
{
	/* SANITISATION */
	set = o.parentNode.id;
	
	// Setname of menu must be defined
	if (undefined == set) 
	{
		alert('set UNDEFINED Error');
		return false;
	}
	
	// Selected value must not be undefined
	nid  = o.value;
	if (undefined == nid) 
	{
		alert('ThanosCat Node UNDEFINED Error');
		return false;
	}
	
	/* Main Process */
	// Get internal matrix definition from
	// current menu set
	// Initialise Thanos Depth at 0, no Vectrii
	n   = 0;
	
	// Intialise Reference To Unique ThanosCat Menu Set
	id  = set + '_' + n;
	dat = '';
	tmp = o.name;
	callLevel = tmp.substr(tmp.lastIndexOf('_') + 1);
	tmp = null;
	
	while (null != (o = document.getElementById(id)))
	{
		val = o.value;
		
		// ACT :: Action Codes -
		// 0 : Normal Id
		// 1 : Select All
		// 2 : Choose
		act = (0 > val) ? 1 : 0;
		dat += n + ',' + val + ',' + act + ';';
		
		// Prepare new id for document to get (o)
		n++;
		id = set + '_' + n;
		if (n > callLevel) break;
	}
	
	app = set + '=' + dat;
	al = 'lang=' + lang;
	www = uri + '?' + app + '&' + al;
	fam = set + '_fam';
	document.getElementById(fam).value = dat;

	
	// Perform Menu Operation on PHP Menu Object
	aj = ajax(www, set, 'GET');
	if(undefined == aj) 
	{
		alert('AJAX error');
		return false;
	}
	return true;
}

// END OF JAVASCRIPT SOURCE CODE
