$(document).ready(function() 
{ 
    $("#cellphone").keypress(function () {
        $("#cellphone_error").css("display", "none"); 
    });
    
    $("#contact_form").validate
    ({ 
        rules: 
        { 
            fname: {required:true},
            phone: {digits:true, rangelength: [7,7]},
            cellphone: {required:true, digits:true, rangelength: [7,7]},
            email: {email: true}
        }
//        ,

//        submitHandler: function (form, event) {
//            checkPhones();
//            return false;
//            event.preventBubble = true;
//        }
    });

    $(".submit_btn").click(function () {

        var cellphone = $("#cellphone").val();
        var phone = $("#phone").val();

        if (phone) {
            if (phone.substring(0, 1) < 2) {
                $("#phone_error").css("display", "block");
                return false;
            }
            else {
                $("#phone_error").css("display", "none");
            }
        }

        if (cellphone.substring(0, 1) < 2) {
            $("#cellphone_error").css("display", "block");
            return false;
        }
        else {
            $("#cellphone_error").css("display", "none");
        }

    });

    $("#controller").jFlow({
        slides: "#slides",
        controller: ".jFlowControl", // must be class, use . sign
        slideWrapper : "#jFlowSlide", // must be id, use # sign
        selectedWrapper: "jFlowSelected",  // just pure text, no sign
        auto: true,		//auto change slide, default true
        width: "874px",
        height: "140px",
        duration: 700,
        prev: ".jFlowPrev", // must be class, use . sign
        next: ".jFlowNext" // must be class, use . sign
    });
  
    
}); 


function checkPhones(){
   
    var cellphone = $("#cellphone").val();
    var phone = $("#phone").val();
    
    if (phone){
        if (phone.substring(0,1) < 2){
	        $("#phone_error").css("display", "block"); 
	        return false;
        }
        else{
            $("#phone_error").css("display", "none"); 
        }
    }
    
    if (cellphone.substring(0,1) < 2){
	    $("#cellphone_error").css("display", "block"); 
	    return false;
    }
    else{
        $("#cellphone_error").css("display", "none");
        $("#contact_form").submit();
    }
}
    


