//Develop:Yaron[NoCheck] Date:07/09/2009 15:39:24 Ticket:
var AdditionalCategories = {
    id: 'ctl00_ctl00_BasicMasterPage_dvAdditionalCategories', isOnLi: false, isOnMenu: false,
    Start: function() { AdditionalCategories.isOnLi = true; var pos = GetElementPos('ctl00_ctl00_BasicMasterPage_tabHeaderTabs_TabsMenuOnMouseOver_liNoneActive'); $get(AdditionalCategories.id).style.left = pos[0] - 140 + "px"; $get(AdditionalCategories.id).style.top = Number(pos[1]) + Number(47) + "px"; show(AdditionalCategories.id); },
    Close : function(){var t = setTimeout("AdditionalCategories.Dispose();",500);},
    Dispose : function(){if ((AdditionalCategories.isOnMenu == false) && (AdditionalCategories.isOnLi == false))hide(AdditionalCategories.id);}
}
var AdditionalGiantCategories = {
    id: 'ctl00_BasicMasterPage_dvAdditionalCategories', isOnLi: false, isOnMenu: false,
    Start: function() { AdditionalGiantCategories.isOnLi = true; var pos = GetElementPos('ctl00_BasicMasterPage_tabHeaderTabs_TabsMenuOnMouseOver_liNoneActive'); $get(AdditionalGiantCategories.id).style.left = pos[0] - 140 + "px"; $get(AdditionalGiantCategories.id).style.top = Number(pos[1]) + Number(47) + "px"; show(AdditionalGiantCategories.id); },
    Close: function() { var t = setTimeout("AdditionalGiantCategories.Dispose();", 500); },
    Dispose: function() { if ((AdditionalGiantCategories.isOnMenu == false) && (AdditionalGiantCategories.isOnLi == false)) hide(AdditionalGiantCategories.id); }
}
function NewsFavoriteAuthorRemove(id){                                                         
    $.ajax('NewsFavoriteAuthorRemove', {postBody:"AuthorID=" + id, onSuccess : function(html, state){            
        if (state){
            $("ctl00_ctl00_BasicMasterPage_dvFavoriteAuthors").innerHTML = html.getHTML('NewsFavoriteAuthor');
        }
    }});
}
function NewsGiantFavoriteAuthorRemove(id,container) {
    $.ajax('NewsFavoriteAuthorRemove', { postBody: "AuthorID=" + id, onSuccess: function(html, state) {
        if (state) {
            $(container).hide();
        }
    }
    });
} 
function NewsFavoriteCategoryRemove(id){
    $.ajax('NewsFavoriteCategoryRemove', { postBody: "NewsTypeID=" + id, onSuccess: function(html, state) {
        if (state){
            $("ctl00_ctl00_BasicMasterPage_dvFavoriteCategories").innerHTML = html.getHTML('NewsFavoriteCategories');
        }
    }});
}
function NewsGiantFavoriteCategoryRemove(id,container) {
    $.ajax('NewsFavoriteCategoryRemove', { postBody: "NewsTypeID=" + id, onSuccess: function(html, state) {
    if (state) {
        $("ctl00_ctl00_BasicMasterPage_dvFavoriteCategories").innerHTML = html.getHTML('NewsFavoriteCategories');
        }
    }
    });
}  
function VoteForArticle(vote){                                                                
    $.ajax('ArticleVote', {postBody:"ArticleID=" + ArticleID + "&VoteFor=" + vote, onSuccess : function(html, state){            
        if (state){                                                                                                                                                                        
            var newValues = trim(html.split("\r\n")[1]);                        
            var VotesFor = newValues.split(",")[0];
            var VotesAgainst = newValues.split(",")[1];                                                                                                                                    
            VotesResults.VotesFor = VotesFor;
            VotesResults.VotesAgainst = VotesAgainst;                                                            
            $("spnVotesFor").innerHTML = VotesResults.VotesFor;
            $("spnVotesAgainst").innerHTML = VotesResults.VotesAgainst;                                                                                                                  
            $("ctl00_ctl00_BasicMasterPage_cphNewsMasterPage_spnVotesAgainstNotVoted").hide();
            $("ctl00_ctl00_BasicMasterPage_cphNewsMasterPage_spnVotesForNotVoted").hide();
            $("ctl00_ctl00_BasicMasterPage_cphNewsMasterPage_spnVotesForVoted").show();
            $("ctl00_ctl00_BasicMasterPage_cphNewsMasterPage_spnVotesAgainstVoted").show();
        }
    }});     
}    
function ArticleDeleteComment(id){                        
    var dvLoader = $('dvLoaderComment');
    setdvLoaderGenericHeight();
    $(dvLoader).show();    
    $.ajax('ArticleDeleteComment', { postBody:"CommentID=" + id + "&CurrentPage=" + PagingCurrentPageNewsViewArticle_Upper + "&BaseLink=" + encodeURIComponent(PagingBaseLinkOfNewsViewArticle_Upper), onSuccess : function(html, state){            
        if (state){
            $(dvLoader).hide();
            $("dvComment").innerHTML = html.getHTML('Comments');                                                              
            $("PagingBarTop").innerHTML = html.getHTML('Paging');
            $("PagingBarBottom").innerHTML = html.getHTML('Paging');
        }
    }});       
}              
function AddFavoriteCategory(id){                                                                                                                                                  
    var intH, intW;
    var element = $('ctl00_ctl00_BasicMasterPage_dvFavoriteCategories');
      
    if(element.offsetHeight) {
        intH = element.offsetHeight;
        intW = element.offsetWidth;
    }else{    
        intH = element.clientHeight;
        intW = element.clientWidth;   
    }
    var dvLoader = $('dvLoaderCatagorie');    
    dvLoader.style.left = ( Math.floor(intW /2)-8 ) + "px";
    dvLoader.style.top = (Math.floor(intH /2)-8 )+ "px";
    $(dvLoader).show();
    
        
    $.ajax('NewsFavoriteCategoryAdd', { postBody:"NewsTypeID=" + id, onSuccess : function(html, state){            
        $(dvLoader).hide();
        if (state){                                
            $get("ctl00_ctl00_BasicMasterPage_dvFavoriteCategories").innerHTML = html.getHTML('NewsFavoriteCategories');
           
            if (typeof AddFavoriteCategoryElement == 'string'){                            
                $(AddFavoriteCategoryElement).hide();
            }else{
                $("ctl00_ctl00_BasicMasterPage_hrfCategoryAddToFavorite").hide();
            }                                                                        
            ScrollToElement("ctl00_ctl00_BasicMasterPage_dvFavoriteCategories",100);
            new Effect.Highlight("ctl00_ctl00_BasicMasterPage_dvFavoriteCategories", {startcolor:'#FFFFD4',endcolor:'#ffffff',duration:1.0});            
        }
    }});               
}         


function hrfAddAuthorToFavorite(id){                                               
    var intH, intW;
    var element = $get('ctl00_ctl00_BasicMasterPage_dvFavoriteAuthors');
    if(element.offsetHeight) {
        intH = element.offsetHeight;
        intW = element.offsetWidth;
    }else{    
        intH = element.clientHeight;
        intW = element.clientWidth;   
    }
    var dvLoader = $('dvLoaderAuthor');
    dvLoader.style.left = ( Math.floor(intW /2)-8 ) + "px";        
    dvLoader.style.top = ( Math.floor(intH /2)-8 ) + "px";
    $show(dvLoader);      
    $.ajax('NewsFavoriteAuthorAdd', { postBody:"AuthorID=" + id, onSuccess : function(html, state){            
        $(dvLoader).hide();
        if (state){                                
            $("ctl00_ctl00_BasicMasterPage_dvFavoriteAuthors").innerHTML = html.getHTML('NewsFavoriteAuthor');
            if (typeof hrfAddAuthorToFavoriteElement == 'string'){
                hide(hrfAddAuthorToFavoriteElement);
                hide(spnAddAuthorToFavoriteElement);
            }else{
                $("ctl00_ctl00_BasicMasterPage_cphNewsMasterPage_hrfAddAuthorToFavorite").hide();
                $("ctl00_ctl00_BasicMasterPage_cphNewsMasterPage_spnAddAuthorToFavorite").hide();
            }
            ScrollToElement("ctl00_ctl00_BasicMasterPage_dvFavoriteAuthors", 100);
            new Effect.Highlight("ctl00_ctl00_BasicMasterPage_dvFavoriteAuthors", {startcolor:'#FFFFD4',endcolor:'#ffffff',duration:1.0});         
        }
    }});         
}                
    
function AddComment(){            
    if (!IsLogin){            
        NotLogin();
        return false;                                  
    }        
    var val = $("txtCommentAdd").value;
    if (val == "") return;
    var PostBody = ["ArticleID=" + ArticleID, "Content=" + encodeURIComponent(val), "BaseLink=" + encodeURIComponent(PagingBaseLinkOfNewsViewArticle_Upper)];

    //if ($('chkAnonymousComment')) {
        //if ($('chkAnonymousComment').checked) {
            //PostBody.push("Anonymous=1");
        //}                
    //}
    
    
    setdvLoaderGenericHeight();
    $("dvLoaderComment").show();
    $.ajax('ArticleAddComment', { postBody: PostBody, onSuccess: function(html, state) {
        $("dvLoaderComment").hide();
        $("txtCommentAdd").value = "";
        $("PagingBarTop").innerHTML = html.getHTML('Paging');
        $("PagingBarBottom").innerHTML = html.getHTML('Paging');
        $("dvComment").innerHTML = html.getHTML('Comments');

        if (html.getHTML('SortOrder').trim() == "DESC")
            ScrollToElement("dvComment", 100);
    }
    });          
}


var  VotesResults = { VotesFor : null , VotesAgainst : null }                                                                                                     
var hrfAddAuthorToFavoriteElement = "ctl00_ctl00_BasicMasterPage_cphNewsMasterPage_hrfAddAuthorToFavorite";
var spnAddAuthorToFavoriteElement = "ctl00_ctl00_BasicMasterPage_cphNewsMasterPage_spnAddAuthorToFavorite";
var AddFavoriteCategoryElement = "ctl00_ctl00_BasicMasterPage_cphNewsMasterPage_spnAddCategoryFavorites";

function EditArticle(id){
    var url = DomainURL + "News/EditArticle.aspx?ArticleID=" + id;
    MoveToPage(url);
    return false;
}
                                  
function NotLogin(){               
    $('dvNotLoggedIn').show();
    ScrollToElement('dvNotLoggedIn');
    return false;
}               
function MoveToPageLogin(url){            
    if (!IsLogin){            
        NotLogin();
        return false;                                  
    }
    window.location.href = url;
    try{$('taSendReply').focus();}catch(e){}
    return true;         
}

var MainPoll = {
Vote: function(pollId, voteBtn, options, answers) {

        if (!IsLogin) {
            window.location = "../Login.aspx";
            return;
        }
        
        selectedAnswerId = this.CheckVoteForPoll(pollId);
        var data = { PollId: pollId, SelectedAnswerId: selectedAnswerId };
        $.json('AnswerMainPoll', { url: 'Json/JsonMain.aspx?action=', postBody: data, onSuccess: function(json, state) {
            if (state) {
                $(options).hide();
                $(voteBtn).hide();
                $(answers).innerHTML = json.MainPollAnswersDisplay;
                $(answers).show();
            }
        }
        });
    },
    CheckVoteForPoll: function(pollId) {
        var Name = "ctl00$ctl00$BasicMasterPage$MainPollDisplay$MainPoll_" + pollId;
        var Options = document.getElementsByName(Name);
        for (var i = 0; i < Options.length; i++) {
            if (Options[i].checked) return Options[i].value;
        }
        $('dvNoAnswer').show();
        Effect.Pulsate('dvNoAnswer', { duration: 1.5, afterFinish: function() { $('dvNoAnswer').hide(); } });
        return false;
    }
};


var NewsEditorPost = {
    charLimit: 130,
    init: function(jsonNewsEditor) {
        Object.extend(this, jsonNewsEditor); // inserted from the server
        $(NewsEditorPost.normalModeContainer).observe('mouseover', function() {
            $(NewsEditorPost.normalModeContainer).addClassName('edit-mode')
        })
        $(NewsEditorPost.normalModeContainer).observe('mouseout', function() {
            $(NewsEditorPost.normalModeContainer).removeClassName('edit-mode')
        })
        $(NewsEditorPost.normalModeContainer).observe('click', function() {
            NewsEditorPost.editMode();
        })
        Event.observe(NewsEditorPost.txtPostId, 'keyup', NewsEditorPost.limitText);
        Event.observe(NewsEditorPost.txtPostId, 'keydown', NewsEditorPost.limitText);

    },
    setPost: function(objectType, objectId, post, postContainer, normalContainer, editContainer) {
        var data = {
            ObjectType: NewsEditorPost.moduleId,
            ObjectID: NewsEditorPost.categoryId,
            Post: $F(NewsEditorPost.txtPostId)
        }
        $.json('SetEditorPost', { url: 'json/jsonNews.aspx?action=', postBody: data, onSuccess: function(json, state) {
            if (state) {
                $(NewsEditorPost.normalModeSpnContainer).update(json.post);
                NewsEditorPost.normalMode();
            }
        }
        })
    },
    editMode: function(normalContainer, editContainer) {
        $(NewsEditorPost.txtPostId).value = $(NewsEditorPost.normalModeSpnContainer).innerHTML.trim();
        $(NewsEditorPost.normalModeContainer).hide();
        $(NewsEditorPost.editModeContainer).show();
        $(NewsEditorPost.txtPostId).focus();
    },
    normalMode: function(normalContainer, editContainer) {
        $(NewsEditorPost.normalModeContainer).show();
        $(NewsEditorPost.editModeContainer).hide();
    },
    limitText: function() {
        if ($F(NewsEditorPost.txtPostId).length > NewsEditorPost.charLimit) {
            $(NewsEditorPost.txtPostId).value = $F(NewsEditorPost.txtPostId).substring(0, NewsEditorPost.charLimit);
        }
    }





}

