function dropDown() {
	var element = document.getElementById('mainNav');
	var els = element.getElementsByTagName('a');
	var classN = 'dd';
	for(i = 0; i<els.length; i++) {
		if(els[i].className.match('dd')) {
			
			
			els[i].onmouseover = function() {
				classN = 'dd';
				if(this.className.match('active') && !this.className.match('ddActive')) {
					classN = 'dd active';
				}
				this.parentNode.getElementsByTagName('div')[0].style.display = 'block';
				this.className = 'dd ddActive';
				this.parentNode.getElementsByTagName('div')[0].onmouseover = function() {
					this.style.display = 'block';
					this.parentNode.getElementsByTagName('a')[0].className = 'dd ddActive';
				}
				
			}
			els[i].onmouseout = function() {
				this.parentNode.getElementsByTagName('div')[0].style.display = 'none';
				this.className = classN;
				this.parentNode.getElementsByTagName('div')[0].onmouseout = function() {
					this.style.display = 'none';
					this.parentNode.getElementsByTagName('a')[0].className = classN;
				}
			}
		}
	}
}

function changeContentBoxes() {
	if(document.getElementById('box1')) {
		var nums = 2;
		if(document.getElementById('box3')) {
			nums = 3;
		}
		var randomnumber=Math.floor(Math.random()*nums);
		randomnumber++;
		var els = document.getElementById('box'+randomnumber);
		els.style.display = 'block';
	}
}

function dropDownSmall() {
	var element = document.getElementById('smallNav');
	if(element != null) {
		var els = element.getElementsByTagName('a');
	
		for(i = 0; i<els.length; i++) {
			if(els[i].className == 'dd') {
				els[i].onmouseover = function() {
					this.parentNode.getElementsByTagName('div')[0].style.display = 'block';
					this.parentNode.getElementsByTagName('div')[0].onmouseover = function() {
						this.style.display = 'block';
					}
					
				}
				els[i].onmouseout = function() {
					this.parentNode.getElementsByTagName('div')[0].style.display = 'none';
					this.parentNode.getElementsByTagName('div')[0].onmouseout = function() {
						this.style.display = 'none';
					}
				}
			}
		}
	}
}

function showSecondBox() {
	if(document.getElementById('secondBox')) {
		document.getElementById('firstBox').style.display = 'none';
		document.getElementById('secondBox').style.display = 'block';
	}
}

function switchBoxes() {
	if(document.getElementById('firstBox')) {
		window.setTimeout('showSecondBox()', 30000);
	}
}

function showHideLoginBox() {
	var element = document.getElementById('loginBox');
	var displayStatus = (element.style.display == 'block')?'none':'block';
	element.style.display = displayStatus;
}

function openPopup(url,width,height){
	window.open(url,'popup','toolbar=0,location=0,directories=0, statusbar=0,menubar=0,scrollbars=0,resizable=0,width='+width+',height='+height);
}

function switchTabs(obj) {
	var objectToHide2 = obj.parentNode.getElementsByTagName('a');
	for(i = 0; i<objectToHide2.length; i++) {
		objectToHide2[i].className = '';
	}
	obj.className = 'active';
	var objectToDisplay = document.getElementById(obj.rel);
	var objectToHide = objectToDisplay.parentNode.getElementsByTagName('div');
	for(i = 0; i<objectToHide.length; i++) {
		objectToHide[i].style.display = 'none';
	}
	objectToDisplay.style.display = 'block';
}

window.onload = function() {
	dropDown();
	dropDownSmall();
	changeContentBoxes(3);
	switchBoxes();
}


//check and validate forms 
function validateForm(form_name)
{
	// number of errrrrrrrrrrrrrrors
	var errors = 0;

	// set up dialog
	$('#dialog').dialog({
		autoOpen: false,
		modal: true,
		hide: 'explode',
		buttons: {
			Ok: function() {
				$(this).dialog('close');
			}
		}
	});

	// check first name field
	if($('#firstname').val() == '')
	{
		errors++;
	}

	// check last name field
	if($('#lastname').val() == '')
	{
		errors++;
	}

	// check company name field
	if($('#company').val() == '')
	{
		errors++;
	}

	// check phone number field
	if($('#phone').val() == '')
	{
		errors++;
	}

	// check email field
	if($('#email').val() == '')
	{
		errors++;
	}

	// check number of errors
	if(errors > 0)
	{
		$('#dialog').dialog('open');
		return false;
	}

	// submit form
	document.forms[form_name].submit();
}

