//mail + captcha
// stores the reference to the XMLHttpRequest object
var xmlHttp = createXmlHttpRequestObject(); 
var captHttp = createXmlHttpRequestObject(); 
// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject() 
{	
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // if running Internet Explorer
  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
 
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}

// make asynchronous HTTP request using the XMLHttpRequest object 
function process()
{
var len; var params; 
  // proceed only if the xmlHttp object isn't busy
thetext = document.frm.thetext.value;
hide = document.getElementById("hide").value;
meno = document.getElementById("meno").value;
email = document.getElementById("email").value;
subj = document.getElementById("subj").value;
protect = document.getElementById("protect").value;
params="hide="+hide+"&thetext="+thetext+"&meno="+meno+"&email="+email+"&subj="+subj+"&protect="+protect;
//len = name.length;
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0 )
  {
    xmlHttp.open("POST", "ajaxmail.php");  
    xmlHttp.onreadystatechange = handleServerResponse;
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(params);
	thetext = document.frm.thetext.value='';
	document.getElementById("meno").value='';
	document.getElementById("email").value='';
	document.getElementById("subj").value='';
  }
process1();
}

function process1()
{
 var myDate=new Date();
 var cparams=myDate.getTime();
  if (captHttp.readyState == 4 || captHttp.readyState == 0 )
  {
    captHttp.open("POST", "ajaxcaptcha.php");  
    captHttp.onreadystatechange = handleServerResponse1;
	captHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    captHttp.send(cparams);
	document.getElementById("protect").value='';
  }

}

function kalc()
{
var len; var params; 
  // proceed only if the xmlHttp object isn't busy
square = document.kalkulator.square.options[document.kalkulator.square.selectedIndex].value;
years = document.kalkulator.years.options[document.kalkulator.years.selectedIndex].value;
mikro = document.kalkulator.mikro.options[document.kalkulator.mikro.selectedIndex].value;
hand = document.kalkulator.hand.options[document.kalkulator.hand.selectedIndex].value;
params="square="+square+"&years="+years+"&mikro="+mikro+"&hand="+hand;
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0 )
  {
    xmlHttp.open("POST", "ajaxcalc.php");  
    xmlHttp.onreadystatechange = CalcServerResponse;
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(params);
  }
}


function kalc2()
{
var len; var params; 
  // proceed only if the xmlHttp object isn't busy
sleif = document.getElementById("sleif").value;
serena = document.getElementById("serena").value;
teploopov = document.getElementById("teploopov").value;
dumopov = document.getElementById("dumopov").value;
params="sleif="+sleif+"&serena="+serena+"&teploopov="+teploopov+"&dumopov="+dumopov+"&hide=tech";
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0 )
  {
    xmlHttp.open("POST", "ajaxcalc.php");  
    xmlHttp.onreadystatechange = CalcServerResponse;
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(params);
  }
}

function kalc4()
{
sleif = document.getElementById("sleif").value;
if(sleif<=150)square =sleif*25;
if(sleif>150&&sleif<=200)square =sleif*20;
if(sleif>200&&sleif<=400)square =sleif*18;
if(sleif>400&&sleif<=600)square =sleif*17;
if(sleif>600&&sleif<=800)square =sleif*16;
if(sleif>800&&sleif<=1000)square =sleif*15;
if(sleif>1000&&sleif<=2000)square =sleif*14;
if(sleif>2000&&sleif<=4000)square =sleif*13;
if(sleif>4000)square =sleif*12;
bpdv=Math.floor(square/6*100);
pdv=bpdv/100;
document.getElementById("calcMessage").innerHTML =  '<span class="red">'+square+'</span> гривень, в тому числі ПДВ <span class="red">'+pdv.toFixed(2)+'</span> гривень.' ;
}

function kalc3()
{
square = document.kalkulator.square.options[document.kalkulator.square.selectedIndex].value;
bpdv=Math.floor(square/6*100);
pdv=bpdv/100;
document.getElementById("calcMessage").innerHTML =  '<span class="red">'+square+'</span> гривень, в тому числі ПДВ <span class="red">'+pdv.toFixed(2)+'</span> гривень.' ;
}


function handleServerResponse() 
{
  // move forward only if the transaction has completed
  if (xmlHttp.readyState == 4) 
  {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
      xmlResponse = xmlHttp.responseText;
	  
      document.getElementById("Message").innerHTML =  xmlResponse ;
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
  else
  {
  document.getElementById("Message").innerHTML =  '<img src="image/rasp.gif" width="50" height="5"><img src="image/by.gif">' ;
  } 
}

function CalcServerResponse() 
{
  // move forward only if the transaction has completed
  if (xmlHttp.readyState == 4) 
  {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
      xmlResponse = xmlHttp.responseText;
	  
      document.getElementById("calcMessage").innerHTML =  xmlResponse ;
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
  else
  {
  document.getElementById("calcMessage").innerHTML =  '<img src="image/by.gif">' ;
  } 
}

function handleServerResponse1() 
{
  if (captHttp.readyState == 4) 
  {
    if (captHttp.status == 200) 
    {
     captchaxml = captHttp.responseText;
	  
      document.getElementById("captcha").innerHTML =  captchaxml ;
    } 
    else 
    {
      alert("There was a problem accessing the server ajaxcaptcha: " + captHttp.statusText);
    }
  }

}

