﻿function writeHTML(html)
{
	document.write(html);
}


	var openMyModal = function(pic,text)
	{
		modalWindow.windowId = "myModal";
		
		modalWindow.width = document.body.offsetWidth;
		modalWindow.height = 600;

		//modalWindow.left=(document.body.offsetWidth/2 - modalWindow.width/2);
modalWindow.left=(document.body.offsetWidth/2);
		modalWindow.top=10;
		modalWindow.content = "<table border=0 cellpadding=3 bgcolor=#005435><tr><td><a  class=\"close-window\"></a><img align=bottom src='"+pic+"'></td></tr><tr><td style='color:white'>"+text+"</td></tr></table>";
		modalWindow.open();
		
	
	};




	var openVideo = function(swf)
	{
		modalWindow.windowId = "myModal";
		
		modalWindow.width = document.body.offsetWidth;
		modalWindow.height = 600;

		modalWindow.left=(document.body.offsetWidth/2 );
		modalWindow.top=10;
		modalWindow.content = "<table border=0 cellpadding=3 bgcolor=black><tr><td><a  class=\"close-window\"></a><OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0  classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 VIEWASTEXT><PARAM NAME=\"_cx\" VALUE=\"13203\"><PARAM NAME=\"_cy\" VALUE=\"6403\"><PARAM NAME='Movie' VALUE='"+swf+"'><PARAM NAME='Src' VALUE='"+swf+"'><PARAM NAME='WMode' VALUE='Opaque'><PARAM NAME='Play' VALUE='-1'><PARAM NAME='Loop' VALUE='-1'>"+                                      
		"<embed src='"+'"+swf+"'+"'  autoplay='false' border='0' autoplay='true'></embed></OBJECT></td></tr></table>"
		modalWindow.open();

	
	
	};

	var openMyEmbed = function(res)
	{
		modalWindow.windowId = "myModal";
		
		modalWindow.width = document.body.offsetWidth;
		modalWindow.height = 600;

		modalWindow.left=(document.body.offsetWidth/2);
		modalWindow.top=10;
		modalWindow.content = "<table border=0 cellpadding=2 bgcolor=#005435><tr><td align=right  style=\"width:34px;height:34px;\" valign=top><a style=\"position:relative;float:left\" class=\"close-window\"></a></td><td >"+res+"</td></tr></table>";
		modalWindow.open();
		
	
	};
function searchResult(albumID)
{
	document.location.href="?albumID="+albumID+"&q="+document.getElementById("srch").value
}
function replaceObject(item, place, picObj,isEmbed)
{
var curentPlace = document.getElementById(place);
var pic = document.getElementById(picObj);
pic.style.display='none';
if(isEmbed=="1")
{
	curentPlace.innerHTML=item;

}
else
{
	curentPlace.innerHTML="<OBJECT style=\"WIDTH: 337px; HEIGHT: 253px\" codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0  classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 VIEWASTEXT><PARAM NAME=\"_cx\" VALUE=\"13203\"><PARAM NAME=\"_cy\" VALUE=\"6403\"><PARAM NAME='Movie' VALUE='"+item+"'><PARAM NAME='Src' VALUE='"+item+"'><PARAM NAME='WMode' VALUE='Opaque'><PARAM NAME='Play' VALUE='-1'><PARAM NAME='Loop' VALUE='-1'><embed width='250' src='"+'"+item+"'+"'  autoplay='false' border='0' autoplay='true'></embed></OBJECT>"
}
}
function getProjects()
{
	document.location.href="?q="+escape(document.getElementById("srch").value)+"&Year="+document.getElementById("Year").value+"&Organisation="+document.getElementById("Organisation").value+"&Theme="+document.getElementById("Theme").value;
}
function getPublications()
{
	document.location.href="?q="+escape(document.getElementById("srch").value)+"&Year="+document.getElementById("Year").value+"&Department=-1";
}
function getCalendarByYear()
{
	document.location.href="?Year="+document.getElementById("Year").value;

}


function viewPicture(pic)
{
	document.location.href="http://yvc.ac.il/picture/?pic="+pic
}
function goBack()
{
history.go(-1);
}

function showSubMenu(parent, id)
{
	menuItemHide = false;
	if (menuItemCurrent && menuItemCurrent.id == "menuitem" + id)
		return;
	if (menuItemCurrent)
	{
		if (menuItemCurrent.filters && menuItemCurrent.filters.length)
			menuItemCurrent.filters[0].apply();
		menuItemCurrent.style.visibility = "hidden";
		if (menuItemCurrent.filters && menuItemCurrent.filters.length)
			menuItemCurrent.filters[0].play();
	}
	var item = document.getElementById("menuitem" + id);
	if (!item) return;
	var isRtl = document.body.style.direction == "rtl";
	item.style.top = _offsetTop(parent) - 1;
	item.style.left = _offsetLeft(parent) - (isRtl ? item.offsetWidth - 30 : -parent.offsetWidth + 30);
	if (item.filters && item.filters.length)
		item.filters[0].apply();
	item.style.visibility = "visible";
	if (item.filters && item.filters.length)
		item.filters[0].play();
	menuItemCurrent = item;
}
function hideSubMenu()
{
	if (!menuItemHide || !menuItemCurrent)
		return;
	if (menuItemCurrent.filters && menuItemCurrent.filters.length)
		menuItemCurrent.filters[0].apply();
	menuItemCurrent.style.visibility = "hidden";
	if (menuItemCurrent.filters && menuItemCurrent.filters.length)
		menuItemCurrent.filters[0].play();
	menuItemCurrent = null;
	menuItemHide = false;
}
var menuItemCurrent = null;
var menuItemHide = false;
var globalEvent;

function _offsetTop(obj)
{
	var top = 0;
	for (; obj; obj=obj.offsetParent)
		top += obj.offsetTop;
	return top;
}

function _offsetLeft(obj)
{
	var left = 0;
	for (; obj && obj != document.body; obj=obj.offsetParent)
		left += obj.offsetLeft;
	return left;
}

// returns true if node a contains event.toElement/relatedTarget.
function containsToElement(a)
{
	var b = globalEvent.toElement ? globalEvent.toElement : globalEvent.relatedTarget;
	if (!b) return false;
	while (b.parentNode)
		if ((b = b.parentNode) == a)
			return true;
	return false;
}

/*
	Validate a form's elements according to varius attributes
*/
function validateForm(form, elements, title)
{
	var message = "";
	for (var i = 0; i < elements.length; i++)
	{
		input = form.elements[elements[i]];
		// skip input when it's not rendered (ie. parent display:none)
		if (input.offsetHeight == 0) continue;
		valid = true;
		// Validate value according to element type and validation pattern
		switch (input.type)
		{
			case "text":
			case "password":
			case "textarea":
			case "file":
				if (input.getAttribute("mandatory"))
					if (input.value.length == 0)
						valid = false;
				if (input.value.length && input.getAttribute("pattern"))
				{
					var regExp = new RegExp();
					regExp.pattern = input.getAttribute("pattern");
					valid = regExp.test(input.value);
				}
				break;
			case "select-one":
			case "select-multiple":
				if (input.getAttribute("mandatory"))
					if (input.selectedIndex == 0)
						valid = false;
				break;
			case undefined:
				switch (input[0].type)
				{
					case "radio":
						if (input[0].getAttribute("mandatory"))
						{
							valid = false;
							for (var j = 0; j < input.length; j++)
								if (input[j].checked)
								{
									valid = true;
									break;
								}
						}
						input = input[0];
						break;
				}
				break;
		}
		if (!valid)
		{
			if (input.getAttribute("validationError"))
				message += input.getAttribute("validationError") + "\n";
			else
				message += "Error in field: " + input.name + "\n";
		}
	}
	if (message.length)
	{
		alert((title ? title + "\n" : "") + message);
		return false;
	}
	return false;
}
function toggleDisplay(el)
{
	var style = el.currentStyle ? el.currentStyle : getComputedStyle(el, null);
	if (style.display == "none")
		el.style.display = "block";
	else
		el.style.display = "none";
}