function createAjax()
{
	var xt;
	xt = window.XMLHttpRequest ? new XMLHttpRequest() : ( window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP') : null)

	return xt;
}

function trim(str, chars) {

    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
	
function strip_tags(str)
{
	var re= /<\S[^><]*>/g
	str = str.replace(re, "")
	return str;
}	


function busy(mode)
{

	var bus = document.getElementById('processing')
	if(bus)
		if(mode)
			bus.style.visibility='visible'
		else
			bus.style.visibility='hidden'
}

function busyx(mode,id)
{

	if(!busyx.prev)prev=null
	if(id) busyx.current = id
	
	if(prev)document.getElementById(prev).style.visibility = 'hidden'

	var bus = document.getElementById(busyx.current)

	if(bus)
		if(mode)
			bus.style.visibility='visible'
		else
			bus.style.visibility='hidden'			
}


function jsalert(str)
{
	alert(str)
	if(jsalert.arguments.length>1)
	{
		if(document.getElementsByName(jsalert.arguments[1])[0])
			document.getElementsByName(jsalert.arguments[1])[0].focus()
	}
	throw new Error('Stopa');
}

function getjsText(nami)
{
	var os = document.getElementsByName(nami)[0];
	if(os)
	{
		if(os.type!='file')
		if(window.trim)os.value = trim(os.value)
		return os.value
	}
	return null
}

function isbien(str)
{
	if(typeof(str)=='object')
	str = str.responseText
	
	str = str.replace(/[\x00-\x1f]/,'')
	if( (str.indexOf('bien')+1) || (str.indexOf('DONiZ')+1) ) return true;
	return false;
}


function makeParam(param)
{
	var str = param.split(',')
	var val='';
	val += str[0] + '=' + str[1];

	for(var i=2;i<str.length;i+=2)
	{
		if(document.getElementById(str[i+1]))
			val += "&" + str[i] + '=' + encodeURIComponent((document.getElementById(str[i+1]).value))
		else { alert(str[i]+' does not exists'); stopit(); }
	}
	return val;	
}

function jpreset(param)
{
	var jax = createAjax();
	var path = arguments.length>1 ?arguments[1]:baseurl+'admin/ajax/';
	jax.open("POST",path,true)
	jax.setRequestHeader('Content-Type','application/x-www-form-urlencoded')
	jax.send(param)
	return jax;
}

function whereIsMouse(e) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	
	return {'x': posx, 'y':posy};
	// posx and posy contain the mouse position relative to the document
	// Do something with this information
}

function totheleft(e,mode)
{
	if(mode)
	{
		var posi = whereIsMouse(e)
//		$('#processinggif').css('display','block')
		$('#processinggif').css('left',posi.x + 20)
		$('#processinggif').css('top',posi.y)
		$('#processinggif').fadeIn(400)
	}
	else
	{
		$('#processinggif').hide();
	}
}
