//<![CDATA[
var tmpvar = false;
function comments(){
  this.objectname		= 'comm';
  this.form_name		= 'comments';
  this.tmptext		    = '';
  this.errors			= '';
  this.phrase			= new Array();
  this.imgplusa		    = '/upload/tmp/plus.gif';
  this.imgplusn		    = '/upload/tmp/plus2.gif';
  this.status			= 0;
  this.approved		    = false;
  this.approvedall      = false;
  this.modcomment		= 0;
  this.totalcomm		= 0;
  this.commentisvoted   = new Array();
  this.issmile          = false;
  this.prevmode 		= false;
  this.sendedstat 		= false;
  this.locationhref     = window.location.href;
  this.retlocation = function(xx){
    if(!xx) xx = 'comments';
    window.location.href = window.location.href.replace(/(#.*)/i,"")+'#'+xx;
  }
  this.smileview = function(){
    if(!this.issmile){
      $('smiles').style.display = 'block';
      $('smilehref').className = 'active';
      this.issmile = true;
    }else{
      $('smilehref').className = '';
      $('smiles').style.display = 'none';
      this.issmile = false;
    }
  }
  this.resetform = function(){
  	this.val('text').value = '';
  }
  this.preview = function(mod){
  	if(!this.prevmode && !mod){
  		this.check_text();
  		if(this.errors != ''){
  			this.screenerr();
  			return false;
  		}
  		var url =  basehref+'/upload/exe/previews.php';
  		var data = encodeURI('text='+this.val('text').value);
  		var h = mkhttp(url+'?'+data);
  		if(!h) return false;
  		if(!h.responseXML.getElementsByTagName("res")[0].firstChild) return;
  		$('previews').innerHTML = h.responseXML.getElementsByTagName("res")[0].firstChild.nodeValue;
  		$('previews').style.display = 'block';
  		$('prewhref').className = 'active';
  		this.prevmode = true;
  	}else{
  		$('prewhref').className = '';
  		$('previews').style.display = 'none';
  		this.prevmode = false;
  	}
  }
  this.init = function(){
    if(!this.approvedall) return;
    this.val('text').value = '';
  	this.approved 	= (userid>0) ? 1 : null;
    if(this.totalcomm == 0 && this.approved) $('allcommentsform').style.display = 'block';
  	this.modcomment = member['moder'];
    if(nocomment){$('msenno').innerHTML = this.phrase['nocomment']; this.approved = null; this.approvedall = null;}
  	this.commentisvoted = commentisvoted;
  	$('comment_form').style.display = 	(this.approved)	?'block':'none';
    $('msenno').style.display = 	    (this.approved)	?'none':'block';
    if(member['sendmailcomment']) this.val('sendmail').checked = true;
    this.val('text').onkeypress		=	function(){tmpvar = false;}
  	this.replace_des_element();
  }
  this.addrate = function(id){
    if(!this.approvedall) return;
  	if(this.commentisvoted[id]) return false;
  	var url =  basehref+'/xml/avote?mode=1&artid='+artid+'&sectid='+sectid+'&commid='+id;
  	var h = mkhttp(url);
  	if(!h) return false;
  	var res = h.responseXML.getElementsByTagName("status")[0].firstChild.nodeValue;
  	if(res < 1)return false;
  	this.commentisvoted[id] = id;
    if( $('vot_'+id)) $('vot_'+id).innerHTML = res;
    this.replace_des_element();
  	alert(this.phrase['rateok']);
  }
  this.moder_delete = function(id){
    if(!this.approved) return;
  	if(!confirm(this.phrase['del_confirm'])) return false;
  	var url =  basehref+'/xml/sendcomm/delete/'+artid+'/'+id;
  	var h = mkhttp(url);
  	if(!h) return false;
  	var res = h.responseXML.getElementsByTagName("status")[0].firstChild.nodeValue;
  	if(res != 1){alert(this.phrase['atten_noprem']);return false;}
    window.location.href = this.locationhref+'?#comments';
    window.location.reload();
  }
  this.reply = function(){
    if(!this.approved) return;
    $('allcommentsform').style.display = 'block';
    $('comment_form').style.display = 'block';
    this.retlocation();
    this.val('text').focus();
  }
  this.quote = function(id,us){
    if(!this.approved || !$('q_id_div_'+id)) return;
    tmpvar = true;
    $('allcommentsform').style.display = 'block';
    $('comment_form').style.display = 'block';
    this.retlocation();
    insteg('textar','<quote id="'+us+'">'+$('q_id_div_'+id).innerHTML.replace(/<p[^>]+<\/p>/gi,"").replace(/<\/?[^>]+>/gi," ").replace(/[\r|\n]/gi,"")+'</quote>\n');
  }
  this.postform = function(){
    if(!this.approved || this.sendedstat) return;
  	this.check_text();
    this.sendedstat = true;
  	if(this.errors != ''){
  		this.screenerr();
  		return false;
  	}else{
        this.tmptext = $('addsombaton').value;
        $('addsombaton').value = this.phrase['whait'];
        var url =  basehref+'/xml/sendcomm/add/'+artid+'/';
  		var data = encodeURI('f[text]='+this.val('text').value+'&f[sendmail]='+this.val('sendmail').value);
  		var h = mkhttp(url,data);
  		if(!h) return false;
  		if(!h.responseXML.getElementsByTagName("status")[0].firstChild) return;
        window.location.href = this.locationhref+'?#comments';
        window.location.reload();
    }
    this.sendedstat = false;
  }
  this.replace_des_element = function(){
    if(!this.approvedall) return;
    var j=1;
    var t = $('reply_all_'+j);
    while(t && t != "undefined"){
        if($('reply_all_'+j) && this.approved) 	$('reply_all_'+j).style.display = 'block';
        if($('quote_all_'+j) && this.approved) 	$('quote_all_'+j).style.display = 'block';
        if(this.modcomment == 1 && $('moder_all_'+j)) 	$('moder_all_'+j).style.display = 'block';
        if($('replyimg_'+j)){
    		var tnsc = $('replyimg_'+j).className.replace('recomj_','');
            $('replyimg_'+j).src = (!this.commentisvoted[tnsc])?this.imgplusa:this.imgplusn;
            if(this.commentisvoted[tnsc] && $('addratehref_'+tnsc)) $('addratehref_'+tnsc).style.cursor = 'default';
    	}
    	var t = $('reply_all_'+(++j));
    }
  }
  this.check_text = function(){
  	if(this.val('text').value == '') this.adderrors(this.phrase['notext']);
  	if(tmpvar) this.adderrors(this.phrase['notxtcom']);
  }
  this.adderrors = function(v){this.errors += v+'\n';}
  this.screenerr = function(){alert(this.errors);this.errors = '';}
  this.val = function(n){
  	if(document.forms[this.form_name].elements['f['+n+']'])	return document.forms[this.form_name].elements['f['+n+']'];
  }
}
//]]>