// JavaScript Document
(function($) {
	$.fn.ITSailForm = function(){
		var capp_form = $('div.item', $(this));
		if(capp_form.length == 0) return false;

		var capp_nums = $('ul.capp_nums li');
		var lastId = 0;

		$('img.submit', $(this)).click(function(){
			capp_numsClick(lastId + 1);
		});
		
		//alert(capp_form.length);
		capp_form.hide();
		capp_nums.click(function(){
			capp_numsClick($(this).index());
		});

		function capp_numsClick(id) {
			var inreq = $('.inreq', capp_form.eq(lastId));
			var str = "";
			var lastItem = null;
			$.each(inreq, function(i, it){
				if($(this).val().length == 0) {
					if(lastItem == null) lastItem = $(this);
					str += $(this).attr('name').replace(/frm\[(.*)\]/g, "$1") + "\n";
				}
				
				if(id == 7) {
					if($(this).attr('type') == 'checkbox' && $(this).attr('checked') == false) {
						//alert($(this).attr('checked'));
						//alert("You should agree with requirement");
						//$(this).focus();
						//return false;
						str += "You should agree with requirement!";
						if(lastItem == null) lastItem = $(this);
					}
				}
			});
			if(str.length > 0) {
				alert("Please fill the below fields:\n\n" + str + "\n\n");
				lastItem.focus();
				return false;
			}
			
			if(id >= capp_form.length) {
				itsail_form_er(2);
				//alert('submit');
				return false;
			}

			capp_nums.eq(lastId).removeClass('on');
			capp_form.eq(lastId).hide();

			capp_nums.eq(id).addClass('on');
			capp_form.eq(id).show();

			lastId = id;
			//alert(id);
		}

		capp_form.eq(0).show();

	};
})(jQuery);


