// jsToolPack.js
//
// a collection af JavaScript Functions that couldt be used several places 
//
// 
//

// used on onkeypress event on input-elements.
//
// arguments
//
//  functionName :  The name of the function to be run.
//  returnFalse  :  used, if the page gets submitted instead of running the JavaScript.
//

function onEnterDoJavaScriptFunction(e, functionName, returnFalse ) 
{                     
    
    var out = fixEventjsToolsPack(e);    
    if ( out.event && out.event.keyCode == 13) 
    {                
        eval(functionName+"();");        
        if ( returnFalse ) {                        
            if ( window.event ) {
                out.event.keyCode = 10;
            }
            return !returnFalse;
        }
        else 
        {
            return returnFalse;
        }        
    } 
    else 
    {
        return false;        
    }
}

function fixEventjsToolsPack(e) 
{
    
    var out = new Object();
    if (!e && window.event ) {
        
        out = window;    
    } else {
        
        out.event = e;
    }    
    return out;
}

function showHidePanel(element)
{
    var panel = document.getElementById(element);
    
    if( panel.style.visibility == "hidden") 
        { 
           panel.style.visibility = "visible";
        }
    else
        {
          panel.style.visibility = "hidden"; 
        }
}

function showHideDiv(element)
{
    var panel = document.getElementById(element);
    
    if( panel.style.display == "none") 
        { 
           panel.style.display = "block";
        }
    else
        {
          panel.style.display = "none"; 
        }
}



function showOpenElement(itemId,edit)
{
    //    var url = "modules/OpenElement/OpenElement.aspx?itemId="+itemId+"&edit="+edit;
    //    window.open(url,"OpenElement","Width=980, Height=700");    
    //    &width=980&height=700&edit=true
    openRebrandedElement(itemId);
}

function openInviteBoard(boardId) 
{
	var inviteWidth = 850;
	var inviteHeight = 445;

	var invitePosTop = ((screen.height - inviteHeight) / 2);
	var invitePosLeft = ((screen.width - inviteWidth) / 2);

	window.open('MO-InviteBoard_OpenBoard.aspx?boardId=' + boardId+'&width='+inviteWidth+'&height='+inviteHeight,'inviteWindow','toolbar=0,location=0,scrollbars=0,directories=0,status=1,menubar=0,resizable=0,minimize=0,width=' + inviteWidth + ',height=' + inviteHeight + ',left=' + invitePosLeft + ',top=' + invitePosTop + '');
}

function newOpenInviteBoard(boardId) 
{
	var inviteWidth = 850;
	var inviteHeight = 445;

	var invitePosTop = ((screen.height - inviteHeight) / 2);
	var invitePosLeft = ((screen.width - inviteWidth) / 2);
    var url = 'Modules/OpenInviteboard/OpenInviteBoard.aspx?boardId=' + boardId+'&width='+inviteWidth+'&height='+inviteHeight;
    
	window.open(url,'inviteWindow','toolbar=0,location=0,scrollbars=0,directories=0,status=1,menubar=0,resizable=0,minimize=0,width=' + inviteWidth + ',height=' + inviteHeight + ',left=' + invitePosLeft + ',top=' + invitePosTop + '');
}

function InviteBoardOpenElement(id, boardId,invitation)
{
	var openwidth = 980;
	var openheight = 700;

	var openposTop = ((screen.height - openheight) / 2);
	var openposLeft = ((screen.width - openwidth) / 2);

   	var url = "modules/OpenElement/OpenElement.aspx?inviteBoard="+ boardId + "&itemId=" + id + "&width=" + openwidth + "&height=" + openheight + "&edit=true";
	if ( invitation != '') {
	    url += "&invitation=" + invitation 
	}
	window.open(url,'OpenElement' + id,'toolbar=0,location=0,scrollbars=0,directories=0,status=0,menubar=0,resizable=0,minimize=0,width=' + openwidth + ',height=' + openheight + ',left=' + openposLeft + ',top=' + openposTop + '');
}      

function StartSearch(event)
{
    if (!event) {
        event = fixEventjsToolsPack(event);         
    }    
    if(event.which || event.keyCode)
    {
        if ((event.which == 13) || (event.keyCode == 13))
        {                           
            document.getElementById('ctl00_ctl06_SimpleSearch_ctl00_bntSearchButton_MosSmartButton_').click();                 
            return false;
        }
    } 
    else 
    {
        return true;
    } 
}

// Return false if EnterKey is hit
function disableEnterKey(e)
{
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     

     return (key != 13);
}

// returns an object with available screenWidth and screenHeight 
// This is also fitted to match every browser.
function returnScreenSize() 
{
        var myWidth = 0;
        var myHeight = 0;
        	    	    
        if( typeof( window.innerWidth ) == 'number' ) {
            //Non-IE
            myWidth = window.innerWidth;
            myHeight = window.innerHeight;
          } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
            //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth;
            myHeight = document.documentElement.clientHeight;
          } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
            //IE 4 compatible
            myWidth = document.body.clientWidth;
            myHeight = document.body.clientHeight;
          }	
          retval  = new SizeObject(myWidth , myHeight );
          return retval;
}


// Object representing a set of width and height.

function SizeObject(widthVal, heightVal) 
{
    this.width = widthVal;
    this.height = heightVal;
}
