var xmlHttp;
var uri = "";
var callingFunc = "";
var sResponse = "";

function GetXmlHttpObject()
{

  xmlHttp=null;
  try
  {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  {

    // Internet Explorer
    try
    {
      //alert('jigishtry');
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    //alert('jigishtried');
    }
    catch (e)
    {
      //alert('jigishcatch');
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    //alert('jigishcatched');
    }
  }
  //	alert(xmlHttp);
  return xmlHttp;
}


function remoteCall(sUrl, sQueryStr, sCalledBy)
{
  uri = sUrl;
  callingFunc = sCalledBy;
	
  xmlHttp=GetXmlHttpObject();
	
  if (xmlHttp==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  }
  if (xmlHttp) 
  {
    xmlHttp.onreadystatechange = stateHandler;
    //alert(sUrl);
    xmlHttp.open("POST", sUrl, true);
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(sQueryStr);
  }	
//	alert('jigish');
}

function stateHandler() 
{
  if (xmlHttp.readyState == 4)
  {
    /*if (xmlHttp.status == 200)
		{*/
    sResponse = xmlHttp.responseText;
    //alert(sResponse);
    eval(callingFunc+'()');
  /*		}
		else 
		{
			//alert('Failed!');
		} */
  }
  return true;
}



var Spell_Win_Name;
var Work_Form_Name;
var Work_Field_Name;

function SpellCheck(form_name,field_name) 
{
  //четене на формата във променливата textform
  //ако формата се казва: proba 
  //а полето за проверка е: description_short
  //правилното използване трябва да бъде
  //var textform = self.document.proba.description_short.value;
  //var textform = self.document["proba"]["description_short"].value;
  
  var textform = self.document[form_name][field_name].value;
  
  //textform = "dfghfhfghfghfgh";
  //обратно записване в формата
  //self.document[form_name][field_name].value = "alabala i towa e";
  //съобщение
  //alert (textform);
  
  //open popup window and submit to spell_check.php ONLY
  //1. IF popup window is not open or popup window was closed
  //2. OR click comes from another form-field
  
  //otherwise spellcheck click just focus popup window
  
  if ( ! Spell_Win_Name || Spell_Win_Name.closed || (Work_Form_Name != form_name || Work_Field_Name != field_name))
  {
    Spell_Win_Name = win_pop('');
    if (Spell_Win_Name.focus) {
      Spell_Win_Name.focus();
    }
  
    self.document.hidden_form.form_name.value = form_name; 	//w skritata forma se izpolzwa ime na pole form_name i field_name
    self.document.hidden_form.field_name.value = field_name;  	// koito nqmat nishto obshto s promrnliwite w tazi funkciq
    self.document.hidden_form.first_time_text.value = textform;
    self.document.hidden_form.submit();
  
    Work_Form_Name=form_name;
    Work_Field_Name=field_name;
  }
  else
  {
    if (Spell_Win_Name.focus) {
      Spell_Win_Name.focus();
    }
  }

}


function win_pop(URL)
{	
  winname=window.open(URL,'WIN','width=600,height=380,left=210,top=210,resizable=yes,scrollbars=yes,status=yes'); 
  return winname;
}


