// JavaScript Document

var tagScript = '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)';
/**
* Eval script fragment
* @return String
*/
String.prototype.evalScript = function()
{
	return (this.match(new RegExp(tagScript, 'img')) || []).evalScript();
};
/**
* strip script fragment
* @return String
*/
String.prototype.stripScript = function()
{
    return this.replace(new RegExp(tagScript, 'img'), '');
};
/**
* extract script fragment
* @return String
*/
String.prototype.extractScript = function()
{
    var matchAll = new RegExp(tagScript, 'img');
    return (this.match(matchAll) || []);
};
/**
* Eval scripts
* @return String
*/
Array.prototype.evalScript = function(extracted)
{
	var s=this.map(function(sr){
    	var sc=(sr.match(new RegExp(tagScript, 'im')) || ['', ''])[1];
        if(window.execScript){
			window.execScript(tagScript);
        }
        else
        {
			window.setTimeout(sc,0);
        }
	});
	
    return true;
 };
/**
* Map array elements
* @param {Function} fun
* @return Function
*/
Array.prototype.map = function(fun)
{
    if(typeof fun!=="function"){return false;}
     var i = 0, l = this.length;
     for(i=0;i<l;i++)
     {
		 fun(this[i]);
     }
	 
     return true;
};  
		
function createXMLcon()
{
	var obj;
	
	try {
		obj = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			obj = new ActiveXObject("Microsoft.XMLHTTP")
		} catch(e) { obj = null; }
	}
	
	if ( obj == null )
	{
		try {
			obj = new XMLHttpRequest();
		} catch (e) {}
	}
	
	if ( obj == null && window.createRequest )
	{
		try {
			obj = window.createRequest();
		} catch (e) {}
	}
	
	return obj; 
}

var xmlReq = null;

function AjaxCall( script, meth, vars )
{
	xmlReq = createXMLcon();
	xmlReq.open(meth, script + '?' + vars, true);
	xmlReq.setRequestHeader("Content-type", "aplication/x-www-form-urlencodes");
	xmlReq.setRequestHeader("X-AJAX-APP", "Cleopatra Asyncrous web plataform");
	xmlReq.setRequestHeader("Content-type", "text/xml; charset=iso-8859-1");
	xmlReq.send(null);
	xmlReq.onreadystatechange = function()
		{
			if(xmlReq.readyState == 1)
			{
				// loading
				document.getElementById("loading").style.visibility = "visible";
				
			} else if(xmlReq.readyState == 4)
			{
				// completed
				var response = xmlReq.responseText.extractScript();
				document.getElementById("mainContent").innerHTML = xmlReq.responseText.stripScript();
				response.evalScript();
				
				document.getElementById("loading").style.visibility = "hidden";
			}
		};
}


function tab( id )
{
	var url = "ajxSrv.php";
	var rnd = Math.round(9899);
	var vars = "pid=" + id + "&rnd=" + rnd ;
	
	get = AjaxCall(url,'GET', vars);
}