var xmlhttp;

if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
{
  try { xmlhttp = new XMLHttpRequest (); }
  catch (e) { xmlhttp = false; }
}

function myXMLHttpRequest ()
{
  var xmlhttplocal;
  try { xmlhttplocal = new ActiveXObject ("Msxml2.XMLHTTP"); }
  catch (e) {
  	try { xmlhttplocal = new ActiveXObject ("Microsoft.XMLHTTP"); }
  	catch (E) { xmlhttplocal = false; }
  }
  if (!xmlhttplocal && typeof XMLHttpRequest != 'undefined') 
  {
    try { var xmlhttplocal = new XMLHttpRequest (); }
    catch (e) { var xmlhttplocal = false; }
  }
  return (xmlhttplocal);
}

var mnmxmlhttp = Array ();
var mnmString = Array ();
var mnmPrevColor = Array ();
var responsestring = Array ();
var myxmlhttp = Array ();
var responseString = new String;


function voteit(id, value)
{
  if (xmlhttp)
  {
    url = "voteit.php";
    var content = "id=" + id + "&value=" + value;
    mnmxmlhttp[id] = new myXMLHttpRequest();
    if (mnmxmlhttp)
    {
      mnmxmlhttp[id].open ("POST", url, true);
      mnmxmlhttp[id].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');

      mnmxmlhttp[id].send (content);
      errormatch = new RegExp ("^ERROR:");

      mnmxmlhttp[id].onreadystatechange = function () {
        if (mnmxmlhttp[id].readyState == 4) {
          mnmString[id] = mnmxmlhttp[id].responseText;
          if (mnmString[id].match(errormatch)) {
            changemnmvalues(id, true);
          } else {
            setCookie("v_"+id, 1, 60);
            changemnmvalues(id, false);
          }
        }
      }
    }
  }
}

function changemnmvalues(id, error)
{
	split = new RegExp ("~--~");
	b = mnmString[id].split (split);
	target1 = document.getElementById ('mnms-' + id);
	target1.className = "star-rating-noh";
	if (error) {
		return false;
	}
	if (b.length <= 3) {
		target1.innerHTML = b[2];
	}
	return false;
}


function setCookie(c_name,value,expiredays)
{
  var exdate=new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  document.cookie = c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
  if (document.cookie.length>0)
  {
    c_start = document.cookie.indexOf(c_name + "=");
    if (c_start!=-1)
    { 
      c_start = c_start + c_name.length+1; 
      c_end = document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end = document.cookie.length;
      return unescape(document.cookie.substring(c_start,c_end));
    }
  }
  return "";
}
