var xmlHttp = createXmlHttpRequestObject();
 

function createXmlHttpRequestObject() {

    var xmlHttp;
    try {

        xmlHttp = new XMLHttpRequest();
    }
    catch(e)  {

        var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                        "MSXML2.XMLHTTP.5.0",
                                        "MSXML2.XMLHTTP.4.0",
                                        "MSXML2.XMLHTTP.3.0",
                                        "MSXML2.XMLHTTP",
                                        "Microsoft.XMLHTTP");

    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) {
          try { 

              xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
          } 
          catch (e) {}
    }
}

  if (!xmlHttp) alert("Ошибка создания XMLHttpRequest");
  else return xmlHttp;
}


function Request() {

        if (xmlHttp) {
            try {
		$name    = document.getElementById('name').value;
		$sname   = document.getElementById('sname').value;
		$age     = document.getElementById('age').value;
		$phone   = document.getElementById('phone').value;
		$zvonok  = document.getElementById('zvonok').value;
		$prog    = document.getElementById('prog').value;
		$info    = document.getElementById('info').value;

                var errorList = [];
	        var errorText = {
    	        1 : "Не заполнено поле 'Номер телефона'"
    		} 
		if ($phone.length < 7)  errorList.push(1);


		if (!errorList.length)
                {
                xmlHttp.open("GET", "/cmd/send2.php?name="+encodeURI($name)+"&sname="+encodeURI($sname)+"&age="+encodeURI($age)+"&phone="+encodeURI($phone)+"&zvonok="+encodeURI($zvonok)+"&prog="+encodeURI($prog)+"&info="+encodeURI($info), true);
                xmlHttp.onreadystatechange = handlerRequest;
                xmlHttp.send(null);
		}
		else {
                var errorMsg = "Ошибка: ";
                for (i = 0; i < errorList.length; i++) {
                errorMsg += errorText[errorList[i]] + "\n";
		}
		alert(errorMsg);
		}

        }
        catch(e) {}
    }
}

function handlerRequest() {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            try {
                var content = xmlHttp.responseText;

	            if (content==200){
                    document.getElementById('vform').innerHTML = "<p><strong>Спасибо! Наш оператор свяжется с Вами в ближайшее время.</strong></p>";
		    }

                }
            catch(e) {}
        }
        else {}
  }
}

function Hide(){
document.getElementById('onl').style.display = "none";

}

function ShowLayer($id) {

        if (xmlHttp) {
            try {


                xmlHttp.open("GET", "/cmd/newsinfo.php?id="+encodeURI($id), true);
                xmlHttp.onreadystatechange = handlerShowLayer;
                xmlHttp.send(null);

        }
        catch(e) {}
    }
}

function handlerShowLayer() {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            try {
                var content = xmlHttp.responseText;
		document.getElementById('onl').innerHTML = content + '<br><a href="javascript:void(0);" onclick="Hide();">закрыть</a>';
		document.getElementById('onl').style.display = "block";
                }
            catch(e) {}
        }
        else {}
  }
}






