var currTopTab = "home";
var currCenter = "";

var oConfirmMsg = null;
var oErrorMsg	= null;

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* selectTopTab																													*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function selectTopTab (whichTab, isParticipantPage)
{
	if (isParticipantPage == undefined) isParticipantPage = false;

	if (!isParticipantPage)
	{
		try {document.getElementById("updateEventDetails").style.display = "none";} catch (e) {}
		try {document.getElementById("canNotInvitePage").style.display   = "none";} catch (e) {}
		try {document.getElementById("tasksPage").style.display   		 = "none";} catch (e) {}
		try {document.getElementById("surveysPage").style.display   	 = "none";} catch (e) {}
	}

	if (currCenter != "")
	{
		document.getElementById(currCenter + "Page").style.display 			 = "none";

		currCenter = "";
	}

	if (currTopTab != "")
	{
		// cancel prev tab
		var className = document.getElementById(currTopTab + "TTab").className;
		document.getElementById(currTopTab + "TTab").className = className.substr(0,className.length-8);

		document.getElementById(currTopTab + "Page").style.display 		 = "none";

		if (!isParticipantPage)
			showHideRightTabs (currTopTab, "none");
	}

	// set curr tab
	currTopTab = whichTab;
	document.getElementById(currTopTab + "TTab").className += "Selected";

	document.getElementById(currTopTab + "Page").style.display 		 = "";

	if (!isParticipantPage)
		showHideRightTabs (currTopTab, "");

	if (!isParticipantPage)
	{
		document.getElementById("theNewEventMsgs").style.display	= "none";
		document.getElementById("theEventMsgs").style.display		= "";
		document.getElementById("homePage").className				= "homePageEvent"

		// handle left 
		if (whichTab == "participants")
		{
			document.getElementById("eventTalkbacks").style.display = "none";
			document.getElementById("myFriends").style.display 		= "";
		}
		else
		{
			document.getElementById("eventTalkbacks").style.display = "";
			document.getElementById("myFriends").style.display 		= "none";
		}
	}
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* changePageCenter																												*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function changePageCenter (to)
{
	try {document.getElementById("updateEventDetails").style.display = "none";} catch (e) {}
	try {document.getElementById("canNotInvitePage").style.display   = "none";} catch (e) {}

	if (currCenter != to)
	{
		if (currCenter != "")
			document.getElementById(currCenter + "Page").style.display	 = "none";

		if (document.getElementById(to + "Page") != undefined)
		{
			document.getElementById(currTopTab + "Page").style.display 	 = "none";
			document.getElementById(to + "Page").style.display 			 = "";
		}

		currCenter = to;
	}
}

var currAddition = "";

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* showHideRightTabs																											*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function showHideRightTabs (which, display)
{
	switch (which)
	{
		case "home"	:
		case "participants"	:
		case "tasks"		:
			document.getElementById("participantsPage_right").style.display = display;
			break;

		case "items" :
			document.getElementById("itemsPage_right").style.display 		= display;
			break;

		case "vehicles" :
			document.getElementById("vehiclesPage_right").style.display 	= display;
			break;

		case "map"	:
		case "album" :

			if (currAddition != "")
			{
				document.getElementById("additionsRight_" + currAddition).className = "additionRightOption";
				document.getElementById("additionsRightImg_" + currAddition).src	= "loadedFiles/addition_arrow.gif";
			}

			currAddition = which;

			document.getElementById("additionsRight_" + currAddition).className = "additionRightOption_selected";
			document.getElementById("additionsRightImg_" + currAddition).src	= "loadedFiles/addition_arrow_selected.gif";

			document.getElementById("additionsPage_right").style.display 	= display;
			break;
	}
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* editBorder																													*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function editBorder (obj)
{
	if (obj.currentStyle)	// IE
	{
		var theColor	= obj.currentStyle['borderColor'];
	}
	else if (window.getComputedStyle)	// Mozilla | Firefox
	{
//		var theColor 	= document.defaultView.getComputedStyle(obj,null).getPropertyValue("color");
		var theColor = "#FFFFFF";
	}

	obj.style.cursor	= "pointer";

	obj.style.save		= theColor;

	if (theColor == "white")
		theColor = "#FFFFFF";

	var objColor 			= new Color(theColor);
	obj.style.borderColor 	= objColor.darken(100).getHex();
}


/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* removeEditBorder																												*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function removeEditBorder (obj)
{
	try
	{
		if (obj.currentStyle)	// IE
		{
			var theColor	= obj.style.save;
		}
		else if (window.getComputedStyle)	// Mozilla | Firefox
		{
			var theColor 	= document.defaultView.getComputedStyle(obj,null).getPropertyValue("save");
		}

		obj.style.borderColor = theColor;
	}
	catch (e)
	{
	}
}

// ----------------------------------------------------------------------------------------------------------------------------

var currEdit = {name		: "",	
				mandatory	: false,
				type		: "text"}

var letterWidth = 7;

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* edit																															*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function edit (name, mandatory, type)
{
	stopEdit (false);

	if (currEdit.name != name)
	{
		currEdit.name = name;

		if (mandatory != undefined)
			currEdit.mandatory = mandatory;

		if (type != undefined)
			currEdit.type = type;

		var oDiv 	= document.getElementById(currEdit.name);
		var oInput 	= document.getElementById(currEdit.name + "Input");
		var oBtns 	= document.getElementById(currEdit.name + "Buttons");
	
		oDiv.style.display = "none";

		btnsTop	  = 0;
		addToTop  = 1;
		addToLeft = 0;
		if (oInput.tagName == "SELECT")
		{
			var oHidden		= document.getElementById(currEdit.name + "Hidden");

			oInput.value 	= oHidden.innerHTML;

			addToTop		= 6;
		}
		else if (oInput.tagName == "TEXTAREA")
		{
			var oHidden		= document.getElementById(currEdit.name + "Hidden");

			if (oHidden != undefined)
			{
				// this is the full value (not cut)
				content = oHidden.value;
			}
			else
			{
				content = oDiv.innerHTML;
			}

			content 		= content.replace(/<BR>/g, "\n");

			content 		= content.replace(/<br>/g, "\n");
			content 		= content.replace(/\n\n/g, "\n");
			content			= content.replace(/^\s+|\s+$/g,"");
			oInput.value 	= content;

			if (name.indexOf("eventMsgs_msg") != -1)
			{
				btnsTop 	= 35;
			}
		}
		else
		{
			var content		= oDiv.innerHTML;
			var oHidden		= document.getElementById(currEdit.name + "Hidden");

			if (oHidden != undefined)
			{
				// this is the full value (not cut)
				content = oHidden.value;
			}

			content 			= content.replace(/^\s+|\s+$/g,"");
			content 			= content.replace(/&nbsp;/g,"");
			oInput.value 		= content;

			oInput.style.width 	= getWidth (content);
		}

		if (btnsTop == 0)
		{
			if (oInput.currentStyle)	// IE
				btnsTop = oInput.currentStyle["height"];
			else
				btnsTop = document.defaultView.getComputedStyle(oInput,null).getPropertyValue("height");
		}

		if (btnsTop == "auto")
			btnsTop = 0;

		if (oBtns != undefined)
		{
			oBtns.style.top  = parseInt(btnsTop)+addToTop;
			oBtns.style.left = 3 + addToLeft;
		}

		// check if content is empty content (for adding)
		try
		{
			emptyMsg = eval(name + "_empty");

			if (oInput.value == emptyMsg)
				oInput.value = "";
		}
		catch (e)
		{
			// doing noting - empty variable does not exist
		}

		oInput.style.display = "";

		if (oBtns != undefined)
			oBtns.style.display  = "";

		oInput.focus();
	}
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* editCalendarDate																												*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function editCalendarDate (name, mandatory)
{
	stopEdit (true);

	if (currEdit.name != name)
	{
		currEdit.name = name;
		currEdit.type = "calendar";

		if (mandatory != undefined)
			currEdit.mandatory = mandatory;
	}
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* stopEditCalendarDate																											*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function stopEditCalendarDate (toUpdate)
{
	if (currEdit.name != "" && currEdit.type == "calendar")
	{
		if (toUpdate)
		{
			update (currEdit.name, document.getElementById(currEdit.name).innerHTML);

			currEdit.name 	= "";
			currEdit.type	= "";
		}
	}
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* stopEdit																														*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function stopEdit (toUpdate)
{
	if (currEdit.name != "" && currEdit.type == "calendar")
	{
		stopEditCalendarDate (toUpdate);
	}

	if (currEdit.name != "" && currEdit.type == "browse")
	{
		eval (currEdit.name + ".close()");
		currEdit.name = "";
		currEdit.type = "";
	}

	if (currEdit.name != "" && currEdit.type == "talkback")
	{
		document.getElementById(currEdit.name).style.display = "none";
		currEdit.name = "";
		currEdit.type = "";
	}

	if (currEdit.name != "")
	{
		var oDiv 	= document.getElementById(currEdit.name);
		var oInput 	= document.getElementById(currEdit.name + "Input");

		if (toUpdate)
		{
			var valid = true;

			if (currEdit.type == "time")
			{
				// check validate
				value = oInput.value;

				if (value != "")
					valid = checkTime (value);
			}

			if (currEdit.type == "digitsPositive")
			{
				value = oInput.value;

				value = value.replace( /^0+/g, "" );

				if (value == 0)
				{
					valid = false;
				}
			}

			if ((!currEdit.mandatory || (currEdit.mandatory && oInput.value != "")) && valid)
			{
				// special updated
				switch (currEdit.name)
				{
					case "event_name" :
						oDiv.innerHTML		 = oInput.value;

						var shortValue = oInput.value.substring(0,25)
						if (shortValue != oInput.value)
							shortValue += "...";

						document.getElementById("title_eventName").innerHTML = shortValue;
						break;
	
					case "event_owner" :
						oDiv.innerHTML		 = oInput.value;

						var shortValue = oInput.value.substring(0,5)
						if (shortValue != oInput.value)
							shortValue += "...";

						document.getElementById("title_owner").innerHTML = shortValue;
						break;

					case "event_cityId"	:
						oDiv.innerHTML		 = oInput.value;
						value = oInput.value.split("_");
						selected = oInput.options[oInput.selectedIndex];
						switch (selected.id)
						{
							case "north"	: area = "צפון";	break;
							case "center"	: area = "מרכז";	break;
							case "south"	: area = "דרום";	break;
							default			: area = "";		break;
						}

						if (area == "")
							oDiv.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
						else
							oDiv.innerHTML = area + "&nbsp;&nbsp;<img src='loadedFiles/graySepNoBg.png' /> " + selected.text;
						
						document.getElementById(currEdit.name + "Hidden").innerHTML = selected.value;
						break;

					case "event_address"					:
						if (oInput.value == "")
							oDiv.innerHTML  = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
						else
							oDiv.innerHTML	= oInput.value;
						break;

					case "participant_additionalNo" :
					case "vehicle_vehicleNumSits"	:

						if (currEdit.name == "vehicle_vehicleNumSits")
							oInput.value = oInput.value.replace( /^0+/g, "" );

						doSafeUpdate (currEdit.name, oInput.value);
						return;

					case "participant_additionalDescription" :
						oDiv.innerHTML		 = oInput.value;
						pId = document.getElementById("participantId").innerHTML;
						document.getElementById("participant" + pId + "_name").title = oDiv.innerHTML;

						break;

					case "vehicle_vehicleExitFromCity" 		:
					case "vehicle_vehicleReturnFromCity" 	:
					case "participant_gender" 				:
					case "participant_showPic" 				:
					case "participant_showDescription"		:
					case "participant_showBirthDateGender"	:
					case "participant_showAddressPhones"	:
					case "participant_showContactDetails"	:
					case "participant_showSiteUrl"			:
						oDiv.innerHTML		 = oInput.value;
						selected = oInput.options[oInput.selectedIndex];
						oDiv.innerHTML = selected.text;
						
						document.getElementById(currEdit.name + "Hidden").innerHTML = selected.value;
						break;
						
					case "participant_nickname" :
						oDiv.innerHTML		 = oInput.value;

						if (oDiv.innerHTML == "")
						{
							document.getElementById("talkbacksFormName").value = document.getElementById("profile_myName").innerHTML;
						}
						else
						{
							document.getElementById("talkbacksFormName").value = oDiv.innerHTML;
						}
						
					case "participant_name" :
						try
						{
							document.getElementById("participant_top_name").innerHTML = oInput.value
							document.getElementById("helloMember").innerHTML = "שלום " +  oInput.value + ",";
						}
						catch (e)
						{
						}
						oDiv.innerHTML		 = oInput.value;
						break;

					case "event_mapUrl" :
					case "event_albumUrl" :

						if (currEdit.name == "event_mapUrl")
							var link = "mapLink";
						else
							var link = "albumLink";

						if (oInput.value == "")
						{
							document.getElementById(link).style.display = "none";
							oDiv.innerHTML = oInput.value;
						}
						else
						{
							oInput.value = validUrl(oInput.value);

							var oHidden		= document.getElementById(currEdit.name + "Hidden");
							var shortValue = oInput.value.substring(0,oHidden.maxLength)
							if (shortValue != oInput.value)
								shortValue += "...";
	
							oDiv.innerHTML = shortValue;

							oHidden.value = oInput.value;

							document.getElementById(link).style.display = "";
							document.getElementById(link + "_a").href   = oInput.value;
						}

						break;

					default :
						var oHidden		= document.getElementById(currEdit.name + "Hidden");
						if (oHidden != undefined)
						{
							var shortValue = oInput.value.substring(0,oHidden.maxLength)
							if (shortValue != oInput.value)
								shortValue += "...";

							oDiv.innerHTML = shortValue;
						}
						else
						{
							oDiv.innerHTML = oInput.value;
						}
						break;
				}

				if (oInput.tagName == "TEXTAREA" && currEdit.name != "event_mapUrl" && currEdit.name != "event_albumUrl")
				{
					oDiv.innerHTML 		 = oInput.value.replace(/\n/g, "<BR>");
				}
	
				update (currEdit.name, oInput.value);
			}
		}

		// check if content is empty content (for adding)
		if (!toUpdate || oInput.value == "")
		{
			try
			{
				emptyMsg = eval(name + "_empty");
	
				oDiv.innerHTML.value = emptyMsg;
			}
			catch (e)
			{
				// doing noting - empty variable does not exist
			}
		}

		oInput.style.display = "none";
		document.getElementById(currEdit.name + "Buttons").style.display = "none";

		oDiv.style.display   = "";

		currEdit.name 		 = "";
		currEdit.type	 	 = "";
	}
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* onlineEnter																													*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function onlineEnter (e)
{ 
	var characterCode;

	if (e && e.which)
	{ 
		//if which property of event object is supported (NN4)
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else
	{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}

	if (characterCode == 8 || characterCode == 46 || characterCode == 12)	// Backspace | Del
		return true;

	var oDiv 	= document.getElementById(currEdit.name);
	var oInput 	= document.getElementById(currEdit.name + "Input");

	if (characterCode == 13 && oInput.type != "textarea")	// Enter
	{ 
		stopEdit (true);
	}
	else if (characterCode == 27)	// ESC
	{
		stopEdit (false);
	}
	else
	{
		if (oInput.type == "textarea" && oInput.maxLength != undefined)
		{
			var maxLen = oInput.maxLength;

			return (oInput.innerHTML.length < maxLen);
		}
		else
		{
			var keychar;
			var check;

			keychar = String.fromCharCode(characterCode)
	
			if (currEdit.type == "digits" || currEdit.type == "digitsPositive")
			{
				check = /\d/
				if (!check.test(keychar))
					return false;
			}

			if (currEdit.type == "time")
			{
				check = /[0-9:]/	
				if (!check.test(keychar) && keychar)
					return false;
			}

			// check prev len
			var prevLen = oDiv.innerHTML.length;
			var newLen  = oInput.value.length;
	
			if (newLen > 4)
			{
				// set input field width
				oInput.style.width = getWidth (oInput.value, oInput.maxLength);
			}
		}
	}

	return true;
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* onlyDigits																													*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function onlyDigits (e)
{
	var characterCode;

	if (e && e.which)
	{ 
		//if which property of event object is supported (NN4)
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else
	{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}

	if (characterCode == 8 || characterCode == 46 || characterCode == 12)	// Backspace | Del
		return true;

	var keychar;
	var check;

	keychar = String.fromCharCode(characterCode)
	
	check = /\d/
	return check.test(keychar);
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* checkMaxLen																													*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function checkMaxLen (oTextarea)
{
	if (oTextarea.type != "textarea") return true;

	if (oTextarea.maxLength != undefined)
	{
		var maxLen = oTextarea.maxLength;

		return (oTextarea.innerHTML.length < maxLen);
	}

	return true;
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* widthFix																														*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function getWidth (value, maxLength)
{
	if (value.length == 0)
		return 35;	// min length for the edit buttons under the input field

	width = (value.length*letterWidth) + 2;

	width -= (("#"+value+"#").split("י").length-1) * 4;		// 3 pixels
	width -= (("#"+value+"#").split("ו").length-1) * 4;		// 3 pixels
	width -= (("#"+value+"#").split("ן").length-1) * 4;		// 3 pixels
	width -= (("#"+value+"#").split(" ").length-1) * 3;		// 4 pixels
	width += (("#"+value+"#").split("ש").length-1) * 1;		// 8 pixels
	width += (("#"+value+"#").split("ת").length-1) * 1;		// 8 pixels
	width += (("#"+value+"#").split("2").length-1) * 2;		// 9 pixels

	if (maxLength != undefined && width > maxLength*8)
		return maxLength*8;

	if (width < 35)
		return 35;

	return width;
}


var xmlRequest = new xmlObj(false);

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* doSafeUpdate																													*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function doSafeUpdate (name, value)
{
	update (name, value)
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* update																														*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function update (name, value, afterConfirm)
{
	if (afterConfirm == undefined || afterConfirm == false)
		afterConfirm = 0;
	else
		afterConfirm = 1;

	var nameArray = name.split("_");

	fieldName = nameArray[1].replace(/_+$/g, "");

	addToXml = "";
	if (nameArray[0] == "vehicle")
		addToXml = "<currVehicle>" + document.getElementById("currVehicle").innerHTML + "</currVehicle>";

	var observer = "0";
	if (document.getElementById("observer") != undefined)
		observer = document.getElementById("observer").innerHTML;

	var xml  = 	"<request>" +
					"<command>private.doAction</command>" +
					"<action>update</action>" +
					"<object>"     		+ nameArray[0] 											+ "</object>" 			+
					"<afterConfirm>"	+ afterConfirm											+ "</afterConfirm>"		+
					"<eventId>"    		+ document.getElementById("eventId").innerHTML 			+ "</eventId>" 			+
					"<participantId>"   + document.getElementById("participantId").innerHTML 	+ "</participantId>" 	+
					"<observer>"   		+ observer	 											+ "</observer>" 		+
					"<fieldName>"  		+ fieldName 											+ "</fieldName>" 		+
					"<fieldValue>" 		+ value 												+ "</fieldValue>" 		+
					addToXml			+
				"</request>";

	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "update_response");

	//08 So you won't get the blink for your own update
	globalEventCounter++;

	return false;
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* update_response																												*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function update_response (i)
{
	var xmlResponse = new xmlObj(false);
	xmlResponse.init(commonDecode(asyncHttpObjs[i].responseText));

	try	
	{
		eventBlink_checkAfterUpdate (xmlResponse);
	}
	catch (e)
	{
		// doing nothing - we are not in the event page
	}

	safeUpdate   = xmlResponse.getValue("safeUpdate");				// 1 - check the confirm/error msg  0|empty - no need to confirm or check error msg
	if (safeUpdate == "1")
	{
		confirmMsg	    = xmlResponse.getValue("confirmMsg");		// if confirmMsg is not empty => we do online update only with confirm 
		errorMsg   		= xmlResponse.getValue("errorMsg");			// if errorMsg is not empty   => update failed - show error msg
	
		if (errorMsg != "")
		{
			if (errorMsg == "no-error")
				updateWhenNoError ();
			else
				showErrorMsg (errorMsg, "eventCenter");	
		}
		else
		{
			if (confirmMsg != "")
				showConfirmMsg (confirmMsg, "eventCenter");
			else
				updateAfterSafe ();
		
			return;
		}

	}

	refreshObjects = xmlResponse.getValue("refreshObjects").replace(/^\s+|\s+$/g,"");

	if (refreshObjects != "")
	{
		refreshObjects = refreshObjects.split(" ");

		for (var i=0; i < refreshObjects.length; i++)
		{
			toRefresh   = refreshObjects[i].split(".");

			obj			= toRefresh[0];
			fieldName	= "";

			if (obj.replace(/^\s+|\s+$/g,"") == "") continue;

			var sortBy  = "";
			var sortDir = "";

			if (toRefresh.length == 2)
			{
				fieldName = toRefresh[1];
			
				try
				{
					sortBy  = eval(fieldName + "_sortBy");
					sortDir = eval(fieldName + "_sortDir");
				}
				catch (e)
				{
					// doing nothing ...
					// the sort variables does not declared for this fieldName and it's OK
				}
			}		

			var addToXml = "";

			switch (obj)
			{
				case "item" :
					addToXml= "<item_selectedParticipant>" + document.getElementById("participantByItems_select").value + "</item_selectedParticipant>"+
							  "<item_selectedItem>" + document.getElementById("items_select").value + "</item_selectedItem>";
					break;

				case "vehicle" :
					addToXml   += "<currVehicle>" + document.getElementById("currVehicle").innerHTML + "</currVehicle>";
					break;
			}

			switch (fieldName)
			{
				case "itemsTree" :
					addToXml   += "<openItems>" + openItems.join(" ") + "</openItems>";
					break;

				case "itemParticipantsTree" :
					addToXml   += "<openItems>" + openItemParticipants.join(" ") + "</openItems>";
					break;
			
				case "eventVehicles" :
					addToXml   += "<openVehicles>" + openVehicles.join(" ") + "</openVehicles>";
					break;

				case "profile" :
					addToXml  += "<profileParticipant>" + document.getElementById("profile_participantId").innerHTML + "</profileParticipant>";
					break;

				case "myMsgs" :
					addToXml   += "<openMsgs>" + openMsgs.join(" ") + "</openMsgs>";
					break;
			}

			var observer = "0";
			if (document.getElementById("observer") != undefined)
				observer = document.getElementById("observer").innerHTML;

			xml  = 	"<request>" +
						"<command>private.doAction</command>" +
						"<action>get</action>" +
						"<object>"  		+ obj 													+ "</object>"			+
						"<eventId>"   		+ document.getElementById("eventId").innerHTML 			+ "</eventId>" 			+
						"<participantId>"   + document.getElementById("participantId").innerHTML 	+ "</participantId>" 	+
						"<observer>"   		+ observer										 		+ "</observer>" 		+
						"<fieldName>" 		+ fieldName 											+ "</fieldName>" 		+
						"<sortBy>" 			+ sortBy 												+ "</sortBy>" 			+
						"<sortDir>" 		+ sortDir 												+ "</sortDir>" 			+
						addToXml 			+
					"</request>";
	
			if (fieldName != "") 
				fieldName += "_";

			xmlRequest.init (xml);
			xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, obj + "_" + fieldName + "get_response");
		}
	}
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* showInfoMsg																													*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function showInfoMsg (infoMsg, parentName, x, y, fieldName)
{
	showErrorMsg (infoMsg, parentName, x, y, fieldName);
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* showErrorMsg																													*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function showErrorMsg (errorMsg, parentName, x, y, fieldName)
{
	if (parentName == undefined || parentName == "")
	{
		parentName = "eventCenter";

		if (document.getElementById(parentName) == undefined)
			parentName = "msgsPage";

		if (document.getElementById(parentName) == undefined || document.getElementById(parentName).style.display == "none")
			parentName = "participantPageCenter";
	}

	if (x == undefined || x == "" || x == 0)
		x = 100;

	if (y == undefined || y == "" || y == 0)
		y = 64;

	var html =  "<div id='errorMsg_window'>" +
					"<div id='errorMsg_inWindow'>" +
						"<table cellpadding='0' cellspacing='0' border='0' id='msgTable'>" + 
						"<tr>" + 
							"<td valign='middle' align='center'>" +
								"<div class='errorMsg'>" + errorMsg + "</div>" + 
								"<div id='confirm_btn' onclick='closeErrorMsg()'></div>" +
							"</td>" +
						"</tr>" + 
						"</table>" + 
					"</div>" +
			   "</div>";

	if (oErrorMsg == null)
	{
		oErrorMsg = new floatWindow ();
	}
	oErrorMsg.create (parentName, "fw_errorMsg", html, x, y, fieldName);
	oErrorMsg.show   ();
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* showWaitMsg																													*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function showWaitMsg (msg, parentName, x, y)
{
	var html =  "<div id='errorMsg_window'>" +
					"<div id='errorMsg_inWindow'>" +
						"<table cellpadding='0' cellspacing='0' border='0' id='msgTable'>" + 
						"<tr>" + 
							"<td>" +
								"<div class='errorMsg'>" + msg + "</div>" + 
							"</td>" +
						"</tr>" + 
						"</table>" + 
					"</div>" +
			   "</div>";

	if (oErrorMsg == null)
	{
		oErrorMsg = new floatWindow ();
	}
	oErrorMsg.create (parentName, "fw_waitMsg", html, x, y);
	oErrorMsg.show   ();
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* closeErrorMsg																												*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function closeErrorMsg ()
{
	oErrorMsg.close();

	if (currEdit.name != "")
	{
		document.getElementById(currEdit.name + "Input").focus();
	}
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* showConfirmMsg																												*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function showConfirmMsg (confirmMsg)
{
	var html =  "<div id='confirmMsg_window'>" +
					"<div id='confirmMsg_inWindow'>" +
						"<table cellpadding='0' cellspacing='0' border='0' id='msgTable'>" + 
						"<tr>" + 
							"<td>" +
								"<div class='confirmMsg'>" + confirmMsg + "</div>" + 
								"<div id='yes_btn' onclick='oConfirmMsg.close();updateAfterSafe();'></div>" +
								"<div id='no_btn'  onclick='oConfirmMsg.close();stopEdit();'></div>" +
							"</td>" +
						"</tr>" + 
						"</table>" + 
					"</div>" +
			   "</div>";

	if (oConfirmMsg == null)
	{
		oConfirmMsg = new floatWindow ();
	}
	oConfirmMsg.create ("eventCenter", "fw_confirmMsg", html, 100, 64);
	oConfirmMsg.show   ();
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* updateAfterSafe																												*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function updateAfterSafe ()
{
	var oDiv 	= document.getElementById(currEdit.name);
	var oInput 	= document.getElementById(currEdit.name + "Input");

	oDiv.innerHTML = oInput.value;

	// special updated
	switch (currEdit.name)
	{
		case "participant_additionalNo" :

			update (currEdit.name, oInput.value, true);				// do update only for confirm (not for ERRORs)

			oDiv.innerHTML = oDiv.innerHTML.replace( /^0+/g, "" );

			pId = document.getElementById("participantId").innerHTML;
			if (oDiv.innerHTML == "")
				document.getElementById("participant" + pId + "_additionalNo").innerHTML = "";
			else
				document.getElementById("participant" + pId + "_additionalNo").innerHTML = "+" + oDiv.innerHTML;
			break;
	}

	stopEdit (false);
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* updateWhenNoError																											*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function updateWhenNoError ()
{
	var oDiv 	= document.getElementById(currEdit.name);
	var oInput 	= document.getElementById(currEdit.name + "Input");

	oDiv.innerHTML = oInput.value;

	stopEdit (false);	// we already did the updates on the server
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* loadHtmlData																													*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function loadHtmlData (objName, httpIndex)
{
	var xmlResponse = new xmlObj(false);
	xmlResponse.init(commonDecode(asyncHttpObjs[httpIndex].responseText));

	try	
	{
		eventBlink_checkAfterUpdate (xmlResponse);
	}
	catch (e)
	{
		// doing nothing - we are not in the event page
	}

	htmlData = xmlResponse.getValue("htmlData");

	obj = document.getElementById(objName);

	switch (obj.tagName)
	{
		case "IMG"	: obj.src 		= htmlData;		break;
		case "SPAN"	: 
		case "DIV"	: obj.innerHTML	= htmlData;		break;
	}
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* sort																															*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function sort (obj, which, by)
{
	var sortBy  = eval(which + "_sortBy");
	var sortDir = eval(which + "_sortDir");

	if (sortBy == by)
	{
		if (sortDir == "desc")
			sortDir = "asc";
		else
			sortDir = "desc";
	}
	else
	{
		sortBy	= by;
		sortDir = "desc";
	}

	addToXml = "";

	// update global sortDir & sortBy
	switch (which)
	{
		case "eventParticipants"	:
			eventParticipants_sortBy  = sortBy;
			eventParticipants_sortDir = sortDir;
			break; 

		case "itemsTree" :
			itemsTree_sortBy	= sortBy;
			itemsTree_sortDir	= sortDir;

			addToXml = "<openItems>" + openItems.join(" ") + "</openItems>" + 
					   "<item_selectedParticipant>"	+ document.getElementById("participantByItems_select").value + "</item_selectedParticipant>";
			break;

		case "itemParticipantsTree" :
			itemParticipantsTree_sortBy		= sortBy;
			itemParticipantsTree_sortDir	= sortDir;

			addToXml = "<openItems>" + openItemParticipants.join(" ") + "</openItems>" +
					   "<item_selectedParticipant>"	+ document.getElementById("participantByItems_select").value + "</item_selectedParticipant>";
			break;

		case "myFriends" :
			myFriends_sortBy		= sortBy;
			myFriends_sortDir		= sortDir;

			break;

		case "myEvents" :
			myEvents_sortBy			= sortBy;
			myEvents_sortDir		= sortDir;

			break;
	}

	var observer = "0";
	if (document.getElementById("observer") != undefined)
		observer = document.getElementById("observer").innerHTML;

	xml  = 	"<request>" +
				"<command>private.doAction</command>" +
				"<action>get</action>" +
				"<object>"  		+ obj 													+ "</object>"			+
				"<eventId>"   		+ document.getElementById("eventId").innerHTML 			+ "</eventId>" 			+
				"<participantId>"   + document.getElementById("participantId").innerHTML 	+ "</participantId>" 	+
				"<observer>"   		+ observer										 		+ "</observer>" 		+
				"<fieldName>"		+ which													+ "</fieldName>"		+
				"<sortBy>"			+ sortBy												+ "</sortBy>"			+
				"<sortDir>"			+ sortDir												+ "</sortDir>"			+
				addToXml			+
			"</request>";
	
	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, obj + "_" + which + "_get_response");
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* participantFriends_myFriends_get_response																					*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function participantFriends_myFriends_get_response (i)
{
	loadHtmlData ("myFriends", i);
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* pgisha_getDomains																											*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function pgisha_getDomains (fieldName)
{
	var domains = "<div class='domains'>" +
					  "<img src='loadedFiles/domain_walla.jpg'   border='0' onclick='pgisha_onClickDomain	(\"walla\",\""   + fieldName + "\")' />" +
					  "<img src='loadedFiles/domain_yahoo.jpg' 	 border='0' onclick='pgisha_onClickDomain	(\"yahoo\",\""   + fieldName + "\")' />" +
					  "<img src='loadedFiles/domain_gmail.jpg' 	 border='0' onclick='pgisha_onClickDomain	(\"gmail\",\""   + fieldName + "\")' />" +
					  "<img src='loadedFiles/domain_hotmail.jpg' border='0' onclick='pgisha_onClickDomain	(\"hotmail\",\"" + fieldName + "\")' />" +
				  "</div>";

	return domains;
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* pgisha_onClickDomain																											*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function pgisha_onClickDomain (which, fieldName)
{
	oField = document.getElementById(fieldName);

	var domainName = "";
	switch (which)
	{
		case "walla"	: domainName = "walla.co.il";	break;
		case "yahoo"	: domainName = "yahoo.com";		break;
		case "gmail"	: domainName = "gmail.com";		break;
		case "hotmail"	: domainName = "hotmail.co.il";	break;
	}

	var newValue   = "";
	var splitValue = oField.value.split("@");

	if (splitValue.length == 1)
	{
		newValue = 	oField.value + "@" + domainName;
	}
	else
	{
		newValue = splitValue[0] + "@" + domainName;
	}

	oField.value = newValue;
}

Array.prototype.remove = function(s)
{
  	for (i=0;i<this .length;i++)
	{
    	if(s==this[i]) this.splice(i, 1);
	}
}

var oAddParticipantMsgWin = null;
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* openAddParticipantMsg																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function openAddParticipantMsg (toId, eventId)
{
	if (eventId == undefined)
		eventId = document.getElementById("eventId").innerHTML;

	parentName = "eventCenter";

	if (document.getElementById(parentName) == undefined)
		parentName = "msgsPage";
		
	stopEdit (true);

	if (oAddParticipantMsgWin == null)
	{
		img	= "<img src='loadedFiles/redSepNoBg.png' border='0' />";

		var html =  "<div id='addParticipantMsg_window'>" +
						"<div id='sendMsg_eventId'>" + eventId + "</div>" +
						"<div id='addParticipantMsg_inWindow'>" +
							"<table cellspacing='2' cellpadding='2' border='0'>" +
							"<tr>" + 
								"<td>" + col_addParticipantMsg_title + "&nbsp;" + img + "</td>" +
								"<td width='8px' rowspan='5'></td>" + 
								"<td><input id='addParticipantMsg_title' type='text' maxLength='200'></input>" + "</td>" +
							"</tr>" +
							"<tr height='6px'><td></td></tr>" +
							"<tr>" +
								"<td>" + col_addParticipantMsg_text + "&nbsp;" + img + "</td>" +
								"<td><textarea id='addParticipantMsg_text'></textarea>" + "</td>" +
							"</tr>" +
							"<tr height='12px'><td></td></tr>" +
							"<tr>" +
								"<td></td>" +
								"<td align='center'>" +
									"<img src='loadedFiles/close_btn.png' border='0' onclick='oAddParticipantMsgWin.close()' style='cursor:pointer'/>" +
									"&nbsp;&nbsp;" +
									"<img src='loadedFiles/send_btn.png' border='0' onclick='addParticipantMsg("+toId+")' style='cursor:pointer' />" +
								"</td>" +
							"</tr>" +
							"</table>" +
						"</div>" +
				   "</div>";

		oAddParticipantMsgWin = new floatWindow ();
		oAddParticipantMsgWin.create (parentName, "fw_addParticipantMsg", html, 123, 48);
	}

	document.getElementById("addParticipantMsg_title").value = "";
	document.getElementById("addParticipantMsg_text").value	 = "";


	oAddParticipantMsgWin.show ();

}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* addParticipantMsg																											*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function addParticipantMsg (toId)
{
	// validate
	// --------------------------------------------------------------
	// # msg title
	var oMsgTitle 	= document.getElementById("addParticipantMsg_title");
	if (oMsgTitle.value == "")
	{
		alert ("יש להזין " + col_addParticipantMsg_title + " למסר");
		oMsgTitle.focus ();
		return false;
	}
		
	oAddParticipantMsgWin.close ();

	var observer = "0";
	if (document.getElementById("observer") != undefined)
		observer = document.getElementById("observer").innerHTML;

	xml  = 	"<request>" +
				"<command>private.doAction</command>" +
				"<action>add</action>" 				  +
				"<object>participantMsgs</object>"	  +
				"<eventId>"   			+ document.getElementById("sendMsg_eventId").innerHTML 				+ "</eventId>" 		+
				"<fromId>" 			  	+ document.getElementById("participantId").innerHTML 				+ "</fromId>" 		+
				"<observer>"	   		+ observer										 					+ "</observer>" 	+
				"<toId>" 			  	+ toId																+ "</toId>" 		+
				"<msgTitle>" 			+ document.getElementById("addParticipantMsg_title").value		  	+ "</msgTitle>" 	+
				"<msgText>" 			+ document.getElementById("addParticipantMsg_text").innerHTML 	 	+ "</msgText>" 		+
			"</request>";
		
	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "addParticipantMsg_response");
	return false;
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* addParticipantMsg_response																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function addParticipantMsg_response (i)
{
	showInfoMsg (addParticipantMsg_success);
}

var oBrowseParticipantPic = null;
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* browseParticipantPic																											*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function browseParticipantPic ()
{
	parentName = "eventCenter";

	if (document.getElementById(parentName) == undefined)
		parentName = "profilePage";
		
	stopEdit (true);

	currEdit.name 	= "oBrowseParticipantPic";
	currEdit.type	= "browse";

	if (oBrowseParticipantPic == null)
	{
		var html =  "<div id='participantPic_window'>" +
						"<div id='participantPic_inWindow'>" +
							"<div id='participantPic_none'     onclick='cancelParticipantPic()'></div>" +
							"<div id='participantPic_browse'   style='display:none'>You need a newer version of flash</div>" +
							"<div id='participantPic_progress'><span id='progressBar' class='progressBar'></span></div>" +
							"<div id='participantPic_close'    onclick='closeParticipantPicBrowse()'></div>" +
						"</div>" +
				   "</div>";

		oBrowseParticipantPic = new floatWindow ();
		oBrowseParticipantPic.create (parentName, "fw_participantPic", html, 42, 3);

		participantPicUploadInit (document.getElementById("participantId").innerHTML);
		//document.getElementById("participantPic_browse").style.display = "";	
	}

	participantPicDoUpload = false;

	oBrowseParticipantPic.show ();
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* closeParticipantPicBrowse																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function closeParticipantPicBrowse ()
{
	if (participantPicDoUpload)
		alert ("נא להמתין לסיום טעינת התמונה");
	else
		oBrowseParticipantPic.close();
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* cancelParticipantPic																											*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function cancelParticipantPic ()
{
	if (participantPicDoUpload)
		alert ("נא להמתין לסיום טעינת התמונה");
	else
	{
		update ("participant_pic", "");
		oBrowseParticipantPic.close();
	}
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* setNewParticipantPic																											*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function setNewParticipantPic ()
{
	if (participantPicDoUpload)
		alert ("נא להמתין לסיום טעינת התמונה");
	else
	{
		var observer = "0";
		if (document.getElementById("observer") != undefined)
			observer = document.getElementById("observer").innerHTML;

		// update pic
		xml  = 	"<request>" +
					"<command>private.doAction</command>" +
					"<action>get</action>" 			+
					"<object>participant</object>" 	+
					"<eventId>"   					+ document.getElementById("eventId").innerHTML 				+ "</eventId>" 				+
					"<participantId>"   			+ document.getElementById("participantId").innerHTML      	+ "</participantId>" 		+
					"<observer>"   					+ observer		 											+ "</observer>" 			+
					"<fieldName>pic</fieldName>" 	+
				"</request>";
		
		xmlRequest.init (xml);
		xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "participant_pic_get_response");

		oBrowseParticipantPic.close();
	}
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* participant_pic_get_response																									*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function participant_pic_get_response (i)
{
	loadHtmlData ("participantPicImg", i);
}

var oSelectBirthDateWin = null;
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* selectBirthDate																												*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function selectBirthDate ()
{
	stopEdit (true);

	if (oSelectBirthDateWin == null)
	{
		img	= "<img src='loadedFiles/redSepNoBg.png' border='0' />";

		var years = "";
		var today = new Date();
		var endYear = today.getFullYear();
		for (i = 1920; i <= endYear; i++)
		{
			years += "<option value='" + i + "'>" + i + "</option>";
		}
 
		var html =  "<div id='selectBirthDate_window'>" +
						"<div id='selectBirthDate_inWindow'>" +
							"<table cellpadding='0' cellspacing='0' border='0' align='center'>" +
							"<tr>" +
								"<td>" + 
									"<select id='birthDate_year'>" + years + "</select>" +
								"</td>" +
								"<td>" + 
									"<select id='birthDate_month'>" +
										"<option value='01'>01</option><option value='02'>02</option><option value='03'>03</option>" +
										"<option value='04'>04</option><option value='05'>05</option><option value='06'>06</option>" +
										"<option value='07'>07</option><option value='08'>08</option><option value='09'>09</option>" +
										"<option value='10'>10</option><option value='11'>11</option><option value='12'>12</option>" +
									"</select>" +
								"</td>" +
								"<td>" + 
									"<select id='birthDate_day'>" +
										"<option value='01'>01</option><option value='02'>02</option><option value='03'>03</option>" +
										"<option value='04'>04</option><option value='05'>05</option><option value='06'>06</option>" +
										"<option value='07'>07</option><option value='08'>08</option><option value='09'>09</option>" +
										"<option value='10'>10</option><option value='11'>11</option><option value='12'>12</option>" +
										"<option value='13'>13</option><option value='14'>14</option><option value='15'>15</option>" +
										"<option value='16'>16</option><option value='17'>17</option><option value='18'>18</option>" +
										"<option value='19'>19</option><option value='20'>20</option><option value='21'>21</option>" +
										"<option value='22'>22</option><option value='23'>23</option><option value='22'>22</option>" +
										"<option value='25'>25</option><option value='26'>26</option><option value='27'>27</option>" +
										"<option value='28'>28</option><option value='29'>29</option><option value='30'>30</option>" +
										"<option value='31'>31</option>" +
									"</select>" +
								"</td>" +
							"</tr>" +
							"<tr><td height='7px'></td></tr>" +
							"<tr>" +
								"<td colspan='3' align='center'>" +
									"<img src='loadedFiles/close_btn.png' border='0' onclick='oSelectBirthDateWin.close()' style='cursor:pointer' />" +
									"&nbsp;&nbsp;" +
									"<img src='loadedFiles/update_btn.png' border='0' onclick='updateBirthDate()' style='cursor:pointer' />" + 
								"</td>" +
							"</tr>" +
							"</table>" +
						"</div>" +
				   "</div>";

		parentName = "eventCenter";
		x = -60;
		y = 58;

		if (document.getElementById(parentName) == undefined)
		{
			parentName = "profilePage";
			x = -10;
			y = 185;
		}

		oSelectBirthDateWin = new floatWindow ();
		oSelectBirthDateWin.create (parentName, "fw_selectBirthDate", html, x, y);
	}

	birthDate = document.getElementById("profile_birthDate").innerHTML.split(".");

	if (birthDate[2] >= 20 && birthDate[2] <= 99)
		birthDate[2] = "19" + birthDate[2];
	else
		birthDate[2] = "20" + birthDate[2];

	document.getElementById("birthDate_day").value	 	 = birthDate[0];
	document.getElementById("birthDate_month").value	 = birthDate[1];
	document.getElementById("birthDate_year").value 	 = birthDate[2];


	oSelectBirthDateWin.show ();

}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* updateBirthDate																												*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function updateBirthDate ()
{
	var birthDate = document.getElementById("birthDate_day").value  + "." + 
				    document.getElementById("birthDate_month").value + "." +
					document.getElementById("birthDate_year").value;

	// validate
	// --------------------------------------------------------------
	var dateErr = isDate (birthDate);

	if (dateErr != "")
	{
		alert (dateErr);
		return false;
	}
		
	shortBirthDate = document.getElementById("birthDate_day").value  + "." + 
				     document.getElementById("birthDate_month").value + "." +
					 document.getElementById("birthDate_year").value.substr(2,2);

	document.getElementById("profile_birthDate").innerHTML = shortBirthDate;

	oSelectBirthDateWin.close ();

	update ("participant_birthDate", birthDate);
}

var oPasswordSend 		= null;
var passwordSendParent	= "";
var passwordSendX;
var passwordSendY;

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* openPasswordSend																												*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function openPasswordSend (parentName, x, y, afterSend)
{
	if (afterSend == undefined) afterSend = false;

	if (oPasswordSend == null)
	{
		oPasswordSend = new floatWindow();
	}
	
	if (afterSend)
	{
		if (passwordSendParent == "")
		{
			passwordSendParent = parentName;
			passwordSendX	   = x;
			passwordSendY	   = y;
		}

		var html =  "<div id='confirmMsg_window'>" +
						"<div id='confirmMsg_inWindow'>" +
							"<table cellpadding='0' cellspacing='0' border='0' id='msgTable'>" + 
							"<tr>" + 
								"<td align='center'>" +
									"<div id='sendPassword_text'>הסיסמא נשלחה בהצלחה.</div>" +
									"<img src='loadedFiles/closeOnGray_btn.png' border='0' onclick='oPasswordSend.close()' style='cursor:pointer'/>" +
								"</td>" +
							"</tr>" + 
							"</table>" + 
						"</div>" +
				   "</div>";
	}
	else
	{
		passwordSendParent  = parentName;
		passwordSendX		= x;
		passwordSendY		= y;

		var html =  "<div id='confirmMsg_window'>" +
						"<div id='confirmMsg_inWindow'>" +
							"<table cellpadding='0' cellspacing='0' border='0' id='msgTable'>" + 
							"<tr>" + 
								"<td>" +
									"<div id='sendPassword_text'>הכנס את כתובת המייל אותה הזנת בעת הרשמתך לאתר וסיסמתך תשלח אליך.</div>" +
									"<div id='sendPassword_input'>" + 
										"<input id='sendPassword_email' type='text' maxLength='100' style='direction:ltr' />" + 
									"</div>" +
									"<div id='sendPassword_btns'>" +
									  "<img src='loadedFiles/closeOnGray_btn.png' border='0' onclick='oPasswordSend.close()' style='cursor:pointer'/>" +
									  "&nbsp;&nbsp;" +
									  "<img src='loadedFiles/sendOnGray_btn.png' border='0' onclick='doSendPassword()' style='cursor:pointer' />" +
									"</div>" +
								"</td>" +
							"</tr>" + 
							"</table>" + 
						"</div>" +
				   "</div>";
	}

	oPasswordSend.create (passwordSendParent, "fw_confirmMsg", html, passwordSendX, passwordSendY);
	oPasswordSend.show   ();
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* doSendPassword																												*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function doSendPassword ()
{
	oEmail = document.getElementById("sendPassword_email");

	if (oEmail.value == "")
	{	
		alert ("יש להזין אימייל");
		return false;
	}

	if (!validateEmailv2(oEmail.value))
	{
		alert ("יש להזין אימייל חוקי");
		return false;
	}


	var xml  = 	"<request>" +
					"<command>private.doAction</command>" 	+
					"<action>sendPassword</action>" 		+
					"<object>global</object>" 				+
					"<email>" + oEmail.value + "</email>" 	+
				"</request>";

	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "doSendPassword_response");
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* doSendPassword_response																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function doSendPassword_response (i)
{
	var xmlResponse = new xmlObj(false);
	xmlResponse.init(commonDecode(asyncHttpObjs[i].responseText));

	success = xmlResponse.getValue("success");

	if (success == "1")
		openPasswordSend ("", 0, 0, true);
	else
		alert ("כתובת המייל שהזנת אינה קיימת. נסה שוב");
}

var currHelpMsg = "";

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* wizard_showHelp																												*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function showHelp (which)
{
	if (currHelpMsg != which)
	{
		document.getElementById("help_" + currHelpMsg).style.display = "none";
		currHelpMsg = which;
		document.getElementById("help_" + currHelpMsg).style.display = "";
	}
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* getCookie																													*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function getCookie (cookieName)
{
	var allCookie = document.cookie;

	var theValue;
    var start = allCookie.indexOf(cookieName+"=");

    if (start == -1) return "";

    var end = allCookie.indexOf(";", start);

    if (end == -1) end = allCookie.length;

    var name_value = allCookie.substring(start, end);

    theValue = name_value.substring(cookieName.length+1, name_value.length);

	return theValue;
}

var oBrowseParticipantEmail = null;
/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* browseParticipantEmail																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function browseParticipantEmail (email, updateEmail)
{
	if (updateEmail == undefined)
		updateEmail = true;

	stopEdit (true);

	currEdit.name 	= "oBrowseParticipantEmail";
	currEdit.type	= "browse";

	if (oBrowseParticipantEmail == null)
	{
		oBrowseParticipantEmail = new floatWindow ();
	}

	if (updateEmail)
	{
		email    = document.getElementById("participant_email").innerHTML;

		var html =  "<div id='participantEmail_window'>" +
						"<div id='participantEmail_inWindow'>" +
							"<table cellpadding='0' cellspacing='0' border='0'>" +
							"<tr>" +
								"<td>" + 
									"<div id='participantEmail_text'>" +
										"הכניסה לאתר \"פגישה\" היא בעזרת כתובת האימייל, <br/>" +
										"אם תשנה כתובת זו, בכל פעם שתרצה להכנס בשנית לאתר \"פגישה\" תאלץ לעשות זאת בעזרת כתובת זו.<br/>" + 
										"שים לב, באפשרותך לשמור על כתובת זו חסוייה <br/>" +
										"ע\"י הגדרת הפרטיות בכרטיס האישי.<br/>(אם לא הגדרת אחרת היא פרטית) <br/><br/>" +
										"לשינוי כתובת - הקש את הכתובת החדשה כאן:" +
									"</div>" +
								"</td>" +
							"</tr>" +
							"<tr><td height='7px'></td></tr>" +
							"<tr>" +
								"<td>" + 
										"<input type='text' maxLength='200' class='inputField' style='direction:ltr' value='" + email + "'" +
										"		id='participantNewEmail' />" +
								"</td>" +
							"</tr>" +
							"<tr><td height='7px'></td></tr>" +
							"<tr>" +
								"<td colspan='3' align='center'>" +
									"<img src='loadedFiles/close_btn.png' border='0' onclick='oBrowseParticipantEmail.close()' " +
									"	  style='cursor:pointer' />" +
									"&nbsp;&nbsp;" +
									"<img src='loadedFiles/update_btn.png' border='0' onclick='updateEmail(\"" + email + "\")' " +
									"	  style='cursor:pointer' />" + 
								"</td>" +
							"</tr>" +
							"</table>" +
						"</div>" +
				   "</div>";
	}
	else
	{
		var html =  "<div id='confirmMsg_window'>" +
						"<div id='confirmMsg_inWindow'>" +
							"<table cellpadding='0' cellspacing='0' border='0' id='msgTable'>" + 
							"<tr>" + 
								"<td>" +
									"<div id='sendPassword_text'>כתובת זו כבר נמצאת במערכת,<br/>לשחזור הסיסמא לכתובת זו<br/>לחץ על 'שלח' </div>" +
									"<div id='participantEmail_text'>" + email + "<br/><br/></div>" + 
									"<div id='sendPassword_btns'>" +
									  "<img src='loadedFiles/closeOnGray_btn.png' border='0' onclick='oBrowseParticipantEmail.close()' " +
									  "	    style='cursor:pointer'/>" +
									  "&nbsp;&nbsp;" +
									  "<img src='loadedFiles/sendOnGray_btn.png' border='0' onclick='participantSendPassword()' " + 
									  "		style='cursor:pointer' />" +
									"</div>" +
								"</td>" +
							"</tr>" + 
							"</table>" + 
						"</div>" +
				   "</div>";
	}

	if (document.getElementById("participantPageCenter") == undefined)
	{
		parentName	= "eventCenter";
		x			= 82;
		y			= 23;
	}
	else
	{
		parentName  = "participantPageCenter";
		x		    = 82;
		y			= 23;
	}
		
	oBrowseParticipantEmail.create (parentName, "fw_participantPic", html, x, y);

	oBrowseParticipantEmail.show ();
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* updateEmail																													*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function updateEmail (oldEmail)
{
	var newEmail = document.getElementById("participantNewEmail").value;

	if (newEmail == oldEmail)
	{
		oBrowseParticipantEmail.close();
		return;
	}

	if (newEmail == "")
	{	
		alert ("יש להזין כתובת אימייל");
		return;
	}

	if (!validateEmailv2(newEmail))
	{
		alert ("כתובת האימייל אינה חוקית");
		return;
	}

	xml  = 	"<request>" +
				"<command>private.doAction</command>" +
				"<action>update</action>" 		+
				"<object>participant</object>" 	+
				"<eventId>"   					+ document.getElementById("eventId").innerHTML 				+ "</eventId>" 				+
				"<participantId>"   			+ document.getElementById("participantId").innerHTML      	+ "</participantId>" 		+
				"<fieldName>email</fieldName>" 	+
				"<fieldValue>" 					+ newEmail													+ "</fieldValue>"			+
			"</request>";
		
	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "updateEmail_response");
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* updateEmail_response																											*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function updateEmail_response (i)
{
	var xmlResponse = new xmlObj(false);
	xmlResponse.init(commonDecode(asyncHttpObjs[i].responseText));

	var	errorMsg 	= xmlResponse.getValue("errorMsg");

	oBrowseParticipantEmail.close();

	if (errorMsg == "no-error")
	{
		document.getElementById("participant_email").innerHTML = document.getElementById("participantNewEmail").value;
	}
	else
	{
		browseParticipantEmail (document.getElementById("participantNewEmail").value, false)
	}
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* participantSendPassword																										*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function participantSendPassword ()
{
	var xml  = 	"<request>" +
					"<command>private.doAction</command>" 	+
					"<action>sendPassword</action>" 		+
					"<object>global</object>" 				+
					"<email>" + document.getElementById("sendPassword_email").innerHTML + "</email>" 	+
				"</request>";

	xmlRequest.init (xml);
	xmlRequest.sendAsyncRequest ("server.php", xmlRequest.obj, "participantSendPassword_response");
}

/* ----------------------------------------------------------------------------------------------------------------------------	*/
/* participantSendPassword_response																								*/
/* ----------------------------------------------------------------------------------------------------------------------------	*/
function participantSendPassword_response ()
{
	oBrowseParticipantEmail.close();

	if (document.getElementById("participantPageCenter") == undefined)
	{
		parentName	= "eventCenter";
		x			= 82;
		y			= 23;
	}
	else
	{
		parentName  = "participantPageCenter";
		x		    = 82;
		y			= 23;
	}
		
	openPasswordSend (parentName, x, y, true);
}

