
function goAction(form) {

	if(form.username.value == '' || form.password.value == '') {
		alert('Введите логин, пароль.'); return false;
	}
	form.action = "http://cp.hostfabrica.ru";
	if(form.ssl.checked) {
		form.action = "https://cp.hostfabrica.ru";
		form.submit();
	}
}
function makeRequestPost(url,query,id) {

  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() { setContents(http_request, id); };
  http_request.open('POST', url, true);
  http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  http_request.send(query);

}
function makeRequest(url, id) {

  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() { setContents(http_request, id); };
	document.getElementById(id).style.cursor = "wait";
  http_request.open('GET', url, true);
	http_request.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
  http_request.send(null);

}

function setContents(http_request, id) {

	if(document.getElementById(id) == null) return;

  if (http_request.readyState == 4) {
    if (http_request.status == 200) {
      document.getElementById(id).value = http_request.responseText;
      document.getElementById(id).innerHTML = http_request.responseText;
			document.getElementById(id).style.cursor = "default";
    } else {
      alert('There was a problem with the request.');
    }
  }

}
function gohome() {
	location.href = "/";
}
function openWin(file, w, h) {

    var x = screen.availWidth;
    var y = screen.availHeight;

    if(w == null) w = x;
    if(h == null) h = y;

    win = open(file,"win","width="+w+",height="+h+",location=no,status=no,toolbar=no,menubar=no,scrollbars=yes,left="+(x-w)/2+",top="+(y-h)/2);
}


function openFullWin(file) {

  var x = screen.availWidth;
  var y = screen.availHeight;

  win = open(file,"open","width="+x+",height="+y+",location=no,status=no,toolbar=no,menubar=no,scrollbars=yes,left=0,top=0");

}

function this_plan(id) {
	makeRequest('this_plan.php?id='+id, 'this_plan');
}

function mail_enter() {
	
  var email = document.getElementById('email').value;
  var password = document.getElementById('mpassword').value;
	var a = email.split('@');
	var imapuser = encodeURIComponent(a[1]+'+'+a[0]);	
	
	var req = 'http://webmail.hostfabrica.ru/imp/redirect.php?server_key=imap&autologin=0&load_frameset=1&imapuser='+imapuser+'&pass='+password+'&loginButton=Вход';
	openFullWin(req);
}
function mail_enter2() {
  var mapp = document.getElementById('mapp').value;
  var email = document.getElementById('email').value;
  var password = document.getElementById('mpassword').value;

	if(mapp == 'hostfabrica') {
	  var browser=navigator.appName;
  	if(browser.indexOf('Microsoft Internet Explorer') != -1) {
    	alert('Браузер Microsoft Internet Explorer не умеет работать с этим почтовым приложением.\nИспользуйте другой современный браузер - Mozilla Firefox, Google Chrome, Opera.');
    	return false;
  	}
		document.mailf.submit();
	} else if(mapp == 'horde') {
		var a = email.split('@');
		var imapuser = encodeURIComponent(a[1]+'+'+a[0]);	
		var req = 'http://webmail.hostfabrica.ru/imp/redirect.php?server_key=imap&autologin=0&load_frameset=1&imapuser='+imapuser+'&pass='+password+'&loginButton=Вход';
		openFullWin(req);
	}

}

function whois_check() {

  var cdomain = document.getElementById('cdomain').value;
	if(cdomain == '') { 
		alert('Введите имя домена.') ; return; 
	}

	var a = cdomain.split('.');
	if(a[0] == cdomain) { alert('Введите имя домена.') ; return; } 
	re =  /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;

	tld = a[a.length-1]

	if(a[0].length < 3 && tld != "aero") {
		alert('Недопустимое имя домена. Первая часть имени домена не может быть меньше 3 символов.');
		return;
	}
//  if(!re.test(a[0]) && a.length == 2) { alert('Недопустимые символы в имени домена!') ; return; }

	var w = 200;
	var h = 400;
  var x = screen.availWidth;
  var y = screen.availHeight;

	document.getElementById("whois").style.width = w;
	document.getElementById("whois").style.display = "block";
	document.getElementById("whois").innerHTML = "Проверка ...";

	new JSWindow(cdomain, document.getElementById("whois"), (x-w)/2, (y-h)/2, w);

	var req = 'domain='+cdomain;

	makeRequestPost('whois.php',req,'whois');
	document.getElementById('cdomain').value = '';
}

function partner_reg() {

  var name1 = document.getElementById('name1').value;
  var name2 = document.getElementById('name2').value;
  var name3 = document.getElementById('name3').value;
  var phone = document.getElementById('phone').value;
  var email = document.getElementById('email').value;

	if(name1 == '' || name2 == '' || name3 == '' || email == '' || phone == '') {
		alert('Нужно заполнить все поля формы.'); return;
	}
	document.getElementById("regdone").style.display = "block";
	var req = 'action=reg&name1='+name1+'&name2='+name2+'&name3='+name3+'&phone='+phone+'&email='+email;
	makeRequestPost('partner_op.php',req,'regdone');
  document.getElementById('name1').value = '';
  document.getElementById('name2').value = '';
  document.getElementById('name3').value = '';
  document.getElementById('email').value = '';
  document.getElementById('phone').value = '';
}

function is_numeric(sText) {
  var ValidChars = "0123456789.";
  var IsNumber=true;
  var Char;
  for (i = 0; i < sText.length && IsNumber == true; i++) { 
    Char = sText.charAt(i); 
    if (ValidChars.indexOf(Char) == -1) {
      IsNumber = false;
    }
  }
  return IsNumber;   
}
