﻿
function feed(comtext) {
 
   FB.ui(
   {
       method: 'stream.publish',
       message: comtext,
       attachment: {
           name: 'MicroVolts Sneak Preview',
           caption: 'Online Multiplayer Toy Shooter',
           description: (
         'Toy figures around the planet are engaged in all out war for valuable battery resources and supremacy of the Micro World. Enlist today for a sneak preview and join the battle!'),
      
           href: 'http://www.microvolts.com',
            media: [{
           'type': 'image',
           'src': 'http://www.rockhippo.com/lib/images/home/mv_thumb.jpg',
           'href': 'http://www.microvolts.com'
        }],
       },
      
       action_links: [
       { text: 'Microvolts', href: 'http://www.microvolts.com' }
     ],
       user_prompt_message: 'Share your thoughts about MicroVolts'
   },
   function (response) {
        window.location.href = window.location.href ;
//       if (response && response.post_id) {
//           window.location.href = window.location.href ;
//         // __doPostBack("uppanelComment", "");
//         // showComDiv();
//       } else {
//           alert('Post was not published.');
//       }
   }
 );
 
 }

 function showSSPage(id) {

           var number = document.getElementById('hidPages').value;
           for (var i = 1; i <= number; i++) {
               document.getElementById('divSSpage' + i).style.display = "none";
           }
           document.getElementById('divSSpage' + id).style.display = "block";
       }

       function showTopOne(img) {

           document.getElementById('imgBigScreenShot').src = img.src
       }

       function preview() {

           var number = document.getElementById('hidPages').value;
           for (var i = 1; i <= number; i++) {
               var dispaly = document.getElementById('divSSpage' + i);
               if (dispaly.style.display == "block") {
                   if (i == 1) {
                       return;
                   }
                   else {
                       dispaly.style.display = "none"
                       document.getElementById('divSSpage' + (i - 1)).style.display = "block";

                   }
               }
           }
       }


       function next() {

           var number = document.getElementById('hidPages').value;

           for (var i = 1; i <= number; i++) {
               var dispaly = document.getElementById('divSSpage' + i);
               if (dispaly.style.display == "block") {
                   if (i == number) {
                       return;
                   }
                   else {
                       dispaly.style.display = "none"
                       document.getElementById('divSSpage' + (i + 1)).style.display = "block";
                       return;
                        
                   }
               }
           }
       }


       function showFBLoginDialog()
       {
           FB.login(function(response) {
              if (response.session) {
                if (response.perms) {
                     showCommentDialog(true);
                } else {
                  // user is logged in, but did not grant any permissions
                  // alert('2');
                }
              } else {
                // showCommentDialog(false);
              }
            }, {perms:'email,publish_stream'});
       }

        function showComDiv() {
           FB.getLoginStatus(function (response) {

                if(response.session)
                {
                
                    showCommentDialog(true);
                }
                else{
                   showCommentDialog(false);
                
                }
               
           
            });
        }

        function showCommentDialog(logined)
        {
        
            if (logined) {
                document.getElementById('mv_fb_div_not_login').style.display = 'none';
                document.getElementById('mv_fb_div_logined').style.display = 'block';
               
            } else {
                document.getElementById('mv_fb_div_not_login').style.display = 'block';
                document.getElementById('mv_fb_div_logined').style.display = 'none';
            }
        }



         function showCommentInput() {
               document.getElementById('fb_txt_msg_div').style.display='none';
               document.getElementById('fb_post_tr').style.display = 'block';
        }

       function loadAddComment(uid,ct,chk) {
           
           var ref = window.location.href.toLowerCase();
             if (ref.indexOf('.microvolts.com') == -1)
             {
                return;
             }
             var urlAction = "";
           
               var str = document.getElementById('fb_txtmsg').value ;
                var title =  document.getElementById('mv_fb_com_title').value ;
                urlAction = "http://www.microvolts.com/facebook/mvComLoginedAction.aspx?action=add&userid=" + uid + "&text=" + str + "&title=" + title + "&ct=" + ct ;
           
 
           if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
               xmlhttp = new XMLHttpRequest();
           }
           else {// code for IE6, IE5
               xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
           }
           xmlhttp.onreadystatechange = function () {
               
               if ((xmlhttp.readyState == 4 && xmlhttp.status == 200) || xmlhttp.status== 0 ) {
                   
                     if(chk)
                       {
                            feed(str);
                       }
                       else
                       {
                       //parent.
                            window.location.href = window.location.href; 
                       }
 
              }
           
           }
           xmlhttp.open("GET",urlAction , true);
           xmlhttp.send();
       }


       function loadRemoveComments(comment_id,ct) {
           var ref = window.location.href.toLowerCase();
             if (ref.indexOf('.microvolts.com') == -1)
             {
                return;
             }

            //alert('ct ' + ct);

            var urlAction = "http://www.microvolts.com/facebook/mvComLoginedAction.aspx?action=remove&comid="  + comment_id + "&ct=" + ct;
        
           if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
               xmlhttp = new XMLHttpRequest();
           }
           else {// code for IE6, IE5
               xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
           }
           xmlhttp.onreadystatechange = function () {
               //alert('status ' + xmlhttp.status);
               //alert('ready status ' + xmlhttp.readyState);
               if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    //alert('k');
                    window.location.href = window.location.href; 
              }
           
           }
           xmlhttp.open("GET",urlAction , true);
           xmlhttp.send();
       }


       function showLoginDiv() {
                alert('ok1');
           FB.getLoginStatus(function (response) {
                alert('ok');
                if(response.session)
                {
                    alert('ok ture');
                    document.getElementById('mv_fb_login_div_not_login').style.display = 'block';
                    document.getElementById('mv_fb_login_div_logined').style.display = 'none';
                }
                else
                {
                    document.getElementById('mv_fb_login_div_not_login').style.display = 'none';
                    document.getElementById('mv_fb_login_div_logined').style.display = 'block';
                }
           
            });
        }


