function getAjaxObject()
  {	
	
	try
    { 
	  // Firefox, Opera 8.0+, Safari    
	  return new XMLHttpRequest();    
	}
    catch (e)
    {    
	  // Internet Explorer 
	  try
      {      
	    return new ActiveXObject("Msxml2.XMLHTTP");      
	  }
      catch (e)
      {      
	    try
        {        
		  return new ActiveXObject("Microsoft.XMLHTTP");        
		}
        catch (e)
        {         
		  return false;        
		}      
	  }    
	}  
}//end getAjaxObject function

	
function gotoSubmit()
		{
				var formHandle = document.emailform;
				var ajaxObject;
				ajaxObject = getAjaxObject();
				var data;
				
				//Validate Email
				var requiredArray = ["email"]
				for(var ii=0; ii<requiredArray.length; ii++){
		
					if( !(email_required(formHandle, requiredArray[ii], "form"))){
		
						 return false;
		
					}//end if
		
				}//end for

				if(!(validateEmailAt(formHandle, "email"))) {return false;}
				//End Validate Email
								
				
				
				var inputObjects = formHandle.getElementsByTagName("input");
						for(var x=0; x < inputObjects.length; x++)
						{
							if(inputObjects[x])
							{
								data+='&';
								data+=inputObjects[x].name;
								data+='=';
								data+=inputObjects[x].value;								
							}//end if check
						}//end for
						
				//get textarea inputs			
				var inputTextareas = formHandle.getElementsByTagName("textarea");
						for(var x=0; x < inputTextareas.length; x++)
						{
							if(inputTextareas[x])
							{												
								data+='&';
								data+=inputTextareas[x].name;
								data+='=';
								data+=inputTextareas[x].value;	
							}//end if check
						}//end for
				//end get textarea inputs
				
				
				ajaxObject.onreadystatechange = function() {
						if (ajaxObject.readyState == 4) {
							disableElement('emailbutton');
							initImage('thankyou','contactform');//fade in the thank you							
						}
				}
				
				ajaxObject.open('POST','contact_us.jsp', true);
				ajaxObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				ajaxObject.send(data);
			}
			
//fade functions
	function initImage(imageId, imageId2) {
	  image = document.getElementById(imageId);
	  image2 = document.getElementById(imageId2);
	  
	  image.style.visibility = 'visible';
	  image2.style.visibility = 'visible';
	  
	  setOpacity(image, 0);	  	
	  fade(imageId,0,imageId2,100);
	}
	function deinitImage(imageId, imageId2) {
	  image = document.getElementById(imageId);
	  image2 = document.getElementById(imageId2);
	  
	  image.style.visibility = 'visible';
	  image2.style.visibility = 'visible';
	  
	  setOpacity(image, 0);	  	
	  fade(imageId,0,imageId2,100);

	}			
	function fade(objId,opacity,objId2,opacity2) {
	  if (document.getElementById) {
		obj = document.getElementById(objId);
		obj2 = document.getElementById(objId2);
		
		if (opacity <= 100) {
		  setOpacity(obj, opacity);
		  setOpacity(obj2, opacity2);
		  opacity += 10;
		  opacity2 = opacity2 - 10;
		  window.setTimeout("fade('"+objId+"',"+opacity+",'"+objId2+"',"+opacity2+")", 30);
		}
	  }
	}
	
	function setOpacity(obj, opacity) {
	  opacity = (opacity == 100)?99.999:opacity;
	  
	  // IE/Win
	  obj.style.filter = "alpha(opacity:"+opacity+")";
	  
	  // Safari<1.2, Konqueror
	  obj.style.KHTMLOpacity = opacity/100;
	  
	  // Older Mozilla and Firefox
	  obj.style.MozOpacity = opacity/100;
	  
	  // Safari 1.2, newer Firefox and Mozilla, CSS3
	  obj.style.opacity = opacity/100;
	}
//end fade functions

function disableElement(whichElement)
{
    if (document.getElementById)
    {
        // this is the way the standards work
        document.getElementById(whichElement).disabled = true;
    }
    else if (document.all)
    {
        // this is the way old msie versions work
        document.all[whichElement].disabled = true;
    }
    else if (document.layers)
    {
        // this is the way nn4 works
        document.layers[whichElement].disabled = true;
    }
}
function enableElement(whichElement)
{
    if (document.getElementById)
    {
        // this is the way the standards work
        document.getElementById(whichElement).disabled = false;
    }
    else if (document.all)
    {
        // this is the way old msie versions work
        document.all[whichElement].disabled = false;
    }
    else if (document.layers)
    {
        // this is the way nn4 works
        document.layers[whichElement].disabled = false;
    }
}

function restartForm(){
	
	//clear text fields on the form
	var texts=document.getElementsByTagName('input')
	for (var i_tem = 0; i_tem < texts.length; i_tem++){
		if (texts[i_tem].type=='text')
			texts[i_tem].value=''
	}
	var textareas=document.getElementsByTagName('textarea')
	for (var i_tem = 0; i_tem < textareas.length; i_tem++){
			textareas[i_tem].value=''
	}
	
	deinitImage('contactform','thankyou');//fade in the contact form
	enableElement('emailbutton');//enable email button
}
///end fade functions

 //************Functions for validating the required email field***************

 	function general_check_required(formHandle, transfer_type, section_type)

	{	//text fields only



		var stringHandler = formHandle[transfer_type].value

		var sh2 = stringHandler.substring(0,2)



		if( stringHandler == "")



		{		alert( "Please fill in the required " + section_type + " field.");		



				formHandle[transfer_type].focus();



				return 0;	

		}	

		return 1;

	}	



	function email_required(formHandle, transfer_type, section_type)

	{	//text fields only



		var stringHandler = formHandle[transfer_type].value

		var sh2 = stringHandler.substring(0,2)



		if( stringHandler == "")

		{		alert( "Please Enter A Valid E-mail Address.");		

				formHandle[transfer_type].focus();

				return false;	

		}	

		return 1;

	}

	

	function validateEmailAt(formHandle, transferType)

	{

		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(formHandle[transferType].value)){

			return (true)

		}

		alert("Invalid E-mail Address. Please Re-enter.");

		formHandle[transferType].focus();

		return (false)

	}
 //****END****Functions for validating the required email field***************
