// JavaScript Document

$(function() {
	$('.jlb a').lightBox();
});

function windowOpen(i,I){
    newWindow=window.open(i,I,"height=570,width=770");
	newWindow.focus();
	return false;
}

jQuery.fn.wait = function (MiliSeconds,cb) {
	$(this).animate({ opacity: '+=0' }, MiliSeconds, cb);
	return this;
}


function initMainSlider(slider,panels,btns) {	
	var btn;
	var index;
	var panels = $("#"+panels + " li");
	var btns = $("#"+btns+" li");	
	btns.click(function(){
		btns.removeClass('active');
		btn = $(this).addClass('active');
		index = btns.index(btn);
		panels.fadeOut(200).eq(index).fadeIn(500);
	});
	var slider = $("#"+slider)
	.mouseleave(function(){
		$(this).wait(4000, function() {
			btns.eq( index<btns.size()-1 ? index+1 : 0 ).click();
			slider.mouseleave();
		});
	})
	.mouseenter(function(){
		 $(this).stop(true);
	});	
	$(function() {
		btns.eq(0).click();
		slider.mouseleave();
	});
}

function togglePanel(I,l){ l ? $("#"+I).show() : $("#"+I).hide(); }
function changeParentURL(url) { $("#poz").attr('src',url); }	
function reloadParentURL(url) {	$('#list').attr('src',url);	}

function isEmail(i){
    var I=/^[\w-]+(\.[\w-_]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if(i.match(I))return true;
    else return false
}


function initContactForm(e,f,g,h) {
    $("*[id^='contact_']").blur(function(){
        $(this).removeClass('error');
    });
	
    $("#btnReset").click(function(event){
		event.preventDefault();
        $("#contactForm").resetForm();
    });

    $("#btnSend").click(function (event) {
		event.preventDefault();
        if (jQuery.trim($("#contact_name").val()) == ''){
            alert(e); 
			$("#contact_name").addClass('error').focus();
        }
        else 
		  if (!isEmail(jQuery.trim($("#contact_email").val()))){
            alert(f); 
			$("#contact_email").addClass('error').focus();
        }
        else 
		  if (jQuery.trim($("#contact_subject").val()) == '' ){
            alert(g); 
			$("#contact_subject").addClass('error').focus();
        }
        else 
		  if (jQuery.trim($("#contact_content").val()) == ''){
            alert(h); 
			$("#contact_content").addClass('error').focus();
        }
        else {
            $("body").css('cursor','wait');
            $.ajax({
                type: "GET",
                url: '/_contact.php',
                data: $("#contactForm").formSerialize(),
                success: function(msg){
                    $('#formResult').html(msg);
                    $("body").css('cursor','auto');
                }
            });
		  }
    });
}


function langAutoComplete(input) {
	for (var i=0; i < input.length ; i++) {
		$(".multi_" + input[i] + "[id='" + input[i] + "_pl']").bind('change',{ n: input[i]} ,function(e) {
			var entered = $(this).val();
			$(".multi_" + e.data.n + "[id!='" + e.data.n + "_pl']").each(function() {
				var prev = $(this);
				if (entered != prev.val() && prev.val() == '') 	
					prev.val(entered);	        
			});
		});
	}
}

function changeEditPanel(id,name,number,field) 
{
	$('#lang').change(function() {
		var pars = new Object();
		pars.field = field;
		pars.lang_symbol = $(this).val();
		pars[name] = id;
		pars.tmp = new Date().getTime();
		$.get('/adm/forms/f_'+name+number+'x.php', pars, 
				function(data){$("#desc_body").html(data);});
	});
}


function showMap(x,y,id)
{
    var coors = new google.maps.LatLng(x,y);
    var options = {
        zoom: 15,
        center: coors,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var myMap = new google.maps.Map(document.getElementById(id), options);
    // stworzenie markera
    var markerOptions =
    {
        position: coors,
        map: myMap
    }
    var marker = new google.maps.Marker(markerOptions);
}


function initLogin(x,y) {
    $("#login").focus(function () {
        if ($(this).val() == x ) $(this).val('') ;
    });
    $("#login").blur(function () {
        if (jQuery.trim($(this).val()) == '' ) $(this).val(x) ;
    });
	
    $("#passFake").focus(function () {
        $(this).toggle();
        $("#pass").toggle().focus();
    })	
    $("#pass").blur(function () {
        if (jQuery.trim($(this).val()) == '' ) {
            $(this).toggle();
            $(this).val('');
            $("#passFake").toggle();
        }
    });
    $('#btnSignin').click(function () {
        if (jQuery.trim($('#login').val())=='' || jQuery.trim($('#login').val())==y ) {
            alert(x);
            $('#login').focus;
        } else if (jQuery.trim($('#pass').val())=='' || jQuery.trim($('#pass').val())==y ) {
            alert(y);
            $('#pass').focus;
        } else {
            $("#loginForm").submit();
        }
    });
}

function initLogout(x) {
    $("#signOut").click(function () {
        if(confirm(x)) {
            return true;
        } else {
            return false;
        }
    });
}

