// JavaScript Document

// clears and replaces text in form input fields and textareas
// -----------------------------------------------------------------
function clearText(thefield) {
  if (thefield.defaultValue==thefield.value) { thefield.value = "" }
} 
function replaceText(thefield) {
  if (thefield.value=="") { thefield.value = thefield.defaultValue }
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function bookmark()
{
bookmarkurl="http://www.onlinelawyersource.com"
bookmarktitle="Online Lawyer Source"
if (document.all)
window.external.AddFavorite(bookmarkurl,bookmarktitle)
}

function verify(fields)
{
    var msg;
    var empty_fields = "";
    var errors = "";
	var thePosition;
	var email;
   
	
    for(var i = 0; i < fields.length; i++) 
	{
        var formver = fields.elements[i];
				
		//thePosition=formver.name.indexOf("_");
		//if(-1==thePosition)
		//{
			//thePosition=formver.name.length;
		//}
			
//////////////////////////////////////////////////////////////////////////////////////////////////		
		//Checks for blank required fields
        if (formver.id== 'text') //checks for required fields
		{
            //check if the field is empty
            if ((formver.value == null) || (formver.value == "") || (formver.value == "Name") || (formver.value == "Type of Injury") || (formver.value == "Cause of Injury") || (formver.value == " Name of Injured Party")) 
			{
                empty_fields += "\n          " + formver.name
                continue;
            }
        }

//////////////////////////////////////////////////////////////////////////////////////////////////		
		//Phone
		
		if (formver.id == 'phone')
		{
			var error = "";
			var stripped = formver.value.replace(/[\(\)\.\-\ ]/g, '');    
	
			if (isNaN(parseInt(stripped))) 
			{
				errors = "The phone number contains invalid characters.\n";
				//fld.style.background = 'Yellow';
				continue;
			} else if (!(stripped.length == 10)) 
			{
				errors = "The phone number is the wrong length. Make sure you included an area code.\n";
				//fld.style.background = 'Yellow';
				continue;
			}
			//return error;
		}
		

////////////////////////////////////////////////////////////////////////////////////////////////////	
		// check to see if email address field is of valid syntax 
  
    if (formver.id == 'email')//Checks for an email field
	{
	  substremail = formver.value.split("@")   
      if (substremail.length > 1)//makes sure the email address has an @ symbol   
      {   
          index = substremail[1].indexOf(".") 
		     
           if (index == -1)   //makes sure there is a dot (.) in the address
           { 
		    
           errors = "Please enter a valid e-mail address";               
		   continue; 
           }   
      } 
  
      else 
	  	{  
           errors = "Please enter a valid e-mail address";     
           continue;  
      	}
	  }
	if (formver.id == 'number')//checks for a number field
	 {	 
	 if (IsNumeric(formver.value)==false)//checks for a non numeric value
		{			
			errors = "Please enter a numeric value";
			continue;	
			
		}
		//if (formver.value.length != formverid[1])//checks to see if the value length matches the perameters
		//	{
		//	errors = "Please enter a 5 digit zip code";
		//	continue;
		//	}	
		
	}
	 
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////	
    // if there were any errors, display the messages, and
    // return false to prevent the form from being submitted. 
    
	if (!empty_fields && !errors) return true;
    
	msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"
    
	if (empty_fields) 
	{
        msg += "The following required field(s) are empty:"
                + empty_fields + "\n";
        if (errors) msg += "\n";
    }
    	msg += errors;
    	alert(msg);
    	return false;  
	
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// this function is called to check if a value is numberic
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;
}


function verifystate(f)
{
    var msg;
    var empty_fields = "";
    var errors = "";
	var thePosition;
	var email;	
	for(var i = 0; i < f.length; i++) 
	{
		var e = f.elements[i];
		if(e.name)
		{
			if(e.name=='State')
			{
				if(e.value!='State'&&e.value!='')
				{
					return true;	
				}
			}			
		}
	}
    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following empty field(s).\n";
    msg += "Please fill out all required fields and re-submit.\n";
    msg += "______________________________________________________\n\n"
    msg += "Selecting a state is required"+ "\n";
    alert(msg);
    return false;	
}


// performs form verification, invoked from the onSubmit() event handler. 
// Loop through the elements of the form, looking for all 
// text and textarea elements that don't have an "optional" property
// defined. Then, check for fields that are empty and make a list of them.
// Put together error messages for invalid fields.
// Writen by Scott Winterbourne June 20th, 2005.

function verifyAll(fields)
{
    var msg;
    var empty_fields = "";
    var errors = "";
	var thePosition;
	var email;	
    for(var i = 0; i < fields.length; i++) 
	{
		var formver = fields.elements[i];
			if(formver.name!='formfield12345678925'&&formver.name!='formfield12345678935'&&formver.name!='formfield12345678945'&&formver.name!='formfield12345678915')
			{
				if ((formver.name!='')&&((formver.value == null) || (formver.value == "") || (formver.value == "Name") || (formver.value == "Address") || (formver.value == "Phone") || (formver.value == "What were you diagnosed with?") || (formver.value == "Email") || (formver.value == "Date Injury Occurred?"))) 
				{
					empty_fields += "\n          " + formver.name
					continue;
				}	
			}
	}
	if (!empty_fields) return true;
    
	msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"
    
	if (empty_fields) 
	{
        msg += "The following required field(s) are empty:"
                + empty_fields + "\n";
        if (errors) msg += "\n";
    }
    	msg += errors;
    	alert(msg);
    	return false;  
		
}




function getURL(theForm)
{
	var searchBox = theForm.theSection;
	var area = searchBox.options[searchBox.selectedIndex].value;
	if(area=='default')
	{
		alert('Please choose an area of law.');
		return false;			
	}	
	if(theForm.ZipCode.value=='')
	{
		alert('Please Select a State');
		return false;
	}
	if(theForm.additionalSelecttheSection)
	{
		var area = theForm.additionalSelecttheSection.options[theForm.additionalSelecttheSection.selectedIndex].value;		
		switch(area)
		{
			case 'bail_bond': 
				theForm.action = 'http://www.onlinelawyersource.com/other/bail_bond/contact.html';								
			break;
			case 'workers_compensation':
				theForm.action = 'http://www.onlinelawyersource.com/other/workers_compensation/contact.html';						
			break;
			case 'meridia':
				theForm.action = 'http://www.onlinelawyersource.com/drug_recall/meridia/contact.html';						
			break;
			case 'fen_phen':
				theForm.action = 'http://www.onlinelawyersource.com/drug_recall/fen_phen/contact.html';						
			break;
			default:
				theForm.action = 'http://www.onlinelawyersource.com/'+area+'/contact.html';					
		}
	}
	else if(theForm.additionalSelecttheSection2)
	{
		var area = theForm.additionalSelecttheSection2.options[theForm.additionalSelecttheSection2.selectedIndex].value;		
		switch(area)
		{
			case 'bail_bond': 
				theForm.action = 'http://www.onlinelawyersource.com/other/bail_bond/contact.html';								
			break;
			case 'workers_compensation':
				theForm.action = 'http://www.onlinelawyersource.com/other/workers_compensation/contact.html';						
			break;
			case 'meridia':
				theForm.action = 'http://www.onlinelawyersource.com/drug_recall/meridia/contact.html';						
			break;
			case 'fen_phen':
				theForm.action = 'http://www.onlinelawyersource.com/drug_recall/fen_phen/contact.html';						
			break;
			default:
				theForm.action = 'http://www.onlinelawyersource.com/'+area+'/contact.html';					
		}
	}	
	//else if(searchBox.options[searchBox.selectedIndex].value=='divorce')
	//{
	//	theForm.action = 'http://www.onlinelawyersource.com/divorce/family-law/'+replaceAll( theForm.ZipCode.value, "-", "_" )+'_contact.html';
	//	theForm.method = 'get';
		//theForm.action = 'http://www.onlinelawyersource.com/divorce/family-law/contact.html';
	//}
	else if(searchBox.options[searchBox.selectedIndex].value=='product_liability')
	{
		theForm.action = 'http://www.onlinelawyersource.com/liability/index.html';		
	}
	else if(searchBox.options[searchBox.selectedIndex].value=='drug_recall')
	{
		theForm.action = 'http://www.onlinelawyersource.com/drug_recall/drug_recall.html';		
	}
	else if(searchBox.options[searchBox.selectedIndex].value=='more_legal_areas')
	{
		theForm.action = 'http://www.onlinelawyersource.com/other/index.html';		
	}
	else if(searchBox.options[searchBox.selectedIndex].value=='truck-accidents')
	{
		theForm.action = 'http://www.onlinelawyersource.com/truck-accidents/contact.html';		
	}
	else{
		theForm.action = 'http://local.onlinelawyersource.com/'+theForm.ZipCode.value;
		theForm.theSection.name='thecampaign';
		theForm.method='GET';
		//theForm.action = 'http://www.onlinelawyersource.com/new/local/state.php';
	}
}

function changeMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function replaceAll( str, from, to ) {
    var idx = str.indexOf( from );


    while ( idx > -1 ) {
        str = str.replace( from, to ); 
        idx = str.indexOf( from );
    }

    return str;
}

// HTML 5 Video

VideoJS.setupAllWhenReady();


	
	
