// JScript File
// Page functions
// Globals
var MAX_LENGTH=300;
// Functions
function checkMaxLength(o,el)
{
var txt = o.value;
if (txt.length > el)
{
txt = txt.substr(0, el);
o.value = txt;
}
updateCount();
}
function submit()
{
var cat = document.getElementById("cmbCategory").value;
if (cat == "-1")
{
alert("נא לבחור קטגוריה");
document.getElementById("cmbCategory").focus();
return;
}
var desc = document.getElementById("txtDesc").value;
if (desc.length == 0)
{
alert("נא למלא תיאור");
document.getElementById("txtDesc").focus();
return;
}
var username = document.getElementById("txtUsername").value;
if (desc.length == 0)
{
alert("נא למלא שם");
document.getElementById("txtUsername").focus();
return;
}
var email = document.getElementById('txtEmail').value;
var notify = email.length > 0 && document.getElementById('chkEmailNotify').checked;
if (!notify)
{
email = '';
}
desc = desc.replace(/"/gi, '`');
desc = desc.replace(/'/gi, '`');
var q = "username=" + username + "&category=" + cat + "&story=" + desc + "¬ify=" + notify + "&email=" + email;
getXmlHttp("POST", "/Service.asmx/SubmitStory", q, callbackSubmit);
}
function callbackSubmit(xmlhttp)
{
if (xmlhttp.readyState!=4)
{
return;
}
var xmlDoc = loadxml(xmlhttp.responseText);
try
{
info=xmlDoc.documentElement.childNodes;
succ=xmlDoc.getElementsByTagName("Success")[0].childNodes[0].nodeValue;
msg=xmlDoc.getElementsByTagName("Message")[0].childNodes[0].nodeValue;
if (succ=="true")
{
hideDiv("divAdd");
alert(msg);
}
else
{
alert(msg);
}
}
catch (e)
{
alert(xmlhttp.responseText);;
}
}
function updateCount()
{
var txt = document.getElementById("txtDesc").value;
document.getElementById("tdCounter").innerHTML = MAX_LENGTH - txt.length;
var txt2 = document.getElementById("txtComment").value;
document.getElementById("tdCounterComment").innerHTML = MAX_LENGTH - txt2.length;
}
function showComment()
{
var un = myDecode(readCookie("username"));
if (un != null)
{
document.getElementById("txtUsernameComment").value = un;
}
hideDiv("spanAddComment");
showDiv("divAddComment");
}
function checkEmail()
{
if (document.getElementById('txtEmail').value.length > 0)
{
document.getElementById('chkEmailNotify').checked = true;
}
}
function showAdd()
{
document.getElementById('txtDesc').value = "היום ... החיים שלי בזבל";
if (document.getElementById('txtUsername').value.length == 0)
{
username=myDecode(readCookie('username'));
if (username != null)
{
document.getElementById('txtUsername').value = username;
}
}
email=myDecode(readCookie('email'));
if (email != null && email.length > 0)
{
document.getElementById('txtEmail').value = email;
document.getElementById('chkEmailNotify').checked = true;
}
else
{
document.getElementById('chkEmailNotify').checked = false;
}
showDiv('divAdd');
}
function KeepData(cookiename, fieldname)
{
var v = document.getElementById(fieldname).value;
if (v != null && v.length > 0)
{
createCookie(cookiename, myEncode(v), 365);
}
else
{
eraseCookie(cookiename);
}
}
function conditionalVote(fmlId, lik, dislik)
{
var votes = readCookie("votes");
if (votes == null)
{
votes = ".";
}
if (votes.indexOf("." + fmlId + ".") == -1)
{
document.write("" + lik + " זבל משובח ");
document.write("" + dislik + " סתם זבל ");
}
else
{
document.write(lik + " זבל משובח ");
document.write(dislik + " סתם זבל ");
}
}
function conditionalFB(id)
{
document.write('שתף ');
}
function track(id, type)
{
var email = "";
var username = myDecode(readCookie('username'));
if (username == null)
{
username = "";
}
username = username.replace(/"/gi, '`');
username = username.replace(/'/gi, '`');
var senderEmail = myDecode(readCookie('email'));
if (senderEmail == null)
{
senderEmail = "";
}
if (username.length > 0 || senderEmail.length > 0)
{
var q = "senderemail=" +senderEmail + "&username=" + username + "&recipientEmail=" + email + "&secret=&story=" + id + "&type=" + type;
getXmlHttp("POST", "/Service.asmx/Track", q, null);
}
return true;
}
function JustVotes(fmlId, lik, dislik)
{
var q = lik + " זבל משובח " + dislik + " סתם זבל ";
document.getElementById('spanButtons' + fmlId).innerHTML = q;
}
function showSendToFriend(id)
{
var re = myDecode(readCookie("recipientEmail"));
if (re != null)
{
document.getElementById('txtEmailRecipient' + id).value = re;
}
var un = myDecode(readCookie("username"));
if (un != null)
{
document.getElementById('txtUsername' + id).value = un;
}
showDiv('divSendToFriend' + id);
}
function SendToFriend(fmlId)
{
var email = document.getElementById('txtEmailRecipient' + fmlId).value;
if (email == null || email.length == 0)
{
alert("נא להכניס כתובת אימייל למשלוח");
document.getElementById('txtEmailRecipient' + fmlId).focus();
return;
}
var username = document.getElementById('txtUsername' + fmlId).value;
if (username == null || username.length == 0)
{
alert("נא להכניס את שמך");
document.getElementById('txtUsername' + fmlId).focus();
return;
}
username = username.replace(/"/gi, '`');
username = username.replace(/'/gi, '`');
var senderEmail = myDecode(readCookie('email'));
if (senderEmail == null)
{
senderEmail = "";
}
var q = "senderemail=" +senderEmail + "&username=" + username + "&recipientEmail=" + email + "&storyId=" + fmlId;
getXmlHttp("POST", "/Service.asmx/SendToFriend", q, callbackSendToFriend);
}
function submitComment()
{
var username = document.getElementById('txtUsernameComment').value;
if (username == null || username.length == 0)
{
username="אנונימי";
}
var comment = document.getElementById('txtComment').value;
if (comment == null || comment.length == 0)
{
alert("נא למלא תגובה");
comment = document.getElementById('txtComment').focus();
return;
}
username = username.replace(/"/gi, '`');
username = username.replace(/'/gi, '`');
comment = comment.replace(/"/gi, '`');
comment = comment.replace(/'/gi, '`');
var fmlId = querySt("story");
if (fmlId == null)
{
alert('החיים בזבל - שגיאה פנימית');
return;
}
var q = "fmlId=" + fmlId + "&username=" + username + "&comment=" + comment;
getXmlHttp("POST", "/Service.asmx/AddComment", q, callbackSubmitComment);
}
function DeleteComment(id, cookie)
{
var q = "commentUid=" + id + "&cookie=" + cookie;
getXmlHttp("POST", "/Service.asmx/DeleteComment", q, callbackSubmitComment);
}
function callbackSubmitComment(xmlhttp)
{
if (xmlhttp.readyState!=4)
{
return;
}
// actually - currently we do nothing with the vote
var xmlDoc = loadxml(xmlhttp.responseText);
try
{
info=xmlDoc.documentElement.childNodes;
succ=xmlDoc.getElementsByTagName("Success")[0].childNodes[0].nodeValue;
if (succ=="true")
{
hideDiv('divAddComment');
showDiv('spanAddComment');
alert("תגובתך נתקבלה");
window.location = window.location;
}
else
{
msg=xmlDoc.getElementsByTagName("Message")[0].childNodes[0].nodeValue;
alert(msg);
}
}
catch (e)
{
alert(xmlhttp.responseText);;
}
}
function vote(fmlId, lik, dislik, v)
{
if (v == 1)
{
lik = lik + 1;
}
else
{
dislik = dislik + 1;
}
JustVotes(fmlId, lik, dislik);
var votes = readCookie("votes");
if (votes == null)
{
votes = ".";
}
votes = "." + fmlId + votes;
if (votes.length > 1024)
{
votes = votes.substring (0, 1024);
}
createCookie("votes", votes, 365);
var q = "fmlId=" + fmlId + "&v=" + v;
getXmlHttp("POST", "/Service.asmx/Vote", q, callbackVote);
}
function filterVote(fmlId, v)
{
var votes = readCookie("votes");
if (votes == null)
{
votes = ".";
}
votes = "." + fmlId + votes;
if (votes.length > 1024)
{
votes = votes.substring (0, 1024);
}
createCookie("votes", votes, 365);
var q = "fmlId=" + fmlId + "&v=" + v;
getXmlHttp("POST", "/Service.asmx/Vote", q, callbackFilterVote);
}
function callbackSendToFriend(xmlhttp)
{
if (xmlhttp.readyState!=4)
{
return;
}
// actually - currently we do nothing with the vote
var xmlDoc = loadxml(xmlhttp.responseText);
try
{
info=xmlDoc.documentElement.childNodes;
succ=xmlDoc.getElementsByTagName("Success")[0].childNodes[0].nodeValue;
msg=xmlDoc.getElementsByTagName("Message")[0].childNodes[0].nodeValue;
if (succ=="true")
{
hideDiv("divSendToFriend" + msg);
alert("הסיפור נשלח");
}
else
{
alert(msg);
}
}
catch (e)
{
alert(xmlhttp.responseText);;
}
}
function callbackVote(xmlhttp)
{
if (xmlhttp.readyState!=4)
{
return;
}
// actually - currently we do nothing with the vote
var xmlDoc = loadxml(xmlhttp.responseText);
if (xmlDoc != null)
{
return;
}
try
{
info=xmlDoc.documentElement.childNodes;
succ=xmlDoc.getElementsByTagName("Success")[0].childNodes[0].nodeValue;
msg=xmlDoc.getElementsByTagName("Message")[0].childNodes[0].nodeValue;
if (succ=="true")
{
}
else
{
}
}
catch (e)
{
alert(xmlhttp.responseText);;
}
}
function callbackFilterVote(xmlhttp)
{
if (xmlhttp.readyState!=4)
{
return;
}
window.location = window.location;
}
function gotoHomepage(id, src, pre)
{
if (src == null)
{
src = "none";
}
if (pre == null)
{
pre = "./";
}
if (id == null || id == 0)
{
window.location=pre + "Default.aspx?ref=" + src;
}
else
{
window.location=pre + "LeaderBoard.aspx?ref=" + src;
}
}
function doSearch(type)
{
var s = document.getElementById("txtSearch").value;
if (s.length == 0)
{
return;
}
if (type == null)
{
type = 0;
}
createCookie("search", myEncode(s, 'd'), 0);
window.location="./Search.aspx?type=" + type + "&search=" + myEncode(s, 'd');
}
function onload()
{
}