//validates contents of form
function checkform()
	{
		if (document.getElementById("p_name").value == "")
		{
			alert("Please enter a value for the \"Plaintiff's Name\" field.");
			document.getElementById("p_name").focus();
			return false;
		}
		if (isDate(document.getElementById("p_dob").value) == false & document.getElementById("p_dob").value != "" & isDate2(document.getElementById("p_dob").value) == false)
		{
			alert("Please enter a valid date for \"Date of Birth\" field. (example 7/6/1981)");
			document.getElementById("p_dob").focus();
			return false;
		}
		if (SSNValidation(document.getElementById("p_ssnumber").value) == false & document.getElementById("p_ssnumber").value != "")
		{
			alert("\"SS# (Line #3)\" must in the format ###-##-#### or ######### or left blank.");
			document.getElementById("p_ssnumber").focus();
			return false;
		}		
		if (document.getElementById("p_phone").value == "")
		{
			alert("Please enter a value for the \"Telephone #1\" field");
			document.getElementById("p_phone").focus();
			return false;
		}		
		if (document.getElementById("p_state").value == "--")
		{
			alert("Please select your state.");
			document.getElementById("p_state").focus();
			return false;
		}			
		if (document.getElementById("p_email").value != "")
		{
			// Email validation
			var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
			var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
			if (!reg1.test(document.getElementById("p_email").value) && reg2.test(document.getElementById("p_email").value)) { 
				// do nothing
			}
			else {
				alert("Your email address is not valid. Please enter a valid address for the \"Email Address (Line #10)\" field or leave it blank.");
				document.getElementById("p_email").focus();
				return (false);
			} 
		}
		if (document.getElementById("ls_type").value == "Select Type")
		{
			alert("The first \"Type of Case\" option is not a valid selection.  Please choose one of the other options.");
			document.getElementById("ls_type").focus();
			return false;
		}		
		if (document.getElementById("ls_adv").value == "")
		{
			alert("Please enter a value for the \"Advance Needed\" field.");
			document.getElementById("ls_adv").focus();
			return false;
		}		
		if ((document.getElementById("ls_prevadv").checked == false) && (document.getElementById("ls_prevadv1").checked == false)) {
			alert("Please select Yes or No for the \"Have You Received a Previous Advance?\" question.");
			document.getElementById("ls_prevadv").focus();
			return false;
		}
		if (document.getElementById("a_name").value == "")
		{
			alert("Please enter a value for the \"Attorney's Name\" field.");
			document.getElementById("a_name").focus();
			return false;
		}
		if (document.getElementById("a_phone").value == "")
		{
			alert("Please enter a value for the \"Attorney Telephone\" field");
			document.getElementById("a_phone").focus();
			return false;
		}
		if (document.getElementById("ls_descr").value == "")
		{
			alert("Please describe the incident.");
			document.getElementById("ls_descr").focus();
			return false;
		}			
		if (document.getElementById("ls_injuriesdescr").value == "")
		{
			alert("Please describe your injuries.");
			document.getElementById("ls_injuriesdescr").focus();
			return false;
		}			
		if(document.getElementById("auth_lfc").checked == false)
		{
			alert("You must check the box indicating you have read and agree to Authorization and Release of Information.");
			document.getElementById("auth_lfc").focus();
			return false;
		}		
	return true;
	}
	
//checks to see if the ss# is valid
function SSNValidation(ssn) {
    var IsValid = true;
    var matchArr = ssn.match(/^(\d{3})-?\d{2}-?\d{4}$/);
    var numDashes = ssn.split('-').length - 1;
    if (matchArr == null || numDashes == 1) {
        IsValid = false;
    }
    return IsValid;
}	

//checks to see if a value is numeric
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;


   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}


// Checks to see if the date is valid. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var dtCh2= "-";
var minYear=1850;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   }
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false
	}
	if (strYear.length < 2 || strYear.length == 3 || year==0 || year<minYear || year>maxYear){
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return false
	}
return true
}

function isDate2(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh2)
	var pos2=dtStr.indexOf(dtCh2,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false
	}
	if (strYear.length < 2 || strYear.length == 3 || year==0 || year<minYear || year>maxYear){
		return false
	}
	if (dtStr.indexOf(dtCh2,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh2))==false){
		return false
	}
return true
}

function fnShowDisclaimer() {
	// show pop up window after checking cookie
	var var_disclaimer = getCookie();
	if (var_disclaimer != "true") {
		myWin =  window.open('http://www.lawsuitcash.com/injury-disclaimer.html', 'Disclaimer', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=610,height=240');
		if (myWin == null) {
			alert('Pop Up Window Blocked! Please consider allowing pop ups for this web site.');
		}
	}
	
	// set cookie value to indicate that disclaimer has been shown
	var expDays = 1; 
	var exp = new Date();
	exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
	strCookie = "disclaimer=true; expires=" + exp.toGMTString();
	document.cookie = strCookie;  	
}

function getCookie() {
        var arg = "disclaimer=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) {
                var j = i + alen;
                if (document.cookie.substring(i,j) == arg) {
                        var endstr = document.cookie.indexOf(";",j);
                        if (endstr == -1)
                                endstr = clen;
                        return unescape(document.cookie.substring(j,endstr));
                }
                i = document.cookie.indexOf(" ",i) + 1;
                if (i == 0)
                        break;
        }
        return null;
}