var menu_hover_old_onload = window.onload ? window.onload : function() {};

var menu_hover_current = null;
var menu_hover_timeout = null;


function hideShow()
{
	var menu = document.getElementById("page_menu");
  var cells = menu.getElementsByTagName("ul"); 
	for (var i = 0; i < cells.length; i++) 
	{ 
   cells[i].style.display="none";
	}
}


function showHide(iddiv, ahref)
{
	
	if(ahref.className=='klikacz_rozwin')
	{
		ahref.className='klikacz_zwin';
	}
	else
	{
	ahref.className='klikacz_rozwin';
	}
	
	
	div = document.getElementById(iddiv);
	//alert(div.style.display);
	var i = 0;
	if(div.style.display=='none')
	{
	//new Effect.BlindDown(iddiv);
		//i = 1;
		div.style.display='block';
	}
	else
	{
		//new Effect.BlindUp(iddiv);
		 //i = 0;
		 div.style.display='none';
	}
}




function insertImage(img,text)
{
	document.getElementById("imgLoader").src=img;
	document.getElementById("galleryDesc").innerHTML=text;
	
}


function menu_hover_change(dest)
{
  if (menu_hover_timeout) {
    clearTimeout(menu_hover_timeout);
    menu_hover_timeout = null;
  }
  if (menu_hover_current == dest) return;
  if (menu_hover_current) {
    menu_hover_current.className = menu_hover_current.className.replace(" hover", "");
  }
  if (dest) {
    dest.className += " hover";
  }
  menu_hover_current = dest;
	
	hideShow()
	if(dest!=null)
	{
		
		
		
		if(document.all)
		{
			var suma = 0
			var szer = 0;
			if(dest!=null)
			{
				
				var menu = document.getElementById("page_menu");
				var children = menu.childNodes;
				for (var i = 0; i < children.length; i++) 
				{
					suma+=children[i].offsetWidth;
					if(dest == children[i])
					{
						szer = 850 - parseInt(suma);
					}
				}
			
				dest.children[1].style.width=szer+'px';	
				dest.children[1].style.display="block";	
		
			}	
		}
	
		
		
		var ul = dest.getElementsByTagName("ul"); 
		if(ul[0])
		{
			ul[0].style.display="block";	
		}
	}
	
	
}

function menu_hover_onload()
{
  if (!document.getElementById) return;
  
  var menu = document.getElementById("page_menu");
  var children = menu.childNodes;
  for (var i = 0; i < children.length; i++) {
    var node = children[i];
    if (node.className && node.className.indexOf("menu_tab") != -1) {
      var old_onmouseover = node.onmouseover ? node.onmouseover : function() {};
      node.onmouseover = function() {
        old_onmouseover();
        menu_hover_change(this);
      }

      var old_onmouseout = node.onmouseout ? node.onmouseout : function() {};
      node.onmouseout = function() {
        old_onmouseout();
        if (menu_hover_timeout) clearTimeout(menu_hover_timeout);
        menu_hover_timeout = setTimeout('menu_hover_change(null);', 1000);
      }
    }
  }
}

window.onload = function() {
  menu_hover_onload();
  menu_hover_old_onload();
}



function popup(url, nr, width, height) 
{
        var Win = window.open(url, nr,'width=' + width + ',height=' + height + ',resizable=0,scrollbars=no,menubar=no,left=50,top=100' );
}




function obsluga_warstw()
 {
  if (document.layers) return true;
  if (document.all) return false;
  if (document.getElementById) return true;
  return true;
 }

function get_elem(co)
 {
  if (!obsluga_warstw()) return document.all[co];
  else return document.getElementById(co);
 }


function set_pic(gdzie, patch, patchbig ,x, y)
 {
  get_elem(gdzie).src = patch;
	get_elem(gdzie).style.cursor="pointer"
	 get_elem("pop").href = "javascript:popup(\"/popup/pop.php?url="+patchbig+"\", 1,"+x+","+y+")"
	//get_elem(gdzie).setAttribute("onclick","popup(\"/popup/pop.php?url="+patchbig+"\", 1,"+x+","+y+")")
 }
 
function set_txt(gdzie, text)
 {
  get_elem(gdzie).innerHTML = text;
 }
 
function chColor(element)
{
	ahref = get_elem('newsLinki').getElementsByTagName("a");
	for (var i = 0; i < ahref.length; i++)
	{ 

     ahref[i].className=""; 
	}
	element.className="active"; 
	
}

function newWindow(url, nr, width, height) 
{
        var Win = window.open(url, nr,'width=' + width + ',height=' + height + ',resizable=0,scrollbars=no,menubar=no,left=50,top=100' );
}




function NextPrev(index,maximum)
{	
	
		index = parseInt(index);
		maximum = parseInt(maximum);
		
	
		document.getElementById("source").innerHTML=dynamicImages[index][0]+dynamicImages[index][1];
	
	if(maximum!=0)
	{
		if(index == maximum)
		{
			document.getElementById("rightButton").innerHTML='<a id="gRight" onclick="NextPrev(0,'+maximum+'); return false;" href="#">NastÄ�pne</a>';
		}
		else
		{
			ix = parseInt(index)+1;
			document.getElementById("rightButton").innerHTML='<a id="gRight" onclick="NextPrev('+ix+','+maximum+'); return false;" href="#">NastÄ�pne</a>';
		}
	
		if(index == 0)
		{
			document.getElementById("leftButton").innerHTML='<a id="gLeft" onclick="NextPrev('+maximum+','+maximum+'); return false;" href="#">Poprzednie</a>';
		}
		else
		{
			ix= parseInt(index)-1;
			document.getElementById("leftButton").innerHTML='<a id="gLeft" onclick="NextPrev('+ix+','+maximum+'); return false;" href="#">Poprzednie</a>';
		}
	
	}
}

function popup(url, nr, width, height) 
{
        var Win = window.open(url, nr,'width=' + width + ',height=' + height + ',resizable=0,scrollbars=no,menubar=no,left=50,top=100' );
}



function next(num)
{
	var obj=document.getElementById('animPop');
	var obj_img=document.getElementById('chImg');
	var obj_text=document.getElementById('textcontainer');
	var arr_r=document.getElementById('arr_r');
	var arr_l=document.getElementById('arr_l');
	obj.href=dynimages[num][0];
	obj_img.src=dynimages[num][1];
	obj_text.innerHTML=dynopis[num];
	if(num > 0)
	{
		arr_l.innerHTML='<a href="#" onClick = "prev('+(num-1)+');return false;">Poprzednie</a>';
	}
	else
	{
		arr_l.innerHTML='';
	}
	
	if(num < (dynimages.length-1))
	{
		arr_r.innerHTML='<a href="#" onClick = "next('+(num+1)+'); return false;">NastÄ�pne</a>';
	}
	else
	{
		arr_r.innerHTML='';
	}
}
function prev(num)
{
	var obj=document.getElementById('animPop');
	var obj_img=document.getElementById('chImg');
	var obj_text=document.getElementById('textcontainer');
	var arr_r=document.getElementById('arr_r');
	var arr_l=document.getElementById('arr_l');
	obj.href=dynimages[num][0];
	obj_img.src=dynimages[num][1];
	obj_text.innerHTML=dynopis[num];
	
	if(num > 0)
	{
		arr_l.innerHTML='<a href="#" onClick = "prev('+(num-1)+')">Poprzednie</a>';
	}
	else
	{
		arr_l.innerHTML='';
	}
	
	if(num < (dynimages.length-1))
	{
		arr_r.innerHTML='<a href="#" onClick = "next('+(num+1)+')">NastÄ�pne</a>';
	}
	else
	{
		arr_r.innerHTML='';
	}
}


function rejestruj()
{
	var stop=0;
	var d=document.forms.frm_rejestracji
	if(stop==0 && d.imieNazwisko.value.length<3)
	{
		alert("Prosze wpisać imię i nazwisko");stop=1;
		d.imieNazwisko.style.border='red solid 1px';
	}
	
	if(stop==0 && d.nazwaFirmy.value.length<3)
	{
		alert("Prosze wpisać nazwę firmy");stop=1;
		d.nazwaFirmy.style.border='red solid 1px';
	}
	

	
	
	if(stop==0 && (d.email.value.length<6 || d.email.value.indexOf("@") == -1 || d.email.value.indexOf(".") == -1))
	{
		alert("Wpisz prawidłowy adres e-mail!");stop=1;
		d.email.style.border='red solid 1px';
	}
	
	if(stop==0 && d.haslo.value.length<5)
	{
		alert("Hasło musi posiaać conajmniej 5 znaków (tylko alfanumerycznych)");stop=1;
		d.haslo.style.border='red solid 1px';
	}
	
	
	if(stop==0)
	{
		rejestracja('frm_rejestracji');
	}
}

function loguj()
{
	var stop=0;
	var d=document.forms.frm_logowanie
	if(stop==0 && (d.login.value.length<6 || d.login.value.indexOf("@") == -1 || d.login.value.indexOf(".") == -1))
	{
		alert("Wpisz poprawnie login!");stop=1;
		d.login.style.background='red';
	}
	if(stop==0 && d.password.value.length<3)
	{
		alert("Wpisz poprawnie hasło!");stop=1;
		d.password.style.background='red ';
	}
	
	if(stop==0)
	{
		rejestracja('frm_logowanie');
	}
}

function rejestracja($co)
{
 advAJAX.submit
 (
	document.getElementById($co), 
	{
		
		onInitialization : function(obj)
		{
			preloaderOn()
		},

		onSuccess : function(obj) { 
			
			preloaderOff()
			
			if (obj.responseText != "1")
			{
          alert(obj.responseText);
			}
			else
			{
				alert("Użytkownik zalogowany!");
				document.location="";
			}
		}
		
	}
 );
}

function przypomnienie()
{
	var stop=0;
	var d=document.forms.frm_przypomnienie;
	if(stop==0 && (d.wpisz_email.value.length<6 || d.wpisz_email.value.indexOf("@") == -1 || d.wpisz_email.value.indexOf(".") == -1))
	{
		alert("Wpisz prawidłowy adres e-mail!");stop=1;
		d.wpisz_email.style.background='red';
	}
	
	if(stop==0)
	{
		przypomnij('frm_przypomnienie');
	}
}

function przypomnij($co)
{
	
 advAJAX.submit
 (
	document.getElementById($co), 
	{
		
		onInitialization : function(obj)
		{
		
			preloaderOn()

		},

		onSuccess : function(obj)
		{ 	
			preloaderOff()
			alert(obj.responseText);
		}
		
	}
 );
}

function border_blank(element)
{
	element.style.background='#fff';
}

function valid()
{
	var d=document.forms.send_frm;  
	var stop=0;
	if(stop==0 && d.nazwa.value.length<3)
	{
		alert("Wpisz nazwę firmy lub swoje imię!");stop=1;
		d.nazwa.focus();
	}
	if(stop==0 && (d.my_email.value.length<6 || d.my_email.value.indexOf("@") == -1 || d.my_email.value.indexOf(".") == -1))
	{
		alert("Wpisz prawidłowy adres e-mail!");stop=1;
		d.my_email.focus();
	}
	if(stop==0)
	{
		wyslij_do('send_frm');
	}
}

function preloaderOff()
{
	document.getElementById("preloader").style.display="none";
}
function preloaderOn()
{

	getPageSize();
	document.getElementById("preloader").style.display="block";
	document.getElementById("preloader").innerHTML='<img style="top:50%; left:50%; position:absolute;background-color:#000000;"  src="/Templates/solgar/images/ajax-loader.gif" />';
	
	document.getElementById("preloader").style.width=arrayPageSize[0];
	document.getElementById("preloader").style.height=arrayPageSize[1];
		
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function wysokosc()
{
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	
	//alert(pageHeight)
	return pageHeight;
}

