function changeImage(imgID,newIMG) {
	window.document.images[imgID].src = newIMG.src;
}

function doShow(objectName) {
	visibleStatus(objectName, 0);
}

function doShow2(objectName) {
    myElement = document.getElementById(objectName);
    if (myElement == null) return;

    myElement.style.display = (myElement.style.display == "none" ? "" : "none");
}

function visibleStatus(objectName, force) {
	myElement = document.getElementById(objectName);
    if (myElement == null) return;

	myClass = myElement.className;
	elementFound = false;
	newClasses = "";

	while (myClass != "") {
		i = myClass.indexOf(" ");

        if (i == -1) {
            oneClass = myClass;
            myClass = "";
        }
        else {
            oneClass = myClass.substring(0,i);
            myClass = myClass.substring(i+1);
		}

		if (force == 1 || force==-1 || force==2 || force==-2) {
			oneClass = "";
		}
		else if (oneClass == "visible") {
			elementFound = true;
			oneClass = "hidden";
		}
		else if (oneClass == "hidden") {
            elementFound = true;
			oneClass = "visible";
        }

        newClasses += " " + oneClass
    }
	if (!elementFound && force==0) newClasses += " hidden";

	if (force > 0 && force != 2)  newClasses += " visible";
	if (force < 0 && force != -2) newClasses += " hidden";

	myElement.className = newClasses; //(myElement.className == 'hidden' ? 'visible' : 'hidden');
}

function showHide(object1, object2) {
    doShow(object1);doShow(object2);
}

function showHide2(object1, object2) {
    doShow2(object1);doShow2(object2);
}

document.write('<form action="" method="post" name="accessURI" class="hidden">' +
			   '<input type="hidden" name="do" value="1"></form>');

function checkTime() {
	$date = new Date();
    $day = $date.getDate();
    $month = $date.getMonth()+1;
	$hours = $date.getHours();
	$minutes = $date.getMinutes();
    $time  = $month < 10 ? "0" + $month : "" + $month;
    $time += $day < 10 ? "0" + $day : $day;
	$time += $hours < 10 ? "0" + $hours : $hours;
	$time += $minutes < 10 ? "0" + $minutes : $minutes;

	document.write('<img src="/users/settime/?time=' + $time + '" alt="" />');
}

function access(submitURI) {
	document.accessURI.action = submitURI;
	document.accessURI.submit();
}

function popupURI(uri) {
	return window.open(uri, "", "width=400,height=300,status,resizable");
}

function checkContent(textField, option1, option0) {
    document.getElementById(document.getElementById(textField).value != "" ? option1 : option0).checked = true;
}

function setAlpha(myObject, myAlpha) {
	if (typeof(myObject) == "string") myObject = document.getElementById(myObject);

	if (navigator.appName == "Netscape")
		myObject.style.MozOpacity = myAlpha/100;
	else if (myObject.filters != null) {
		if (myObject.filters.alpha == null) myObject.style.filter="alpha(opacity=" + myAlpha + ")";
		myObject.filters.alpha.opacity = myAlpha;
	}
}

function getAlpha(myObject) {
	if (typeof(myObject) == "string") myObject = document.getElementById(myObject);

	if (navigator.appName == "Netscape")
		return myObject.style.MozOpacity * 100;
	else if (myObject.filters != null) {
		if (myObject.filters.alpha == null) return 100;
		return myObject.filters.alpha.opacity;
	}
}

var effects = new Array();

function fadeAlpha(myObject, newValue, effect) {
	if (typeof(myObject) == "string") myObject = document.getElementById(myObject);
    key = myObject.id;
    keyActive = myObject.id + "_A";
    debug = false;

    if (effect == 0) {
        if (effects[key] == null) effects[key] = 0;
        if (effects[keyActive] == null) effects[keyActive] = 0;
        effect = ++effects[key];
        effects[keyActive] = 1;
    }

    curValue = getAlpha(myObject);
    diff = newValue - curValue;
    if (Math.abs(diff) < 2) {
        effects[keyActive] = 0;
        if (newValue != 100) setAlpha(myObject, newValue);  // allowing it set to 100 breaks fadeout in Firefox
        return;
    }
    if (effects[key] > effect) {
        effects[keyActive] = 0;
        return;
    }

    curValue += ((diff > 0) ? Math.max(diff / 12.5, 2) : Math.min(diff / 40, -2));
    setAlpha(myObject, curValue);

    setTimeout("fadeAlpha(\"" + myObject.id + "\", " + newValue + ", " + effect + ")", 75);
}

function setAlphaI(myObject, myObjectIE, myAlpha) {
	if (navigator.appName == "Netscape")
		myObject.style.MozOpacity = myAlpha/100;
	else {
		myObject.filters.alpha.opacity = myAlpha;
		setAlpha(document.getElementById(myObjectIE), myAlpha);
	}
}

function setAlphaA(myObject, myAlpha) {
	for (i=0; i<myObject.length; i++) {
		setAlpha(myObject[i],myAlpha);
	}
}

function gotoURI(uri) {
	window.location.href=uri;
}

function welcome(who) {
    welcome2(who, 0);
}

function welcome2(who, design) {
	var hours = (new Date()).getHours();
	var myElement = document.getElementById("welcome");

	if (who == "") {
		if (hours >= 19)
			myElement.firstChild.nodeValue = "Welcome and good evening.";
		else if (hours >= 13)
			myElement.firstChild.nodeValue = "Welcome and good afternoon.";
		else if (hours >= 10)
			myElement.firstChild.nodeValue = "Hello and welcome.";
		else if (hours >= 5)
            myElement.innerHTML = "Welcome and good morning. " + (design==2?"<img src=\"/img/interna/sun.gif\" style=\"position:relative;top:2px;\" alt=\"\">":"");
		else
			myElement.firstChild.nodeValue = "Welcome ^-^ Up late or early?";
	}
	else {
		if (hours >= 19)
			myElement.innerHTML = "Good evening, " + who;
		else if (hours >= 10)
			myElement.innerHTML = "Hello, " + who;
		else if (hours >= 4)
			myElement.innerHTML = "Good morning, " + who + (design==2?" <img src=\"/img/interna/sun.gif\" style=\"position:relative;top:2px;\" alt=\"\">":"");
		else
			myElement.firstChild.nodeValue = "Hi, " + who;
	}
}

function postSuggestion(prompttext, data) {
    var suggestion = prompt(prompttext, ''); 
    if (suggestion) {
        element = document.getElementById('suggestiondata');
        element.value=data;
        element = document.getElementById('suggestion');
        element.value=suggestion;
        element = document.getElementById('gee_es');
        if (element != null) element.value="valid";
        document.suggestionForm.submit();
    }
    return false;
}

/* generic function */

    function setText(where, what) {
	    var myElement = document.getElementById(where);
	    myElement.innerHTML = what;

	    return true;
    }

    function copyFormText(from, to) {
	    var eFrom = document.getElementById(from);
        var eTo = document.getElementById(to);
	    eTo.value=eFrom.value;

	    return true;
    }

    function addText(where, what) {
	    var myElement = document.getElementById(where);
	    myElement.innerHTML += what;
    }

    function isKey(event) {
      if (window.event)
	    key = window.event.keyCode;
      else if (event)
	    key = event.which;
      else
	    return false;

      return (key >= 32 && key <=255);
    }

    function hideElement(objectName) {
        myElement = document.getElementById(objectName);
        if (myElement != null) myElement.style.display = "none";
    }
    function showElement(objectName) {
        myElement = document.getElementById(objectName);
        if (myElement != null) myElement.style.display = "";
    }

/* affiliate mouseover effects */

    var lastAffiliate = null;
    var lastAffiliateHeight = null;
    var affState = new Array();
    var affElementHeight = new Array();

    function showAffiliate(affiliate) {
        if (affState[affiliate] == null) affState[affiliate] = 0;
        
        if (lastAffiliate != null) {
            if (affiliate == lastAffiliate) return;
            affState[lastAffiliate] = 3;
            lastAffiliateObj = document.getElementById(lastAffiliate);
            setTimeout("hideAffiliate(\"" + lastAffiliate + "\",\"" + affElementHeight[lastAffiliate] + "\")", 33);
        }
        
        if (affState[affiliate] != 0) return;
        
        lastAffiliate = affiliate;
        affState[affiliate] = 1;
        
        affiliateHeader = document.getElementById(affiliate);
        setAlpha(affiliateHeader, 1);
        affiliateHeader.style.display = "";
        if (affElementHeight[affiliate] == null) {
            if (navigator.appName == "Microsoft Internet Explorer")
                affElementHeight[affiliate] = affiliateHeader.offsetHeight - 2;
            else
                affElementHeight[affiliate] = affiliateHeader.offsetHeight - 8;
        }
        affiliateHeader.style.height = 1;
        setTimeout("fadeAffiliate(\"" + affiliate + "\",1)", 33);
    }

    function fadeAffiliate(affiliate, height) {
        affiliateHeader = document.getElementById(affiliate);
        curValue = getAlpha(affiliateHeader);
        
        if (affState[affiliate] != 1) return;
        
        affiliateHeader.style.height = height;

        if (curValue < 90) {
            setAlpha(affiliateHeader, curValue + 10);
            setTimeout("fadeAffiliate(\"" + affiliate + "\"," + Math.min(height + Math.round(affElementHeight[affiliate] / 3), affElementHeight[affiliate]) + ")", 33);
        }
        else {
            affState[affiliate] = 2;
            affiliateHeader.style.height = affElementHeight[affiliate];
            setAlpha(affiliateHeader, 99);
        }
    }

    function hideAffiliate(affiliate, height) {
        affiliateHeader = document.getElementById(affiliate);
        curValue = getAlpha(affiliateHeader);
        if (curValue > 10) {
            setAlpha(affiliateHeader, curValue - 10);
            affiliateHeader.style.height = height;
            setTimeout("hideAffiliate(\"" + affiliate + "\",\"" + Math.max(height-Math.round(affElementHeight[affiliate] / 10),33) + "\")", 33);
        }
        else {
            setAlpha(affiliateHeader, 0);
            affiliateHeader.style.display = "none";
            affState[affiliate] = 0;
        }
    }

    function getWidth() {
        if (typeof( window.innerWidth ) == 'number') {
            return window.innerWidth;
        }
        else if (document.documentElement && document.documentElement.clientWidth) {
            return document.documentElement.clientWidth;
        }
        else if (document.body && document.body.clientWidth) {
            return document.body.clientWidth;
        }
        
        return 1234;
    }

/* ajax */

    var af = {
        ajax: null,dom_content: null,dom_wait: null,return_uri: null,sending: false,postnotify: null,returnXML:false,
        failed: function() {
            if (af.dom_wait != null) af.dom_wait.innerHTML = '';
            af.sending = false;
        },
        timeout: function () {
            if (af.sending) {
                af.failed();
            }
        },
        statechange: function () {
            if (af.ajax.readyState == 4) {
                af.sending = false;
                if (af.ajax.status >= 400) {
                    alert(af.ajax.statusText);
                    af.failed();
                }
                else {
                    if (af.dom_wait) af.dom_wait.innerHTML = '';
                    af.dom_content.innerHTML = af.ajax.responseText;
                    if (af.return_uri && getWidth() <= 1024) location.href='#' + af.return_uri;
                }
            }
        },
        poststatechange: function () {
            if (af.ajax.readyState == 4) {
                af.sending = false;
                if (af.ajax.status >= 400) {
                    af.failed();
                }
                else if (af.postnotify != null) {
                    af.postnotify(af.returnXML ? af.ajax.responseXML : af.ajax.responseText);
                }
            }
        }
    };

    function ajaxFetch(uri, divid, waitid, returnto, link) {
        if (link) urchinTracker('/ajax/' + link);
        af.ajax = createHTTPObject();
        if (!af.ajax) return true; // can't check, browser has to send it
        af.dom_content = document.getElementById(divid);
        if (!af.dom_content) return true; // div element not found
        af.dom_wait = document.getElementById(waitid);
        if (af.dom_wait) {
            af.dom_wait.innerHTML = '<div align="center" style="width:15em; border:1px navy solid;padding:10px;"><div style="float:left; padding-right:15px;"><img src="/img/interna/bouncy.gif" width="8" height="16" alt="." /></div>Please wait ^^</div>';
        }
        af.return_uri = returnto;

        af.sending = true;
        af.ajax.onreadystatechange = af.statechange;
        af.ajax.open('GET', uri, true);
        af.ajax.setRequestHeader("Connection", "close");
        af.ajax.send(null);
        setTimeout("af.timeout()", 45000);

        return false;
    }
    
    function ajaxSend(uri, parameters, successnotification, returnXML, async) {
        af.ajax = createHTTPObject();
        if (!af.ajax) return true; // can't check, browser has to send it
        af.sending = true;
        
        af.returnXML = returnXML;
        af.postnotify = successnotification;
        
        af.ajax.onreadystatechange = af.poststatechange;
        af.ajax.open('POST', uri, async);
        af.ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        af.ajax.setRequestHeader("Content-length", parameters.length);
        af.ajax.setRequestHeader("Connection", "close");
        af.ajax.send(parameters);
        setTimeout("af.timeout()", 45000);

        return false;
    }

    function createHTTPObject() {
        http_request = false;
        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) http_request.overrideMimeType('text/xml');
        } 
        else if (window.ActiveXObject) { // IE
            try {http_request = new ActiveXObject("Msxml2.XMLHTTP");} 
            catch (e) { // OldIE
                try {http_request = new ActiveXObject("Microsoft.XMLHTTP");} 
                catch (e2) {;}
            }
        }
        
        return http_request;
    }