// Seanergic's object
var seanergic = {

	// common functions
	common: {},
	
	// top menu functions
	topMenu: { canHide: [] }
};

// Hide an Html form
seanergic.common.hideHtmlElment = function(elmentName) {
	
	if(document.getElementById(elmentName)) {

		document.getElementById(elmentName).style.display = "none";
	}
	
}

// Show an Html form
seanergic.common.showHtmlElment = function(elmentName) {
	
	if(document.getElementById(elmentName)) {

		document.getElementById(elmentName).style.display = "block";
	}
	
}

// Show the connection form
seanergic.common.showConnect = function() {
	
	seanergic.common.hideHtmlElment('fastConnectLink');
	seanergic.common.showHtmlElment('fastConnectForm');	
}

// Hide the connection form
seanergic.common.hideConnect = function() {
	
	seanergic.common.hideHtmlElment('fastConnectForm');	
	seanergic.common.showHtmlElment('fastConnectLink');
}

// Show a submenu in the top menu
seanergic.topMenu.show = function(subMenuName) {
	if(document.getElementById(subMenuName)) {
		seanergic.topMenu.canHide[subMenuName] = false;
		seanergic.common.showHtmlElment(subMenuName);
	}
}

// Hide a submenu in the top menu
seanergic.topMenu.hide = function(subMenuName) {	
	if(seanergic.topMenu.canHide[subMenuName] == true) {
		seanergic.common.hideHtmlElment(subMenuName);	
	} else {
		setTimeout("seanergic.topMenu.hide('" + subMenuName + "')", 100);	
	}
}

// Allow hidding
seanergic.topMenu.allowHide = function(subMenuName) {	
	seanergic.topMenu.canHide[subMenuName] = true;
	setTimeout("seanergic.topMenu.hide('" + subMenuName + "')", 100);	
}

// Cancel a hide action
seanergic.topMenu.dontHide = function(subMenuName) {	
	seanergic.topMenu.canHide[subMenuName] = false;
}

// Affect a sub-menu to and HTML element
seanergic.topMenu.affect = function(submenuId, elementId) {
	
	if(document.getElementById(submenuId) == null || document.getElementById(elementId) == null)
		return;
	
	var submenu = document.getElementById(submenuId);
	var element = document.getElementById(elementId);
	
	submenu.onmouseover = function() { seanergic.topMenu.dontHide(submenuId); }; 
	submenu.onmouseout = function() { seanergic.topMenu.allowHide(submenuId); };
	
	element.onmouseover = function() { seanergic.topMenu.show(submenuId); };
	element.onmouseout = function() { seanergic.topMenu.allowHide(submenuId); };
}

// Clear or set a field on the focus, depending on a value
seanergic.common.setDefaultValue = function(feildId, dValue) {
	
	if(!document.getElementById(feildId))
		return;
		
	var feild = document.getElementById(feildId);

	feild.onfocus = function() {
		if(this.value == dValue) {
			this.value = "";
		}
	}
	
	feild.onblur = function() {
		if(this.value == "") {
			this.value = dValue;
		}
	}
}
