// User data validator



/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

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 trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
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++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
function checkInternationalPhone(strPhone){
var bracket=3;
strPhone=trim(strPhone);
if(strPhone.indexOf("+")>1) return (false);
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return (false);
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return (false);
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return (false);
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}


//E-mail Validattion script Courtesy of SmartWebby.com 
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 Validator(theForm)
{
  //check for valid last name entered  
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ";
  var checkStr = theForm.Last_Name.value;
  var allValid = true;
  var validGroups = true;
  if (checkStr == "")
  {
  	alert("Please enter a value in the \"Last Name\" field.")
	theForm.Last_Name.focus();
	return (false);
  }
  if (checkStr == "Last")
  {
  	alert("Please enter a value in the \"Last Name\" field.")
	theForm.Last_Name.focus();
	return (false);
  }
  if (checkStr.length < 2)
  {
  	alert("Please enter a value in the \"Last Name\" field.")
	theForm.Last_Name.focus();
	return (false);
  }
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter characters in the \"Last Name\" field.");
    theForm.Last_Name.focus();
    return (false);
  }
  //check for valid First Name entered
  var checkStr = theForm.First_Name.value;
  var allValid = true;
  var validGroups = true;
  if (checkStr == "")
  {
  	alert("Please enter a value in the \"First Name\" field.");
	theForm.First_Name.focus();
	return (false);
  }
  if (checkStr == "First")
  {
  	alert("Please enter a value in the \"First Name\" field.");
	theForm.First_Name.focus();
	return (false);
  }
  if (checkStr.length < 2)
  {
  	alert("Please enter a value in the \"First Name\" field.");
	theForm.First_Name.focus();
	return (false);
  }
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter characters in the \"First Name\" field.");
    theForm.First_Name.focus();
    return (false);
  }
//check for valid Middle Name entered
  var checkStr = theForm.Middle_Int.value;
  var allValid = true;
  var validGroups = true;
  if (checkStr == "")
  {
  	alert("Please enter a value in the \"Middle Name\" field. If you do not have a middle name, enter N/A.");
	theForm.Middle_Int.focus();
	return (false);
  }
  if (checkStr == "Middle")
  {
  	alert("Please enter a value in the \"Middle Name\" field. If you do not have a middle name, enter N/A.");
	theForm.Middle_Int.focus();
	return (false);
  }
  if (checkStr.length < 2)
  {
  	alert("Please enter a value in the \"Middle Name\" field. If you do not have a middle name, enter N/A.");
	theForm.Middle_Int.focus();
	return (false);
  }
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter characters in the \"Middle Name\" field.");
    theForm.Middle_Int.focus();
    return (false);
  }
//Check for valid E-mail Address
	var str = theForm.Applicants_Email;
	if ((str.value==null)||(str.value=="")){
		alert("Please Enter your Email Address");
		str.focus();
		return (false);
	}
	if (echeck(str.value)==false){
		str.value=""
		str.focus()
		return (false);
	}

//Check for vaild cell phone number
	var Phone=theForm.Applicants_Cell;
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please enter your cell phone Number or a number where you can be reached.");
		Phone.focus();
		return (false);
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please enter a valid phone number in the \"Cell Phone\" field using this format xxx-xxx-xxxx.");
		Phone.value="";
		Phone.focus();
		return (false);
	}

  var checkStr = theForm.Applicants_Cell.value;
  if (checkStr.length > 12)
  {
    alert("Please enter a valid phone number in the \"Cell Phone\" field using this format xxx-xxx-xxxx.");
    theForm.Applicants_Cell.focus();
    return (false);
  }
 //Check on valid department choices
//	var Park = theForm.Parking.value;
//	var TT=theForm.Ticket_Takers.value;
//	var Usher=theForm.Ushers.value;
//	var Maint=theForm.Maintenance.value;
//	var Sec = theForm.Security.value;
//	var PSec= theForm.Parking_Lot_Security.value;
//	var GS= theForm.Guest_Services.value;
//	var VIP = theForm.VIP.value;
//	var num = 0;
	
	
//		if((Park == "1st")||(Park == "2nd")||(Park == "3rd")||(Park=="4th")){
//			num = num + 1;
//		}
//		if((TT== "1st")||(TT == "2nd")||(TT == "3rd")||(TT == "4th")){
//			num = num + 1;
//		}
//		if((Usher == "1st")||(Usher == "2nd")||(Usher == "3rd")||(Usher == "4th")){
//			num = num + 1;
//		}
//		if((Maint == "1st")||(Maint == "2nd")||(Maint == "3rd")||(Maint == "4th")){
//			num = num + 1;
//		}
//		if((Sec == "1st")||(Sec == "2nd")||(Sec == "3rd")||(Sec == "4th")){
//			num = num + 1;
//		}
//		if((PSec == "1st")||(PSec == "2nd")||(PSec == "3rd")||(PSec == "4th")){
//			num = num + 1;
//		}
//		if((GS == "1st")||(GS == "2nd")||(GS == "3rd")||(GS == "4th")){
//			num = num + 1;
//		}
//		if((VIP == "1st")||(VIP == "2nd")||(VIP == "3rd")||(VIP == "4th")){
//			num = num + 1;
//		}
//		if(num <= 3){
//			alert("You must select a 1st Choice, 2nd Choice, 3rd Choice, and 4th Choice for the department you are interested in working in.")
//			theForm.Previous_Position.focus();
//			return (false);
//		}
//check that the date field isn't left blank  
  	var checkStr = theForm.Submission_Date.value;
	if(checkStr==""){
		alert("Please enter today's date");
		theForm.Submission_Date.focus();
		return(false);
	}

//Check that there has been an address entered
	var checkStr=theForm.Address.value;
	if(checkStr==""){
		alert("Please enter your address");
		theForm.Address.focus();
		return(false);
	}
	if(checkStr=="Street"){
		alert("Please enter your address");
		theForm.Address.focus();
		return(false);
	}
	var checkStr=theForm.City.value;
	if(checkStr==""){
		alert("Please enter the city you live in");
		theForm.City.focus();
		return(false);
	}
	if(checkStr=="City"){
		alert("Please enter the city you live in");
		theForm.City.focus();
		return(false);
	}
	
//Check for valid Zip Code
  var checkStr = theForm.ZipCode.value;
  if (checkStr == "")
  {
    alert("Please enter a valid Zip Code");
    theForm.ZipCode.focus();

    return (false);
  }
  if (checkStr=="Zip"){
	  alert("Please enter a valid Zip Code");
	  theForm.ZipCode.focus();
	  return(false);
  }
  if (checkStr.length < 5)
  {
    alert("Please enter a valid Zip Code");
    theForm.ZipCode.focus();
    return (false);
  }

  if (checkStr.length > 5)
  {
    alert("Please enter a valid Zip Code");
    theForm.ZipCode.focus();
    return (false);
  }

  var checkOK = "0123456789";
  var allValid = true;
  var validGroups = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter a valid Zip Code");
    theForm.ZipCode.focus();
    return (false);
  }
  
//Check for Position Desired selected
	var checkStr=theForm.Position_Desired.value;
	if (checkStr=="Select"){
		alert("Please select the department in which you are applying");
		theForm.Position_Desired.focus();
		return(false);
	}
	
//Check to see that how learned of Live Nation is selected
	var checkStr=theForm.Hear01.value;
	if (checkStr=="HowLearnSelect"){
		alert("Please select on of the options of how you heard about Live Nation");
		theForm.Hear01.focus();
		return(false);
	}
	
//Check if previously employed by Live Nation

	if ((theForm.PrevEmp[0].checked==false)&&(theForm.PrevEmp[1].checked==false)) {
		alert("Please select Yes or No on whether you've previously worked for Live Nation");
		theForm.PrevEmp[1].focus();
		return (false);
	}
	if (theForm.PrevEmp[0].checked == true){
		if(theForm.WhereEmployed.value==""){
			alert("Please fill in the proper information on where you were last employed with Live Nation and when");
			theForm.WhereEmployed.focus();
			return(false);
		}
	}
	
	//Check on work restrictions
	var checkStr=theForm.Restrictions01;
	if ((checkStr[0].checked ==false) && (checkStr[1].checked==false)){
		alert("Please select Yes or No whether you have any work restrictions regarding previous employment");
		theForm.Restrictions01[1].focus();
		return(false);
	}

	if (checkStr[0].checked==true){
		if(theForm.Restrictions02.value==""){
			alert("Please fill in the proper information on what restrictions you may have");
			theForm.Restrictions02.focus();
			return(false);
		}
		if(theForm.Restrictions02.value=="If yes, please explain."){
			alert("Please fill in the proper information on what restrictions you may have");
			theForm.Restrictions02.focus();
			return(false);
		}
	}
//Check on right to work in US
	var checkStr=theForm.Work_Right;
	if((checkStr[0].checked==false)&&(checkStr[1].checked==false)){
		alert("Please select either Yes or No regarding whether or not you can submit verification of your legal right to work in the U.S.");
		theForm.Work_Right[0].focus();
		return(false);
	}

//Check on Terminated
	var checkStr=theForm.Terminated_In_The_Past_10_Years;
	if ((checkStr[0].checked==false)&&(checkStr[1].checked==false)){
		alert("Please select Yes or No whether you have been terminated by an employer");
		theForm.Terminated_In_The_Past_10_Years[1].focus();
		return(false);
	}
	if (checkStr[0].checked==true){
		if(theForm.Termination_Reasons.value==""){
			alert("Please fill in the proper information regarding the terms of which you were terminated or asked to resign");
			theForm.Termination_Reasons.focus();
			return(false);
		}
		if(theForm.Termination_Reasons.value=="If you answered, yes, please provide employer, dates, and circumstances."){
			alert("Please fill in the proper information regarding the terms of which you were terminated or asked to resign");
			theForm.Termination_Reasons.focus();
			return(false);
		}
	}

//Check on Performing Function
	var checkStr=theForm.Function1;
	if((checkStr[0].checked==false)&&(checkStr[1].checked==false)){
		alert("Please select Yes or No whether or not you can perform job functions with or without reasonable accommodation");
		theForm.Function1[0].focus();
		return(false);
	}
	if (checkStr[1].checked==true){
		if(theForm.performance_probs.value==""){
			alert("Please fill in the proper information describing the fuctions that cannot be performed");
			theForm.performance_probs.focus();
			return(false);
		}
		if(theForm.performance_probs.value=="If no, describe the functions that cannot be performed."){
			alert("Please fill in the proper information describing the fuctions that cannot be performed");
			theForm.performance_probs.focus();
			return(false);
		}
	}

//Check on Felony
	var checkStr=theForm.Felony;
	if((checkStr[0].checked==false)&&(checkStr[1].checked==false)){
		alert("Please select Yes or No whether you have been convicted of a felony within the past 7 years");
		theForm.Felony[1].focus();
		return(false);
	}
	if (checkStr[0].checked==true){
		if(theForm.Conviction_Details.value==""){
			alert("Please fill in the proper information regarding the felony in which you were convicted");
			theForm.Conviction_Details.focus();
			return(false);
		}
		if(theForm.Conviction_Details.value=="If above checked yes, please list the date(s) and details."){
			alert("Please fill in the proper information regarding the felony in which you were convicted");
			theForm.Conviction_Details.focus();
			return(false);
		}
	}


//Check on last attended for education
	if(theForm.LastAttended.value==""){
		alert("Please list the highest level of education completed.");
		theForm.LastAttended.focus();
		return(false);
	}



//Check on background check consent
	var checkStr=theForm.Contact_Present_Employer;
	if((checkStr[0].checked==false)&&(checkStr[1].checked==false)){
		alert("Please select either Yes or No regarding whether we may contact your previous employers for a reference check or not");
		theForm.Contact_Present_Employer[0].focus();
		return(false);
	}




//Check on accepting the terms of employment
	if(!theForm.Accept_1of7.checked){
		alert("Please check the first box regarding the validity of the information on the application");
		theForm.Accept_1of7.focus();
		return (false);
	}
	if(!theForm.Accept_2of7.checked){
		alert("Please check the second box regarding the collection of information regarding previous schooling, employment, experience, etc.");
		theForm.Accept_2of7.focus();
		return (false);
	}
	if(!theForm.Accept_3of7.checked){
		alert("Please check the third box regarding Live Nation's terms of employment");
		theForm.Accept_3of7.focus();
		return (false);
	}
	if(!theForm.Accept_4of7.checked){
		alert("Please check the forth box regarding the conditions of an offer of employment");
		theForm.Accept_4of7.focus();
		return (false);
	}
	if(!theForm.Accept_5of7.checked){
		alert("Please check the fifth box regarding your execution of an arbitration agreement.");
		theForm.Accept_5of7.focus();
		return (false);
	}
	if(!theForm.Accept_6of7.checked){
		alert("Please check the sixth box regarding your compliance with Live Nation's employment policies and code of conduct, should you be hired.");
		theForm.Accept_6of7.focus();
		return (false);
	}
	if(!theForm.Accept_7of7.checked){
		alert("Please check the seventh box regarding your understanding of the previous conditions read");
		theForm.Accept_7of7.focus();
		return (false);
	}




	

	

  
}



