var selectedImg = null;

startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("mainMenu");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}

//obsługa menu górnego
function przygotuj()
{
	//pobieram wszystkie anchory z diva "mainMenu"
	var menu = document.getElementById("mainMenu").getElementsByTagName("li");
	for(i = 0; i < menu.length; i++)
	{
		//przypisanie do akcji ONLCIK funckji "zmienPrzycisk"
		if( menu[i].className == 'lvl1' )
		{
			menu[i].onmouseover = function() { this.style.background = 'url(./images/mm_left.gif) no-repeat'; }
			menu[i].onmouseout = function() { this.style.background = 'url(./images/m_pipe.jpg) right top no-repeat'; }
		}
	}
}

function changeBg( id, photo )
{
	var zakladki = document.getElementById("paginesBox").getElementsByTagName("a");
	for(d = 0; d < zakladki.length; d++)
	{
		zakladki[d].className = "";
	}
	for(k = 1; k < 4; k++ )
		document.getElementById('p'+k).style.display = 'none';

	document.getElementById("s"+id).className="selected";
	var image = 'url(./Firms/Komako/images/welcomebox/'+photo+')';
	document.getElementById('welcomeBox').style.backgroundImage = image;
	document.getElementById('p'+id).style.display = 'block';
}
var changingIndex = 1;
var changingHandler;
var foto1;
var foto2;
var foto3;

function startChanging(){
  switch (changingIndex)
  {
	case 1:
	  changeBg(changingIndex, foto1);
	  break;
	case 2:
	  changeBg(changingIndex, foto2);
	  break;
	case 3:
	  changeBg(changingIndex, foto3);
	  break;
		
  }
  changingIndex++;
  if (changingIndex == 4){
    changingIndex = 1;
  }
}
function stopChanging(){
  window.clearInterval(changingHandler)
}
function setChanging(pFoto1, pFoto2, pFoto3){
  foto1 = pFoto1;
  foto2 = pFoto2;
  foto3 = pFoto3;
  changingHandler = setInterval("startChanging();", 5000);
}
function change( id, img, url, kid )
{
	var tab = new Array();
	tab[0] = './Firms/Komako/images/k_demo_on.jpg';
	tab[1] = './Firms/Komako/images/k_makler_on.jpg';
	tab[2] = './Firms/Komako/images/k_ekomako_on.jpg';
	//tab[3] = './Firms/Komako/images/k_biuro_on.jpg';

	setDefault();

	for(var z=1;z<=3;z++)
	{
		if( z == kid )
		{
			document.getElementById('kb' + z).src = tab[z-1];
			document.getElementById('kb' + z).onmouseover = function() { changePic( z, false, false ); }
			document.getElementById('kb' + z).onmouseout = function() { changePic( z, false, false ); }
		}
	}
	
	if( kid != 1 )
	{
		document.getElementById('kb1').onmouseover = function() { changePic( 1, true, false ); }
		document.getElementById('kb1').onmouseout = function() { changePic( 1, false, true ); }
	}
	if( kid != 2 )
	{
		document.getElementById('kb2').onmouseover = function() { changePic( 2, true, false ); }
		document.getElementById('kb2').onmouseout = function() { changePic( 2, false, true ); }
	}
	if( kid != 3 )
	{
		document.getElementById('kb3').onmouseover = function() { changePic( 3, true, false ); }
		document.getElementById('kb3').onmouseout = function() { changePic( 3, false, true ); }
	}
	/*
	if( kid != 4 )
	{
		document.getElementById('kb4').onmouseover = function() { changePic( 4, true, false ); }
		document.getElementById('kb4').onmouseout = function() { changePic( 4, false, true ); }
	}
	*/
	document.getElementById(id).innerHTML = '<a href="'+url+'"><img src="'+img+'" alt="" /></a>';
}

function setDefault()
{
	var tab = new Array();
	tab[0] = './Firms/Komako/images/k_demo.jpg';
	tab[1] = './Firms/Komako/images/k_makler.jpg';
	tab[2] = './Firms/Komako/images/k_ekomako.jpg';
	//tab[3] = './Firms/Komako/images/k_biuro.jpg';

	for(y=1;y<=3;y++)
		document.getElementById('kb'+y).src = tab[y-1];
}

function changePic( id, blnMouseOver, blnMouseOut )
{
	//alert( id );

	var tab = new Array();
	tab[0] = './Firms/Komako/images/k_demo.jpg';
	tab[1] = './Firms/Komako/images/k_makler.jpg';
	tab[2] = './Firms/Komako/images/k_ekomako.jpg';
	//tab[3] = './Firms/Komako/images/k_biuro.jpg';

	var tab1 = new Array();
	tab1[0] = './Firms/Komako/images/k_demo_on.jpg';
	tab1[1] = './Firms/Komako/images/k_makler_on.jpg';
	tab1[2] = './Firms/Komako/images/k_ekomako_on.jpg';
	//tab1[3] = './Firms/Komako/images/k_biuro_on.jpg';

	var el = document.getElementById('kb'+id);

	if( blnMouseOver == true )
		el.src = tab1[id-1];
	if( blnMouseOut == true )
		el.src = tab[id-1];
}

function changeEl( id1, id2)
{
	var m = document.getElementById(id1);
	var l = document.getElementById(id2);
	
	if( m.style.display == 'block')
	{
		m.style.display = 'none';
		l.style.display = 'block';
		Set_Cookie( 'ShowLoggedUserMenu', '', '', '/', '', '' );
		if (id1 == 'mainMenuLoged')
			document.getElementById('rightMenu').style.display = 'block';
	}
	else
	{
		m.style.display = 'block';
		l.style.display = 'none';
		if (id1 == 'mainMenuLoged')
			document.getElementById('rightMenu').style.display = 'none';
		Set_Cookie( 'ShowLoggedUserMenu', '1', '', '/', '', '' );
	}
}
function SetMenus()
{
	if ((document.getElementById('mainMenuLoged') != null) && Get_Cookie('ShowLoggedUserMenu') && (Get_Cookie('ShowLoggedUserMenu') != ''))
	{
		document.getElementById('mainMenuLoged').style.display = 'block';
		document.getElementById('mainMenu').style.display = 'none';
		document.getElementById('rightMenu').style.display = 'none';
	}
	else
	{
		if (document.getElementById('mainMenuLoged') != null)
			document.getElementById('mainMenuLoged').style.display = 'none';
		document.getElementById('mainMenu').style.display = 'block';
		document.getElementById('rightMenu').style.display = 'block';
	}
}
function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     anchor.target = "_blank"; 
 } 
} 
function PrepareAll()
{
	startList();
	przygotuj();
	SetMenus();
	//externalLinks();
}
window.onload=PrepareAll;

function SumbitPaymentForm() {
    if (document.forms[1] != null) {
        document.forms[1].submit();
    }
}
