/*
http://drnicwilliams.com/2006/11/21/diy-widgets/
*/


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;
}


function gup( name )
{
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null )
	return "";
    else
	return results[1];
}

MyXssMagic = new function() {

	var BASE_URL = 'http://webweary.dev.clicknowlogy.com/widget/';
	var STYLESHEET = BASE_URL + 'cssWidget.php' + '?sid=' + sid;
        var CONTENT_URL = BASE_URL + 'contentWidget.php' + '?sid=' + sid;
	var ROOT = 'clicknowlogy';

	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( local ) {
	    var script = document.createElement('script');
	    // How you'd pass the current URL into the request
	    // script.src = CONTENT_URL + '&url=' + escape(local || location.href);
	    script.src = CONTENT_URL;
	    document.getElementsByTagName('head')[0].appendChild(script);
	}

	this.init = function() {
	    this.serverResponse = function(data) {
		if (!data) return;
		var div = document.getElementById(ROOT);
                var txt ="";
                var count = data[0]['Count'];
		for (var i = 1; i <= count; i++) {
		    //		    if (txt.length > 0) { txt += ", "; }
		    //txt += "<li><a href='" + data[0][i] + "'>" + data[0][i] + "</a>";
		    //		    txt += "<li><a href='" + link + "'>" + data[0]['Links'][i] + "</a>";
		    txt += "<p><a href='" + data[0]['Link-' + i] + "'>" + data[0]['Title-' + i] + "</a><br>";
		}

                var widget_header = data[0]['Header'];
                if(widget_header) {
		   div.innerHTML = "<h3>" + widget_header + "</h3> " + txt;  // assign new HTML into #ROOT
                } else {
		   div.innerHTML = txt;  // 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();
	    var no_script = document.getElementById('no_script');
	    if (no_script) { no_script.style.display = 'none'; }
	}
    }
    MyXssMagic.init();


