var form = "";
var submitted = false;
var error = false;
var error_message = "";

function checkConsultForm()
{
	error_message = "";
	if (submitted == true) 
	{
    	alert("You have already submitted the form");
    	return false;
  	}

  	error = false;
  	form = document.forms['consultForm'];

	check_input("firstname", "1", "You did not enter your first name.");
  	check_input("lastname", "1", "You did not enter your last name.");
	check_input("company", "1", "You did not enter your company.");
	check_input("phone", "1", "You did not enter your work phone.");
	check_input("email", "1", "You did not enter your email address.");
	
	
	
	//ensure question entered and less than 1000 characters
	if(form.elements['question'].value == '')
	{
		error_message = error_message + "* " + "You did not enter your question." + "\n";
      	error = true;
	}
	else if(form.elements['question'].value.length > '1000')
	{
		error_message = error_message + "* " + "Question cannot exceed 1000 characters." + "\n";
      	error = true;
	}
	
	if (error == true) {
    	alert(error_message);
    	return false;
  	} else {
    	submitted = true;
    	return true;
  	}
}


function check_input(field_name, field_size, message) {
	
  if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
    var field_value = form.elements[field_name].value;

    if (field_value == '' || ( (field_size != '') && (field_value.length < field_size)) ) {
      error_message = error_message + "* " + message + "\n";
      error = true;
    }
  }
}



function showHideLayers() { 

  var i,p,v,obj,args=showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
  { 
		if ((obj=findObj(args[i]))!=null) 
		{ 
			v=args[i+2];
			if (obj.style) 
			{ 
				obj=obj.style; 
				v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
			}
			obj.visibility=v; 
		} 
	}
}


//this function shows the layer(s) passed into the function while hiding all other dd's
//each level is new argument ('1', '2'... = 1st dropdown & 2nd sub dropdown for the 1st box)
//if nothing is passed, all layers will close
function hideAllOtherLayers()
{
	var dd_depth_max = 7; //depth of dropdowns
	var dds = hideAllOtherLayers.arguments, dd_id;
  
	for(var x=1; x<=dd_depth_max; x++)
	{	
		dd_id = 'dd_' + x;
		
		if(dds[0] == x)
			showHideLayers(dd_id, '', 'show');
		else
			showHideLayers(dd_id, '', 'hide');
			
		for(var s=1; s<=dd_depth_max; s++)
		{
			if( (dds[0] == x) && (dds[1] == s) ) //only show the dd where both numbers are the id (e.g. '2_1' not '2_1', '3_1', '4_1')
				showHideLayers(dd_id + '_' + s, '', 'show');
			else
				showHideLayers(dd_id + '_' + s, '', 'hide');
		}
	}
	
	if(dds[0] != '') //if not empty, we want to show a drop down layer so show the closer!
		showHideLayers('closer', '', 'show');
	else
		showHideLayers('closer', '', 'hide'); //if '' was passed in, we want to close everything
}



function findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&id.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function openPopup(thePage, theWidth, theHeight, theWindowName, intScroll)
{
	//This function accepts the page to be loaded, the width and height of the popup, and the name of the window so that
	//new popups open in their own window and not in other ones
	//Also accepts intScroll indicating if scrollbars should be included (0=no, 1=yes)
	
	//POPUP PROPERTIES CODE
	var popWin, theProperties, popWidth, popHeight, leftPos, topPos;
	
	popWidth = theWidth;
	popHeight = theHeight;
	
	if(intScroll == '') intScroll = 0;
	
	//open in center
	leftPos = (screen.width-popWidth)/2;
	topPos = (screen.height-popHeight)/2;
	
	//popup only has scrollbars
	theProperties = "menubar=0,toolbar=0,resizable=1,scrollbars=" + intScroll + ",width=" + popWidth + ",height=" + popHeight + ",left=" + leftPos + ",top=" + topPos;
	
	//Open a popup window
	popWin = window.open(thePage, theWindowName, theProperties);
	popWin.focus();
	
	return false;
}
