//==================================================
//---------------------------------------------
// date: 05/12/2009
//---------------------------------------------
// 	> Copyright (c) ZNTeam.ru
//	> Author: Кирюхин Станислав (KorsaR)
//	> WebSite: http://ZNTeam.ru/
//	> E-mail: info@ZNTeam.ru
//	> From: Russia(Moscow/Zhukovsky)
//----------------------------------------------
// All Rights Reserved.
//----------------------------------------------
//==================================================
var cKajax = function() { }

cKajax.prototype = {

	error: null,

	// Опции класса :)
	option:
	{
		url: "/loadAjax/",
		file: null,
		method: "GET",
		timeout: 10000,
		contentType: "application/x-www-form-urlencoded",
		async: true,
		data: null,
		username: null,
		password: null,
		callback: null
	},

	get: function(file, callback)
	{
		return this.ajax({ method: "GET", file: file, callback: callback });
	},

	post: function(file, data, callback)
	{
		return this.ajax({ method: "POST", file: file, data: data, callback: callback });
	},

	ajax: function(s)
	{
		s = this.getParam(s);

		var xmlHttp = (!window.ActiveXObject) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
			
		if(s.username != null)
			xmlHttp.open(s.method, s.url + s.file, s.async, s.username, s.password);
		else
			xmlHttp.open(s.method, s.url + s.file, s.async);

		xmlHttp.onreadystatechange = function() 
		{
			// Запрос выполнен.
			if(xmlHttp.readyState == 4)
			{
				if(s.callback != null)
					s.callback(xmlHttp.responseText);
			}
			
			return false;			
		}

		if(s.method == "POST")
		{
			xmlHttp.setRequestHeader("Content-Type", s.contentType);
			xmlHttp.send(s.data);
		}
		else
			xmlHttp.send(null);
			
		return true;
	},
	
	getParam: function(s)
	{
	
		this.option.method = (s.method == "GET" || s.method == "POST") ? s.method : this.option.method;
		this.option.callback = (s.callback != "undefined") ? s.callback : this.option.callback;
		this.option.data = (s.data != "undefined") ? s.data : this.option.data;
		this.option.file = s.file;
			
		return this.option;
	}
}
