function validateEmail(email) {
    var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(String(email).toLowerCase());
}

function validatePhone(phone) {
    var re = /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,7}$/im;
    return re.test(phone);
}

function instantPrint(divName) {
	var printContents = document.getElementById(divName).innerHTML;
	var originalContents = document.body.innerHTML;

	document.body.innerHTML = printContents;
	window.print();
	document.body.innerHTML = originalContents;
}

(function($){
	$.fn.refreshMockForMastersheet = function(options) {

		var defaultContentField = $(this).find("tbody");
		var defaultContent = $(defaultContentField).html();

      	$.ajax({
		    type: 'POST',
		    url: 'contents/plugins/external_examination/ajax.php',
		    data: {action: 'get_mock_for_mastersheet'},
		    success: function(data) {

		    	var html = "";
		    	try {
		    		data = JSON.parse(data);
		    		var i = 1;
		    		for(var key in data.res) {
			    		html += '<tr>';
			    		html += '<td>'+i+'</td>';
			    		html += '<td>'+data.res[key].term_name+'</td>';
			    		html += '<td>'+data.res[key].class_name+'</td>';
			    		html += '<td>'+data.res[key].ext_exam+'</td>';
			    		html += '<td><a href="javascript:void(0);" class="remove_post_item" data-callback="refreshMockForMastersheet" data-callbackid=".mock_for_mastersheet_table" data-id="'+data.res[key].id+'">Remove</a></td>';
			    		html += '</tr>';
			    		i++;
			    	}
		    		$(defaultContentField).html(html);
		    	}
		    	catch(err) {
		    		console.log(err);
		    		console.log(data);
		    		$(defaultContentField).html(defaultContent);
		    	}
		    	finally {

		    	}
		    },
		    error: function(e) {
		    	$(defaultContentField).html(defaultContent);
		    }
		});
   };
})(jQuery)