function open_wnd(exp_bar,width,height,url,status_bar) {
        winName = "_blank";
        theURL = url;
        page_height = (height != '')?height:600;
        page_width = (height != '')?width:500;
        toolbar = (exp_bar == 1)?'yes':'no';
        statusbar = (status_bar == 1)?'yes':'no';
        page_top = Math.round((screen.height-page_height)/2);
        page_left = Math.round((screen.width-page_width)/2);
        size = "width="+page_width+",height="+page_height+",top="+page_top+",left="+page_left;
        features = 'status='+statusbar+',toolbar='+toolbar+',scrollbars=auto,resizable=yes,'+size;
        window.open(theURL,winName,features);

}

	$(document).ready(function() { 
	
	
	
	
	
	
	   if ($("#in_regform").attr("value") == "1") {
		   
		   $(".tipas").click(function() {

			if ($(this).attr("value") == "fizinis") {
				var required_fields = ["pavarde", "vardas", "telefonas", "telefonas", "email", "uzsiemimu_rusys"];
				CheckForm(required_fields);
			} else if ($(this).attr("value") == "juridinis") {
				var required_fields = ["imones_pavadinimas", "imones_kodas", "telefonas", "email", "uzsiemimu_rusys"];				
				CheckForm(required_fields);
			}
			
			$("#webdev_form").submit(function() {
			
				if (CheckForm(required_fields)) {
					var post_data = $("#webdev_form").serialize();
			        $.post($("#self").val(), post_data, function(data){
			                $("#form_sent").fadeIn("fast", function(){});
			            });
					$("#webdev_form").fadeOut("fast");
				} 
				
				return false;
				
			});
			
			$(".text_input, .input_textarea, select").focus(function(){
				$(this).addClass("focused");
			});
			$(".text_input, .input_textarea, select").blur(function(){
				$(this).removeClass("focused");
				
				CheckForm(required_fields);
				
			});

		   });

	   }
	   
	   
	   
	   
	   
	   
	   
	   if ($("#in_gift_form").attr("value") == "1") {

			var required_fields = ["agreed", "rusis", "atsiemimas", "pirk_pavarde", "pirk_vardas", "pirk_telefonas", "pirk_email", "miestas", "adresas", "pasto_indeksas"];
			CheckForm(required_fields);

			$("#webdev_form").submit(function() {
			
				if (CheckForm(required_fields)) {
					var post_data = $("#webdev_form").serialize();
			        $.post($("#self").val(), post_data, function(data){
			                $("#form_sent").fadeIn("fast", function(){});
			            });
					$("#webdev_form").fadeOut("fast");
				} 
				
				return false;
				
			});
			
			$(".text_input, .input_textarea, select").focus(function(){
				$(this).addClass("focused");
			});
			
			$(".text_input, .input_textarea, select").blur(function(){
				$(this).removeClass("focused");
				
				CheckForm(required_fields);
				
			});
			
			$("input").click(function() {

				CheckForm(required_fields);
				
			});
			
			$("#kuponu_kiekis").change(function() {

				calc_gift()
				
			});
			
	   }
	   
	   
	   
	   
	   
	   
	   
	   
		   // soham spec.

		   $(window).bind("resize", function() {
				var mt_height = $("body").height() - 237;
				
				$(".maintext").css("height", mt_height+"px");
		   });
		   $(window).bind("load", function() {
				var mt_height = $("body").height() - 237;
				$(".maintext").css("height", mt_height+"px");
		   });


	});
	
	
	
	function CheckForm(required_fields) {
	
		$(".asterix > span").removeClass("status_error");
		var allow_submit = true;
			
		if (required_fields.length == 0) return false;
		
		
		
		
		
		for (i=0;i < required_fields.length; i++) {
			if (CheckField(required_fields[i], required_fields))
			allow_submit = false;
		}
		
		if ($("#in_gift_form").attr("value") == "1") {
		
			if ($("#agreed").attr("checked") == "") allow_submit = false;
		
		}
		
		if ( $("#uzsiemimu_laikas").val() == "1" ){	
			allow_submit = false;
		}

		
		if (allow_submit) {
			$(".butt_submit").attr("disabled", "");
			return true; 
		}
		else {
			return false;
		}
	
	}
	
	
	function calc_gift() {
	
		var gift_sum = 0;

		if ( $('input[name=rusis]:checked').attr("id") == "rusis1") gift_sum = gift_sum + 220;
		if ( $('input[name=rusis]:checked').attr("id") == "rusis2") gift_sum = gift_sum + 200;
		if ( $('input[name=rusis]:checked').attr("id") == "rusis3") gift_sum = gift_sum + 180;
		if ( $('input[name=rusis]:checked').attr("id") == "rusis4") gift_sum = gift_sum + 360;
		if ( $('input[name=rusis]:checked').attr("id") == "rusis5") gift_sum = gift_sum + 800;
		if ( $('input[name=rusis]:checked').attr("id") == "rusis6") gift_sum = gift_sum + 120;

		if ( $('input[name=atsiemimas]:checked').attr("id") == "atsiemimas1") gift_sum = gift_sum + 15;
		//if ( $('input[name=atsiemimas]:checked').attr("id") == "atsiemimas2") gift_sum = gift_sum + 0;

		if ($('#kuponu_kiekis').val() > 0) {
			var kuponu_kiekis = $('#kuponu_kiekis').val();
		} else {
			var kuponu_kiekis = 0;
		}
		
		gift_sum = gift_sum * kuponu_kiekis;
		
		$("#kaina").html(gift_sum + " Lt");
	}
	
	
	function CheckField(Field, required_fields) {

		if ((( $('[name=' + Field + ']').val() == "" )) && ( InArray(Field, required_fields) )) {
		
			$("#"+Field+"_ast").addClass("status_error");
		
			return true;
			
		} else {
		
			return false;
		
		}

	}
	
	function InArray(needle, haystack, strict) {

		var found = false, key, strict = !!strict;

	    for (key in haystack) {
	        if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
	            found = true;
	            break;
	        }
	    }

	    return found;
	}

