jQuery.fn.ForceNumericOnly =
function()
{
    return this.each(function()
    {
        $(this).keydown(function(e)
        {
            var key = e.charCode || e.keyCode || 0;
            // allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
            return (
                key == 8 || key == 17 || key == 17 || key == 46 || key == 86 || key == 67 ||   key == 189 ||
                key == 9 ||
                key == 46 || key == 12 || key == 61 || key == 109 ||
                (key >= 37 && key <= 40) ||
                (key >= 48 && key <= 57) ||
                (key >= 96 && key <= 105));
        })
    })
};

$(document).ready(function() {
var screenWidth = 0;
screenWidth=getWidth();
function getWidth()
{
  if (window.innerWidth)
        return window.innerWidth;
  else if (document.documentElement && document.documentElement.clientWidth)
     return document.documentElement.clientWidth;    
  else if (document.body)
    return document.body.clientWidth;
}
 
  $(window).bind("resize", function(){
        screenWidth=getWidth();
        if (screenWidth>1000){
            $("#fixme").css('left', (screenWidth-825)/2-90);
            $("#fixme").fadeIn("fast");
            }
        else{
             $("#fixme").fadeOut("fast");
             }
})
   // alert((screen.width-825)/2-40);
    $("#fixme").css('left', (screenWidth-825)/2-90);
  
    if (screenWidth>1000)
        $("#fixme").fadeIn("fast");
    else
         $("#fixme").fadeOut("fast");

    $("#wz_12").ForceNumericOnly();
Array.max = function( array ){
    return Math.max.apply( Math, array );
}; 

	$('#Form1').submit(function() {

        $alert_message = "אנא מלאו בבקשה את השדות הבאים :\n";
        if ($('#wz_11').val()=="" || $('#wz_11').val()=="שם:"){
            $alert_message+="שדה \"שם:\" הינו שדה חובה . \n";
        }   
        if ($('#wz_12').val()=="" || $('#wz_12').val()=="טלפון:"){
            $alert_message+="שדה \"טלפון:\" הינו שדה חובה . \n";
        }
        else{
             if ($('#wz_12').val().length<8 || $('#wz_12').val().length>12)
                    $alert_message+="הטלפון שהזנת אינו תקין - כנראה חסרים מספרים . \n";
             else{
             // count what the most length of squences
                var digits=new Array(1,1,1,1,1,1,1,1,1,1,1,1,1,1);
                var j=0;
                var lastdigit=$('#wz_12').val().charAt(0);
                for( i=0; i < $('#wz_12').val().length; i++){
                    if ($('#wz_12').val().charAt(i)==lastdigit)
                   
                        digits[j]=digits[j]+1;
                      else{
                         lastdigit=$('#wz_12').val().charAt(i);
                         j=j+1;
                         }
                    }
                    if (Math.max.apply(null,digits)>5){
                      $alert_message+="הטלפון אינו תקין - אנא הזן טלפון תקין . \n";  
                    }
                    
                   
            }
           
        }
        if ($alert_message == "אנא מלאו בבקשה את השדות הבאים :\n"){
            return true;
        }
        else{ 
        alert($alert_message);  
        return false;
        }
    });
});
