var DOMtype = '';
if (document.getElementById) {
	DOMtype = "std";
}
else if (document.all) {
	DOMtype = "ie4";
}
else if (document.layers) {
	DOMtype = "ns4";
}
var objects = new Array();

function fetch_obj(idname, forcefetch) {

	if (forcefetch || typeof(objects[idname]) == "undefined") {
		switch (DOMtype) 		{
			case "std":
				objects[idname] = document.getElementById(idname);
			break;

			case "ie4":
				objects[idname] = document.all[idname];
			break;

			case "ns4":
				objects[idname] = document.layers[idname];
			break;
		}
	}
	return objects[idname];
}
 /*
function trhover( objid, over, out ) {

        obj = fetch_obj( objid );
	     alert(obj.className);
        if ( obj.className == out )
             obj.className = over;
        else
             obj.className = out;

        return true;
}   */

//---------------------------------------
var marked_row = new Array;

function setPointer2(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor) {
     obj = fetch_obj ( theRow );
     return setPointer(obj, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor);
}


function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function


function set_cookie(name, value, expires) {
	if (!expires) 	{
		expires = new Date();
	}
	document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() +  "; path=/";
}

function fetch_cookie(name) {
	cookie_name = name + "=";
	cookie_length = document.cookie.length;
	cookie_begin = 0;
	while (cookie_begin < cookie_length) {
		value_begin = cookie_begin + cookie_name.length;
		if (document.cookie.substring(cookie_begin, value_begin) == cookie_name) {
			var value_end = document.cookie.indexOf (";", value_begin);
			if (value_end == -1) {
				value_end = cookie_length;
			}
			return unescape(document.cookie.substring(value_begin, value_end));
		}
		cookie_begin = document.cookie.indexOf(" ", cookie_begin) + 1;
		if (cookie_begin == 0) {
			break;
		}
	}
	return null;
}

function delete_cookie(name) {
	var expireNow = new Date();
	document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}


function displayWindow(url, width, height) {

     var Win = window.open(url,"displayWindow",'width=' + width
         + ',height=' + height + ',resizable=0,scrollbars=yes,menubar=no' );

}

function setAvatar(ipath) {

    document.favatar.avatar.value = ipath;
    str = new String();
    str = ipath.slice(ipath.lastIndexOf("/")+1, ipath.lastIndexOf("."));
    alert("Ustawiłeś avatar o nazwie: \"" + str + "\"\n Jeżeli chcesz go używać to: Zapisz zmiany");

}

function avatarSubmit() {
    if (document.favatar.avatar.value == '')
       alert('Pole z adresem avatara jest puste!');
    else
        document.favatar.submit();
}

function explodeArray(item, delimiter) {

    tempArray = new Array(1);
    var Count = 0;
    var tempstring = new String(item);

    while (tempstring.indexOf(delimiter)>0) {
        tempArray[Count] = tempstring.substr(0, tempstring.indexOf(delimiter));
        tempstring = tempstring.substr(tempstring.indexOf(delimiter)+1, tempstring.length-tempstring.indexOf(delimiter)+1);
        Count = Count + 1;
    }
    tempArray[Count] = tempstring;
    return tempArray;
}



function Refresh(_url,i){
    if (i == 0) {
        location = _url;
        return 0;
    }
    i--;
    j = i;
    address = _url;
    setTimeout("Refresh(address,j)",1000);
}
