function str_replace ( search, replace, subject ) {   
	 
	    if(!(replace instanceof Array)){
	        replace=new Array(replace);
	        if(search instanceof Array){//If search    is an array and replace    is a string, then this replacement string is used for every value of search
	            while(search.length>replace.length){
	                replace[replace.length]=replace[0];
	            }
	        }
	    }
	 
	    if(!(search instanceof Array))search=new Array(search);
	    while(search.length>replace.length){//If replace    has fewer values than search , then an empty string is used for the rest of replacement values
	        replace[replace.length]='';
	    }
	 
	    if(subject instanceof Array){//If subject is an array, then the search and replace is performed with every entry of subject , and the return value is an array as well.
	        for(k in subject){
	            subject[k]=str_replace(search,replace,subject[k]);
	        }
	        return subject;
	    }
	 
	    for(var k=0; k<search.length; k++){
	        var i = subject.indexOf(search[k]);
	        while(i>-1){
	            subject = subject.replace(search[k], replace[k]);
	            i = subject.indexOf(search[k],i);
	        }
	    }
	 
	    return subject;	 
	}
	
	function reply_form(id,type,post_ID,request_uri) {
		if (type=="open") {
			input_name = get_author(id);
			first = "<div class=\"comments_smiles\" id=\"smiles-" + id + "\"></div> \
			<div id=\"error-" + id + "\" style=\"display:none;color:red;\"></div> \
		<div id=\"loading-" + id + "\" style=\"display:none;color:grey;\"><img src=\"/ratings/images/loading.gif\"> Loading</div> \
		 <form action=\"/sources/comments_post.php\" method=\"post\" id=\"commentform-" + id + "\"> <p>";
		 
			last = "</p> \
		<p><textarea name=\"comment_text-" + id + "\" id=\"comment_text-" + id + "\" cols=\"100%\" rows=\"3\" tabindex=\"4\" style=\"width:500px;\"></textarea></p> \
		<p> \
			<input  type=\"button\" id=\""+id+"\" tabindex=\"5\" onclick=\"ajax_send(this);\" value=\"Submit Comment\" /> <input name=\"close\" type=\"button\" id=\"close\" tabindex=\"6\" onclick=\"reply_form(" + id + ",'close','','');\" value=\"Close\" /> \
			<input type=\"hidden\" name=\"comment_post_ID\" value=\"" + post_ID + "\" /> \
			<input type=\"hidden\" name=\"request_uri\" value=\"" + request_uri + "\" /> \
			<input type=\"hidden\" name=\"action\" value=\"post\" /> \
		</p> \
		</form>";
			
			document.getElementById('reply-'+id).style.display = "block";
			document.getElementById('reply-'+id).innerHTML = first + input_name + last;
			sm = document.getElementById('smiles').innerHTML;
			document.getElementById('smiles-'+id).innerHTML = str_replace("''", "'"+ id +"'",sm);
		} else if(type=="close") {
			document.getElementById('reply-'+id).style.display = "none";
		}		
	}
	
	function check_comment(id) {
		if (document.getElementById("comment_text"+id).value.length>1000) {
			document.getElementById('error'+id).style.display = "block";
			document.getElementById("error"+id).innerHTML = "Comment's length is more than 1000 symbols";
			return false;
		} else if (document.getElementById("comment_text"+id).value.length>0) {
			document.getElementById('error'+id).style.display = "none";
			//document.getElementById("error").innerHTML = "";
		    //document.getElementById("commentform"+id).submit();
			//alert(document.getElementById("commentform").submit);
			return true;
		} else {
		    //alert("comment_text"+id);
		   // alert(document.getElementById("comment_text"+id).value);
			document.getElementById('error'+id).style.display = "block";
			document.getElementById("error"+id).innerHTML = "Please type a comment";
			return false;
		}
	}