function mywrite(flash)
{
	document.write(flash)
}


function $(name)
{
	obj =  document.getElementById(name);
	return obj;
}

function CheckEMail(address) {
	return address != "" 	&& address.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/);	
}

function myMail(f)
{
	if (!CheckEMail(f.email.value))
	{
		alert("Prosze podać poprawnie adres e-mail...");
		f.email.focus();
		return false;
	}

	return true;
}


function checkForm()
{
	if (!$("nazwisko").value)
	{
		alert("Prosze podać imię i nazwisko...");
		$("nazwisko").focus();
		return false;
	}

	
	if (!$("email").value && !$("telefon").value)
	{
		alert("Prosze podać adres e-mail lub telefon kontaktowy...");
		$("email").focus();
		return false;
	}
	
	if ($("email").value && !CheckEMail($("email").value))
	{
		alert("Prosze podać poprawnie adres e-mail...");
		$("email").focus();
		return false;
	}
	
	if (!$("opis").value)
	{
		alert("Prosze podać opis zdjęcia...");
		$("opis").focus();
		return false;
	}

	if (!$("zgoda").checked)
	{
		alert("Prosze wyrazić zgodę na przetwarzanie danych osobowych oraz na wykorzystanie zdjęcia...");
		$("zgoda").focus();
		return false;
	}

	return true;
}





function SetOpacity(elem, opacityAsInt)
{

	if (opacityAsInt==0) 
		elem.style.display = "none";
	else
		elem.style.display = "block";
	
//	alert(elem.style.display);
	
	var opacityAsDecimal = opacityAsInt;
	
	if (opacityAsInt > 100)
		opacityAsInt = opacityAsDecimal = 100; 
	else if (opacityAsInt < 0)
		opacityAsInt = opacityAsDecimal = 0; 
	
	opacityAsDecimal /= 100;
	if (opacityAsInt < 1)
		opacityAsInt = 1; // IE7 bug, text smoothing cuts out if 0
	
	elem.style.opacity = opacityAsDecimal;
	elem.style.filter  = "alpha(opacity=" + opacityAsInt + ")";
}

function FadeOpacity(elemId, fromOpacity, toOpacity)
{
	var steps = 1;
	var delta = (toOpacity - fromOpacity) / steps;
	
	FadeOpacityStep(elemId, 0, steps, fromOpacity, delta, 10);
}

function FadeOpacityStep(elemId, stepNum, steps, fromOpacity, delta, timePerStep)
{
    SetOpacity($(elemId), Math.round(parseInt(fromOpacity) + (delta * stepNum)));

    if (stepNum < steps)
        setTimeout("FadeOpacityStep('" + elemId + "', " + (stepNum+1) + ", " + steps + ", " + fromOpacity + ", " + delta + ", " + timePerStep + ");", timePerStep);
}


function Center(wraper, idx)
{
	if ($(wraper))
	{

		// wielkosc okna przegladarki
		if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		  myWidth = document.body.clientWidth;
		  myHeight = document.body.clientHeight;
		}
	

		myHeight = (myHeight - 30 - 139 - 50)
		$(wraper).style.height = myHeight + "px";

	}
	
//		var myHeight = 500;

	var id = "";
	
	if ($("center")) id = "center";
	if ($("txt")) id = "txt";
	
	
	if (id)
	{
		var divHeight = parseInt(($(id).offsetHeight), 10); 
		
		if (divHeight + 60 > myHeight)
		{
			myHeight = divHeight + 60;
			$(wraper).style.height = myHeight + "px";
		}
	
		if ($("center"))
		{
			topx = ((myHeight - divHeight) / 2 );
			
			margintop = marginbottom = topx;
			
	//		alert(divHeight + " "+margintop);
			$(id).style.marginTop = margintop + "px";
		}
	}
}


function Close()
{
	$("content").innerHTML = "";
	$("main_box").style.display = "none";
	FadeOpacity("overlay", 80, 0);
}

function Show()
{
	if ($("main_box").style.display != "block")
	{
		$("main_box").style.display = "block";
		window.onresize = function () { Center("main_box"); }
		Center("main_box");	
		
//		FadeOpacity("overlay", 0, 80);
		
		SetOpacity(document.getElementById('overlay'), 80);
		
	//	Scroll();
		SetOpacity(document.getElementById('wait'), 100);
	//	isInitialized = false;
		sIFR.isActive = false;
		Fonts();
	}
	else
	{
		FadeOpacity('wait', 0, 100);
	}
}


function Scroll()
{
	var scroller  = null;
	var scrollbar = null;
	scroller  = new jsScroller(document.getElementById("pole_1"), 820, 420);
	scrollbar = new jsScrollbar (document.getElementById("pole_1_winda"), scroller, false);

}



function updateDiv(content) {
	var http = false;
	
	if(navigator.appName == "Microsoft Internet Explorer") {
	  http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
	  http = new XMLHttpRequest();
	}

	http.abort();
  	http.open("GET", content, true);
  	http.onreadystatechange=function() {
//	alert(http.readyState);
	if(http.readyState == 4 || http.readyState=="complete")
    {
      $("content").innerHTML = http.responseText;
	  
	  FadeOpacity('wait', 100, 0);
	  Scroll();
	  Fonts();
	  initSlide();
    }
  }
  http.send(null);
}


function loadTxt(id)
{
	Show();
	updateDiv("ajax_tresc.php?id="+id);
}


function mywidth()
{
	  // wielkosc okna przegladarki
  if( typeof( window.innerWidth ) == 'number' ) {
  //Non-IE
  myWidth = window.innerWidth;
  myHeight = window.innerHeight;
   } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
  //IE 6+ in 'standards compliant mode'
  myWidth = document.documentElement.clientWidth;
  myHeight = document.documentElement.clientHeight;
   } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
  //IE 4 compatible
	  myWidth = document.body.clientWidth;
	  myHeight = document.body.clientHeight;
   }
	
	return myWidth;
}


var zawodnik = 0;

function ViewZawodnik(id)
{
	var zx = zawodnik;
	CloseZawodnik();

	if (zx!=id)	
	{
		$("zawodnik_"+id).style.display = "block";
				
		$("zawodnik_"+id).style.marginTop = -1 * $("zawodnik_"+id).offsetHeight - 7 + "px";
		$("zawodnik_"+id).style.marginLeft = "10px"
		zawodnik = id;
	}
}

function CloseZawodnik()
{
	if ($("zawodnik_"+zawodnik)) 
		$("zawodnik_"+zawodnik).style.display = "none";
	zawodnik = 0;
}

//window.onload = resize;
//window.onresize = resize;
