  var _ids = Array();
//==================================================

function refresh_page() {

    setTimeout("window.location.reload()",500000);

}             


function switchD() {

  var temp = document.getElementById("direction1").value.substr(0,2);
  document.getElementById("direction1").value = document.getElementById("direction2").value+"_";
  document.getElementById("direction2").value = temp;
  table();
  document.getElementById("inp_word").focus();
}


function isKeyPressed(event) {

	if (event.keyCode==13)
	{
		if (ValidateWord())
		showResult(document.getElementById("direction1").value, document.getElementById("direction2").value, document.getElementById("direction").value, 1, document.getElementById("inp_word").value, document.getElementById("use_dia").checked, "");
	}
}



function isOkPressed(event, callback) {

	if (ValidateWord())
    showResult(document.getElementById("direction1").value, document.getElementById("direction2").value, document.getElementById("direction").value, 1, document.getElementById("inp_word").value, document.getElementById("use_dia").checked, '0', callback);
}



function found() {

	if (xmlHttp_1.readyState==4 || xmlHttp_1.readyState=="complete")
    {
		document.getElementById("statistics").innerHTML=xmlHttp_1.responseText;
    }

}


function stateChanged_add() {

	if (xmlHttp_add.readyState==4 || xmlHttp_add.readyState=="complete")
    {
		var tl=document.getElementById("translate_last");
		if (tl!=null) tl.innerHTML=xmlHttp_add.responseText;
	}

}


function stateChanged() {
	if (xmlHttp.readyState<4) {
		document.getElementById("result").innerHTML="<img src='loader.gif' />";    //ПОКАЗЫВАЕТ ЛОАДЕР
    }
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
		if(xmlHttp.responseText == "exit"){
			document.location = "index.php?session=close";
			xmlHttp.responseText = "";
		}
     // document.getElementById("result").innerHTML=xmlHttp.responseText;

		var c_txt=xmlHttp.responseText;
		if (c_txt!=null && c_txt.substr(0,5)=="error")
        {
			var a_sp=c_txt.split('~',3);
		  	//window.alert(a_sp[1]);
    	  	document.getElementById("result").innerHTML=a_sp[2];
		  	window.top.document.location.reload();
		  	return true;
        }
		else
		{
			document.getElementById("result").innerHTML=xmlHttp.responseText;  //ПОКАЗЫВАЕТ РЕЗУЛЬТАТ
		}

		translate_found_value = document.getElementById("translate_found").value;
      	new_translate_value = document.getElementById("new_translate").value;
      	translate_found_value = translate_found_value*new_translate_value;
      	xmlHttp_add=GetXmlHttpObject();
      	var url="include/components/vivod_add.php?translate_found="+translate_found_value+"&sid="+Math.random();
      	xmlHttp_add.onreadystatechange=stateChanged_add;
      	xmlHttp_add.open("GET",url,true);
      	xmlHttp_add.send(null);

      	xmlHttp_1=GetXmlHttpObject();
      	url="include/components/found.php?sid="+Math.random();
      	xmlHttp_1.onreadystatechange=found;
      	xmlHttp_1.open("GET",url,true);
      	xmlHttp_1.send(null);

      	xmlHttp_2=GetXmlHttpObject();
      	url="include/components/last_most.php?sid="+Math.random();
      	xmlHttp_2.onreadystatechange=last_most;
      	xmlHttp_2.open("GET",url,true);
      	xmlHttp_2.send(null);
      
	 }
}


function stateChanged2() {
	if (xmlHttp.readyState<4) {
		document.getElementById("result").innerHTML="<img src='loader.gif' />";
    }
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
      	document.getElementById("result").innerHTML=xmlHttp.responseText;
    }
}



function showResult(direction1, direction2, direction, start_page, inp_word, use_dia, req_type, callback) {

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
    {
		alert ("Browser does not support HTTP Request");
		return;
    }
		inp_word = inp_word.toLowerCase();
		var str;
		for (var i=0; i<inp_word.length; i++) {
			str+="/"+inp_word.charCodeAt(i);
        }
        str+="/";
    var c_req_type='0';
    if (req_type!=null) c_req_type=req_type;
    var url="include/components/vivod.php";    //ЗАГРУЗКА ВЫВОДЯЩЕЙ ПЕПЕРВОД СТРАНИЦЫ
    url=url+"?direction1="+direction1+"&direction2="+direction2+"&direction="+direction+"&start_page="+start_page+"&inp_word="+str+"&use_dia="+use_dia+"&req_type="+c_req_type+"&sid="+Math.random();
	if (c_req_type=='0')
		xmlHttp.onreadystatechange = function() { 
			stateChanged();
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
			{
				if(xmlHttp.responseText == "exit")
				{
					document.location.href = "index.php?session=close";
					
				}
				if (callback)
					setTimeout(function() { eval(callback); }, 500);
			}
		}
    else
		xmlHttp.onreadystatechange = function() { 
			stateChanged2();
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
			{
				if (callback)
					setTimeout(function() { eval(callback); }, 500);
			}
		}
		 
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}


  function last_most() {
	if (xmlHttp_2.readyState==4 || xmlHttp_2.readyState=="complete") {
      document.getElementById("most").innerHTML=xmlHttp_2.responseText;
    }
  }

  function GetXmlHttpObject() {

        var xmlHttp=null;
    try
     {
     // Firefox, Opera 8.0+, Safari
     xmlHttp=new XMLHttpRequest();
     }
    catch (e)
     {
     //Internet Explorer
     try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
     catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
     }
    return xmlHttp;
  }

  function Show(id) {

	oldid_i = document.getElementById("oldid").value;
	if(oldid_i) {
		document.getElementById("trans_" + document.getElementById("oldid").value).style.display = "none";
		document.getElementById("a_" + document.getElementById("oldid").value).style.color = "#0066cc";
	}

    document.getElementById("trans_" + id).style.display = "block";
    document.getElementById("a_" + id).style.color = "#FF0000";

    document.getElementById("oldid").value=id;
  }
//==================================================
  function Trans(id) {
    for (i = 0; i < _ids.length; i++) {
      document.getElementById("trans_" + _ids[i]).style.display = "none";
      document.getElementById("a_" + _ids[i]).style.color = "#014401";
    }
    document.getElementById("trans_" + id).style.display = "block";
    document.getElementById("a_" + id).style.color = "#FF0000";
  }
//==================================================
  function storeCaret (textEl) {
    if (document.getElementById(textEl).createTextRange)
      document.getElementById(textEl).caretPos = document.selection.createRange().duplicate();
  }
//==================================================
  function insertAtCaret (textEl, text) {
    if (document.getElementById(textEl).createTextRange && document.getElementById(textEl).caretPos) {
      var caretPos = document.getElementById(textEl).caretPos;
      caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
    } else {
      document.getElementById(textEl).value = document.getElementById(textEl).value + text; // если броузер не MSIE
    }
        document.getElementById("inp_word").focus();
    return true;
  }
//==================================================
  function ValidateWord() {

    if (document.getElementById("inp_word").value == '') {
           alert('Введите слово для перевода.');
           document.getElementById("inp_word").focus();
           return false;
        }
    if ((document.getElementById("inp_word").value).length < 2) {
           alert('В слове должно быть не менее двух букв!');
           document.getElementById("inp_word").focus();
           return false;
        }

        for (var i=0; i<(document.getElementById("inp_word").value).length; i++) {
          if (document.getElementById("direction1").value=="ro_" && (document.getElementById("inp_word").value).charCodeAt(i)!=32 && (document.getElementById("inp_word").value).charCodeAt(i)!=45) {
            if ((document.getElementById("inp_word").value).charCodeAt(i)>400 || (document.getElementById("inp_word").value).charCodeAt(i)<65) {
                  alert("Caracterele introduse nu corespund cerintelor sau limba nu este specificata corect");
                  document.getElementById("inp_word").focus();
                  return false;
                }
          }
          if (document.getElementById("direction1").value=="ru_" && (document.getElementById("inp_word").value).charCodeAt(i)!=32 && (document.getElementById("inp_word").value).charCodeAt(i)!=45) {
            if ((document.getElementById("inp_word").value).charCodeAt(i)<900) {
                  alert("Язык не соответствует введённому слову");
                  document.getElementById("inp_word").focus();
                  return false;
                }
          }

          if (document.getElementById("direction1").value=="en_" && (document.getElementById("inp_word").value).charCodeAt(i)!=32 && (document.getElementById("inp_word").value).charCodeAt(i)!=45) {
            if ((document.getElementById("inp_word").value).charCodeAt(i)>400 || (document.getElementById("inp_word").value).charCodeAt(i)<65) {
                  alert("Your charset is not aloowed!");
                  document.getElementById("inp_word").focus();
                  return false;
                }
          }
        }

    if (document.getElementById("inp_word").value.substr(0,2)==document.getElementById("inp_word").value.toUpperCase().substr(0,2))
          document.getElementById("inp_word").value = document.getElementById("inp_word").value.toUpperCase();
    document.getElementById("direction").value = document.getElementById("direction1").value+document.getElementById("direction2").value;
    return true;
  }
//==================================================
//==================================================
nereidFadeObjects = new Object();
nereidFadeTimers = new Object();
//==================================================
function nereidFade(object, destOp, rate, delta){
if (!document.all)
return
    if (object != "[object]"){  //do this so I can take a string too
        setTimeout("nereidFade("+object+","+destOp+","+rate+","+delta+")",0);
        return;
    }
    clearTimeout(nereidFadeTimers[object.sourceIndex]);
    diff = destOp-object.filters.alpha.opacity;
    direction = 1;
    if (object.filters.alpha.opacity > destOp){
        direction = -1;
    }
    delta=Math.min(direction*diff,delta);
    object.filters.alpha.opacity+=direction*delta;

    if (object.filters.alpha.opacity != destOp){
        nereidFadeObjects[object.sourceIndex]=object;
nereidFadeTimers[object.sourceIndex]=setTimeout("nereidFade(nereidFadeObjects["+object.sourceIndex+"],"+destOp+","+rate+","+delta+")",rate);
    }
}
//==================================================
var select = false;
function changeLang()
{
	if(!select)
	{
		select = $("#direction2").clone(true);
	}
	var Opt = {
		ro_ : new Array("ru","en"),
		ru_ : new Array("ro"),
		en_ : new Array("ro")
	}
	
	var opts = Opt[$("#direction1").val()];
	
	var container = $("#direction2").parent();
	$("#direction2").remove();
	select.appendTo(container);
	select = $("#direction2").clone(true);
	
	var changeSelected = false;
	$("#direction2 > option").each(function(){
		//console.log($(this).val());
		var display = false;
		for(var i = 0;i < opts.length;i++)
		{
			if($(this).val() == opts[i])
			{
				display = true;
				changeSelected = true;
				break;
			}
		}
		if(!display)
		{
			$(this).remove();
		}
	});
	if(changeSelected)
		$("#direction2").children("option:visible:first").attr("selected","selected");
}


function table()
{
obj='table_ro';
var theObj = document.getElementById(obj).style;
if (document.getElementById("direction1").value=="ro_")
{theObj.display = "inline";
 document.getElementById("use_dia").checked="true";}
else
{theObj.display = "none";
 document.getElementById("use_dia").checked="false";}
 changeLang();
}
//==================================================

function check()
{
obj='use_dia';
var theObj = document.getElementById(obj);
theObj.checked="true";
}
//==================================================

function showdata (name,lastname,email,phone,website,id,new_window0,new_window1,new_window2,new_window3,new_window4,new_window5,new_window6)
 {
                var myWin = open('','newWindow'+id,'width=300,height=200,status=no,toolbar=no,menubar=no');
                myWin.document.open();
                myWin.document.write('<title>User details</title>');
                myWin.document.write('<link href="../../admin/original/css/theme_right.css" rel="stylesheet" type="text/css" />');
                myWin.document.write('<table class=data>');

                myWin.document.write('<tr class=odd><td>'+new_window2+'</td><td>');
                myWin.document.write(name);
                myWin.document.write('</td></tr>');
                myWin.document.write('<tr class=even><td>'+new_window3+'</td><td>');
                myWin.document.write(lastname);
                myWin.document.write('</td></tr>');
                myWin.document.write('<tr class=odd><td>'+new_window4+'</td><td>');
                myWin.document.writeln(email);
                myWin.document.write('</td></tr>');
                myWin.document.write('</td><tr class=even><td>'+new_window5+'</td><td>');
                myWin.document.write(phone);
                myWin.document.write('</td></tr>');
                myWin.document.write('<tr class=odd><td>'+new_window6+'</td><td>');
                myWin.document.write(website);
                myWin.document.write('</td></tr></table>');


 }

function showLoginForm()
{
  $("#login-error").empty();
  var overlay = $("#overlay");
  overlay.css({"width" : screen.availWidth-20 + "px", "height" : $("body").height() + "px", "display" : "block"});
  overlay.bind("click", function() { hideLoginForm(); });
  var container = $("#quick-login");
  container.css({"top" : Math.round((screen.availHeight-400)/2) + "px",
				"left" : Math.round((screen.availWidth-252)/2) + "px", 
				"display" : "block"});
  var id = "username";
  if (document.getElementById(id).value!="")
    id = "password";
  document.getElementById(id).focus();
}

function hideLoginForm()
{
  var container = $("#quick-login");
  container.css("display", "none");
  var overlay = $("#overlay");
  overlay.css("display", "none");
  overlay.unbind("click");
}

function quickLogin(eText) {
	errorText = '<p class="frmModalError">'+eText+'</p>';
    document.getElementById("login-error").innerHTML = "";
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp==null)
    {
		alert ("Browser does not support HTTP Request");
		return;
    }
	var myusername = document.getElementById("username").value;
	var mypassword = document.getElementById("password").value;
	var callbackType = document.getElementById("callback_type").value;
	var callback = document.getElementById("callback").value;
	while (callback.search("&")!=-1)
		callback = callback.replace("&", "!amp");
	while (callback.search("/")!=-1)
		callback = callback.replace("/", "!slash");
	var word = document.getElementById("inp_word").value;
	var direction1 = document.getElementById("direction1").value;
	var direction2 = document.getElementById("direction2").value;
    var url = "include/components/quick_login.php";
    url = url + "?rand=" + Math.random() + "&q=" + myusername + "/" + mypassword + "/" + callbackType + "/" + callback + "/" + word + "/" + direction1 + "/" + direction2;
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
		  if (xmlHttp.responseText=="1")
		    window.location = "index.php";
		  else
			document.getElementById("login-error").innerHTML = errorText;
		}
		else
		  document.getElementById("login-error").innerHTML = '<img src="img/ajax-loader.gif" alt="" />';
	};
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", url.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(url);
}

function showReportBugForm() {
  $("#report-bug-message").empty();
  var overlay = $("#overlay");
  overlay.css({"width" : screen.availWidth-20 + "px", "height" : $("body").height() + "px", "display" : "block"});
  overlay.bind("click", function() { hideReportBugForm(); });
  var container = $("#report-bug");
  container.css({"top" : Math.round((screen.availHeight-400)/2) + "px",
				"left" : Math.round((screen.availWidth-440)/2) + "px",
				"display" : "block"
  });
  document.getElementById("ta_message").focus();
}

function hideReportBugForm() {
  var container = $("#report-bug");
  container.css("display", "none");
  var overlay = $("#overlay");
  overlay.css("display", "none");
  overlay.unbind("click");
}

function reportBug() {
    document.getElementById("report-bug-message").innerHTML = "";
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp==null)
    {
		alert ("Browser does not support HTTP Request");
		return;
    }
	var text = document.getElementById("ta_message").value;
    var url = "include/components/report_bug.php";
    url = url + "?rand=" + Math.random() + "&q=" + text;
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			document.getElementById("report-bug-message").innerHTML = xmlHttp.responseText;
			if (xmlHttp.responseText.search("send-error")==-1)
				setTimeout(function() { hideReportBugForm() }, 3000);
		}
	};
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", url.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(url);
}

function execCallback(callback) {
	eval("isOkPressed(false, callback);");
}
