var is_l_fbc = false;
var fbc_vote_type = -1;
var tmp_vote_id;
function item_loading(){
    $('progress').style.display='inline';
}
function item_complete(){
    $('progress').style.display='none';    
}
function item_loading2(){
    $('progress2').style.display='inline';
}
function item_complete2(){
    $('progress2').style.display='none';    
}

function vote(property_id,v,vote_v){
    var query_string = 'action=cast_vote';
    query_string += '&property_id='+property_id;
    query_string += '&vote='+v;
    query_string += '&vote_v='+vote_v;
    
    if(is_l_fbc) fbc_prepare_vote();
    
    new Ajax.Updater('ajax-response',ajax_script_rating,{onLoading:function(request){item_loading()},onComplete:function(request){item_complete()},parameters:query_string, insertion:Insertion.Bottom, asynchronous:true});        
    
    var score = parseInt($('score-'+property_id).innerHTML);
    if(v==1){
        score = score+1;
        $('up-votes-'+property_id).innerHTML=1+parseInt($('up-votes-'+property_id).innerHTML);
    }else{
        score = score-1;
        $('down-votes-'+property_id).innerHTML=1+parseInt($('down-votes-'+property_id).innerHTML);
    }
    if(score > 0) score = '+'+score;
    $('score-'+property_id).innerHTML=score;
    
    $('vote-image-up-'+property_id).innerHTML='<img src="/images/thumb_up_dis.gif" width="14" heigth="14" />&nbsp;&nbsp;';
    $('vote-image-down-'+property_id).innerHTML='<img src="/images/thumb_down_dis.gif" width="14" heigth="14" />';
    if($('vote-image-up-2-'+property_id))
        $('vote-image-up-2-'+property_id).innerHTML='<img src="/images/thumb_up_dis.gif" width="14" heigth="14" />';
    if($('vote-image-down-2-'+property_id))
        $('vote-image-down-2-'+property_id).innerHTML='<img src="/images/thumb_down_dis.gif" width="14" heigth="14" />';
    
    
    $('vote-request').innerHTML='Your vote has been added.';
    
    if(trim($('comment-text-form').value)){
        $('comment-submit-button').disabled=false;
    }
    $('comment-text-form').setAttribute('onkeyup',"enableSaveButton('comment-text-form','comment-submit-button')");

	// doing this for IE as setAttribute doesnt work for IE
	// also in this case we can not pass any param to our function - so hacked the function as well
	try
	{
	    $('comment-text-form').attachEvent('onkeyup', enableSaveButton);
	}
	catch(err)
	{
		// do nothing here
	}	
    return false;    
}

function enableSaveButton(tarea, idbut){    
	if (!idbut)
	{
		var idbut = 'comment-submit-button';
		var tarea = 'comment-text-form';
	}

    if(trim(document.getElementById(tarea).value).length > 0){
        document.getElementById(idbut).disabled=false;
//	if(idbut == 'comment-submit-button')
//		document.getElementById(idbut).className = "enabledBut";

    }else{
        document.getElementById(idbut).disabled=true;
//	if(idbut == 'comment-submit-button')
//		document.getElementById(idbut).className = "disabledBut";
    }
}

function incrementTotalCommentVotes(comm_id,type){
    var rep='';
    if(type==2){
        rep = 'r-';
    }
    $('number-of-total-votes-'+rep+comm_id).innerHTML=parseInt($('number-of-total-votes-'+rep+comm_id).innerHTML)+1;
}
function incrementUpCommentVotes(comm_id,type){
    var rep='';
    if(type==2){
        rep = 'r-';
    }
    $('number-of-up-votes-'+rep+comm_id).innerHTML=parseInt($('number-of-up-votes-'+rep+comm_id).innerHTML)+1;    
}
function decrementUpCommentVotes(comm_id,type){
    var rep='';
    if(type==2){
        rep = 'r-';
    }
    $('number-of-up-votes-'+rep+comm_id).innerHTML=parseInt($('number-of-up-votes-'+rep+comm_id).innerHTML)-1;    
}


function saveComment(vote_id, comment, prop_id){
    $('ajax-response').innerHTML='';
    $('comment-form').innerHTML='';
    var query_string = 'action=save_comment';
    query_string += '&vote_id='+vote_id;
    query_string += '&comment='+URLEncode(comment);
    new Ajax.Updater('ajax-response',ajax_script_rating,{onLoading:function(request){item_loading2()},onComplete:function(request){item_complete2()},parameters:query_string, insertion:Insertion.Bottom, asynchronous:true});        

    if($('comments-number-'+prop_id)){
        var current_comments_number = parseInt($('comments-number-'+prop_id).innerHTML);
    }else{
        var current_comments_number = 0;
    }
    
    try{
        if(current_comments_number==0){
            $('comments-link-'+prop_id).innerHTML = '<a href="#comments">1 Comment</a>';
        }else{
            current_comments_number++;
            $('comments-link-'+prop_id).innerHTML = '<a href="#comments">'+current_comments_number+' Comments</a>';
        }    
    }catch(err){
        //
    }
    return false;    
}

function skipComment(comm_id,type){
    var rep='';
    if(type==2){
        rep = 'r-';
    }
    $('ajax-response-'+rep+comm_id).innerHTML='';
}

function saveCommentComment(comment_id, vote_id,comment,type){
    var rep='';
    if(type==2){
        rep = 'r-';
    }
    $('ajax-response-'+rep+comment_id).innerHTML='';
    var query_string = 'action=save_comment_comment';
    query_string += '&vote_id='+vote_id;
    query_string += '&comment_id='+comment_id;
    query_string += '&comment='+URLEncode(comment);
    query_string += '&type='+type;
    new Ajax.Updater('ajax-response-'+rep+comment_id,ajax_script_rating,{onLoading:function(request){item_loading2()},onComplete:function(request){item_complete2()},parameters:query_string, insertion:Insertion.Bottom, asynchronous:true});        
    return false;    
}


function previewComment(author,comment){
        
    comment = comment.replace(/\n/g,'<br />'); 
    comment = comment.replace(/(<([^>]+)>)/ig,"");    
    
    $('propertyComments').innerHTML=$('propertyComments').innerHTML + '<a name="comment-preview"></a><br /><div class="rating_author"><div class="right_votes">Comment rating: <strong>+1</strong></div><strong>'+author+'</strong></div><div class="rating_body">'+comment+'</div><div class="vote">your comment has been added</div>';

    location.href='#comment-preview';
}                                                                                                                                                                                                                             


function updateVoteArea(property_id, text){
    $('vote-area-'+property_id).innerHTML=text;
}


function updateVoteAreaComment(comm_id,text,type){
    var rep='';
    if(type==2){
        rep = 'r-';
    }
    $('vote-area-'+rep+comm_id).innerHTML=text;
}

function vote_form2(frm){
    if($('vote-id'))
        $('vote-id-form').value=parseInt($('vote-id').innerHTML);
        

    var comment = $('comment-text-form').value;
    comment = comment.replace(/\n/g,'<br />');
    comment = comment.replace(/(<([^>]+)>)/ig,"");           
    if($('auhtor-name').value){
        author = $('auhtor-name').value;
    }else{
        author = fbc_user  ;
    }
    $('propertyComments').innerHTML = $('propertyComments').innerHTML + '<br /><div class="rating_author"><div class="right_votes">Comment rating: +1</div><strong>'+author+'</strong></div><div class="rating_body">'+comment+'</div><div class="vote">your comment has been added</div>';
    
    saveComment($('vote-id-form').value, $('comment-text-form').value, frm.prop_id_form.value);
    
    return false;
}

function saveReply(vote_id, comment){
    $('ajax-response').innerHTML='';
    var query_string = 'action=save_reply';
    query_string += '&vote_id='+vote_id;
    query_string += '&comment='+URLEncode(comment);
    new Ajax.Updater('ajax-response',ajax_script_rating,{onLoading:function(request){item_loading()},onComplete:function(request){item_complete()},parameters:query_string, insertion:Insertion.Bottom, asynchronous:true});        
    
    $('number-of-comments').innerHTML=parseInt($('number-of-comments').innerHTML)+1;
    
    return false;    
}

var opened_comment_box = '';
function vote_comment(comment_id,v,type, is_l){
    
    if(opened_comment_box != ''){
        document.getElementById(opened_comment_box).innerHTML='';
        opened_comment_box = '';
    }
    
    var rep='';
    if(type==2){
        rep = 'r-';
    }
    
    if(!is_l && !is_l_fbc){      
        popMembershipBox(); return;                       
    }
    
    var query_string = 'action=cast_vote_comment';
    query_string += '&comment_id='+comment_id;
    query_string += '&vote='+v;
    query_string += '&type='+type;
    if(is_l_fbc){
        query_string += '&fbc_user='+fbc_user;  
    }        

    new Ajax.Updater('ajax-response-'+rep+comment_id,ajax_script_rating,{onLoading:function(request){item_loading2()},onComplete:function(request){item_complete2()},parameters:query_string, insertion:Insertion.Bottom, asynchronous:true});        
    
    //$('vote-image-comment-up-'+rep+comment_id).innerHTML='<img src="/images/thumb_up_dis.gif" width="14" heigth="14" />';
    //$('vote-image-comment-down-'+rep+comment_id).innerHTML='<img src="/images/thumb_down_dis.gif" width="14" heigth="14" />';
 
    opened_comment_box='ajax-response-'+rep+comment_id;
       
    $('vote-bar-c-'+rep+comment_id).innerHTML='';
    if(v==1){
        var ud = 'up';
    }else{
        var ud = 'down';
    }
    
    $('vote-bar-c-'+rep+comment_id).innerHTML += 'You voted&nbsp;<img id="voted-how-'+rep+comment_id+'" src="/images/thumb_'+ud+'.gif" width="14" height="14" />&nbsp;';
    $('vote-bar-c-'+rep+comment_id).innerHTML += '<a href="javascript:void(0)" onclick="toogleCommentVote('+comment_id+','+type+')">(change)</a>';
    
    
    var score = parseInt($('score-comment-'+rep+comment_id).innerHTML);    
    if(v==0){
        score = score-1;
        //$('down-votes-comment-'+rep+comment_id).innerHTML= 1 + parseInt($('down-votes-comment-'+rep+comment_id).innerHTML);
    }else{
        score = score+1;
        //$('up-votes-comment-'+rep+comment_id).innerHTML= 1 + parseInt($('up-votes-comment-'+rep+comment_id).innerHTML);
    }
    if(score > 0) score = '+'+score;
    $('score-comment-'+rep+comment_id).innerHTML=score;
                   
    return false;    
}

function toogleVote(prop_id){
    var query_string = 'action=toogle_vote';
    query_string += '&property_id='+prop_id;
    new Ajax.Updater('ajax-response',ajax_script_rating,{onLoading:function(request){item_loading()},onComplete:function(request){item_complete()},parameters:query_string, insertion:Insertion.Bottom, asynchronous:true});                
    
    var cur_image = $('voted-how-p-'+prop_id).src.split('/').pop();    
    if(cur_image=='thumb_up.gif'){
        var old_vote = 1;        
        $('voted-how-p-'+prop_id).src='/images/thumb_down.gif';
        $('up-votes-'+prop_id).innerHTML = -1 + parseInt($('up-votes-'+prop_id).innerHTML);
        $('down-votes-'+prop_id).innerHTML = 1 + parseInt($('down-votes-'+prop_id).innerHTML);
    }
    else{
        var old_vote = 0;
        $('voted-how-p-'+prop_id).src='/images/thumb_up.gif';
        $('up-votes-'+prop_id).innerHTML = 1 + parseInt($('up-votes-'+prop_id).innerHTML);
        $('down-votes-'+prop_id).innerHTML = -1 + parseInt($('down-votes-'+prop_id).innerHTML);        
    }
        
    
    var score = parseInt($('score-'+prop_id).innerHTML);
    if(old_vote==1){
        score = score-2;
    }else{
        score = score+2;
    }
    if(score > 0) score = '+'+score;
    $('score-'+prop_id).innerHTML=score;
}

function toogleCommentVote(comm_id,type){
    var rep='';
    if(type==2){
        rep = 'r-';
    }
    var query_string = 'action=toogle_comment_vote';
    query_string += '&comment_id='+comm_id;
    query_string += '&type='+type;    
    new Ajax.Updater('ajax-response',ajax_script_rating,{onLoading:function(request){item_loading2()},onComplete:function(request){item_complete2()},parameters:query_string, insertion:Insertion.Bottom, asynchronous:true});            
    
    
    var cur_image = $('voted-how-'+rep+comm_id).src.split('/').pop();    
    if(cur_image=='thumb_up.gif'){
        var old_vote = 1;        
        $('voted-how-'+rep+comm_id).src='/images/thumb_down.gif';
    }
    else{
        var old_vote = 0;
        $('voted-how-'+rep+comm_id).src='/images/thumb_up.gif';
    }
        
    var score = parseInt($('score-comment-'+rep+comm_id).innerHTML);    
    
    if(old_vote==1){
        score = score-2;
        //$('up-votes-comment-'+rep+comm_id).innerHTML= -1 + parseInt($('up-votes-comment-'+rep+comm_id).innerHTML);
        //$('down-votes-comment-'+rep+comm_id).innerHTML= 1 + parseInt($('down-votes-comment-'+rep+comm_id).innerHTML);
    }else{
        score = score+2;
        //$('up-votes-comment-'+rep+comm_id).innerHTML= 1 + parseInt($('up-votes-comment-'+rep+comm_id).innerHTML);
        //$('down-votes-comment-'+rep+comm_id).innerHTML= -1 + parseInt($('down-votes-comment-'+rep+comm_id).innerHTML);
    }
    if(score > 0) score = '+'+score;
    $('score-comment-'+rep+comm_id).innerHTML=score;
    
}

function showCommentReplies(comment_id, type){
    var rep='';
    if(type==2){
        rep = 'r-';
    }
    var query_string = 'action=show_comment_replies';
    query_string += '&comment_id='+comment_id;
    query_string += '&type='+type;
    new Ajax.Updater('comment-replies-place-'+rep+comment_id,ajax_script_rating,{onLoading:function(request){item_loading2()},onComplete:function(request){item_complete2();FB.XFBML.Host.parseDomTree();},parameters:query_string, insertion:Insertion.Bottom, asynchronous:true});            
    $('reply-show-'+rep+comment_id).style.display='none';
    $('reply-hide-'+rep+comment_id).style.display='inline';
}
function hideCommentReplies(comment_id,type){
    var rep='';
    if(type==2){
        rep = 'r-';
    }
    $('reply-show-'+rep+comment_id).style.display='inline';
    $('reply-hide-'+rep+comment_id).style.display='none';
    $('comment-replies-place-'+rep+comment_id).innerHTML='';
}

function vote_prop_direct(prop_id, vote, is_l, preview){    
    
    if($('pop_opened').value == 'true') return;
    
    if(is_l_fbc){
        fbc_prepare_vote();
    }
    if(!is_l && !is_l_fbc){
        fbc_vote_type = vote;
        fbc_prop_id = prop_id;
        popMembershipBox(); return;             
    }
    
    if(vote==0){
        var ud='down';
        var ivote = -1;
    }else{
        var ud='up';
        var ivote = 1;
    }

    $('vote-image-up-'+prop_id).innerHTML='<img src="/images/thumb_up_dis.gif" width="14" heigth="14" />&nbsp;&nbsp;';
    $('vote-image-down-'+prop_id).innerHTML='<img src="/images/thumb_down_dis.gif" width="14" heigth="14" />';

	try
	{
	    $('vote-image-up-'+prop_id+'-2').innerHTML='<img src="/images/thumb_up_dis.gif" width="14" heigth="14" />&nbsp;&nbsp;';
	    $('vote-image-down-'+prop_id+'-2').innerHTML='<img src="/images/thumb_down_dis.gif" width="14" heigth="14" />';
	}
	catch(err)
	{
		// do nothing here
	}	

    if($('vote-bar-'+prop_id)){
        $('vote-bar-'+prop_id).innerHTML = 'You voted&nbsp;<img id="voted-how-p-'+prop_id+'" src="/images/thumb_'+ud+'.gif" width="14" heigth="14" />&nbsp;<a href="javascript:void(0)" onclick="toogleVote('+prop_id+')">change</a>';
    }    
    
    var score = ivote+parseInt($('score-'+prop_id).innerHTML);
    if(score > 0){
        score = '+'+score;
        $('up-votes-'+prop_id).innerHTML = 1 + parseInt($('up-votes-'+prop_id).innerHTML);
    }else{
        $('down-votes-'+prop_id).innerHTML = 1 + parseInt($('down-votes-'+prop_id).innerHTML);
    }
    $('score-'+prop_id).innerHTML=score;
    
    if($('comment-form'))
    $('comment-form').innerHTML='';
    showCommentPop(prop_id,vote,preview);
    
    var query_string = 'action=vote_property_direct';
    query_string += '&property_id='+prop_id;
    query_string += '&vote='+vote;  
    if(is_l_fbc){
        query_string += '&fbc_user='+fbc_user;  
    }        
    new Ajax.Request(ajax_script_rating,{
      method: 'post',
      parameters: query_string,
      onLoading: function(transport) {
            $('comment-box-progress').style.display='inline';
            $('comment-box-ta').disabled=true;
            $('comment-box-ta').value='saving vote...';
      },      
      onSuccess: function(transport) {            
            tmp_vote_id = transport.responseText;
            $('comment-box-progress').style.display='none';
            $('comment-box-ta').disabled=false;
            $('comment-box-ta').value='';
            
    }})
}


/* POP - START */

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE);
if(IE){
    window.onload = function(){
        if($('pop_opened'))
        $('pop_opened').value = 'false';
    }
}

document.onmousemove = getMouseXY;
document.onclick = getMouseXY;
// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

var scrOfX = 0, scrOfY = 0;
function getScrollXY() {
  
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
}

function getMouseXY(e) {
  getScrollXY();  
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + scrOfX
    tempY = event.clientY + scrOfY
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  //alert(tempX+','+tempY);
  return true
}

function showCommentPop(prop_id,vote,preview){  
      
    $('pop_opened').value = 'true';
    $('show_preview').value = preview;
    $('glob_prop_id').value = prop_id;
    $('comment-box-no').disabled=false;    
    $('comment-box-ta').value='';
    $('comment-box-ar').innerHTML='';
    
    var cbw = 400;
    var cbh = 200;

    var w = document.body.clientWidth;
    
    var leftPos = (w-cbw)/2;
    var topPos = jQuery(window).scrollTop();
    
    jQuery('#comment-box').css('left',leftPos);
    jQuery('#comment-box').css('top',topPos);
    
    var wrap_height = jQuery('document').height();
    jQuery('body').prepend('<div id="_wrapper_mask""></div>');    
    var mask = jQuery('#_wrapper_mask');    
    mask.css({
        position:'absolute', 
        height: jQuery(document).height(), 
        width: jQuery(document).width(),
        left:0, top:0,
        background:'#000'        
        });
        
    if(is_ie)
    mask.css({
        filter:'alpha(opacity=50)'
        });
         
    jQuery('#comment-box').css({
        position:'absolute', 
        width:cbw,
        height:cbh,
        left: (jQuery(document).width() - cbw)/2,
        top: jQuery(document).scrollTop() + cbh
        });
    if(is_ie)
    mmf_pop.css({position:'absolute'});
    
    jQuery('#_wrapper_mask').fadeIn('fast', function(){
        if(is_ie6) jQuery('select').css('visibility','hidden');
        jQuery('#comment-box').show();        
    });        
}
function cancelCommentDirect(){
    jQuery('#_wrapper_mask').fadeOut('fast', function(){jQuery('#_wrapper_mask').remove();if(is_ie6) jQuery('select').css('visibility','visible');});
    $('comment-box').style.display='none';    
    $('comment-box-ta').value='';
    $('comment-box-save').disabled=true;    
    $('pop_opened').value = 'false';
}

/* POP - START */

function item_loading3(){
    $('comment-box-progress').style.display='inline';
}
function item_complete3(author,comment){   
    if(author==undefined){
        author = fbc_user;
    }     
    $('comment-box-progress').style.display='none';    
    if($('propertyComments') && parseInt($('show_preview').value))
        previewComment(author,comment);    
    window.setTimeout('cancelCommentDirect()',500);            
}
function saveCommentDirect(comment,author){    
    prop_id = $('glob_prop_id').value;
    //alert(tmp_vote_id);
    vote_id = tmp_vote_id;
    if($('comments-number-'+prop_id)){
        var current_comments_number = parseInt($('comments-number-'+prop_id).innerHTML);
    }else{
        var current_comments_number = 0;
    }
    if(current_comments_number==0){
        if($('comments-link-'+prop_id)) $('comments-link-'+prop_id).innerHTML = 'comment added';
    }else{
        $('comments-number-'+prop_id).innerHTML = 1 + parseInt($('comments-number-'+prop_id).innerHTML);
    }
    $('comment-box-no').disabled=true;
    $('comment-box-save').disabled=true;
    var query_string = 'action=save_comment_direct';
    query_string += '&comment='+URLEncode(comment);
    query_string += '&vote_id='+vote_id;    
    if(!author){
        author = fbc_user;
    }    
    new Ajax.Updater('comment-box-ar',ajax_script_rating,{onLoading:function(request){item_loading3()},onComplete:function(request){item_complete3(author,comment)},parameters:query_string, insertion:Insertion.Bottom, asynchronous:true});                    
}

function item_loading_4(comment_id, rep){
    $('progress-fetch-comment-'+rep+comment_id).style.display='inline';
}
function item_complete4(comment_id, rep){
    $('progress-fetch-comment-'+rep+comment_id).style.display='none';
}
function show_comment_below_treshold(comment_id,type,current_vote,is_l){
    var rep='';
    if(type==2){
        rep = 'r-';
    }
    
    if($('show_comment_below_th_'+rep+comment_id).innerHTML){
        $('show_comment_below_th_'+rep+comment_id).innerHTML='';
        $('reply-show-'+rep+comment_id).style.display='none';        
        $('reply-hide-'+rep+comment_id).style.display='none';
        $('show_comment_below_treshold-link-'+rep+comment_id).innerHTML=$('show_comment_below_treshold-link-'+rep+comment_id).innerHTML.replace(/hide comment/,'show comment');        
        if(current_vote==-1){
            $('vote-image-comment-up-'+rep+comment_id).innerHTML='<img src="/images/thumb_up_dis.gif" width="14" heigth="14" />';
            $('vote-image-comment-down-'+rep+comment_id).innerHTML='<img src="/images/thumb_up_dis.gif" width="14" heigth="14" />';        
        }
        return ;
    }
    
    $('reply-show-'+rep+comment_id).style.display='inline';    
    $('show_comment_below_treshold-link-'+rep+comment_id).innerHTML=$('show_comment_below_treshold-link-'+rep+comment_id).innerHTML.replace(/show comment/,'hide comment');
    if(current_vote==-1){        
        $('vote-image-comment-up-'+rep+comment_id).innerHTML='<a href="javascript:void(0)"><img src="/images/thumb_up.gif" onclick="vote_comment('+comment_id+',1,'+type+','+is_l+');" width="14" heigth="14"/></a>';
        $('vote-image-comment-down-'+rep+comment_id).innerHTML='<a href="javascript:void(0)"><img src="/images/thumb_down.gif" onclick="vote_comment('+comment_id+',0,'+type+','+is_l+');" width="14" heigth="14"/></a>';
    }
    
    
    
    var query_string = 'action=show_comment_below_treshold';
    query_string += '&comment_id='+comment_id;
    query_string += '&type='+type;
    new Ajax.Updater('show_comment_below_th_'+rep+comment_id,ajax_script_rating,{onLoading:function(request){item_loading_4(comment_id, rep)},onComplete:function(request){item_complete4(comment_id, rep)},parameters:query_string, insertion:Insertion.Bottom, asynchronous:true});                        
}

function popMembershipBox(){
    //test margins
    if(tempX + 350 > document.body.clientWidth) tempX = tempX-350;
    if(tempY + 60 > document.body.clientHeight) tempY = tempY-60;

    box = $('membership-prompt-box');
    box.style.left = tempX+'px';
    box.style.top = tempY+'px';    
    box.style.display='block';
}

function trim(sString){
    while (sString.substring(0,1) == ' ' || sString.substring(0,1) == '\n'){
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' ' || sString.substring(sString.length-1, sString.length) == '\n'){
        sString = sString.substring(0,sString.length-1);
    }
    return sString;
}

function URLEncode(plaintext)
{
    // The Javascript escape and unescape functions do not correspond
    // with what browsers actually do...
    var SAFECHARS = "0123456789" +                    // Numeric
                    "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +    // Alphabetic
                    "abcdefghijklmnopqrstuvwxyz" +
                    "-_.!~*'()";                    // RFC2396 Mark characters
    var HEX = "0123456789ABCDEF";

    var encoded = "";
    for (var i = 0; i < plaintext.length; i++ ) {
        var ch = plaintext.charAt(i);
        if (ch == "+") {
            encoded += "%2B";
        }else
        if (ch == " ") {
            encoded += "+";                // x-www-urlencoded, rather than %20
        } else if (SAFECHARS.indexOf(ch) != -1) {
            encoded += ch;
        } else {
            var charCode = ch.charCodeAt(0);
            if (charCode > 255) {
                alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
                          "(URL encoding only supports 8-bit characters.)\n" +
                          "A space (+) will be substituted." );
                encoded += "+";
            } else {
                encoded += "%";
                encoded += HEX.charAt((charCode >> 4) & 0xF);
                encoded += HEX.charAt(charCode & 0xF);
            }
        }
    } // for

    return encoded;
};
