﻿var siteUrl = "http://" + document.domain;
var p = document.location.port;
if (p != "")
    siteUrl += ":" + p + "/";
else
    siteUrl += "/";



function AddToFavorites() {
    if (window.sidebar) { // Mozilla Firefox Bookmark
        window.sidebar.addPanel('האגיס', 'http://www.huggies.co.il', "");
    }
    else
        if (window.external) // IE Favorite
            window.external.AddFavorite('http://www.huggies.co.il', 'האגיס');
}



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 LoginBoxHandler() {
    
    var u = $("#LoginBoxUserName").val();
    var p = $("#LoginBoxPWD").val();
    var s = $("#LoginBoxSaveMe").is(':checked'); 

    if (!ValidateEmail(u)) {
        alert("אימייל לא בפורמט תקין");
        return false;
    }

    if (p == "") {
        alert("יש למלא סיסמה");
        return false;
    }



    
    $.post(siteUrl + "Handlers/LoginBox.ashx",
    {
        email: u,
        pwd: p,
        saveme: s
    },

      function (data) {
          
          USERID = $(data).find("USERID").text();

          if (USERID != "0") {
              $("#divCustomerEmail").text($(data).find("EMAIL").text());
              $("#spanUserFullName").text($(data).find("FULLNAME").text());

              $("#divUnLoggedUser").hide();
              $("#divLoggedUser").css("display", "block");
          }
          else {
              alert("שם משתמש וסיסמה לא קיימים במערכת");
          }
      }
    );
  }


  function BirthDateSearch() {

      SubjectId = $("#ddlSubjects").val();
      LocationId = $("#ddlLocations").val();
      AgeId = $("#ddlAges").val();


      url = siteUrl + "Birthdays/BirthdaysSearch.aspx?SubjectId=" + SubjectId + "&LocationId=" + LocationId + "&AgeId=" + AgeId;
      location.href = url;
  }

function CreationSearch() {

    AgeGroupId = $("#ddlAgeGroup").val();
    LocationId = $("#ddlLocations").val();
    ParticipantId = $("#ddlParticipants").val();
    CategoryId = $("#ddlCategories").val();

    url = siteUrl + "Activities/SearchActivity.aspx?AgeGroupId=" + AgeGroupId + "&LocationId=" + LocationId + "&ParticipantId=" + ParticipantId + "&CategoryId=" + CategoryId;
    location.href = url;
}


function CookingSearch() {

    AgeGroupId = $("#ddlAgeGroup").val();
    CategoryId = $("#ddlCategories").val();

    url = siteUrl + "Activities/CookingSearch.aspx?AgeGroupId=" + AgeGroupId + "&CategoryId=" + CategoryId;
    location.href = url;
}

function GameSearch() {

    AgeGroupId = $("#ddlAgeGroup").val();
    LocationId = $("#ddlLocations").val();
    ParticipantId = $("#ddlParticipants").val();
    SkillId = $("#ddlSkills").val();

    url = siteUrl + "Activities/GamesSearch.aspx?AgeGroupId=" + AgeGroupId + "&LocationId=" + LocationId + "&ParticipantId=" + ParticipantId + "&SkillId=" + SkillId;
    location.href = url;
}

function GreetingsSet(id) {
    location.href = "GreetingStepTwo.aspx?greetingId=" + id;
}


function InvitationsSet(id) {
    location.href = "BirthdayStepTwo.aspx?InvitationId=" + id;
}



function InjectFlash(file,div, width, height) {
    FlashReplace.replace(div, file, "flash-element-FlashBox", width, height, 9,
        {
            wmode: "transparent",
            quality: "high",
            bgcolor: "#ffffff"
        });
    }


    function TipSearch() {
        document.location.href = siteUrl + "Tools/AllTips.aspx?TipCategoryId=" + $("#ddlTipType").val();
}
function AddTip() {

    
    var name = $("#txtSenderPop").val();
    var tip = $("#txtTipPop").val();
    var tiptype = $("#ddlTipTypePop").val();


    if (name == "") {
        alert("נא למלא שם השולח");
        return false;
    }

    if (tip == "") {
        alert("נא למלא טיפ");
        return false;
    }
    
    $.post(siteUrl + "Handlers/TipAdd.ashx",
    {
        name: name,
        tip: tip,
        tiptype: tiptype
    },
      function (data) {

          if (data != "-1") {
              $("#PopUpDivTip").hide();
              $("#PopUpDivOk").show();
          }
          else {
              alert("אופס...יש לנו איזו תקלה");
          }
      }
    );
    return true;

}



function showTipPop() {

    $('#PopUpDivTip').css('display', 'block');

}

function InjectFlashMovie(divId, url, width, height, name) {
    var flashFileUrl = url;
    var width = width;
    var height = height;
    var movieName = name;
    //var containerDiv = $("#"+divId);
    var Object = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='" + width + "' height='" + height + "' id='" + movieName + "'>";
    Object += "<param name='allowScriptAccess' value='sameDomain' />";
    Object += "<param name='allowFullScreen' value='false' />";
    Object += "<param name='wmode' value='transparent' />";
    Object += "<param name='movie' value='" + flashFileUrl + "' />";
    Object += "<param name='quality' value='high' />";
    Object += "<param name='bgcolor' value='#ffffff' />";
    Object += "<embed src='" + flashFileUrl + "' quality='high' wmode='transparent' width='" + width + "' height='" + height + "' id='" + movieName + "'  allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
    Object += "</object>";
    
    document.write(Object);
}


function WeekBabyAddImg() {
    alert($("#txtUploadBabyName").val());
    /*if ($("#txtUploadBabyName").val() == "") {
        alert("נא מלאו שם התינוק");
        return false;
    }

    if ($("#iagree").is(':checked') == false) {
        alert("יש להסכים לתנאים");
        return false;
    }
    */
    return true;
}


function WeekBabyChangeBabyImg(i, t) {

    $("#spanWeekBabyTitle").text(t);
    $("#imgMain").attr("src", siteUrl + "Handlers/ImageFetcher.ashx?id=" + i);

}

function WeekBabyChangeBaby(i, m,y) {

    location.href = "WeeklyBaby.aspx?i=" + i + "&m=" + m + "&y=" + y;

}



function chkRegistrationForm() {
    if ($("#chkAgree").is(':checked') == false) {
        alert("יש להסכים לתנאים");
        return false;
    }

    if ($("#chkMailingList2").is(':checked') == false) {
        alert("יש לאשר קבלת מידע שיווקי על הטבות ומבצעים");
        return false;
    }



    return true;
}


function IsLoggedIn() {

    $.post(siteUrl + "Handlers/IsUserLogin.ashx",
    {
    },
      function (data) {

          if (data != "0") {
              return true;
          }
          else {
              return false;
          }
      }
    );

}

function ShowUploadImageDiv() {

    
    $.post(siteUrl + "Handlers/IsUserLogin.ashx",
    {
    },
      function (data) {

          if (data != "0") {
              $("#PopUpDiv").center();
              $('#PopUpDiv').show();
          }
          else {
              location.href = siteUrl + "Registration.aspx?SignBefore";
          }
      }
    );
}

function AlbumsChangeImg(i, t) {
    $(".ImageName").text(t);
    $("#img").attr("src", siteUrl + "Handlers/ImageFetcher.ashx?id=" + i);
    $("#aI").val(i);
}
function confirmDeleteAlbumImages() {
    b = false;
    $('input[name$="chkImg"]').each(function () {
        if ($(this).is(':checked')) {
            b = true;
        }
    });
    if (!b) {
        alert("נא לבחור תמונה");
    }
    return b;
}

function showDeleteAlbumDiv(a) { 

var h = '\
    <div id="delAlbumDiv" class="PopUpDiv"> \
    <div class="TitleDelete" onclick="javascript:closeDeleveAlbumDiv();"></div> \
    <div class="Body"> \
        <div class="Text">האם אתה רוצה למחוק את האלבום?</div> \
        <div class="LinksWrap"> \
            <a href="javascript:doDeleveAlbum(' + a + ');" class="ButtonDelete technique"><span>מחק</span></a> \
            <a href="javascript:closeDeleveAlbumDiv();" class="ButtonNoDelete technique"><span>לא למחוק</span></a> \
        </div> \
    </div> \
    <div class="Bottom"></div> \
</div>'

$("#end").after(h);

}
function doDeleveAlbum(a) {
    if (confirm("נא לאשר מחיקה")) {
        location.href = siteUrl + "Albums/DeleteAlbum.aspx?AlbumId=" + a;
    }
}

function closeDeleveAlbumDiv() {
    $("#delAlbumDiv").hide();
}
function AlbumImageMove(t) {

    var row, col;
    var ni = parseInt($('input[name$="rdImg"]').length);


    b = false;
    var v = 0;
    $('input[name$="rdImg"]').each(function () {
        if ($(this).is(':checked')) {
            b = true;
            v = $(this).val();
            rel = parseInt($(this).parent().attr("rel"));

            var six = 0;
            var eix = 0;

            switch (t) {
                case "r":
                    if (rel % 4 > 0) {
                        six = rel;
                        eix = six - 1;
                    }
                    break;
                case "l":
                    if ((rel + 1) % 4 > 0) {
                        six = rel;
                        eix = six + 1;
                    }
                    break;
                case "d":
                    if (rel + 4 <= (ni - 1)) {
                        six = rel;
                        eix = six + 4;
                    }
                    break;
                case "u":
                    if (rel - 4 >= 0) {
                        six = rel;
                        eix = six - 4;
                    }
                    break;
            }


            if (six + eix != 0) {
                ids = $("li[rel*=" + six + "]").find("input").attr("value");
                ide = $("li[rel*=" + eix + "]").find("input").attr("value");

                $.post(siteUrl + "Handlers/AlbumSwitchImages.ashx",
                    {
                        abuid: $("#abuid").val(),
                        ids: ids,
                        ide: ide
                    },
                      function (data) {

                          if (data != "-1") {

                              owiengb = $("li[rel*=" + six + "]").html();
                              $("li[rel*=" + six + "]").html($("li[rel*=" + eix + "]").html());
                              $("li[rel*=" + eix + "]").html(owiengb);
                          }
                          else {
                              alert("אופס...יש לנו איזו תקלה");
                          }
                      }
                    );

               

            }

        }
    });
    if (!b) {
        alert("נא לבחור תמונה");
    }

}



/* MAKE INPUT FIELD WITH BORDER WHEN FOCUS */

jQuery(document).ready(function ($) {
    $("input").focus(function () {
        $(this).css('border-width', '2px');
    });
    $("input").blur(function () {
        $(this).css('border-width', '1px');
    });
})


function SearchSite() {

    if ($("#SearchWord").val() == "" || $("#SearchWord").val()=="חפש") {
        if ($("#SearchWord").val() == "חפש") $("#SearchWord").val("");
        alert("נא הקלידו מילת חיפוש");
        return;
    }
    else {
        location.href = siteUrl + "Search/SearchResults.aspx?SearchWord=" + $("#SearchWord").val();
    }

}

function downLoadScreenServer(i) {
    window.location = siteUrl + "Tools/ScreenSavers/Src" + i + ".zip";
}

function closepopLoginBox() {
    $(".PopUpDivRegister").css("display", "none");
}

var shipme = "";
function popLoginBox(cont) {
    shipme = cont;
    var x = '\
<div class="PopUpDivRegister"> \
    <div class="TitleRegister" onclick="javascript:closepopLoginBox();"></div> \
    <div class="Body"> \
        <div class="BodyRegister"> \
            <div class="RegisterWrap"> \
                <div class="TitleRegisterUser">משתמש רשום</div> \
                <div class="Row RowMargin3"> \
                    <span class="Text">שם משתמש</span> \
                    <div class="PopUpSelectWrap"> \
                        <span class="Right"></span> \
                        <span class="Center"><input type="text" id="popLoginBoxUserName"></span> \
                        <span class="Left"></span> \ \
                    </div> \
                </div> \
                <div class="Row RowMargin"> \
                    <span class="Text">סיסמא</span> \
                    <div class="PopUpSelectWrap"> \
                        <span class="Right"></span> \
                        <span class="Center"><input type="password" id="popLoginBoxPWD"></span> \
                        <span class="Left"></span> \
                    </div> \
                </div> \
                <div class="Row RowMargin4"> \
                    <a title="שכחתי סיסמא" class="OrangeArrowLink OrangeArrowLinkFloat" href="' + siteUrl + "" + '">שכחתי סיסמא</a> \
                </div> \
                <div class="Row"><input type="button" class="ButtonGreenTypeB ButtonFloat" value="כניסה" onclick="javascript:popLoginBoxHandler();"></div> \
            </div> \
            <div class="NoneRegisterWrap"> \
                <div class="TitleRegisterUser">משתמש לא רשום</div> \
                    <div class="Row RowMargin4"> \
                    <a title="לחץ כאן להרשמה" class="OrangeArrowLink" href="' + siteUrl + "Registration.aspx" + '">לחץ כאן להרשמה</a> \
                </div> \
            </div> \
        </div> \
    </div> \
    <div class="Bottom"></div> \
</div> '

 
    if ($.cookie('HUGGIES') != null) {
        return true;
    }
    else {
        $("#end").after(x);
        $(".PopUpDivRegister").center();
        return false;
    }
    
}

function closepopForgotPwdBox() {
    $("#popForgotPwd").remove();
}

function popForgotPwd() { 
    var f = '\
    <div id="popForgotPwd" class="PopUpDiv"> \
        <div class="TitleForgetPassword" onclick="javascript:closepopForgotPwdBox();"></div> \
        <div id="popForgotPwdBody" class="Body"> \
            <div class="PopSubTitle">שכחת סיסמא?</div> \
            <div class="Text">הזן את המייל איתו נרשמת</div> \
            <div class="Text PopUpSelectWrapForgetPassword"> \
                <div class="PopUpSelectWrap"> \
                    <span class="Right"></span> \
                    <span class="Center"><input type="text" style="width:230px;" id="fpemail" name="fpemail"></span> \
                    <span class="Left"></span> \
                </div> \
            </div> \
            <div class="PopSubTitle" ><input type="button" class="ButtonGreenTypeB ButtonFloat" style="display:inline;" value="שלח" onclick="javascript:popForgotPwdHandler();"></div> \
        </div> \
        <div class="Bottom"></div> \
    </div>';

    $("#end").after(f);
    $("#popForgotPwd").center();
    return false;

}

function popForgotPwdHandler() {
    var fpemail = $("#fpemail").val();
    if (fpemail == "") {
        alert("נא מלאו אימייל");
        return false;
    }

    if (!ValidateEmail(fpemail)) {
        alert("אימייל לא תקין");
        return false;
    }



    $.ajax({
        url: siteUrl + "Handlers/ForgotPwd.ashx",
        data: "email=" + fpemail,
        async: false,
        type: "POST",
        dataType: "XML",
        success: function (data) {
            if (data != "-1") {
                if (data == "1") {
                    $("#popForgotPwdBody").html("<div class=\"Text TextForget\">פרטי ההרשמה יגיעו אליך במייל, תוך מספר דקות<br /><b>תודה</b></div>");
                }
                else { 
                    alert("כתובת המייל לא קיימת במאגר");
                }

            }
            else {
                alert("אופס...יש לנו איזו תקלה");
            }
        }
    });


}

function popLoginBoxHandler() {

    var u = $("#popLoginBoxUserName").val();
    var p = $("#popLoginBoxPWD").val();
    

    if (!ValidateEmail(u)) {
        alert("אימייל לא בפורמט תקין");
        return false;
    }

    if (p == "") {
        alert("יש למלא סיסמה");
        return false;
    }


    $.ajax({
        url: siteUrl + "Handlers/LoginBox.ashx",
        data: "email=" + u + "&pwd=" + p,
        async: false,
        type: "POST",
        dataType: "XML",
        success: function (data) {
            if (data != "-1") {
                USERID = $(data).find("USERID").text();

                if (data.indexOf("<USERID>0</USERID>") == -1) {

                    if (shipme == "") {
                        closepopLoginBox();
                        return;
                    }
                    if (shipme.indexOf("javascript") != -1) {
                        closepopLoginBox();
                        eval(shipme.replace("javascript:", ""));
                    }
                    else
                        location.href = shipme;
                }
                else {
                    alert("שם משתמש וסיסמה לא קיימים במערכת");
                }
            }
            else {
                alert("אופס...יש לנו איזו תקלה");
            }
        }
    });
}



function GreetinSendClick() {

    if ($("#chkPrint").is(':checked'))
        open("GreetingPrint.aspx?GreetingId=" + $("#hdGreetingId").val() + "&GreetingText=" + $("#divTxt").text());

    if ($("#chkEmail").is(':checked'))
        return true;
    else
    return false;

}


function InvitationSendClick() {

    if ($("#chkPrint").is(':checked'))
        open("BirthdayPrint.aspx?InvitationId=" + $("#hdInvicationId").val() + "&D=" + $("#divtxtDay").text() + "&H=" + $("#divtxtHour").text() + "&A=" + $("#divtxtAddress").text() + "&N=" + $("#divtxtName").text());

    if ($("#chkEmail").is(':checked'))
        return true;
    else
        return false;

}




function showSendAlbum() {
    $(".SendToFriend").css("display", "block");
}
function SendAlbumToFriend(x) {
    var sn = $("#SendToFriendSenderName").val();
    var sfn = $("#SendToFriendName").val();
    var se  = $("#SendToFriendEmail").val();

    if (sn == "") {
        alert("נא מלאו את שמכם");
        return false;
    }

    if (sfn == "") {
        alert("נא מלאו את שם הנמען");
        return false;
    }

    if (se == "") {
        alert("נא מלאו את כתובת המייל של הנמען");
        return false;
    }



    $.post(siteUrl + "Handlers/SendAlbum.ashx",
    {
        sn: sn,
        sfn: sfn,
        se: se
    },
      function (data) {

          if (data != "-1") {
              $(".SendToFriend").css("display", "none");
              $("#SendToFriendError").css("display", "block");
          }
          else {
              $(".SendToFriend").css("display", "none");
              alert("אופס...יש לנו איזו תקלה");
          }
      }
    );
  }


  function showChangeName() {
      $("#txtImageName").val($(".ImageName").text());
      $("#PopUpDivAlbum").css("display", "block");
  }


  function WeekBabyChangeMonth() {
      var osidh = $("#ddlDates").val();
      var osidha = osidh.split("/");
      WeekBabyChangeBaby(0, osidha[0], osidha[1]);
  }



  function chkTakanon() {
      if (!$("#iagree").is(':checked')) {
          alert("נא לאשר את התקנון");
          return false;
      }
      else
          return true;
  
  }
