function moveResize(_width, _height)	{
	window.moveTo((window.screen.width - _width)/2, (window.screen.height - _height/2));
	window.resizeTo(_width, _height);
}

function openpopup(url, w, h)	{

	_top  = (screen.height - h) / 2
	_left = (screen.width  - w) / 2;
	option = "top="+_top+",left="+_left+",width="+w+",height="+h+",status=no,toolbar=no,menubar=no,location=no";
	winPopup = window.open(url,'',option);
	winPopup.focus();
}

/* * * * * * * * * * * * * * */
function checkAll(btn)	{
	itemId = btn.form['itemId[]'];
	if (itemId.length)	{
		for (i=0; i<itemId.length; i++)	{
			itemId[i].checked = btn.checked;
		}
	} else {
		itemId.checked = btn.checked;
	}
}

function deleteSelected(btn, notConfirmAction)	{
	itemId = btn.form['itemId[]'];
	if (itemId.length == undefined && itemId.checked)	{
		itemChecked = 1;
	} else {
		itemChecked = 0;
		for (i=0; i<itemId.length; i++)	{
			if (itemId[i].checked)	{
				itemChecked++;
			}
		}
	}
	if (itemChecked == 0)	{
		alert('Devi selezionare almeno un elemento da eliminare');
		return;
	}
	if (notConfirmAction)	{
		btn.form.submit();
		return;
	}
	if (confirm("\n\nHai scelto di Eliminare [ "+itemChecked+" ] elemeto/i\n\nVuoi davvero completare l'operazione?\n\n"))	{
		btn.form.submit();
	}
}

function syncToRole(btn)	{
	itemId = btn.form['itemId[]'];
	if (itemId.length == undefined && itemId.checked)	{
		itemChecked = 1;
	} else {
		itemChecked = 0;
		for (i=0; i<itemId.length; i++)	{
			if (itemId[i].checked)	{
				itemChecked++;
			}
		}
	}
	if (itemChecked == 0)	{
		alert('Devi selezionare almeno un utente da sincronizzare');
		return;
	}
	if (btn.form.role.value == '')	{
		alert('Devi selezionare un ruolo');
		return;
	}
	if (confirm('Vuoi davvero sincronizzare i ['+itemChecked+'] utenti selezionati ?'))	{
		btn.form.action = btn.form.action.replace('Delete','SyncToRole');
		btn.form.submit();
	}
}

function help(id, show)	{
	dhelp = document.getElementById(id);
	if (dhelp)	{
		dhelp.style.display = show ? "block":"none";
	}
	return false;
}

function propose(itm)	{

	itm.form.elements['porto'].value =
		 itm.form.elements['hpropose'].options[itm.form.elements['hpropose'].selectedIndex].value;
}

/**
 * FCKeditor inizialized
 */
var _FCK_EDITOR_ENABLED_ = true;
//var _FCK_EDITOR_ENABLED_ = false;

function ini_fck(fck_field_name, fck_width, fck_height) {

	if (_FCK_EDITOR_ENABLED_)	{

		var oFCKeditor = new FCKeditor(fck_field_name);
		oFCKeditor.Height = (fck_height) ? fck_height : "300";
		oFCKeditor.Width = (fck_width && false) ? fck_width : "100%";
		oFCKeditor.BasePath = "/FCK/"
		oFCKeditor.ReplaceTextarea() ;
  }
}


var lastHidden = 0;
function showHide(img, id)    {
 if (id != lastHidden)	{
 	initShowHide();
 }
 lastHidden = id;
 if (mitem = document.getElementById(id)) {
	if (mitem.style.display == "none") {
		mitem.style.display = "block";
		img.src = "images/002.gif"
	 } else {
		mitem.style.display = "none";
		img.src = "images/001.gif"
 	}
 }
}

function initShowHide()	{
	return;
	aClass = document.getElementsByTagName('div');
	for (i=0;i<aClass.length;i++)	{
		if (aClass[i].className == 'hidden_tb')	{
			aClass[i].style.display = "none";
		}
	}
	aImage = document.getElementsByTagName('img');
	for (i=0;i<aImage.length;i++)   {
                if (aImage[i].className == 'showHideBtn') {
                        aImage[i].src = "images/001.gif";
                }
        }
}

/**
 * YTH SlideShow
 */
var slideShowA = new Array();
var slideShowCounter = 0;

function slideShowNext()	{

	if (slideShowA.length == 0)	{
		document.images['slideShowImage'].style.display='none';
		document.getElementById('slideShowTr').style.display='none';
		return;
	}

	if (slideShowA.length == 1 && document.getElementById('slideShowTr'))	{
		document.getElementById('slideShowTr').style.display='none';
	}

	if (++slideShowCounter < slideShowA.length)	{
		document.images['slideShowImage'].src = slideShowA[slideShowCounter].src;
	} else {
		slideShowCounter = 0;
		document.images['slideShowImage'].src = slideShowA[slideShowCounter].src;
	}

	if (document.getElementById('innerCounter'))	{
		document.getElementById('innerCounter').innerText = (slideShowCounter +1 ) + " / " + slideShowA.length;
	}
}

function slideShowPrev()	{
	if (slideShowA.length == 0)	{ document.images['slideShowImage'].style.display='none'; return; }
	if (--slideShowCounter > -1)	{
		document.images['slideShowImage'].src = slideShowA[slideShowCounter].src;
	} else {
		slideShowCounter = slideShowA.length - 1;
		document.images['slideShowImage'].src = slideShowA[slideShowCounter].src;
	}
	if (document.getElementById('innerCounter'))	{
		document.getElementById('innerCounter').innerText = (slideShowCounter +1 ) + " / " + slideShowA.length;
	}
}


function userInfo(field, url)	{
	idx = field.form.elements['yachts[owner]'].selectedIndex;
	if (idx == 0)	{
		alert('Selezionare un utente');
		return;
	}

	document.location.href = "/" + url + "/Users/Users/Edit/" +
		field.form.elements['yachts[owner]'].options[idx].value;
}

var lastMenuOpen = false;
function showMenu(id)	{	return true; // DISABLED
	if (_item = document.getElementById(id)) {
		if (_item.style.display == "block") {
			_item.style.display = "none";
		} else {
			if (lastMenuOpen) {
				lastMenuOpen.style.display = "none";
			}
			_item.style.display = "block";
		}
		lastMenuOpen = _item;
	}
}

function msMainMenuHover()	{

	uri = self.location.href;
	aDiv = document.getElementById('mainMenu').getElementsByTagName('div');
	for (i=0; i<aDiv.length;i++)	{
		if (aDiv[i].className != 'smenu')	{
			aDiv[i].onmouseover = function() {this.style.backgroundColor = "#F0F0F0";}
			aDiv[i].onmouseout = function() {this.style.backgroundColor = "transparent";}
		} else {
			aDiv[i-1].onmouseover = function() {}
			aDiv[i-1].onmouseout = function() {}

			aLink = aDiv[i].getElementsByTagName('a');
			for(a=0;a<aLink.length;a++) {

				if (uri.match(aLink[a].href+"$")) {
// 					aLink[a].style.backgroundColor = "red";
					showMenu(aDiv[i].id);
				}
			}
		}
	}
}


function privacyConfirm(btn, message)	{

	if (btn.form.privacy.checked) {
		btn.form.submit();
		return true;
	} else {
		alert(message);
		return false;
	}
}