function sgxGetCacheKiller() {
    return new Date().getTime();
}

function $onLoad(f) { window.addEvent('domready', f); }

// type: 1:elements, 2:attribute, 3:text etc.
function sgxIterateChildren(node, type, func)
{
    if (!node) return;

    if (node.hasChildNodes) {
		for (var i = 0; i < node.childNodes.length;i++) {
            sgxIterateChildren(node.childNodes[i], type, func);
		}
        if (node.nodeType == type) func(node);
    }
}

function sgxIterateChildrenByClass(node, classname, func)
{
    if (!node) return false;

    if (node.hasChildNodes) {
		for (var i = 0; i < node.childNodes.length;i++) {
            sgxIterateChildrenByClass(node.childNodes[i], classname, func);
		}
        if (node.nodeType == 1 && node.className.match(classname)) {
       		func(node);
        }
    }
    return true;
}

function sgxHiliteSearches(content) {
    var query = window.location.search;

    if (typeof decodeURI != 'undefined'){
        query = decodeURI(unescape(query))
    }
    else {
        return false
    }
	
    if (query) {
        var qfinder = new RegExp()
        qfinder.compile("hilight=([^&]*)", "gi")
        qq = qfinder.exec(query)

        if (qq && qq[1]){
            query = qq[1]

            if (!query) return false;
            var queries = query.replace(/\+/g,' ').split(/&/);
            var word;

            var func = function(node) {
                var i = node.nodeValue.toLowerCase().indexOf(word.toLowerCase())
                if (i != -1) {
                    if (node.parentNode.className != "searchhl") {
                        par = node.parentNode;
                        contents = node.nodeValue;

                        hiword = document.createElement("span");
                        hiword.className = "searchhl";
                        hiword.appendChild(document.createTextNode(contents.substr(i, word.length)));

                        par.insertBefore(document.createTextNode(contents.substr(0, i)), node);
                        par.insertBefore(hiword, node);
                        par.insertBefore(document.createTextNode(contents.substr(i + word.length)), node);

                        par.removeChild(node);
                    }
                }
            }

            for (var q = 0; q < queries.length;q++) {
                word = queries[q];
                sgxIterateChildren(content, 3, func);
            }
        }
    }
    return false;
}

$onLoad(function() {
	sgxHiliteSearches($('content'));
})

// element-id, diff to screen-size
function sgxAutoResize(element, dist)
{
	var min_height;
	var el;

	function setHeight()
	{
		var h = window.getHeight() - dist;
		if (h < min_height) h = min_height;
		el.style.height = h + "px";
		return false
	}

	$onLoad(function() {
		el = $(element);
		min_height = el.offsetHeight
		window.addEvent("resize", setHeight)
		setHeight()
	})
}


function regInlineInfo(name, info_text) {
	var el = $(name)
	el.onfocus = function() {
		if (el.value == info_text) {
			// if (el.was_pw) el.type = "password"
			el.style.color = "black"
			el.value = ""
		}
	}
	el.onblur = function() {
		if (el.value == "") {
			/*if (!is_ie && el.type == "password") {
				el.type = "text"
				el.was_pw = true
			}*/
			el.value = info_text
			el.style.color = "#aaa"
		}
	}
	el.value = ""
	el.onblur()
}


function Img(src1, src2) {
	this.src1 = src1;
	this.src2 = src2;
}

var js_imgs = {};

function lowlite(id) {
	$("img_" + id).src = js_imgs[id].src1;
}

function hilite(id) {
	$("img_" + id).src = js_imgs[id].src2;
}


