// JavaScript Document
function slide( type, id_show, id_on, id_off )
{
	$('#' + id_show).slideToggle('slow');

	if( type == "on" )
	{
		$('#' + id_on).hide();
		$('#' + id_off).show();

	}
	else
	{
		$('#' + id_on).show();
		$('#' + id_off).hide();
	}
}

//popup Jquery Block
function loadJavaScript( _path , _init_func )
{
    var base_tag = document.getElementsByTagName('base')[0];
    var base_href = base_tag.getAttribute('href');

    var scripts = document.getElementsByTagName('script');
    var loaded = false;

	for ( var i=0; i<scripts.length; i++)
	{
	    if ( scripts[i].src == base_href + _path )
	    {
	        loaded = true;
	        break;
        }
	}

    if ( loaded == false )
    {
        var head_tag = document.getElementsByTagName('head')[0];

        var newJSf = document.createElement('script');
        newJSf.type = "text/javascript";
        newJSf.src = base_href + _path;

        head_tag.appendChild(newJSf);

        if ( _init_func )
        {
            callFuncTimeout( _init_func, 200 );
        }

    }
}
function callFuncTimeout( _func, _timeout, _repeat )
{
    if ( typeof window.init_recomanda_articol == 'function' || typeof window.init_recomanda_companie == 'function' || typeof window.init_adauga_companie == 'function' || typeof window.init_login == 'function' || typeof window.init_comment == 'function' )
    {
        eval( _func + '()' );
    }
    else
    {
        setTimeout( function() {
            callFuncTimeout( _func, _timeout );
        }, _timeout );
    }
}

function showVideo()
{
    loadJavaScript('scripts/jquery.blockUI.js');

    if ( typeof window.initVideo == 'function' )
    {
        initVideo();
    }
}

function initVideo()
{
    $(document).ready(function()
    {
        var bui_width = 820;
        var bui_height = 610;
        var iframe = $('#blockUI_iframe');
        iframe.css({
            width: bui_width + 'px',
            height: bui_height + 'px'
        });

		var base_tag = document.getElementsByTagName('base')[0];

		var url = base_tag.href + "prezentare.html";
		url = url;
		iframe.attr('src', url );

        $.blockUI({
            message: $('#blockUI_window'),
            css: {
                border: 'none',
                padding: '0px',
                top: ($(window).height() - bui_height) /2 + 'px',
                left: ($(window).width() - bui_width) /2 + 'px',
                width: bui_width + 'px',
                height: bui_height + 'px'
            }
        });

        $('.blockOverlay')
            .attr('title','Click to unblock')
            .click($.unblockUI);
    });
}

function closeVideo()
{
    $.unblockUI();
}


function check_subscribe()
{
    var pemail = document.getElementById('newsletter_email').value;

    if ( !pemail )
    {
		alert('Introduceti o adresa de email pentru a va putea abona!');
		return false;
    }
	if (!pemail.match(/^[a-zA-Z0-9\._\%\-]+@[a-zA-Z0-9\.\-]+\.[a-zA-Z]+$/))
	{
		alert('Adresa de email este invalida!');
		return false;
	}
	return true;
}

function checkTelefon()
{
    var telefon = document.getElementById('telefon_suna').value;
    if(isNaN(telefon))
    {
        alert('Numarul de telefon trebuie sa fie format doar din cifre!');
        return false;
    }
     if(telefon.length < 10 )
    {
    	alert('Numarul de telefon trebuie sa fie format din minim 10 cifre!');
        return false;
    }
}
