﻿//*************************************************************************************
// trim - this function deletes spaces around the string.
//*************************************************************************************
String.prototype.trim = function()
{
    // Use a regular expression to replace leading and trailing 
    // spaces with the empty string
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

function myFunctionSort(points) {
    return points.sort(function (a, b) { return a - b });
}


//return false if email is not valid ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function checkEmail(checkThisEmail){
//  return (strEmail.indexOf(".") > 2) && (strEmail.indexOf("@") > 0);
   //return /^\w+@([\w\-]+\.)+\w{2,3}$/.test(strEmail);
var myEMailIsValid = true;
var myAtSymbolAt = checkThisEmail.indexOf('@');
var myLastDotAt = checkThisEmail.lastIndexOf('.');
var mySpaceAt = checkThisEmail.indexOf(' ');
var myLength = checkThisEmail.length;
// at least one @ must be present and not before position 2
// @yellow.com : NOT valid
// x@yellow.com : VALID
if (myAtSymbolAt < 1 ){myEMailIsValid = false}
// at least one . (dot) afer the @ is required
// x@yellow : NOT valid
// x.y@yellow : NOT valid
// x@yellow.org : VALID
if (myLastDotAt < myAtSymbolAt){myEMailIsValid = false}
// at least two characters [com, uk, fr, ...] must occur after the last . (dot)
// x.y@yellow. : NOT valid
// x.y@yellow.a : NOT valid
// x.y@yellow.ca : VALID
if (myLength - myLastDotAt <= 2){myEMailIsValid = false}
// no empty space " " is permitted (one may trim the email)
// x.y@yell ow.com : NOT valid
if (mySpaceAt != -1){myEMailIsValid = false}
   return myEMailIsValid

}

function emptyField(textObj){
	if (textObj.value.length == 0) return true;
	for (var i=0; i<textObj.value.length; i++) {
		var ch = textObj.value.charAt(i);
		if (ch != ' ' && ch != '\t') return false;	
	}
	return true;	
}

function onchange_select_search_AreaID_no_action(site_url) {
    /*
	var areaID,cityID = "";
	if(document.getElementById('search_AreaID')){areaID = document.getElementById('search_AreaID').value}   
	if(document.getElementById('search_cityID')){cityID = document.getElementById('search_cityID').value}   
	var url = site_url+"include/get_city_by_area.asp?areaID="+areaID+"&cityID="+cityID;  
	document.getElementById('div_search_city').innerHTML="<img src='"+site_url+"images/indicator.gif' border='0'>"
	new Ajax.Updater("div_search_city", url, {asynchronous:true});
    */
}

function onchange_select_search_AreaID(areaID){
    
    var cityID = "";
    cityID = $('#search_cityID').val();
    var page = site_url + "include/get_city_by_area.asp?areaID=" + areaID + "&cityID=" + cityID;
    var oContentDiv = $("#div_search_city")
    if ($(oContentDiv)) {
        $(oContentDiv).html('<div style="color:#000000;"><img src="'+site_url+'images/indicator.gif" width="10" height="10" hspace="5"></div>')
        $.get(page, {}, function (data) { oContentDiv.html(data); })
    }
    //if (url.trim() != '') {document.location.href = url;}
}

function onchange_select_search_CityID(url){
   //var cityID="";
   //cityID = document.getElementById('search_cityID').value;
    //document.location.href=site_url+'cards/city.asp?cityID='+cityID;
    if (url.trim() != '') { document.location.href = url; }
}

function onclick_search() {
    var str_cat = new String("");
    var str_action = new String("");
    var str_vacants = new String("");
    var areaID = new String($('#search_AreaID').val());
    var cityID = new String($('#search_cityID').val());
    var catId = new String($('#search_catID').multipleSelect("getSelects"));
    var rooms = new String($('#rooms').val());
    fromDate = $('#FromDate').val();
    toDate = $('#ToDate').val();
    if (fromDate == '') {alert("נא לציין את תאריך כניסה");return false;}
    if (toDate == '') {alert("נא לציין את תאריך עזיבה"); return false;}
    // jquery.spin - - -
    obj_spinner = "div_search_button";
    var opts = { color: '#A8A8A8', top: '-10' };
    var target, spinner;
    $(function () {
        target = $('#' + obj_spinner).get(0);
        spinner = new Spinner(opts);
        spinner.spin(target);
    });
    //  End spin - - -

    if (fromDate != '') {
        if (str_vacants != '') {
            str_vacants = str_vacants + "&fromDate=" + fromDate;
        } else {
            str_vacants = "cards/cards_vacants.asp?fromDate=" + fromDate;
        }
    }
    if (toDate != '') {
        if (str_vacants != '') {
            str_vacants = str_vacants + "&toDate=" + toDate;
        } else {
            str_vacants = "cards/cards_vacants.asp?toDate=" + toDate;
        }
    }

    if (rooms != '') {
        if (str_vacants != '') {
            str_vacants = str_vacants + "&rooms=" + rooms;
        } else {
            str_vacants = "cards/cards_vacants.asp?rooms=" + rooms;
        }
    }

    if (cityID != '') {
        if (str_vacants != '') {
            str_vacants = str_vacants + "&cityID=" + cityID;
        } else if (str_action != '') {
            str_action = str_action + "&cityID=" + cityID;
        } else {
            str_action = "cards/city.asp?cityID=" + cityID;
        }
    }

    if (catId != '') {
        var arr_cat = JSON.parse("[" + catId + "]");
        id_sort = myFunctionSort(arr_cat)
        if (str_vacants != '') {
            str_vacants = str_vacants + "&cId=" + id_sort;
        } else if (str_action != '') {
            str_action = str_action + "&cardCatID=" + id_sort;
        } else {
            str_action = "cards/selected.asp?cardCatID=" + id_sort;
        }
    }
    //alert(str_action)
    if (areaID != '') {
        if (str_vacants != '') {
            str_vacants = str_vacants + "&areaID=" + areaID;
        } else if (str_action != '' && cityID == '') {
            str_action = str_action + "&areaID=" + areaID;
        } else if (str_action == '' && cityID == '') {
            str_action = "cards/cards.asp?areaID=" + areaID;
        }
    }
    if (str_vacants != '') {
        //alert(str_vacants)
        document.location.href = site_url + str_vacants;
    } else if (str_action != '') {
        //alert(str_action)
        document.location.href = site_url + str_action;
    } else {
        //alert("0")
        document.location.href = site_url + "cards/cards_vacants.asp"
        // alert('נא לציין את אזור ו/או יישוב ו/או תאריכים ו/או מספר יחידות לחיפוש');
    }
}

function onsubmit_areasForm(formObj,site_url){
   var areaID="",cityID = "",str_action="";
   if(document.getElementById('search_AreaID')){areaID = document.getElementById('search_AreaID').value}   
   if(document.getElementById('search_cityID')){cityID = document.getElementById('search_cityID').value}   
   if (cityID!=''){str_action=site_url+'cards/city.asp?cityID='+cityID;}else if(areaID!=''){c}
   //alert(str_action)
   if(str_action!==''){formObj.action=str_action;formObj.submit();}else{return false;}
}


function onclick_main_contact_us() {
    var sendok = true;
    firstName = $("#FirstName").val();
    lastName = $("#LastName").val();
    phone = $("#phone").val();
    email = $("#email").val();
    if (firstName == "") { sendok = false; alert("יש למלא שם פרטי"); $("#FirstName").focus(); return false; }
    if (lastName == "") { sendok = false; alert("יש למלא שם משפחה"); $("#LastName").focus(); return false; }
    if (phone == "") { sendok = false; alert("יש למלא טלפון"); $("#phone").focus(); return false; }
    if (email == "") { sendok = false; alert("יש למלא כתובת מייל"); $("#email").focus(); return false; }
    if (!checkEmail(email) && email != '') { sendok = false; alert("כתובת דואר אלקטרוני לא חוקית"); $("#email").focus(); return false; }
    if (sendok == true) {
        $("#button_form_contact").css("display", "none");
        $("#line_button_form_contact").html("שליחת אימייל");
        file_url = site_url + "contact_us/get_main_form_contact_send.asp";
        var obj_form = "form_contact";
        var div = "div_contact_send";
        serializeForm(obj_form, div, file_url);
        $("#div_contact_form").hide();
    }
}

function toggle_menu() {
    if ($("#toggle_categories_slide").css("display")=="block"){
        $("#toggle_categories_slide").slideUp();
        $("#toggle_categories_title").css("display", "block");
    } else {
        $("#toggle_categories_slide").slideDown();
        $("#toggle_categories_title").css("display", "none");
    }
}


function readmore() {
    //$('#shorttext').hide();
    $('#longtext').slideDown();
    //$("#readmore_title").slideUp();
    $("#readmore_title").html("<a href=\"#\" onclick=\"readless(); return false;\" title=\"סגור ההמלצות\" class=\"link_grey_13_b_u\">&laquo; סגור ההמלצות</a>");
}

function readless() {
    $('#longtext').slideUp();
    //$('#shorttext').show();
    //$("#readmore_title").slideDown();
    $("#readmore_title").html("<a href=\"#\" onclick=\"readmore(); return false;\" title=\"קרא עוד ההמלצות\" class=\"link_grey_13_b_u\" id=\"readmore_title_text\">קרא עוד ההמלצות&raquo;</a>");
}

function readmore_details(id) {
    $("#div_cards_details_" + id).slideDown();
    $("#div_cards_details_title_" + id).html("<a href=\"javascript:readless_details(" + id + ");\" title=\"סגור מה יש בחדר\" class=\"link_grey_13_b_u\">&laquo; סגור מה יש בחדר</a>");
}
function readless_details(id) {
    $("#div_cards_details_" + id).slideUp();
    $("#div_cards_details_title_" + id).html("<a href=\"javascript:readmore_details(" + id + ");\" title=\"לצפייה מה יש בחדר\" class=\"link_grey_13_b_u\">&laquo; לצפייה מה יש בחדר</a>");
}


function onclick_info(id,itemId) {
    if ($("#ul_info_" + id + "_" + itemId).css("display") == "block") {
        $("#a_info_" + id + "_" + itemId).text("[+]");
        $("#ul_info_" + id + "_" + itemId).slideUp();
        $("#a_info_" + id + "_" + itemId).attr("title", "קרא עוד");
    } else {
        $("#a_info_" + id + "_" + itemId).text("[-]");
        $("#ul_info_" + id + "_" + itemId).slideDown();
        $("#a_info_" + id + "_" + itemId).attr("title", "סגור");
    }
}

function onclick_right_menu(item,itemName) {
    if ($("#right_menu_" + item).css("display") == "block") {
        $("#right_menu_" + item).slideUp();
        $("#right_menu_" + item + "_title").text(itemName + " ◄");
    } else {
        $("#right_menu_" + item).slideDown();
        $("#right_menu_" + item + "_title").text(itemName+" ▼");
    }
}


function addbookmark() {
    var url = "http://www.zimerim4u.co.il";
    var title = "צימרים שאפו - צימרים נבחרים בישראל "
    if (window.sidebar) { // firefox
        //alert('firefox');
        window.sidebar.addPanel(title, url, "");
    } else if (window.opera && window.print) { // opera
        var elem = document.createElement('a');
        elem.setAttribute('href', url);
        elem.setAttribute('title', title);
        elem.setAttribute('rel', 'sidebar');
        elem.click();
    } else if (document.all)// ie
        window.external.AddFavorite(url, title);
}
var pl_search = "חפשו באתר";
function checkSearch(obj) {
    if (obj.keySearch.value.trim() == "" || obj.keySearch.value.trim() == pl_search) { alert('חובה למלא שדה לחיפוש'); obj.keySearch.focus(); return false; }
    // jquery.spin - - -
    obj_spinner = "div_keySearch_button";
    var opts = { color: '#A8A8A8', top: '-10' };
    var target, spinner;
    $(function () {
        target = $('#' + obj_spinner).get(0);
        spinner = new Spinner(opts);
        spinner.spin(target);
    });
    //  End spin - - -

}
function MM_openBrWindow(theURL,winName,features){window.open(theURL,winName,features);}


function onclick_open_close(catID){
  var  statusLink=new String(document.getElementById('link_icon_'+catID).src);
  if(statusLink.indexOf("plus",0)>0){
     document.getElementById('link_icon_'+catID).src=site_url+'images/icon_minus.gif'
     document.getElementById('div_subcatlist_'+catID).style.display='block';
  }else if (statusLink.indexOf("minus",0)>0){
     document.getElementById('link_icon_'+catID).src=site_url+'images/icon_plus.gif'
     document.getElementById('div_subcatlist_'+catID).style.display='none';
  }     
}

function mouseover_hp_card(card,from,to) {
    for (i = from; i <= to; i++) {
        if (document.getElementById('div_hp_card_link_' + i) ) {
            document.getElementById('div_hp_card_link_' + i).className = "hp_cards_list";
        }
        if (document.getElementById('div_hp_card_desc_' + i) && i != card) {
            document.getElementById('div_hp_card_desc_' + i).style.display = "none";
        }
        if (document.getElementById('div_hp_card_picture_' + i) && i!=card) {
            document.getElementById('div_hp_card_picture_' + i).style.display = "none";
        }
    }
    if (document.getElementById('div_hp_card_link_' + card)) {
        document.getElementById('div_hp_card_link_' + card).className = "hp_cards_list_act";
    }
    if (document.getElementById('div_hp_card_desc_' + card)) {
        document.getElementById('div_hp_card_desc_' + card).style.display = "block";
    }
    if (document.getElementById('div_hp_card_picture_' + card) ) {
        document.getElementById('div_hp_card_picture_' + card).style.display = "block";
    }
}

function LoadIMG(siteUrl) { document.getElementById('captcha_numchar').src = siteUrl + 'global/captcha.asp?' + Date(); }

function applyFilter(obj_picture) {
    if (document.all && document.getElementById(obj_picture)) // Apply only 4 IE
    {
        document.getElementById(obj_picture).style.filter = "blendTrans(duration=1)";
        document.getElementById(obj_picture).filters.blendTrans.apply();
        document.getElementById(obj_picture).filters.blendTrans.play()
    }
}

function customer_recommend(cardId) {
    $.get(site_url + "cards/get_form_recommend.asp?cardId=" + cardId, function (data) {
        $("#div_body_out").css("display", "block");
        closebtn = "<a href=\"javascript:hide_dialog(\'div_dialog\')\" class='xclose' >סגור</a>";
        $("#div_dialog").html(closebtn + data);
        $("#div_dialog").show();
        $("#dialog_form").submit(function (event) {
            var sendok = true;
            nameval = $("#qualityClientName").val();
            emailval = $("#qualityClientEmail").val();
            descval = $("#qualityDesc").val();
            if (nameval == "") { sendok = false; alert("יש למלא שם"); $("#qualityClientName").focus(); return false; }
            if (emailval == "") { sendok = false; alert("יש למלא כתובת מייל");  $("#qualityClientEmail").focus(); return false; }
            if (!checkEmail(emailval) && emailval !='') { sendok = false; alert("כתובת דואר אלקטרוני לא חוקית");  $("#qualityClientEmail").focus(); return false;}
            if (descval == "") { sendok = false; alert("יש למלא תיאור"); $("#qualityDesc").focus(); return false; }
            event.preventDefault();
            var $form = $(this),
            furl = site_url + "cards/get_form_recommend_send.asp";
            if (sendok == true) {
                $("#button_form").css("display", "none");
                $("#line_button_form").html("שליחת אימייל");
                $.ajax({
                    type: 'POST',
                    url: furl,
                    data: $form.serialize(),
                    success: function (data) {
                        if (data.indexOf("True") != -1) {
                            $form[0].reset();
                            $("#dialog_form").html("<center><br /><br /><br />ההמלצה נקלטה , נציגנו ישובו אליכם בהקדם</center>");
                        }
                        else {alert("היתה בעיה בשליחת הטופס");}
                    }
                });
            }
            //else {alert("יש למלא שם , כתובת מייל ו/או טלפון");}
        });
        //re install ends
    });
}

function customer_contact_us(custID) {
    $("#div_contact_send").html('');
    $("#div_contact_form").show();
    $.get(site_url + "cards/get_form_contact_us.asp?custID=" + custID, function (data) {
        $("#div_body_out").css("display", "block");
        closebtn = "<a href=\"javascript:hide_dialog(\'div_dialog_contact\')\" class='xclose' >סגור</a>";
        $("#div_dialog_contact").html(closebtn + data);
        $("#div_dialog_contact").show();
    });
}

function onclick_customer_contact_us(custID) {
    var sendok = true;
    nameval = $("#name_contact").val();
    emailval = $("#email_contact").val();
    phone = $("#phone_contact").val();
    if (nameval == "") {sendok = false; alert("יש למלא שם"); $("#name_contact").focus(); return false; }
    if (phone == "") { sendok = false; alert("יש למלא טלפון"); $("#phone_contact").focus(); return false; }
    if (emailval == "") { sendok = false; alert("יש למלא כתובת מייל"); $("#email_contact").focus(); return false; }
    if (!checkEmail(emailval) && emailval != '') { sendok = false; alert("כתובת דואר אלקטרוני לא חוקית"); $("#email_contact").focus(); return false;}
    if (sendok == true) {
        $("#button_form_contact").css("display", "none");
        $("#line_button_form_contact").html("שליחת אימייל");
        file_url = site_url + "cards/get_form_contact_us_send.asp";
        var obj_form = "dialog_form_contact";
        var div = "div_contact_send";
        serializeForm(obj_form, div, file_url);
        $("#div_contact_form").hide();
    }
}

function hide_dialog(div) {
    $("#div_body_out").hide();
    $("#" + div).html("");
    $("#" + div).hide();
}

function slideImage(obj) {
    url = $(obj).attr("href");
    $("#mainpic").attr("src",url);
}

// jQuery - - - -
function serializeForm(obj_form, div, file_url) {
    var str = $("#" + obj_form).serialize();
    $.ajax({
        type: "POST",
        url: file_url,
        data: str,
        success: function (html) {
            $("#" + div).html(html);
        }
    });
}


function show_box(url, w, h) {
    document.getElementById("div_body_box").style.display = "";
    makeFrame(url, w, h);
}

function hide_box() {
    lastobj = document.getElementById('div_box');
    //ifrm.src = "";
    document.body.removeChild(lastobj);
    document.getElementById("div_body_box").style.display = "none";
}

function makeFrame(url, w, h) {
    ifrm = document.createElement("IFRAME");
    last_float_div = "div_box";
    ifrm.setAttribute("src", url);
    ifrm.setAttribute("id", last_float_div);
    ifrm.style.width = w + "px";
    ifrm.style.height = h + "px";
    ifrm.style.position = "fixed";
    ifrm.style.zIndex = "999999";
    ifrm.style.top = "50%";
    ifrm.style.left = "50%";
    ifrm.style.marginLeft = "-" + w / 2 - 20 + "px";
    ifrm.style.marginTop = "-" + h / 2 + "px";
    ifrm.style.borderWidth = "0px";
    ifrm.style.borderColor = "CDCDCD";
    //ifrm.style.borderRadius = "4px";
    document.body.appendChild(ifrm);
    document.getElementById("xclose_box").style.top = ifrm.style.top;
    document.getElementById("xclose_box").style.right = ifrm.style.right;
    document.getElementById("xclose_box").style.marginTop = "-" + h / 2 + "px";
    document.getElementById("xclose_box").style.marginRight = w / 2 - 20 + "px";
    document.getElementById("xclose_box").zIndex = "9999999";
    document.getElementById("xclose_box").href = "javascript:hide_box()";
    document.getElementById("xclose_box").style.display = "";
}

function card_vacantsCalendar(cardID, vacantsMonth) {
    //alert(cardID + "; " + vacantsMonth);
    div_update = "div_card_vacants_" + cardID;
    if (document.getElementById(div_update)) { document.getElementById(div_update).innerHTML = '<div style="padding-top:100px;padding-top:50px;"> <img src="' + site_url + 'images/loading.gif" width="128" height="128" hspace="5"></div>' }
    page = site_url + "cards/get_card_vacant_month.asp?cardID=" + cardID + "&view_date=" + vacantsMonth;
    //alert(page);
    var oContentDiv = $("#" + div_update);
    $.get(page, {}, function (data) { oContentDiv.html(data); })
}

