/*
    (c) 2004 - Rikard Bartholf, <rikard.bartholf@benzler.se>                  
    Benzler Data AB

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

/**
 * methods that helps working with different aspects of DOM
 */
function EventParser(e) {
    this.e = (e) ? e : window.event;
    this.target = (document.all) ? this.e.srcElement : this.e.target;
}
/**
 * makes an element
 */
function makeElement(instrTagName, instrInnerText) {
    var objElement = document.createElement(instrTagName);
    if( instrInnerText )
        objElement.appendChild(document.createTextNode(instrInnerText + ""));
    return objElement;
}
/**
 * adds an attribute to an element
 */
function addAttributeToElement(inobjElement, instrAtr, instrVal) {
    inobjElement.setAttribute(instrAtr, instrVal);
}
/**
 * returns an array of all document elements with passed classname
 *
 * @param   className
 * @param   container   if omitted, the whole document is searched
 * @return  Array
 */
function getElementsByClassName(className, container) {
    container = container || document;
    var all = container.all || container.getElementsByTagName('*');
    var arr = new Array();
    for(var k=0;k<all.length;k++)
        if(all[k].getAttribute("className") == className
           || all[k].getAttribute("class") == className
        )
            arr[arr.length] = all[k];
    return arr;
}
/**
 * returns an array of all document elements with passed classname
 *
 * @param   className
 * @param   container   if omitted, the whole document is searched
 * @return  Array
 */
function getElementsByPrefixedClassName(instrPrefix, container) {
    container = container || document;
    var all = container.all || container.getElementsByTagName('*');
    var arr = new Array();
    var strClass;
    for(var k=0;k<all.length;k++) {
        strClass = all[k].getAttribute("className") || all[k].getAttribute("class") || "";
        if(strClass.indexOf(instrPrefix) == 0) {
            arr[arr.length] = all[k];
            //alert(strClass);
        }
    }
    return arr;
}
/*
function getElementsByPrefixedClassName(instrPrefix, container) {
    container = container || document;
    var all = container.all || container.getElementsByTagName('*');
    var arr = new Array();
    var strClass;
    for(var k=0;k<all.length;k++) {
        strClass = all[k].getAttribute("className") || all[k].getAttribute("class") || "";
        if(strClass.indexOf(instrPrefix) == 0
           || strClass.indexOf(instrPrefix) == 0
        )
            arr[arr.length] = all[k];
    }
    return arr;
}
*/


/**
 * returns an array of all document elements with passed classname
 *
 * @param   className
 * @param   container   if omitted, the whole document is searched
 * @return  Array
 */
function getFormElementsByName(inobjForm, instrName) {
    var arr = new Array();
    var strClass;
    for(var k=0;k<inobjForm.elements.length;k++) {
        if(inobjForm.elements[k].name == instrName)
            arr[arr.length] = inobjForm.elements[k];
    }
    return arr;
}
/**
 * returns an array of all document elements with passed classname
 *
 * @param   className
 * @param   container   if omitted, the whole document is searched
 * @return  Array
 */
function getFormElementsByPrefixedName(inobjForm, instrPrefixName) {
    var arr = new Array();
    var strClass;
    for(var k=0;k<inobjForm.elements.length;k++) {
        if(inobjForm.elements[k].name.indexOf(instrPrefixName) == 0)
            arr[arr.length] = inobjForm.elements[k];
    }
    return arr;
}
/**
 *
 */
function getCSSAttribute(inObj, instrAttribute) {
    if(is.msie) return eval("inObj.currentStyle." + instrAttribute);
    return eval("document.defaultView.getComputedStyle(inObj, null).getPropertyValue(\"" + instrAttribute + "\")");
}
/**
 *
 */
function Is() {
    this.msie = (navigator.appName.indexOf("Explorer")>-1)
}
var is = new Is();

/**
 *
 */
var mobjWin = null;
var mstrArgs = null;


function doPopup(instrUrl, inintWidth, inintHeight) {
    var strUrl = "";
    if(instrUrl) strUrl = instrUrl;
    mobjWin = window.open(strUrl, 'utilWin','resizable=1,scrollbars,status,width=' + inintWidth + ',height=' + inintHeight);
    mobjWin.focus();
    return true;
}

var objHidden;
var objContainer;
function execHidden(instrSrc, instrAction, inblnDO_NOT_HIDE_WINDOW) {
    /**
     * we must remove old containers in order to ensure correct value for the
     * parent.eventwin_Load attribute
     */
    if(objContainer)
        document.body.removeChild(objContainer);

    objContainer = document.createElement("div");
    if(!inblnDO_NOT_HIDE_WINDOW) objContainer.style.display = "none";
    
    var strIframe = "<iframe id=\"ifrHidden\" name=\"ifrHidden\" onload=\"if(parent.eventwin_Load)parent.eventwin_Load('" + instrAction + "');\"></iframe>";
    
    document.body.appendChild(objContainer);
    objContainer.innerHTML = strIframe;

    objHidden = document.getElementById("ifrHidden");
    objHidden.src = instrSrc;

}

function alerter() {
    alert(1)
}

var oldRow;
var oldRowClassName;
var evenRow;

function onMouseOver(tr, instrTitle) {
    if(instrTitle) {
        with(tr.style) {
            cursor = "hand";
            cursor = "pointer";
        }
        tr.title = instrTitle;
    }
    oldRowClassName = tr.className;
    oldRow = tr;
    tr.className = "altover";
    return;
}

function onMouseOut(tr) {
    if(!oldRow) return;
    oldRow.className = oldRowClassName;
    oldRow = null;
}

function onClick(tr, instrHref) {
    if(!instrHref) return;
    window.location.href = instrHref;
}

