/* common JS for the whole GemGate website */

$(document).ready(function(){ 
        $("ul.sf-menu").superfish({ 
            animation: {height:'show'},   // slide-down effect without fade-in 
			speed:       'fast',
            delay:     100               // 1.2 second delay on mouseout 
        }); 
});

function fix_columns() {

	
	var leftnav_obj = document.getElementById('leftnav');
	var content_obj = document.getElementById('content');
	var container_obj = document.getElementById('container');
	var search_obj = document.getElementById('search');
	var topnav_obj = document.getElementById('topnav');
	var leftnav_height = leftnav_obj.offsetHeight;
	var content_height = content_obj.offsetHeight;
	
	var filename = window.location.pathname.replace( /.*\//, "" );
	if (filename == 'index.html') {
		content_obj.style.paddingTop = '38px';
	}
	// Need to fix this for every page
	
	var right_offset = container_obj.offsetLeft + 15;
	search_obj.style.right = right_offset + 'px';

	if (leftnav_height > content_height) {	
		content_obj.style.height = leftnav_obj.offsetHeight + 'px';
	}
	
	if (filename == 'search.php') {
		var contentHeight = leftnav_obj.offsetHeight + 25;
		content_obj.style.height = contentHeight + 'px';
	}
	
	
	if (navigator.userAgent.indexOf('MSIE') == -1) {
		// this is for everything but microsoft
		topnav_obj.style.marginLeft = '184px';
		
	} else {
		if (navigator.userAgent.indexOf('MSIE 8.0') != -1) {
			// this is just for ie 8
			topnav_obj.style.paddingLeft = '184px';
			var tempObj = container_obj.getBoundingClientRect();
			leftnav_obj.style.left = tempObj.left + 'px';
		} else {
			// < ie 8
			topnav_obj.style.paddingLeft = '1px';
			leftnav_obj.style.left = container_obj.offsetLeft + 'px';
		}
	}

}

function showIt(name) {
	
	var div_obj = document.getElementById(name);
	
	if (div_obj.style.display == 'none' || ! div_obj.style.display) {
		div_obj.style.display = 'block';
	} else {
		div_obj.style.display = 'none';
	}
}

function popwindow(URL, X, Y) {

	if (X == 0) {
		X = 500;
	}
	
	if (Y == 0) {
		Y = 300;
	}

	var ATT = "toolbar=no,scrollbars=yes,statu=no,width=" + X + ",height=" + Y;
	
	newWindow = window.open(URL,"Gemgate",ATT);
	
}

function validate() {
	
	/* Check name  */
	if (! document.forms[1].first_name.value) {
		alert('Please provide your first name.');
		return false;
	} 
	
	if (! document.forms[1].last_name.value) {
		alert('Please provide your last name.');
		return false;
	}
	
	/* Check email */
	if (! document.forms[1].email.value) {
		alert('Please provide your email address.');
		return false;
	} else {
		var email = document.forms[1].email.value;
	}
	
	/* Check email_confirm */
	if (! document.forms[1].email_confirm.value) {
		alert('Please confirm your email address.');
		return false;
	} else {
		var email_confirm = document.forms[1].email_confirm.value;
	}
	
	if (email != email_confirm) {
		alert('Your email address does not match');
		return false;
	}
	
	return true;
}

