var xmlhttp
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	  try {
	  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
	 } catch (e) {
	  try {
	    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	  } catch (E) {
	   xmlhttp=false
	  }
	 }
	@else
	 xmlhttp=false
	@end @*/
	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;
	  alert('couldn\'t create xmlhttp object');
	 }
	}
	return(xmlhttplocal);
}

function topic_rate(){
    this.settings={'allow_rating':0,
                   'default_rating':3,
                   'img_star_on':'star_filled.gif',
                   'img_star_selected':'star_selected.gif',
                   'img_star_off':'star_empty.gif',
                   'img_main_star_0':'rating_0.gif',
                   'img_main_star_1':'rating_1.gif',
                   'img_main_star_2':'rating_2.gif',
                   'img_main_star_3':'rating_3.gif',
                   'img_main_star_4':'rating_4.gif',
                   'img_main_star_5':'rating_5.gif',
                   'img_base_url':'',
                   'div_rating_wrapper':'topic-rating-wrapper',
                   'text_rating_image':'topic-rating-img-',
                   'topic-rating-img-main':'topic-rating-img-main',
                   'topic-rating-my-rating':'topic-rating-my-rating',
                   'topic-rating-hits':'topic-rating-hits'};

    this.languages={'img_alt_rate':'','rate_me':''};

    this.init_rating_images=function(){
        var html='';
        if(!this.settings['allow_rating']){return false;}
        for(var i=1;i<=5;i++){
            var _onmouseover='';
            var _onmouseout='';
            var _onclick='';
            var _title='';
            _onmouseover=' onmouseover="this.style.cursor=\'pointer\'; topic_rate.show_rating_images('+i+', 0)"'; _onmouseout=' onmouseout="topic_rate.show_rating_images(-1, 1)"';
            _onclick=' onclick="topic_rate.send_rating('+i+')"';
            _title=this.languages['img_alt_rate'];
            html+="<img style='vertical-align:top' src='"+this.settings['img_base_url']+'/'+this.settings['img_star_off']+"' "+_onmouseover+_onmouseout+_onclick+"id='"+this.settings['text_rating_image']+i+"' alt='-' title='"+_title+"' />";
        }
        document.getElementById(
        this.settings['div_rating_wrapper']).innerHTML=this.languages['rate_me']+' '+html;

        this.show_rating_images(this.settings['default_rating'],1);};

        this.send_rating=function(rating){
            rating=rating?rating:0;
            xmlhttp.open('get', mw_root + '/extensions/ipbwiki/ipbwiki_rating.php?act=rate&ipbwiki_skin=1&user_id='+mw_userid+'&ip_address='+mw_ipaddress+'&article_id='+mw_articleid+'&rating='+rating);
            xmlhttp.onreadystatechange = handleResponse;
            xmlhttp.send(null);
        };

        this.show_rating_images=function(rating,restore_default){            rating=restore_default?this.settings['default_rating']:parseInt(rating);
            var star=restore_default?this.settings['img_star_on']:this.settings['img_star_selected'];
            for(var i=1;i<=5;i++){
                var _img=document.getElementById(this.settings['text_rating_image']+i);
                _img.src=this.settings['img_base_url']+'/'+this.settings['img_star_off'];
            }
            for(var i=1;i<=rating;i++){
                var _img=document.getElementById(this.settings['text_rating_image']+i);
                _img.src=this.settings['img_base_url']+'/'+star;}document.getElementById(this.settings['topic-rating-img-main']).src=this.settings['img_base_url']+'/'+this.settings['img_main_star_'+rating];
            };
        };

function handleResponse() {
	if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
	        var html = xmlhttp.responseText;
	        if(html=='no_permission'){
	                alert(js_error_no_permission);
            } else if(html!='error') {
                var _result=html.split(',');
                var _new_value=_result[0];
                var _new_hits=_result[1];
                var _new_stars=_result[2];
                topic_rate.settings['default_rating']=parseInt(_new_stars);
                topic_rate.show_rating_images(topic_rate.settings['default_rating'],1);
                menu_action_close();
                document.getElementById('topic-rating-hits').innerHTML=_new_hits;
                document.getElementById('topic-rating-my-rating').innerHTML=_new_value;show_inline_messages_instant('rating_updated');
            }
 		}
    }
}

function alternative_rate (mw_root, articleid, rating, userid, ipaddress) {
     xmlhttp.open('get', mw_root + '/extensions/ipbwiki/ipbwiki_rating.php?act=rate&ipbwiki_skin=0&user_id='+userid+'&ip_address='+ipaddress+'&article_id='+articleid+'&rating='+rating);
     xmlhttp.onreadystatechange = handleResponse2;
     xmlhttp.send(null);
}

function handleResponse2() {
	if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
	        var response = xmlhttp.responseText;
	        var update = new Array();

	        if(response.indexOf('|') != -1) {
	            update = response.split('|');
	            changeText2(update[0], update[1]);
	        }
 		}
    }
}

function changeText2( div2show, text ) {
    // Detect Browser
    var IE = (document.all) ? 1 : 0;
    var DOM = 0;
    if (parseInt(navigator.appVersion) >=5) {DOM=1};

    // Grab the content from the requested "div" and show it in the "container"
    if (DOM) {
        var viewer = document.getElementById(div2show);
        viewer.innerHTML = text;
    }  else if(IE) {
        document.all[div2show].innerHTML = text;
    }
}

