function showLogin(action,type) {
advAJAX.get({
    url: "ajaxLogin.php",
    parameters : {
      "action" : action,
      "type" : type
    },
    onSuccess : goLogin,
    onError : errorLogin
});
}

function checkLogin(action,type) {
advAJAX.get({
    url: "ajaxLogin.php",
    parameters : {
      "action" 		: action,
      "login"       : getId('nick').value,
      "password"    : getId('password').value,
      "type"	    : type
    },
    onSuccess : goLogin,
    onError : errorLogin
});
}


function goLogin(obj) {
  if (obj.responseText == "1" || obj.responseText == "2") {
     closeLogin();
	if( obj.responseText == "1")   		document.getElementById("commentForm").submit();
	else if( obj.responseText == "2")   document.getElementById("commentVotes").submit();
  } else {
     document.getElementById("blogRegister").style.display = "inline";
     document.getElementById("blogRegisterMid").innerHTML = obj.responseText;
     centerBox(getId("blogRegister"));
  }
}


function errorLogin(obj) {
     document.getElementById("blogRegister").style.display = "none";
     alert("Nie można nawiązać połączenia!");
}

function getId(id) {
//  if( !document.getElementById(id) )
//      return '';
    return document.getElementById(id);
}



function checkRegister(action, type) {
advAJAX.get({
    url: "ajaxLogin.php",
    parameters : {
      "action" 		: action,
      "login"       : getId('nick').value,
      "email"	    : getId('email').value,
      "pass1"	    : getId('pass1').value,
      "pass2"	    : getId('pass2').value,
      "type"	    : type
    },
    onSuccess : goLogin,
    onError : errorLogin
});
}


function closeLogin() {
  document.getElementById("blogRegister").style.display = "none";
}

function voteOnComment( id, vote )
{
    document.getElementById('idc').value 	= id;
    document.getElementById('vote').value 	= vote;
    showLogin('vote', 'login');
}



function centerBox(obj) {
    obj.style.marginTop = parseInt(js_getScrollY() - (obj.offsetHeight / 2)) + "px";
}

function js_getScrollY () {
    if (document.body && document.body.scrollTop) /* DOM */
      return document.body.scrollTop;
    else if (document.documentElement && document.documentElement.scrollTop) /* IE */
      return document.documentElement.scrollTop;
    return 0;
}

   