// JavaScript Document

$(document).ready(function(){

// Our Menu
$('li.headlink').hover(
			function() { $('ul', this).css('display', 'list-item'); },
			function() { $('ul', this).css('display', 'none'); });

/*For the conatct form */
   $('div#contactarea').hide();
	
	// Mouse Pointers 
   $('.toggleContactArea').mouseover(function() {$(this).addClass("over");}).mouseout(function() {$(this).removeClass("over");});
   $('.closeMessageArea').mouseover(function() {$(this).addClass("over");}).mouseout(function() {$(this).removeClass("over");});

	// Toggle feature for showing and hiding
	$('.toggleContactArea').click(function() {
		$('div#contactarea').toggle();
	});

	$('.closeContactArea').click(function() {
		$('div#contactmessage').hide();
	});


 })

/*For the conatct page*/
function isContact (contactType,optional) {

	if (optional == null) {
		value = document.getElementById('contact').value;
	} else {
		value = optional;
	}
	
	switch (contactType) {
		case 'phone':
			// reg expression to find out if unexpected values are included
			var regExpressionObj = RegExp(/^[+]?([0-9]*[\.\s\-\(\)]|[0-9]+){3,24}(( x| ext| extension)\d{1,5}){0,1}?$/);
			if (regExpressionObj.test(value) == false) {
				alert("Please use this format for your phone number: +## (###) ###-#### x#####");
				return false;
			}
			
			return true;
			break;
		
		case 'email':
			// reg expression to find correct format
			var regExpressionObj2 = RegExp(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/);
			if (regExpressionObj2.test(value) == false) {
					alert("Please use the correct format for your email address: 'value@organization.com'.");
					return false;
				}
			return true;
			break;
		
		default:
		// assume no value has been entered yet and be patient
		return false;
		break;
	}
}

function checkForm () {

	// get our values to check
	name = document.contactform.name.value;
	contact = document.contactform.contact.value;
	
	for (i=0;i<document.contactform.ct.length;i++) {
	if (document.contactform.ct[i].checked) {
		contactType = document.contactform.ct[i].value;
		}
	}

	// make sure nothing is too long or contains script
	
	if (name == '') {
		// something is wrong
		alert('Please provide your name');
		return false;
	} 
	else if (isContact(contactType,contact) == false) {
		// something else is wrong
		alert('Please provide valid contact information.');
		return false;
	}
	
	// If the script makes it to here, everything is OK,
	// so you can submit the form

	return true;
}

// For the Click2Dial Link
// JavaScript Document

/* For internal page links, upto 9 elements*/
function opencontact(section){
	
	// set a variable to the section we want to show
	var contact = document.getElementById(section);

	// Set our contact section to visible
	contact.style.visibility = "visible";
	contact.style.display = "block";
	contact.style.height = "100%";
	
	// Set our body to be overlayed
}

function closecontact (section){
	// set a variable to the section we want to show
	var contact = document.getElementById(section);
	
	// Set our contact section to hidden
	contact.style.visibility = "hidden";
	contact.style.display = "none";
	contact.style.height = "0";
	
}

function makecall(dummy) {
	document.write('<iframe src ="'+dummy+'" width="0" height="0"><p>Your browser does not support iframes.</p></iframe>'); 
	// opens in iFrame
}

function writemessage(mes) {
	document.getElementById("returnmessagearea").innerHTML = mes;
}
