/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$j = jQuery.noConflict();
$j(function(){
    var lang = "vi_VN";
    $j.each($j("meta"),function(){
        if($j(this).attr("http-equiv")=="Content-Language"){
           lang = $j(this).attr("content")!=""?$j(this).attr("content").replace("-", "_"):"en_US";
        }
    });
    $j.each($j(".published_class"),function() {
        var datetime = $j(this).html();
        var now = new Date();
        var now_date = now.format("dd/mm/yyyy");
        var now_hour = now.format("H");
        var now_min = now.format("M");
        var published_date = datetime.substring(0, 10);
        var published_hour = parseInt(datetime.substring(11, 13));
        var published_min = parseInt(datetime.substring(14, 16));
        if(now_date==published_date){
            time1 = now_hour*60*60 + now_min*60;
            time2 = published_hour*60*60 + published_min*60;
            time = Math.abs(time1 - time2);
            if(time < 60){
                $j(this).addClass("timestamp");
                $j(this).html("<span class=\"timestamp\"><b>"+time+" "+
                    ss.i18n.getDictionary(lang)['PAGE.SEC']+" "+ss.i18n.getDictionary(lang)['PAGE.AGO']+"</span>");
            }else if(time < 3600){
                $j(this).addClass("timestamp");
                $j(this).html("<span class=\"timestamp\"><b>"+parseInt(time/60)+" "+
                    ss.i18n.getDictionary(lang)['PAGE.MIN']+" "+ss.i18n.getDictionary(lang)['PAGE.AGO']+"</span>");
            }else if(time < 43200){
                $j(this).addClass("timestamp");
                $j(this).html("<span class=\"timestamp\"><b>"+parseInt(time/3600)+" "+
                    ss.i18n.getDictionary(lang)['PAGE.HOUR']+" "+ss.i18n.getDictionary(lang)['PAGE.AGO']+"</span>");
            }else{
                $j(this).html(datetime);
            }
        }else{
            $j(this).html(datetime);
        }
    });        
});

function openEmail(){
    $j = jQuery.noConflict();
    var domain = "http://www.tuanvietnam.net";
    var urlsegment = $j("#CtxURLSegment").html();
    var title = $j("#CtxTitle").html();
    title = title.replace("?","");
    windowHandle = window.open(domain+"/send2friends?link="+urlsegment+"&title="+title,
    "Email","location=no,height=650,width=450");
}

function statistics(){
    /* statistics */
    var url = $j("#CtxURLSegment").html();
    var id = $j("#CtxId").html();
    new Ajax.Request(url+'/statistics?statistics=1&ajax=1&pageid='+id);
}




