function preloader() {
    // counter
    var i = 0;
    //create object
    imageObj = new Array(13);
    //set image list
    images = new Array();
    images[0] = "http://www.popgraph.com/images/mid-vs-active.gif";
    images[1] = "http://www.popgraph.com/images/vs_active.png";
    images[2] = "http://www.popgraph.com/images/small-vs-button_active.gif";
    images[3] = "http://www.popgraph.com/images/people_active.gif";
    images[4] = "http://www.popgraph.com/images/movies_active.gif";
    images[5] = "http://www.popgraph.com/images/music_active.gif";
    images[6] = "http://www.popgraph.com/images/tv_active.gif";
    images[7] = "http://www.popgraph.com/images/games_active.gif";
    images[8] = "http://www.popgraph.com/images/sports_active.gif";
    images[9] = "http://www.popgraph.com/images/books_active.gif";
    images[10] = "http://www.popgraph.com/images/science-&-nature_active.gif";
    images[11] = "http://www.popgraph.com/images/computers_active.gif";
    images[12] = "http://www.popgraph.com/images/food-&-Drink_active.gif";
    //start preloading
    for (i = 0; i <= 12; i++) {
        imageObj[i] = new Image();
        imageObj[i].src = images[i];
    }
}

function mousehover(obj, image) {
    document.getElementById(obj).src = 'http://www.popgraph.com/images/' + image;  //vs_active.png';
}
function mousedown(obj, image) {
    document.getElementById(obj).src = 'http://www.popgraph.com/images/' + image; //vs_pressed.png';
}

function mouseup(obj, image) {
    document.getElementById(obj).src = 'http://www.popgraph.com/images/' + image; //vs_active.png';
}
function mouseout(obj, image) {
    document.getElementById(obj).src = 'http://www.popgraph.com/images/' + image; //vs.png';
}

/*Validation for upload Avatar */
//Javascript to check for the file whether it is image or not
function CheckFileIsImage() {
    var fileTypes = "jpg";  //["bmp", "gif", "png", "jpg", "jpeg"];
    var fileTypesec = "jpeg";
    //var msgFileExtension = "Invalid File. Only bmp, gif, png, jpg files are allowed.";
    var source = document.getElementById("FileUploadPhoto").value;
    var ext = source.substring(source.lastIndexOf(".") + 1, source.length).toLowerCase();
    if (fileTypes == ext || fileTypesec == ext)
        return true;
    else {
        document.getElementById("LabelUpload").innerHTML = "Invalid File. Only jpg files are allowed.";
        return false;
    }
}


/* script method for follow /stop following cases in topics pages */
var link;
var follow;
function following(id, follower) {
    follow = follower;
    link = id;
    var fbid = document.getElementById("HiddenID").value;

    PopGraph.handlers.ajax.user.followTopic(fbid, onFollowCompleteGetStatus, onFollowFailed);
    return false;
}
//method for follow topic
function onFollowCompleteGetStatus(result) {
    if (result == "StopFollowing" || result == "Following") {

        if (result == "Following") {
            document.getElementById(link).innerHTML = "<img id='ImgStopFollow' src='http://www.popgraph.com/images/stop-following-btn.gif' height='21px' width='95px' alt='' onmouseover=\"mousehover(this.id,'stop-following-over.gif');\" onmouseout=\"mouseout(this.id,'stop-following-btn.gif');\" onmousedown=\"mousedown(this.id,'stop-following-pressed.gif');\" onmouseup=\"mouseup(this.id,'stop-following-over.gif');\" />";

        }
        else {
            document.getElementById(link).innerHTML = "<img id='ImgFollow' src='http://www.popgraph.com/images/follow-btn.gif' height='21px' width='48px' alt='' onmouseover='mousehover(this.id,'follow-hover.gif');' onmouseout='mouseout(this.id,'follow-btn.gif');' onmousedown='mousedown(this.id,'follow-pressed.gif');' onmouseup='mouseup(this.id,'follow-hover.gif');' />";

        }
        document.getElementById(link).focus();
        //link.InnerHtml = "<img id='ImgStopFollow' src='images/stop-following-btn.gif' height='21px' width='95px' alt='' onmouseover=\"mousehover(this.id,'stop-following-over.gif');\" onmouseout=\"mouseout(this.id,'stop-following-btn.gif');\" onmousedown=\"mousedown(this.id,'stop-following-pressed.gif');\" onmouseup=\"mouseup(this.id,'stop-following-over.gif');\" />";
        var fbid = document.getElementById("HiddenID").value;

        PopGraph.handlers.ajax.user.getTopicFollowingCount(fbid, onGetFollowCountComplete, onFollowFailed);
    }
    else {
        // alert("You must be logged in to use this feature.");
        $find('Login_ModalPopupExtenderRegistrationLogin').show();
    }
}
//method for follow topic when  failed(exceptiion occured)
function onFollowFailed(result) {
    alert(result);

}

//method for get follow count  sussess
function onGetFollowCountComplete(result) {
    document.getElementById("FollowersLabel").innerHTML = result;
    if (follow == "follow") {
        document.getElementById("TotalFolowerCount").innerHTML = result;
        loadFollowersData(1);
    }
}

//method for save the comment for popgraph page
function saveComment() {
    if (document.getElementById("comments_TextBoxComment").value != "") {
        var commenttext = document.getElementById("comments_TextBoxComment").value;
        var fbid = document.getElementById("HiddenID").value;
        var url = document.getElementById('comments_HiddenUrl').value;
        PopGraph.handlers.ajax.user.commentTopic(fbid, commenttext, url, onSaveCommentStatus, onFollowFailed);
    }
    else {
        document.getElementById("SpanCommentmessage").innerHTML = "Please enter comment.";
    }
    return false;
}
function onSaveCommentStatus(result) {
    if (result) {
        $find('comments_ModalPopUpComment').hide();
        loadCommentData(1);
        document.getElementById("comments_commentlink").focus();
    }
    else
        document.getElementById("SpanCommentmessage").innerHTML = "Problem occured while saving the record";
}

/* function for remove the friend */
function removefriend(friendid) {
    PopGraph.handlers.ajax.user.removeFriend(friendid, onRemoveStatus, onFollowFailed);
    return false;
}

function onRemoveStatus(result) {

    if (result >= 0) {
        document.getElementById("TotalFriendControlCount").innerHTML = result;
        loadFriendData(1);
    }
    else
        alert("Problem occured while delete the record");
}

/*function for add the friend */
var AddLinkId = null;
function addfriends(friendid, LinkId) {
    AddLinkId = LinkId;
    PopGraph.handlers.ajax.user.addFriends(friendid, onAddfriendStatus, onFollowFailed);
}

function onAddfriendStatus(result) {
    if (result) {
        //loadFriendData(1);
        document.getElementById(AddLinkId).innerHTML = "<img id=\"imgremovefriend\" src=\"/images/remove-btnFri.gif\" width=\"114\" height=\"21\" onmouseover=\"mousehover(this.id, 'remove-overfri.gif');\" onmouseout=\"mouseout(this.id, 'remove-btnFri.gif');\" onmousedown=\"mousedown(this.id, 'remove-pressedfri.gif');\" onmouseup=\"mouseup(this.id, 'remove-overfri.gif');\" />";
        //alert("Member has been added successfully in friend list");
    }
    else
        document.getElementById(AddLinkId).innerHTML = "<img id=\"addfriend\" src=\"/images/add-as-friend.gif\" width=\"101\" height=\"21\" onmouseover=\"mousehover(this.id, 'add-as-friend-over.gif');\" onmouseout=\"mouseout(this.id, 'add-as-friend.gif');\" onmousedown=\"mousedown(this.id, 'add-as-friend-pressed.gif');\" onmouseup=\"mouseup(this.id, 'add-as-friend-over.gif');\" />";
    //alert("This member already in you friend list.");
}


/* function for stop following in user section on user following control*/
function stopFollowingTopic(TopicId) {
    PopGraph.handlers.ajax.user.stopfollowTopic(TopicId, onStopFollowingStatus, onFollowFailed);
    return false;
}

function onStopFollowingStatus(result) {

    if (result) {
        loadTopicData(1);
    }
    else
        alert("Problem occured while delete the record");
}


//method for vote on topic
/*var voteStatus = true;
function Voting() {
var isLogin = '<%= Session["PopgraphUID"]%>';
alert(isLogin);
if (isLogin == "" || isLogin == null) {
$find('Login_ModalPopupExtenderRegistrationLogin').show();
return false
}
else
return true;


/*PopGraph.handlers.ajax.user.checkUserLogin(onVoteCompleteGetStatus, onFollowFailed);
alert(voteStatus);
if (voteStatus)
return false;
else
return true ;
}*/
//method for vote on topic
/*function onVoteCompleteGetStatus(result) {
if (result)
voteStatus = false;
else {
$find('Login_ModalPopupExtenderRegistrationLogin').show();
voteStatus = true;
}
}*/

/* method for vote on contest page*/
var argsVote;
function ContestVotes(args) {
    argsVote = args;
    var contestId = document.getElementById("HiddenID").value;
    var leftfbid = document.getElementById("HiddenLeftId").value;
    var rightfbid = document.getElementById("HiddenRightId").value;
    PopGraph.handlers.ajax.user.ContestVote(args, contestId, leftfbid, rightfbid, onContestVoteCompleteStatus, onFollowFailed);

}
function onContestVoteCompleteStatus(result) {    
    if (result) {
        if (argsVote == "LEFT")
            document.getElementById("LeftVoteCount").innerHTML = result;
        if (argsVote == "RIGHT")
            document.getElementById("RightVoteCount").innerHTML = result;
    }
    document.getElementById("LinkLeftVote").style.display = 'none';
    document.getElementById("LinkRightVote").style.display = 'none';
    document.getElementById("labelVoteCounted").innerHTML = "<font color='red'>Vote Counted!</font>";
}