﻿//*************************************************************************************
// 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 onclick_clear(obj){
   if(obj.value.trim() == "שם מלא" || obj.value.trim() == "טלפון" || obj.value.trim() == "דואר אלקטרוני" || obj.value.trim() == "הערות"){
      obj.value = "";
   }
}

function DoCalAdmin(elTarget,elName) {
  if (showModalDialog) {
    var sRtn;
    sRtn = showModalDialog(site_url + "include/calendar.asp",elTarget.value,"center=yes; dialogWidth=160pt; dialogHeight=170pt; status=0; help=0;");
    if (sRtn!=""){
       elTarget.value = sRtn;
    }
  } else
    alert("Internet Explorer 4.0 or later is required.")
 return false;
 window.document.focus;   
}

//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 LoadIMG(siteUrl){
    document.getElementById('captcha_numchar').src=siteUrl+'global/captcha.asp?'+Date();
}


function div_loading(site_url,div){
   document.getElementById(div).innerHTML="<img src='"+site_url+"images/indicator.gif' border='0'>";
}

function addbookmark(){
var url="http://www.zimmerwow.co.il";
var title="צימרים wow";
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);
}

function checkSearch(obj){if(obj.keySearch.value.trim() == ""){alert('חובה למלא שדה לחיפוש');obj.keySearch.focus();return false;}}
function MM_openBrWindow(theURL,winName,features){window.open(theURL,winName,features);}

function change_pictureBig(pictureID){
 var url = site_url+"cards/get_pictureBig.asp?pictureID="+pictureID;
 var page = site_url+"cards/get_pictureBig.asp?pictureID="+pictureID;  
 var obj_picture="picture_card";
 var oContentDiv = $('#picture_card');
 $.get(page,{},function(data){
 response_Results=new String(data);
 arr_Results=response_Results.split('_SRC_');
 applyFilter(obj_picture);
 document.getElementById(obj_picture).src = arr_Results[0];
 $("#div_card_desc").html(arr_Results[1]);
 $("#div_card_nav").html(arr_Results[2]);
 });
}

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 check_contactForm(formObj) {	
if (document.activeElement.id != "searchCommon"){	
  if (emptyField(formObj.name) || formObj.name.value.trim() == "שם מלא") {window.alert("אנא מלא/י שם מלא ");formObj.name.focus();return false;}
  if (formObj.phone){
  if (emptyField(formObj.phone) || formObj.phone.value.trim() == "טלפון") {window.alert("אנא מלא/י טלפון");formObj.phone.focus();return false;}	}
  // if (emptyField(formObj.email)) {window.alert("אנא מלא/י שדה כתובת דואר אלקטרוני");formObj.email.focus();return false;}	
  if (formObj.email){
  if ( formObj.email.value.trim()!='דואר אלקטרוני' && formObj.email.value!='' && !checkEmail(formObj.email.value)){alert("כתובת דואר אלקטרוני לא חוקית");formObj.email.select();return false;}	}
 // if (document.getElementById('captchacode').value==''){alert("אנא מלא/י קוד זיהוי ");document.getElementById('captchacode').focus();return false;}
  if (formObj.id!='form_contact'){
  uploadFormToDiv();
   }
 }else{
   if (emptyField(formObj.keySearch)){window.alert("אנא למלא מילות מפתח לחיפוש ");formObj.keySearch.focus();return false;}
  }
}

// jQuery - - - - 
function uploadFormToDiv(){
   $('#form_topSearch').submit(function(){   
         var str = $(this).serialize(); 
         $.ajax({   
            type: "POST",   
            url: site_url+"contact_us/choosed_thanks.asp",   
            data: str,
            success: function(html){   
                $("#div_formThanks").html(html);   
            }   
       });   
        return false;   
    }); 
}

function onclick_ahavti(cardID,divName){
   var div_card="#div_"+divName+"_"+cardID;
   var oContentDiv = $(div_card);
   var page = site_url+"cards/get_ahavti.asp?cardId="+cardID+"&div="+divName;
   //alert(page);
   $.get(page,{},function(data){oContentDiv.html(data);});
}

function onclick_myChoice(cardID,divName){
   var div_card="#div_"+divName+"_"+cardID;
   var oContentDiv = $(div_card);
   var page = site_url+"cards/get_myChoice.asp?cardId="+cardID+"&div="+divName;
   //alert(page);
   $.get(page,{},function(data){oContentDiv.html(data);});
}

function show_prices(typeid){
   var oContentDiv = $('#ul_pricetype');
   var priceid= $('#hiddenPriceID').val();
   //alert(priceid)
   var page = site_url+"search/get_search.asp?priceTypeid="+typeid+"&search=prices"+"&priceid="+priceid;  
   $.get(page,{},function(data){oContentDiv.html(data);});
}

function show_categories(){
   var oContentDiv = $('#div_catid');
   
   var page = site_url+"search/get_search.asp?search=categories";  
   $.get(page,{},function(data){oContentDiv.html(data);});
}

function show_areas(){
   var oContentDiv = $('#ul_region');
   var page = site_url+"search/get_search.asp?search=areas";  
   $.get(page,{},function(data){oContentDiv.html(data);});
}
function show_cities(){
   var oContentDiv = $('#select_cityID');
   var page = site_url+"search/get_search.asp?search=cities";  
   $.get(page,{},function(data){oContentDiv.html(data);});
}


