﻿var ie=document.all ? true : false;
var ie5=(document.all && !document.getElementById)? (true):(false);if (ie5){document.getElementById=function (e){return document.all[e];}}

function $(id){return document.getElementById(id);}
function addEvent(eventType,handlerFunc,addToObject){
	var o=(addToObject)?(addToObject):(window);if (o){	
	if (window.attachEvent){o.attachEvent("on"+eventType,handlerFunc);}
	else if (window.addEventListener){o.addEventListener(eventType,handlerFunc,false);}
	}
}

function onContent(f){//(C)webreflection.blogspot.com
var a=onContent,b=navigator.userAgent,d=document,w=window,c="onContent",e="addEventListener",o="opera",r="readyState",
s="<scr".concat("ipt defer src='//:' on",r,"change='if(this.",r,"==\"complete\"){this.parentNode.removeChild(this);",c,".",c,"()}'></scr","ipt>");
a[c]=(function(o){return function(){a[c]=function(){};for(a=arguments.callee;!a.done;a.done=1)f(o?o():o)}})(a[c]);
if(d[e])d[e]("DOMContentLoaded",a[c],false);
if(/WebKit|Khtml/i.test(b)||(w[o]&&parseInt(w[o].version())<9))(function(){/loaded|complete/.test(d[r])?a[c]():setTimeout(arguments.callee,1)})();
else if(/MSIE/i.test(b))d.write(s);
};

function setHTML(id,str)	{var o=$(id);if(!o)return;o.innerHTML=str;}
function getHTML(id)		{var str="";var o=$(id);if (o)str=o.innerHTML;return str;}
function setFocus(id)		{var o=$(id);if(!o)return;o.focus();}
function setValue(id,str)	{var o=$(id);if(!o)return;o.value=str;}
function autoselect(id,str)	{var o=$(id);if(!o)return;if (!o.length)return;for (var i=0;i<o.length; i++){if (o[i].value==str){o.selectedIndex=i;break;}}}

function getOffsetTop (el){var ot = el.offsetTop;while ( ( el = el.offsetParent ) != null ){	ot += el.offsetTop;	}return ot;}
function getOffsetLeft (el){var ot = el.offsetLeft;while ( ( el = el.offsetParent ) != null ){ot += el.offsetLeft;}return ot;}
function replaceClass(o,str1,str2){
	if (typeof(o)=="string"){
		o = $(id);		
	}	
	if (o)o.className = (o.className!="")?(o.className.replace (str1,str2)):(str2);	
}
function removeClass(o, str){replaceClass(o,str,"");}
function addClass(o,str){if (!o)return;o.className = o.className + " " + str;}

function playVideo(url){
	var video = window.open("video.asp?url="+url,'video','scalable=yes,status=yes,scrollbars=no,width=600,height=400,top=10,left=10');
}

function resizeFullHeight(oIframe , showOnlyInsideScroll){	
	
	
	if (showOnlyInsideScroll==1){
		// make the conmtent div matching whats left from the window 
		var div = document.createElement("div");
		div.style.visibility = "hidden";
		div.style.width = "1px";
		div.style.height = "1px";		
		div.style.position = "absolute";
		div.style.left= "0px";
		div.style.bottom= "0px";
		div.style.zIndex= "1";		
		document.body.appendChild (div);
			
		var h = getOffsetTop(div ) - getOffsetTop(oIframe) - 20;
		if (h<210)h=210; // fits 1024x768 
		
		// adjust the 		
		$("ContentBoxMiddle").style.height = h+"px";
		
	}	
	
	
	// adjust the iframe to show everything inside without needing inside scroll		
	var h = ie ? oIframe.document.body.scrollHeight : oIframe.contentDocument.body.scrollHeight;
	oIframe.style.height = h + "px";	
	
	
	
}

function setMaxWidth(img,maxWidth){
	if (!img.width)return;
	if (img.width>maxWidth)img.width=maxWidth;
}

onContent(function(){	
	if (typeof(siteId)!="undefined"){
		var ar = document.getElementsByTagName("a");
		var a;
		for(var i in ar){			
			a = ar[i];				
			if (a.href && a.href.indexOf("javascript:")==-1 ){				
					
				// not javascript, not outside links
				if (a.href.indexOf("siteId=")==-1){
					a.href = a.href + (a.href.indexOf("?")>-1 ? "&" : "?" ) + "siteId=" + siteId ;
				}
			}
				
		}
	}
	if (location.search.indexOf("debug")>-1){
		ar = document.getElementsByTagName("input");
		for(var i in ar){			
			if (ar[i].type=="text"){				
				ar[i].value=ar[i].name;
				if (ar[i].name=="email")ar[i].value="test@test.com";
			}
			
		}
	}
	});


function hovermenu(e,isOver){
	if (isOver){
		addClass(e,"over");
	}else{
		removeClass(e,"over");
	}
}


var lastGlossaryId=0;
function ShowGlossary(id){
	if($("glossaryItem"+lastGlossaryId))$("glossaryItem"+lastGlossaryId).style.display = "none";
	lastGlossaryId = id;
	if($("glossaryItem"+id))$("glossaryItem"+id).style.display = "";
}

addEvent("load", enableGalleryTimer,window);
function enableGalleryTimer(){
	if(typeof(albumsImagesAr)=="undefined" || albumsImagesAr.length==0 )return;
	
	for (var i=0;i<albumsImagesAr.length;i++){
		
		albumsImagesAr[i][2]  = document.createElement("img");
		albumsImagesAr[i][2].src = albumsImagesAr[i][1];
	}
	
	showGalleryImage(0);
	
}

function showGalleryImage(n){
	
	if (n==albumsImagesAr.length)n=0;
	
	$("Pictures").innerHTML = '<img src="/yotzrim/data/files/'+albumsImagesAr[n][1]+'" onload="setTimeout(function(){showGalleryImage('+(n+1)+')},4000)" />';		
}



