/*
 * SimpleModal Basic Modal Dialog
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2009 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: basic.js 212 2009-09-03 05:33:44Z emartin24 $
 *
 */

$(document).ready(function () {
//alert("running");
	$('#Modal a.basic').click(function (e) {
	//alert("running");
		e.preventDefault();
		$('#Modal-Content').modal();
	});
});
// This function will open a modal with a zoom
function zoom(){
// Change min height and width
$("#Modal-Zoom").modal({
	minHeight:400,
	minWidth: 600
});
}



function submitForm()
{
var errmsg='';
var fname=document.getElementById('firstName').value;
var eMail=document.getElementById('email').value;
var phone=document.getElementById('phone').value;
var contact=document.getElementById('contactMe').value;
var question=document.getElementById('question').value;
var security=document.getElementById('security').value.toUpperCase();
var securityHash=document.getElementById('captchaHash').value;

//We are going to convert our security string to hash
security = hex_md5(security).toUpperCase();
//alert(security + ' ' + securityHash);
//Now we check for form validation

if (fname =='')
	{
		errmsg = errmsg + '<B>You must enter a name</b><br>';
	}
if (eMail =='')
	{
		errmsg = errmsg + '<b>You must enter an email address</b><br>';
	}
if (eMail != '' && eMail.match("@") != "@")
{
		errmsg = errmsg + '<b>You must enter a valid email address</b><br>';
}

if (security != securityHash)
{
		errmsg = errmsg + '<b>You must enter a valid security code</b><br>';
}
if (errmsg != '')
{ 
	errmsg = '<font color="#FFFFFF">' + errmsg + '</font>';
}

//alert(eMail.match("@"));
if(errmsg != '')
{
document.getElementById('Modal-Content').innerHTML = errmsg;
modal();
}
else
	{
	 ColdFusion.Ajax.submitForm('contactForm', 'sendForm.cfm', formSubmit);
	 document.getElementById('Modal-Content').innerHTML = "<img src='images/contact-loader.gif'><br> Please wait, form being submitted";
    $('#Modal-Content').modal();
	}
}

function formSubmit()
{
	document.getElementById('Modal-Content').innerHTML = "Your question has been submitted. <br> Thank you.";
	$('#Modal-Content').modal();
	setTimeout('close()', 2000);
		document.contactForm.security.value = 'Enter Code';	
		document.contactForm.firstName.value = '';
		document.contactForm.email.value = '';
		document.contactForm.phone.value = '';
		document.contactForm.contactMe.value = '';
		document.contactForm.question.value = '';
}
function modal()
{
//alert('MODAL!');
	$('#Modal-Content').modal({
	minHeight:100,
	minWidth: 400});
}
function close()
{
//alert('test');
$.modal.close();
}

