var id_post_curent = "";
var html_div_curent = "";

function ArataInputSL(id) {
	if (id_post_curent != "" ) { AscundeInputSL(); }
	id_post_curent = id;
	html_div_curent = document.getElementById('spanModSL_' + id).innerHTML;	
	document.getElementById('spanModSL_' + id).innerHTML = '<input name="input_text_sl" type="text" id="input_text_sl" /><input name="boton_sl_trimite_input" type="button" value="Rate" onclick="TrimiteInputAjax()" /><input name="boton_sl_ascunde_input" type="button"  value="Cancel" onclick="AscundeInputSL()"/>';	
}

function AscundeInputSL() {
	document.getElementById('spanModSL_' + id_post_curent).innerHTML = html_div_curent;
	id_post_curent = "";
}

function TrimiteInputAjax() {
	inputValue = document.getElementById('input_text_sl').value;
		ObiectTrimiteInputSL = function() {
		this.OnSuccess = function() {
			text_primit = this.GetResponseText();
			var RezultatSplit = text_primit.split("|");			
			if (RezultatSplit[0] == "eroare") {				
				alert(RezultatSplit[1]);
			} else {				
				document.getElementById('divModSL_' + id_post_curent).innerHTML = '<br/><span id="spanNrVoturi_' + id_post_curent + '">' + RezultatSplit[1] + ' points / ' + RezultatSplit[2] + ' votes</span>';
				id_post_curent = "";
				html_div_curent = "";
			}			
		}
		this.GetData = function() {
			this.InitializeRequest('GET', '/ajax_salveaza_input.php?actiune=adauga&postId='+id_post_curent+'&puncte='+encodeURIComponent(inputValue)+'&random=' + Math.random());
			this.Commit(null);
		}
	}
	ObiectTrimiteInputSL.prototype = new ajax();
	ObiectTrimiteInputSLAjax = new ObiectTrimiteInputSL();		
	ObiectTrimiteInputSLAjax.GetData();
}

function ReseteazaPuncteSL(postId) {
		ObiectReseteazaPuncteSL = function() {
		this.OnSuccess = function() {
			text_primit = this.GetResponseText();
			var RezultatSplit = text_primit.split("|");			
			if (RezultatSplit[0] == "eroare") {				
				alert(RezultatSplit[1]);
			} else {				
				document.getElementById('divModSL_' + postId).innerHTML = '<br/><span id="spanNrVoturi_' + postId + '">0.0 points / 0 votes</span>';
				id_post_curent = "";
				html_div_curent = "";
			}			
		}
		this.GetData = function() {
			this.InitializeRequest('GET', '/ajax_salveaza_input.php?actiune=sterge&postId=' + postId + '&random=' + Math.random());
			this.Commit(null);
		}
	}
	ObiectReseteazaPuncteSL.prototype = new ajax();
	ObiectReseteazaPuncteSLAjax = new ObiectReseteazaPuncteSL();		
	ObiectReseteazaPuncteSLAjax.GetData();
}

function ArataDivKeywordsDescriereSL () {
	document.getElementById('ModKeysDescSL').style.display = "none";
	document.getElementById('KeywordsDescriereSL').style.display = "block";
	
}

function SalveazaKeywordsDescriereSL(topicId) {
	keywords = encodeURIComponent(document.getElementById('keywordsModSL').value);
	descriere = encodeURIComponent(document.getElementById('descriereModSL').value);
	ObiectKeywordsDescriereSL = function() {
		this.OnSuccess = function() {
			text_primit = this.GetResponseText();
			var RezultatSplit = text_primit.split("|");			
			if (RezultatSplit[0] == "eroare") {	
				alert(RezultatSplit[1]); 
			} else {
				document.getElementById('ModKeysDescSL').style.display = "block";
				document.getElementById('KeywordsDescriereSL').style.display = "none";
			}
		}
		this.GetData = function() {
			this.InitializeRequest('GET', '/ajax_salveaza_input.php?actiune=skey&topicId=' + topicId + '&keywords=' + keywords + '&descriere=' + descriere + '&random=' + Math.random());
			
			this.Commit(null);
		}
	}
	ObiectKeywordsDescriereSL.prototype = new ajax();
	ObiectKeywordsDescriereSLAjax = new ObiectKeywordsDescriereSL();		
	ObiectKeywordsDescriereSLAjax.GetData();
}



function SalveazaKeywordsDescriereForumSL(forumId) {
	keywords = encodeURIComponent(document.getElementById('keywordsModSL').value);
	descriere = encodeURIComponent(document.getElementById('descriereModSL').value);
	ObiectKeywordsDescriereForumSL = function() {
		this.OnSuccess = function() {
			text_primit = this.GetResponseText();
			var RezultatSplit = text_primit.split("|");			
			if (RezultatSplit[0] == "eroare") {	
				alert(RezultatSplit[1]); 
			} else {
				document.getElementById('ModKeysDescSL').style.display = "block";
				document.getElementById('KeywordsDescriereSL').style.display = "none";
			}
		}
		this.GetData = function() {
			this.InitializeRequest('GET', '/ajax_salveaza_input.php?actiune=skeyForum&forumId=' + forumId + '&keywords=' + keywords + '&descriere=' + descriere + '&random=' + Math.random());
			
			this.Commit(null);
		}
	}
	ObiectKeywordsDescriereForumSL.prototype = new ajax();
	OObiectKeywordsDescriereForumSLAjax = new ObiectKeywordsDescriereForumSL();		
	OObiectKeywordsDescriereForumSLAjax.GetData();
}
