﻿// JScript File
<!--
//***************************************************************************
//ButtonArray is built in the following way
//[0] id
//[1] parent -> if parent is 0 then is top
//[2] text
//[3] hint
//[4] icon
//[5] link or action
//***************************************************************************

var M_BaseOverId = '';
var M_OverId = '';
//###################################################
function GetPosition(thisObject)
//###################################################
{
	var L_LeftOffSet=0, L_TopOffSet=0, L_HeightOffSet=0;
	while (thisObject)
    	{
      		L_LeftOffSet += thisObject.offsetLeft;
      		L_TopOffSet += thisObject.offsetTop;
      		thisObject = thisObject.offsetParent;
    	}
    	return [L_LeftOffSet, L_TopOffSet];
}	

//ParentId = direct buttons parent
//BaseParentId = root node (level 0) for item

//###################################################
function AddAction(MenuId, ButtonId, ParentId, BaseParentId, ButtonObject, ButAction, ButtonArray)
//###################################################
{
	
	ButtonObject.onclick = function(){
		
		if ((ButAction == '')||(ButAction == null)){
			
			
			//if already exists then make visible, else create
			var L_Exists = document.getElementById(MenuId + '-table-'+ButtonId);
					
			if(!L_Exists){ 		
			
				//CHECK FOR SUBMENU						
				var L_SubMenu = null;

				for(var i=0; i<ButtonArray.length; i++)
				{				
					var L_ThisButtonArray = ButtonArray[i].split(',');
					var L_ParentId = L_ThisButtonArray[1];				
					if (ButtonId == L_ParentId)
					{	
					
						if(L_SubMenu==null){
							//get position of parent 						
							var L_Parent = document.getElementById(MenuId+'-td-'+ButtonId);
							var L_Pos = GetPosition(L_Parent);
						
							var L_SubMenu = document.createElement('div');
							L_SubMenu.setAttribute('id', MenuId + '-table-' + ButtonId);
							L_SubMenu.setAttribute('class', 'class-'+MenuId);
							L_SubMenu.setAttribute('name', 'name-'+MenuId);
							L_SubMenu.style.fontFamily='Verdana,Arial';
							L_SubMenu.style.zIndex='100';						
							L_SubMenu.style.fontSize='11px';
							//L_SubMenu.style.fontWeight='bold';
							L_SubMenu.style.color='#ffffff';
							if (parseInt(ParentId) == 0){
								L_SubMenu.style.left = L_Pos[0] + 'px';
								L_SubMenu.style.top  = '' + (parseInt(L_Pos[1]) + document.getElementById(MenuId).offsetHeight) + 'px';	
							}else{
								L_SubMenu.style.left = ''+(parseInt(L_Pos[0]) + document.getElementById(MenuId+'-table-'+ParentId).offsetWidth) + 'px';
								L_SubMenu.style.top  = L_Pos[1] + 'px';	
							}
							L_SubMenu.style.backgroundColor="#555555";
							L_SubMenu.style.borderColor="#000000";
							//L_SubMenu.style.borderStyle='solid';
							L_SubMenu.style.borderSize='2px';
							
							L_SubMenu.style.position='absolute';																		
												
							// ONLY HAPPENS ONCE!!
							document.body.appendChild(L_SubMenu);																																											
						}	
						//var L_SubTr = document.createElement('tr');
						//L_SubMenu.appendChild(L_SubTr);
					
						var L_SubTd = document.createElement('div');
						L_SubTd.style.padding = '4px';
						L_SubTd.setAttribute('id', MenuId + '-td-' + L_ThisButtonArray[0]);
						L_SubTd.innerHTML = L_ThisButtonArray[2];
						AddAction(MenuId, L_ThisButtonArray[0], L_ThisButtonArray[1], BaseParentId, L_SubTd, L_ThisButtonArray[5], ButtonArray);
						//L_SubTr.appendChild(L_SubTd);
						//L_SubMenu.style.width='100%';
						L_SubMenu.appendChild(L_SubTd);
					
					}
												
				}	
				return;	
			}else{
				L_Exists.style.display='';
			}						
			
		}
		
		if (ButAction.substr(0,4)=='url(')
		{
			document.location.href = ButAction.substr(4,ButAction.length-5);
		}else{
			eval(ButAction); 
		}
	}
	ButtonObject.onmouseover = function(){
		M_BaseOverId = BaseParentId;		
		
		//ButtonObject.style.backgroundColor='#cccccc';
		if (parseInt(ParentId) == 0){			
			M_OverId = ButtonId;
			ButtonObject.style.color='#ffff00';
			ButtonObject.className='menu-bg-on';
			//ButtonObject.style.backgroundImage='url(template/menu-bg-on.gif)';
		}else{			
			M_OverId = ParentId;
			ButtonObject.style.color='#ffff00';
			ButtonObject.style.backgroundImage='url(template/bg-steel.gif)';
		}		
		//Button.style.backgroundImage.opacity = 0.5;
		//Button.style.backgroundOpacity=0.5;
		//Button.style.opacity=0.5;
		//Button.style.backgroundFilter = 'apha(opacity=50)';		
	}
	ButtonObject.onmouseout = function(){
		//Button.style.backgroundColor="";
		M_BaseOverId = '';
		M_OverId = '';
		
		ButtonObject.style.backgroundImage='';
		if (parseInt(ParentId) == 0){			
			ButtonObject.style.color='#ffffff';
		}else{		
		    ButtonObject.style.color='#ffffff';	
		}
		
		ButtonObject.className='';
		setTimeout( 'HideSubMenu(\''+MenuId+'\');', 500);
		//Button.style.backgroundOpacity=1;
		//Button.style.opacity=1;
		//Button.style.backgroundFilter = 'apha(opacity=100)';
	}
}

//###################################################
function HideSubMenu(MenuId)
//###################################################
{
	//
	//get all items of class menu
	// go through all options - if baseparent different, then delete
	for (var i=0; i<ButtonArray.length; i++){
	    var L_Split = ButtonArray[i].split(',');
	    //if (L_Split[1]!=0){
	        var L_MenuItem = document.getElementById(MenuId + '-table-' + L_Split[0]);
	        if (L_MenuItem){
	            //alert('over:'+M_OverId+' - base id:'+M_BaseOverId);
    	        if (M_OverId != L_Split[0]){
	                L_MenuItem.style.display='none';
	            }
	        }
	    //}
	
	}
	return;
	    //alert(L_Array[i].className);
		//if (L_Array[i].className == 'class-'+MenuId){
			L_Split = L_Array[i].id.split('-');
			//MenuId + '-table-' + ButtonId
			if (
			(M_BaseOverId == '')||
			(M_OverId == '')|| 
			(L_Split[0] != MenuId)||
			(parseInt(L_Split[2]) > parseInt(M_OverId))
			)
			{
				L_Array[i].style.display='none';
			}		
		//}
	
	
	
	
	
	//var L_Array = document.getElementsByTagName('div');
	var L_Array = document.getElementsByName('name-'+MenuId);
	if (!L_Array)retturn;
	
		
	for (var i=0; i<L_Array.length; i++){
	    //alert(L_Array[i].className);
		//if (L_Array[i].className == 'class-'+MenuId){
			L_Split = L_Array[i].id.split('-');
			//MenuId + '-table-' + ButtonId
			if (
			(M_BaseOverId == '')||
			(M_OverId == '')|| 
			(L_Split[0] != MenuId)||
			(parseInt(L_Split[2]) > parseInt(M_OverId))
			)
			{
				L_Array[i].style.display='none';
			}		
		//}
	}
}

var MenuId = "DivTools";
var ButtonArray = null;
//###################################################
function SetMenu()
//###################################################
{
	ButtonArray = new Array(0);
    	//[0] id
	//[1] parent -> if parent is 0 then is top
	//[2] text
	//[3] hint
	//[4] icon
	//[5] link or action
		
    	ButtonArray.push('1,0,<font color="#ffff00">[&nbsp;Login&nbsp;]</font>,,,');
    	ButtonArray.push('2,1,<table style="color:#000000;background-image:url(template/steel.jpg);" ><tr><td align="right">User&nbsp;Name:</td><td><input size=10 type="text" id="edtUserName" value=""></td></tr><tr><td align="right">Password:</td><td><input type="text" size=10 id="edtMonth" value=""></td></tr><tr><td colspan=2><a href="#" onclick="alert(\'Invalid Username!\');"><center><b><font color="#000000">Login</font></b></center></a></td></tr></table>,,,');    	
    	ButtonArray.push('4,0,Home,,,location="index.php";');
    	ButtonArray.push('5,0,Development,,,location="development.php";'); 	
    	//ButtonArray.push('6,5,Software&nbsp;Development,,,location="development.php";');
    	ButtonArray.push('6,0,Web&nbsp;Solutions,,,location="web-development.php";');
    	ButtonArray.push('7,0,Graphic&nbsp;Design,,,location="graphic-design.php";');
    	ButtonArray.push('8,0,CD&nbsp;/&nbsp;DVD&nbsp;Solutions,,,location="cd-printing.php";');    	
    	ButtonArray.push('9,0,Contact&nbsp;Us,,,location="contact-us.php";'); 
 	
	var L_TableBody = document.getElementById(MenuId+"-body");
	    
	var L_MenuTr = document.createElement('tr');
	L_MenuTr.setAttribute('id', MenuId+'-tr');	
	L_TableBody.appendChild(L_MenuTr);
	
	var L_Count = 0;
	
	for (var i=0; i<ButtonArray.length; i++)
	{	
						
 	    var L_Split = ButtonArray[i].split(','); 	    
	    if (parseInt(L_Split[1])==0){
 		     		    		     		    
 		    var L_MenuTd = document.createElement('td');
 		
 		
 		    
		    L_MenuTd.setAttribute('id', MenuId+'-td-'+L_Split[0]);
		    L_MenuTd.innerHTML = '<div>'+L_Split[2]+'</div>';	
            L_MenuTd.style.padding = '4px';
            AddAction(MenuId, L_Split[0], L_Split[1], L_Split[0], L_MenuTd, L_Split[5], ButtonArray);
 	        //AddAction(MenuId, ButtonId, ParentId, BaseParentId, ButtonObject, ButAction, ButtonArray)
            L_MenuTr.appendChild(L_MenuTd);
            
 		    //draw line
 		    var L_MenuTdLine = document.createElement('td');	
            //L_MenuTdLine.style.backgroundColor="#777777";
            //L_MenuTdLine.style.backgroundImage='url(template/menu-bg-on.gif)';            
            L_MenuTdLine.className='menu-bg-on';
            L_MenuTdLine.style.width='1';
            L_MenuTr.appendChild(L_MenuTdLine);
                            
            L_Count++;
        }
    }        
}

//###################################################
function ChangeCurrentPeriod()
//###################################################
{
    var L_Date = new Date();                                
    var L_CurrentMonth = L_Date.getMonth()+1;
    var L_CurrentYear = L_Date.getYear();                        
    if (L_CurrentYear<1900){ L_CurrentYear=(L_CurrentYear+1900); }    
    
    var L_NewYear = document.getElementById("edtYear").value;
	var L_NewMonth = document.getElementById("edtMonth").value;
	
	if (parseInt(""+L_NewYear+""+L_NewMonth) < parseInt(""+L_CurrentYear+""+L_CurrentMonth)){
	    alert("The proposed input period ('"+L_NewYear+""+L_NewMonth+"') cannot be used as it is earlier than the current period!");
	    return;
	}
	
	document.getElementById("Year").value = L_NewYear; 
	document.getElementById("Month").value = L_NewMonth; 		   
}
-->
