﻿function GetCommentStream(a,uid)
        {
        if(readCookie(uid)=="1")
        {
        $.get('/Toplets/UserRatingComments2/CommentStream.aspx?aid='+uid+'&page='+a+'&rand='+Math.floor(Math.random()*100001),function(data){
        $("#CollectComments").html(data);
        });
        }else
     {
    
     $.get('/commentst?aid='+uid+'&page='+a,function(data){
        $("#CollectComments").html(data);
        });
     }
        return false;
        }
        function ShowBlock(a)
{
if($("#pop_box").html()=="")
{
$("#pop_box").html($(a).html());
$("#pop_box").css("display","block")
}else{
$("#pop_box").html("");
$("#pop_box").css("display","none")
}
return false;
}

function Link(city,arurl)
        {
        var l_city=city;
        var rurl=arurl;
        $.get('/Toplets/UserRatingComments2/LinkComments.aspx?city='+l_city+"&rurl="+rurl+"&rand="+Math.floor(Math.random()*10001),function(data){
        $("#AuthComment").html(data);
        });
        }
        
        
        
        
        
        
        function PostStory(comment_txt,comment_title,uid)
        {
        try{
            $.get('/toplets/UserRatingComments2/postuserrating.aspx?domain=MetroNews&AssetID=' + uid + '&Rating=0&rand=' + Math.floor(Math.random() * 100001), { desc: comment_txt, Title: comment_title }, function(data) {
            createCookie(uid, "1", 0.02);
            ShowBlock('#Pop_2');
            document.location=document.location;    
            });
        
        }catch(ex){}
//        if($("#Put_on_fb").attr("checked"))
//        {
//        PostStoryFB(comment_txt,comment_title);
//        //ShowBlock('#Pop_2');
//        }else{
        
       // }
        
        }
        
          function popup_alert_local(a,x)
                        {
                        alert('You cannot agree, disagree or tag offensive your own comments.');
                       //alert("You can't agree or disagree" + '\n' + "with your own comments!");
                       return false;
                        }
                        function showmessage(p,x)
                        {
                        var a='You must be logged in to agree.';
                        var d='You must be logged in to disagree.';
                        var o = 'You must be logged in to alert a moderator.';
                        var rand = parseInt(Math.random() * 10001);
                        if (x == "o") {
                            $.modal.show($("#st1").attr("value") + $("#st2").attr("value") + p + $("#st3").attr("value"));
                        } else {
                        if (x == "a") {
                            $.get("/Toplets/UserRatingComments2/PostUserCommentResponse.aspx?CommentID=" + p + "&Response=Positive&assetID=" + $("#RAid").val() + "&ra=" + rand, function(data) {
                                if (data.indexOf("unauthenticated") > -1) {
                                    eval("alert(" + x + ");");
                                } else {  GetCommentStream($("pnoa").val(), $("#RAid").val());  }
                            });
                        
                        }
                        if (x == "d") {
                            $.get("/Toplets/UserRatingComments2/PostUserCommentResponse.aspx?CommentID=" + p + "&Response=Negative&assetID=" + $("#RAid").val()+"&ra="+rand, function(data) {
                                if (data.indexOf("unauthenticated") > -1) {
                                    eval("alert(" + x + ");");
                                } else { GetCommentStream($("pnoa").val(), $("#RAid").val()); }
                            });
                        }
                           
                        }
                        return false;
                        }            
                        
                        function Mark(a,x)
                        {
                        
                        switch(x)
                        {
                        case "a":
                        MarkAgree(a);
                        break;
                        case "d":
                        MarkDisagree(a);
                        break;
                        case "o":
                        MarkOffensive(a);
                        break;
                         default:
                         break;
                        }
                        return false;
                        }
                        function MarkAgree(a)
                        {
                        //if($("#ag_"+a).html()=="")
                        //{$("#ag_"+a).html("1")}else{
                        //$("#ag_"+a).html(parseInt($("#ag_"+a).html())+1);}
                        $.get("/Toplets/UserRatingComments2/PostUserCommentResponse.aspx?CommentID="+a+"&Response=Positive&assetID="+$("#RAid").val(),function(data){
                        GetCommentStream($("pnoa").val(),$("#RAid").val());
                        });
                        return false;
                        }
                        function MarkDisagree(a)
                        {
                        //if($("#disag_"+a).html()=="")
                        //{$("#disag_"+a).html("1")}else{
                        //$("#disag_"+a).html(parseInt($("#ag_"+a).html())+1);}
                        $.get("/Toplets/UserRatingComments2/PostUserCommentResponse.aspx?CommentID="+a+"&Response=Negative&assetID="+$("#RAid").val(),function(data){
                        GetCommentStream($("pnoa").val(),$("#RAid").val());
                        });
                        return false;
                        }            
                        function MarkOffensive(a)
                        {
                        $.get("/Toplets/UserRatingComments2/PostUserCommentResponse.aspx?CommentID="+a+"&Response=Offensive&assetID="+$("#RAid").val(),function(data){
                        GetCommentStream($("pnoa").val(),$("#RAid").val());
                        });
                        return false;
                        } 
                        
                        
                        function MarkAnonymousOffensive(a)
                        {
                        $.get("/Toplets/UserRatingComments2/PostUserCommentResponse.aspx?CommentID="+a+"&Response=Offensive&assetID="+$("#RAid").val()+"&anon=1",function(data){
                        GetCommentStream($("pnoa").val(),$("#RAid").val());
                        });
                        return false;
                        }
                        
                        
                        
/*=========================FACEBOOK CODE======================*/
function Metro_FbLogin(a)
{Metro_FbLogin()}
function Metro_FbLogout(a)
{Metro_FbLogout()}
function Metro_FbLogin()
{


FB.Connect.get_status().waitUntilReady(function(status){
  if(status==FB.ConnectState.connected){ShowBlock("#Pop_4");}
  else{
   FB.Connect.requireSession(function()
                             {
                              FB.Facebook.apiClient.users_hasAppPermission('publish_stream',function(result){});
                               
                              },null,true);
  
      }
});
//}catch(e){window.setTimeout('',5000);Metro_FbLogin();}

return false;
}
function Metro_FbLogout()
{
FB.Connect.logout(function(){document.location=document.location;});
return false;
}

/*=====================GOOGLE CONNECT=========================*/






function RenderUserData(userArr)
{
try{
var req = opensocial.newDataRequest();
var idspec1=opensocial.newIdSpec({'userId':userArr})
//var idspec2=opensocial.newIdSpec(opensocial.Person.Field.PROFILE_URL);


var fetchPersonRequest1 = req.newFetchPeopleRequest(idspec1);
//var fetchPersonRequest2 = req.newFetchPeopleRequest(idspec2);

req.add(fetchPersonRequest1, "people");
//req.add(fetchPersonRequest2, "people");
req.send(function (data) {
var people = data.get("people").getData();
people.each(function(friend){
var ID=friend.getId();
$(".gfc_"+ID).html("<img src='"+friend.getField(opensocial.Person.Field.THUMBNAIL_URL)+"' style='height:48px;width:48px;'/><br/>"+friend.getDisplayName());


});
});
}catch(e){

}
}
function CheckforLogStatus()
{
var req = opensocial.newDataRequest();
var fetchPersonRequest1 = req.newFetchPeopleRequest(opensocial.newIdSpec({"userId":"VIEWER"}));
req.add(fetchPersonRequest1, "people");
req.send(function (data) {
var person=data.get("people").getData();
if(person==null){document.location=document.location;}else{ShowBlock("#Pop_5");}
});
}



function Metro_SNLogin()
{
var l_in=document.cookie.indexOf("fcauth",0);
var req = opensocial.newDataRequest();
var fetchPersonRequest1 = req.newFetchPeopleRequest(opensocial.newIdSpec({"userId":"VIEWER"}));
req.add(fetchPersonRequest1, "people");
req.send(function (data) {
var person=data.get("people").getData();
if(person==null){google.friendconnect.requestSignIn();}else{ShowBlock("#Pop_5");}
});
return false;
}
function Metro_SNLogout()
{
google.friendconnect.requestSignOut();
return false;
}