
function bill_ip() {
	makeRequest('bill_op.php?action=step1&ptype=ip','pay');
}

function bill_org() {
	document.getElementById('pay_choose').style.display = "none";
	makeRequest('bill_op.php?action=step1&ptype=org','pay');
}

function bill_step1_back() {

  var http_request = false;

  if (window.XMLHttpRequest) {
    http_request = new XMLHttpRequest();

  } else if (window.ActiveXObject) {
    try {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
    }
  }

  if (!http_request) {
    alert('Giving up :( Cannot create an XMLHTTP instance');
    return false;
  }

  http_request.onreadystatechange = function() { bill_st_back(http_request); };
  http_request.open('GET', 'bill_op.php', true);
  http_request.send(null);
}
function bill_st_back(http_request) {

  if (http_request.readyState == 4) {
    if (http_request.status == 200) {
      document.getElementById('pay').innerHTML = http_request.responseText;
			document.getElementById('submit').disabled = false;
    } else {
      alert('There was a problem with the request.');
    }
  }
}

function bill_step2(ptype) {
	
	if(ptype == 'org') {

  	var data = new Array("o_company","o_city","o_str","o_pindex","o_pcity","o_pstr","o_inn","o_kpp","o_phone","domain");
	} else if(ptype == 'ip') {

  	var data = new Array("p_name1","p_name2","p_name3","p_index","p_city","p_str","o_inn","p_phone","domain");
	}
  var req = 'action=step2&';

  for(x=0;x<data.length;x++) {
    var v = document.getElementById(data[x]).value;
    if(v != '' && v != null)
      req = req + data[x]+'='+v+'&';
		else {
			alert('Необходимо заполнить всё поля формы.'); 
			return;
		}
  }

	makeRequestPost('bill_op.php',req,'pay');
	document.getElementById('pay').innerHTML = 'Выполнение запроса...';	 
}

function domain_check(obj) {
	
	if(obj.value.indexOf('.') == -1) {
		alert('Неверное имя домена.');
		return;
	}

  var http_request = false;

  if (window.XMLHttpRequest) {
    http_request = new XMLHttpRequest();

  } else if (window.ActiveXObject) {
    try {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
    }
  }

  if (!http_request) {
    alert('Giving up :( Cannot create an XMLHTTP instance');
    return false;
  }

  http_request.onreadystatechange = function() { domain_st(http_request); };
  http_request.open('POST','domain_check.php', true);
  http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  http_request.send('domain='+obj.value);
	document.getElementById('domain_status').innerHTML = '';	 
}
function domain_st(http_request) {
 if (http_request.readyState == 4) {
   if (http_request.status == 200) {
		var ret = http_request.responseText;

		document.getElementById('domain_status').innerHTML = '';

		if(ret == 0 || ret == 1) {
			document.getElementById('submit').disabled = false;
		} else if (ret == -1) {
			document.getElementById('domain_status').innerHTML = 'Домен не найден. Сперва домен нужно создать в панели управления.';
		} else {
			document.getElementById('domain_status').innerHTML = ret;
		}


   } else {
    alert('There was a problem with the request.');
   }
 }
}
function bill_step2_back(ptype) {
	var req = 'action=step2back&paytype='+ptype;
	makeRequestPost('bill_op.php',req,'pay');
}


function bill_step3() {

	var paytype = 'hosting';
	var pt_o = document.getElementById('ptype');

	if(pt_o != null)
		paytype = pt_o.options[pt_o.selectedIndex].value;

	var req = 'action=step3&paytype='+paytype;
	makeRequestPost('bill_op.php',req,'pay');

}

function bill_period(obj) {

	var rate = document.getElementById('rate').value;
	var price = rate;
	var period = 1;

	if(obj != null)
		period = obj.options[obj.selectedIndex].value;

	document.getElementById('price').innerHTML = rate*period;	 
}
function bill_genbill() {

	var price = '';
	var p_o = document.getElementById('price');
	if(p_o != null) {
		if(p_o.value == undefined) {
			price = document.getElementById('price').innerHTML;
		} else {
			price = p_o.value;
		}
	}
	makeRequestPost('bill_op.php','action=genbill&price='+price,'pay');
}
