﻿function validemail(str){
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
	if (!reg1.test(str) && reg2.test(str)&&str.indexOf(" ")==-1) {
		return true;
	}
	return false;
}
function trimString(str)
{
	if (!(str == "")) {
	while('' + str.charAt(0) == ' '){
		str=str.substring(1,str.length);
	}
	}
	//take out trailing spaces
	if (!(str == "")) {
	while (str.charAt(str.length - 1) == ' '){
    	str = str.substring(0, str.length - 1);
	}
	}
	return str;
}
function verify(){
	var doc = document.expertForm; 
	var strmessage="";
    if (trimString(doc.firm.value) ==""){
        strmessage = "Firm Name:\n";
    }
    if (trimString(doc.contact.value) ==""){
        strmessage = strmessage+"Contact Name:\n";
    }  
    if (trimString(doc.address.value) ==""){
        strmessage = strmessage+"Address:\n";
    }else if (!(checkField(doc.address.value))){
		alert("You have entered invalid data in this field including web addresses or URLs, which are not acceptable.\nPlease edit and resubmit.");
		doc.address.focus();
		return;
	}   
    if (trimString(doc.email.value) ==""){
        strmessage = strmessage+"Email Address:\n";
    }else if (!(validemail(doc.email.value))){
		strmessage = strmessage+"Email Address is not valid.\n";
	}
	var stripped = doc.phone.value.replace(/[\(\)\.\-\ ]/g, '');
    if (stripped ==""){
        strmessage = strmessage+"Phone:\n";
    }else if (isNaN(parseInt(stripped))) {
	   		strmessage = strmessage+"The phone number contains illegal characters.\n";
	}else if (!(stripped.length == 10)) {
			strmessage = strmessage+"The phone number is the wrong length.\n Make sure you included an area code.\n";
	}
	if (!(checkField(doc.stageOfCase.value))){
		alert("You have entered invalid data in this field including web addresses or URLs, which are not acceptable.\nPlease edit and resubmit.");
		doc.stageOfCase.focus();
		return;
	}   
	if (!(checkField(doc.summaryOfCase.value))){
		alert("You have entered invalid data in this field including web addresses or URLs, which are not acceptable.\nPlease edit and resubmit.");
		doc.summaryOfCase.focus();
		return;
	}   
	if (!(checkField(doc.parametersForWitness.value))){
		alert("You have entered invalid data in this field including web addresses or URLs, which are not acceptable.\nPlease edit and resubmit.");
		doc.parametersForWitness.focus();
		return;
	}   
	if (!(checkField(doc.deadlineDetails.value))){
		alert("You have entered invalid data in this field including web addresses or URLs, which are not acceptable.\nPlease edit and resubmit.");
		doc.deadlineDetails.focus();
		return;
	}   

    if(strmessage == ""){
        alert("Your request form will be submitted to RTG \nand a representative will contact you soon.");
        doc.submit();
		return true;
		  
    }else{  
        alert("You have one or more of the following fields missing\n\n"+strmessage+
          " \nYou must correct them prior to submitting this request form.\n");
          return false;
    } 
}
function validateSize(obj, limit){ 
//example function call to be placed inside <input> onkeyup="validateSize(this,'60')"
	var val = trimString(obj.value);
	if (val.length > limit){
		alert("You have exceeded the field limit of " + limit + " characters.");
		obj.value = val.substring(0, limit);
	}
}
function checkField(val){

	var valar = val.split("http://");
	if (1<valar.length)
		return false;
	valar = val.split("www.");
	if (1<valar.length)
		return false;
	return true;
}
function getURL(){
  var strReturn = "";
  var strHref = window.location.href;
  if (strHref.lastIndexOf("/") !=-1){
    var slashPos = strHref.lastIndexOf("/");
    strReturn = strHref.substring(0,slashPos+1);
  }
  return strReturn;  
}
function loadSearchForm () {
  var url = getURL();
  window.location.href = url+"Initiate Custom Expert Search.aspx";
}
function clearConfirm() {

document.expertForm.reset();
}
function IsEmptyString(StringToCheck)
{
StrToCheck= StrToCheck.replace(/^\s+|\s+$/, '');
if( StrToCheck.length==0)
return false;
else
return true;
}
function checkRecaptcha()
{
var elems = document.forms[0].elements;
for(var i=0;i<elems.length;i++)
 {
 if(elems[i].name=="recaptcha_response_field")
 {
 if(IsEmptyString(elems[i].value))
 {
 alert("Please Enter a Value");
 }
 }
 }
}
function clearForm1()
{
var elems = document.forms[0].elements;

 for(var i=0;i<elems.length;i++)
 {
  if( elems[i].type=="text")
  {   

  elems[i].value="";
  }
    if(elems[i].type=="select-one")
    {
    var str = elems[i].name;
    if(str.match("Country"))
    {
     elems[i].value="1";
    }
   if(str.match("State"))
    {
  //  alert(elems[i].value);
     elems[i].value="0";
     elems[i].disabled=false;
    }
    }
    if(elems[i].type=="textarea")
    {
     elems[i].value="";
    }
    if(elems[i].type=="radio")
    {
    elems[i].checked=false;
    }

    }
}