function is_empty(s)
{   
	return ((s == null) || (s.length == 0))
}

function echeck(str) 
{
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);

		if (str.indexOf(at)==-1)
		{
		   alert("Invalid e-mail address.")
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		{
		   alert("Invalid e-mail address.")
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		{
		    alert("Invalid e-mail address.")
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1)
		 {
		    alert("Invalid e-mail address.")
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		 {
		    alert("Invalid e-mail address.")
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1)
		 {
		    alert("Invalid e-mail address.")
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1)
		 {
		    alert("Invalid e-mail address.")
		    return false;
		 }

 		 return true;
}

function checkForm()
{
	if(document.order_form.prefix.value == "Please Select One")
	{
		alert("Please select a prefix.");
		document.order_form.prefix.focus();
		return false;
	}

	if(is_empty(document.order_form.fname.value))
	{
		alert("You must enter your first name.");
		document.order_form.fname.focus();
		return false;
	}
	
	if(is_empty(document.order_form.lname.value))
	{
		alert("You must enter your last name.");
		document.order_form.lname.focus();
		return false;
	}
	
	if(is_empty(document.order_form.addr.value))
	{
		alert("You must enter your address.");
		document.order_form.addr.focus();
		return false;
	}
	
	if(is_empty(document.order_form.city.value))
	{
		alert("You must enter your city.");
		document.order_form.city.focus();
		return false;
	}
	
	if(document.order_form.state.value == "Please Select One")
	{
		alert("Please select your state.");
		document.order_form.state.focus();
		return false;
	}
	
	if ((document.order_form.state.value == "Other") && is_empty(document.order_form.ostate.value))
	{
		alert("Please enter your state.");
		document.order_form.ostate.focus();
		return false;
	}

	if(is_empty(document.order_form.zip.value))
	{
		alert("You must enter your zip code.");
		document.order_form.zip.focus();
		return false;
	}

	if (is_empty(document.order_form.email.value))
	{
		alert("Please enter your e-mail address.");
		document.order_form.email.focus();
		return false;
	}
	
	if (echeck(document.order_form.email.value)==false)
	{
		alert("Please enter a valid e-mail address.");
		document.order_form.email.value = "";
		document.order_form.email.focus();
		return false;
	}
	
	if (is_empty(document.order_form.password.value))
	{
		alert("Please enter a password.");
		document.order_form.password.focus();
		return false;
	}
	
	if (is_empty(document.order_form.cpassword.value))
	{
		alert("Please enter your password again.");
		document.order_form.cpassword.focus();
		return false;
	}

	if (document.order_form.password.value != document.order_form.cpassword.value)
	{
		alert("Passwords do not match.");
		document.order_form.password.value="";
		document.order_form.cpassword.value="";
		document.order_form.password.focus();
		return false;
	}
	
	if (is_empty(document.order_form.ccnumber.value))
	{
		alert("Please enter your credit card number.");
		document.order_form.ccnumber.focus();
		return false;
	}
	
	if(document.order_form.ccmonth.value == "--")
	{
		alert("Please select your credit card expiry month.");
		document.order_form.ccmonth.focus();
		return false;
	}
	
	if(document.order_form.ccyear.value == "----")
	{
		alert("Please select your credit card expiry year.");
		document.order_form.ccyear.focus();
		return false;
	}

	if (is_empty(document.order_form.cvv.value))
	{
		alert("Please enter your credit card's CVV2 value.");
		document.order_form.cvv.focus();
		return false;
	}
}

function checkReport()
{
	if(document.rtype.value == "None")
	{
		alert("Please select a report type.");
		document.order_form.rtype.focus();
		return false;
	}

	if(is_empty(document.order_form.plantiff.value))
	{
		alert("You must enter a plaintiff and/or defendant.");
		document.order_form.plantiff.focus();
		return false;
	}
	
	if(is_empty(document.order_form.details.value))
	{
		alert("You must enter case details.");
		document.order_form.details.focus();
		return false;
	}
	
	if(is_empty(document.order_form.amount.value))
	{
		alert("You must enter amount.");
		document.order_form.amount.focus();
		return false;
	}
	
	if(is_empty(document.order_form.counsel.value))
	{
		alert("You must enter counsel information.");
		document.order_form.counsel.focus();
		return false;
	}
	
	if(is_empty(document.order_form.issuedate.value))
	{
		alert("You must enter an issue date.");
		document.order_form.issuedate.focus();
		return false;
	}
}

function checkContactForm()
{
	if(is_empty(document.order_form.fname.value))
	{
		alert("You must enter your first name.");
		document.order_form.fname.focus();
		return false;
	}
	
	if(is_empty(document.order_form.lname.value))
	{
		alert("You must enter your last name.");
		document.order_form.lname.focus();
		return false;
	}
	
	if(is_empty(document.order_form.addr.value))
	{
		alert("You must enter your address.");
		document.order_form.addr.focus();
		return false;
	}
	
	if(is_empty(document.order_form.city.value))
	{
		alert("You must enter your city.");
		document.order_form.city.focus();
		return false;
	}
	
	if(document.order_form.state.value == "Please Select One")
	{
		alert("Please select your state.");
		document.order_form.state.focus();
		return false;
	}

	if(is_empty(document.order_form.zip.value))
	{
		alert("You must enter your zip code.");
		document.order_form.zip.focus();
		return false;
	}
	
	if (is_empty(document.order_form.email.value))
	{
		alert("Please enter your e-mail address.");
		document.order_form.email.focus();
		return false;
	}
	
	if (echeck(document.order_form.email.value)==false)
	{
		alert("Please enter a valid e-mail address.");
		document.order_form.email.value = "";
		document.order_form.email.focus();
		return false;
	}
	
	if(document.order_form.customer.value == "Please Select One")
	{
		alert("Please select your customer status.");
		document.order_form.customer.focus();
		return false;
	}
	
	if(is_empty(document.order_form.comments.value))
	{
		alert("Please enter your comments.");
		document.order_form.comments.focus();
		return false;
	}	
}

function checkEmail()
{
	if (is_empty(document.order_form.email.value))
	{
		alert("Please enter your e-mail address.");
		document.order_form.email.focus();
		return false;
	}
	
	if (echeck(document.order_form.email.value)==false)
	{
		alert("Please enter a valid e-mail address.");
		document.order_form.email.value = "";
		document.order_form.email.focus();
		return false;
	}
}

function SetCookie(cookieName,cookieValue) 
{
 var today = new Date();
 var expire = new Date();

 var nDays=365;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString()+";path=/";
}
