﻿function collapse(objID) {
	
	var obj=new Array();
	obj[1] = 'box1';
	obj[2] = 'box2';
	obj[3] = 'box3';

	for(i=1; i<=3; i++){
			
		thisObj = document.getElementById(obj[i]);
		
		if(obj[i] == objID){
			if (thisObj.className == "closed") {
        		thisObj.className = "box";
    			}
			else {
        		thisObj.className = "closed";
	    		}
		}
		else{
			if (thisObj.className == "box") {
        		thisObj.className = "closed";
	    		}
		}
	}
}




var parent_page = 'empty';
var page_location = window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1,window.location.pathname.indexOf("."));


Array.prototype.inArray = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};



function parentIsset(page){
	aboutUs = new Array('History', 'Mission', 'Vision', 'DirectorsNote');
	products = new Array('GeneralAccounting', 'BudgetCalculation','InventoryCalculation','ProductivityCalculation','Amortization', 'SalaryCalculation','DocumentManagement', 'Other', 'Products');
	news = new Array('News', 'Press');
	
	
	if (aboutUs.inArray(page)) {
		parent_page = 'aboutUs';
	}
	else if (products.inArray(page)){
		parent_page = 'products';
	}	
	else if (news.inArray(page)){
		parent_page = 'news';
	}	
	
}




function menu(pageUrl, pageName, parentName, parentType){
		
	parentIsset(page);
	
	var page_format = '';
	if (pageUrl.lastIndexOf(".")+1){
		page_format = pageUrl.substring(pageUrl.lastIndexOf(".")+1);
		pageUrl = pageUrl.substring(0, pageUrl.lastIndexOf("."));
	}
	
	if (page_format == ''){page_format = 'html'}	

	if (parentName != null){
		if (parentName == parent_page){
			
			document.write('<li><a class="menu_a" onclick="collapse(\''+parentType+'\')"><b>'+pageName+'</b></a>');
			
			document.write('<div class="box" id=\"'+parentType+'\">');
			document.write('<div class=\"boxTop\"></div>');
			document.write('<ul class="back">');
			
			submenu(parentType);

			document.write('</ul>');
			document.write('<div class=\"boxBottom\"></div>');
			document.write('</div>');
		}	
		else{
			
			document.write('<li><a href=\"'+pageUrl+'.'+page_format+'\" onclick="collapse(\''+parentType+'\')" class="menu_a" >'+pageName+'</a>');
			
			document.write('<div class="closed" id=\"'+parentType+'\">');
			document.write('<div class=\"boxTop\"></div>');
			document.write('<ul class="back">');
			
			submenu(parentType);

			document.write('</ul>');
			document.write('<div class=\"boxBottom\"></div>');
			document.write('</div>')
		}
	}
	else if (pageUrl == page_location){
		
		document.write('<li><a class=\"menu_a\"><b>'+pageName+'</b></a></li>');
	}
	else{
		
		document.write('<li><a class=\"menu_a\" href=\"'+pageUrl+'.'+page_format+'\">'+pageName+'</a></li>');
	}
}

function childMenu(pageUrl, pageName){
	
	var page_format = '';
	if (pageUrl.lastIndexOf(".")+1){
		page_format = pageUrl.substring(pageUrl.lastIndexOf(".")+1);
		pageUrl = pageUrl.substring(0, pageUrl.lastIndexOf("."));
	}
	if (page_format == ''){page_format = 'html'}
	
	if (pageUrl == window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1,window.location.pathname.indexOf("."))){
			document.write('<li><a><b>'+pageName+'</b></a></li>');
			
		}
		else{
			document.write('<li><a href="'+pageUrl+'.'+page_format+'">'+pageName+'</a></li>');
		}	
}

