//==================================================
//---------------------------------------------
// date: 05/12/2009
//---------------------------------------------
// 	> Copyright (c) ZNTeam.ru
//	> Author: Kiryukhin Stanislav (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.php?cKfile=",
		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, data, callback)
	{
		var sendFile = file+"&"+data;
		return this.ajax({ method: "GET", file: sendFile, 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 ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
		
			
		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)
				s.callback(xmlHttp.responseText, xmlHttp.status);	
		}

		if(s.method == "POST")
		{
			xmlHttp.setRequestHeader("Content-Type", s.contentType);
			xmlHttp.send(s.data);
		}
		else
			xmlHttp.send(null);
	},
	
	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;
	}
}
