/**
* HONKI Menu 0.1 (based on CSShiarchMenu v0.4)
*/

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
};

//declare
var submenu = new Array();
var tmr = new Array();
var adj = new Array();
var last_zIndex = 10000;
var lastOverId = '';

var hide = new Array();
//build or unhide submenu div...
function hideNow(){
	if (hide.length>0){
		for(var h=0; h<hide.length;h++){
			hideSubmenu(hide[h], true);
		}
		hide = new Array()
	}
}
function buildSubmenu(obj, now, topSpan){
	if (!menuOn) return;
	if (!topSpan) topSpan = 0;
	for (b in obj.cells) obj.cells[b].className='menuItemOver';
	lastBuild = false;
	if (now && hide.length>0){
		for(var h=0; h<hide.length;h++){
			hideSubmenu(hide[h], now);
		}
		hide = new Array()
	}
	lastOverId = obj.id;

	//get common part of div id
	menuPath = obj.id.split('_');

	//unset mousout of parent menus and make sure they are visible...
	x = "div";
	for(i=0;i<menuPath.length;i++){
		x+= '_' + menuPath[i];
		if(document.getElementById(x)){
			if(tmr[x])
				window.clearTimeout(tmr[x]);
			document.getElementById(x).style.visibility = 'visible';
		}
	}

	//check if we have a submenu of the obj...
	if(submenu[obj.id]){

		//calc position of mouseover
		d = obj;
		if(d){
			L_pos = d.offsetLeft + d.offsetWidth-1;
			T_pos = d.offsetTop;
			while(d.offsetParent){
				d = d.offsetParent;
				L_pos+= d.offsetLeft;
				T_pos+= d.offsetTop;
			}
		}


		//patch first submenu to go right below the main buttons...
		if(obj.className.indexOf('menuItem') < 0 && alignSubmenu == 'bottom'){
			L_pos-= obj.offsetWidth;
			T_pos+= obj.offsetHeight;
		}

		//move the submenu (overlap?)
		//if((adjustTop || adjustLeft) && (adjustFirst || (!adjustFirst && obj.className.indexOf('menuItem') >= 0))){
			L_pos+= adjustLeft;
			T_pos+= adjustTop+topSpan;
		//}
		//check if allready build...
		c = document.getElementById('div_' + obj.id);
		if(c){
			//unhide...
			c.style.top = T_pos + "px";
			c.style.left = L_pos + "px";
			c.style.visibility = 'visible';
			c.style.zIndex = last_zIndex++;
		}else{
			//build new div
			subObj = document.createElement('div');
			subObj.id = 'div_' + obj.id;
			subObj.className = 'submenu';
			subObj.style.position = 'absolute';
			subObj.style.zIndex = last_zIndex++;
			subObj.style.width = menuWidth;
			subObj.style.top = T_pos + "px";
			subObj.style.left = L_pos + "px";
			subObj.style.paddingRight = "1px";

			//write div to the body...
			document.getElementsByTagName('body')[0].appendChild(subObj);

			//build html for submenu
			content="<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" >";
			m = submenu[obj.id];
			for(i=0;i<m.length;i++){

				//determin target for onclick...
				//	(sorry, I should rewrite this routine...)
				if(!m[i][2] || m[i][2] == '_self')
					act = "self.location.href='" + m[i][1] + "';";
				else if(m[i][2] == '_top')
					act = "top.location.href='" + m[i][1] + "';";
				else if(m[i][2] == '_blank')
					act = "window.open('" + m[i][1] + "');";
				else
					act = "window.frames['"+m[i][2]+"'].location.href='" + m[i][1] + "';";

				//make item
				content+= "<tr onmouseout=\"hideSubmenu(this)\" onmouseover=\"buildSubmenu(this" +(m[i][1] ?"":",true")+ ")\" "+ (m[i][1] ? "onclick=\""+ act + "\" " : "") +"class=menuItem id=\"" + obj.id + "_" + i +"\"><td class=menuItem><img border=\"0\" src=\"img/spacer.gif\" width=\"1\"></td>" + (m[i][1] ? "<td class=menuItem colspan=\"2\">" + m[i][0]+ "</td>" : "<td class=menuItem>" + m[i][0]+ "</td><td style=\"padding-left:5px\" align=\"right\" valign=\"middle\"><img  border=\"0\" width=\"9\" height=\"9\" src=\"img/arrow.gif\"></td>") + "<td class=menuItem><img border=\"0\" src=\"img/spacer.gif\" width=\"1\"></td></tr>";
				adj[i] = obj.id + "_" + i;
				if (i<m.length-1) content+="<tr><td class=menuSpacerLeft><img border=\"0\" src=\"img/spacer.gif\" width=\"1\" height=\"1\"></td><td class=menuSpacerCenter colspan=\"2\"><img border=\"0\" src=\"img/spacer.gif\" height=\"1\"></td><td class=menuSpacerRight><img border=\"0\" src=\"img/spacer.gif\" width=\"1\" height=\"1\"></td></tr>"
			}
			content+="</table>";
			//insert new menu
			subObj.innerHTML = content;

			//make all just made div's the same width...
			//for(i=0;i<adj.length;i++)
			//	document.getElementById(adj[i]).style.width = subObj.style.width;
		}
	}
}

//hide a submebu div
function hideSubmenu(obj, now){
	if (!menuOn) return;
	if (!now) {
		hide.push(obj);
		for (b in obj.cells){ obj.cells[b].className='menuItem';}
	}

	//get common part of div id
	closePath = obj.id.split('_');

	//hide path
	x = "div";
	for(i=0;i<closePath.length;i++){
		x+= '_' + closePath[i];
		if(document.getElementById(x)) {
			if (now) document.getElementById(x).style.visibility = 'hidden';
			else tmr[x] = window.setTimeout("document.getElementById('"+x+"').style.visibility = 'hidden'",500);
		}
		//The timeout above is needed for MSIE browsers... Or else the menu's will disapear on EVERY mousout!!!
		//Please get a normal browser like Firefox, Mozilla or Opera!!
	}
}



//add an menu item to the config array (called in the config lines)
function menuItem(txt,url,tar){
	return new Array(txt,url,tar);
}

//*** Patch for firefox bug with focus on mouseover...
//		This function should be called onMouseOver of every iFrame that's under the menu structure.
function iFramePatch(){
	if(!document.all && lastOverId)
		hideSubmenu(document.getElementById(lastOverId));
}

var menuWidth 		= 300;			//width of submenu in pixels
var alignSubmenu 	= 'bottom';		//bottom or right side of the main button.
var adjustFirst		= false;		//overlap the first submenu too?
var adjustTop		= 0;			//move the submenu's some pixels. Positive number (10) for down, negative (-10) for up.
var adjustLeft		= 2;			//move the submenu's some pixels. Positive number (10) for right, negative (-10) for left.


//---------------------------------------------------------------------------------------------------------
// Funkcje newslettera
//---------------------------------------------------------------------------------------------------------

function onNewsletterFocus(qt)
{

	if(qt.value ==' e-mail address')
		qt.value = '';
}

function email(e)
{
	if(e.indexOf('@') >=0)
		return true;
	else
		return false;
}

function dodaj(form)
{
	var nl = null;
	if(form)
		nl = document.forms[form];
	else
		nl = document.newsletter;

	if(email(nl.email.value))
	{
		nl.submit();
	}
	else
	{
		alert("Enter correct e-mail address.");

	}

}

