
function registration() {

un = document.getElementById("username-r").value;
    ps = document.getElementById("password-r").value;
	reps = document.getElementById("repassword-r").value;
	e = document.getElementById("email-r").value;
	c = document.getElementById("registration-code-r").value;
	d = encodeURIComponent(document.getElementById("day").value);
	m = encodeURIComponent(document.getElementById("month").value);
	y = encodeURIComponent(document.getElementById("year").value);
	g = encodeURIComponent(document.getElementById("gender").value);
	
	document.getElementById("login-text").innerHTML = 'логин';
	document.getElementById("password-text").innerHTML = 'пароль - дважды';
	document.getElementById("email-text").innerHTML = 'e-mail';
	document.getElementById("code-text").innerHTML = 'код';
   document.getElementById("error-registration-text").innerHTML = '<i>Пожалуйста, подождите</i>';
    

	
    // execute the quickstart.php page from the server
    
      var url = "/xml/registration.php";
var params = "username=" + un + "&password=" + ps + "&repassword=" + reps + "&email=" + e + "&code=" + c + "&day=" + d + "&month=" + m + "&year=" + y + "&gender=" + g;
xmlHttp.open("POST", url, true);

//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");


    // define the method to handle server responses
    xmlHttp.onreadystatechange = handleServerResponseRegistration;
    // make the server request
    xmlHttp.send(params);
}
function handleServerResponseRegistration() 
{
  // move forward only if the transaction has completed
  if (xmlHttp.readyState == 4) 
  {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
      // extract the XML retrieved from the server
      xmlResponse = xmlHttp.responseXML;
      // obtain the document element (the root element) of the XML structure
      
       xmlRoot = xmlResponse.documentElement;  
      
      error = xmlRoot.getElementsByTagName("error");
	  if(error.length > 0) {
	    document.getElementById("error-registration-text").innerHTML = '';
        for (var i=0; i < error.length; i++) {
		    if(error.item(i).firstChild.data == 0) document.getElementById("login-text").innerHTML = 'логин <span style="color: red">такой логин уже зарегистрирован</span>';
            if(error.item(i).firstChild.data == 1) document.getElementById("login-text").innerHTML = 'логин <span style="color: red">слишком короткий логин</span>';
            if(error.item(i).firstChild.data == 2) document.getElementById("password-text").innerHTML = 'пароль <span style="color: red">слишком короткий пароль: минимум 4 символа</span>';
		    if(error.item(i).firstChild.data == 3) document.getElementById("password-text").innerHTML = 'пароль <span style="color: red">пароль и его подтверждение не совпадают</span>';
		    if(error.item(i).firstChild.data == 4) document.getElementById("email-text").innerHTML = 'e-mail <span style="color: red">e-mail набран неправильно</span>';
		    if(error.item(i).firstChild.data == 5) document.getElementById("code-text").innerHTML = 'код <span style="color: red">неправильно указан код с картинки</span>';
		 if(error.item(i).firstChild.data == 6) document.getElementById("email-text").innerHTML = 'e-mail <span style="color: red">пользователь с этим e-mail уже есть</span>';
		   
		}
	} else {
	document.getElementById("error-registration-text").innerHTML = '';
	    document.getElementById("reg-content").innerHTML = '<div style="padding: 10px;color: #666;   -moz-border-radius: 5px; background: #fbf9be; margin: 10px 0; font-size: 11px;border: 1px dotted #ccc;">Регистрация почти завершена. На ваш электронный ящик выслано письмо с подтверждением вашего почтового адреса.</div>';
	}

	 
	
	  
	 
	
	  
      
      // restart sequence
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}
function ctrlEnter(event)
    {
    if((event.ctrlKey) && ((event.keyCode == 0xA)||(event.keyCode == 0xD)))
        {
        addcomment();
        }
    }
	

