// JavaScript Document

/***************************** 
*  Written By Nicholas Klick *
*  www.nicholasklick.com     *
*   2/5/2008                 *
*****************************/






var isIE = false;
var isFF = false;
if (document.all) {isIE=true;}
else if (document.getElementById) {isFF=true;}
var validFormData=true;

function checkName()
        {
		var fieldValue=document.request.name.value;
		if (isIE) 
			{
			nameDiv.innerText="";
			}
		else if(isFF)
			{
			document.getElementById('nameDiv').textContent = "";
			}

        if (fieldValue=="" || fieldValue==null)
            {
			if (isFF) 
					{
				document.getElementById('errorDiv').textContent = "Error Please Check the form";
				document.getElementById('nameDiv').textContent = "Error";
					}
			else if (isIE) 
					{
					errorDiv.innerText="Error Please Check the form";
					nameDiv.innerText="Error";
					}
			 
			 validFormData=false;
			 window.location="#top";
			}
			 return validFormData;
		}
function checkAddress()
        {
		var fieldValue=document.request.address.value;
		if (isIE) 
			{
		addressDiv.innerText="";
			}
		else if(isFF)
			{
			document.getElementById('addressDiv').textContent = "";
			}
        if (fieldValue=="" || fieldValue==null)
            {
			if (isFF) 
				{
			document.getElementById('errorDiv').textContent = "Error Please Check the form";
			document.getElementById('addressDiv').textContent = "Error";
				}
			else if (isIE) 
				{
				errorDiv.innerText="Error Please Check the form";
				addressDiv.innerText="Error";
				}
			 
			 validFormData=false;
			 window.location="#top";
			}
			 return validFormData;
		}

function checkCity()
        {
		var fieldValue=document.request.city.value;
		if (isIE) 
			{
		cityDiv.innerText="";
			}
		else if(isFF)
			{
			document.getElementById('cityDiv').textContent = "";
			}
        if (fieldValue=="" || fieldValue==null)
            {
			if (isFF) 
				{
			document.getElementById('errorDiv').textContent = "Error Please Check the form";
			document.getElementById('cityDiv').textContent = "Error";
				}
			else if (isIE) 
				{
				errorDiv.innerText="Error Please Check the form";
				cityDiv.innerText="Error";
				}
			
			 validFormData=false
			 window.location="#top";;
			}
			 return validFormData;
		}

function checkState()
        {
		var fieldValue=document.request.state.value;
		if (isIE) 
			{
		stateDiv.innerText="";
			}
		else if(isFF)
			{
			document.getElementById('stateDiv').textContent = "";
			}
        if (fieldValue=="" || fieldValue==null)
            {
			if (isFF) 
				{
			document.getElementById('errorDiv').textContent = "Error Please Check the form";
			document.getElementById('stateDiv').textContent = "Error";
				}
			else if (isIE) 
				{
				errorDiv.innerText="Error Please Check the form";
				stateDiv.innerText="Error";
				}
			
			 validFormData=false;
			 window.location="#top";
			}
			 return validFormData;
		}

function checkZip()
        {
		var fieldValue=document.request.zip.value;
		if (isIE) 
			{
		zipDiv.innerText="";
			}
		else if(isFF)
			{
			document.getElementById('zipDiv').textContent = "";
			}
        if (fieldValue=="" || fieldValue==null)
            {
			if (isFF) 
				{
			document.getElementById('errorDiv').textContent = "Error Please Check the form";
			document.getElementById('zipDiv').textContent = "Error";
				}
			else if (isIE) 
				{
				errorDiv.innerText="Error Please Check the form";
				zipDiv.innerText="Error";
				}
			 
			 validFormData=false;
			 window.location="#top";
			}
			 return validFormData;
		}

function checkEmail()
        {
		
		var fieldValue=document.request.email.value;
		emailString=new String(fieldValue);
        var atPosition=emailString.indexOf("@");
		var lastAt=emailString.lastIndexOf("@"); 
		var fieldLength = document.request.email.value.length;		
		if (isIE) 
			{
			emailDiv.innerText="";  
			}
		else if(isFF)
			{
		document.getElementById('emailDiv').textContent = ""; 
			}
    	if (fieldValue=="" || fieldValue==null)
             {
			 if (isFF) 
				{
				document.getElementById('errorDiv').textContent = "Error Please Check the form";
				document.getElementById('emailDiv').textContent = "Error";
				}
			 else if (isIE) 
				{
				errorDiv.innerText="Error Please Check the form";
				emailDiv.innerText="Error";
				}
				
		        validFormData=false;
				window.location="#top";
		    }
				 
				else if (atPosition==-1) 
				{
         
				 if (isFF) 
				{
				document.getElementById('errorDiv').textContent ="The email address entered is not valid.";
				document.getElementById('emailDiv').textContent = "Error";
                       
         } 
				 	 else if (isIE) 
				{
				errorDiv.innerText="The email address entered is not valid.";
				emailDiv.innerText="Error";
				 }
				
		     validFormData=false;
			 window.location="#top";
				 }
			
			else if (lastAt!==atPosition)
			 {
                            
				 if (isFF) 
				{
				document.getElementById('errorDiv').textContent ="The email address entered is not valid.";
				document.getElementById('emailDiv').textContent = "Error";
                       
         } 
				 	else if (isIE) 
				{
				errorDiv.innerText="The email address entered is not valid.";
				emailDiv.innerText="Error";
				 }
				
		     validFormData=false;
			 window.location="#top";
				 }							
				 
		else if (atPosition==0) {
                                
				if (isFF) 
				{
				document.getElementById('errorDiv').textContent ="The email address entered is not valid.";
				document.getElementById('emailDiv').textContent = "Error";
                       
         } 
				 	 else if (isIE) 
				{
				errorDiv.innerText="The email address entered is not valid.";
				emailDiv.innerText="Error";
				 }						
					
		      validFormData=false;
			  window.location="#top";
					}										
													
					else if (atPosition == (fieldLength -1))
					  {
							if (isFF) 
				{
				document.getElementById('errorDiv').textContent ="The email address entered is not valid.";
				document.getElementById('emailDiv').textContent = "Error";
                       
         } 
				 	 else if (isIE) 
				{
				errorDiv.innerText="email error";
				emailDiv.innerText="Error";
				validFormData=false;
				window.location="#top";
				 }	
				
		    validFormData=false;
			window.location="#top";
				}
        
	     
		 validFormData=false;
		
		
	   

		return validFormData;
		}

function validateForm()
		{
      /*
        if (isIE) 
			{
			errorDiv.innerText="";
			}
		else if(isFF)
			{
			document.getElementById('errorDiv').textContent = "";
			}	  
	  */
		if (isIE || isFF)
		{
		checkEmail();
		checkZip();
		checkState();
		checkCity();
		checkAddress();
 		checkName();
		}
		if (validFormData)
		    {
			 alert("The form is valid");
			 return true;
			}
		 
		
		
		return validFormData;
		}
function resetForm()
	{
	location.reload();
	}
	
// function switchDiv()
//  this function takes the id of a div
//  and calls the other functions required
//  to show that div
//
/*function switchDiv(div_id)
{
  var style_sheet = getStyleObject(div_id);
  if (style_sheet)
  {
    hideAll();
    changeObjectVisibility(div_id,"visible");
  }
  else
  {
    alert("You must turn Javascript on to use this form");
  }
}

// function hideAll()
//  hides a bunch of divs
//
function hideAll()
{
   changeObjectVisibility("yes","hidden");
   changeObjectVisibility("no","hidden");

}

// function getStyleObject(string) -> returns style object
//  given a string containing the id of an object
//  the function returns the stylesheet of that object
//  or false if it can't find a stylesheet.  Handles
//  cross-browser compatibility issues.
//
function getStyleObject(objectId) {
  // checkW3C DOM, then MSIE 4, then NN 4.
  //
  if(document.getElementById && document.getElementById(objectId)) {
	return document.getElementById(objectId).style;
   }
   else if (document.all && document.all(objectId)) {
	return document.all(objectId).style;
   }
   else if (document.layers && document.layers[objectId]) {
	return document.layers[objectId];
   } else {
	return false;
   }
}

function changeObjectVisibility(objectId, newVisibility) {
    // first get a reference to the cross-browser style object
    // and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
}*/
