var site_host   = 'http://' + location.host;
var site_path   = '';
var url         = site_host + site_path;

function favorite(link_id){
    
    dataString  = "action=fovorite" + "&link_id=" + link_id;
    //alert(dataString); return false;
    
    jQuery.ajax({
        type: "POST",
        url: url + "/ajax.php",
        data:  dataString,

        success: function(response){                           
            jQuery('#fav_unfav_' + link_id).html(response);
            
        }
    });
   
}

function unfavorite(link_id){
    
    dataString  = "action=unfovorite" + "&link_id=" + link_id;
    //alert(dataString); return false;
    
    jQuery.ajax({
        type: "POST",
        url: url + "/ajax.php",
        data:  dataString,

        success: function(response){                           
            jQuery('#fav_unfav_' + link_id).html(response);
            
        }
    });
   
}

function report_story(link_id, flag){
    if (link_id == '0'){
        window.location = url + '/login';
    } else { 
        if(  flag != '0' ){
            jQuery.ajax({
                type: "POST",
                url: url + "/ajax.php",
                data:  "action=report" + "&link_id=" + link_id + "&flag=" + flag,
                success: function(response){                           
                    jQuery('#report_story_' + link_id).html(response);
                    
                }
            });            
            
        }

    }
   
}

function allow_for_comment(author, domid){
    if(!confirm('Are you sure want to allow this user for comment?')){return;}
    dataString  = "action=allow_for_comment" + "&author=" + author;
    //alert(dataString); return false;
    jQuery.ajax({
        type: "POST",
        url: url + "/ajax.php",
        data:  dataString,
        success: function(response){                           
            //jQuery('#comment_allowed_' + domid).html(response);
            window.location = location.href;
        }
    });
   
}

function countLetter(textareanm , maxChar , spanName , MessageCaption , shouldShowSpan ){

    span_area = document.getElementById(spanName) ;
    txtara = document.getElementById(textareanm)   ;
    ev_v =  txtara.value ;
    erase_space =  trim(ev_v,''); 
    tfVal = parseInt(erase_space.length) ; 
    maxChar = parseInt(maxChar) ; 

    
    if(tfVal >= 0){
        nb =  maxChar -  tfVal;

        shouldShowSpan == 1 ? span_area.innerHTML = "<strong>"+nb+"</strong> characters left" : "" ;
     
    }
    
}//end countLetter fnc

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function checkThisRedio(theElement) {
    var theForm = theElement.form, z;
    //clear all buttons
    for(z=0; z<theForm.length;z++){
        if(theForm[z].type == 'radio' ){
            theForm[z].checked = false;
        }
    }
    //check the selected one
    theElement.checked = true;
}

function unfriend(from, to){
    if (from == '0' || to == '0' ){
            window.location = url + '/login';
   } else { 
        if(!confirm('Are you sure want to remove this friend?')){return;}
        dataString  = "action=unfriend" + "&from=" + from + "&to=" + to;
        //alert(dataString); return false;
        
        jQuery.ajax({
            type: "POST",
            url: url + "/ajax.php",
            data:  dataString,

            success: function(response){                           
                jQuery('#unfriend_' + to).html(response);
                
            }
        });
   }
   
}

function befriend(from, to){
    if (from == '0' || to == '0' ){
            window.location = url + '/login';
   } else { 
        
        dataString  = "action=befriend" + "&from=" + from + "&to=" + to;
        //alert(dataString); return false;
        
        jQuery.ajax({
            type: "POST",
            url: url + "/ajax.php",
            data:  dataString,

            success: function(response){                           
                jQuery('#befriend_' + to).html(response);
                
            }
        });
   }
   
}