function getBannerUrl(iUrlID) {
  switch(iUrlID) {
    case 1:
      getUrl('Content.asp?mdl=content&page=163&m=0&class=hatzil');
    break;
    case 2:
      getUrl('Content.asp?mdl=content&page=162&m=0&class=hatzil');
    break;
    case 3:
      getUrl('Content.asp?mdl=content&m=49&page=160&class=blue');
    break;
  }
}
function getUrl(sUrl) {
  window.top.location.href = sUrl;
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}
function rolloverImage(sImageID) {
	var oImg = document.getElementById(sImageID);
	var sNewImage = sImageID;
	sNewImage = sNewImage.replace('_','-');
	sNewImage = sNewImage +'-over.jpg';
	oImg.src = 'Images/inner/'+ sNewImage;
}
function rolloutImage(sImageID) {
	var oImg = document.getElementById(sImageID);
	var sNewImage = sImageID;
	sNewImage = sNewImage.replace('_','-');
	sNewImage = sNewImage +'.gif';
	oImg.src = 'Images/inner/'+ sNewImage;
}
function overImage(sImageID) {
	var oImg = document.getElementById(sImageID);
	var sNewImage = sImageID;
	sNewImage = sNewImage.replace('_','-');
	sNewImage = 'btn-'+ sNewImage +'-over.gif';
	oImg.src = 'Uploads/menu/'+ sNewImage;
}
function outImage(sImageID) {
	var oImg = document.getElementById(sImageID);
	var sNewImage = sImageID;
	sNewImage = sNewImage.replace('_','-');
	sNewImage = 'btn-'+ sNewImage +'.gif';
	oImg.src = 'Uploads/menu/'+ sNewImage;
}
function overImageHome(sImageID) {
	var oImg = document.getElementById(sImageID);
	var sNewImage = sImageID;
	sNewImage = sNewImage.replace('_','-');
	sNewImage = 'btn-'+ sNewImage +'-over.gif';
	oImg.src = 'Uploads/menu/home/'+ sNewImage;
}
function outImageHome(sImageID) {
	var oImg = document.getElementById(sImageID);
	var sNewImage = sImageID;
	sNewImage = sNewImage.replace('_','-');
	sNewImage = 'btn-'+ sNewImage +'.gif';
	oImg.src = 'Uploads/menu/home/'+ sNewImage;
}

function fnSwapImage(sImageID,sImagePath) {
	var oImg = document.getElementById(sImageID);
	oImg.src = sImagePath;
}

function openCenterWindow(url,nm,wd,ht,st) {
	d = (screen.width-wd)/2;
	h = ((screen.height-ht)/2);
	window.open(url,nm,'top='+h+',left='+d+',width='+wd+',height='+ht+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+st+',resizable='+st+'');
}

function PopupGalleryPic(iPicID,iWidth,iHeight) { 
    var wd = iWidth;
    var ht = iHeight;
    var d = ((screen.width-wd)/2);
		var h = ((screen.height-ht)/2);
    window.open('popup-gallery-pic.asp?'+iPicID,'popupImage','top='+h+',left='+d+',width='+wd+',height='+ht+',toolbar=no,location=no,directories=no,menubar=no,status=no,scrollbars=yes,resizable=yes');
}

// =========== Functions for <div> ==========

function pLayer(layerName) {
	if (document.getElementById(layerName).style.display == "none") {
		document.getElementById(layerName).style.display = "block";
	}
	else {
		document.getElementById(layerName).style.display = "none";
	} 
}

function ColapseAll(StrDivName) {
	var d = document.getElementsByTagName('div');
	for (var h=0;h<d.length;h++)
	{
		if (d[h].id.substr(0, 3) == StrDivName)
			d[h].style.display = 'none';
	}
}

function ExpandAll(StrDivName) {
	var d = document.getElementsByTagName('div');
	for (var h=0;h<d.length;h++)
	{
		if (d[h].id.substr(0, 3) == StrDivName)
			d[h].style.display = 'block';
	}
}

// =========== Price Quote Functions ==========
var g_currency = '₪';
var aPriceID = new Array();
var aPrices = new Array();

function fnUpdateCart(iID,iPrice) {
  var ItmLine = document.getElementById('PA_'+iID);
  var imgIcon = document.getElementById('PL_'+iID);
  var linkTtl = document.getElementById('LK_'+iID);
  if(aPriceID.isIn(iID)) {
    //alert(imgIcon.src);
    aPriceID.remove(iID);
    aPrices.remove(iPrice);
    fnUpdateSum();
    setOpacity(ItmLine,100);
    imgIcon.src = 'Images/inner/icon-add.gif';
    imgIcon.alt = 'הוסף להצעת המחיר';
    linkTtl.title = 'הוסף להצעת המחיר';
  } else {
    //alert(imgIcon.src);
    aPriceID.push(iID);
    aPrices.push(iPrice);
    fnUpdateSum();
    setOpacity(ItmLine,35);
    imgIcon.src = 'Images/inner/icon-remove.gif';
    imgIcon.alt = 'הסר מהצעת המחיר';
    linkTtl.title = 'הסר מהצעת המחיר';
  }
  var oInptTotal = document.getElementById('numOfPersons');
  var iCount = oInptTotal.value;
  if(iCount > 19)
    fnCalcTotal();
}

function fnUpdateSum() {
  var oPricelistSum = document.getElementById('pricelistSum');
  var iSum = 0;
  for(var i=0; i<aPrices.length; i++) 
    iSum += aPrices[i];
    
  oPricelistSum.innerHTML = formatCurrency(iSum)+' <br /> למשתתף';
  var oInptTotal = document.getElementById('numOfPersons');
  var iCount = oInptTotal.value;
  if(iSum>0) {
    save_cookie('aPrices'+iGroup,aPrices.join(','),10);
    save_cookie('aPriceID'+iGroup,aPriceID.join(','),10);
    if(iCount > 19)
      save_cookie('iCount'+iGroup,iCount,10);
  } else {
    delete_cookie('aPrices'+iGroup);
    delete_cookie('aPriceID'+iGroup);
    delete_cookie('iCount'+iGroup);
  }
  return iSum;
}

function fnCalcTotal() {
  var oInptTotal = document.getElementById('numOfPersons');
  var oPriceTotalSum = document.getElementById('priceTotalSum');
  var iSum = fnUpdateSum();
  var iCount = oInptTotal.value;
  if(iCount > 19)
    oPriceTotalSum.innerHTML = formatCurrency(iSum*iCount)+' <br /> לקבוצה';
  else {
    alert('אנא הקלד מספר משתתפים');
    oInptTotal.focus();
  }
}

function formatCurrency(num) {
  num = num.toString().replace(/\$|\,/g,'');
  if(isNaN(num))
  num = "0";
  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num*100+0.50000000001);
  cents = num%100;
  num = Math.floor(num/100).toString();
  if(cents<10)
  cents = "0" + cents;
  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
  num = num.substring(0,num.length-(4*i+3))+','+
  num.substring(num.length-(4*i+3));
  return (((sign)?'':'-') + g_currency + num);// + '.' + cents);
}

// =========== Array Functions ==========
// http://hexmen.com/blog/2006/12/push-and-pop/
Array.prototype.push = function() {
    var n = this.length >>> 0;
    for (var i = 0; i < arguments.length; i++) {
        this[n] = arguments[i];
        n = n + 1 >>> 0;
    }
    this.length = n;
    return n;
};

Array.prototype.pop = function() {
    var n = this.length >>> 0, value;
    if (n) {
        value = this[--n];
        delete this[n];
    }
    this.length = n;
    return value;
};

Array.prototype.inArray = function (value)
// Returns true if the passed value is found in the
// array.  Returns false if it is not.
{
    var i;
    for (i=0; i < this.length; i++) {
        // Matches identical (===), not just similar (==).
        if (this[i] === value) {
            return true;
        }
    }
    return false;
};
Array.prototype.remove=function(s){
  for(i=0;i<this.length;i++){
    if(s==this[i]) this.splice(i, 1);
  }
}
/*
  Code from "Developing Featherweight Web Services with JavaScript"
      http://feather.elektrum.org/
  (c)An Elektrum Press, retain this notice
      License: http://feather.elektrum.org/appendix/licenses.html
*/

Array.prototype.serial = function() {
  switch( this.length ) {
    case 0 : return false;
    case 1 : return this[0].toString();
    case 2 : return this.join(' and ');
    default: return this.slice(0,-1).join(', ') +
               ', and ' + this[ this.length - 1 ];
  }
}

Array.prototype.sum = function() {
  var sum = 0;
  for ( var i = 0; i < this.length; i++ ) sum += this[i];
  return sum;
}

Array.prototype.isIn = function( what ) {
  if ( ! what ) return false;
  for ( var i = 0; i < this.length; i++ ) {
    if ( this[i] == what ) return true;
  }
  return false;
}

Array.prototype.dedup = function () {
  var newArray = new Array ();
  var seen = new Object ();
  for ( var i = 0; i < this.length; i++ ) {
    if ( seen[ this[i] ] ) continue;
    newArray.push( this[i] );
    seen[ this[i] ] = 1;
  }
  return newArray;
}

Array.prototype.max = function () {
  var max = new Number();
  for ( var i = 0; i < this.length; i++ ) {
    if ( this[i] > max ) max = this[i];
  }
  return max;
}

Array.prototype.min = function () {
  var min = new Number();
  for ( var i = 0; i < this.length; i++ ) {
    if ( this[i] < min ) min = this[i];
  }
  return min;
}

Array.prototype.mean = function () {
  return this.sum() / this.length;
}

// =================== Other Functions =================== 
/* 
Use it like this:
var e=document.getElementById('myElement');
setOpacity(e, 50);//Sets the opacity to 50%
*/
function setOpacity(e,opacity) {
  var o=e.style;
  o.opacity=(opacity/100); //Opera
  o.MozOpacity=(opacity/100); //Mozilla+Firefox
  o.KhtmlOpacity=(opacity/100); //Konqueror
  o.filter="alpha(opacity="+opacity+")"; //IE
}


function save_cookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000))
		var expires = "; expires="+date.toGMTString()
	}
	else expires = ""
	document.cookie = name+"="+value+expires+"; path=/"
}

function read_cookie(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) return c.substring(nameEQ.length,c.length)
	}
	return null
}

function delete_cookie(name) {
	save_cookie(name, "", -1);
}
