$(document).ready(function() {
    var options = {
        target:        '#medicala',   // target element(s) to be updated with server response
        beforeSubmit:  showRequest,  // pre-submit callback
        success:       showResponse  // post-submit callback
        // other available options:
        //url:       url         // override for form's 'action' attribute
        //type:      type        // 'get' or 'post', override for form's 'method' attribute
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type)
        //clearForm: true        // clear all form fields after successful submit
        //resetForm: true        // reset the form after successful submit

        // $.ajax options can be used here too, for example:
        //timeout:   3000
    };
		var options1 = {
        target:        '#business',   // target element(s) to be updated with server response
        beforeSubmit:  showRequest,  // pre-submit callback
        success:       showResponse  // post-submit callback
		};
		var options2 = {
        target:        '#locuinta',   // target element(s) to be updated with server response
        beforeSubmit:  showRequest,  // pre-submit callback
        success:       showResponse  // post-submit callback
		};
		var options3 = {
        target:        '#casco',   // target element(s) to be updated with server response
        beforeSubmit:  showRequest,  // pre-submit callback
        success:       showResponse  // post-submit callback
		};

    // bind to the form's submit event
    $('#comanda_online').submit(function() {
        // inside event callbacks 'this' is the DOM element so we first
        // wrap it in a jQuery object and then invoke ajaxSubmit
        $(this).ajaxSubmit(options);
        // !!! Important !!!
        // always return false to prevent standard browser submit and page navigation
        return false;
    });
		$('#business_online').submit(function() {
       $(this).ajaxSubmit(options1);
			 return false;
		});
		$('#locuinta_online').submit(function() {
       $(this).ajaxSubmit(options2);
			 return false;
		});
		$('.asigurare_locuinta').submit(function() {
       $(this).ajaxSubmit(options2);
			 return false;
		});
		$('.asigurare_casco').submit(function() {
       $(this).ajaxSubmit(options3);
			 return false;
		});
		

// pre-submit callback
function showRequest(formData, jqForm, options) {
    // formData is an array; here we use $.param to convert it to a string to display it
    // but the form plugin does this for you automatically when it submits the data
    var queryString = $.param(formData);

    // jqForm is a jQuery object encapsulating the form element.  To access the
    // DOM element for the form do this:
    // var formElement = jqForm[0];

   // alert('About to submit: \n\n' + queryString);

    // here we could return false to prevent the form from being submitted;
    // returning anything other than false will allow the form submit to continue
    return true;
}

// post-submit callback
function showResponse(responseText, statusText)  {
    // for normal html responses, the first argument to the success callback
    // is the XMLHttpRequest object's responseText property

    // if the ajaxSubmit method was passed an Options Object with the dataType
    // property set to 'xml' then the first argument to the success callback
    // is the XMLHttpRequest object's responseXML property

    // if the ajaxSubmit method was passed an Options Object with the dataType
    // property set to 'json' then the first argument to the success callback
    // is the json data object returned by the server

   // alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +'\n\nThe output div should have already been updated with the responseText.');
}
});
$(document).ready(function() {
	 
	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
		$( 'html, body' ).animate( { scrollTop: 0 }, 0 );
    //Cancel the link behavior
		e.preventDefault();
		//Get the A tag
		var id = $(this).attr('href');

		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();

		//Set height and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});

		//transition effect
		$('#mask').fadeIn(1000);
		$('#mask').fadeTo("slow",0.8);

		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();

		//Set the popup window to center
    $(id).css('top',  winH/2-300);
		$(id).css('left', winW/2-$(id).width()/2);

		//transition effect

		var base="<?=BASE;?>";
		var site= "<?=BASE;?>pages/asigurare_medicala.php";
		$(id).fadeIn(2000);

		});
		
		//select all the a tag with name equal to rcaCalc
	$('a[name=rcaCalc]').hover(function(e) {
		$( 'html, body' ).animate( { scrollTop: 0 }, 0 );
    //Cancel the link behavior
		e.preventDefault();
		//Get the A tag
		var id = $(this).attr('href');

		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();

		//Set height and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});

		//transition effect
		$('#mask').fadeIn(1000);
		$('#mask').fadeTo("slow",0.8);

		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();

		//Set the popup window to center
    $(id).css('top',  winH/2-300);
		$(id).css('left', winW/2-$(id).width()/2);

		//transition effect

		var base="<?=BASE;?>";
		var site= "<?=BASE;?>pages/asigurare_medicala.php";
		$(id).fadeIn(2000);

		});
		
    //business
		$('a[name=medical]').click(function(e) {
		$( 'html, body' ).animate( { scrollTop: 0 }, 0 );
    //Cancel the link behavior
    e.preventDefault();
   
		//Get the A tag
		var id = $(this).attr('href');

		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();

		//Set height and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});

		//transition effect
		$('#mask').fadeIn(1000);
		$('#mask').fadeTo("slow",0.8);

		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();

		//Set the popup window to center
		//$(id).css('top',  "winH/2"-300);
    $(id).css('top',  "50%");
    $(id).css('margin-top',  "-300px");
		$(id).css('left', winW/2-$(id).width()/2);

		//transition effect

		var base="<?=BASE;?>";
		var site= "<?=BASE;?>pages/asigurare_business.php";
		$(id).fadeIn(2000);

		});
    //business
		$('a[name=business]').click(function(e) {
		$( 'html, body' ).animate( { scrollTop: 0 }, 0 );
    //Cancel the link behavior
		e.preventDefault();
		//Get the A tag
		var id = $(this).attr('href');

		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();

		//Set height and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});

		//transition effect
		$('#mask').fadeIn(1000);
		$('#mask').fadeTo("slow",0.8);

		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();

		//Set the popup window to center
		$(id).css('top',  winH/2-300);
		$(id).css('left', winW/2-$(id).width()/2);

		//transition effect

		var base="<?=BASE;?>";
		var site= "<?=BASE;?>pages/asigurare_business.php";
		$(id).fadeIn(2000);

		});
// locuinta
	$('a[name=locuinta]').click(function(e) {
		$( 'html, body' ).animate( { scrollTop: 0 }, 0 );
    //Cancel the link behavior
		e.preventDefault();
		//Get the A tag
		var id = $(this).attr('href');

		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();

		//Set height and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});

		//transition effect
		$('#mask').fadeIn(1000);
		$('#mask').fadeTo("slow",0.8);

		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();

		//Set the popup window to center
		$(id).css('top',  winH/2-300);
		$(id).css('left', winW/2-$(id).width()/2);

		//transition effect

		var base="<?=BASE;?>";
		var site= "<?=BASE;?>pages/asigurare_business.php";
		$(id).fadeIn(2000);

		});

// casco
		 $('a[name=casco]').click(function(e) {
		$( 'html, body' ).animate( { scrollTop: 0 }, 0 );
    //Cancel the link behavior
		e.preventDefault();
		//Get the A tag
		var id = $(this).attr('href');

		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();

		//Set height and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});

		//transition effect
		$('#mask').fadeIn(1000);
		$('#mask').fadeTo("slow",0.8);

		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
		
		//Set the popup window to center
    //$(id).css('top',  winH/2-$(id).height()/2+350);
		$(id).css('top',  winH/2-300);
		$(id).css('left', winW/2-$(id).width()/2);

		//transition effect

		var base="<?=BASE;?>";
		var site= "<?=BASE;?>pages/asigurare_business.php";
		$(id).fadeIn(2000);

		});
	//if close button is clicked
	$('.close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();		
		setTimeout(function(){
							$('#mask').hide();
							$('.window').hide(); 
							$('#mask').remove(); 
							$('#frame').append('<div id="mask"></div>');
					} , 1000);
		location.reload();
		
		
		

	});

	//if mask is clicked
	//$('#mask').click(function () {
	//	$(this).hide();
	//	$('.window').hide();
	//});

});
$(function() {
	$("#datepicker").datepicker({
		dateFormat: 'dd.mm.yy',
		minDate: 0,
		showOn: 'button',
		buttonImage: base+'images/calendar.gif',
		buttonImageOnly: true});
});
$(function() {
	$('#altaadresa').hide();
	$("#livrare").change(function() {
		if (this.value == 2 ) {$("#altaadresa" ).show();} else {$("#altaadresa" ).hide();}
	});
});

function dynamic_Select(ajax_page, country) {
	$.ajax({
		type: "POST",
		url: base+'include/'+ajax_page,
		data: "judet=" + country,
		dataType: "text/html",
		
		success: function(html){$("#txtResult").html(html);	}
	});
}
function dynamic_Select_2(ajax_page, country) {
	$.ajax({
		type: "POST",
		url: base+'include/'+ajax_page,
		data: "judet=" + country,
		dataType: "text/html",
		success: function(html){ $("#txtResult").html(html);	}
	});
}
function get_moneda(value) {
	document.getElementById('locuinta_mon').innerHTML=value;
  //document.getElementById('mon2').innerHTML=value;
}
function dynamic_Select_3(ajax_page, country) {
	$.ajax({
		type: "POST",
		url: base+'include/'+ajax_page,
		data: "judet=" + country,
		dataType: "text/html",
		success: function(html){$("#casco_localitati").html(html);	}
	});
}

function dynamic_Select_4(ajax_page, country) {
	$.ajax({
		type: "POST",
		url: base+'include/'+ajax_page,
		data: "judet=" + country,
		dataType: "text/html",
		success: function(html){$("#td_civila_localitate").html(html);	}
	});
}

function dynamic_Select_5(ajax_page, country) {
	$.ajax({
		type: "POST",
		url: base+'include/'+ajax_page,
		data: "judet=" + country,
		dataType: "text/html",
		
		success: function(html){$("#td_medicala_localitate").html(html);	}
	});
}

function dynamic_Select_6(ajax_page, country) {
	$.ajax({
		type: "POST",
		url: base+'include/'+ajax_page,
		data: "judet=" + country,
		dataType: "text/html",
		
		success: function(html){$("#td_business_localitate").html(html);	}
	});
}
function dynamic_Select_7(ajax_page, country) {
	$.ajax({
		type: "POST",
		url: base+'include/'+ajax_page,
		data: "judet=" + country,
		dataType: "text/html",
		
		success: function(html){$("#td_locuinta_cladire_localitate").html(html);	}
	});
}
function dynamic_Select_8(ajax_page, country) {
	$.ajax({
		type: "POST",
		url: base+'include/'+ajax_page,
		data: "judet=" + country,
		dataType: "text/html",
		
		success: function(html){$("#td_locuinta_localitate").html(html);	}
	});
}
function dynamic_Select_9(ajax_page, country) {
	$.ajax({
		type: "POST",
		url: base+'include/'+ajax_page,
		data: "judet=" + country,
		dataType: "text/html",
		
		success: function(html){$("#td_rca_localitate").html(html);	}
	});
}
function disableall(){
	$("#rca_optiuni1").attr("disabled","disabled");
	$("#rca_optiuni2").attr("disabled","disabled");
	$("#rca_optiuni3").attr("disabled","disabled");
	$("#rca_optiuni4").attr("disabled","disabled");
	$("#rca_optiuni5").attr("disabled","disabled");
	$("#rca_optiuni6").attr("disabled","disabled");
	$("#rca_optiuni7").attr("disabled","disabled");
	$("#rca_optiuni8").attr("disabled","disabled");
}

function enable1(){
	disableall();
	$("#rca_optiuni1").removeAttr("disabled");
}
function enable2(){
	disableall();
	$("#rca_optiuni2").removeAttr("disabled");
}
function enable3(){
	disableall();
	$("#rca_optiuni3").removeAttr("disabled");
}

function enable4(){
	disableall();
	$("#rca_optiuni4").removeAttr("disabled");
}

function enable5(){
	disableall();
	$("#rca_optiuni5").removeAttr("disabled");
}

function enable6(){
	disableall();
	$("#rca_optiuni6").removeAttr("disabled");
}

function enable8(){
	disableall();
	$("#rca_optiuni8").removeAttr("disabled");
}

