
function prepareTabBoxes() {
	if (!document.getElementById) return false;
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById('tab_box')) return false;
	
	var $box_parent = document.getElementById('tab_box');
	var $box_children = $box_parent.childNodes;
	
	var $total = 0;
	for (var $i=0; $i<$box_children.length; $i++) {
		var $box_child = $box_children[$i];
		if ($box_child.nodeName != 'DIV') continue;
		$total++;
	}
	if ($total < 2) return false;
	
	var $tabs_box = document.createElement('div');
	$tabs_box.setAttribute('id','tabs');
	
	for (var $i=0; $i<$box_children.length; $i++) {
		var $box_child = $box_children[$i];
		if ($box_child.nodeName != 'DIV') continue;
		
		var $tab = document.createElement('div');
		var $tab_text = document.createTextNode($box_child.getAttribute('title'));
		$tab.appendChild($tab_text);
		$tab.setAttribute('rel','box_child_'+$i);
		$tab.className = 'tab';
		
		if ($box_child.className == 'tab_box_selected') $tab.setAttribute('id','tab_selected');
		
		$tab.onclick = function() {
			var $box_parent = document.getElementById('tab_box');
			var $box_children = $box_parent.childNodes;
			
			for (var $i=0; $i<$box_children.length; $i++) {
				var $box_child = $box_children[$i];
				if ($box_child.nodeName != 'DIV') continue;
				if ($box_child.getAttribute('id') == 'tabs') continue;
				if ($box_child.getAttribute('id') == this.getAttribute('rel')) $box_child.className = 'tab_box_selected';
				else $box_child.className = '';
			}
			
			var $tabs = document.getElementsByClassName('tab');
			for (var $i=0; $i<$tabs.length; $i++) {
				var $tab = $tabs[$i];
				$tab.setAttribute('id','');
			}
			this.setAttribute('id','tab_selected');
		}
		
		$box_child.setAttribute('id','box_child_'+$i);
		$box_child.setAttribute('title','');
		$tabs_box.appendChild($tab);
	}
	
	$box_parent.insertBefore($tabs_box,$box_parent.firstChild);
}
addLoadEvent(prepareTabBoxes);


function prepareHiddenInformation() {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementsByClassName('hidden_content')) return false;
	
	var $hidden_content_boxes = document.getElementsByClassName('hidden_content');
	for (var $i=0; $i<$hidden_content_boxes.length; $i++) {
		var $hidden_content_box = $hidden_content_boxes[$i];
		
		var $link = document.createElement('a');
		$link.onclick = function() {
			if (this.getAttribute('status') == 'open') {
				$hidden_content_box_id = this.getAttribute('rel');
				$hidden_content_box = document.getElementById($hidden_content_box_id);
				$hidden_content_box.style.display = 'none';
				
				this.setAttribute('status','closed');
				var $old_text = this.childNodes[0];
				this.removeChild($old_text);
				if ($hidden_content_box.getAttribute('title')) var $text = document.createTextNode('More '+$hidden_content_box.getAttribute('title')+'>>>');
				else var $text = document.createTextNode('More Information >>>');
				this.appendChild($text);
			}
			else {
				$hidden_content_box_id = this.getAttribute('rel');
				$hidden_content_box = document.getElementById($hidden_content_box_id);
				$hidden_content_box.style.display = 'block';
				
				this.setAttribute('status','open');
				var $old_text = this.childNodes[0];
				this.removeChild($old_text);
				if ($hidden_content_box.getAttribute('title')) var $text = document.createTextNode('Less '+$hidden_content_box.getAttribute('title')+'<<<');
				else var $text = document.createTextNode('Less Information <<<');
				this.appendChild($text);
			}
		}

		$link.setAttribute('title','Information');
		$link.className = 'information_link';
		var $hidden_content_box_id = 'hidden_content'+$i;
		$hidden_content_box.setAttribute('id',$hidden_content_box_id);
		$link.setAttribute('rel',$hidden_content_box_id);
		if ($hidden_content_box.getAttribute('title')) var $text = document.createTextNode('More '+$hidden_content_box.getAttribute('title')+'>>>');
		else var $text = document.createTextNode('More Information >>>');
		$link.appendChild($text);
		var $parent = $hidden_content_box.parentNode;
		$parent.insertBefore($link,$hidden_content_boxes[$i]);
	}
}
addLoadEvent(prepareHiddenInformation);




function prepareQuickSearch() {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementsByClassName('hidden_full_search')) return false;
	
	var $hidden_text_boxes = document.getElementsByClassName('hidden_full_search');
	for (var $i=0; $i<$hidden_text_boxes.length; $i++) {
		
		var $hidden_text_box = $hidden_text_boxes[$i];
		var $link = document.createElement('legend');
		$link.onclick = function() {
			if (this.getAttribute('status') == 'open') {
				this.setAttribute('status','closed');
				var $text = document.createTextNode('Open Advanced Search >>');
				this.innerHTML = '';
				this.appendChild($text);
				
				$id = this.getAttribute('rel');
				$hidden_element = document.getElementById($id);
				$hidden_element.style.display = 'none';
			}
			else {
				this.setAttribute('status','open');
				var $text = document.createTextNode('Close Advanced Search <<');
				this.innerHTML = '';
				this.appendChild($text);
				
				$id = this.getAttribute('rel');
				$hidden_element = document.getElementById($id);
				$hidden_element.style.display = 'block';
			}
		}
		$link.setAttribute('title','Click here');
		$link.className = 'information_link';
		var $id = $hidden_text_box.getAttribute('id');
		$link.setAttribute('rel',$id);
		var $text = document.createTextNode('Open Advanced Search >>');
		$link.appendChild($text);
	
		var $parent = $hidden_text_box.parentNode;
		$parent.insertBefore($link,$hidden_text_boxes[$i]);
	}
}
addLoadEvent(prepareQuickSearch);



function prepareTelescopicParagraphs() {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementsByClassName('telescopic_paragraph')) return false;
	
	var $telescopic_paragraphs = document.getElementsByClassName('telescopic_paragraph');
	for (var $i=0; $i<$telescopic_paragraphs.length; $i++) {
		
		var $telescopic_paragraph = $telescopic_paragraphs[$i];
		$telescopic_paragraph.style.display = 'block';
		var $telescopic_paragraph_string = innerXHTML($telescopic_paragraph);
		
		if ($telescopic_paragraph.getAttribute('rel')) var $shortened_length = parseInt($telescopic_paragraph.getAttribute('length'));
		else var $shortened_length = 150;
		if ($telescopic_paragraph_string.length <= $shortened_length) continue
		
		$telescopic_paragraph.setAttribute('fulltext',$telescopic_paragraph_string);
		innerXHTML($telescopic_paragraph,$telescopic_paragraph_string.substr(0,$shortened_length)+'... ');
		
		$toggle_telescope_link = document.createElement('a');
		$toggle_telescope_link.href = '';
		$toggle_telescope_link.setAttribute('rel','tooltip_exclude');
		$toggle_telescope_link.setAttribute('title','more');
		$toggle_telescope_link.onclick = function() {
			var $telescopic_paragraph = this.parentNode;
			if (this.getAttribute('title') == 'less') {
				if ($telescopic_paragraph.getAttribute('rel')) var $shortened_length = parseInt($telescopic_paragraph.getAttribute('length'));
				else var $shortened_length = 150;
				innerXHTML($telescopic_paragraph,$telescopic_paragraph_string.substr(0,$shortened_length)+'... ');
				$telescopic_paragraph.appendChild(this);
				innerXHTML(this,'more');
				this.setAttribute('title','more');
			}
			else {
				innerXHTML($telescopic_paragraph,$telescopic_paragraph.getAttribute('fulltext'));
				$telescopic_paragraph.appendChild(this);
				innerXHTML(this,'less');
				this.setAttribute('title','less');
			}
			return false;
		}
		$toggle_telescope_link_text = document.createTextNode('more');
		$toggle_telescope_link.appendChild($toggle_telescope_link_text);
		$telescopic_paragraph.appendChild($toggle_telescope_link);
	}
}
addLoadEvent(prepareTelescopicParagraphs);
