$j(document).ready(function() {

	window.verifyKeyAndIncludeSelection = function() {
		var iflag = false;
		var kflag = false;
                
                
                // Now let's try to check if user's trying to be brat by not selecting a key and/or include
                if ($j('input.source-keybox:checked').length == 0)
                {
                    var message = "You didn't select any source field as KEY field(s)";
                    $j('#sourcefield_error').show().html('<b>Error:</b> ' + message);
                    alert(message);
                    return false;
                }
                else if ($j('input.source-includebox:checked').length == 0)
                {
                    var message = 'You didn\'t select any source field as INCLUDE field';
                    $j('#sourcefield_error').show().html('<b>Error:</b> ' + message);
                    alert(message);
                    return false;
                }
                
                $j('#sourcefield_error').html('').hide();

		el = $j('table.list');
		for(var g=0; g < el.length; g++) {

			var count = document.getElementById('count').value;
			var start = document.getElementById('start').value;
			var shown = document.getElementById('sourceFieldsSingle');

			var sinclude = "";
			var skey = "";
                        
			if(shown.style.display == "block")
				tableid = null;
			else
				tableid = "multi";
                            //alert(tableid);
			if($j(el[g]).attr('id') == tableid) {

				iflag = false;
				kflag = false;

				var ele = el[g].getElementsByTagName("input");
				for( var i =0 ; i < (ele.length); i++){
					if(ele[i].type == 'radio') {
						iflag = iflag || ele[i].checked;
					} else {
						if(ele[i].id.indexOf('minclude') > -1)
							iflag = iflag || ele[i].checked;
						else
							kflag = kflag || ele[i].checked;
					}
				}
				if(!kflag || !iflag) break;
			}
		}

		if (!kflag || !iflag)
                {
                    if (!kflag)
                        alert("At least one field should be set as key for each Source Table" );
                    else if (!iflag)
                        alert("At least one field should be included for each Source Table");

                    return false;
		}
                
                
                return true;
	}



//    $j('form[name=mapping]').on("submit", function(e) {
//
//        if (!verifyKeyAndIncludeSelection(e.target))
//            e.preventDefault();
//
//    });



});