// catch possible bugs with WebTV and other older browsers
var is_regexp = (window.RegExp) ? true : false;

var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    &&
    navigator.userAgent.indexOf('Mac') != -1
);

var W3CDOM = (!bugRiddenCrashPronePieceOfJunk && 
    document.getElementsByTagName && document.createElement);

window.onload = initialize; 

/* Why no window.onload = function () {} ? Because NN3 doesn't support the function
    constructor and gives an error message. This site must be accessible to NN3 */

function initialize ()
{

    /* Hide nifty stuff from old browsers */
    if (W3CDOM) {

        /* Go through all links. If any has a type="popup" write the popup 
            function into its onclick */
        var x = document.getElementsByTagName('a');
        for (var i=0;i<x.length;i++) {
            /* just a basic popup */
            if (x[i].getAttribute('type') == 'popup') {
                x[i].onclick = function () {
                    return pop(this.href)
                }
            }
        }
    }
    /* End hide. This is for all browsers */
}

// Popup

var popUp = null;

function pop(url)
{
	if (popUp && !popUp.closed)
		popUp.location.href = url;
	else
		popUp = window.open(url,'popUp','height=500,width=700,scrollbars=yes,resizable=yes,toolbar=no,location=no,status=no');
	popUp.focus();
	return false;
}

// #############################################################################

function switch_skin(selectobj)
{
	var skinid = selectobj.options[selectobj.selectedIndex].value;

	if (skinid == "")
	{
		return;
	}

	var url = new String(window.location);
	var fragment = new String("");

	// get rid of fragment
	url = url.split("#");

	// deal with the fragment first
	if (url[1])
	{
		fragment = "#" + url[1];
	}

	// deal with the main url
	url = url[0];

	// remove styleid=x& from main bit
	if (url.indexOf("skinid=") != -1 && is_regexp)
	{
		re = new RegExp("skinid=\\d+&?");
		url = url.replace(re, "");
	}

	// add the ? to the url if needed
	if (url.indexOf("?") == -1)
	{
		url += "?";
	}
	else
	{
		// make sure that we have a valid character to join our styleid bit
		lastchar = url.substr(url.length - 1);
		if (lastchar != "&" && lastchar != "?")
		{
			url += "&";
		}
	}
	window.location = url + "skinid=" + skinid + fragment;
}