﻿// JScript File
    
    function clickButton(e, buttonid){ 
      var bt = document.getElementById(buttonid); 
      if (typeof bt == 'object'){ 
            if(navigator.appName.indexOf("Netscape")>(-1)){ 
                  if (e.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
            if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
                  if (event.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
      }
    } 
    
    function getObj(objId){
        for(i=0; i<document.forms[0].elements.length;i++){
            if(document.forms[0].elements[i].id.replace(objId,"") != document.forms[0].elements[i].id){
                return document.forms[0].elements[i];
            }
        }
    }
    
    function hideShowObject(objId)
    {
        var Element;
        
        Element = document.getElementById(objId);
        
        if(Element.style.display != 'block')
            Element.style.display = 'block';
        else
            Element.style.display = 'none';
    }
    
    //Posting in community    
    function addSmiley(smileyObj, txtBoxName){
        var smileySymbol = smileyObj.title;

        var textBox = getObj(txtBoxName);//"txtReplyMessage"
        
        addTextToTextBox(textBox,smileySymbol);
    }
    
    function addTextToTextBox(inTxtBox, inTxtValue)
    {
        if (inTxtBox != null)
        {   
            //IE
            if((clientVer >=4) && is_ie && is_win){
                inTxtBox.focus();
                var sel = document.selection.createRange();
                sel.text = inTxtValue;
                sel.collapse(true);
                sel.select();
            }//Mozilla
            else {
                var selLength = inTxtBox.textLength;
                var selStart = inTxtBox.selectionStart;
                var selEnd = inTxtBox.selectionEnd;
                 
                if (selEnd == 1 || selEnd == 2){
                   selEnd = selLength;}
                    
                var startString = (inTxtBox.value).substring(0,selStart);
                var selectedString = (inTxtBox.value).substring(selStart, selEnd)
                var endString = (inTxtBox.value).substring(selEnd, selLength);
                 
                inTxtBox.value = startString + inTxtValue + endString;
            }
         
        }
    }
   
    function addFormation(formatObj, txtBoxName){
        var startTag = "[" + formatObj.title + "]";
        var endTag = "[/" + formatObj.title + "]";
        var theSelection = false;

        var textBox = getObj(txtBoxName); // txtReplyMessage
    
        if (textBox != null){
            if((clientVer >=4) && is_ie && is_win){
                theSelection = document.selection.createRange().text;
                if(theSelection){
                    document.selection.createRange().text = startTag + theSelection + endTag;
                    textBox.focus();
                    theSelection = "";
                    return;
                }
            }
            else if(textBox.selectionEnd && (textBox.selectionEnd - textBox.selectionStart > 0)){
                cutter(textBox,startTag,endTag);
                return;
            }
            textBox.value += startTag + endTag;
            textBox.focus();
            return;
        }
    }
        
    function cutter(txtarea, open, close)
    {
         var selLength = txtarea.textLength;
         var selStart = txtarea.selectionStart;
         var selEnd = txtarea.selectionEnd;
         
         if (selEnd == 1 || selEnd == 2){
            selEnd = selLength;}
            
         var startString = (txtarea.value).substring(0,selStart);
         var selectedString = (txtarea.value).substring(selStart, selEnd)
         var endString = (txtarea.value).substring(selEnd, selLength);
         
         txtarea.value = startString + open + selectedString + close + endString;
         return;
    }
    function uploadAvatar()
    {
        var height = 220;
        var width = 555;
        
        openPopup(width, height, '../common/uploadAvatarPopup.aspx','Uppload_Avatar','no','no'); 
    }
    function addAttribute()
    {
        var height = 150;
        var width = 555;
        
        openPopup(width, height, 'addAttributePopup.aspx','Add_Education','no','no'); 
    }
    function addEducation()
    {
        var height = 490;
        var width = 555;
        
        openPopup(width, height, 'addEducationPopup.aspx','Add_Education','no','no'); 
    }
    
    function editScheduleComment(inScheduleReplyId)
    {
        var height = 290;
        var width = 555;
        
        openPopup(width, height, 'editScheduleCommentPopup.aspx?ScheduleId=' + inScheduleReplyId + "&type=edit",'EditScheduleComment','no','no'); 
    } 
    function editScheduleCommentAdmin(inScheduleReplyId)
    {
        var height = 375;
        var width = 555;
        
        openPopup(width, height, 'editScheduleCommentPopup.aspx?ScheduleId=' + inScheduleReplyId + "&type=edit",'EditScheduleComment','no','no'); 
    }
    
    
    
    function editBlog(inBlogId)
    {
        var height = 290;
        var width = 555;
        
        openPopup(width, height, 'editBlogPopup.aspx?blogId=' + inBlogId + "&type=edit",'Editblog','no','no'); 
    } 
    
    function editBlogReply(inBlogId)
    {
        var height = 375;
        var width = 555;
        
        openPopup(width, height, 'editBlogPopupReply.aspx?blogId=' + inBlogId + "&type=edit",'Editblog','no','no'); 
    }

    
    function editBlogAdmin(inBlogId)
    {
        var height = 375;
        var width = 555;
        
        openPopup(width, height, 'editBlogPopup.aspx?blogId=' + inBlogId + "&type=edit",'Editblog','no','no'); 
    }
    function editBlogAdminReply(inBlogId)
    {
        var height = 375;
        var width = 555;
        
        openPopup(width, height, 'editBlogPopupReply.aspx?blogId=' + inBlogId + "&type=edit",'Editblog','no','no'); 
    }
    
    
     
    function editPost(inReplyId)
    {
        var height = 290;
        var width = 555;
        
        openPopup(width, height, 'editPostPopup.aspx?replyId=' + inReplyId + "&type=edit",'Editpost','no','no'); 
    }
    
    function addTags(inGameId)
    {
        var height = 560;
        var width = 170;
        
        openPopup(width, height, 'addTagsPopup.aspx?gameId=' + inGameId,'AddTagToGame','no','no'); 
    }
    
    function seeGameDescriptionHistory(inGameId)
    {
        var height = 500;
        var width = 370;
        
        openPopup(width, height, 'boardGameDescriptionHistoryPopup.aspx?gameId=' + inGameId,'AddTagToGame','yes','no'); 
    }
    
    function addBlogTags(inBlogId)
    {
        var height = 560;
        var width = 170;
        
        openPopup(width, height, 'addBlogTagsPopup.aspx?blogId=' + inBlogId,'AddTagToBlog','no','no'); 
    }
    
    function editPostAdmin(inReplyId)
    {
        var height = 375;
        var width = 555;
        
        openPopup(width, height, 'editPostPopup.aspx?replyId=' + inReplyId + "&type=edit",'Editpost','no','no'); 
    }
    
    function moveThreadAdmin(inThreadId)
    {
        var height = 780;
        var width = 235;
        
        openPopup(width, height, 'threadMovePopup.aspx?threadId=' + inThreadId,'MoveThread','no','no'); 
    }
    
    function editThread(inThreadId)
    {
        var height =170;
        var width = 555;
        
        openPopup(width, height, 'editThreadPopup.aspx?threadId=' + inThreadId + "&type=edit",'EditThread','no','no'); 
    }
    
    function editForum(inForumId)
    {
        var height =170;
        var width = 555;
        
        openPopup(width, height, 'editForumPopup.aspx?forumId=' + inForumId + "&type=edit",'EditThread','no','no'); 
    }
    
    function addVoteSystemToThread(inThreadId)
    {
        var height = 470;
        var width = 550;
        
        openPopup(width, height, 'addVoteModulePopup.aspx?threadId=' + inThreadId,'Röstsystem','no','no'); 
    }
    
    function openPopup(width, height, url, title, scrollbars, resizable)
    {   
        height += 32;
        width += 96;
        
        wleft = (screen.width - width) / 2;
        wtop = (screen.height - height) / 2;
        var win = window.open(url,
          title,
          'width=' + width + ', height=' + height + ', ' +
          'left=' + wleft + ', top=' + wtop + ', ' +
          'location=no, menubar=no, ' +
          'status=no, toolbar=no, scrollbars=' + scrollbars + ', resizable=' + resizable);

        win.resizeTo(width, height);

        win.moveTo(wleft, wtop);
        win.focus();
    }
    
    function qSearch()
    {
        var searchBox = getObj("txtSearchWord");
        
        if (searchBox.value.length > 0)
            window.location = qSearchAdr + "?qSearchWord=" + searchBox.value;
    }
    function askUser(inQuestion)
    {
        return window.confirm(inQuestion);
    }
    function validateDates(fromYear, fromMonth, toYear, toMonth)
    {
        if(fromYear > toYear)
            return false;
        else if(fromYear == toYear && fromMonth > toMonth)
            return false;
            
        return true;
    }
    

