var topstatus='';
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("Ошибка создания объекта!");
 }
 else
 return xmlHttp;

}

function process(id,value)
{
aa=createXmlHttpRequestObject();

if(aa)
   {
		  try
		  {
		  aa.open("POST", "../../valid.php", true);
          /*Меняем MIME-тип*/
		  
          aa.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
          /*Указываем функцию*/
          aa.onreadystatechange = otvet;
         /*Отправляем запрос*/
		  
		
		  aa.send('id='+id+'&value='+value+'&topstatus='+topstatus);
		  
		 }
		  catch(e)
		  {
		  
		 
		  }
		
		
		
		
	}

}
function newvalueip(a,fff){
if(fff=="top"){
topstatus='top';
} else {
  if(fff=="c"){
  topstatus='c';
  } else {
  topstatus='';
  }
}

process('ip',a);
var id="ip";
document.getElementById("Resultip"+topstatus).innerHTML="<img src='images/spinner.gif' >";
}

function otvet(){
if(aa.readyState == 4) 
{

 if (aa.status == 200) 
  {
 
    try  
	{
	
	var xmlResponse=aa.responseXML;
    if(!xmlResponse || !xmlResponse.documentElement)
    throw("NEVERNAJA Strcutura XML");
    var rootNodeName=xmlResponse.documentElement.nodeName;
    if(rootNodeName=="parsererror")throw("Invalid XML");
    xmlRoot=xmlResponse.documentElement;
    OtvetOtServera=xmlRoot.getElementsByTagName("Otvet");
	var Otvet="";
    for(var i=0;i<OtvetOtServera.length;i++)
    Otvet+=OtvetOtServera.item(i).firstChild.data;
	  if(Otvet=="ERROR"){
	  document.getElementById("Resultip"+topstatus).innerHTML="Ошибка! Такого сервера нет в нашем мониторинге!";
	  document.getElementById("Resultip"+topstatus).style.color="red";
	  document.getElementById("periondtr"+topstatus).style.display="none";
	  document.getElementById("summa"+topstatus).style.display="none";
	  document.getElementById("icq"+topstatus).style.display="none";
	  document.getElementById("email"+topstatus).style.display="none";
	  document.getElementById("weiter"+topstatus).style.display="none";
	  document.getElementById("cwetline"+topstatus).style.display="none";
	  document.getElementById("topstatusi").style.display="none";
	 
	  }
	    else{
		  if(Otvet=="ERROREMAIL"){
		  if(document.getElementById("weiter"+topstatus).style.display=="table-row"){document.getElementById("weiter").style.display="none";}
			  document.getElementById("Resultemail"+topstatus).innerHTML="";
			  document.getElementById("Resultemail"+topstatus).innerHTML="Введите настоящий E-mail";
			   document.getElementById("Resultemail"+topstatus).style.color="red";
		  
		  
		  } else {
		    if(Otvet=="OKEMAIL"){
			 document.getElementById("weiter"+topstatus).style.display="table-row";
		
	  
			   document.getElementById("Resultemail"+topstatus).style.color="green";
			   document.getElementById("Resultemail"+topstatus).innerHTML="";
			    document.getElementById("Resultemail"+topstatus).innerHTML="E-mail успешно введен.";
		
			}
			  else{
			        document.getElementById("cwetline"+topstatus).style.display="table-row";
					document.getElementById("Resultip"+topstatus).innerHTML="Сервер найден! "+Otvet;
					document.getElementById("Resultip"+topstatus).style.color="green";
					document.getElementById("periondtr"+topstatus).style.display="table-row";
					document.getElementById("summa"+topstatus).style.display="table-row";
					  if(topstatus=="top"){
					  document.getElementById("topstatusi").style.display="table-row";
					  }
					  if(topstatus==""){
					  document.getElementById("vipstatusi").style.display="table-row";
					  
					  }
			  }
		  
		  }
		}
	}
	  catch(e)
	  {
	  
	  }
   }
}


}

function newvalue(){
b=document.getElementById("period"+topstatus).value;
   if(b!==0){
  document.getElementById("summa"+topstatus).style.display="none";
  document.getElementById("topstatusi").style.display="none";
   if(document.getElementById("icq"+topstatus).style.display=="none"){
	 document.getElementById("icq"+topstatus).style.display="table-row";
	 }
  }
   if(b==0){
  document.getElementById("summa"+topstatus).style.display="table-row";
  document.getElementById("topstatusi").style.display="table-row";
  
  }
}
function newvaluesumma(){
 a=document.getElementById("sum"+topstatus).value;
 if(a>=20){
     document.getElementById("Resultsumma"+topstatus).innerHTML="";
	 if(topstatus=="top"){
	 document.getElementById("Resultsumma"+topstatus).innerHTML="Примерно <b>"+a/13.3+"</b> дней";
	 } else {
	   if(topstatus=="c"){
	   document.getElementById("Resultsumma"+topstatus).innerHTML="Примерно <b>"+a/3.3+"</b> дней";
	   } else {
	   document.getElementById("Resultsumma"+topstatus).innerHTML="Примерно <b>"+a/6.6+"</b> дней";
	   }
	 }
	 document.getElementById("Resultsumma"+topstatus).style.color="green";
	 if(document.getElementById("icq"+topstatus).style.display=="none"){
	 document.getElementById("icq"+topstatus).style.display="table-row";
	 }
	
	 
	} else {
	 document.getElementById("Resultsumma"+topstatus).innerHTML="";
	 document.getElementById("Resultsumma"+topstatus).innerHTML="Минимум 20 рублей";
	 document.getElementById("Resultsumma"+topstatus).style.color="red";
	 if(document.getElementById("icq"+topstatus).style.display=="table-row"){
	 document.getElementById("icq"+topstatus).style.display="none";
	 }
	 if(document.getElementById("weiter"+topstatus).style.display=="table-row"){
	 document.getElementById("weiter"+topstatus).style.display="none";
	 }
	 if(document.getElementById("email"+topstatus).style.display=="table-row"){
	 document.getElementById("email"+topstatus).style.display="none";
	 }
	
	}
}
function newvalueicq(f){
  if(f!==""){
  document.getElementById("email"+topstatus).style.display="table-row";
  }
    else{
	if(document.getElementById("weiter"+topstatus).style.display=="table-row"){
	 document.getElementById("weiter"+topstatus).style.display="none";
	 }
	 if(document.getElementById("email"+topstatus).style.display=="table-row"){
	 document.getElementById("email"+topstatus).style.display="none";
	 }
	}

}
function newvaluemail(f){
if(f!==""){
process("email",f);

}
  else{
  if(document.getElementById("weiter"+topstatus).style.display=="table-row"){document.getElementById("weiter").style.display="none";}
			  document.getElementById("Resultemail"+topstatus).innerHTML="";
			  document.getElementById("Resultemail"+topstatus).innerHTML="Введите настоящий E-mail";
			   document.getElementById("Resultemail"+topstatus).style.color="red";
  }

}