//-------------------------------------------------------------------------------------------------------------------------------------------------- Ajax
var isAjax=(window.XMLHttpRequest||window.ActiveXObject);

var ajReq=null;
var ajObj='';

function ajLoad(url,val)
{
	if(window.ActiveXObject)
	{
		try{ ajReq=new ActiveXObject('Msxml2.XMLHTTP'); }
		catch(a)
		{
			try{ ajReq=new ActiveXObject('Microsoft.XMLHTTP'); }
			catch(b){}
		}
	}

	if(!ajReq && typeof XMLHttpRequest!="undefined")
	{
		ajReq=new XMLHttpRequest;

		if(ajReq.overrideMimeType )
			ajReq.overrideMimeType('text/html');
	}

	if(ajReq)
	{
		ajReq.onreadystatechange=ajProcess;
		ajReq.open('POST',url,true);
		ajReq.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		ajReq.setRequestHeader('Content-length',val.length);
		ajReq.setRequestHeader('Connection','close');
		ajReq.send(val);
		return false;
	}

	return true;
}

function ajProcess()
{
	if(ajReq.readyState==4)
	{
		if(ajReq.status==200)
		{
			if(ajObj&&ajObj!='')
			{
				ajObj.innerHTML=ajReq.responseText;
				return;
			}
		}
	}

	//ajObj.innerHTML='loading...';
}

function ajRequest(url,id)
{
	ajRequestValue(url,id,'');
}

function ajEncode(text)
{
	return encodeURI(text);
}

function ajCheckbox(check)
{
	if(check)
	{
		if(check.value==0)
			return 0;
		else
			return (check.checked?1:0);
	}

	return 0;
}

function ajRequestModule(obj,type,url)
{
	if(isAjax)
	{
		obj.disabled=true;
		value='system='+type;

		if(type=='field')
		{
			value+='&login='+ajEncode(document.getElementById('plugin_login_login').value);
			value+='&password='+ajEncode(document.getElementById('plugin_login_password').value);
			value+='&memory='+ajCheckbox(document.getElementById('plugin_login_memory'));
		}

		value+='&submit=1';
		return ajRequestValue(url,'id_plugin_login',value);
	}
	else
		return true;
}

function ajLogin(obj,type,url)
{
	if(isAjax)
	{
		obj.disabled=true;
		var value='submit=1';

		if(type=='login')
		{
			value+='&login='+ajEncode(document.getElementById('plugin_login_login').value);
			value+='&password='+ajEncode(document.getElementById('plugin_login_password').value);
			value+='&memory='+ajCheckbox(document.getElementById('plugin_login_memory'));
		}

		return ajRequestValue(url,'id_plugin_login',value);
	}

	return true;
}

function ajRequestPlugin(obj,type,url)
{
	if(isAjax)
	{
		obj.disabled=true;
		value='system='+type;
		id='';

		switch(type)
		{
			case 'login_out': id='id_plugin_login'; break;
			case 'login_msg': id='id_plugin_login'; break;
			case 'login_in':
			{
				id='id_plugin_login';
				value+='&login='+ajEncode(document.getElementById('plugin_login_login').value);
				value+='&password='+ajEncode(document.getElementById('plugin_login_password').value);
				value+='&memory='+ajCheckbox(document.getElementById('plugin_login_memory'));
				break;
			}
			case 'calendar':
			{
				id='id_plugin_calendar';
				value+='&date='+document.getElementById('plugin_calendar_date').value;
				break;
			}
			case 'feedback_submit':
			{
				id='id_plugin_feedback';
				value+='&title='+ajEncode(document.getElementById('plugin_feedback_title').value);
				value+='&text='+ajEncode(document.getElementById('plugin_feedback_text').innerHTML);
				value+='&contact='+ajEncode(document.getElementById('plugin_feedback_contact').innerHTML);
				value+='&mail='+ajEncode(document.getElementById('plugin_feedback_mail').value);
				break;
			}
			case 'feedback_back': id='id_plugin_feedback'; break;
			default: break;
		}

		if(id!='')
		{
			value+='&submit=1';
			return ajRequestValue(url,id,value);
		}
	}

	return true;
}

function ajRequestValue(url,id,value)
{
	ajObj=document.getElementById(id);
	return ajLoad(url,value);
}