var ratePosting = {

 int_req_counter : 0,
 int_sync_result : null ,
 _timeoutAdjustment : 1,
 xmlHttp : null,
	
rpc_rate_posting : function () {
	var ar=arguments;
	
	var cb = ar[0];
	var cb_args = ar[1];
	
	var args_bez = new Array();
	args_bez[2] = "ar_n"; 
	args_bez[3] = "ar_v";
	var args = "";
	for ( var j=2; j<=3; j++ ) {
	  for ( var i=0; i<ar[j].length; i++ ) {
		 args += args_bez[j] + i + "=" + ar[j][i] + "&";
	  }
	}
	args += "args_count=" + (ar[2].length+0);
	return this.async_request('rpc_rate_posting',cb,cb_args,args);
},

async_request : function (method,cb,cb_args,args) {
	
	this.int_req_counter++;
	var rc = this.int_req_counter;
	this.int_sync_result = null;
	
	var query = '/jsconnect/rpc/connector.m?rc='+rc+'&'+args;

	xmlHttp = this.getXMLHTTP();
	if(xmlHttp) {
      xmlHttp.open("GET",query,true);
      xmlHttp.onreadystatechange = function() {
        if(xmlHttp.readyState == 4 && xmlHttp.responseText) {
          if(xmlHttp.responseText.charAt(0) == "<") {
            this._timeoutAdjustment--;
          } else {
            // The response text gets executed as javascript... 
            eval(xmlHttp.responseText);
            cb(ratePosting.int_sync_result,cb_args);
          }
        }
      }
      xmlHttp.send(null);
      return 1;
    } else {
      return 0;
    }
    return 0;
}, 

// HELPER

// Was function jb...
// returns an XMLHttp object... gets it in an IE/Mozilla friendly way..
 getXMLHTTP : function () {
  var A = null;
  if(typeof ActiveXObject != "undefined") {
    try {
      A = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {
        A = new ActiveXObject("Microsoft.XMLHTTP");
      } catch(oc){
        A = null;
      }
    }
  }
  if(!A && typeof XMLHttpRequest != "undefined") {
    A = new XMLHttpRequest();
  }
  if(A) {
    return A;
  } else {
    return;
  }
}

// end var ratePosting
}

var hide_bew = 0;
var last_pnr = 0;
function bewertung(pnr,nr,rating,poster) {
 if (pnr != last_pnr) {
  last_pnr = pnr;
  var curr_rating = 0;
  var curr_rating_html = document.getElementById("bewertung_display_" + pnr).innerHTML;
  curr_rating_html = curr_rating_html.toLowerCase(); // IE macht <b> zu <B>
  if      (curr_rating_html.indexOf('fs.gif') > -1) { curr_rating = 1; }
  else if (curr_rating_html.indexOf('fb.gif') > -1) { curr_rating = -1; }
  else if (curr_rating_html.indexOf('ratneg') > -1) {
  	curr_rating = parseInt("-"+curr_rating_html.substr(curr_rating_html.indexOf('<b>')+3));
  }
  else if (curr_rating_html.indexOf('ratpos') > -1) { 
  	curr_rating = parseInt(curr_rating_html.substr(curr_rating_html.indexOf('<b>')+3));
  } 
  var issc = "";
  if (document.getElementById("ISSC")) {
    issc = document.getElementById("ISSC").value;
  }
  href = document.location.href.split("/");
  status = ratePosting.rpc_rate_posting(
    function(r){
      var text = "";
      if ( r.error == "0" ) {
        document.getElementById("bewertung_display_" + r.pnr).innerHTML = r.rating_post + "&nbsp;";
        text = "Ihre Bewertung '"+r.rating+"' wurde aufgenommen.";
      }
      else {
        text = "<font color='#ff0000'>" + r.error + "</font>";
      }
      document.getElementById("bewertung_form_" + r.pnr).style.display = "none"; 
      document.getElementById("bewertung_form_" + r.pnr).style.padding = "0px"; 
      document.getElementById("bewertung_info_" + r.pnr).innerHTML = text;
      document.getElementById("bewertung_info_" + r.pnr).style.display = "block";
    }
    ,[],['pnr','tnr','rating','poster','curr_rating','ISSC'],[pnr,nr,rating,poster,curr_rating,issc]);
  if ( status == 0 ) {
    //window.location.href="http://" + href[2] + "/forum/rater.m?pnr=" + pnr + "&tnr=" + nr + "&rater=" + rater + "&poster=" + poster + "&rating=" + rating;
	//window.location.href = "/forum/rater.m?pnr=" + pnr + "&tnr=" + nr + "&poster=" + poster + "&rating=" + rating;
  }
 }
}
function display_ausw(show, which) {
  elem0 = document.getElementById('bewertung_ausw_' + which);
  elem1 = document.getElementById('button_bewerten_' + which);
  elem2 = document.getElementById('button_int_' + which);
  elem3 = document.getElementById('button_zelle_' + which);
  if ( show == 1 ) {
    elem0.style.display = 'block';
    elem1.style.display = 'none';
    elem2.style.display = 'block';
    elem3.style.backgroundColor = '#E7F9E7';
    elem3.style.borderColor = '#5DA95D'; 
  }
  else {
    elem0.style.display = 'none';
    elem1.style.display = 'block';
    elem2.style.display = 'none';
    elem3.style.backgroundColor = '#ffffff';
    elem3.style.borderColor = '#a3a3a3';
  }
}
if ( typeof postings != "undefined" && postings ) {
  for ( i=0;i<postings.length;i++ ) {
    if ( document.getElementById("bewertung_posting_" + postings[i]) ) {
      tmp_html = document.getElementById("bewertung_html").innerHTML;
      tmp_html = tmp_html.replace(/--pnr--/gi, postings[i]);
      tmp_html = tmp_html.replace(/--poster--/gi, poster_id[i]);
      if ( first_posting == postings[i] ) {
        tmp_html = tmp_html.replace(/--button_text--/gi, "Thema bewerten");
      }
      else {
        tmp_html = tmp_html.replace(/--button_text--/gi, "bewerten");
      }
      document.getElementById("bewertung_posting_" + postings[i]).innerHTML = tmp_html;
      width = first_posting == postings[i] ? '115px' : '90px';
      document.getElementById("bewertung_div_" + postings[i]).style.width = width;
      document.getElementById("bewertung_ausw_" + postings[i]).style.width = width;
      document.getElementById("bewertung_table_" + postings[i]).style.width = width;
      document.getElementById("bewertung_ausw_table_" + postings[i]).style.width = width;
      document.getElementById("bewertung_div_" + postings[i]).style.display = "block";      
    }
  }
}
