pref = '_rte';
tr_pref = 'tr_';
use_rte = 0;
//if (navigator.appName != 'Netscape')
use_rte = 1;

//===============================================================================
//## <RTE>
//===============================================================================
function submitForm() {
	//make sure hidden and iframe values are in sync for all rtes before submitting form
	updateRTEs();

	//change the following line to true to submit form
   //alert("rte1 = " + (document.RTEDemo.rte1.value));
	return false;
}
//===============================================================================
function PlainTextMode(dname) {
   tt = getElementByMy(tr_pref + dname);
   tt.style.display = 'inline';

   tt = getElementByMy(tr_pref + dname + pref);
   tt.style.display = 'none';
   //v(tr_pref + dname + pref);
   //delete(dname+pref);
}
//===============================================================================
function getRte(dname, rteUrl) {
   if (use_rte ==0) {return;}

   initRTE(rteUrl + "images/", rteUrl, "", false);

   var rte1 = new richTextEditor(dname + pref);

   t = getElementByMy(tr_pref + dname);
   t.style.display = 'none';

   t = getElementByMy(tr_pref + dname + pref);
   t.style.display = 'inline';

   rte1.html = getElementByMy(dname).value;

   rte1.toggleSrc = false;

   rte1.width = 300;

   rte1.cmdInsertLink = false;
   rte1.cmdInsertImage = false;
   rte1.cmdInsertSpecialChars = false;
   rte1.cmdInsertTable = false;
   rte1.cmdSpellcheck = false;

   rte1.cmdCut = false;
   rte1.cmdCopy = false;
   rte1.cmdPaste = false;
   rte1.cmdUndo = false;
   rte1.cmdRedo = false;
   rte1.cmdRemoveFormat = false;
   rte1.cmdUnlink = false;


   rte1.build();

   return rte1;
}
//===============================================================================
//## <AJAX>
var working;
//===============================================================================
function getElementByMy(name) {
   if (document.getElementById) {
      curElement = document.getElementById(name);
   } else {
      curElement = document.all[name];
   }
   if (! curElement) {
      if (document.forms["frm"]) {
         curElement = document.frm[name];
      }
      if (! curElement) {
         if (document.forms["frm1"]) {
            curElement = document.frm1[name];
         }
      }
   }
   return curElement;
}
//========================================================================================
function vacation(url) {
   ajax_scr = 'accounts.php';
   vac_step = 'arv';
   vac_url = script_url + '/' + ajax_scr + '?step=' + vac_step;

   var parr = new Array('country', 'city', 'hotel', 'jetplane', 'lady', 'menu');
   out = '';
   for (var i=0;i<parr.length;i++) {
      cel = getElementByMy(parr[i]);
      if (cel) {
         var val = '';
         if ((cel.type == 'select-one') || (cel.type == 'select')) {
            val = cel.options[cel.selectedIndex].value.toString();
            if (val==1) val = '';
         }
         out = out + '&' + parr[i] + '=' + val;
      }
   }

   //v(vac_url+ out);
   majaxGetUrl(vac_url + out);
   //majaxGetUrl('http://127.0.0.1');
}
//========================================================================================
function ParceResponse(str) {
   //v(str);
   mr = /<(.+?)>(.+?)<\/(.+?)>/gi;
   var res = new Array;
   //#myc !!! certain count
   for (a=0; a<17; a++) {
      arr = mr.exec(str);
      if (arr) {
         if (arr[1].indexOf('|')>-1) {
            atypes = arr[1].split("|");
            arr[1] = atypes[0];
            ctype = atypes[1];
         } else {
            ctype = '';
         }
         //v(arr[1] + ctype);
         curElement = getElementByMy(arr[1]);
         //alert(arr[1] + curElement);
         if ((! ctype) || (ctype=='select')) {
            res[arr[1]] = arr[2].split("|");
            FillSelect(curElement, res[arr[1]]);
         } else if (ctype=='sel_index') {
            curElement.selectedIndex = arr[2];
         } else {
            curElement.innerHTML = arr[2];
         }
      }
   }
}
//========================================================================================
function FillSelect(sel, arr) {
   for (var i = 0; i < sel.options.length; i++) {
      sel.options[i] = null;
   }
   sel.options.count = 0;
   //sel.options =null;
   var tmp = '';
   //c(sel.options.count);
   for (var i = 0; i < arr.length; i=i+2) {
      var a=i/2;
      //c(a);
      sel.options[a] = new Option(arr[i+1], arr[i]);
      tmp = tmp + i/2 + '|';
   }
   c(sel.name);
}
//========================================================================================
function majaxGetUrl(url) {
   var http;

   http = get_http();
   if(! http){
      alert('err XMLHTTP err!')
   }

   // Получаем объект XMLHTTPRequest
   if(!this.http){
      this.http = get_http();
      working = false;
   }
   // Запрос
   //alert(working + '|' +this.http);
   if ((! working) && this.http) {
      var http = this.http;

      //создаём запрос
      this.http.open("GET", url, true);
      //прикрепляем к запросу функцию-обработчик
      //событий
      this.http.onreadystatechange = function() {
         // 4 – данные готовы для обработки
         if (http.readyState == 4) {
            working = false;
            //retrun http.responseText;
            ParceResponse(http.responseText);
         } else {
            // данные в процессе получения,
            // можно повеселить пользовател
            //сообщениями
            // ЖДИТЕ ОТВЕТА
         }
      }
      working = true;
      this.http.send(null);
   }
   if(!this.http){
      alert('err XMLHTTP объекта!')
   }
}
//========================================================================================
function get_http_(){
    var xmlhttp;
    //@cc_on
    if (_jscript_version >= 5)
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                xmlhttp = false;
            }
        }
    else
        xmlhttp = false;
    end


    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }
    return xmlhttp;
}
//========================================================================================
function get_http() {
  if (window.XMLHttpRequest) {
    //создание объекта для всех браузеров кроме IE
        requestObj = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
      //для IE
        requestObj = new ActiveXObject("Msxml2.XMLHTTP");
        if (!requestObj) {
            requestObj = new ActiveXObject("Microsoft.XMLHTTP");
        };
    };
    return requestObj;
};
//========================================================================================
//## <ENGINE>
//========================================================================================
function HideNeed() {
   sel = getElementByMy('accept_type');
   need_id_in = getElementByMy('need_id');
   if (sel.selectedIndex == 0) {
      need_id_in.style.display = "none";
   } else {
      need_id_in.style.display = "inline";
   }
}
//========================================================================================
//## <OTHER FUNC>
//========================================================================================
function CheckFields(ta) {
   d = ' | ';
   err = 0;
   for (var i=0;i<ta.length;i++) {
      var e = ta[i];
      //alert(e);
      tInp = getElementByMy(e);
      if (tInp) {
         if (tInp.type == 'checkbox') {
            //alert(tInp.name + d + tInp.type + d + tInp.value + d  + tInp.value.length + d + tInp.checked);
            tInp1 = document.getElementById(tInp.name + '0');
            if (tInp1) {
               if (err!=1) {
                  err=1;
                  for (a=0; a<100; a=a+2) {
                     tInp1 = document.getElementById(tInp.name + a);
                     if (tInp1) {
                        //alert(tInp.name + d + tInp.type + d + tInp.value + d  + tInp.value.length + d + tInp.checked);
                        if (tInp1.checked == true) {
                           err=0;
                           break;
                        }
                     }
                  }
               }
            } else {
               if (tInp.checked == false) {
                  err=1;
               }
            }
         } else {
            //alert(tInp.name + d + tInp.type + d + tInp.value + d  + tInp.value.length + d + tInp.checked);
            if (tInp.value.length<1) {
               err=1;
               //alert('err');
               //htmo = document.getElementById(e.toString());
            }
         }
      }
   }

   //alert(err);
   //return false;

   if (err>0) {
      alert("Please fill in all required (*) fields");
      return false;
   } else {
      return true;
   }
}
//========================================================================================
function SubmitAction(act, id) {
   frm.substep.value = act;
   frm.id.value = id;
   frm.submit();
}
//========================================================================================
function QstDel(link) {
   if (window.confirm('Delete item ?') == true) { // + link
      window.location=link;
   }
   return false;
}
//========================================================================================
function SubmitAction1(act, id) { //, id, cpos_null
   document.frm1.substep.value = act;
   document.frm1.id.value = id;
   if ((act=='del') && (window.confirm('Delete item ?') != true)) {
      return;
   }
   document.frm1.submit();
}
//========================================================================================
function SubmitAction2(act, id) { //, id, cpos_null

   //v(getElementByMy('frm1'));

   document.frm1.substep.value = act;
   document.frm1.id.value = id;
   document.frm1.cpos.value = 0;
   if ((act=='del') && (window.confirm('Delete item ?') != true)) {
      return;
   }
   document.frm1.submit();
}
//========================================================================================
function CheckAll() {
   frm=document.frm1;
   for (var i=0;i<frm.elements.length;i++) {
      var e = frm.elements[i];
      if ((e.name != 'allbox') && (e.type=='checkbox')) {
         e.checked = frm.allbox.checked;
      }
   }
}
//========================================================================================
function ChangeContinent() {

   var SelectedContinent = frm.continent.options[frm.continent.selectedIndex].value;
   var oldSelectedCountry = frm.country.options[frm.country.selectedIndex].value;


   // (clear)
   var k = frm.country.options.length;
   for (var i = 0; i < k; i++) {
      frm.country.options[0] = null;
   }

   var result = '';
   var k=0;
   frm.country.options[k] = new Option('All', 'all');
   for (var i in ctr_cnt_h) {
      if ((ctr_cnt_h[i] == SelectedContinent) || (SelectedContinent == 'all')) {
         k++;
         frm.country.options[k] = new Option(i, i);
         if (oldSelectedCountry == i) frm.country.selectedIndex = k;
         result += i;
      }
   }
   //alert(result);
}
//========================================================================================
//## <DEBUG>
//========================================================================================
function v(str) {
   alert(str);
}
//========================================================================================
function c(str) {
   var debug = getElementByMy('debug');
   if (debug) {
     //debug.innerHTML += ' [' + str + '] ';
   }
}
//========================================================================================
