<!-- 

//-------------------------------------------------------------------------------------
//
// Author:	Dan Carlson
// Modified by: Marc Fogel
// Description:	Contained JavaScript functions specific to Freightliner Case Study and White Paper
//------------------------------------------------------------------------------------- 

//-------------------------------------------------------------------------------------
// Perform input validations, set the appropriate submit action, and then submit
// input data to server.
//-------------------------------------------------------------------------------------

function DoSubmit() {

	if (!ValidUserInput()) return;
    
	DownloadCaseStudy.submit();
}

function DoSubmitGW() {

	if (!ValidUserInput()) return;
	
	DownloadGreenWhitePaper.submit();

}

function DoSubmitW() {

	if (!ValidUserInput()) return;
    
	DownloadWhitePaper.submit();
}

// Submit code for C_CaseStudy2.asp
function DoSubmitR() {

	if (!ValidUserInput()) return;
    
	DownloadCaseStudy2.submit();
}
//-------------------------------------------------------------------------------------
// Inserts a red asterisk for all required fields. Note: You must add the custom 
// attribute "InputReq='y'" to all TD elements used as labels for input fields in the
// user interface.  
//-------------------------------------------------------------------------------------
function SetRequiredInputFlags() {

	var aInputFields = document.getElementsByTagName("label");
//	alert("counts " + aInputFields.length);
	var sAsterisk = '<label style="color:red;font-weight:bold">*</label>'
    
	for (var i=0; i<aInputFields.length; i++) {
		var oField = aInputFields[i];
		if (oField.getAttribute("InputReq") != null) {
		var sText = oField.innerHTML;
		oField.innerHTML = "";
		oField.innerHTML = sText + " " + sAsterisk;
		}        
	}
}

//-------------------------------------------------------------------------------------
// Validate user input.
//-------------------------------------------------------------------------------------
function ValidUserInput() {

 //   var da = document.all;
 
 	//Name.
    if ($("Name").value.length == 0) {
        alert("Please enter your name.");
        $("Name").focus();
        return false;
    }	

 	//Company Name
    if ($("company").value.length == 0) {
        alert("Please enter your Company name.");
//        $("company").focus();
        return false;
    }

    //Email.
	
    if ($("Email").value.length == 0) {
        alert("Please enter your email address.");
        $("Email").focus();
        return false;
    }
	
	var apos=$("Email").value.indexOf("@");
	var dotpos=$("Email").value.lastIndexOf(".");

	if ((apos<1) || ((dotpos-apos)<2)) {
		alert("Please enter a valid email address.");
  		$("Email").focus();
  		return false;
}

    //Area code.
	
    if ($("telephone").value.length == 0) {
        alert("Please enter your area code and phone number.");
        $("telephone").focus();
        return false;
    }	

	if ($("telephone").value.length != 3) {
		alert("Please Enter 3 Digits");
		$("telephone").focus();
		return false;
   }
   
	//Phone prefix.
    if ($("telephone2").value.length == 0) {
        alert("Please enter your phone number.");
        $("telephone2").focus();
        return false;
    }	

	if($("telephone2").value.length != 3) {
		alert("Please Enter 3 Digits");
		$("telephone2").focus();
		return false;
   }
    //Phone suffix.
    if ($("telephone3").value.length == 0) {
        alert("Please enter your phone number.");
        $("telephone3").focus();
        return false;
    }	

	if($("telephone3").value.length != 4) {
		alert("Please Enter 4 Digits");
		$("telephone3").focus();
		return false;
   }

    //Success.
    return true;

}

function KeyPhoneNumberOnly(evt) {

	var charCode = (evt.which) ? evt.which : event.keyCode;
//	alert("charcode " + charCode + ", evt.which = " + evt.which);
    if ((charCode >= 48 && charCode <= 57)) {
        //Allow 0-9    
    }
    else if (charCode == 45) {
        // allow hyphen
    }
    else {
        //Not valid.
        return false;
    }
    
    return true;    
}

// ******* allows only letters in text box - no numbers or special characters
function KeyTextOnly(evt) {

	var charCode = (evt.which) ? evt.which : event.keyCode;
//	alert("charcode " + charCode + ", evt.which = " + evt.which);
    if ((charCode >= 97 && charCode <= 122)) {
        //Allow a-z    
    }
    else if ((charCode >= 65 && charCode <= 90)) {
        //Allow A-Z    
    }    
    else if (charCode == 46) {
        // allow period
    }
    else if (charCode == 32) {
        // allow space
    }   
    else if (charCode == 8) {
        // allow backspace
    } 
    else {
        //Not valid.
        return false;
    }
    
    return true;    
}

	
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Cyanide_7 |  */
var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
  var keyCode = (isNN) ? e.which : e.keyCode; 
  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
  if(input.value.length >= len && !containsElement(filter,keyCode)) {
    input.value = input.value.slice(0, len);
    input.form[(getIndex(input)+1) % input.form.length].focus();
  }

function containsElement(arr, ele) {
    var found = false, index = 0;
    while(!found && index < arr.length)
    if(arr[index] == ele)
    found = true;
    else
    index++;
    return found;
  }

function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
    if (input.form[i] == input)index = i;
    else i++;
    return index;
  }
  return true;
}
// * end of tab next function


function $(sName) {

	return document.getElementById(sName);
}

function FocusName() {
	$("Name").focus();
}

-->