var http = false;
var i    = 30;
var j,  bgc;

if(navigator.appName == "Microsoft Internet Explorer") {
  http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
  http = new XMLHttpRequest();
}

function cluster_update() {
  nocache = Math.random();
  http.open("GET", "/data/cluster-small.php?flow="+(i-1)+"&nocache="+nocache, true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      document.getElementById("cluster").innerHTML = http.responseText;
    }
  }
  http.send(null);
  i=i-1;
  if (i!=0) {
   setTimeout("cluster_update()",15000);
  }
}


function big_cluster_update() {
  nocache = Math.random();
  http.open("GET", "/cluster/?ajax=yes&nocache="+nocache, true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      document.getElementById("clusterspots").innerHTML = parseScript(http.responseText);
    }
  }
  http.send(null);
  setTimeout("big_cluster_update()",60000);
}



function cluster_reset() {
	i = 30;
	cluster_update();
}


function ajax_put(URL, divname) {
  nocache = Math.random();
  http.open("GET", URL+"&nocache="+nocache, true);
  http.onreadystatechange=function() {
    if(http.readyState == 4) {
      document.getElementById(divname).innerHTML = http.responseText;
    }
  }
  http.send(null);
}


function update_div(data, divname) {
      document.getElementById(divname).innerHTML = data;
}



function Blog_ShowBigImage(filename) {
 var st=0;
 var x,y;

	if (self.innerHeight) // all except Explorer
	{
	 x = self.innerWidth;
	 y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
	{
	 x = document.documentElement.clientWidth;
	 y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
	 x = document.body.clientWidth;
	 y = document.body.clientHeight;
	}

        /*
           alert("x="+x+" - y="+y);
           Check ViewPort size.. 
        */

        if (x == 0) x = 1004; 
        if (x == 0) x = 615;
        /* 1024x768 standard with IE6 */ 

	var ImgxMax = Math.floor(x * 0.9);
	var ImgyMax = Math.floor(y * 0.9);

	if (document.documentElement && document.documentElement.scrollTop)
	 st = document.documentElement.scrollTop; /* IE6 Scrolling */
	else if (document.body && document.body.scrollTop)
	 st = document.body.scrollTop; /* Others scrolling */
	else if (window.pageYOffset) /* FF Scrolling */
         st = 0;

      document.getElementById('overlayBG').style.top          = st + "px";
      document.getElementById('overlayBG').style.height       =  y  + "px";
      document.getElementById('overlayBG').style.width        = "100%";
      document.getElementById('overlayCONTENT').style.top     = st + "px";
      document.getElementById('overlayCONTENT').style.height  = y  + "px";
      document.getElementById('overlayCONTENT').style.width        = "100%";

      document.getElementById('overlayBG').innerHTML = "<table style='width:100%; height:100%;' cellpadding=0 cellspacing=0><tr><td id='gray_td' width=100% height=100% style='color:red; background-color: #000000;' align=center vAlign=middle><b>Loading..<b></td></tr></table>";
      document.getElementById('overlayCONTENT').innerHTML = "<table style='width:100%; height:100%; cursor:pointer;' cellpadding=0 cellspacing=0 onClick='JavaScript:Blog_CloseImage();'><tr><td width=100% height=100% vAlign=middle align=center><img src=\"/data/thumb.php?img="+filename+"&width="+ImgxMax+"&height="+ImgyMax+"&nosave=1\"></td></tr></table>";
 
//      setTimeout('MakeGray(0);', 100);
      if ( document.onresize ) {
       document.onresize = Blog_ResizeGrayArea;
       document.onscroll = Blog_ResizeGrayArea;
      } else {
       window.onresize = Blog_ResizeGrayArea;
       window.onscroll = Blog_ResizeGrayArea;
      }

}

function Blog_ResizeGrayArea() {
 var st=0;
 var x,y;

	if (self.innerHeight) // all except Explorer
	{
	 x = self.innerWidth;
	 y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
	{
	 x = document.documentElement.clientWidth;
	 y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
	 x = document.body.clientWidth;
	 y = document.body.clientHeight;
	}

        if (x == 0) x = 1004; 
        if (x == 0) x = 615;
        /* 1024x768 standard with IE6 */ 

	if (document.documentElement && document.documentElement.scrollTop)
	 st = document.documentElement.scrollTop; /* IE6 Scrolling */
	else if (document.body && document.body.scrollTop)
	 st = document.body.scrollTop; /* Others scrolling */
	else if (window.pageYOffset) /* FF Scrolling */
         st = 0;

      document.getElementById('overlayBG').style.top        = st + "px";
      document.getElementById('overlayBG').style.height     = y  + "px";
      document.getElementById('overlayCONTENT').style.top   = st + "px";
      document.getElementById('overlayCONTENT').style.height= y  + "px";
}

function MakeGray(j) {
 if(document.getElementById('gray_td')) {
 var os = document.getElementById('gray_td').style; 

 if ( j == 0 ) os.backgroundColor = '#000000';

 j=j+6;
    
 os.opacity      = (j / 100); 
 os.MozOpacity   = (j / 100); 
 os.KhtmlOpacity = (j / 100); 
 os.filter       = "alpha(opacity=" + j + ")";

 if ( j < 80 ) setTimeout('MakeGray('+j+');', 100);
}
}

function Blog_CloseImage() {
  j = 100;

 if ( document.onresize ) {
  document.onresize = '';
  document.onscroll = '';
 } else {
  window.onresize = '';
  window.onscroll = '';
 }

 document.getElementById('overlayCONTENT').innerHTML = "";
 document.getElementById('overlayBG').innerHTML = "";
 document.getElementById('overlayBG').style.width        = "0px";
 document.getElementById('overlayCONTENT').style.width   = "0px";

}


function SWA_Popup() {
 window.open( "http://www.dahlund.se/lasse/sm6mgz/swa.htm", "SWA", "status = 1, width = 780, height = 600, resizable = 0" )
}

	function parseScript(_source) {
		var source = _source;
		var scripts = new Array();
		
		// Strip out tags
		while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
			var s = source.indexOf("<script");
			var s_e = source.indexOf(">", s);
			var e = source.indexOf("</script", s);
			var e_e = source.indexOf(">", e);
			
			// Add to scripts array
			scripts.push(source.substring(s_e+1, e));
			// Strip from source
			source = source.substring(0, s) + source.substring(e_e+1);
		}
		
		// Loop through every script collected and eval it
		for(var i=0; i<scripts.length; i++) {
			try {
				eval(scripts[i]);
			}
			catch(ex) {
				// do what you want here when a script fails
			}
		}
		
		// Return the cleaned source
		return source;
	}

