//----------------------------------------------------------
//	Project Validation Routines
//----------------------------------------------------------


function LTrim(str)
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
}

function RTrim(str)
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {

      var i = s.length - 1;       // Get length of string
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }

   return s;
}

function Trim(str)
{
   return RTrim(LTrim(str));
}

function ValidateTextField(varData, msg) {
	if (Trim(varData.value) == "") {
		if (msg == "") {
			msg += "A value is required for this field.\n";
		}
		alert(msg);
		varData.focus();
		varData.select();
		return false;
	}
	return true;
}

function ValidateEmail(item) {
	var lsAT;
	var lsDOT;

	lsAT = item.value.indexOf("@");
	lsDOT = item.value.indexOf(".");
	
	if (lsAT == -1 || lsDOT == -1 || item.value.indexOf(" ") != -1 ) {
		alert("The Email Address you have entered is invalid")
		item.focus();
		item.select();
		return false;
	}	
	return true;
}

function ValidateWhereHeard(item) {
	if (item.value == -1) {
		alert("Please specify where you heard about us");
		
		return false;
	}	
	return true;
}

function ValidateProductSamples(item) {
	if (item.value=="--") {
		alert("Please select the samples you wish to receive")
		item.focus();
		return false;
	}	
	return true;
}

function ValidateWhitePaper(item) {
	
	if (item.value=="--") {
		alert("Please select the whitepaper you wish to receive")
		item.focus();
		return false;
	}	
	return true;
}

function ValidateWebinar(item) {
    if (item.value=="--") {
		alert("Please select the type of webinar you wish to attend")
		item.focus();
		return false;
	}	
	return true;
}
function ValidateDropDown(item, msg) {
    if (item.value=="--") {
		alert(msg)
		item.focus();
		return false;
	}	
	return true;
}
function ValidateWhatSystems(item) {    
    if (item.value=="--") {
		alert("Please enter one or more JDE platforms")
		item.focus();
		return false;
	}	
	return true;
}

function ValidateCollection(item, msg) 
{   
    var hasSelected = false;
   
    for (i = 0; i < item.length; i++)
    {
        if (item[i].checked)
        {
            hasSelected = true;
            break;
        }
    }
     
    if (!hasSelected) {
		alert(msg)
		return false;
	}	
	return true;
}

	
