function ForumPridaj() {
Meno = document.getElementsByName('Meno')[0].value;
if (Meno == "meno") {Meno = "";}
Obsah = document.getElementsByName('Obsah')[0].value;
Adresa = document.getElementsByName('Adresa')[0].value;

if (Obsah != "" && Obsah != "text") { 
 if (window.ForumObrazok == false) {	//ak nebol urceny obrazok na upload, pridam text priamo 
  PridajText('');
 } else {				//inak zavolam funkciu na upload, ktora zavola PridajText()
  document.getElementById('Progress').innerHTML='Pridávam obrázok...';
  $('#uploadify').uploadifyUpload();
 };
 return false;  
} else {
 alert('Napíš text.');
 document.getElementsByName('Obsah')[0].focus();
 return false; 
};

}


function PridajText(ObrazokNazov) {
document.getElementById('Progress').innerHTML='Pridávam záznam...';
Obsah = EncodeForumDescription(Obsah);
Adresa = EncodeForumAdresa(Adresa);
$.post("forum-pridaj-zaznam.php",
{
Meno: Meno,
Obsah: Obsah,
Adresa: Adresa,
ObrazokNazov: ObrazokNazov
},
function(Odpoved){ $('#Main').load("forum.php?Link="+Math.floor(Math.random()*1001)); }
);
}


function AddSmiley(Ktory) {
document.getElementsByName('Obsah')[0].value = document.getElementsByName('Obsah')[0].value+Ktory;
document.getElementsByName('Obsah')[0].focus();
}

function CheckPic(field) {
entry = document.getElementsByName(field)[0].value;
entry = entry.toLowerCase();	//all letters -> lowercase
if (entry != "" && entry.slice(entry.length-4, entry.length) != ".jpg" && entry.slice(entry.length-4, entry.length) != ".jpe" && entry.slice(entry.length-5, entry.length) != ".jpeg") {
 alert("Obrázok musí byť súbor typu jpe, jpg alebo jpeg");
 document.getElementsByName(field)[0].value = "";
 document.getElementsByName(field)[0].focus();
 return false;
};
}

		//format Description value from custom to html
function EncodeForumDescription(entry) {
for (i = 0; i < entry.length; i++) {
 entry = entry.replace(/\n/, "<br>");	//replace \n (new line character) with <br>
 entry = entry.replace(/\r/, "");	//don't allow line breaks (wagenruecklauf)
 entry = entry.replace(/^ /, "");	//don't allow empty spaces at description beginning -> no empty lines
 entry = entry.replace(/ $/, "");	//don't allow empty spaces at description end -> no empty lines
 entry = entry.replace(/^<br>/, "");	//don't allow empty lines at description beginning
 entry = entry.replace(/<br>$/, "");	//don't allow empty lines at description end
};
return entry;
}

function EncodeForumAdresa(entry) {
if (entry != "email / www adresa" && entry != "http://" && entry != "") {
 if (entry.search(/http:\/\//) == -1) { entry = "http://"+entry; };
 if (entry.search('@') != -1) { entry = entry.replace('http://', ""); entry = "mailto:"+entry; }; 
 entry = "<a href='"+entry+"' target='new'>"+entry.replace(/http:\/\//, "").replace('mailto:', '')+"</a>";
} else {
 entry = "";
}
return entry;
}

