// JavaScript Document


window.multiMenu = new Object();

window.multiMenu.add = function( id, linkHref, decoration, parentItem, path, target ){
	window.multiMenu[id] = new Object();
	window.multiMenu[id].linkHref = linkHref;
	window.multiMenu[id].decoration = decoration;
	window.multiMenu[id].parentItem = parentItem;
	window.multiMenu[id].path = path;
	window.multiMenu[id].target = target;
	
	
}

function loadContent( href, itemId ){
	
	//alert( window.currentAction );

	//window.location.href = href + "&bid="+itemId+"&lang="+window.currentLanguage;
	
	if( window.currentAction == "edit" ) {
		window.location.href = href + "&bid="+itemId+"&lang="+window.currentLanguage+"&action="+window.currentAction;
	} else {
		if( !window.multiMenu[itemId].target ){
			href += "&bid="+itemId+"&lang="+window.currentLanguage+"&action="+window.currentAction;
			request_content( href, "Page", update_content ); 
			
		}
	}
}

function hide_intro(){
	var intro = document.getElementById( 'mainIntroBox' );
	
	if( intro ){
		intro.style.display = 'none';	
	}
}



function set_menu( subMenuId, topMenuId ){
	
	var topMenuItem = document.getElementById( topMenuId );
						                        
	var subMenuItem = document.getElementById( subMenuId );
	

	//subMenu_<?=$itemIndex?>.style.left = topMenuItem.offsetLeft + topMenu.offsetLeft - 7 + "px";
	
	
	subMenuItem.style.left = topMenuItem.offsetLeft - 6 + "px";
}


function menu_link_remover( menuName ){
	
	var itemIndex = 0;

	var itemId = menuName+ "Link_" + itemIndex;
	var menuItem = document.getElementById( itemId );
			
	while( menuItem ){
		if( !window.multiMenu[itemId].target ){
			menuItem.removeAttribute( "href" );
		}
		itemIndex++;
		itemId = menuName+ "Link_" + itemIndex;
		menuItem = document.getElementById( itemId );
	}                
	
	//alert( menuName + " " + itemIndex + " Removed" );
}   	   

function menu_press( itemId ){

	highlight_menu( itemId );
	
	
	
	loadContent(window.multiMenu[itemId].linkHref, itemId);
		
	
}	

function highlight_menu( itemId ){

	imageId = itemId.replace( /Link/, "Image" );
	
	var menuItem = document.getElementById( itemId );
	var menuImage = document.getElementById( imageId );

	if( menuItem && menuImage ){

		if( window.selectedMenuItem ){
			
			/*
			recentItemId = window.selectedMenuItem;
			recentImageId = recentItemId.replace( /Link/, "Image" );
			
			var recentItem = document.getElementById( window.selectedMenuItem );
			var recentImage = document.getElementById( recentImageId );
			
			if( recentItem && recentImage  ){
				recentImage.src = window.multiMenu[recentItemId].path +".jpg";
			}
			*/
		}
		
		menuImage.src = window.multiMenu[itemId].path +"_over.jpg";
		window.selectedMenuItem = itemId;

	}
	


}


function top_menu_over( itemId, subMenuId ){

	imageId = itemId.replace( /Link/, "Image" );
	
	var menuItem = document.getElementById( itemId );
	var menuImage = document.getElementById( imageId );
	
	if( menuItem && menuImage ){
		menuImage.src = window.multiMenu[itemId].path + "_over.jpg";
		
	}
	
	var subMenu  = document.getElementById( subMenuId );
	
	if( subMenu ){
		subMenu.style.visibility = "visible";	
	}
	

}




function top_menu_out( itemId, subMenuId, evt ){
	

	if( !evt ){
		var evt = window.event;
	}
	

	var targetId = ( evt.toElement ? evt.toElement.id : false );
	
	if( !targetId ){
	 targetId = ( evt.relatedTarget ? evt.relatedTarget.id : false  );
	} 
	
	if( !targetId ){
		return;	
	}
	
	//alert( targetId );
	
	if( targetId.substr( 0, 7 ) == "subMenu" ){
		return;	
	}
	
	imageId = itemId.replace( /Link/, "Image" );
	
	var menuItem = document.getElementById( itemId );
	var menuImage = document.getElementById( imageId );
	
	if( menuItem && menuImage ){ //&& ( window.selectedMenuItem != itemId ) ){
		menuImage.src = window.multiMenu[itemId].path +".jpg";
		
	}
	
	var subMenu  = document.getElementById( subMenuId );
	
	if( subMenu ){
		subMenu.style.visibility = "hidden";	
	}
	
}



function sub_menu_out( subMenuId, itemId, evt ){

	if( !evt ){
		var evt = window.event;
	}

	var targetId = ( evt.toElement ? evt.toElement.id : false );
	
	if( !targetId ){
	 targetId = ( evt.relatedTarget ? evt.relatedTarget.id : false  );
	} 
	
	if( !targetId ){
		return;	
	}
	
	//alert( targetId );
	
	if( targetId.substr( 0, 7 ) == "subMenu" ){
		return;	
	}
		
	var subMenu = document.getElementById( subMenuId );
	
	
	if( subMenu ){
		subMenu.style.visibility = "hidden";	
	}
	
	imageId = itemId.replace( /Link/, "Image" );
	
	var menuItem = document.getElementById( itemId );
	var menuImage = document.getElementById( imageId );
	
	if( menuItem && menuImage ){// && ( window.selectedMenuItem != itemId ) ){
		menuImage.src = window.multiMenu[itemId].path +".jpg";
	}
	
	
}

function sideSub_press( itemId ){
}

function sideSub_menu_out( itemId ){
}

function sideSub_menu_over( itemId ){
}

function menu_over( itemId ){

	imageId = itemId.replace( /Link/, "Image" );
	
	var menuItem = document.getElementById( itemId );
	var menuImage = document.getElementById( imageId );
	
	if( menuItem && menuImage ){
		menuImage.src = window.multiMenu[itemId].path +"_over.jpg";
	}
	

}





function menu_out( itemId ){
	
	imageId = itemId.replace( /Link/, "Image" );
	
	var menuItem = document.getElementById( itemId );
	var menuImage = document.getElementById( imageId );
	
	if( menuItem && menuImage ){ //&& ( window.selectedMenuItem != itemId ) ){
		menuImage.src = window.multiMenu[itemId].path +".jpg";
	}
	
}

function decorate_item( menuItem, decoration ){

	if( !decoration ){
		decoration = "underline";
	}

	if( menuItem ){
		
		if( menuItem.name == window.selectedMenuItemName ){
			return false;
		}
	
		//menuItem.style.textDecoration = decoration;
		
		//var itemName = menuItem.name;
		
		decorate_name( menuItem.name, decoration );
		
		
	}	
	
	return true;
}

function decorate_name( itemName, decoration ){
	if( itemName ){
		var items = document.getElementsByName( itemName );
			
		for( itemIndex = 0; itemIndex < items.length; itemIndex++ ){
			var theItem = items[itemIndex];
			if( theItem ){
				//alert( theItem.id );
				//alert( window.multiMenu[theItem.id].decoration );
				if( window.multiMenu[theItem.id].decoration == "color" ){
					if( decoration == "none" ){
						theItem.style.color = "#4E4B4A";
					} else {
						theItem.style.color = "#7DB900";
					}
					
				} else {
					
					theItem.style.textDecoration = decoration;
				}	
			}
		}	
	}	
}

/**********************
* Update Main Image
***********************/

function update_mainImage( src ){
	
	var image = document.getElementById( "mainImage" );
	
	if( image ){
		image.src = src;	
	}
	
}

function update_title( text ){


	document.title = text;	
}

function update_link( theLink ){
	
	var refLink = document.getElementById( "managmentLink" );
		
	if( refLink ){
		refLink.src = theLink;	
	}
	

	
}

function update_description( description ){
	
}

function update_keywords( keywords ){
	
}


/******************************
*	Managment Menu
*******************************/

function show_managment( itemId ){

	imageId = itemId.replace( /Link/, "Image" );
	
	var menuItem = document.getElementById( itemId );
	var menuImage = document.getElementById( imageId );
	
	if( menuItem && menuImage ){
		menuImage.src = window.multiMenu[itemId].path +"_over.jpg";
	}	
	
	
	var button = document.getElementById("managmentButton");
	
	if( button ){
		button.style.visibility = "visible";	
	}
	
}

function hide_managment( itemId, theEvent ){

	var button = document.getElementById("managmentButton");
	
	if( window.selectedMenuItem == itemId ){
		menu_over( itemId );	
	}
	
	if( button ){
		button.style.visibility = "hidden";	
	}
} 

/********************************
*	Locations
*********************************/

	function toggle_newLocation( checked ){
					
		var newLocation = document.getElementById( "newLocationDetails" );
		
		if( newLocation ){
			if( checked ){
				newLocation.style.visibility  = "visible";
			} else {
				newLocation.style.visibility = "hidden";
			}
		}
	}
	
	
	function collapse_location( locationIndex ){
		var locationId =  "locationDetails_" + locationIndex;
		var location = document.getElementById( locationId );
		
		if( location ){
			location.style.display = "none";
		}
	}	
	
	window.currentLocation = "";
	
	function toggle_location( locationId ){
	
		
		var location = document.getElementById( "locationDetails_" + locationId );
		
		if( location ){
			if( locationId == window.currentLocation ){
				location.style.display = "none";
				window.currentLocation = "";
			} else {
				var lastLocationId= window.currentLocation;
				var lastLocation =  document.getElementById( "locationDetails_" + window.currentLocation );
				
				if( lastLocation ){
					lastLocation.style.display = "none";
				}
				
				location.style.display = "";
				window.currentLocation = locationId;
				
				location_out( lastLocationId );
			}
		}
		
	}
	
	function location_over( locationId ){
		
		if( locationId == window.currentLocation ){
			return;	
		}
		
		var title = document.getElementById( "locationTitle_" + locationId );
		
		if( title ){
			title.src = window.rootPath + 'DynamicContent/Locations/Titles/btn_' + locationId +'_over.jpg';	
		}
	}
	
	function location_out( locationId ){
		
		if(  locationId == window.currentLocation ){
			return;	
		}
		
		var title = document.getElementById( "locationTitle_" + locationId );
		
		if( title ){
			title.src = window.rootPath + 'DynamicContent/Locations/Titles/btn_' + locationId +'.jpg';	
		}
	}
	
	
	
/**********************8
*	PriceList Menu
***********************/

function plist_press( itemId ){
	
	loadContent(window.multiMenu[itemId].linkHref, itemId);
	
}	


function plist_over( itemId ){

	
	var menuItem = document.getElementById( itemId );

	if( menuItem ){
		menuItem.style.textDecoration = "underline";
	}
	

}





function plist_out( itemId ){
	
	var menuItem = document.getElementById( itemId );

	if( menuItem ){
		menuItem.style.textDecoration = "none";
	}
	
}

	