
function indPageImg(imgNum, imgSpeed){
    var imgArr=new Array(imgNum);
    for(var key=1; key < imgNum+2; key++){
        imgArr[key-1]='img/home_'+key+'.jpg';
        //return imgArr[key];
        //alert(imgArr);
    }
    changImg(0)
    function changImg(changImgNum){
                   if(changImgNum < imgNum)
  {changImgNum++;}
          else{changImgNum = 0;}
  $('.bg_all .bg_2').fadeIn(0);
          $('.bg_all .bg_1').css({'background-image': 'url('+imgArr[changImgNum]+')'});
          $('.bg_all .bg_2').delay(3000).fadeOut(imgSpeed, function(){
    $('.bg_all .bg_2').css('background-image','url('+imgArr[changImgNum]+')');
    changImg(changImgNum)});
   }
    
}

function validateGrade(evt) {
  var theEvent = evt || window.event;
  var key = theEvent.keyCode || theEvent.which;
  if (key!=8)
  {
  key = String.fromCharCode( key );

  var regex = /[1-5]|\./;
  if( !regex.test(key) ) {
    theEvent.returnValue = false;
    if(theEvent.preventDefault) theEvent.preventDefault();
  }
   }
}


function getImgSmall(){
    /*for(var key = 1; i< imgNum+1; i++){
        $('.indImgGall div.muve').append('<a href="" ><img src="img/ofn_'+i+'_sm.jpg" alt></img></a>');
    }*/
    $('a.toLeft').css({'opacity': 0.5});
    var imgNum = $('.indImgGall  div.muve a').length;
    var tempW = $('.indImgGall  div.muve a').outerWidth()+20;
    $('.indImgGall div.muve').width(tempW*imgNum+10);
    
    getImgSmall.toRight = function (){
        var posTemp = $('.indImgGall div.muve').css('left');
        posTemp =  parseFloat(posTemp);
        if(posTemp%tempW == 0||posTemp==0){
            if(posTemp+760 < tempW*imgNum)
            {
              $('.indImgGall div.muve').animate({'left': posTemp+tempW+'px'}, 500,function(){
                  var posTemp = $('.indImgGall div.muve').css('left');
                  posTemp =  parseFloat(posTemp);
                  if(posTemp+760 < tempW*imgNum)
                  {
                     $('a.toLeft').css({'opacity': 1});
                  }
                  else
                  {
                     $('a.toRight').css({'opacity': 0.5});
                  }
              });
                
            }
            
       }
    }
    getImgSmall.toLeft = function (){
        var posTemp = $('.indImgGall div.muve').css('left');
        posTemp = parseFloat(posTemp);
        if(posTemp%tempW == 0||posTemp==0){
            if(posTemp+1 > tempW){
              $('.indImgGall div.muve').animate({'left': posTemp-tempW+'px'}, 500,function(){
                var posTemp = $('.indImgGall div.muve').css('left');
                posTemp =  parseFloat(posTemp);
                if(posTemp+1 > tempW){
                  $('a.toRight').css({'opacity': 1});
                }
                else
                {
                  $('a.toLeft').css({'opacity': 0.5});
                }
              });
                
            }
        }
    }
}

function getMap(obj){
  if(obj.attr('class') == 'cl'){
       $('b.op').removeClass('op').addClass('cl');
       $('.imgMap').animate({height: '0'}, 
            500,
            function(){obj.parents('.articl').children('.imgMap').animate({height: '430px'}, 
                500, 
                function(){obj.removeClass('cl').addClass('op')
            });
       });
    }
    else{
        obj.parents('.articl').children('.imgMap').animate({height: '0'}, 500, function(){obj.removeClass('op').addClass('cl')});
    }
}

function forFormOn(obj){
    obj.css({'border-color': 'rgb(210, 35, 42)'});
}
function forFormOff(obj){
    obj.css({'border-color': 'rgb(215, 215, 215)'});
}
          
 function sendmail() {
    var mess = "";
    var flag = true;
    if (($("#name").val() == "") || ($("#name").val() == "שדה חובה")) {
        // $("#name").val("שדה חובה");
        $("#name").css({'border-color': 'rgb(210, 35, 42)'});
        flag = false;
    }


    var regex = new RegExp("^([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$");
    if (!regex.test($("#mail").val())) {
        $("#mail").css({'border-color': 'rgb(210, 35, 42)'});
        flag = false;
    }
    if (flag) {
        $("#contactvalidmess").html("");
        $.post("handlers/SendMail.ashx",
                   {
                       fullName: $("#name").val(),
                       phone: $("#tel").val(),
                       email: $("#mail").val(),
                       message: $("#message").val()
                   }
            , function (data) {
                if (data == "sucsses") {
                    $("#contactForm").html("<div class=\"sendemailmessage\" ><br/><br/>תודה על פנייתך</div>");
                }
            });
    }

}
  
  
function sendBuyTest(){
   $(".errorMesWrap").hide();
    var flag = true;
$(".questionnaireContent input").each(function(){
  if($(this).val() == "")
  {
    flag = false;
  }
});

if (!$(".jqTransformChecked").length > 0 )
{
    flag = false;
}


if(flag)
{
     $.post("handlers/BuyTest.ashx",
                   {
                     que1 : $(".textarea250:eq(0)").val(),
                     que2 : $(".textarea250:eq(1)").val(),
                     que3 : $(".questionnaireContent input:eq(0)").val(),
                     que4 : $(".questionnaireContent input:eq(1)").val(),
                     que5 : $(".questionnaireContent input:eq(2)").val(),
                     que6 : $(".questionnaireContent input:eq(3)").val(),
                     que7 : $(".questionnaireContent input:eq(4)").val(),
                     que8 : $(".jqTransformChecked").parent().prev().text(),
                     que9 : $(".textarea560").val()
                   }
            , function (data) {
                if (data == "sucsses") {
                   $("#popup").bPopup().close();
                   $("#popup2").bPopup({follow:[false,false]});
                   // $("#contactForm").html("<div class=\"sendemailmessage\" ><br/><br/>תודה על פנייתך</div>");
                }
            });
}
  else
  {
    $(".errorMesWrap").show();
  }
}
  
  
  $(function(){
    
      
         $(".radio").jqTransform();
      
       $(".popupLink").bind("click", function(){
            $("#popup").bPopup({follow:[false,false]});
            return false
        });
         
        $(".popupLinkCons").bind("click", function(){
            $("#popupCons").bPopup({follow:[false,false]});
            return false
        });
       
        $(".popupLinkPolicy").bind("click", function(){
            $("#popupLinkPolicy").bPopup({follow:[false,false]});
            return false
        });
            
            
   
  }); 

