﻿//NEWSLETTER FUNCTIONS
//====================

//Newsletter Responder
function sendContactToResponderViaAjax() {

    /*
    //Initalize Variables
    var SentCompleted = true;
    var contactEmail = document.getElementById("ctl00_ucContactBox_txtEmailBox").value;
    document.getElementById("jsOutput").innerHTML = "";
    //validate email
    var filter = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+){1,4}$/;
    if (!filter.test(contactEmail)) {
    document.getElementById("jsOutput").innerHTML = "יש להזין כתובת מייל תקינה<br/>";
    $("#ctl00_ucContactBox_txtEmailBox").addClass("redBorder");
    SentCompleted = false;
    }
    else {
    $("#ctl00_ucContactBox_txtEmailBox").removeClass("redBorder");
    }

    //validate name
    var contactName = document.getElementById("ctl00_ucContactBox_txtNameBox").value;
    if (contactName.length < 2) {
    document.getElementById("jsOutput").innerHTML = document.getElementById("jsOutput").innerHTML + "יש להזין שם";
    $("#ctl00_ucContactBox_txtNameBox").addClass("redBorder");
    SentCompleted = false;
    }
    else {
    $("#ctl00_ucContactBox_txtNameBox").removeClass("redBorder");
    }

    //Send ajax request

    var xmlHttp;
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlHttp = new XMLHttpRequest();
    }
    else {// code for IE6, IE5
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (SentCompleted) {
    url = "http://cp.responder.co.il/subscribe.php?form_id=7968&fields[subscribers_email]=" + contactEmail + "&fields[subscribers_name]=" + contactName + "&fields[מקור רישום]=האתר";
    xmlHttp.open("GET", url, false);
    xmlHttp.send();
    document.getElementById("jsOutput").innerHTML = "";
} 
return SentCompleted;
*/
    return true; 
}

//SHARE BAR FUNCTIONS
//===================

//FACEBOOK
function shareFacebook(url) {
    var urlToGo = "http://www.facebook.com/sharer.php?u=" + url;
    window.open(urlToGo, "FacebookShare", "height=436", "width=635", "left=200", "top=100", "location=no", "menubar=no", "resizable=yes",
        "scrollbars=yes", "status=no", "titlebar=no", "toolbar=no");
}

//BOOKMARK
function shareBookMark(title, url) {
    if (window.sidebar) {
        window.sidebar.addPanel(title, url, "");
    }
    else if (window.opera && window.print) {
        var elem = document.createElement('a');
        elem.setAttribute('href', url); elem.setAttribute('title', title); elem.setAttribute('rel', 'sidebar'); elem.click();
    }
    else if (document.all){
     window.external.AddFavorite(url, title);
     }
}

//REDIRECT TO PRINT FREINDLY PAGE
function sharePrint(url) {
    window.open(url, "",
 "height=800, width=1024, left=200, top=100, location=no, menubar=no, resizable=yes, scrollbars=yes, status=no, titlebar=no, toolbar=YES");
}

//SHARE A FRIEND
function shareWithAFriend(url) {
    window.open(url, "",
"height=400, width=550, left=200, top=100, location=no, menubar=no, resizable=yes, scrollbars=yes, status=no, titlebar=no, toolbar=no");
}




//FORM FUNCTIONS
//==============
function isNameValid(id, charLength) {
    var jqueryId = "#" + id;
    if (document.getElementById(id).value.length > charLength) {
        $(jqueryId).removeClass("redBorder");
        return true;
    }
    else {
        $(jqueryId).addClass("redBorder");
        return false;
    }
}

function isEmailValid(id) {
    var jqueryId = "#" + id;
    var filter = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+){1,4}$/;
    if (filter.test(document.getElementById(id).value)) {
        //$(jqueryId).removeClass("redBorder");
        return true;
    }
    else {
        //$(jqueryId).addClass("redBorder");
        return false;
    }
}

//Contact Form Functions
//======================


//Validates the contact form
function validateContactInsertBlessingForm() {
    var isFormValid = true;
    document.getElementById("vsJsContactForm").innerHTML = "";
    //Validate Conduct
    if (!document.getElementById("ctl00_ContentPlaceHolder1_uiContactForm_chkConduct").checked) {
        document.getElementById("vsJsContactForm").innerHTML += "עלייך להסכים לתקנון";
        isFormValid = false;
    }
    //Validate Name
    if (!isNameValid("ctl00_ContentPlaceHolder1_uiContactForm_txtFullName", 2)) {
        document.getElementById("vsJsContactForm").innerHTML += "<br/>יש למלא שם";
        $("#ctl00_ContentPlaceHolder1_uiContactForm_txtFullName").addClass("redBorder");
        isFormValid = false;
    }
    else {
        $("#ctl00_ContentPlaceHolder1_uiContactForm_txtFullName").removeClass("redBorder");
    }

    if (isFormValid) {
        if (document.getElementById("ctl00_ContentPlaceHolder1_uiContactForm_chkIsDivur").checked)
            addContactToNewsletterList();
        document.getElementById("vsJsContactForm").innerHTML = "";
    }
    return isFormValid;
}

//Validates the contact form with insert blessing element
function validateContactForm() {
    var isFormValid = true;
    document.getElementById("vsJsContactForm").innerHTML = "";

    //Validate Name
    if (!isNameValid("ctl00_ContentPlaceHolder1_uiContactForm_txtFullName", 2)) {
        document.getElementById("vsJsContactForm").innerHTML += "<br/>יש למלא שם";
        $("#ctl00_ContentPlaceHolder1_uiContactForm_txtFullName").addClass("redBorder");
        isFormValid = false;
    }
    else {
        $("#ctl00_ContentPlaceHolder1_uiContactForm_txtFullName").removeClass("redBorder");
    }

    if (isFormValid) {
        //if (document.getElementById("ctl00_ContentPlaceHolder1_uiContactForm_chkIsDivur").checked)
            //addContactToNewsletterList();
        document.getElementById("vsJsContactForm").innerHTML = "";
    }
    
    return isFormValid;
}

//adds the contact to the newsletter list
function addContactToNewsletterList() {
    //Validate Email
        
    if (isEmailValid("ctl00_ContentPlaceHolder1_uiContactForm_txtEmail")) {
        //Send the Newsletter request to the cpresponder
        var xmlHttp;
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlHttp = new XMLHttpRequest();
        }
        else {// code for IE6, IE5
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        url = "http://cp.responder.co.il/subscribe.php?form_id=7968&fields[subscribers_email]="
         + document.getElementById("ctl00_ContentPlaceHolder1_uiContactForm_txtEmail").value +
          "&fields[subscribers_name]=" +
          document.getElementById("ctl00_ContentPlaceHolder1_uiContactForm_txtFullName").value +
           "&fields[מקור רישום]=האתר";
        xmlHttp.open("GET", url, false);
        xmlHttp.send();

        return false;
    }
    return false;
}

//Blessing Form Functions
//=======================
//Validates the blessing form
function validateBlessingForm() {
    document.getElementById("vsJsBlessingForm").innerHTML = "";
    var isFormValid = true;
    //Validate Email To
    if (!isEmailValid("ctl00_ContentPlaceHolder1_uiBlessingForm_txtToEmail")) {
        isFormValid = false;
        document.getElementById("vsJsBlessingForm").innerHTML += "<br/>יש להזין כתובת מייל תקינה באל";
        document.getElementById("ctl00_ContentPlaceHolder1_uiBlessingForm_txtEmailHeadline").focus();
    }

    //Validate Name To
    if (!isNameValid("ctl00_ContentPlaceHolder1_uiBlessingForm_txtFromName", 2)) {
        isFormValid = false;
        document.getElementById("vsJsBlessingForm").innerHTML += "<br/>יש להזין שם באל";
        document.getElementById("ctl00_ContentPlaceHolder1_uiBlessingForm_txtEmailHeadline").focus();
    }

    //Validate Name From
    if (!isNameValid("ctl00_ContentPlaceHolder1_uiBlessingForm_txtToName", 2)) {
        isFormValid = false;
        document.getElementById("vsJsBlessingForm").innerHTML += "<br/>יש להזין שם במאת";
        document.getElementById("ctl00_ContentPlaceHolder1_uiBlessingForm_txtEmailHeadline").focus();
    }


    //Validate Blessing Headline
    if (!isNameValid("ctl00_ContentPlaceHolder1_uiBlessingForm_txtEmailHeadline", 3)) {
        isFormValid = false;
        document.getElementById("vsJsBlessingForm").innerHTML += "<br/>יש להזין כותרת";
        document.getElementById("ctl00_ContentPlaceHolder1_uiBlessingForm_txtEmailHeadline").focus();
    }

    //Check if we need to validate Blessing Stars
    if (document.getElementById("ctl00_ContentPlaceHolder1_uiBlessingForm_txtStars") != null) {
        //Validate Blessing Stars
        if (!isNameValid("ctl00_ContentPlaceHolder1_uiBlessingForm_txtStars", 2)) {
            isFormValid = false;
            document.getElementById("vsJsBlessingForm").innerHTML += "<br/>יש להזין שם במקום";
            document.getElementById("ctl00_ContentPlaceHolder1_uiBlessingForm_txtEmailHeadline").focus();
        }
    }

    if (isFormValid)
        document.getElementById("vsJsBlessingForm").innerHTML = "";

    return isFormValid;
}

//updates the background of the blessing to the targeted background
function changeBackground(backgroundUrl) {
    document.getElementById("blessingContentBg").style.backgroundImage = "url("+backgroundUrl+")";
}

function handleRblSelection() {
    changeBackground($('.from input[type=radio]:checked').val());
}


    //SEO FUNCTIONS
    //=============

    //REDIRECT THE USER VIA JAVASCRIPT TO KEEP THE STRENGTH OF ANOTHER LINK
    function JSLink(url, target) {
        if (target == 0) {
            document.location.href = url;
        }
        else {
            window.open(url);
        }
    }


    //POP FUNCTIONS
    //=============
    //SHOWS AN ELEMENT
    function ShowPop(id) {
        var popId = "pop" + id;
        document.getElementById(popId).style.display = "block";
    }

    //HIDES EN ELEMENT
    function HidePop(id) {
        var popId = "pop" + id;
        document.getElementById(popId).style.display = "none";
    }

    //UI Functions
    function colorIcon(id, src) {
        document.getElementById(id).src = src;
    }




    
