/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
} else {
request_type = new XMLHttpRequest();
}
return request_type;
}
var http = createObject();
/* -------------------------- */
/* SEARCH */
/* -------------------------- */
function searchNameq() {
searchq = encodeURI(document.getElementById('searchq').value);
document.getElementById('search-result').style.display = "block";
nocache = Math.random();
http.open('get', 'search.php?searchq='+searchq
+'&nocache = '+nocache);
http.onreadystatechange = searchNameqReply;
http.send(null);
}

function searchNameqReply() {
if(http.readyState == 4){
var response = http.responseText;
document.getElementById('search-result').innerHTML = response;
}
}



var url = 'captcheck.php?code=';
        var captchaOK = 2;  // 2 - not yet checked, 1 - correct, 0 - failed

        function getHTTPObject()
        {
        try {
        req = new XMLHttpRequest();
          } catch (err1)
          {
          try {
          req = new ActiveXObject("Msxml12.XMLHTTP");
          } catch (err2)
          {
          try {
            req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (err3)
            {
	req = false;
            }
          }
	}
        return req;
	}

        var http = getHTTPObject(); // We create the HTTP Object

        function handleHttpResponse() {
        if (http.readyState == 4) {
            captchaOK = http.responseText;
            if(captchaOK != 1) {
              alert('Введеный код не верен. Пожалуйста, попробуйте снова!');
              document.zakaz.code.value='';
              document.zakaz.code.focus();
              return false;
              }
              document.zakaz.submit(); 
           }
        }

        function checkcode(thecode) {
        http.open("GET", url+thecode, true);
        http.onreadystatechange = handleHttpResponse;
        http.send(null);
        }

        function checkform() {
        // First the normal form validation
        if(document.zakaz.firstname.value=='') {
          alert('Введите имя');
          document.zakaz.name.focus();
          return false;
          }

        if(document.zakaz.mail.value=='') {
          alert('Введите E-mail адресс');
          document.zakaz.mail.focus();
          return false;
          }



        if(document.zakaz.code.value=='') {
          alert('Пожалуйста, введите проверочный код');
          document.zakaz.code.value='';
          document.zakaz.code.focus();
          return false;
          }
          // Now the Ajax CAPTCHA validation
          checkcode(document.zakaz.code.value);
          return false;
        }
//Generic Section Loader Alpha 

/*
function loadsec(name)
{
 if (document.name.checked)
	 {
	    document.secform.text.value = 
     }
} 

function ahah(url, target) {
  url = url + '.htm';
  document.secform.text.value = ' Fetching data...';
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() {ahahDone(url, target);};
    req.open("GET", url, true);
    req.send("");
  }
}  

function ahahDone(url, target) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.secform.text.value = req.responseText;
    } else {
      document.secform.text.value = " AHAH Error:\n"+ req.status + "\n" +req.statusText;
    }
  }
}
	
function load(name, div) {
	ahah(name,div);
	return false;
} */



function load(sec_name) {
nocache = Math.random();
http.open('get', 'loadsec.php?sec='+sec_name
+'&nocache='+nocache);
http.onreadystatechange = GetSecReply;
http.send(null);
}

function GetSecReply() {
 if(http.readyState == 4)
 {
  var response = http.responseText;
  tinyMCE.activeEditor.setContent(response);
  //document.getElementById('coc').innerHTML = response;
 }
}
