function iecheck() 
{
    if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent)
    {
        var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
        var iever = (rslt != null && Number(rslt[1]) >= 5.5 && Number(rslt[1]) <= 7 );
    }
    return iever;
}

Netroots_Embed = new function()
{
    var BASE_URL = 'http://www.socialdemokraterna.se/netroots/';
    var STYLESHEET = BASE_URL + 'styles/embed.css';
    var CONTENT_URL = BASE_URL + 'EmbedGenerator.aspx';
    var ROOT = 'Netroots_Embed_div_' + new Date().getTime();

    function requestStylesheet(stylesheet_url) 
    {
        stylesheet = document.createElement("link");
        stylesheet.rel = "stylesheet";
        stylesheet.type = "text/css";
        stylesheet.href = stylesheet_url;
        stylesheet.media = "all";
        document.lastChild.firstChild.appendChild(stylesheet);
    }

    function requestContent( params, div )
    {
        var script = document.createElement('script');
        // How you'd pass the current URL into the request
        
        //script.src = CONTENT_URL + '?pageID=' + params['pageID'] + '&count=' + params['count'] + '&divid=' + div;
        script.src = CONTENT_URL + '?' + params + '&divid=' + div;
        document.getElementsByTagName('head')[0].appendChild(script);
    }

    this.init = function() 
    {
	    this.serverResponse = function(data, div) 
	    {
	        if (!data) return;
	        var div = document.getElementById(div);
	        div.innerHTML = unescape(data);  // assign new HTML into #ROOT
	        div.style.display = 'block'; // make element visible
	        div.style.visibility = 'visible'; // make element visible
	    }
	    requestStylesheet(STYLESHEET);
	    document.write("<div id='" + ROOT + "' style='display: none'></div>");
	    requestContent(GetParams(), ROOT);
	    var no_script = document.getElementById('no_script');
	    if (no_script) { no_script.style.display = 'none'; }
	}
	
	function GetParams()
	{
	    var scripts = document.getElementsByTagName('script');
        var myScript = scripts[ scripts.length - 1 ];
        var queryString = myScript.src.replace(/^[^\?]+\??/,'');
        return queryString;
        //return parseQuery( queryString );
    }
//    function parseQuery ( query ) 
//    {
//        var Params = new Object ();
//        if ( !query ) 
//        return Params; // return empty object
//        var Pairs = query.split(/[;&]/);
//        for ( var i = 0; i < Pairs.length; i++ ) 
//        {
//            var KeyVal = Pairs[i].split('=');
//            if ( ! KeyVal || KeyVal.length != 2 ) 
//                continue;
//            var key = unescape( KeyVal[0] );
//            var val = unescape( KeyVal[1] );
//            val = val.replace(/\+/g, ' ');
//            Params[key] = val;
//        }
//        return Params;
//    }
}

Netroots_Embed.init();
