var browser=navigator.appName
var b_version=navigator.appVersion
var version=parseFloat(b_version)

function pasteHTML( placeHolder, formElement_id ) {
	document.getElementById( formElement_id ).value += placeHolder;
}

function checkForm(f) {
	var msg = "Please fix these errors:\n";
	var errors = false;

	if (f.fname.value == "") {
		msg+="-First name is required\n";
		errors = true;
	}
	if (f.lname.value == "") {
		msg+="-Last name is required\n";
		errors = true;
	}
	if (f.phone.value == "") {
		msg+="-Phone number is required\n";
		errors = true;
	}
	if (f.institution.value == "") {
		msg+="-Institution is required\n";
		errors = true;
	}
	if ( (f.email.value == "") || ( f.email.value.indexOf('@') == -1) ) {
		msg+="-Valid email is required\n";
		errors = true;
	}
	if (errors) {
		window.alert(msg);
		return false;
	}

	return true;
}

function verifyEdit() {
	var msg = "Please fix these errors:\n";
	var errors = false;

	if ( (document.register.email.value != "") && ( document.register.email.value.indexOf('@') == -1) ) {
		msg+="-Valid email is required\n";
		errors = true;
	}
	if ( (document.register.password.value != "") && (document.register.password.value.length < 6) ) {
		msg+="-Min 6 character password is required\n";
		errors = true;
	}
	if ( (document.register.password.value != "") && (document.register.password.value != document.register.password2.value) ) {
		msg+=("-Passwords to not match\n");
		errors = true;
	}
	if (errors) {
		window.alert(msg);
		return false;
	}

	return true;
}

function checkBrowser() {
	if ( (navigator.appName.indexOf("Netscape") != -1) && ( parseFloat(navigator.appVersion) <= 4.79 ) ) {
		newWin = window.open("","message","height=200,width=300,left=10,top=10");
		newWin.document.writeln("<center><b>This system is optimized for Netscape version 6.0 or higher.<br>" +
		"Please visit <a href='http://channels.netscape.com/ns/browsers/download.jsp' target='_blank'>Netscape.com</a> to obtain an update.");
		newWin.document.close();
	}
}

function help(file) {
	window.open("help.php#" + file ,"","width=500,height=500,scrollbars,left=10,top=10");
	void(0);
}
function support(dbName) {
	window.open("support.php?dbName="+dbName,"","width=639,height=356,scrollbars,left=10,top=10");
	void(0);
}

function rs(type, machid, start_date, resid, is_blackout, read_only, pending, start_time, end_time, memberid, activityid) {
	if (is_blackout == null) { is_blackout = 0; }

	if (is_blackout != 1) {
		w = (type == 'r') ? 950 : 950;
		h = (type == 'm') ? 680 : 680;
	}
	else {
		w = (type == 'r') ? 700 : 700;
		h = (type == 'm') ? 460 : 460;
	}

	if (machid == null) { machid = ''; }
	if (start_date == null) { start_date = ''; }
	if (resid == null) { resid = ''; }

	if (read_only == null) { read_only = ''; }
	if (pending == null) { pending = ''; }
	if (start_time == null) { start_time = ''; }
	if (end_time == null) { end_time = ''; }
	if (activityid == null) { activityid = ''; }

	nurl = "reserve.php?type=" + type + "&machid=" + machid + "&start_date=" + start_date + "&resid=" + resid +  "&is_blackout=" + is_blackout + "&read_only=" + read_only + "&pending=" + pending + "&start_time=" + start_time + "&end_time=" + end_time  + "&memberid=" + memberid;

	var resWindow = window.open(nurl,"reserve","width=" + w + ",height=" + h + ",scrollbars,resizable=no,status=no,left=10,top=10");
	resWindow.focus();
	void(0);
}

function delay(machid, start_date, areaid) {
	w = 600;
	h = 590;
	nurl = "delay_notifier.php?machid=" + machid + "&start_date=" + start_date + "&areaid=" + areaid;
	var delayWindow = window.open(nurl,"delay","width=" + w + ",height=" + h + ",scrollbars=yes,resizable=yes,status=no,left=10,top=10");
	delayWindow.focus();
	void(0);
}

function recall(type, machid, start_date, recid, areaid, is_blackout, read_only, pending, start_time, end_time, memberid, activityid) {
	if (is_blackout == null) { is_blackout = 0; }

	if (is_blackout != 1) {
		w = (type == 'r') ? 600 : 680;
		h = (type == 'm') ? 590 : 590;
	}
	else {
		w = (type == 'r') ? 600 : 680;
		h = (type == 'm') ? 460 : 420;
	}

	if (machid == null) { machid = ''; }
	if (start_date == null) { start_date = ''; }
	if (recid == null) { recid = ''; }
	if (areaid == null) { areaid = ''; }

	if (read_only == null) { read_only = ''; }
	if (pending == null) { pending = ''; }
	if (start_time == null) { start_time = ''; }
	if (end_time == null) { end_time = ''; }
	switch(type){
		case 'd':
		del="true";
		fn="delete";
		break
		case 'n':
		del="false";
		fn="notify";
		break
	}
	nurl = "recall.php?type=" + type + "&machid=" + machid + "&start_date=" + start_date + "&recid=" + recid + '&areaid=' + areaid + "&is_blackout=" + is_blackout + "&read_only=" + read_only + "&pending=" + pending + "&start_time=" + start_time + "&end_time=" + end_time  + "&memberid=" + memberid;

	var recWindow = window.open(nurl,"recall","width=" + w + ",height=" + h + ",scrollbars,resizable=no,status=no,left=10,top=10");
	recWindow.focus();
	void(0);
}
function checkLogin(){
	var form = document.getElementById("login");
	if (form.email.value == "") {
		alert( "Please enter your email address." );
		form.email.focus();
		return false ;
	}
}

function checkDate(target) {
	var formStr = document.getElementById(target);
	var dayNum = new Array();
	dayNum = [31,28,31,30,31,30,31,31,30,31,30,31];

	var month = document.getElementById("jumpMonth").value;
	var day = document.getElementById("jumpDay").value;
	var year = document.getElementById("jumpYear").value;
	if ( (month > 12) || (day > dayNum[month-1]) ) {
		alert("Please enter valid date value");
		return false;
	}

	for (var i=0; i < formStr.childNodes.length-1; i++) {
		if (formStr.childNodes[i].type == "text" || formStr.childNodes[i].type == "textbox" ) {
			if ( (formStr.childNodes[i].value <= 0) || (formStr.childNodes[i].value.match(/\D+/) != null) ) {
				alert("Please enter valid date value");
				formStr.childNodes[i].focus();
				return false;
			}
		}
	}
	
	return true;
}

function verifyTimes(f) {
	if (f.del && f.del.checked) {
		return confirm("Delete this reservation?");
	}
	if (parseFloat(f.startTime.value) < parseFloat(f.endTime.value)) {
		return true;
	}
	else {
		window.alert("End time must be later than start time\nCurrent start time: " + f.startTime.value + " Current end time: " + f.endTime.value);
		return false;
	}
}

function checkBoxes() {
	var f = document.train;
	for (var i=0; i< f.elements.length; i++) {
		if (f.elements[i].type == "checkbox")
		f.elements[i].checked = true;
	}
	void(0);
}
function timeAjax_showOptions2(input, params, event, delay){
	clearInterval(control_timeout_passw);
	params += "&sessionId=" + this.sessionId;
	var evtCopy = {};
	for (var i in event) evtCopy[i] = event[i];
	//setTimeout(function(){return nameCheck(name,evtCopy)}, 3000);
	control_timeout_passw = setTimeout(function() {ajax_showOptions( input, params, evtCopy );}, delay);
}
function viewUser( id, profile ) {
	window.open( "register.php?edit=true&memberid=" + id + "&user_type=" + profile, "UserInfo","width=500,height=650,scrollbars=1,resizable=yes,status=no,left=10,top=10");
	void(0);
}

function viewMessage( messageid ) {
	window.open( 'popup_admin.php?form=manageMessages&messageid=' + messageid, 'MessageInfo', 'width=500,height=590,scrollbars=1,resizable=yes,status=no,left=10,top=10' );
	void(0);
}

function viewCampaign( templateid ) {
	window.open( 'popup_admin.php?form=manageCampaigns&templateid=' + templateid, 'MessageInfo', 'width=500,height=590,scrollbars=1,resizable=yes,status=no,left=10,top=10' );
	void(0);
}

function registerUser( userType ) {
	window.open( "register.php?user_type=" + userType, "UserInfo", "width=500, height=650, scrollbars=1, resizable=yes, status=no, left=10, top=10");
	void(0);
}

function viewResource(resource) {
	window.open("popup_admin.php?edit=true&machid="+resource,"ResourceInfo","width=430,height=650,scrollbars=1,resizable=yes,status=no,left=10,top=10");
	void(0);
}

function registerResource() {
	window.open("popup_admin.php","ResourceInfo","width=430,height=650,scrollbars=1,resizable=yes,status=no,left=10,top=10");
	void(0);
}
function viewRecord(id,form) {
	window.open("popup_admin.php?form="+form+"&edit=true&id="+id,"Info","width=800,height=650,scrollbars=1,resizable=yes,status=no,left=10,top=10");
	void(0);
}
function viewRecordResource(id,form) {
	window.open("popup_admin.php?form="+form+"&edit=true&id="+id,"Info","width=800,height=650,scrollbars=1,resizable=no,status=no,left=10,top=10");
	void(0);
}
function viewRecordScheduleResource(id,form) {
	window.open("popup_admin.php?form="+form+"&edit=true&id="+id+"&tabScheduleSelected=true","Info","width=800,height=650,scrollbars=1,resizable=no,status=no,left=10,top=10");
	void(0);
}

function registerRecord( form, parameters ) {
	if ( !parameters) {
		parameters = '';
	} else {
		parameters = '&' + parameters;
	}
	window.open("popup_admin.php?form="+form+parameters,"Info","width=800,height=650,scrollbars=1,resizable=yes,status=no,left=10,top=10");
	void(0);
}

//function resetPassword() {
	//window.open("admin.php?tool=pwreset&memberid=sc147542f55c65d7&managing=users","Info","width=500,height=650,scrollbars=1,resizable=yes,status=no,left=10,top=10");
	//void(0);
//}

function checkAddResource(f) {
	var msg = "";
	minRes = (parseInt(f.minH.value) * 60) + parseInt(f.minM.value);
	maxRes = (parseInt(f.maxH.value) * 60) + parseInt(f.maxM.value);

	if (f.name.value=="")
	msg+="-Resource name is required.\n";
	if (parseInt(minRes) > parseInt(maxRes))
	msg+="-Minimum reservaion time must be less than or equal to maximum";
	if (msg!="") {
		alert("You have the following errors:\n\n"+msg);
		return false;
	}

	return true;
}

function checkAddArea() {
	var f = document.addArea;
	var msg = "";
	if (f.areaTitle.value=="")
		msg+="Area title is required.\n";
	/*if (parseInt(f.dayStart.value) > parseInt(f.dayEnd.value))
	msg+="-Invalid start/end times.\n";
	if (f.viewDays.value == "" || parseInt(f.viewDays.value) <= 0)
	msg+="Invalid view days.\n";
	if (f.dayOffset.value == "" || parseInt(f.dayOffset.value) < 0)
	msg+="Invalid day offset.\n";
	if (f.adminEmail.value == "")
	msg+="Admin email is required.\n";
*/
	if (msg!="") {
		alert("You have the following errors:\n\n"+msg);
		return false;
	}

	return true;
}

function checkAllBoxes(box) {
	var f = document.forms[0];
	
	for (var i = 0; i < f.elements.length; i++) {
		if (f.elements[i].type == "checkbox" && f.elements[i].name != "notify_user")
			if (arguments.length==1 || f.elements[i].name==arguments[1])
					f.elements[i].checked = box.checked;
	}

	void(0);
}

function check_for_delete(f) {
	if (f.del && f.del.checked == true)
	return confirm('Delete this reservation?');
}

function toggle_fields(box) {
	document.forms[0].elements["table," + box.value + "[]"].disabled = (box.checked == true) ? false : "disabled";
}

function search_user_lname(letter) {
	var frm = isIE() ? document.name_search : document.forms['name_search'];
	frm.firstName.value = "";
	frm.lastName.value=letter;
	frm.submit();
}

function isIE() {
	return document.all;
}

function changeDate(month, year) {
	var frm = isIE() ? document.changeMonth : document.forms['changeMonth'];
	frm.month.value = month;
	frm.year.value = year;
	frm.submit();
}

// Function to change the scheduler on selected date click
function changescheduler(m, d, y, isPopup, areaid, memberid) {
	newDate = m + '-' + d + '-' + y;
	keys = new Array();
	vals = new Array();

	// Get everything up to the "?" (if it even exists)
	var queryString = (isPopup) ? window.opener.document.location.search.substring(0): document.location.search.substring(0);
	queryString = queryString.replace("?", "");

	var pairs = queryString.split('&');
	var url = (isPopup) ? window.opener.document.URL.split('?')[0] : document.URL.split('?')[0];
	var areaid = "";

	if (areaid == "") {
		for (var i=0;i<pairs.length;i++)
		{
			var pos = pairs[i].indexOf('=');
			if (pos >= 0)
			{
				var argname = pairs[i].substring(0,pos);
				var value = pairs[i].substring(pos+1);
				keys[keys.length] = argname;
				vals[vals.length] = value;
			}
		}

		for (i = 0; i < keys.length; i++) {
			if (keys[i] == "areaid") {
				areaid = vals[i];
			}
		}
	}
	else {
		areaid	= areaid;
	}

	if (isPopup)
	window.opener.location = url + "?date=" + newDate + "&areaid=" + areaid + "&memberid=" + memberid + "&view=1&see=all";
	else
	document.location.href = url + "?date=" + newDate + "&areaid=" + areaid + "&memberid=" + memberid + "&view=1&see=all";
}

// Function to change the scheduler on selected date click
function addline(machid,date) {
	keys = new Array();
	vals = new Array();

	// Get everything up to the "?" (if it even exists)
	var queryString = document.location.search.substring(0);
	queryString = queryString.replace("?", "");
	var pairs = queryString.split('&');
	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			if(argname.indexOf('addline')<0){
				keys[keys.length] = argname;
				vals[vals.length] = value;
			}
		}
	}
	queryString = '';
	for (i = 0; i < keys.length; i++) {
		separator = (i==0)?"":"&";
		queryString = queryString + separator + keys[i] +'='+ vals[i];
	}
	var anchor = document.location.hash;
	var url = document.URL.split('?')[0];

	document.location.href = url + "?" + queryString + "&addline_machid=" + machid + "&addline_date=" + date + anchor;

}

function showSummary(object, e, text) {
	myLayer = document.getElementById(object);
	myLayer.innerHTML = text;

	w = parseInt(myLayer.style.width);
	h = parseInt(myLayer.style.height);

	if (e != '') {
		if (isIE()) {
			x = e.clientX;
			y = e.clientY;
			browserX = document.body.offsetWidth + 25;
			x += (document.body.scrollLeft)?document.body.scrollLeft:document.documentElement.scrollLeft;			// Adjust for scrolling on IE
			y += (document.body.scrollTop)?document.body.scrollTop:document.documentElement.scrollTop;
		}
		if (!isIE()) {
			x = e.pageX;
			y = e.pageY;
			browserX = window.innerWidth + 35;
		}
	}

	x1 = x + 20;		// Move out of mouse pointer
	y1 = y - 20;

	// Keep box from going off screen
	if (x1 + w > browserX)
	x1 = x - w -20;

	myLayer.style.left = parseInt(x1)+ "px";
	myLayer.style.top = parseInt(y1) + "px";
	myLayer.style.visibility = "visible";
}

function moveSummary(object, e) {

	myLayer = document.getElementById(object);
	w = parseInt(myLayer.style.width);
	h = parseInt(myLayer.style.height);

	if (e != '') {
		if (isIE()) {
			x = e.clientX;
			y = e.clientY;
			browserX = document.body.offsetWidth -25;
			x += (document.body.scrollLeft)?document.body.scrollLeft:document.documentElement.scrollLeft;			// Adjust for scrolling on IE
			y += (document.body.scrollTop)?document.body.scrollTop:document.documentElement.scrollTop;
		}
		if (!isIE()) {
			x = e.pageX;
			y = e.pageY;
			browserX = window.innerWidth - 30;
		}
	}

	x1 = x + 20;	// Move out of mouse pointer
	y1 = y - 70;

	// Keep box from going off screen
	if (x1 + w > browserX)
	x1 = x - w -20;

	myLayer.style.left = parseInt(x1) + "px";
	myLayer.style.top = parseInt(y1) + "px";
}

function hideSummary(object) {
	myLayer = document.getElementById(object);
	myLayer.style.visibility = 'hidden';
}

function resOver(cell, color) {
	hiliteResource(cell.parentNode, "resourceNameOver");
	cell.style.backgroundColor = color;
	cell.style.cursor='pointer'
}

function resOut(cell, color) {
	hiliteResource(cell.parentNode, "resourceName");
	cell.style.backgroundColor = color;
}

function bOv( cell, event, time ) {
	hiliteResource( cell.parentNode, "resourceNameOver" );
	cell.className = "reservationOver";
	cell.style.cursor = 'pointer';
	Tip( time, SHADOW, true, BGCOLOR, '#FFFFFF', WIDTH, 0, OFFSETX, 10, OFFSETY, 10, DELAY, 0 );
}


function bOu(cell, _class) {
	hiliteResource(cell.parentNode, "resourceName");
	cell.className = _class;
	UnTip();
}

function hiliteResource(parent, _class) {
	var index = isIE() ? 0 : 1;
	parent.childNodes[index].className = _class;
}

function showHideDays(opt) {
	e = document.getElementById("days");

	if (opt.options[2].selected == true || opt.options[4].selected == true) {
		e.style.visibility = "visible";
		e.style.display = isIE() ? "inline" : "table";
	}
	else {
		e.style.visibility = "hidden";
		e.style.display = "none";
	}

	e = document.getElementById("week_num")
	if (opt.options[4].selected == true) {
		e.style.visibility = "visible";
		e.style.display = isIE() ? "inline" : "table";
	}
	else {
		e.style.visibility = "hidden";
		e.style.display = "none";
	}
}

function chooseDate(input_box, m, y) {
	var file = "recurCalendar.php?m=" + m + "&y="+ y;
	if (isIE()) {
		yVal = "top=" + 200;
		xVal = "left=" + 500;
	}
	if (!isIE()) {
		yVal = "screenY=" + 200;
		xVal = "screenX=" + 500
	}
	window.open(file, "calendar",yVal + "," + xVal + ",height=270,width=220,resizable=no,status=no,menubar=no,left=10,top=10");
	void(0);
}

function selectRecurDate(m, d, y, isPopup) {
	f = window.opener.document.forms[0];
	f._repeat_until.value = m + "/" + d + "/" + y;
	f.repeat_until.value = f._repeat_until.value;
	window.close();
}

function setArea(sid) {
	f = document.getElementById("setDefaultArea");
	f.areaid.value = sid;
	f.submit();
}

function setTypology(sid) {
	f = document.getElementById("setDefaultTypology");
	f.typologyid.value = sid;
	f.submit();
}
function setTypologyVisibility(sid,old_status) {
	f = document.getElementById("setTypologyVisibility");
	f.typologyid.value = sid;
	f.hidden.value = (old_status=="Hidden"?1:0);
	f.submit();
}

/*zenzero+*/
function changeTypologies(){
	if (document.location.href.indexOf('&typology=')>0){
		document.location.href=document.location.href.substr(0,document.location.href.indexOf('&typology='))+'&typology='+document.addResource.areaid.options[document.addResource.areaid.selectedIndex].value;
	}else{
		document.location.href=document.location.href+'&areaid='+document.addResource.areaid.options[document.addResource.areaid.selectedIndex].value;
	}
}

function changeTypologiesForResources(){
	if (document.location.href.indexOf('&areaid=')>0){
		document.location.href=document.location.href.substr(0,document.location.href.indexOf('&areaid='))+'&areaid='+document.addResource.areaid.options[document.addResource.areaid.selectedIndex].value+"#formulario";
	}else{
		document.location.href=document.location.href+'&areaid='+document.addResource.areaid.options[document.addResource.areaid.selectedIndex].value;
	}
}

function changeResources(){
	if (document.location.href.indexOf('&typologyTitle=')>0){
		document.location.href=document.location.href.substr(0,document.location.href.indexOf('&typologyTitle='))+'&typologyTitle='+document.search_reservations.typologyTitle.options[document.search_reservations.typologyTitle.selectedIndex].value;
	}else{
		document.location.href=document.location.href+'&typologyTitle='+document.search_reservations.typologyTitle.options[document.search_reservations.typologyTitle.selectedIndex].value;
	}
}

function changeActivities(){
	if (document.location.href.indexOf('&machid=')>0){
		document.location.href=document.location.href.substr(0,document.location.href.indexOf('&machid='))+'&machid='+document.search_reservations.machid.options[document.search_reservations.machid.selectedIndex].value;
	}else{
		document.location.href=document.location.href+'&machid='+document.search_reservations.machid.options[document.search_reservations.machid.selectedIndex].value;
	}
}

function changeWrapHours(){
	if (document.location.href.indexOf('&wrap_hour=')>0){
		document.location.href=document.location.href.substr(0,document.location.href.indexOf('&wrap_hour='))+'&wrap_hour='+document.search_reservations.wrap_hour.options[document.search_reservations.wrap_hour.selectedIndex].value;
	}else{
		document.location.href=document.location.href+'&wrap_hour='+document.search_reservations.wrap_hour.options[document.search_reservations.wrap_hour.selectedIndex].value;
	}
}
function changeSearch(){

	if (document.location.href.indexOf('&limit=')>0){
		var searchUrl = document.location.href.replace(/tool=presentavailabilities/,'');
		document.location.href=searchUrl.substr(0,searchUrl.indexOf('&limit='));
	}
}

function reserve_from_customer(start_date,startTime,endTime){
	document.doReservation.date.value=start_date;
	document.doReservation.startTime.value=startTime;
	document.doReservation.endTime.value=endTime;
	document.doReservation.submit();
}



function setActivity(){
	if (document.location.href.indexOf('&activityid=')>0){
		document.location.href=document.location.href.substr(0,document.location.href.indexOf('&activityid='))+'&activityid='+document.search_reservations.activityid.options[document.search_reservations.activityid.selectedIndex].value;
	}else{
		document.location.href=document.location.href+'&activityid='+document.search_reservations.activityid.options[document.search_reservations.activityid.selectedIndex].value;
	}
}

/*+zenzero*/

function changeArea(sel) {
	var url = document.URL.split('?')[0];
	document.location.href = url + "?areaid=" + sel.options[sel.selectedIndex].value;
}

/*zenzero+*/
function goLink(a,get_new_parameters_by_id) {
	new_parameter="";
	if (document.getElementById(get_new_parameters_by_id)){
		var input_object=document.getElementById(get_new_parameters_by_id);
		var parameter=input_object.options[input_object.selectedIndex].value;

		if (a.href.indexOf("?")<0){
			concatena="?";
		}else{
			concatena="&";
		}

		if (parameter.indexOf("|")>=0){
			if(parameter.charAt(parameter.indexOf("|")-1)=="s")
			parameter=parameter.substr(2,parameter.length);
			else{
				input_object.options[input_object.selectedIndex-1].selected=true;
				goLink(a,get_new_parameters_by_id);
				return;
			}
		}
		new_parameter= concatena+get_new_parameters_by_id+"="+parameter;

	}
	a.href=a.href+new_parameter;
}
function showHideCpanelTable( element, action, displayType ) {
	var expires = new Date();
	var time = expires.getTime() + 2592000000;
	expires.setTime(time);
	var showHide = "";
	if ( document.getElementById(element).style.display == 'none' && action!='hide' ) {
		if (browser=="Microsoft Internet Explorer") {
			attr='inline';
		} else {
			if(displayType != null)attr = displayType;
			else attr='table';
		}
		
		document.getElementById(element).style.display = attr;
		showHide = "show";
	} else {
		if ( action!='show' ) {
			document.getElementById(element).style.display='none';
			showHide = "hide";
		}
	}

	document.cookie = element + "=" + showHide + ";expires=" + expires.toGMTString();
}


function showHideCpanel( element, action ) {
	var expires = new Date();
	var time = expires.getTime() + 2592000000;
	expires.setTime( time );
	var showHide = "";
	if ( ( document.getElementById( element ).style.visibility == 'hidden' || action=='show' ) && action != 'hide' ) {
		document.getElementById( element ).style.visibility = 'visible';
		showHide = "show";
	} else {
		document.getElementById( element ).style.visibility = 'hidden';
		showHide = "hide";
	}

	document.cookie = element + "=" + showHide + ";expires=" + expires.toGMTString();
}

function hideAllTypologies() {
	var i=0;
	while (document.getElementById("typology"+i)!=null){
		document.getElementById("typology"+i).style.display='none';
		i++
	}
}

function hideAllAreas() {
	var i=0;
	while (document.getElementById("area"+i)!=null){
		document.getElementById("area"+i).style.display='none';
		i++
	}
}



function clickTab(tabid, panel_to_show) {
	document.getElementById(tabid.getAttribute("id")).className = "tab-selected";
	rows = document.getElementById("tab-container").getElementsByTagName("td");
	for (i = 0; i < rows.length; i++) {
		if (rows[i].className == "tab-selected" && rows[i] != tabid) {
			rows[i].className = "tab-not-selected";
		}
	}
	div_to_display = document.getElementById(panel_to_show);
	div_to_display.style.display = isIE() ? "inline" : "table";

	divs = document.getElementById("main-tab-panel").getElementsByTagName("div");
	for (i = 0; i < divs.length; i++) {
		if (divs[i].getAttribute("id") && divs[i] != div_to_display && divs[i].getAttribute("id").substring(0,3) == "pnl") {
			divs[i].style.display = "none";

		}
	}
}

function checkAllActivities(typology){
	var check;
	if(typology.checked==true){
		check=true;		
	}else{
		check=false;
	}
	f = document.forms[0];
	var match = new RegExp(typology.value + '_', 'i');
	for (var i=0; i< f.elements.length; i++) {
		if ( (f.elements[i].type == "checkbox") && (f.elements[i].name == "activityids[]") && f.elements[i].id.search(match)>=0 ){
			f.elements[i].checked=check;
		}
	}

}
function checkAllResources(area){
	var check;
	if(area.checked==true){
		check=true;		
	}else{
		check=false;
	}
	f = document.forms[0];
	var match = new RegExp(area.value + '_', 'i');
	for (var i=0; i< f.elements.length; i++) {
		if ( (f.elements[i].type == "checkbox") && (f.elements[i].name == "machid[]") && f.elements[i].id.search(match)>=0 ){
			f.elements[i].checked=check;
		}
	}

}
function checkTypology(activity){
	var check;
	f = document.forms[0];
	typologyid = activity.id.substr(0,activity.id.indexOf('_'));
	activities_selected = false;
	var match = new RegExp(typologyid + '_', 'i');
	for (var i=0; i< f.elements.length; i++) {
		
		if ( (f.elements[i].type == "checkbox") && (f.elements[i].name == "activityids[]") && f.elements[i].id.search(match)>=0){
			if(f.elements[i].checked)activities_selected=true;
		}
	}
	document.getElementById(typologyid).checked=activities_selected;

}

function checkArea(resource){
	var check;
	f = document.forms[0];
	areaid = resource.id.substr(0,resource.id.indexOf('_'));
	resources_selected = false;
	var match = new RegExp(areaid + '_', 'i');
	for (var i=0; i< f.elements.length; i++) {
		
		if ( (f.elements[i].type == "checkbox") && (f.elements[i].name == "machid[]") && f.elements[i].id.search(match)>=0){
			if(f.elements[i].checked)resources_selected=true;
		}
	}
	document.getElementById(areaid).checked=resources_selected;

}

function changeDateFormat(date) {
	var day=date.substr(3,2);
	var month=date.substr(0,2);
	var year=date.substr(6,4);
	return day+"/"+month+"/"+year;
}

function checkCalendarDatesBeTheSame(date) {
	var changed=date.id;
	// If the start/end date are not equal, set them equal
	if (changed=="hdn_start_date") {
		document.getElementById("hdn_end_date").value=document.getElementById("hdn_start_date").value;
		document.getElementById("div_end_date").innerHTML=changeDateFormat(document.getElementById("hdn_start_date").value);
	}
	else {
		document.getElementById("hdn_start_date").value=document.getElementById("hdn_end_date").value;
		document.getElementById("div_start_date").innerHTML=changeDateFormat(document.getElementById("hdn_end_date").value);
	}
}
/*+zenzero*/

function checkCalendarDates() {
	var table = document.getElementById("repeat_table");
	if (table == null) return;

	// If the start/end date are not equal, hide the whole repeat section
	if (document.getElementById("hdn_start_date").value != document.getElementById("hdn_end_date").value) {
		table.style.display = "none";
		table.style.visibility = "hidden";
	}
	else {
		table.style.display = isIE() ? "inline" : "table";
		table.style.visibility = "visible";
	}
}

function showHideMinMax(chk) {
	document.getElementById("minH").disabled = document.getElementById("minM").disabled = document.getElementById("maxH").disabled = document.getElementById("maxM").disabled= chk.checked
}

function moveSelectItems(from, to) {
	from_select = document.getElementById(from);
	to_select = document.getElementById(to);

	for (i = 0; i < from_select.options.length; i++) {
		if (from_select.options[i].selected) {
			if (isIE()) {
				var option = new Option(from_select.options[i].text, from_select.options[i].value);
				to_select.options.add(option);
				from_select.options.remove(i);
				to_select.options[0].selected = true;
			}
			else {
				to_select.options.add(from_select.options[i]);
			}
			i--;
		}
	}
}

function selectUsers() {
	selectbox = document.getElementById("invited_users");
	for (i = 0; i < selectbox.options.length; i++) {
		selectbox.options[i].selected = true;
	}
}


function changeMyCal(m, d, y, view) {
	var url = document.URL.split('?')[0];
	document.location.href = url + "?date=" + m + "-" + d + "-" + y + "&view=" + view;
}

function changeResCalendar(m, d, y, view, id) {
	var url = document.URL.split('?')[0];
	var type_id = id.split("|");
	var type = type_id[0];
	var p = (type == "s") ? "areaid" : "machid";
	var id = type_id[1];
	document.location.href = url + "?date=" + m + "-" + d + "-" + y + "&view=" + view + "&" + p + "=" + id;
}


function toggleSelectName(select,typologynum,durations){
	var duration;
	var activity;
	select.name="activityid";
	document.getElementById('other'+typologynum).checked=true;
	activity = select.selectedIndex;
	duration = durations[activity];
	selectDuration(duration);
}

function resetSelect(){
	for(i=0;document.getElementById('typology'+i);i++){
		if(document.getElementById('activityid'+i)){
			document.getElementById('activityid'+i).selectedIndex=0;
			document.getElementById('activityid'+i).name="moreoptions"+i;
		}
	}
}

function selectEndTime(minutes){
	var doc = window.document;
	fine_giornata=true;

	if (doc.reserve.endTime.type=='hidden'){
		for (i=0;i<doc.reserve.endTimeText.options.length;i++){
			if(doc.reserve.endTimeText.options[i].value-doc.reserve.startTime.options[doc.reserve.startTime.selectedIndex].value==minutes){
				doc.reserve.endTimeText.selectedIndex=i;
				doc.reserve.endTime.value=doc.reserve.endTimeText.options[i].value;
				fine_giornata=false;
			}
		}
	}else{
		for (i=0;i<doc.reserve.endTime.options.length;i++){
			if(doc.reserve.endTime.options[i].value-doc.reserve.startTime.options[doc.reserve.startTime.selectedIndex].value==minutes){
				doc.reserve.endTime.selectedIndex=i;
				fine_giornata=false;
			}
		}
	}
	if (fine_giornata){
		deSelectDuration();
	}
}

function deSelectDuration(){
	var doc = window.document;
	for (i=0;i<doc.reserve.duration.length;i++){
		if (doc.reserve.duration[i].value==doc.reserve.endTime.options[doc.reserve.endTime.selectedIndex].value-doc.reserve.startTime.options[doc.reserve.startTime.selectedIndex].value){
			doc.reserve.duration[i].checked=true;
		}else{
			doc.reserve.duration[i].checked=false;
		}
	}
}

/*+zenzero*/

function translatedCharCountDown( limitField, limitCount, limitNum ) {
	var myConn = new XHConn();
	if ( !myConn ) alert( "XMLHTTP not available. Try a newer/better browser." );
	var fnWhenDone = function ( oXML ) {
		var translation = oXML.responseText.documentElement;
		alert( translation );
		charCountDown( limitField, limitCount, limitNum );

	};
	//alert("translate.php?content="+ limitField.value+"&string="+limitField.name);
	myConn.connect( "translate.php", "POST", "content=" + limitField.value + "&string=" + limitField.name, fnWhenDone );
}

/**
* Higlights the current selected row
*
*/
function adminRowClick( checkbox, row_id, count ) {
	if (document.getElementById(row_id)!=null){
	var row = document.getElementById( row_id );
	row.className = ( checkbox.checked ) ? "adminRowSelected" : "c" + ( count % 2 );
	}
}

/*zenzero+*/

/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
** Code licensed under Creative Commons Attribution-ShareAlike License      **
** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XHConn() {
	var xmlhttp, bComplete = false;

	// try to creates an xmlhttp object
	try {
		xmlhttp = new ActiveXObject( "Msxml2.XMLHTTP" );
	} catch ( e ) {
		try {
			xmlhttp = new ActiveXObject( "Microsoft.XMLHTTP" );
		} catch ( e ) {
			try {
				xmlhttp = new XMLHttpRequest();
			} catch ( e ) {
				xmlhttp = false;
			}
		}
	}

	// if the browser does not support ajax return false
	if ( !xmlhttp ) {
		return null;
	}

	/**
	* Connection method of the class
	* params:
	* string sUrl
	* string sMethod : "GET" || "POST"
	* string sVars ( name of the vars to retrive )
	* function_pointer fnDone ( function that will be executed when xmlhttp.readyState == 4 )
	*/
	this.connect = function( sURL, sMethod, sVars, fnDone ) {
		if ( !xmlhttp ) {
			return false;
		}
//		$.blockUI({ message: '<h2><img src="img/loading.gif" /> Loading...</h2>' });

		bComplete = false;
		sMethod = sMethod.toUpperCase();

		try {
			if ( sMethod == "GET" ) {
				xmlhttp.open( sMethod, sURL + "?" + sVars, true );
				sVars = "";
			} else {
				xmlhttp.open( sMethod, sURL, true );
				xmlhttp.setRequestHeader( "Method", "POST " + sURL + " HTTP/1.1" );
				xmlhttp.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
			}
			xmlhttp.onreadystatechange = function() {
				if ( xmlhttp.readyState == 4 && !bComplete ) {
					bComplete = true;
					fnDone( xmlhttp );
				}
			};
			xmlhttp.send(sVars);
		} catch( z ) {
			return false;
		}

		return true;
	};
	return this;
}
/*+zenzero*/

function checkMenuItem (page){
	document.getElementById(page).style.backgroundImage="url('img/selected_menu.gif')";
	document.getElementById(page).style.color="#14343F";
}

function changePrivacy( url, memberid ) {
	var doc = window.document;
	
	var new_privacy = doc.getElementById('privacy').value == 1 ? 0 : 1;
	
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
		var fnWhenDone = function (oXML) {
		var user=oXML.responseText;
		selectUserForReservationHere( memberid );
	};
	myConn.connect(url, "POST", 'memberid='+memberid+'&privacy='+new_privacy , fnWhenDone);
}

var http_request = null;

function createRequestObject() {
	var request_obj = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		request_obj = new XMLHttpRequest();
		if (request_obj.overrideMimeType) {
			request_obj.overrideMimeType('text/xml');
		}
	}
	else if (window.ActiveXObject) { // IE
		try {
			request_obj = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				request_obj = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {}
		}
	}

	return request_obj;
}

function checkReservation(url, formid, txt) {
	var div = document.getElementById("checkDiv");
	var f = document.getElementById(formid);

	http_request = createRequestObject();
	http_request.onreadystatechange = showCheckResults;
	http_request.open('POST', url , true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	div.style.textAlign = "center";
	div.style.display = "inline";
	div.innerHTML = "<h4>" + txt + "..." + "</h4>";

	var keyValue = "";
	keyValue = buildKeyValueString(f, keyValue);

	http_request.send(keyValue);
}


function buildKeyValueString(f, keyValue) {
	for (var i = 0; i < f.elements.length; i++) {
		if (f.elements[i].name == "") { continue; }
		if (f.elements[i].type=="select-multiple") {
			for (var o = 0; o < f.elements[i].options.length; o++) {
				keyValue += f.elements[i].name + "=" + f.elements[i].options[o].value + "&";
			}
		}
		else {
			keyValue += f.elements[i].name + "=" + f.elements[i].value + "&";
		}
	}

	return keyValue;
}


function showCheckResults() {
	if (http_request.readyState == 4) {
		var txt = "";
		var div = document.getElementById("checkDiv");

		if (http_request.status == 200) {
			div.style.textAlign = "left";
			txt = http_request.responseText;
		}
		else {
			txt = "Error checking reservations";
		}

		div.innerHTML = txt;
	}
}


function add_activity() {
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	var fnWhenDone = function (oXML) {
		var new_activity=oXML.responseText;
		
		var lastRow = tbl.rows.length;
		var newRow = tbl.insertRow(lastRow);
		var newCell0 = newRow.insertCell(-1);
		newCell0.colSpan=9;
		newCell0.innerHTML = '<table border="0" cellpadding=0 cellspacing="0" width=100%><tr>'+new_activity+'</tr></table>';
		//newRow.innerHTML = new_activity;
		//div.innerHTML = new_activity;
	};
	
	var doc = window.document;
	var tbl = doc.getElementById("activities");

	
	counter=0;
	for (var o = 0; o < document.forms[0].elements.length; o++) {
		
		if((document.forms[0].elements[o].name.indexOf("activityTitle"))!=-1) {
			counter+=1;
			}
	}
	myConn.connect("./ajax_more_activities.php", "GET", "i=" + counter , fnWhenDone);

}

function add_schedule() {
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	
	$.blockUI({ message: '<h2><img src="img/loading.gif" /></h2>' });
	
	var fnWhenDone = function (oXML) {
		unblockUI();
		var new_schedule=oXML.responseText;
		
		var lastRow = tbl.rows.length;
		var newRow = tbl.insertRow(lastRow);
		var newCell0 = newRow.insertCell(-1);
		newCell0.colSpan=9;
		newCell0.innerHTML = '<table border="0" cellpadding=0 cellspacing="0" width=100%><tr>'+new_schedule+'</tr></table>';
		
		var i = document.getElementById("numTotSchedulesVisible").value;

		openCloseSchedulesTitle(document.getElementById('scheduleTitleDiv'+i), parseInt(i) ); 
		openCloseSchedules(document.getElementById('scheduleDiv'+i), parseInt(i) );
		
		document.getElementById("numTotSchedulesVisible").value = parseInt(document.getElementById("numTotSchedulesVisible").value) + 1;
		
	};
	
	var doc = window.document;
	var tbl = doc.getElementById("table_schedules");


	var counter=0;
	var counterDiv=0;
	/*
	for (var o = 0; o < document.forms[0].elements.length; o++) {
		
		if((document.forms[0].elements[o].name.indexOf("title"))!=-1) {
			counter+=1;
		}
		if((document.forms[0].elements[o].name.indexOf("scheduleDiv"))!=-1) {
			counterDiv+=1;
		}

	}
	*/
	
	counter = parseInt(document.getElementById("numTotSchedulesVisible").value) + parseInt(document.getElementById("numTotSchedulesPast").value);
	counterDiv = parseInt(document.getElementById("numTotSchedulesVisible").value);
	
	myConn.connect("./ajax_more_schedules.php", "GET", "i=" + counter + "&newScheduleDiv=" + counterDiv, fnWhenDone);

}

/**
*	This function retrive a generated password from the php server
*	AJAX
*	used in register.php
*/

function getGeneratedPassword() {

	// XMHLHttp Object
	var myConn = new XHConn();

	if ( !myConn ) {
		alert( "XMLHTTP not available. Try a newer/better browser." );
	}

	// function that will be called when the result is available
	var fnWhenDone = function ( oXML ) {

		var password = oXML.responseText;
		var pwdInfo = doc.getElementById( 'passwordInfo' );

		if ( password ) {
			doc.getElementById( 'password' ).value = password;
			doc.getElementById( 'password2' ).value = password;
			pwdInfo.style.visibility = 'visible';
		} else {
			pwdInfo.innerHTML = "<strong>There were errors generating the pwd.</strong>";
			pwdInfo.style.visibility = 'visible';
		}

		checkPasswords(true);
	};

	// current document reference
	var doc = window.document;

	// Init the connection
	myConn.connect( "register.php", "POST", "fn=generatePasswordButtonClicked" , fnWhenDone );
}

/**
* marks all rows and selects its first checkbox inside the given element
* the given element is usaly a table or a div containing the table or tables
*
* @param    container    DOM element
*/
function markAllRows( container_id ) {
	var rows = document.getElementById( container_id ).getElementsByTagName( 'tr' );
	var checkbox;
	var j = 0; // row id number
	
	for ( var i = 0; i < rows.length; i++ ) {

		checkbox = rows[i].getElementsByTagName( 'input' )[0];

		if ( checkbox && checkbox.type == 'checkbox' ) {
			if ( checkbox.disabled == false ) {
				checkbox.checked = true;
				adminRowClick( checkbox, 'tr'+j, j );
				j++;
			}
		}
	}
	return true;
}

/**
* unmarks all rows and selects its first checkbox inside the given element
* the given element is usaly a table or a div containing the table or tables
*
* @param    container    DOM element
*/
function unMarkAllRows( container_id ) {
	var rows = document.getElementById(container_id).getElementsByTagName('tr');
	var checkbox;
	var j = 0; // row id number
	for ( var i = 0; i < rows.length; i++ ) {

		checkbox = rows[i].getElementsByTagName( 'input' )[0];

		if ( checkbox && checkbox.type == 'checkbox' ) {
			checkbox.checked = false;
			checkbox.disabled = false;
			adminRowClick( checkbox, 'tr'+j, j);
			j++;
		}
	}

	return true;
}


function getCheckedValues( container_id, select_all_memberids  ) {
	var result = new Array();
	if( (select_all_memberids == '') || (select_all_memberids == null) || (select_all_memberids == undefined) ){
		var rows = document.getElementById( container_id ).getElementsByTagName( 'tr' );
		var checkbox;
		var j = 0;
		for ( var i = 0; i < rows.length; i++ ) {
			checkbox = rows[i].getElementsByTagName( 'input' )[0];
			if ( checkbox && checkbox.type == 'checkbox' ) {
				if ( checkbox.disabled == false ) {
					if ( checkbox.checked == true ) {
						result[j] = checkbox.value;
						j++;
					}
				}
			}
		}
	}else{
		var selectAllMemberids = select_all_memberids;
		selectAllMemberids = selectAllMemberids.split(",");
		result = selectAllMemberids;
	}
	return result;
}

function KeyCheck(e) {

	var KeyID = (window.event) ? event.keyCode : e.keyCode;

	if ( KeyID == 13 ) {
		return true;
	} else {
		return false;
	}
}

function saveSetting( key, value ) {
	// XMHLHttp Object
	var myConn = new XHConn();
	var checkbox = document.getElementById( key );
	var indicator = document.getElementById( key + '_indicator' );
	checkbox.style.display = 'none';
	indicator.style.display = 'block';

	if ( !myConn ) {
		alert( "XMLHTTP not available. Try a newer/better browser." );
	}

	// function that will be called when the result is available
	var fnWhenDone = function ( oXML ) {
		var result = oXML.responseText;
		if ( result == 'true' ) {
			setTimeout( function() { checkbox.style.display = 'block'; indicator.style.display = 'none'; }, 250 );
		} else {
			alert( 'Errore' );
		}
	};

	// current document reference
	var doc = window.document;

	// Init the connection
	myConn.connect( "ajax_save_config.php", "GET", "key=" + key + "&value=" + value , fnWhenDone );
}

/*
*	show send to selected buttons specified by media
*/
function showSendToSelected( media ) {
	var contactsDiv = document.getElementById('contactsDiv');
	var sms_send_1 = document.getElementById('sms_send_1');
	var sms_send_2 = document.getElementById('sms_send_2');
	var email_send_1 = document.getElementById('email_send_1');
	var email_send_2 = document.getElementById('email_send_2');
	//var html_email_send_1 = document.getElementById('html_email_send_1');
	//var html_email_send_2 = document.getElementById('html_email_send_2');
	//var fax_send_1 = document.getElementById('fax_send_1');
	//var fax_send_2 = document.getElementById('fax_send_2');
	var selectedMediaVar = document.getElementById('selectedMedia');
	selectedMediaVar.value = media;
	
	if ( contactsDiv.style.display == 'block' ) {
		if ( media == 'sms' ) {
			sms_send_1.style.display = 'block';
			sms_send_2.style.display = 'block';
			email_send_1.style.display = 'none';
			email_send_2.style.display = 'none';
			//html_email_send_1.style.display = 'none';
			//html_email_send_2.style.display = 'none';
			//fax_send_1.style.display = 'none';
			//fax_send_2.style.display = 'none';
		} else if (media == 'email') {
			sms_send_1.style.display = 'none';
			sms_send_2.style.display = 'none';
			email_send_1.style.display = 'block';
			email_send_2.style.display = 'block';
			//html_email_send_1.style.display = 'none';
			//html_email_send_2.style.display = 'none';
			//fax_send_1.style.display = 'none';
			//fax_send_2.style.display = 'none';
		} else if (media == 'fax') {
			sms_send_1.style.display = 'none';
			sms_send_2.style.display = 'none';
			email_send_1.style.display = 'none';
			email_send_2.style.display = 'none';
			//html_email_send_1.style.display = 'block';
			//html_email_send_2.style.display = 'block';
			//fax_send_1.style.display = 'block';
			//fax_send_2.style.display = 'block';
		}
	}
}

/*
 * Hides send all to selected buttons
 */
function hideSendToSelected() {
	var sms_send_1 = document.getElementById('sms_send_1');
	var sms_send_2 = document.getElementById('sms_send_2');
	var email_send_1 = document.getElementById('email_send_1');
	var email_send_2 = document.getElementById('email_send_2');
	//var fax_send_1 = document.getElementById('fax_send_1');
	//var fax_send_2 = document.getElementById('fax_send_2');
	sms_send_1.style.display = 'none';
	sms_send_2.style.display = 'none';
	email_send_1.style.display = 'none';
	email_send_2.style.display = 'none';
	//fax_send_1.style.display = 'none';
	//fax_send_2.style.display = 'none';
}

/*
 * Show/Hide contacts list and send button specified by media parameter
 */
function showContacts( media ) {
	var contactsDiv = document.getElementById('contactsDiv');
	var showContactsVar = document.getElementById('showContacts');
	var sendToNum = document.getElementById(media + 'SendToNum');
	var showSendToNum = document.getElementById('showSendToNum');
	var sendToAll = document.getElementById(media + 'SendToAll');
	var showSendToAll = document.getElementById('showSendToAll');
	var infoDiv = document.getElementById('sendInfoDiv');

	if ( contactsDiv.style.display == 'none' ) {
		contactsDiv.style.display = 'block';
		showContactsVar.value = 1;
		
		infoDiv.style.display = 'none';
		sendToAll.style.display = 'none';
		showSendToAll.value = 0;
		sendToNum.style.display = 'none';
		showSendToNum.value = 0;
		showSendToSelected( media );

		
	} else {
		contactsDiv.style.display = 'none';
		showContactsVar.value = 0;
		hideSendToSelected();	
	}
}

/*
 * Show/Hide alert message and send button specified by media parameter
 */
function showAlertSendToAll( media ) {
	var sendToAll = document.getElementById(media + 'SendToAll');
	var showSendToAll = document.getElementById('showSendToAll');
	var sendToNum = document.getElementById(media + 'SendToNum');
	var showSendToNum = document.getElementById('showSendToNum');
	var contactsDiv = document.getElementById('contactsDiv');
	var showContactsVar = document.getElementById('showContacts');
	var infoDiv = document.getElementById('sendInfoDiv');
	
	if ( sendToAll.style.display == 'none' ) {
		 sendToAll.style.display = 'block';
		 showSendToAll.value = 1;
		 
		 infoDiv.style.display = 'none';
		 sendToNum.style.display = 'none';
		 showSendToNum.value = 0;
		 contactsDiv.style.display = 'none';
		 showContactsVar.value = 0;
		 hideSendToSelected();
		 
	} else {
		sendToAll.style.display = 'none';
		showSendToAll.value = 0;
	}
}

/*
 * Show/Hide textarea and send button specified by media parameter
 */
function showAlertSendToNum( media ) {
	var sendToNum = document.getElementById(media + 'SendToNum');
	var showSendToNum = document.getElementById('showSendToNum');
	var sendToAll = document.getElementById(media + 'SendToAll');
	var showSendToAll = document.getElementById('showSendToAll');
	var contactsDiv = document.getElementById('contactsDiv');
	var showContactsVar = document.getElementById('showContacts');
	var infoDiv = document.getElementById('sendInfoDiv');
	
	if ( sendToNum.style.display == 'none' ) {
		 sendToNum.style.display = 'block';
		 showSendToNum.value = 1;
		 
		 infoDiv.style.display = 'none';
		 sendToAll.style.display = 'none';
		 showSendToAll.value = 0;
		 contactsDiv.style.display = 'none';
		 showContactsVar.value = 0;
		 hideSendToSelected();
		 
	} else {
		sendToNum.style.display = 'none';
		showSendToNum.value = 0;
	}
}

function unblockUI()
{
	$.unblockUI();
}

function refreshRegister( memberid ) {
	if ( window.opener.document.location.href.indexOf( 'reserve.php' ) ) {
		memberid_param = "&memberid=" + memberid;
		if ( window.opener.document.URL.indexOf('?') < 0 ) {
			memberid_param = "?" + memberid_param;
		}
	} else {
		memberid_param = "";
	}
	window.opener.document.getElementById('member_hidden').value = memberid;
	window.opener.selectUserForReservationHere( memberid ); 
	window.opener.document.getElementById('member').value = ''; 
	//window.opener.document.getElementById('s_memberid').selectedIndex = 2; 

	//window.opener.document.location.href = window.opener.document.URL + memberid_param;
}

/* Ripristina le preferenze temporanee quando si passa da un tab all'altro nell anteprima del modulo di 
 * di prenotazione
 */
function keep_preference(){
	var browser;
	var str="#";
	var name, id, value;
	 if (document.all) {
	 	 browser = 'IE';
	 }
	 else if (document.getElementById) {
	  	browser = 'FF';
	 }
	 
	
	for(var i=0; i< arguments.length; i++) {
		 if ( arguments[i]!=null && arguments[i]!='undefined' ){
		if( arguments[i].value!=""){
			id=arguments[i].id;
			name=arguments[i].name;
			value=arguments[i].value;
			if(browser=='IE'){
				if(id=='.big_table_box'){
					changecss('.tab_selected', 'backgroundColor', value);
					changecss('.tab_not_selected', 'backgroundColor', value);
				}
				if(id=='.big_table_box, .tab_selected, .tab_not_selected'){
						id='.tab_base';
						
						changecss('.tab_selected', 'borderColor', value);
						changecss('.tab_not_selected', 'borderColor', value);
						changecss('.second_button', 'borderLeftColor', value);
						changecss('.tab_riepilogo', 'borderColor', value);
						changecss('.big_table_box', 'borderColor', value);
						
				}
				if(id=='body, .link'){
						id='body';
						changecss('.link', 'color', value);
						changecss('.fields', 'color', value);
				}
				if(id=='.big_table_box'){
					changecss('.tab_selected', 'backgroundColor', value);
					changecss('.tab_not_selected', 'backgroundColor', value);
				}
		    }
		    if(browser=='FF'){
		    	if(id=='.big_table_box, .tab_selected, .tab_not_selected' && name=='borderColor'){
		    		changecss('.second_button', 'borderColor', value);
		  	    	changecss('.tab_riepilogo', 'borderColor', value);
		  	    }
		  	    if(id=='.big_table_box'){
		  	    	id='.big_table_box, .tab_selected, .tab_not_selected';
		  	    }
		  	    if (id=='body, .link'){
		  	    	changecss('.fields', 'color', value);
		  	    }
		    }			
			if( id=='.highlight_riepilogo a'){
					id='.highlight_riepilogo';
			}
			if( id=='.button a'){
				id='.button';
			}
		    value=str.concat(value);
		    if( name.match('Color') ){
		    	changecss(id, 'color', value);
		    	continue;
		    }
		    if (name.match('Bckgnd')){
		    	changecss(id, 'background-color', value);
		    	continue;
		    }
		    if( name.match('Border')){
				changecss(id, 'borderColor', value);
				continue;
		    }
		}
	}	
}
}
/* modifica gli attributi della classe css di una pagina
 * 
 */
function changecss(theClass,element,value) {
	 var cssRules;
	 if (document.all) {
	 	 cssRules = 'rules';
	 }
	 else if (document.getElementById) {
	  	 cssRules = 'cssRules';
	 }
	 var added = false;
	 	 
	 for (var S = 0; S < document.styleSheets.length; S++){
	 	ref = new String();
	 	ref= document.styleSheets[S].href;
	 	if( ref.match('localhost') != null || ref.match('tt_')!= null) {
				if(!ref.match('calend')){ 
	 				 for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
	 				 	
	 				 	var classe=document.styleSheets[S][cssRules][R].selectorText;
	 				 	classe=classe.toLowerCase(); //IE non sempre le restituisce in minuscolo
	   					if (classe == theClass) {
	   						if(document.styleSheets[S][cssRules][R].style[element]){
	    								document.styleSheets[S][cssRules][R].style[element] = value;
	    								added=true;
										break;
	   						}
	   					}
	  				}

				  	if(!added){
				  		 if(document.styleSheets[S].insertRule){
							  document.styleSheets[S].insertRule(theClass+' { '+element+': '+value+'; }',document.styleSheets[S][cssRules].length);
						 }
						 else if (document.styleSheets[S].addRule) {
								document.styleSheets[S].addRule(theClass,element+': '+value+';');
						 }
				  	}
				}
		}
	}
}

/*Serve per andare a leggere i valori degli attributi del css di una pagina
* Attenzione serve 
*/


function getCssStyle(theClass,element) {
	
	var cssRules;
	var temp;
	classe= new String();
	 if (isIE()) {
	 	 cssRules = 'rules';
	 	 mop = document.getElementById('wizardPreview');
	 	 mop=mop.contentWindow;
	 }
	 else { //firefox
	  		 cssRules = 'cssRules';
	  		 mop = frames[0];
	 } 
	 
	 for (var S = 0; S < mop.document.styleSheets.length; S++){
	 	 ref = new String();
	 	 ref= mop.document.styleSheets[S].href;
	 	 
	 	 if(ref.match('localhost') != null || ref.match('tt_')!= null) {
			if(!ref.match('calend')){ //esclude il css del calendario che rallenta
		 	 	for (var R = 0; R < mop.document.styleSheets[S][cssRules].length; R++) {
		 			classe= mop.document.styleSheets[S][cssRules][R].selectorText;
		 			classe=classe.toLowerCase();//IE alcune classi le ritorna maiuscole altri minuscole
		 					if(cssRules =='rules'){//IE
		 						if (classe == theClass) {
		 							classe=mop.document.styleSheets[S][cssRules][R].style[element];
		 							if(mop.document.styleSheets[S][cssRules][R].style[element]){
		 								temp=mop.document.styleSheets[S][cssRules][R].style[element];
		    								temp=temp.slice(1);//elimina il #
									
		    						}
		 						}
		 					}
		    				if(cssRules=='cssRules') {//FIREFOX
		    					if (classe == theClass) {
		 							classe=mop.document.styleSheets[S][cssRules][R].style[element];
		 							
		 							if(mop.document.styleSheets[S][cssRules][R].style[element]){
		 								temp=mop.document.styleSheets[S][cssRules][R].style[element];
		    							temp=rgbSplit(temp);
		 									    					
		    						}
		    					
		   						}
		  					}
		 	   	}
	 		}
		}
	}
	return temp;
}

/* per estrarre i valori di rosso verde e blu*/
function rgbSplit(string){
	var start= string.indexOf('(');
	var end= string.indexOf(')');
	var stringa= string.slice(start+1, end);
	stringa= stringa.split(', ');
	return RGBtoHex(stringa[0], stringa[1], stringa[2]);
}

function RGBtoHex(R,G,B) {
	return toHex(R)+toHex(G)+toHex(B)
}

function toHex(N) {
 	if (N==null)
 		 return "nd";
 	N=parseInt(N);
 	if (N==0 || isNaN(N)) 
 		return "00";
 	N=Math.max(0,N); 
 	N=Math.min(N,255);
 	N=Math.round(N);
 	return "0123456789abcdef".charAt((N-N%16)/16)
      + "0123456789abcdef".charAt(N%16);
}

function save_color(){
	var browser;
	 if (isIE()) {
	 	 browser = 'IE';
	 }
	 else if (document.getElementById) {
	  	browser = 'FF';
	 }
	for(var i=0; i<arguments.length; i++){
		if( arguments[i].value==""){
			var temp=arguments[i].id;
			if( temp.match(" a")!= null || temp=='body, .link'){
				if(temp=='.highlight_riepilogo a'){
					temp='.highlight_riepilogo';
				}
				if(temp=='.button a'){
					temp='.button';
				}
				if(temp=='body, .link'){
					if(browser=='IE'){
						temp='body';
					}
				}
				arguments[i].value=getCssStyle(temp, 'color');
				continue;
			}
			if(temp=='.big_table_box, .tab_selected, .tab_not_selected') {
				if(browser=='IE'){
					temp='.big_table_box';
				}
				arguments[i].value=getCssStyle(temp, 'borderColor');
				continue;
			}
			if(temp=='.big_table_box'){
				if(browser=='FF'){
					temp='.big_table_box, .tab_selected, .tab_not_selected';
				}
			}
			arguments[i].value=getCssStyle(temp, 'backgroundColor');
			continue;
		}
	}
}

function reset_input(){
	for(var i=0; i< arguments.length; i++){
		arguments[i].value="";
	}
}

function rsOver(cell){
	document.getElementById('arrow_'+cell.id).src='img/arrow1.png';cell.className='resourceNameOver';
}
function rsOut(cell){
	document.getElementById('arrow_'+cell.id).src='img/arrow2.png';cell.className='resourceName';
}

function changeFn(fn, value){
	fn.value = value;
}

function reservationTooltipContent( summary, clientFirstName, clientLastName, activityTitle, typologyTitle, startTime, endTime, messageStatus, linkDelete, linkCompleted, linkNoshow ) {
	// retrive the global variable that contains the template
	var template = reservationTooltipTemplate;
	template = template.replace( /summary/i, summary );
	template = template.replace( /clientFirstName/i, clientFirstName );
	template = template.replace( /clientLastName/i, clientLastName );
	template = template.replace( /activityTitle/i, activityTitle );
	template = template.replace( /typologyTitle/i, typologyTitle );
	template = template.replace( /startTime/i, startTime );
	template = template.replace( /endTime/i, endTime );
	template = template.replace( /messageStatus/i, messageStatus );
	template = template.replace( /linkDelete/i, linkDelete );
	template = template.replace( /linkCompleted/i, linkCompleted );
	template = template.replace( /linkNoshow/i, linkNoshow );
	return template;
}

function resourceTooltipContent( name, linkModify, linkDelay, linkOverbook, displayDelayLink, linkSchedule ) {
	// retrive the global variable that contains the template
	var template = resourceTooltipTemplate;
	template = template.replace( /name/, name );
	template = template.replace( /linkModify/, linkModify );
	template = template.replace( /linkDelay/, linkDelay );
	template = template.replace( /linkOverbook/, linkOverbook );
	template = template.replace( /displayDelayLink/, displayDelayLink );
	template = template.replace( /linkSchedule/, linkSchedule );
	return template;
}

function areaTooltipContent( linkAddResource, linkEditArea ) {
	var template = areaTooltipTemplate;
	template = template.replace( /linkAddResource/, linkAddResource );
	template = template.replace( /linkEditArea/, linkEditArea );
	return template;
}

function tiactionTooltipContent( name,linkLogin, linkEditConf, linkLog, linkCredits, linkReminder, linkPoll, linkPollCampaign, linkShowDump, linkRestore, linkDel, linkReactive, linkLogReminder, displayLink, linkClone ) {
	// retrive the global variable that contains the template
	var template = tiactionTooltipTemplate;
	template = template.replace( /name/, name );
	template = template.replace( /linkLogin/, linkLogin );
	template = template.replace( /linkEditConf/, linkEditConf );
	template = template.replace( /linkLog/, linkLog );
	template = template.replace( /linkCredits/, linkCredits );
	template = template.replace( /linkReminder/, linkReminder );
	template = template.replace( /linkLogReminder/, linkLogReminder );
	template = template.replace( /linkPoll/, linkPoll );
	template = template.replace( /linkPollCampaign/, linkPollCampaign );
	template = template.replace( /linkShowDump/, linkShowDump );
	template = template.replace( /linkRestore/, linkRestore );
	template = template.replace( /linkDel/, linkDel );
	template = template.replace( /linkReactive/, linkReactive );
	template = template.replace( /linkClone/, linkClone );
	template = template.replace( /displayLink/, displayLink );
	
	
	
	return template;
}

function setCaretPosition( elemId, caretPos ) {
	if ( elemId ) {
    	var elem = document.getElementById( elemId );
	}

    if ( elem != null ) {
        if ( elem.createTextRange ) {
            var range = elem.createTextRange();
            range.move( 'character', caretPos );
            range.select();
        } else {
            if ( elem.selectionStart ) {
                elem.focus();
                elem.setSelectionRange( caretPos, caretPos );
            } else {
                elem.focus();
            }
        }
    }
}

function changePrivacyManageUser( url, memberid, privacy ) {
	var doc = window.document;
	
	var new_privacy = privacy;
	var changeNot = function (){
		changePrivacyManageUser('ajax_change_privacy.php', memberid, 0);
	}
	var changeYes = function (){
		changePrivacyManageUser('ajax_change_privacy.php', memberid, 1);
	}
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
		var fnWhenDone = function (oXML) {
		var privacy=oXML.responseText;
		var id = memberid+'Privacy'
		if ( privacy==1 ){
			document.getElementById(id).src = "img/ok.gif";
			document.getElementById(id).onclick = changeNot;
		}else{
			document.getElementById(id).src = "img/no.gif";
			document.getElementById(id).onclick = changeYes;
		}
		
	};
	myConn.connect(url, "POST", 'memberid='+memberid+'&privacy='+new_privacy , fnWhenDone);
}

/**
 * This function is to check the maxlenght attribute on HTML textareas
 */
function ismaxlength( obj ) {
	var mlength = obj.getAttribute ? parseInt( obj.getAttribute( "maxlength" ) ) : "";
	if ( obj.getAttribute && obj.value.length > mlength ) {
		obj.value = obj.value.substring( 0, mlength );
	}
}

/**
* change style of element_to_show
*/
function openCloseActivityDescription(element_to_show, num){
	if(element_to_show.style.display == 'block' ){
		element_to_show.style.display = 'none';
		changeActivityLink(num);
	}else{
		element_to_show.style.display = 'block';
		changeActivityLink(num);
		closeAllDescription(num);
	}
}
/**
* change style of element_to_show
*/
function openCloseNoteMop(element_to_show){
	if(element_to_show.style.display == 'block' ){
		element_to_show.style.display = 'none';
	}else{
		element_to_show.style.display = 'block';
	}
}

/**
* change style of descritionDiv to none and change style of link 
*/
function closeAllDescription(num){
	var i=0;
	while (document.getElementById("descriptionDiv"+i)!=null){
		if(i != num){
			document.getElementById("descriptionDiv"+i).style.display='none';
			document.getElementById("openLink"+i).style.display = 'block';
			document.getElementById("closeLink"+i).style.display = 'none';
		}
		i++
	}
}

/**
* change style of link 
*/
function changeActivityLink(num){
	var i = num;
	if(document.getElementById("openLink"+i).style.display == 'none'){
		document.getElementById("openLink"+i).style.display = 'block';
		document.getElementById("closeLink"+i).style.display = 'none';
	}else{
		document.getElementById("openLink"+i).style.display = 'none';
		document.getElementById("closeLink"+i).style.display = 'block';
	}
}

function setElementVisibility(elementToSet, showItSwitch, keepPlacementSwitch){
 if (showItSwitch) {
   elementToSet.style.display = "";
   elementToSet.style.visibility = "visible";
 }
 else{
   if (keepPlacementSwitch) {
    // elementToSet.style.display = "inline";
     elementToSet.style.visibility = "hidden";
   }
   else{
     elementToSet.style.display = "none";
   }
 }
}

/**
* change style of schedulesTitleDiv to none 
*/
function openCloseSchedulesTitle(element_to_show, num){
	if(element_to_show.style.display == 'block' ){
		element_to_show.style.display = 'none';
		
		openAllSchedulesTitle(num);
		
	}else{
		element_to_show.style.display = 'block';
	}
}

/**
* change style of all schedulesTitleDiv to block 
*/
function openAllSchedulesTitle(num){
	var i=0;
	while (document.getElementById("scheduleTitleDiv"+i)!=null){
		if(i != num){
			document.getElementById("scheduleTitleDiv"+i).style.display='block';
		}
		i++;
	}
}

function deleteSchedule(hidden_to_del, num){
	hidden_to_del.value = 1;
	// aggiungo una linea sopra lo schedule da eliminare e non lo rendo più editabile
	var scheduleTitleDiv = document.getElementById("scheduleTitleDiv"+num);
	var scheduleDiv = document.getElementById("scheduleDiv"+num);
	var scheduleTitle = document.getElementById("scheduleTitle"+num);
	var scheduleTitleLink = document.getElementById("scheduleTitleLink"+num);
	var scheduleEdit = document.getElementById("scheduleEdit"+num);
	
	scheduleTitleLink.style.textDecoration= "none";
	scheduleTitleLink.onclick= "";
	//scheduleTitle.removeChild(scheduleTitleLink);
	scheduleTitle.style.textDecoration= "line-through";
	scheduleTitleDiv.style.display='block';
	scheduleEdit.style.display='none';
	scheduleDiv.style.display='none';
}

function refreshSchedulePreview(change_value, field_title, span_title){
	
	var field_preview = document.getElementById(field_title);
	var span_preview = document.getElementById(span_title);
	
	field_preview.value = change_value;
	
	if(change_value.length > 0){
		span_preview.style.visibility='visible';
	}else{
		span_preview.style.visibility='hidden';
	}
}

/**
* change style of schedulesDiv to none 
*/
function openCloseSchedules(element_to_show, num){
	if(element_to_show.style.display == 'block' ){
		element_to_show.style.display = 'none';
	}else{
		
		if(num==0){
			if( document.getElementById('useInstanceSchedule').value == 'true' ){
				document.getElementById('instanceSchedule').style.display = 'block';
				document.getElementById('customizeLink').style.display = 'block'; 
			}else{
				document.getElementById('resourceSchedules').style.display = 'block';
				document.getElementById('backLink').style.display = 'block';
				element_to_show.style.display = 'block';
			}
		}else{
			element_to_show.style.display = 'block';
		}
		
		closeAllSchedules(num);
	}
}

/**
* change style of all schedulesDiv to none 
*/
function closeAllSchedules(num){
	var i=0;
	while (document.getElementById("scheduleDiv"+i)!=null){
		if(i != num){
			document.getElementById("scheduleDiv"+i).style.display='none';
		}
		i++;
	}
	if(num != 0){
		document.getElementById('instanceSchedule').style.display = 'none'; 
		document.getElementById('resourceSchedules').style.display = 'block'; 
		document.getElementById('customizeLink').style.display = 'none'; 
		document.getElementById('backLink').style.display = 'none';
	}
}

/**
* Detecting Carriage Return / Enter Key Presses in Text Fields and Textareas
* Detecting an enter/return key press within a text input or textarea is a common scripting 
* task when it comes to handling user interaction within forms. The ability to detect this particular 
* keyboard event allows a form to be submitted - or not submitted - when the enter key (PC) or return key (Mac) is pressed. 
*/
function checkEnter(e, form_submit){ //e is event object passed from function invocation
	var characterCode; 	//literal character code will be stored in this variable

	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 == 13){ //if generated character code is equal to ascii 13 (if enter key)
	if(form_submit){
		document.getElementById('search').value = document.getElementById('setCursor').value;
		document.forms[form_submit].submit(); //submit the form
	}
	return false;
	}
	else{
	return true;
	}

}

function setVoiceTwCheckboxHidden() {
	
	var checkTW   	  = document.getElementById( 'e_reminder_voice_tw' );
	var checkCancel   = document.getElementById( 'e_reminder_voice_tw_cancel' );
	var checkConfirm  = document.getElementById( 'e_reminder_voice_tw_confirm' );
	var checkTransfer = document.getElementById( 'e_reminder_voice_tw_transfer' );
	
	if ( checkCancel.checked == true || checkCancel.Confirm == true || checkTransfer.checked == true ) {
		
		checkTW.checked = true;
			
	} else {	
		
		checkTW.checked = false;
	}

}

/*
 * Show mode edit activity by num row parameter
 */
function showEditActivity( row, num_changed_td ) {
	
	var edit_tr = document.getElementById('edit_tr'+row);
	
	var tr = document.getElementById('tr'+row);
	
	for (var i=1; i <= num_changed_td; i++) {
		
		var show = document.getElementById('show_'+row+'_'+i);
		var edit = document.getElementById('edit_'+row+'_'+i);
		
		show.style.display = 'none';
		edit.style.display = 'block';
	}
	
	edit_tr.style.display = '';
	
}

/*
 * Hide mode edit activity by num row parameter
 */
function hideEditActivity( row, num_changed_td ) {
	
	var edit_tr = document.getElementById('edit_tr'+row);
	
	var tr = document.getElementById('tr'+row);
	
	for (var i=1; i <= num_changed_td; i++) {
		
		var show = document.getElementById('show_'+row+'_'+i);
		var edit = document.getElementById('edit_'+row+'_'+i);
		
		show.style.display = 'block';
		edit.style.display = 'none';
	}
	
	edit_tr.style.display = 'none';
	
}

/*
 * show new row to insert a new activity
 */
function addNewActivity( row ) {
	
	var edit_tr = document.getElementById('edit_tr'+row);
	
	var tr = document.getElementById('tr'+row);
	
	tr.style.display = '';
	edit_tr.style.display = '';
	
}

/*
 * close new row to insert a new activity
 */
function closeNewActivity( row ) {
	
	var edit_tr = document.getElementById('edit_tr'+row);
	
	var tr = document.getElementById('tr'+row);
	
	tr.style.display = 'none';
	edit_tr.style.display = 'none';
	
}

/**
* marks all rows and highlights selected rows
*
* @param    
*/
function markAllActivities( num_activities_in_this_page ) {
	
	var checkbox;
	var j = 0; // row id number
	
	for ( var i = 0; i < num_activities_in_this_page; i++ ) {

		checkbox = document.getElementById( 'check_activity'+i );

		if ( checkbox && checkbox.type == 'checkbox' ) {
			if ( checkbox.disabled == false ) {
				checkbox.checked = true;
				adminRowClick( checkbox, 'tr'+j, j );
				j++;
			}
		}
	}
	return true;
}

/**
* unmarks all rows
*
* @param   
*/
function unMarkAllActivities( num_activities_in_this_page ) {
	
	var checkbox;
	var j = 0; // row id number
	for ( var i = 0; i < num_activities_in_this_page; i++ ) {

		checkbox = document.getElementById( 'check_activity'+i );

		if ( checkbox && checkbox.type == 'checkbox' ) {
			checkbox.checked = false;
			adminRowClick( checkbox, 'tr'+j, j);
			j++;
		}
	}

	return true;
}

function switchManageActivity(form){
	
	var switch_hidden = document.getElementById( 'switch' );
	
	if (switch_hidden.value == 'activities'){
		switch_hidden.value = 'typologies';
	}else{
		switch_hidden.value = 'activities';
	} 
	
	document.forms[form].submit();
}

//--- MANAGE_USER ---------------------------------------------- //
//-------------------------------------------------------------- //
function openCloseViewProfile(){

	var openClose =  document.getElementById('openCloseArrow');
	
	var viewProfile2 = document.getElementById('viewProfile2');
	var viewProfile3 = document.getElementById('viewProfile3');

	if( viewProfile2.style.display == 'none' || viewProfile3.style.display == 'none'){
		viewProfile2.style.display = '';
		viewProfile3.style.display = '';
		openClose.src = "img/profile_arrow_open.jpg";
	}else{
		viewProfile2.style.display = 'none';
		viewProfile3.style.display = 'none';
		openClose.src = "img/profile_arrow_close.jpg";
	}
}

function openEditProfile(){

	document.getElementById('viewProfileDiv1').style.display = 'none';
	document.getElementById('editProfileDiv1').style.display = '';
	closeUserTable('reservations');
	closeUserTable('messages');
	closeUserTable('recalls');
}

function closeEditProfile(){

	document.getElementById('viewProfileDiv1').style.display = '';
	document.getElementById('editProfileDiv1').style.display = 'none';
}

function openUserTable( tab ){

	var table = '';
	
	table = 'reservations';
	var closeRes 	= document.getElementById( table + '_close');
	var openRes 	= document.getElementById( table + '_open');
	if( tab == table ){
		if( closeRes.style.display == '' ){
			openRes.style.display 	= '';
			closeRes.style.display 	= 'none';
			closeEditProfile();
		}
	}else{
		if( openRes.style.display == '' ){
			openRes.style.display 	= 'none';
			closeRes.style.display 	= '';
		}
	}

	table = 'messages';
	var closeMes 	= document.getElementById( table + '_close');
	var openMes		= document.getElementById( table + '_open');
	if( tab == table ){
		if( closeMes.style.display == '' ){
			openMes.style.display 	= '';
			closeMes.style.display 	= 'none';
			closeEditProfile();
		}
	}else{
		if( openMes.style.display == '' ){
			openMes.style.display 	= 'none';
			closeMes.style.display 	= '';
		}
	}

	table = 'recalls';
	var closeRec 	= document.getElementById( table + '_close');
	var openRec		= document.getElementById( table + '_open');
	if( tab == table ){
		if( closeRec.style.display == '' ){
			openRec.style.display 	= '';
			closeRec.style.display 	= 'none';
			closeEditProfile();
		}
	}else{
		if( openRec.style.display == '' ){
			openRec.style.display 	= 'none';
			closeRec.style.display 	= '';
		}
	}
}

function closeUserTable( table ){

	var close 	= document.getElementById( table + '_close');
	var open 	= document.getElementById( table + '_open');

	if( open.style.display == '' ){
		open.style.display 		= 'none';
		close.style.display 	= '';
	}
}
// -------------------------------------------------------------- //