/**
 * @author
 */
var ie = (navigator.userAgent.indexOf('MSIE')!=-1) ? true : false;
var valid_mail = /^[0-9a-zA-Z\.\-_]+\@+[0-9a-zA-Z\.\-_]+\.+[0-9a-zA-Z]{2,3}$/;

function getFormsNumber ()
{
	return document.forms.length;
}

function getFormName ( form_name )
{
	var number_of_forms = getFormsNumber();
	for( i = 0; i < number_of_forms; i++ )
	{
   	if( document.forms[i].name == form_name )
			return document.forms[i];
	}
}

function showMenu ( contentName )
{
	var area 	= document.getElementById( contentName ) ;

	if ( !area.style.display )
	{
		area.style.display = "none" ;
	}

	if ( area.style.display != "none" )
	{
		area.style.display = "none" ;
	}
	else
	{
		area.style.display = "block" ;
	}

}

function corectDisplay () {
	var box = document.getElementById("pageSlide");
	if ( box ) {
		var hei = (ie) ? document.body.clientHeight : window.innerHeight;

		if( hei < 590 )
		{
			box.className = 'corect';
		}
		else
		{
			box.className = 'normal';
		}
		box.style.visibility = 'visible';
	} else {
		return false;
	}
}

function checkTell ()
{
	var cform = getFormName( 'polec_znajomym' );

	if ( cform )
	{
		var sender 	= ( valid_mail.test( cform.sender_mail.value ) == false ) ? false : true;
		var reciver = ( valid_mail.test( cform.reciver_mail.value ) == false ) ? false : true;

		if( !sender ) {
			alert('Twój adres e-mail jest nieprawidłowy. Proszę poprawić.');
		}
		else if ( !reciver )
		{
			alert('Adres e-mail odbiorcy jest nieprawidłowy. Proszę poprawić.');
		}
		else
		{
			cform.submit();
		}
	}
	else
	{
		return false;
	}
}

function catchError ()
{
	var cform = getFormName( 'polec_znajomym' );
	var msg = location.search;

	if ( cform && msg )
	{
		switch ( msg )
		{
			case "?msg=ok":
			alert('Wiadomość została wysłana pomyślnie. Dziękujemy!');
			break;

			case "?msg=code":
			alert('Podany kod jest błędny. Proszę spróbować ponownie.');
			break;

			case "?msg=error":
			alert('Wystąpił błąd w wysyłaniu wiadomości. Przepraszamy.');
			break;
		}
	}
}

function showimage ( src, w, h )
{
	window.open( 	'popup.php?src=' + src,
						'popup',

						'menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,fullscreen=no,channelmode=no,width=' + w + ',height=' + h + ',left=20,top=20' );
}

function initOnLoad ()
{
	corectDisplay();
	//catchError();
}

onload = initOnLoad
