var checklocation = document.domain;

if (checklocation == "localhost"){
	myurl = "http://localhost/essa/";
} else {
	myurl = "http://www.ergonomicssa.com/";	
}

var menuids=["treemenu1"];

function buildsubmenus_horizontal(){
for (var i=0; i<menuids.length; i++){
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
		if (ultags[t].parentNode.parentNode.id==menuids[i]){ //if this is a first level submenu
			ultags[t].style.top=ultags[t].parentNode.offsetHeight+"px" //dynamically position first level submenus to be height of main menu item
			ultags[t].parentNode.getElementsByTagName("a")[0].className="mainfoldericon"
		}
		else{ //else if this is a sub level menu (ul)
		  ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
    	  ultags[t].parentNode.getElementsByTagName("a")[0].className="subfoldericon"
		}
    ultags[t].parentNode.onmouseover=function(){
    this.getElementsByTagName("ul")[0].style.visibility="visible"
    }
    ultags[t].parentNode.onmouseout=function(){
    this.getElementsByTagName("ul")[0].style.visibility="hidden"
    }
    }
  }
}

if (window.addEventListener)
window.addEventListener("load", buildsubmenus_horizontal, false)
else if (window.attachEvent)
window.attachEvent("onload", buildsubmenus_horizontal)

function checkForm() {
	
	// Default variables
	var errorMsg = "";
	var errorMsgLong = "";
	
	// Check for a title
	if (document.frmreg.name.value == "") {
		errorMsg += "\nFirst name - Please enter member firstname";
	}
	
	
	if (document.frmreg.email.value == "" || (document.frmreg.email.value.indexOf("@", 0) == -1 || document.frmreg.email.value.indexOf(".", 0) == -1)) {
		errorMsg +="\nEmail address - Please enter a valid email address";
	}
	
	if (document.frmreg.passsword.value == "") {
		errorMsg += "\nPassword - Please enter a password";
	}
	
	// If there is a problem with the form then display an error
	if ((errorMsg != "") || (errorMsgLong != "")) {
		msg = "The form was not submitted as there are errors in your input\n";
		msg += "Please correct the following error(s) and re-submit the form.\n\n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
		
		// Return false
		return false;
	}
	// Return true
	return true;
}

$(document).ready(function()
{
	$("#frmquestion").submit(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').text('Validating...').fadeIn(1000);
		//check the username exists or not from ajax
		$.post(myurl + "askaquestion.php",{ 
			   name:$('#qname').val(),
			   email:$('#qemail').val(),
			   message:$('#qtext').val()
		} ,function(data)
        {
		  if(data=='yes') //if correct login detail
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Sending Mail...').addClass('messageboxok').fadeTo(900,1,
              function()
			  { 
			  	 //redirect to secure page
				 document.location='index.php?pid=12&mode=thankyou';
			  });
			  
			});
		  }
		  else 
		  {
		  	$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  var error = "Failed <br/><br/>" + data;
			  $(this).html(error).addClass('messageboxerror').fadeTo(900,1);
			});		
          }
				
        });
 		return false; //not to post the  form physically
	});
});
