function in_array(search_phrase, array)
{
    for( var i = 0; i < array.length; i++ ) {
        if( search_phrase == array[i] ){
            return true;
        }
    }
    return false;
}


var Class = {
  create: function() {
    return function() {
      this.initialize.apply(this, arguments);
    }
  }
}

function getParentTag(obj, tag)
{
    var tmp = obj;
    while (tmp = tmp.parentNode) {
        if (tmp.nodeName == tag) {
            return tmp;
        }
    }
    return null;
}

function getPreviousTag(obj, tag)
{
    var tmp = obj;
    while (tmp = tmp.previousSibling) {
        if (tmp.nodeName == tag) {
            return tmp;
        }
    }
    return null;
}

function openPopupByLocation(location, target, pW, pH)
{
    if (typeof pW != 'number') {
        pW = screen.width/2;
    }
    if (typeof pH != 'number') {
        pH = screen.height - screen.height/3;
    }
    var top = screen.height/2-pH/2;
    var left = screen.width/2-pW/2;
    var params = 'toolbar=0,location=0,menubar=0,resizable=1,status=0,scrollbars=yes,screenX='
        +left+',screenY='+top+',top='+top+',left='+left
        +',width='+pW+',height='+pH;
    var wnd = window.open(location, target, params);
        wnd.opener = self;
        wnd.focus();
}

function openPopup(a, pW, pH)
{
    openPopupByLocation(a.href, a.getAttribute('target'), pW, pH);
    return false;
}

function getElementPos(obj)
{
    var l = 0;
    var t = 0;
    var w = obj.offsetWidth;
    var h = obj.offsetHeight;
    while (obj) {
        l += obj.offsetLeft;
        t += obj.offsetTop;
        if ((obj.tagName != "TABLE") && (obj.tagName != "BODY")) {
            l += (obj.clientLeft)?obj.clientLeft:0;
            t += (obj.clientTop)?obj.clientTop:0;
        }
        obj = obj.offsetParent;
    }
    var res = new Object();
    res.x = l;
    res.y = t;
    res.left = l;
    res.top = t;
    res.w = w;
    res.h = h;
    res.width = w;
    res.height = h;
    return res;
}

function urlencode (str) {
    // URL-encodes string
    //
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/urlencode
    str = (str+'').toString();
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
                                                                    replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}

function urldecode (str) {
    // Decodes URL-encoded string
    //
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/urldecode
    return decodeURIComponent(str.replace(/\+/g, '%20'));
}

// {{{ number_format
function number_format( number, decimals, dec_point, thousands_sep ) {
    // Format a number with grouped thousands
    //
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_number_format/
    // +       version: 809.2411
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // *     example 1: number_format(1234.5678, 2, '.', '');
    // *     returns 1: 1234.57

    var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
    var d = dec_point == undefined ? "." : dec_point;
    var t = thousands_sep == undefined ? "," : thousands_sep, s = n < 0 ? "-" : "";
    var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;

    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}// }}}

