Simple status box for the sidebar.
[elgg_plugins.git] / ratings / ratings.js
blob23ef421830d7c364c267285cde7b1125a70199fd
1 function ratings_showhide(oid)
3 var e = document.getElementById(oid);
4 if(e.style.display == 'none') {
5 e.style.display = 'block';
6 } else {
7 e.style.display = 'none';
10 function ratings_getAjaxObj()
12 var xmlHttp;
14 try
16 // Firefox, Opera 8.0+, Safari
17 xmlHttp=new XMLHttpRequest();
19 catch (e)
21 // Internet Explorer
22 try
24 xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
26 catch (e)
28 try
30 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
32 catch (e)
34 return false;
39 return xmlHttp;
42 function ratings_alertContents()
44 if (http_Request.readyState == 4) {
45 if (http_Request.status == 200) {
47 result = http_Request.responseXML;
48 message = result.getElementsByTagName('message')[0];
50 error = result.getElementsByTagName('error')[0];
51 if (error.textContent == '0') {
52 success = true;
55 if (success == true)
57 document.getElementById('ratings_ajaxmessages_' + objectid).innerHTML = '<a href="">' + message.textContent + '</a>';
58 document.getElementById('ratings_link_' + objectid).innerHTML = '&nbsp;';
60 else
62 document.getElementById('ratings_ajaxmessages_' + objectid).innerHTML = message.textContent;
64 } else {
65 alert('There was a problem with the request.');
70 function ratings_sendcomment(url, formid, oid)
72 var parameters;
73 objectid = oid;
75 http_Request = getAjaxObj();
77 if (http_Request==false)
79 return false;
82 // Construct parameters
83 frm = document.getElementById(formid);
85 parameters = "";
86 for(var i = 0;i < frm.elements.length;i++)
88 element = frm.elements[i];
90 element_value = '';
91 add_element = false;
92 if ((element.type=='radio') || (element.type=='checkbox'))
94 if (element.checked == true)
96 element_value = element.value;
97 add_element = true;
100 else
102 element_value = element.value;
103 add_element = true;
106 if (add_element==true)
108 parameters = parameters + element.name +"=" + encodeURI( element_value ) + "&";
112 // Post result
113 http_Request.onreadystatechange = ratings_alertContents;
114 http_Request.open('POST', url, true);
115 http_Request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
116 http_Request.setRequestHeader("Content-length", parameters.length);
117 http_Request.setRequestHeader("Connection", "close");
118 http_Request.send(parameters);