function is_alpha(test, v) {

	if (v == "a") var lists = "abcdefghijklmnoqprstuvwxyzABCDEFGHIJKLMNOQPRSTUVWXYZ_-./ ";
	if (v == "b") var lists = "1234567890abcdefghijklmnoqprstuvwxyzABCDEFGHIJKLMNOQPRSTUVWXYZ_-!,.?()/ ";
	if (v == "c") var lists = "1234567890_-/.\\ ";
	if (v == "d") var lists = "1234567890";
	else var lists = "1234567890abcdefghijklmnoqprstuvwxyzABCDEFGHIJKLMNOQPRSTUVWXYZ_-./ ";

	var match = true;
	var found = false;
	var chars = "";

	for (var i = 0; i < test.length; i++) {
		chars = test.charAt( i );
		found = false;
		for (var j = 0; j < lists.length; j++) {
			if(lists.charAt( j ) == chars) {
				found = true;
				break;
			}
		}
		if (!found) {
			match = false;
			break;
		}
	}
	return match;
}

$(document).ready(function(){
	$('#formcnp').submit(function(){
		var vcnp = $('#cnp').val();
		
		if(vcnp != ''){			
				if(!is_alpha(vcnp, 'd')){
					alert('CNP-ul introdus nu este numeric, sunt acceptate cifrele de la 0 la 9 !');
					return false;
				} else if(vcnp.replace(/^\s+|\s$/g, '').length != 13){
					alert('CNP-ul nu este valid, nu are 13 caractere');
					return false;
				}
					var html = $.ajax({
						type: "POST",
						url: "server.php",
						data: "cnp="+vcnp+"&action=getcnp",
						async: false
					}).responseText;
					if(html == 'exista') {
					return true;
				} else if(html == 'nuexista') {
					alert('CNP-ul introdus nu exista in baza de date\r\nva rugam sa ne contactati, e posibil ca notele pentru elevul respectiv\r\n sa nu fi fost introduse inca.');
					return false;
				}
				return false;
		} else {			
			$('#cnp').css({border: '1px solid red'});
			alert('Introdu corect CNP-ul!');
			return false;
		}		
	});
});

$(document).ready(function() {

	$('a.hasPic').lightBox();
});
 $(document).ready(
				function(){
					
					$('#slider').innerfade({
						speed: 1000,
						timeout: 8000,
						type: 'sequence',
						containerheight: '228px'
					});
					
					});
(function($) {
	$(function() { //on DOM ready
		$("#scroller").simplyScroll({
			autoMode: 'loop'
			
		});
	});
})(jQuery);
