var _isValid = false;

jQuery.validator.addMethod("phone", function(phone_number, element) {
    //phone_number = phone_number.replace(/\s+/g, ""); 
    return this.optional(element) || phone_number.length >= 9 &&
        phone_number.match(/^(\+420)? ?[0-9]{3} ?[0-9]{3} ?[0-9]{3}$/);
}, "Telefonní číslo je vyžadováno ve formátu (+420 123 456 789)");


jQuery.validator.addMethod("phoned", function(phone_number, element) {
    //phone_number = phone_number.replace(/\s+/g, ""); 
    return this.optional(element) || phone_number.length >= 3 && 
        phone_number.match(/^(\+)[0-9]{2,3}$/);
},  "První předčíslý telefonního čísla je vyžadováno ve formátu (+420)");

jQuery.validator.addMethod("phoned1", function(phone_number, element) {
		    //phone_number = phone_number.replace(/\s+/g, ""); 
		       	return this.optional(element) || phone_number.length >=9  &&
		        phone_number.match(/^[0-9]{3} ?[0-9]{3} ?[0-9]{3}$/);
		}, "<br />Telefonní číslo je vyžadováno ve formátu (+420 123 456 789)" );
		
/*
jQuery.validator.addMethod("phoned1", function(phone_number, element) {
		    //phone_number = phone_number.replace(/\s+/g, ""); 
		       	return this.optional(element) || phone_number.length >= 3 &&
		        phone_number.match(/^[0-9]{3}$/);
		}, validPhone());

function validPhone()
{
	console.log(_isValid);
	 if(_isValid == false){
	 	_isValid = true;
		return "<br />Telefonní číslo je vyžadováno ve formátu (+420 123 456 789)";
	}
	else{
		return "";
	}
	
}*/


 $(document).ready(function(){
        $("#frmservis").validate();        
        $("#frmspojeni").validate();
        $("#frmpoptavka").validate();
        $("#frmzavolame").validate();
        $("#workVacancyForm").validate();
        
 });
 
 
 $(document).ready(function() {

	 $("#telefon").keyup(function() {
	        if ($(this).val().length == 4) {
	               $("#telefon1").focus();
	        }
	});
});
 
$(document).ready(function() {

	 $("#telefon1").keyup(function() {
	        if ($(this).val().length == 3) {
	               $("#telefon2").focus();
	        }
	});
});
$(document).ready(function() {

	 $("#telefon2").keyup(function() {
	        if ($(this).val().length == 3) {
	               $("#telefon3").focus();
	        }
	});
});
