
function vote_up(id) {
 $.ajax({
  type: "POST",
  url: "/vot_up.php",
  data: "id="+id,
  success: function(msg){
    vot_result="vot_result"+id;
    document.getElementById(vot_result).innerHTML=msg;
   //alert( "Data Saved: " + msg );
  }
 });
}

function vote_down(id) {
 $.ajax({
  type: "POST",
  url: "/vot_down.php",
  data: "id="+id,
  success: function(msg){
    vot_result="vot_result"+id;
    document.getElementById(vot_result).innerHTML=msg;
   //alert( "Data Saved: " + msg );
  }
 });
}

function login() {
// alert("Stop");
var username = $("input#username").val();
var password = $("input#password").val();
var remember_me = $("#remember_me:checked").val();
//alert(password);
//alert(remember_me);
 $.ajax({
  type: "POST",
  url: "/login.php",
  data:{username:username,password:password,remember_me:remember_me},
  success: function(msg){
   //document.getElementById(menu_user).innerHTML=msg;
//    alert( "Data Saved: " + msg );

//   $("fieldset#signin_menu").hide();
// password_incorect="password_incorect";
var response = eval("(" + msg + ")");

if (response.auth !=1){
  document.getElementById("password_incorect").innerHTML="Username/password incorrect";
  document.forms["signin"].password.value="";
}else{
  window.location.reload();
//  alert("aici");
  $("fieldset#signin_menu").hide();
  
  document.getElementById("menu_user").innerHTML=response.info;

}
  }
 });
}

function comments_remove(id)
{
var txt = 'Are you sure you want to remove this comment?<input type="hidden" id="comments_id" name="comments_id" value="'+ id +'" />';

$.prompt(txt,{ 
					buttons:{Delete:true, Cancel:false},
					callback: function(v,m,f){
						
						if(v){
							var uid = f.comments_id;
							  $.post('/comments_remove.php', {comments_id: f.comments_id}, function(msg){
							  
							  var response = eval("(" + msg + ")");
 							    if (response.cd == 1){
							     window.location.reload();
							    }else{
							      $.prompt('An Error Occured while removing this comment');
							    }
							  });
						}
						else{}
						
					}
				});

}

function comments_report(id)
{
var txt = 'Are you sure you want to report this comment?<input type="hidden" id="comments_id" name="comments_id" value="'+ id +'" />';

$.prompt(txt,{ 
					buttons:{Report:true, Cancel:false},
					callback: function(v,m,f){
						
						if(v){
							var uid = f.comments_id;
							  $.post('/comments_report.php', {comments_id: f.comments_id}, function(msg){
							  
							  var response = eval("(" + msg + ")");
//  							    if (response.cr == 1){
// 							     $.prompt('This comment was reported');
// 							    }else{
// 							      $.prompt('An Error Occured while removing this comment');
// 							    }
							  });
  							    

						}
						else{}
						
					}
				});

}


//limit no of new lines in textarea
function limitLines(obj, e) {
	var val = obj.value;
	var lines = 0;
	if(val.match(/\n/g))
		lines = val.match(/\n/g).length;

	// IE
	if(window.event) {
		keynum = e.keyCode;
	// Netscape/Firefox/Opera
	} else if(e.which) {
		keynum = e.which;
	}

	document.getElementById("desccharsleft").innerHTML = 350 - obj.value.length;

	if(keynum != 13) //if != enter
		return true;
	else if(lines >= 5)
		return false;	

}

