var objXMLReq = null;
var console   = null;
/*******************************************************/
/*******************************************************/
function ungrounded(htmlText)
{
	
}
function putHTML(htmlText)
{
	if (console != null){
		console.innerHTML = htmlText;
		console.style.display = 'block';
	}
	document.body.style.cursor = 'default';
	//objXMLReq = null;
}
/*******************************************************/
/*******************************************************/
/*******************************************************/
function ajaxGo(my, httpURL, idName, className)
{
	//alert('ops!');
	//alert(httpURL);
	//window.document.write(httpURL);
	//return;
	//write(httpURL);
	//write(httpURL);
	if (console  = document.getElementById(idName)) {
		console.style.display = 'none';
		console.className = className;
		document.body.style.cursor = 'wait';
		var i=1;
		var he = null;
		while(he = document.getElementById('bookmarks_' + i)) {
			he.className = '';
			i++;
		}
		my.className = 'active';
		
		//if(objXMLReq == null) {
			objXMLReq = new net.ContentLoader(httpURL, putHTML, null, 'GET', null);
		//} else {
		//	objXMLReq.loadXMLDoc(httpURL);
		//}
	} else {
		document.body.style.cursor = 'wait';
		var i=1;
		var he = null;
		while(he = document.getElementById('bookmarks_' + i)) {
			he.className = '';
			i++;
		}
		my.className = 'active';
		document.body.style.cursor = 'default';
	}
}

// Инициализируем таблицу перевода
var trans = [];
for (var i = 0x410; i <= 0x44F; i++)
  trans[i] = i - 0x350; // А-Яа-я
trans[0x401] = 0xA8;    // Ё
trans[0x451] = 0xB8;    // ё

// Сохраняем стандартную функцию escape()
var escapeOrig = window.escape;

// Переопределяем функцию escape()
window.escape = function(str)
{
  var ret = [];
  // Составляем массив кодов символов, попутно переводим кириллицу
  for (var i = 0; i < str.length; i++)
  {
    var n = str.charCodeAt(i);
    if (typeof trans[n] != 'undefined')
      n = trans[n];
    if (n <= 0xFF)
      ret.push(n);
  }
  return escapeOrig(String.fromCharCode.apply(null, ret));
}

function ajaxGoForm(my, httpURL, idName)
{
	//alert(my.item.value);
	//return;
	var myRegExp = /&/;
	var item    = 'item=' + escape(my.item.value);
	//var user    = 'user=' + escape(my.user.value.replace(myRegExp, "%26"));
	var user    = 'user=' + escape(my.user.value);
	var email   = 'email=' + escape(my.email.value);
	//var comment = 'comment=' + escape(my.comment.value.replace(myRegExp, "%26"));
	var comment = 'comment=' + escape(my.comment.value);
	var rating  = 'rating=' + escape(my.rating.value);
	var spam    = 'spam=' + escape(my.spam.value);
	var str     = item + '&' +  user + '&' + email + '&' + comment + '&' + rating + '&' + spam;

	txt = new String(my.user.value);
	//alert(str);
	if (console  = document.getElementById(idName)) {
		console.style.display = 'none';
		document.body.style.cursor = 'wait';		

		objXMLReq = new net.ContentLoader(httpURL, putHTML, null, 'POST', str);

		document.body.style.cursor = 'wait';
	}
	document.body.style.cursor = 'default';
	
	/*
	if (console  = document.getElementById(idName)) {
		console.style.display = 'none';
		document.body.style.cursor = 'wait';	
		
	JsHttpRequest.query(
            httpURL, // backend
            {
                'item': my.item.value,  
                'user': my.user.value,
                'email': my.email.value,
                'comment': my.comment.value,
                'rating': my.rating.value,
                'spam': my.spam.value
            }
            
             ,
            // Function is called when an answer arrives. 
            function(result, errors) {
                // Write errors to the debug div.
                //document.getElementById("debug").innerHTML = errors; 
                // Write the answer.
                alert(result);
                if (console != null){
									console.innerHTML = result;
									console.style.display = 'block';
								}
								document.body.style.cursor = 'default';
            },
            false  // do not disable caching
        );
	}
	document.body.style.cursor = 'default';	*/
}

function ajaxGoImage(httpURL)
{
	objXMLReq = new net.ContentLoader(httpURL, ungrounded, null, 'GET', null);
}

/*******************************************************/
//encoding: 'UTF-8' //windows-1251
//Ajax.Base.setOptions(encoding: 'windows-1251');
/*
	new Ajax.Request(httpURL, {
		method: 'get', //encoding: 'windows-1251',
	  onSuccess: function(transport) {
	  	console.innerHTML = transport.responseText;
	  	console.style.display = 'block';
	   //alert(transport.responseText);
	  }
	});	*/
/*******************************************************/