function submitForm()
{

//***************************** SET VARIABLES *********************************************//
var form;
form = document.forms["mimeoForm"];

if (form.name) {	
	var name = form.name.value;
}
if (form.first_name) {		
	var first_name = form.first_name.value;
}
if (form.last_name)	{
	var last_name = form.last_name.value;
}
if (form.email)	{
	var email = form.email.value;
}
if (form.phone)	{
	var phone = form.phone.value;
}
if (form.company)	{
	var company = form.company.value;  
}
if (form.subject)	{
	var subject = form.subject.value;  
}
//job function field used in Product Pages request quote form
if (form.elements["00N00000005kKxj"])	{
	var job_function = form.elements["00N00000005kKxj"].selectedIndex;
}
// quote textarea used in Product pages
if (form.quote)	{
	var quote = form.quote.value;
}
// Question Box in Print Now Get 50% off form
if (form.elements["00N00000006ykw1"])	{
	var question = form.elements["00N00000006ykw1"].value;
}
// Question Box in Ask Us Customer Form
if (form.elements["description"])	{
	var description = form.elements["description"].value;
}
if (form.captcha_code)	{
	var captcha_code = form.captcha_code.value;
}


var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;


//***************************** CHECK VALUES *********************************************//

if(name == "") {
  inlineMsg('name','<strong>Error</strong><br />Please enter your name.',2);
  return false;
} 
if(first_name == "") {
  inlineMsg('first_name','<strong>Error</strong><br />Please enter your name.',2);
  return false;
}  
if(last_name == "") {
  inlineMsg('last_name','<strong>Error</strong><br />Please enter your last name.',2);
  return false;
} 
if(company == "") {
  inlineMsg('company','<strong>Error</strong><br />Please enter your company name.');
  return false;
} 
if(phone == "") {
  inlineMsg('phone','<strong>Error</strong><br />Please enter a phone number.',2);
  return false;
} 
if(email == "") {
  inlineMsg('email','<strong>Error</strong><br />Please enter your email.',2);
  return false;
}
if(!email.match(emailRegex)) {
  inlineMsg('email','<strong>Error</strong><br />You have entered an invalid email.',2);
  return false;
}
if(job_function == 0) {
  inlineMsg('00N00000005kKxj','<strong>Error</strong><br />Please select an item from the list.',2);
  return false;
}
if(subject == "") {
  inlineMsg('subject','<strong>Error</strong><br />Please enter a subject.');
  return false;
} 
// Question Box in Print Now Get 50% off form
if( question == "") {
    inlineMsg('00N00000006ykw1','<strong>Error</strong><br />Please enter a question.',2);
    return false;
}
// Question Box in Ask Us Customer Form
if( description == "") {	
    inlineMsg('description','<strong>Error</strong><br />Please enter a question.',2);
    return false;
}
if(quote == "") {
  inlineMsg('quote','<strong>Error</strong><br />Please enter your quote description.',2);
  return false;
}
//if( subject != "") {    
//    return false;	
//}
document.forms["mimeoForm"].submit();  // !Important! form name must be 'mimeoForm' in order for the script to work for all forms.  Form ID can be different

return true;
}

// START OF MESSAGE SCRIPT //

var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 3;


// build out the divs, set attributes and call the fade function //
function inlineMsg(target,string,autohide) {
	
  form = document.forms["mimeoForm"];	
  
  var msg;
  var msgcontent;
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  var targetdiv = form.elements[target];
  targetdiv.focus();
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  window.setTimeout("hideMsg()", (autohide * 2000));
}

// hide the form alert //
function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}

// face the message box //
function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 200);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 199) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}

// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}

// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}

// preload the arrow //
if(document.images) {
  arrow = new Image(7,80); 
  arrow.src = "../images/msg_arrow.gif"; 
}
