// JavaScript Document

function show_window(adres, width, height) 
{
	wspolrzednax = (screen.width-width)/2;
	wspolrzednay = (screen.height-height)/2;
	window.open(adres, "abonamenty","menubar=no, toolbar=no, scrollbars=no, resizable=no,location=no, status=no, width="+width+", height="+height+", left="+wspolrzednax+", top="+wspolrzednay+"");
}

function pokaz(obiekt)
{ 
	document.getElementById(obiekt).style.display = "block";
}

function ukryj(obiekt) 
{ 
	document.getElementById(obiekt).style.display = "none";
}

function on_blur(obj)
{
	if (obj.value=='') 
		obj.value=g_input_value;
}


function on_focus(obj)
{
	g_input_value=obj.value; 
	if (g_input_value=="Szukaj w SerwisPrawa.pl" || g_input_value=="Wpisz swój adres e-mail")
		obj.value='';
}


function bookmark(){
    var title="SerwisPrawa.pl";
    var url="http://www.serwisprawa.pl";

    if (window.sidebar) window.sidebar.addPanel(title, url,"");

    else if( window.opera && window.print )
    {
    var mbm = document.createElement('a');
    mbm.setAttribute('rel','sidebar');
    mbm.setAttribute('href',url);
    mbm.setAttribute('title',title);
    mbm.click();
    }

    else if( document.all ) window.external.AddFavorite( url, title);

}


function check_email(email)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]+)+$/;
	
	if (filter.test(email)) 
		return true;
	else
		return false;
}

function validateEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email)== false) 
      return false;
   return true;
}

function validate_comment_form(obj)
{
	var msg='Proszę uzupełnić pola: ';
	var arr=new Array;
	
	if (obj.ftitle.value=='')
		arr.push('tytuł');
		
	if (obj.fcomm.value=='')
		arr.push('komentarz');
		
	if (obj.fname.value=='')
		arr.push('imię i nazwisko');
		
	msg=msg+arr.join(', ');
	
	if (arr.length>0)
	{
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}
}


function validate_stf_form(obj)
{
	var msg='Proszę poprawnie uzupełnić pola: ';
	var arr=new Array;
	
	if (!check_email(obj.femail1.value))
		arr.push('e-mail znajomego');

	if (obj.fcsi.value=='')
		arr.push('kod');
		
	msg=msg+arr.join(', ');
	
	if (arr.length>0)
	{
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}
}


function validate_newsletter_form(obj)
{
	if (!check_email(obj.email.value))
	{
		alert('Podaj poprawny adres e-mail');
		return false;
	}
	else
	{
		return true;
	}
}


function chce_fv()
{
	if (document.getElementById('fv').checked) document.getElementById('faktura').style.display='block'; else document.getElementById('faktura').style.display='none';
	
	document.getElementById('arr_form_fields[firm]').value=document.getElementById('arr_form_fields[first_name]').value+' '+document.getElementById('arr_form_fields[last_name]').value;
	
	document.getElementById('arr_form_fields[firm_street]').value=document.getElementById('arr_form_fields[street]').value;
	document.getElementById('arr_form_fields[firm_city]').value=document.getElementById('arr_form_fields[city]').value;	
	document.getElementById('arr_form_fields[firm_flat_number]').value=document.getElementById('arr_form_fields[flat_number]').value;
	document.getElementById('arr_form_fields[firm_house_number]').value=document.getElementById('arr_form_fields[house_number]').value;
	document.getElementById('arr_form_fields[firm_zip]').value=document.getElementById('arr_form_fields[zip]').value;
}


function change_abonament_desc(id, element, name)
{
	
	el=document.getElementById(element);
	
	for (i=0; i<el.childNodes.length; i++)
	{
		if (el.childNodes[i].className==name)
			el.childNodes[i].style.display='none';
	}
	
	document.getElementById('abonament_desc'+id).style.display='block';
}


function referer_change(id)
{	
	$('#inna_strona1').hide();
	$('#inna_strona2').hide();
	$('#inne_zrodlo1').hide();
	$('#inne_zrodlo2').hide();
	
	if (id==5)
	{
		$('#inna_strona1').show();
		$('#inna_strona2').show();
	}
	
	if (id==7)
	{
		$('#inne_zrodlo1').show();
		$('#inne_zrodlo2').show();
	}
		
}
