// $Id$

var nn = (document.layers)? true:false;
var ms = (document.all)? true:false;
var n6 = (document.getElementById) ? true:false;

var loadedContent = new Array();
function loadDiseaseRate(areaId, year)
{
	var req;
	if(window.XMLHttpRequest)
		req = new XMLHttpRequest();
	else if(window.ActiveXObject)
		req = new ActiveXObject("Microsoft.XMLHTTP");

	if(!req)
		return true;

	var element = document.getElementById("disease_rates");
	var url  = location.protocol + "//" + location.host + "/portlets/disease_rate.xml?area_id=" + areaId + "&year=" + year;
	if (loadedContent[url]!=null)
	{
		element.innerHTML = loadedContent[url];
		return false;
	}

	req.open("GET", url , true );

	// process function
 	req.onreadystatechange = function()
 	{
  		if (req.readyState == 4)
  		{
  			if(req.status == 200)
  			{
				element.innerHTML = req.responseText;
				loadedContent[url] = req.responseText;
			}
		}
	}

	// send request
	req.send(null);
	return false;
}

function openWindow(file,szer,wys,scrollec){
	wys = (!wys)?(300):(wys);
	szer = (!szer)?(400):(szer);
	scrollec = (!scrollec)?('no'):('yes');
	if (ms) var xMax = screen.width, yMax = screen.height
	else if (nn) var xMax = window.outerWidth, yMax = window.outerHeight
	var xOffset = (xMax - szer)/2, yOffset = (yMax - wys)/2; 
	okienko = window.open(file,'B2BPrint','scrollbars='+scrollec+',height='+wys+',width='+szer+',screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset);
	okienko.focus();
}

function checkSearch(){
	form = document.formsearch;
	if (trim(form["search-clause"].value) != "")
		return true
	else
		return false
}

function checkLogin(){
	form = document.formlogin;
	if (trim(form["login"].value) != "" && trim(form["password"].value) != "")
		return true
	else
		return false
}

function checkCongressman()
{
	form = document.formcongresmman;
	
	if (!radioActive)
	{
		alert("Please choose the topic.");
		return false;
	}
	
	if (trim(form.zip.value) == "")
	{
		alert("Please enter zip code.");
		form.zip.focus();
		return false;
	}

	return true;
}

function checkWriteCongressman(form)
{
	return checkInput("form_write_subject", "Please enter subject.") &&
	checkInput("form_write_body", "Please enter message body.") &&
	checkInput("form_write_name", "Please enter your name.") &&
	checkEmail("form_write_email", "Please enter valid email.");
}

function checkCoreComponent(form)
{
	return checkInput("form_entry_body", "Please type information.");
}

function searchsubmit(){
	if (checkSearch())
		document.formsearch.submit();
}

function trim(lancuch){
	while (lancuch.charAt(0) == " ") 
		lancuch = lancuch.substring(1,lancuch.length);
	while (lancuch.charAt(lancuch.length-1) == " ") 
		lancuch = lancuch.substring(0,lancuch.length-2);
	return lancuch;	
}


/* ----------------------------------------------------------------------
	WRITE FLASH
---------------------------------------------------------------------- */
function writeFlash(url, width, height){
	document.writeln("<object height='" + height + "' width='" + width + "' id='ROGFla' data='" + url + "' type='application/x-shockwave-flash'>");
	document.writeln("<param name='movie' value='" + url + "' />");
	document.writeln("<param name='pluginurl' value='http://www.macromedia.com/go/getflashplayer' />");
	document.writeln("<param name='wmode' value='transparent' />");
	document.writeln("<param name='quality' value='high' />");
	document.writeln("<param name='bgcolor' value='#ffffff' />");
	document.writeln("<param name='scale' value='noscale' />");
	document.writeln("<param name='ROGFla' value='false' />");
	document.writeln("</object>");		
}


/* ----------------------------------------------------------------------
	CREATE OBJECT
---------------------------------------------------------------------- */
function createObject(divID) {
	if(document.layers){
		return document.layers[divID+'C'].document.layers[divID];
	}
	if(document.getElementById) {
		return document.getElementById(divID);
	}
	if(document.all) {
		return document.all[divID];
	}
	if(document[divID+'C']) {
		return document[divID+'C'].document[divID];
	}
	return false;
}


function replaceBack(mid, mstan) {
	obj = createObject(mid);
	if (obj) {
		obj.value = trim(obj.value);
		if (mstan){
			obj.className = "";
		} else {
			//alert(obj.value.length);
			if (obj.value.length > 1){
				obj.className = "";
			} else {
				obj.className = "over"
			}
		}
	}
}

function autocompletOn() {
	replaceBack('loginUser', false);
	replaceBack('loginPass', false);
}


/* ----------------------------------------------------------------------
	SET MAX HEIGHT IN BLOCKS
---------------------------------------------------------------------- */
function setMaxHeightBlocks(data){
	var i;
	var obj = [];
	var tmp;
	var maxHeight = 0;
	
	for (i=0; i<data.length; i++) {
		tmp = createObject(data[i]);
		if (tmp){
			obj.push(tmp);
			maxHeight = (tmp.offsetHeight > maxHeight)?(tmp.offsetHeight):(maxHeight);
		}
	}
	
	for (i=0; i<obj.length; i++) {
		obj[i].style.height = maxHeight;
	}
}


/* ----------------------------------------------------------------------
	CHECK LEFT COLUMN HEIGHT
---------------------------------------------------------------------- */
function checkLeftColumHeight() {
	objSubmenu = createObject("submenu");
	objContent = createObject("content");
	if (objSubmenu && objContent) {
		if (objContent.offsetHeight > objSubmenu.parentNode.offsetHeight){
			objSubmenu.style.height = objSubmenu.offsetHeight + objContent.offsetHeight - objSubmenu.parentNode.offsetHeight;
		}
	}
}

function addUnderlineToH3() {
	allTags = document.getElementsByTagName("span");
	if (allTags) {
		for (q=0; q<allTags.length; q++) {
			if (allTags[q].className == "underline" ){
				obj = allTags[q];
				pLeft = obj.offsetWidth + 5;
				obj.parentNode.style.background = "url(/images/body/line1.gif) no-repeat " + pLeft + "px 16px";
			}
		}
	}
}


/* ----------------------------------------------------------------------
	CHECK CONTENT HEIGHT
---------------------------------------------------------------------- */
function checkContentHeight() {
	var objContent = createObject("content");
	var minContentHeight = 200;
	if (objContent){
		if (objContent.offsetHeight < minContentHeight){
			objContent.style.height = minContentHeight;
		}
	}
}


/* ----------------------------------------------------------------------
	TOOL BOX
---------------------------------------------------------------------- */
function tollBoxVisibility()
{
	if(!window.getCookie)
		return;

	if(getCookie("showToolBox")=="none")
	{
		var tollBox = document.getElementById("toolBox");
		if(tollBox)
		{
			tollBox.style.display = "none";
			var button = document.getElementById("toolBoxButton");
			if(button)
				button.className += " off";
				button.title = "Show ToolBox";
		}
	}
}

function changeToolBoxVisiblity(button)
{
	var tollBox = document.getElementById("toolBox");
	if(!tollBox)
		return false;

	var displayStatus = tollBox.style.display == "none";
	tollBox.style.display = ( displayStatus ) ? "block" : "none";
	if(displayStatus)
	{
		button.className = button.className.replace("off","");
		button.title = "Hide ToolBox";
	}
	else
	{
		button.className += " off";
		button.title = "Show ToolBox";
	}

	setCookie("showToolBox", tollBox.style.display, "/");
	return false;
}


function starter()
{
	checkContentHeight();
	checkLeftColumHeight();
	addUnderlineToH3();
	window.setTimeout("tollBoxVisibility()", 5);
	
	setTimeout("autocompletOn()",20);
}

window.onload = starter;