var showIntId = 0;
var hideIntId = 0;

var showIntIds = new Array();
var hideIntIds = new Array();

var lowerIntId = 0;
var raiseIntId = 0;

var interval = 20;

var openAction = true;

function show(divElemId, widthRate, maxWidth, heightRate, maxHeight)
{	
	var widthDone = false;
	var heightDone = false;
	var divElem = document.getElementById(divElemId);
	var divElemCurrentWidth = 0; 
	divElemCurrentWidth = parseInt(divElem.style.width);
	var divElemCurrentHeight = 0;
	divElemCurrentHeight = parseInt(divElem.style.height);

	if(maxWidth > 0 && divElemCurrentWidth < maxWidth) {
		divElemCurrentWidth = divElemCurrentWidth + widthRate;
		divElem.style.width=''+divElemCurrentWidth+'px';				
	} else {
		widthDone = true; 
	}
	
	if(maxHeight > 0 && divElemCurrentHeight < maxHeight) {
		divElemCurrentHeight = divElemCurrentHeight + heightRate
		divElem.style.height=''+divElemCurrentHeight+'px'
	} else {	
		heightDone = true;		
	}
	
	if(widthDone && heightDone) {
		//clearInterval(showIntId);
		clearInterval(showIntIds[divElemId]);
	}
} 

function hide(divElemId, widthRate, minWidth, heightRate, minHeight)
{
	var widthDone = false;
	var heightDone = false;
	var divElem = document.getElementById(divElemId);
	var divElemCurrentWidth = 0; 
	divElemCurrentWidth = parseInt(divElem.style.width);
	var divElemCurrentHeight = 0;
	divElemCurrentHeight = parseInt(divElem.style.height);
		
	if(minWidth > 0 && divElemCurrentWidth > minWidth) {
		divElemCurrentWidth = divElemCurrentWidth - widthRate;
		divElem.style.width=''+divElemCurrentWidth+'px';				
	} else {
		widthDone = true; 
	}
	
	if(minHeight > 0 && divElemCurrentHeight > minHeight) {
		divElemCurrentHeight = divElemCurrentHeight - heightRate
		divElem.style.height=''+divElemCurrentHeight+'px'
	} else {	
		heightDone = true;		
	}
	
	if(widthDone && heightDone) {
		//clearInterval(hideIntId);
		clearInterval(hideIntIds[divElemId]);
	}
} 

function hideSubmenu(menuId) {
	clearInterval(showIntIds[("menu_" + menuId)]);

	var submenuDivElem = document.getElementById('submenu_'+menuId);
	if( submenuDivElem != null ) {
		var command = "hide('menu_" +menuId + "', 0, 0, 10, 20)";
		//hideIntId=setInterval(command,interval);
		hideIntIds[("menu_" + menuId)]=setInterval(command,interval);
		submenuDivElem.style.visibility='hidden';
	}
}

function showSubmenu(menuId) {
	clearInterval(hideIntIds[("menu_" + menuId)]);

	var submenuDivElem = document.getElementById('submenu_'+menuId);
	if( submenuDivElem != null ) {
		var command = "show('menu_" +menuId + "', 0, 0, 10, 85)";
		//showIntId=setInterval(command,interval);
		showIntIds[("menu_" + menuId)]=setInterval(command,interval);
		submenuDivElem.style.visibility='visible';
	}
}
	

function validateEnquiryForm(theForm) {
	var allRequiredSelected = true;
	var errorMessage = 'Please fill in the following required field(s):';
	
	if(theForm.businessName.value=='') {
		//allRequiredSelected = false;
	}
	
	if(theForm.contactName.value=='') {
		allRequiredSelected = false;
		errorMessage = errorMessage + '\nContact name';
	}
	
	if(theForm.phone.value=='') {
		allRequiredSelected = false;
		errorMessage = errorMessage + '\nPhone';	
	}
	
	if(theForm.email.value=='') {
		allRequiredSelected = false;
		errorMessage = errorMessage + '\nE-Mail';	
	} else {
		var addSymbolIndex = theForm.email.value.indexOf('@');
		var dotSymbolIndex = theForm.email.value.indexOf('.');
		var lastDotSymbolIndex = theForm.email.value.lastIndexOf('.');
		var sizeOfEmailAddress = theForm.email.value.length;
		if(addSymbolIndex <= 0 || dotSymbolIndex <= 0 || (dotSymbolIndex - addSymbolIndex) == 1 || ((theForm.email.value.length - 1) == lastDotSymbolIndex)) {
			errorMessage = errorMessage + '\nValid E-Mail';	
		}
	}
	
	if(theForm.regarding.value=='') {
		allRequiredSelected = false;
		errorMessage = errorMessage + '\nRegarding';	
	}
	
	if(theForm.hearUs.value=='') {
		allRequiredSelected = false;
		errorMessage = errorMessage + '\nHow did you find us?';	
	}	

	if(theForm.message.value=='') {
		allRequiredSelected = false;
		errorMessage = errorMessage + '\nMessage';	
	}		

	if(!allRequiredSelected) {	
		alert(errorMessage);
	} else {
		alert('An email will be sent to your email address provided in the form above to acknowledge receiving of your enquiry.\n\nThank you for your enquiry with Knowledge Cube.');
	}
	
	return allRequiredSelected;
}
