// Check that text input not blank
	function isEmpty (s) {
		var i;
		var space = " \r\n";
		if ((s == null) || (s.length < 1)) return true;
		for (i = 0; i < s.length; i++) {
			var ch = s.charAt(i);
			if (space.indexOf(ch) == -1) return false;
		}
		return true;
	}

// Check to make sure text input is in the form of an Email Address
	function isEmail (s) {
		if (isEmpty(s)) return false;
		if (s.indexOf('@') == -1) return false;
		if (s.indexOf('.') == -1) return false;
		if (s.length < 4) return false;
		return true;
 	}

	function isPhoneNum(s){
			var stripped = s.replace(/[\(\)\.\-\ ]/g, '');
			//strip out acceptable non-numeric characters
			if (isNaN(parseInt(stripped))) {
			   error = "The phone number contains illegal characters.";return false;
			}else{
			return true;
			}
	}
	function isGoodEmail(s) {
		if ((s.indexOf('@yahoo') != -1) || (s.indexOf('@hotmail') != -1) || (s.indexOf('@gmail') != -1) || (s.indexOf('@aol') != -1) || (s.indexOf('@rediffmail') != -1)
			|| (s.toLowerCase().indexOf('@yahoo')!= -1) || (s.toLowerCase().indexOf('@hotmail')!= -1) || (s.toLowerCase().indexOf('@gmail')!= -1) || (s.toLowerCase().indexOf('@aol')!= -1) || (s.toLowerCase().indexOf('@rediffmail')!= -1)
		) return true;
		return false;
 	}

//  Check to make sure select box value not empty
	function isSelected(s) {
		if (s.selectedIndex == 0) return true;
		else return false;
	}

// Check business type
	function checkBusiness(busType) {
		//modified for IPS # PC4027
        //if (busType.options[busType.selectedIndex].value == "Academic") alert("Academic organizations are not eligible for a corporate trial. \r\nPlease go to www.ieee.org/go/freetrial to request a trial for your institution.");

		if (busType.options[busType.selectedIndex].value == "Individual") alert("Individuals are not eligible for the free trial.");
	}

// Check job title
	function checkJobTitle(busType) {
		//modified for IPS # PC4027
        //if (busType.options[busType.selectedIndex].value == "Faculty/Professor") alert("Academic organizations are not eligible for a corporate trial. \r\nPlease go to www.ieee.org/go/freetrial to request a trial for your institution.");

        // HD 165364
        if (busType.options[busType.selectedIndex].value == "Student") alert("Thank you for your interest in a free trial. \nIEEE Xplore trials must be initiated by your institution's librarian. Please inform your librarian of your interest in IEEE Xplore.");
	}

function enablestate()
{
	var selObj = document.getElementById("00N50000001RYTt");

	if ((document.trialform.elements['00N50000001RYTy'].value == 'United States') || (document.trialform.elements['00N50000001RYTy'].value == 'Canada'))
	{
		selObj.options[66] = null;
                selObj.remove(65);
		document.trialform.elements['00N50000001RYTt'].disabled = false;
	}else {
		selObj.options[66]=new Option("Outside the U.S or Canada" , "Outside the U.S or Canada");
		selObj.options[66].selected = true;
		document.trialform.elements['00N50000001RYTt'].disabled = true;


	}
}

// Cycle through required form fields
function checkFields() {

   if (document.trialform.elements['00N50000001Q9mV'].options[document.trialform.elements['00N50000001Q9mV'].selectedIndex].value == "Individual") {

          alert("Individuals are not eligible for the free trial.");

          return false;

    }
    else
        if (isEmpty(document.trialform.first_name.value)) {
          alert( "Please enter your first name.");
          document.trialform.first_name.focus();
          return false;
    } else
        if (isEmpty(document.trialform.last_name.value)) {
          alert( "Please enter your last name.");
          document.trialform.last_name.focus();
      return false;
    } else
        if (isEmpty(document.trialform.company.value)) {
          alert( "Please enter your company.");
          document.trialform.company.focus();
      return false;
    } else
        if (isSelected(document.trialform.elements['00N50000001Q9mV'])) {
          alert("Please select your business type.");
          document.trialform.elements['00N50000001Q9mV'].focus();
      return false;
    } else
        if (isSelected(document.trialform.elements['00N50000001Q9mU'])) {
          alert( "Please select your job title.");
          document.trialform.elements['00N50000001Q9mU'].focus();
      return false;
    } else
        if (document.trialform.elements['00N50000001Q9mU'].options[document.trialform.elements['00N50000001Q9mU'].selectedIndex].value == "Student") {
          checkJobTitle(document.trialform.elements['00N50000001Q9mU']);
          document.trialform.elements['00N50000001Q9mU'].focus();
      return false;
    }  else
        if (isEmpty(document.trialform.elements['00N50000001RYTj'].value)) {
          alert( "Please enter your address.");
          document.trialform.elements['00N50000001RYTj'].focus();
      return false;
    } else
        if (isEmpty(document.trialform.elements['00N50000001RYTk'].value)) {
          alert( "Please enter your city.");
          document.trialform.elements['00N50000001RYTk'].focus();
      return false;
    } else
        if (isSelected(document.trialform.elements['00N50000001RYTy'])) {
          alert( "Please select your country.");
          document.trialform.elements['00N50000001RYTy'].focus();
      return false;
    } else
        if (isSelected(document.trialform.elements['00N50000001RYTt'])) {
          alert( "Please select your state/province.");
          document.trialform.elements['00N50000001RYTt'].focus();
      return false;
    } else
        if (!isEmail(document.trialform.email.value)) {
          alert( "Please enter your email address.");
          document.trialform.email.focus();
      return false;
    } else
        if (isGoodEmail(document.trialform.email.value)) {
          alert("You have provided a personal email address. Please provide a corporate email address.");
          document.trialform.email.focus();
      return false;
        }
        return true;
}