﻿// Copyright (C) 2008 Deskpage
// by Johan van der Vleuten
// info@deskpage.net

/*

                    (\ /)
                    (O.o)
                    (> <)
                
This is the mighty bunny, watching over my code.


No seriously, if you want to use this javascript code,
please contact us at info@deskpage.net because it is copyrighted.

*/

/* 
Summary: Variable to determine if the Browser is IE
*/
var IE = document.all?true:false;



/* 
Summary: Used to set the Opacity of an object (object, opacity ranging from 0-100) 
*/
function setOpacity(object, opacity)
{
    if (!IE)  
    {  
        object.style.opacity = opacity / 100;
    }
    else
    {
        object.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + opacity + ");";
    }    
}
    
/* 
Summary: Used to disable selection of text
*/    
function disableSelect()
{   
    if (document.captureEvents)
    {
        document.onmousedown = function(){ return false; } ;
    }
    else
    {
        document.onselectstart = function(){ return false; } ;
    }    
}

/* 
Summary: Used to enable selection of text
*/
function enableSelect()
{ 
    if (document.captureEvents)
    {
        document.onmousedown = null;
    }
    else
    {
        document.onselectstart = null;
    }
}

/* 
Summary: Used to get the X coordinate of an object
*/
function findPosX(obj)
{
    var curleft = 0;
    
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curleft += obj.offsetLeft;
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
        
    return curleft;
}

/* 
Summary: Used to get the X coordinate of an object
*/
function findPosY(obj)
{
    var curtop = 0;
    
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    
    return curtop;
}



/* 
Summary: Used to get the X coordinate of the cursor
*/
function getX(e)
{
    if(IE){
        XCor = event.clientX + document.body.scrollLeft;
    }
    else
    {
        XCor = e.pageX; 
    } 
     
    if(XCor < 0)
    {
        XCor = 0;
    }  
}

/* 
Summary: Used to get the Y coordinate of the cursor
*/
function getY(e){
    if(IE){
        YCor = event.clientY + document.body.scrollLeft;
    }
    else
    {
        YCor = e.pageY; 
    }  
    
    if(YCor < 0){
        YCor = 0;
    }
}

/* 
Summary: Used to stop the bubbling effect trough different layers on an event
*/
function stopBubble(e)
{        
    if (!e) var e = window.event;
        e.cancelBubble = true;
        
    if (e.stopPropagation) e.stopPropagation();    
}


/* 
Summary: Used to determine if a node is a child of a parentNode
*/
function isChildNode( node, parentNode )
{
  if ( node == parentNode )
  {
    return true;
  }
  else if ( node && node.parentNode )
    return isChildNode( node.parentNode, parentNode );
  else
    return false;
}

/* 
Summary: Easier getting an object
*/
function _(object)
{
    return document.getElementById(object);
}


/* 
Summary: Checking event for enter
*/
function checkEnter(e)  //e is event object passed from function invocation
{ 
    var characterCode;

    if(e && e.which)
    { 
        e = e;
        characterCode = e.which; //character code is contained in NN4's which property
    }
    else
    {
        e = event;
        characterCode = e.keyCode; 
    }

    if(characterCode == 13)
    {         
        return true;
    }
    else
    {
        return false;
    }

}


/* The following is copyrighted by dustindiaz */

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function nl2br(s) {
  return s.replace(/\n/g,'<br />')
}





