var base_url='http://dev.emanuel-lainas.com/windsoft';
function back_to_config(){
	$('#config_result').fadeOut(2000, function(){
		$('#configurator_solutii form').fadeIn(1000);
	});
}
$(document).ready(function(){
	/*if ($('#dreapta2_1').height()>$('#dreapta2_2').height()) {
		$('#dreapta2_2').height($('#dreapta2_1').height());
	} else {
		$('#dreapta2_1').height($('#dreapta2_2').height());
	}*/

	$('.submeniu').width(function(){
		if ($(this).width() < $(this).parent().width()) {
			width=$(this).parent().width();
			return width;
		}
	});
	$('.submeniu_bottom_center').width(function(){
		width=$(this).parent().parent().width();
		width1=width-14;
		return width1;
	});
	$('.submeniu_item').hover(function(){
		$(this).toggleClass('submeniu_item_hover');
	});
	$('#conf_sol,#config_sol').fancybox({
		'scrolling':'no'
	});
	$('#configurator_solutii form').submit(function(ev){
		ev.preventDefault();
		/* Validarea formularului*/
		var rege = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if (($('input[type="text"]', this).val()=='')){
			alert('Completati toate campurile');
		} else {
			if(!rege.test($('#e-mail').val())){
				alert('Introduceti o adresa de mail valida!')
			} else {
				if ((!$('#da_contact').attr('checked')&&!$('#nu_contact').attr('checked'))||
					(!$('#sub_10').attr('checked')&&!$('#peste_10').attr('checked'))||
					(!$('#un_pct').attr('checked')&&!$('#mai_multe_pct').attr('checked'))||
					(!$('#case_exp').attr('checked')&&!$('#transportatori').attr('checked')&&
					!$('#service').attr('checked')&&!$('#paza_protectie').attr('checked')&&
					!$('#alta_comp_flota').attr('checked')&&!$('#alta_comp').attr('checked'))) {

						alert('Completati tipul companiei, numarul de utilizatori, numarul punctelor de lucru si daca doriti sa fiti contactat dupa trimiterea formularului.')
				} else{
					$.ajax({
						type:'POST',
						url:'inc/configurator.php',
						data:$(this).serialize(),
						success: function(data) {
							$('#config_form').fadeOut(2000, function(){
								$('#config_result').html(data);
								$('#config_result').fadeIn(1000);
							});
						}

					});
				}
			}
		}
	});
	$('.checkbox_max2').click(function(ev){
		if ($('.checkbox_max2:checked').length>2) {
			ev.preventDefault();
		}
	});
	$('#da_contact').click(function(){
		$('#nu_contact').attr('checked',false);
	});
	$('#nu_contact').click(function(){
		$('#da_contact').attr('checked',false);
	});
	$('#sub_10').click(function(){
		$('#peste_10').attr('checked',false);
	});
	$('#peste_10').click(function(){
		$('#sub_10').attr('checked',false);
	});
	$('#un_pct').click(function(){
		$('#mai_multe_pct').attr('checked',false);
	});
	$('#mai_multe_pct').click(function(){
		$('#un_pct').attr('checked',false);
	});
	$("#telefon, #contact_telefon").keydown(function(event) {
		// Allow only backspace and delete
		if( !(event.keyCode == 8                                // backspace
        || event.keyCode == 46                              // delete
        || (event.keyCode >= 35 && event.keyCode <= 40)     // arrow keys/home/end
		|| (event.keyCode >= 48 && event.keyCode <= 57)     // numbers on keyboard
		|| (event.keyCode >= 96 && event.keyCode <= 105))   // number on keypad
		) {
			event.preventDefault();     // Prevent character input
		}
	});
	
	if (window.location.hash!='') {
	    $('.page_content').hide();
	    $('.active').removeClass('active');
	    $('#section_menu_contents li[rel='+window.location.hash+']').addClass('active');
        $('.active ul li:first').addClass('active');
        $($('.active ul li:first a').attr('rel')).show();
        $('#section_menu_contents_produse li ul li a[rel='+window.location.hash+']').parent().addClass('active');

	    $(window.location.hash).show();
    }
	$('#section_menu_contents a').click(function(){
		$('li').removeClass('active');
		$(this).parent().addClass('active');
		$(this).parent().parent().parent().addClass('active');
		var pagina=$(this).attr('rel');
		$('.page_content').hide();
		$(pagina).show();
	});
	$('#section_menu_contents_produse a').click(function(){
		$('li').removeClass('active');
		$(this).parent().addClass('active');
		var pagina=$(this).attr('rel');
		$('.page_content').hide();
		$(pagina).show();
	});
	$('#formular_contact form').submit(function(ev){
		if (($('input:text',this).val()=='') ||($('textarea',this).val()=='')){
			ev.preventDefault();
			alert('Toate campurile sunt obligatorii'+$(this).attr('name'));
		}
		
	});
	$('.servicii_link').hover(
	    function(){
	        $(this).css('background-image','url('+base_url+'/imagini/hover1.jpg)');
	        $(this).css('color','#ffffff');
	    },
	    function(){
	        $(this).css('background-image','url('+base_url+'/imagini/normal1.jpg)');
	        $(this).css('color','#ffffff');
	    }
    );
    
	$('.servicii_link').click(function(){
	    if ($('.submeniu_lateral',this).css('display')=='block') {
	        $('.submeniu_lateral').fadeOut();
	    } else {
	        $('.submeniu_lateral').fadeOut();
	        $('.submeniu_lateral',this).fadeIn();
	    }
	});
	$('.submeniu_lateral li a').hover(
	    function(){
	        $(this).css('background','#F0F0F2');
	    },
	    function(){
	        $(this).css('background','transparent');
	    }
	);
});

