﻿
function createCookie(name, value, minutes) {
    if (minutes) {
        var date = new Date();
        date.setTime(date.getTime() + (minutes * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }

    else {
        var expires = "";
    }
    document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0)
            if (c.indexOf(nameEQ) == 0)
            return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function initializeInteractive(index) {
    var menu = $('.home-interactive-wide .nav li a');
    var a = $('.home-interactive-wide .cover');
    var img = $('.home-interactive-wide .image')
    if (menu.length = 0) {
        return false;
    }
    if (index > 0) {
        a[index - 1].style.display = 'none';
        img[index - 1].style.display = 'none';
    }
    else {
        a[3].style.display = 'none';
        img[3].style.display = 'none';
    }
    a[index].style.display = 'block';
    img[index].style.display = 'block';
}

function reLoadListener() {
    var tooltip = $('.tooltip-135-link');
    var toolnum = $('.tooltip-135');
    for (var i = 0; i < tooltip.length; i++) {
        addEventListener(tooltip[i], 'click', (function(i) {
            return function() {
                var el = document.getElementById('content-135-' + i);
                el.style.display = (el.style.display == 'block') ? '' : 'block';
            };
        }
               )(i + 1));
        addEventListener(toolnum[i].getElementsByTagName('a')[0], 'click', (function(i) {
            return function() {
                document.getElementById('content-135-' + i).style.display = 'none';
            };
        })(i + 1));
    }

        tooltip = $('.tooltip-225-link');
        toolnum = $('.tooltip-225');
        for (var i = 0; i < tooltip.length; i++) {
            addEventListener(tooltip[i], 'click', (function(i) {
                return function() {
                    var el = document.getElementById('content-225-' + i);
                    el.style.display = (el.style.display == 'block') ? '' : 'block';
                };
            }
            )(i + 1));
            addEventListener(toolnum[i].getElementsByTagName('a')[0], 'click', (function(i) {
                return function() {
                    document.getElementById('content-225-' + i).style.display = 'none';
                };
            })(i + 1));
        }

    //load listener for extra city div
        var tooltip = $('.tooltip-more-options-link'),
    		toolnum = $('.tooltip-more-options');
        if (tooltip.length > 0) {
            addEventListener(tooltip[0], 'click', (function(i) {
                return function() {
                    var el = document.getElementById('options-content-' + 1);
                    el.style.display = (el.style.display == 'block') ? '' : 'block';
                };
            })(i + 1));
            addEventListener(toolnum[0].getElementsByTagName('a')[0], 'click', (function(i) {
                return function() {
                    document.getElementById('options-content-' + 1).style.display = 'none';
                };
            })(i + 1));
        }
}

function reLoadListBoxClass() {
    $('.send-msg-selectbox').selectbox(
      {
          inputClass: 'selectbox2',
          containerClass: 'selectbox-wrapper2',
          hoverClass: 'current',
          currentClass: 'selected',
          debug: false
      }
    );
    $('.area-code-selectbox').selectbox(
	{
	    inputClass: 'selectbox1',
	    containerClass: 'selectbox-wrapper1',
	    hoverClass: 'current',
	    currentClass: 'selected',
	    debug: false
	}
	);
}
//function reLoadSendToFriend() {
//    tooltip = $('.tooltipSTF-225-link');
//    toolnum = $('.tooltip-225 tooltip-225-ie7');
//    for (var i = 0; i < tooltip.length; i++) {
//        addEventListener(tooltip[i], 'click', (function(i) {
//            return function() {
//                var el = document.getElementById('content-225-' + i);
//                el.style.display = (el.style.display == 'block') ? '' : 'block';
//            };
//        }
//            )(i + 1));
//        addEventListener(toolnum[i].getElementsByTagName('a')[0], 'click', (function(i) {
//            return function() {
//                document.getElementById('content-225-' + i).style.display = 'none';
//            };
//        })(i + 1));
//    }
//}

function GetExtraCities() {
    var CB = $(".cityCB");
    var input = $(".cityCBI");
    var areaInput = $(".areaCBI");
    var name = $(".cityCBName");
    var idString = "";
    document.getElementById('ExtraCitiesAreaInp').value = '';
    for (var i = CB.length - 1; i >= 0; i--) {
        if (CB[i].checked) {
            document.getElementById('CityNameInp').value = name[i].innerHTML;
            idString += input[i].value + ";";
            if (document.getElementById('ExtraCitiesAreaInp').value == '')
                document.getElementById('ExtraCitiesAreaInp').value = areaInput[i].value;
            else
                if (document.getElementById('ExtraCitiesAreaInp').value != areaInput[i].value) {
                    alert('לא ניתן לבחור ערים מאיזורים שונים');
                    return false;
                }
        }
        }
//        if (idString.substring(idString.length - 1) == ';')
//            document.getElementById('ExtraCitiesInp').value = idString.substr(0, idString.length - 1);
//        else
            document.getElementById('ExtraCitiesInp').value = idString;
    if (idString.length > 0) {
        return true;
    }
    else {
        return false;
    }
}


function CheckAreaForExtraCities(ctl) {
    var checkedCounter = 0;
    var CB = $(".cityCB");
    var nameOfCitySpan = $(".cityCBName");
    for (var k = 0; k < CB.length; k++)
        if (CB[k].checked) {
            checkedCounter++;
            if (checkedCounter > 1)
                return;
                
        }
       
    if ((checkedCounter == 1) & (ctl.checked)) {
        var areaInput = $(".areaCBI");
        
        var areaSelected;
        for (var i = 0; i < CB.length; i++)
            if (CB[i].checked) {
                areaSelected = areaInput[i].value;
                break;
            } 
        for (var j = 0; j < CB.length; j++) {
            if (areaInput[j].value == areaSelected) {

                CB[j].disabled = false;
                CB[j].style.cursor = "pointer";
                nameOfCitySpan[j].style.color = "#4586D9";
                nameOfCitySpan[j].style.cursor = "pointer";
            }
            else {
                CB[j].disabled = true;
                CB[j].style.cursor = "default";
                nameOfCitySpan[j].style.color = "#93A49B";
                nameOfCitySpan[j].style.cursor = "default";
            }
        } 
    }
    
    if ((checkedCounter == 0) & (!ctl.checked)) {
        for (var k = 0; k < CB.length; k++) {
            CB[k].disabled = false;
            CB[k].style.cursor = "pointer";
            nameOfCitySpan[k].style.color = "#4586D9";
            nameOfCitySpan[k].style.cursor = "pointer";
        }
    }
}

function LockExtraCities() {
    if (document.getElementById('IsCityLockedinp').value == "true") {
        if (document.getElementById('Culomn1Rpt_ctl00_Column1LB') != null) {
            document.getElementById('Culomn1Rpt_ctl00_Column1LB').setAttribute("disabled", true);
            document.getElementById('Culomn1Rpt_ctl00_Column1LB').setAttribute("click", "return false;");
            document.getElementById('Culomn1Rpt_ctl00_Column1LB').setAttribute("cursor", "help");
        }
        if (document.getElementById('Culomn1Rpt_ctl01_Column1LB') != null) {
            document.getElementById('Culomn1Rpt_ctl01_Column1LB').setAttribute("disabled", true);
            document.getElementById('Culomn1Rpt_ctl01_Column1LB').setAttribute("click", "return false;");
            document.getElementById('Culomn1Rpt_ctl01_Column1LB').setAttribute("cursor", "help");
        }
        if (document.getElementById('Culomn1Rpt_ctl02_Column1LB') != null) {
            document.getElementById('Culomn1Rpt_ctl02_Column1LB').setAttribute("disabled", true);
            document.getElementById('Culomn1Rpt_ctl02_Column1LB').setAttribute("click", "return false;");
            document.getElementById('Culomn1Rpt_ctl02_Column1LB').setAttribute("cursor", "help");
        }
        if (document.getElementById('Culomn1Rpt_ctl03_Column1LB') != null) {
            document.getElementById('Culomn1Rpt_ctl03_Column1LB').setAttribute("disabled", true);
            document.getElementById('Culomn1Rpt_ctl03_Column1LB').setAttribute("click", "return false;");
            document.getElementById('Culomn1Rpt_ctl03_Column1LB').setAttribute("cursor", "help");
        }
        if (document.getElementById('Culomn1Rpt_ctl04_Column1LB') != null) {
            document.getElementById('Culomn1Rpt_ctl04_Column1LB').setAttribute("disabled", true);
            document.getElementById('Culomn1Rpt_ctl04_Column1LB').setAttribute("click", "return false;");
            document.getElementById('Culomn1Rpt_ctl04_Column1LB').setAttribute("cursor", "help");
        }
    }
    else {
        if (document.getElementById('Culomn1Rpt_ctl00_Column1LB') != null) {
            document.getElementById('Culomn1Rpt_ctl00_Column1LB').removeAttribute("disabled");
        }
        if (document.getElementById('Culomn1Rpt_ctl01_Column1LB') != null) {
            document.getElementById('Culomn1Rpt_ctl01_Column1LB').removeAttribute("disabled");
        }
        if (document.getElementById('Culomn1Rpt_ctl02_Column1LB') != null) {
            document.getElementById('Culomn1Rpt_ctl02_Column1LB').removeAttribute("disabled");
        }
        if (document.getElementById('Culomn1Rpt_ctl03_Column1LB') != null) {
            document.getElementById('Culomn1Rpt_ctl03_Column1LB').removeAttribute("disabled");
        }
        if (document.getElementById('Culomn1Rpt_ctl04_Column1LB') != null) {
            document.getElementById('Culomn1Rpt_ctl04_Column1LB').removeAttribute("disabled");
        }
    }
}
function GetExtraCategory() {
    var CB = $(".categoryCB");
    var input = $(".categoryCBI");
    var idString = "";
    for (var i = CB.length - 1; i >= 0; i--) {
        if (CB[i].checked) {
            idString += input[i].value + ";";
        }
    }

    document.getElementById('ExtraCategoriesInp').value = idString;
    return true;
}

function GetExtraArea() {
    var CB = $(".areaCB");
    var input = $(".areaCBI");
    var idString = "";
    for (var i = CB.length - 1; i >= 0; i--) {
        if (CB[i].checked) {
            idString += input[i].value + ";";
        }
    }

    document.getElementById('ExtraAreasInp').value = idString;
    return true;
}
function GetExtraWriterName() {
    var CB = $(".writerNameCB");
    var input = $(".writerNameCBI");
    var idString = "";
    for (var i = CB.length - 1; i >= 0; i--) {
        if (CB[i].checked) {
            idString += input[i].value + ";";
        }
    }

    document.getElementById('ExtraWriterNameInp').value = idString;
    return true;
}
function AreaAClick(aClicked, id) {
    var aArray = $('.main-events-top  li a');
    for (var i = 0; i < aArray.length; i++) {
        aArray[i].className = "";
    }
    aClicked.className = "active";
    document.getElementById('AreaInp').value = id
    document.getElementById('AreaBtn').click();
    return true;
}
function CheckIfNext() {
    if (document.getElementById('NextBLB').className == "next-active") {
        return true;
    }
    else {
        return false;
    }
}
function CheckIfPrev() {
    if (document.getElementById('PrevBLB').className == "prev-active") {
        return true;
    }
    else {
        return false;
    }
}
function IsRateAllowed(rate) {
    if (document.getElementById('RateInp').value == rate) {
        return false;
    }
    else {
        if (rate == 1) {
            document.getElementById('Star1').className = "full";
            document.getElementById('Star2').className = "null";
            document.getElementById('Star3').className = "null";
            document.getElementById('Star4').className = "null";
            document.getElementById('Star5').className = "null";
        }
        else if (rate == 2) {
            document.getElementById('Star1').className = "full";
            document.getElementById('Star2').className = "full";
            document.getElementById('Star3').className = "null";
            document.getElementById('Star4').className = "null";
            document.getElementById('Star5').className = "null";
        }
        else if (rate == 3) {
            document.getElementById('Star1').className = "full";
            document.getElementById('Star2').className = "full";
            document.getElementById('Star3').className = "full";
            document.getElementById('Star4').className = "null";
            document.getElementById('Star5').className = "null";
        }
        else if (rate == 4) {
            document.getElementById('Star1').className = "full";
            document.getElementById('Star2').className = "full";
            document.getElementById('Star3').className = "full";
            document.getElementById('Star4').className = "full";
            document.getElementById('Star5').className = "null";
        }
        else if (rate == 5) {
            document.getElementById('Star1').className = "full";
            document.getElementById('Star2').className = "full";
            document.getElementById('Star3').className = "full";
            document.getElementById('Star4').className = "full";
            document.getElementById('Star5').className = "full";
        }
        document.getElementById('RateInp').value = rate;
        GoToServerFunction('Rating', rate);
    }
}


function CheckRightMsgValidation() {
    var isOK = true;
    var name = document.getElementById("NameTB");
    var title = document.getElementById("TitleTB");
    var email = document.getElementById("EmailTB");
    var msg = document.getElementById("MsgTB");
    if (name.value.length == 0) {
        isOK = false;
    }
    if (title.value.length == 0) {
        isOK = false;
    }
    if (email.value.length == 0) {
        isOK = false;
    }
    if (msg.value.length == 0) {
        isOK = false;
    }
    if (isOK == false) {
        alert('נא למלא את כל השדות');
    }
    return isOK;
}
function CheckLeftMsgValidation() {
    var isOK = true;
    var name = document.getElementById("NameLTB");
    var title = document.getElementById("TitleLTB");
    var email = document.getElementById("EmailLTB");
    var msg = document.getElementById("MsgLTB");
    if (name.length == 0) {
        isOK = false;
    }
    if (title.value.length == 0) {
        isOK = false;
    }
    if (email.value.length == 0) {
        isOK = false;
    }
    if (msg.value.length == 0) {
        isOK = false;
    }
    if (isOK == false) {
        alert('נא למלא את כל השדות');
    }
    return isOK;
}
function CheckContactMsg() {
    var isOK = true;
    if (document.getElementById("NameTB").value.length == 0) {
        isOK = false;
    }
    if (document.getElementById("PhoneTB").value.length == 0 && document.getElementById("EmailTB").value.length == 0) {
        isOK = false;
    }
    if (document.getElementById("MsgTB").value.length == 0) {
        isOK = false;
    }
    if (document.getElementById("TitleDDL").selectedIndex == "-1") {
        isOK = false;
    }
    if (isOK == false) {
        alert('נא למלא שדות חובה');
        return false;
    }
    else {
        $('.page-contact .content').fadeOut();
        return true;
    }
}

function CheckAdsMsgValidation(msg) {
    var isOK = true;
    var message = msg.parentNode.children[3].children[1].children[0].value; //$('#' + msg.id).parent()[0].childNodes[5].childNodes[2].children[0].value;
    var name = msg.parentNode.children[4].children[1].children[0].value; //$('#' + msg.id).parent()[0].childNodes[6].childNodes[2].children[0].value;
    var phone = msg.parentNode.children[5].children[1].children[0].value; //$('#' + msg.id).parent()[0].childNodes[7].childNodes[2].children[0].value;
    var mail = msg.parentNode.children[6].children[1].children[0].value; //$('#' + msg.id).parent()[0].childNodes[8].childNodes[2].children[0].value;
    var preFix = msg.parentNode.children[5].children[2].value; //$('#' + msg.id).parent()[0].childNodes[7].childNodes[4].value;
    var title = msg.parentNode.children[2].children[1].value; //$('#' + msg.id).parent()[0].childNodes[4].children[1].value;
    
    document.getElementById('MsgInp').value = message;
    document.getElementById('NameMsgInp').value = name;
    document.getElementById('PhoneMsgInp').value = preFix + "-" + phone;
    document.getElementById('MailMsgInp').value = mail;
    document.getElementById('TitleMsgInp').value = title;
    
    if (message.length == 0) {
        isOK = false;
    }
    if (name.length == 0) {
        isOK = false;
    }
    if (phone.length > 0 && phone.length < 8) {
        if (/^\d{2}|d{3}-\d{7}$/.test(phone) == false) {
            isOK = false;
        }
    }
    else {
        isOK = false;
    }
    if (mail.length > 0) {
        if (/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(mail) == false) {
            isOK = false;
        }
    }
    else {
        isOK = false;
    }
    if (isOK == false) {
        alert('נא לתקן שדות חובה');
    }
    return isOK;
}

function GetAdvertisementsIds() {
    var cbs = $('.main-results .result .tools .CBClass');
    var dealIds = $('#DealIdInp');
}
function AddAdvertisementToFavoriteList() {
    document.getElementById('FavoriteAdvertismentInp').value = "";
    var cbs = $('.CBClass');
    var products = $('.ProductIdInp');
    var deals = $('.DealIdInp');
    for (var i = 0; i < cbs.length; i++) {
        if (cbs[i].checked == true) {
            document.getElementById('FavoriteAdvertismentInp').value = document.getElementById('FavoriteAdvertismentInp').value + deals[i].value + ';' + products[i].value + ";";
        }
    }
    if (document.getElementById('FavoriteAdvertismentInp').value.length > 0) {
        document.getElementById('AddtoFavBtn').click();
    }
    for (var i = 0; i < cbs.length; i++) {
        cbs[i].checked = false
    }
}


function RemoveAdvertisementFromFavoriteList() {
    document.getElementById('FavoriteAdvertismentInp').value = "";
    var cbs = $('.CBClass');
    var products = $('.ProductIdInp');
    var deals = $('.DealIdInp');
    for (var i = 0; i < cbs.length; i++) {
        if (cbs[i].checked == true) {
            document.getElementById('FavoriteAdvertismentInp').value = document.getElementById('FavoriteAdvertismentInp').value + deals[i].value + ';' + products[i].value + ";";
        }
    }
    if (document.getElementById('FavoriteAdvertismentInp').value.length > 0) {
        document.getElementById('RemoveFromFavBtn').click();
    }
    for (var i = 0; i < cbs.length; i++) {
        cbs[i].checked = false
    }
}


function ResetNoButton() {
    if (document.getElementById('EMailNoCB').checked == true) {
        document.getElementById('EMailNoCB').checked = false;
    }
}
function ResetYesButton() {
    if (document.getElementById('EMailYesCB').checked == true) {
        document.getElementById('EMailYesCB').checked = false;
    }
}
function ValidMessage() {
    var isOK = true;
    if (document.getElementById('PrivateNameTB').value.length == 0) {
        isOK = false;
    }
    if (document.getElementById('LastNameTB').value.length == 0) {
        isOK = false;
    }
    if (document.getElementById('Phone1TB').value.length == 0) {
        isOK = false;
    }
    if (document.getElementById('EMailTB').value.length == 0) {
        if (/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(document.getElementById('EMailTB').value) == false) {
            isOK = false;
        }
    }
    if (document.getElementById('BusinessFieldTB').value.length == 0) {
        if (isOK != true) {
            isOK = false;
        }
    }
    else {
        isOK = true;
    }
    if (document.getElementById('EMailYesCB').checked == false & document.getElementById('EMailNoCB').checked == false) {
        isOK = false;
    }
    document.getElementById('MessageInp').value = document.getElementById('message').value;
    if (isOK == false) {
        pageTracker._trackPageview('/advertisementpage/?Area=Contact&Location=' + document.getElementById('AreaDDL')[document.getElementById('AreaDDL').value].innerHTML + '&Success=Failed');
        alert('נא למלא שדות חובה');
    }
    else {
        pageTracker._trackPageview('/advertisementpage/?Area=Contact&Location=' + document.getElementById('AreaDDL')[document.getElementById('AreaDDL').value].innerHTML + '&Success=Approved');
    } 
    return isOK;
}
function CheckRangerValidation() {
    var email = document.getElementById('EMailTB');
    var name = document.getElementById('NameTB').value;
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (name.length == 0) {
        alert('נא למלא שם');
        name.focus
        return false;
    }
    if (!filter.test(email.value)) {
        alert('אימייל לא חוקי');
        email.focus
        return false;
    }
}

function SetPicId(id) {
    picId = id;
}
function MovePicId(param) { 
    var numOfPic = document.getElementById('NumberOfPictures').value;

    picId = picId + param;
    if (picId > numOfPic) {
        picId = 1;
    }
    if (picId < 1) {
        picId = numOfPic
    }
}
function RateRecommendation(starsNum) {
    switch (starsNum) {
        case 1:
            document.getElementById('RecommendationRateInp').value = 1;
            document.getElementById('StarRecommendation1').className = "full";
            document.getElementById('StarRecommendation2').className = "null";
            document.getElementById('StarRecommendation3').className = "null";
            document.getElementById('StarRecommendation4').className = "null";
            document.getElementById('StarRecommendation5').className = "null";
            break;
        case 2:
            document.getElementById('RecommendationRateInp').value = 2;
            document.getElementById('StarRecommendation1').className = "full";
            document.getElementById('StarRecommendation2').className = "full";
            document.getElementById('StarRecommendation3').className = "null";
            document.getElementById('StarRecommendation4').className = "null";
            document.getElementById('StarRecommendation5').className = "null";
            break;
        case 3:
            document.getElementById('RecommendationRateInp').value = 3;
            document.getElementById('StarRecommendation1').className = "full";
            document.getElementById('StarRecommendation2').className = "full";
            document.getElementById('StarRecommendation3').className = "full";
            document.getElementById('StarRecommendation4').className = "null";
            document.getElementById('StarRecommendation5').className = "null";
            break;
        case 4:
            document.getElementById('RecommendationRateInp').value = 4;
            document.getElementById('StarRecommendation1').className = "full";
            document.getElementById('StarRecommendation2').className = "full";
            document.getElementById('StarRecommendation3').className = "full";
            document.getElementById('StarRecommendation4').className = "full";
            document.getElementById('StarRecommendation5').className = "null";
            break;
        case 5:
            document.getElementById('RecommendationRateInp').value = 5;
            document.getElementById('StarRecommendation1').className = "full";
            document.getElementById('StarRecommendation2').className = "full";
            document.getElementById('StarRecommendation3').className = "full";
            document.getElementById('StarRecommendation4').className = "full";
            document.getElementById('StarRecommendation5').className = "full";
            break;
    }
}
function CheckRecommendationValidation(msg) {
    var isOK = true;
    var message = document.getElementById('comment-4').value;
    var name = document.getElementById('name-4').value;
    var phone = document.getElementById('PhoneRecommendationDDL').value + "-" + document.getElementById('phone-4').value;
    var mail = document.getElementById('email-4').value;
    var title = document.getElementById('subject-4').value;
    document.getElementById('MsgTitleRecommendationInp').value = title;
    document.getElementById('MsgRecommendationInp').value = message;
    document.getElementById('NameMsgRecommendationInp').value = name;
    document.getElementById('PhoneMsgRecommendationInp').value = phone;
    document.getElementById('MailMsgInp').value = mail;
    if (message.length == 0) {
        isOK = false;
    }
    if (name.length == 0) {
        isOK = false;
    }
    if (document.getElementById('phone-4').value.length > 0 && document.getElementById('phone-4').value.length < 8) {
        if (/^\d{2}|d{3}-\d{7}$/.test(phone) == false) {
            isOK = false;
        }
    }
    else {
        isOK = false;
    }
    if (mail.length > 0) {
        if (/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(mail) == false) {
            isOK = false;
        }
    }
    else {
        isOK = false;
    }
    if (isOK == false) {
        alert('נא לתקן שדות חובה');
    }
    return isOK;
}
function InsertSearchEngineDropdownIntoInput() {
    document.getElementById('SEUC_AreaInp').value = document.getElementById('SEUC_AreaDDL').value;
}
function PrintAdvertisement(dealId, productId) {
    printWindow = window.open('PrintAdvertisement.aspx?DealId=' + dealId + '&ProductID=' + productId, '', 'top=100,left=200,directories=no,location=yes,menubar=no,status=no,toolbar=no,scrollbars=yes,width=580,height=640');
    printWindow.focus();
}
function CheckSendToFriendMsg(msg) {
    var isOK = true;
    var name = $('#' + msg.id).parent()[0].childNodes[5].childNodes[2].children[0].value;
    var mail = $('#' + msg.id).parent()[0].childNodes[6].childNodes[2].children[0].value;
    if (name.length == 0) {
        isOK = false;
    }
    if (mail.length > 0) {
        if (/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(mail) == false) {
            isOK = false;
        }
    }
    document.getElementById('FriendNameInp').value = name;
    document.getElementById('FriendMailInp').value = mail;
    if (isOK == false) {
        alert('נא לתקן שדות חובה');
    }
    return isOK;
}
function CheckAndSendToFriend(msg) {
    var isOK = true;
    var name = $('#' + msg.id).parent()[0].childNodes[5].childNodes[2].children[0].value;
    var mail = $('#' + msg.id).parent()[0].childNodes[6].childNodes[2].children[0].value;
    if (name.length == 0) {
        isOK = false;
    }
    if (mail.length > 0) {
        if (/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(mail) == false) {
            isOK = false;
        }
    }
    document.getElementById('FriendNameInp').value = name;
    document.getElementById('FriendMailInp').value = mail;

    document.getElementById('FavoriteAdvertismentInp').value = "";
    var cbs = $('.CBClass');
    var products = $('.ProductIdInp');
    var deals = $('.DealIdInp');
    for (var i = 0; i < cbs.length; i++) {
        if (cbs[i].checked == true) {
            document.getElementById('FavoriteAdvertismentInp').value = document.getElementById('FavoriteAdvertismentInp').value + deals[i].value + ';' + products[i].value + ";";
        }
    }
    if (!document.getElementById('FavoriteAdvertismentInp').value.length > 0) {
        isOK = false;
        alert('נא לסמן מודעות');
        return false;
    }
    for (var i = 0; i < cbs.length; i++) {
        cbs[i].checked = false
    }
    if (isOK == false) {
        alert('נא לתקן שדות חובה');
    }
    return isOK;
}

function PrintAdvertisments() {


    document.getElementById('PrintAdvertisementsInp').value = "";
    var cbs = $('.CBClass');
    var products = $('.ProductIdInp');
    var deals = $('.DealIdInp');
    for (var i = 0; i < cbs.length; i++) {
        if (cbs[i].checked == true) {
            document.getElementById('PrintAdvertisementsInp').value = document.getElementById('PrintAdvertisementsInp').value + deals[i].value + ';' + products[i].value + ";";
        }
    }
    if (document.getElementById('PrintAdvertisementsInp').value.length > 0) {
        printWindow = window.open('../Content/PrintAdvertisements.aspx?AdvertismentsIDs=' + document.getElementById('PrintAdvertisementsInp').value, '', 'top=100,left=200,directories=no,location=yes,menubar=no,status=no,toolbar=no,scrollbars=yes,width=640,height=640');
        printWindow.focus();
    }
    for (var i = 0; i < cbs.length; i++) {
        cbs[i].checked = false
    }
}
function ShowArticleResponses() {
    var obj = $(".main-content-page .right-side .comments");
    obj.find(".comments-list").slideToggle("slow", function() {
        if ($('.comments-list').css('display') == 'block')
            obj.find(".comments-bar .comments-button a").css("backgroundPosition", "0 -10px");
        else
            obj.find(".comments-bar .comments-button a").css("backgroundPosition", "0 0");
    });
}
function clickButton(e, buttonid) { 
    var evt = e ? e : window.event;
    var bt = document.getElementById(buttonid);
    if (bt) {
        if (evt.keyCode == 13) {
            bt.click();
            return false;
        }
    }
}
function PrintArticle(articleId) {
    printWindow = window.open('Content/PrintArticle.aspx?ArticleId=' + articleId, '', 'top=100,left=200,directories=no,location=yes,menubar=no,status=no,toolbar=no,scrollbars=yes,width=580,height=640');
    printWindow.focus();
}
function PrintHowToStart(howToStartId) {
    printWindow = window.open('../Content/PrintHowToStart.aspx?HowToStartId=' + howToStartId, '', 'top=100,left=200,directories=no,location=yes,menubar=no,status=no,toolbar=no,scrollbars=yes,width=580,height=640');
    printWindow.focus();
}
function TransferToPageLocation(url) {
    window.location.href = url;
}
function ReLoadExtraCities() {
    $(document).ready(function() {
        var tooltip = $('.tooltip-435-link'),
		toolnum = $('.tooltip-435');

        for (var i = 0; i < tooltip.length; i++) {
            addEventListener(tooltip[i], 'click', (function(i) {
                return function() {
                    var el = document.getElementById('content-435-' + i);
                    el.style.display = (el.style.display == 'block') ? '' : 'block';
                };
            })(i + 1));
            addEventListener(toolnum[i].getElementsByTagName('a')[0], 'click', (function(i) {
                return function() {
                    document.getElementById('content-435-' + i).style.display = 'none';
                };
            })(i + 1));
        }
    });
}
function CheckFooterSendValidation() {
    var isOK = true;
    var email = document.getElementById('Footer$EMailTB');
    var name = document.getElementById('Footer$NameTB');
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (name.length == 0) {
        alert('נא למלא שם');
        name.focus
        isOK = false;
        return false;
    }
    else if (!filter.test(email.value)) {
        alert('אימייל לא חוקי');
        email.focus
        isOK = false;
        return false;
    }
    if (isOK) {
        return true;
    }
    
}
function reLoadFooterClass() {
    var tooltip = $('.tooltip-225-footer-link'),
		toolnum = $('.tooltip-225-footer');

    for (var i = 0; i < tooltip.length; i++) {
        addEventListener(tooltip[i], 'click', (function(i) {
            return function() {
                var el = document.getElementById('content-225-footer-' + i);
                el.style.display = (el.style.display == 'block') ? '' : 'block';
            };
        })(i + 1));
        addEventListener(toolnum[i].getElementsByTagName('a')[0], 'click', (function(i) {
            return function() {
                document.getElementById('content-225-footer-' + i).style.display = 'none';
            };
        })(i + 1));
    }
}

function ReLoad225Class(num) {
    var tooltip = $('.tooltip-225-link');
    var toolnum = $('.tooltip-225' + num);
    for (var i = 0; i < tooltip.length; i++) {
        addEventListener(tooltip[i], 'click', (function(i) {
            return function() {
                var el = document.getElementById('content-225-' + i);
                el.style.display = (el.style.display == 'block') ? '' : 'block';
            };
        }
            )(i + 1));
        addEventListener(toolnum[i].getElementsByTagName('a')[0], 'click', (function(i) {
            return function() {
                document.getElementById('content-225-' + i).style.display = 'none';
            };
        })(i + 1));
    }
}
function ReLoad135Class(num) {
    var tooltip = $('.tooltip-135-link');
    var toolnum = $('.tooltip-135' + num);
    for (var i = 0; i < tooltip.length; i++) {
        addEventListener(tooltip[i], 'click', (function(i) {
            return function() {
                var el = document.getElementById('content-135-' + i);
                el.style.display = (el.style.display == 'block') ? '' : 'block';
            };
        }
               )(i + 1));
        addEventListener(toolnum[i].getElementsByTagName('a')[0], 'click', (function(i) {
            return function() {
                document.getElementById('content-135-' + i).style.display = 'none';
            };
        })(i + 1));
    }
}


function GetSearchSelectionID(source, eventArgs) {
    var myId_array = source._id.split("_");
    document.getElementById('SEUC_SearchIdInp').value = eventArgs._value;
    document.getElementById('SEUC_SearchSelectedBtn').click();
}
//function GetSearchLocationSelectionID(source, eventArgs) {
//    var myId_array = source._id.split("_");
//    document.getElementById('SEUC_LocationInp').value = eventArgs._value;
//}



function getNextSibling(startBrother) {

    endBrother = startBrother.nextSibling;

    while (endBrother.nodeType != 1) {

        endBrother = endBrother.nextSibling;

    }

    return endBrother;

}


