﻿
$(document).ready(function() {

   $("#search_words").bind("keydown", function(event) {
      // track enter key
      var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
      if (keycode == 13) { // keycode for enter key
         // force the 'Enter Key' to implicitly click the Update button
         document.getElementById('btnSearchButton').click();
         return false;
      } else  {
         return true;
      }
   }); // end of function

}); // end of document ready



function ClearFields()
{
  $("*[id$='txtJunctionStart']").val('');
  $("*[id$='txtJunctionEnd']").val('');
  $("*[id$='ddlNumberDay']").val('1');
  $("*[id$='ddlNumberMonth']").val('1');
  $("*[id$='ddlVehicles']").val('0');
  
  
}


function CalcIt()
{
 
  var sc =  $("*[id$='txtJunctionStart']").val();
  if(sc=="")
  {
    alert("בחר נקודת מוצא");
    return false;
  }
  var v =  $("*[id$='ddlVehicles']").val();
  if(v=="0")
  {
    alert("בחר סוג רכב");
    return false;
  }
  var nd =  $("*[id$='ddlNumberDay']").val();
  var ec =  $("*[id$='txtJunctionEnd']").val();
  if(ec=="")
  {
    alert("בחר נקודת יעד");
    return false;
  }
  var md =  $("*[id$='ddlNumberMonth']").val();
  
  
  document.location.href="Calc.aspx?sc="+escape(sc)+"&v="+v+"&nd="+nd+"&ec="+escape(ec)+"&md="+md;
    
}


function CalcIt2()
{
 
  var sc =  $("*[id$='txtJunctionStart']").val();
  if(sc=="")
  {
    alert("בחר נקודת מוצא");
    return false;
  }
  var v =  $("*[id$='ddlVehicles']").val();
  if(v=="0")
  {
    alert("בחר סוג רכב");
    return false;
  }
  var nd =  $("*[id$='ddlNumberDay']").val();
  var ec =  $("*[id$='txtJunctionEnd']").val();
  if(ec=="")
  {
    alert("בחר נקודת יעד");
    return false;
  }
  var md =  $("*[id$='ddlNumberMonth']").val();
  
  
  document.location.href="CalcPage.aspx?sc="+escape(sc)+"&v="+v+"&nd="+nd+"&ec="+escape(ec)+"&md="+md;
    
}

function ShowIt()
{
    var sc =  $("*[id$='txtJunctionStart']").val();
    var ec =  $("*[id$='txtJunctionEnd']").val();
    open("MapRoute.aspx?sc=" + (sc) + "&ec=" + (ec));
}
function CalcShow()
{
    
    $("#CalcWarp").show();
}

function chkCV()

{

    var x;
    x =  $("*[id$='txtFullName']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא למלא שם מלא");
        return false;
    }

  
    x =  $("*[id$='txtCellPhone']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא למלא מספר טלפון נייד");
        return false;
    }
    
    x =  $("*[id$='txtEmail']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא למלא כתובת דואר אלקטרוני");
        return false;
    }
    else
    {
         if(!ValidateEmail(x))
        {
            alert("נא למלא אימייל תקין");
            return false;
        }
    }
    
      x =  $("*[id$='txtCaptch']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא למלא קוד אימות");
        return false;
    }
    else
    {
        if(x.length!=6)
        {
            alert("קוד אימות לא תקין");
            return false;
        }
    }
    
    return true;
}

function chkContactUs()
{

    var x;
    
    
    x =  $("*[id$='txtFullName']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא למלא שם מלא");
        return false;
    }

    x =  $("*[id$='txtIdNumber']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא למלא תעודת זהות");
        return false;
    }
    
    
    x =  $("*[id$='txtCarNumber']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא למלא מספר רכב");
        return false;
    }
    else
    {
        if(isNaN(x))
        {
            alert("מספר רכב בספרות בלבד");
            return false;
        }
    }
    
    x =  $("*[id$='txtCellPhone']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא למלא מספר טלפון נייד");
        return false;
    }
    
    x =  $("*[id$='txtEmail']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא למלא כתובת דואר אלקטרוני");
        return false;
    }
    else
    {
         if(!ValidateEmail(x))
        {
            alert("נא למלא אימייל תקין");
            return false;
        }
    }
    
    x =  $("*[id$='txtCaptch']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא למלא קוד אימות");
        return false;
    }
    else
    {
        if(x.length!=6)
        {
            alert("קוד אימות לא תקין");
            return false;
        }
    }
    return true;

}


function ValidateEmail(s)
{
    var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
    if (!filter.test(s)) 
        return false;
    else
        return true;
}



function search()
{
    document.location.href="SearchResults.aspx?search_words="+escape(document.getElementById("search_words").value);
    
    return false;
    
}

function ShowT()
{
    if($("#divCalcTableBox").css("display")=="none")
        $("#divCalcTableBox").show();
    else
        $("#divCalcTableBox").hide();
    
}


function ShowSubs(i)
{
    if($("#"+i+"_divClassRightNavLinkSub").css("display")=="none")
        $("#"+i+"_divClassRightNavLinkSub").show();
    else
        $("#"+i+"_divClassRightNavLinkSub").hide();
}

function OpenMapRoute() {
    open("MapRoute.aspx");
}



function getParameterByName( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}




function chkGreenForm()
{

    var x;
    
    
    x =  $("*[id$='txtName']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא למלא שם הגוף הפונה");
        return false;
    }

    x =  $("*[id$='txtNumber']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא למלא מס' עמותה");
        return false;
    }
    
    
    x =  $("*[id$='txtProjectName']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא למלא שם הפרויקט");
        return false;
    }

    x =  $("*[id$='txtReqMoney']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא למלא סכום מבוקש");
        return false;
    }

    x =  $("*[id$='txtContactPerson']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא למלא שם איש קשר");
        return false;
    }
    
    x =  $("*[id$='txtPhone']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא למלא מספר טלפון");
        return false;
    }
    
    
    x =  $("*[id$='txtCellPhone']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא למלא מספר טלפון נייד");
        return false;
    }

    x = $("*[id$='txtFax']").val();
    x = jQuery.trim(x);
    if (x == "") {
        alert("נא למלא מספר פקס");
        return false;
    }
    
    x =  $("*[id$='txtEmail']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא למלא כתובת דואר אלקטרוני");
        return false;
    }
    else
    {
         if(!ValidateEmail(x))
        {
            alert("נא למלא אימייל תקין");
            return false;
        }
    }
    
    x =  $("*[id$='txtWebSite']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא למלא כתובת אתר אינטרנט");
        return false;
    }
    
    x =  $("*[id$='txtEstablishDate']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא למלא מועד הקמת הגוף");
        return false;
    }

    x =  $("*[id$='txtAmountOfPaidWorkers']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא למלא מספר עובדים בשכר");
        return false;
    }
    
    x =  $("*[id$='txtAmountOfVolunteers']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא למלא מספר מתנדבים");
        return false;
    }
    
    x =  $("*[id$='txtExperience']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא פרטו ניסיון קודם בפעילות סביבתית");
        return false;
    }
    
    
    x =  $("*[id$='txtHeardAboutUs']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא מלאו כיצד שמעתם עלינו");
        return false;
    }


    x = $("*[id$='FileUpload1']").val();
    x = jQuery.trim(x);
    if (x == "") {
        alert("נא צרפו את הקובץ");
        return false;
    }
    
    
    x =  $("*[id$='txtCaptch']").val();
    x=jQuery.trim(x);
    if(x=="")
    {
        alert("נא למלא קוד אימות");
        return false;
    }
    else
    {
        if(x.length!=6)
        {
            alert("קוד אימות לא תקין");
            return false;
        }
    }
    return true;

}

