
//***********************************************************
// check that only digits are written                       *
//***********************************************************
function ckdigits() {
  if ((event.keyCode<48)||(event.keyCode>57))
    return false;
  return true;
}


//***********************************************************
// check if not NULL, otherwise print message and focus     *
//***********************************************************
function isEmpty(fieldName, hebFieldName, isShowMessage) {
  if (document.getElementById(fieldName).value == "") {
    if (isShowMessage == 1) { alert("שדה " + hebFieldName + " הוא שדה חובה"); document.getElementById(fieldName).focus(); }
    return true;
  }
  return false;
}


//***********************************************************
// check that no character " or ' pressed                   *
//***********************************************************
function noCommas() { 
  if ((event.keyCode==39) || (event.keyCode==34)) 
    return false; 
  return true; 
}


//***********************************************************
// check that the Email is correct                          *
//***********************************************************
function ckMail(fieldName) { 
  if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.getElementById(fieldName).value))) {
      alert("אימייל לא תקין");
      document.getElementById(fieldName).focus();
      return false;
   }
  return true;
}


//***********************************************************
// Check if any of the CheckBox group is selected           *
//***********************************************************
function isAtLeastOneOfCkBxGroupSelected(ckbxObj) {
  var isAtLeastOneSelected = false;
  for (i_ckBx = 0; i_ckBx < ckbxObj.length; i_ckBx++) {
    if (ckbxObj[i_ckBx].checked == true) 
      isAtLeastOneSelected = true;
  }
  
  return isAtLeastOneSelected;
}


//***********************************************************
// Display message for the user in a Dialog                 *
//***********************************************************
function showModal(comment) {
  window.showModalDialog(comment);
}


//***********************************************************
// Display message for the user in a Dialog                 *
//***********************************************************
function ckFieldSize(objField,limit) {
  if (objField.value.length >= limit) {
    alert("אורך השדה מוגבל ל- " + limit + " תווים");
    objField.value=objField.value.substring(0,limit);
    objField.focus();
    return false;
  } 
  return true;
}


//***********************************************************
// Display message for the user in a Dialog                 *
//***********************************************************
function ckFieldMinSize(fieldName,limit,hebFieldName) {
  if (document.getElementById(fieldName).value.length < limit) {
    alert("מינימום אורך " + hebFieldName + " " + limit + " תווים");
    document.getElementById(fieldName).focus();
    return false;
  } 
  return true;
}


//***********************************************************
// check if PASSWORD and PASSWORD Verification are equals   *
//***********************************************************
function strEqual(fieldName1, fieldName2, notEqualMessage) {
  var fieldVal1 = document.getElementById(fieldName1).value;
  var fieldVal2 = document.getElementById(fieldName2).value;

  if (fieldVal1 != fieldVal2) {
    document.getElementById(fieldName1).value = "";
    document.getElementById(fieldName2).value = "";
    alert(notEqualMessage);
    document.getElementById(fieldName1).focus();
    return false;
  }
  return true;
}


//***********************************************************
// check if fields are equal, and display relative message  *
//***********************************************************
function isFieldsEqual(fieldName1, fieldName2) {
  var fieldVal1 = document.getElementById(fieldName1).value;
  var fieldVal2 = document.getElementById(fieldName2).value;

  if (fieldVal1 != fieldVal2) 
    return false;

  return true;
}


//***********************************************************
// this function gets confirmation from the user to delete  *
//***********************************************************
function isDelConfirm(hiddenDelFieldName, Message) {
  if (confirm(Message) == true) {
    document.getElementById(hiddenDelFieldName).value = "delExecute";
    return true;
  }
  
  return false;
}


//**************************************************************************************************** 
// The Function: send data to server and get response by Ajax                                        *
// DataToSend : "clientID=7&articleID=9"                                                             *
// URL        : "updateUserOnDemand.asp"                                                             *
//                                                                                                   *
// Call Example :                                                                                    *
// var getResponseText = getAjaxResponse("clientID=7&articleID=9", "updateUserOnDemand.asp", true);  *
//****************************************************************************************************
var xmlhttp, genericAjaxResult = ""; // global varient (because of firefox javascript problems)
function getAjaxResponse(DataToSend, URL, bText) {

  // Explorer
  if (document.all) {
    xmlhttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");
    xmlhttp.Open("POST", URL + '?rand=' + Math.random(), false);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.send(DataToSend);
    return (bText ? xmlhttp.responseText : xmlhttp.responseXML);
 

  // FireFox
  } else {
  xmlhttp = new XMLHttpRequest();

  xmlhttp.open("POST", URL + "?rand=" + Math.random(), false); /* the false here makes it synchronous */
  xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  xmlhttp.send(DataToSend);
  
  if (xmlhttp.status == 200)  /* the request has been returned */
    return (xmlhttp.responseText.toString());
  }
}



//***********************************************************
// this function Add Site to favorites                      *
// siteUrl  : "http://www.moment.co.il/articlesN"           *
// siteTitle: "Moment - מומנט מאמרים"                       *
//***********************************************************
function addToFavorites(siteUrl, siteTitle) {
  if (document.all) window.external.AddFavorite(siteUrl, siteTitle);
}


//**************************************************************************
// this function make Site as homePage                                     *
// objClicked: the object with the 'onClick' atttibute                     *
// siteURL  : the url to make as home page                                 *
// EXAMPLE: onclick = "makeHomePage(this, 'http://Zimers.moment.co.il/')"  *
//**************************************************************************
function makeHomePage(objClicked, siteURL) {
	objClicked.style.behavior = 'url(#default#homepage)';
	objClicked.setHomePage(siteURL);
}


//***********************************************************************
// this function Display the help Msg Border on the screen              *
// Warning:                                                             *
//          1. Need to set onmouseover (on img "helpImg.png").          *
//             Exm: onmouseover="displayHelpMsg('helpTable',1,20,20);"  *
//          2. Need to set onmouseout (on img "helpImg.png").           *
//             Exm: onmouseout="displayHelpMsg('helpTable',0,20,20);"   *
//***********************************************************************
function displayHelpMsg(elementID, isActive, rightFromMouse, upFromMouse) {
  if (isActive == 1) {
    document.getElementById(elementID).style.display = "inline";
    document.getElementById(elementID).style.left = (event.x + rightFromMouse) + 'px';
    document.getElementById(elementID).style.top = ((event.y - document.getElementById(elementID).clientHeight) - upFromMouse) + document.body.scrollTop + 'px';
  }
  else if (isActive == 0) {
    document.getElementById(elementID).style.display = "none";
  }
}



//***********************************************************************
// this function return the fix size for width or height as request     *
// sourceImage = supposed to be the object itself                       *
// scaleToReturn = "width" OR "height"                                  *
//***********************************************************************
function getFixSize(sourceImage, maxWidth, maxHeight, scaleToReturn) {
  var imageFixLoad = new Image();
  imageFixLoad.src = sourceImage.src;
  
  var tempWidth = parseInt(imageFixLoad.width); var tempHeight = parseInt(imageFixLoad.height);

  if (parseInt(tempWidth) > parseInt(maxWidth)) {
    tempHeight = parseInt(tempHeight * (maxWidth / tempWidth));
    tempWidth = maxWidth;
  }

  if (parseInt(tempHeight) > parseInt(maxHeight)) {
    tempWidth = parseInt(tempWidth * (maxHeight / tempHeight));
    tempHeight = maxHeight;
  }

  if (scaleToReturn == "width")
    return parseInt(tempWidth);
  else if (scaleToReturn == "height")
    return parseInt(tempHeight);
}



//***************************************************************************************************
// this function Uses function getFixSize to return the fix size for width or height as request     *
// imgObj - the object of the img, usually used as "this" in an ims tag                             *
// widthMax - is going top be the maximum width size the pictur can be                              *
// heightMax - is going top be the maximum height size the pictur can be                            *
//***************************************************************************************************
function setPicProportionSize(imgObj, widthMax, heightMax) {
  imgObj.style.width = getFixSize(imgObj, widthMax, heightMax, "width");
  imgObj.style.height = getFixSize(imgObj, widthMax, heightMax, "height");
}



//***********************************************************************************
// this function used in Lists Files to display big image next to the small one     *
//***********************************************************************************
function displayOriginalImg(divID, imgID, imgSrc, rightFromMouse, upFromMouse, isActive) {
  var imagePreLoad = new Image();
  imagePreLoad.src = imgSrc;

  if (isActive == 1) {
    document.getElementById(divID).style.display = "inline";
    document.getElementById(imgID).src = imgSrc;
    document.getElementById(imgID).style.width = getFixSize(imagePreLoad, parseInt((document.body.clientWidth - event.x) - (rightFromMouse + 10)), 250, "width") + 'px';
    document.getElementById(imgID).style.height = getFixSize(imagePreLoad, parseInt((document.body.clientWidth - event.x) - (rightFromMouse + 10)), 250, "height") + 'px';
    document.getElementById(divID).style.left = (event.x + rightFromMouse) + 'px';
    document.getElementById(divID).style.top = ((event.y - document.getElementById(divID).clientHeight) - upFromMouse) + document.body.scrollTop + 'px';
  }
  else if (isActive == 0) {
    document.getElementById(imgID).src = "";
    document.getElementById(divID).style.display = "none";
  }
}



