function checkforcookies()
{
/*This is all very simple, on the page load, we call this function.  Here, we check for a cookie,
 if there is one, go to the else statement where we dont do a thing.  Otherwise, redirect to the 'no cookies'

  check for a cookie */

  var allcookies = document.cookie;
  var mktSegCookie = allcookies.indexOf("MarketSegment");

  if (document.cookie == "" || mktSegCookie == -1)
  {
    /* if a cookie is not found - alert user -*/
    window.location="nocookies.html"
     return false;
  } else {
   /* the user has cookies, so leave them be*/
   return true;
  }
}

function valCookies()
{
 /*This is all very simple, on the page load, we call this function.  Here, we check for a cookie,
 if there is one, go to the else statement where we dont do a thing.  Otherwise, redirect to the 'no cookies'

  check for a cookie */

  var allcookies = document.cookie;
  var mktSegCookie = allcookies.indexOf("MarketSegment");

  if (document.cookie == "" || mktSegCookie == -1)
  {
     return false;
  } else {
   return false;
  }
}
/*
Set a cookie to be sure that one exists.
   Note that this is outside the function*/
//document.cookie = 'tmpcookie' + escape('nothing')
//

function LeftNavSearch_Validator(theForm)
{
    //alert('called!');
    var s;
    s = theForm.SearchTerm.value;
    //alert(theForm.SearchTerm.value);
    filteredValues = "!@#$%^&*()[]{}-_+=\\/;':\",.<>?";     // Characters stripped out
    var i;
    var returnString = "";
    for (i = 0; i < s.length; i++) {  // Search through string and append to unfiltered values to returnString.
    //    alert(c);
        var c = s.charAt(i);
        if (filteredValues.indexOf(c) == -1) returnString += c;
    }
    //alert(returnString);
    theForm.SearchTerm.value = returnString;

  if (theForm.SearchTerm.value.length < 3)
  {
    alert('Please enter at least 3 characters in the Search For field.');
    return false
  }
  
  else{
    
  return true
  }
}

function LeftNavKeyPress(e,theForm)
{
     var key;

     if(window.event){
          key = window.event.keyCode;     //IE
          }
     else{
          key = e.which;     //firefox
}
     if(key == 13){
        //alert('level1');
                /*if (theForm.SearchTerm.value.length > 0)
                    {
                    //alert('level2');
                        if (theForm.SearchTerm.value.length < 3)
                            {
                            //alert('level3');
                                alert('Please enter at least 3 characters in the Search For field.');
                                return false;
                            }
                        else
                        //alert('level4');
                           // return true;
                            theForm.submit();
                   }
                   else
                       return false;
              */
              return LeftNavSearch_Validator(theForm)         
          }
          
     else

          return true;
}

function valContactForm(theForm){
//alert(theForm.Name.value);

if (trim(theForm.Name.value) == ''){
    alert('Please enter your name');
    return false;
}

else if (trim(theForm.Phone.value) == ''){
    alert('Please enter your phone');
    return false;
}

else if (trim(theForm.EMail.value) == ''){
    alert('Please enter your email');
    return false;
}

else if (trim(theForm.S1.value) == ''){
    alert('Please enter your message');
    return false;
}
else{
    return true;
}

}

function ltrim(str) { 
	for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
	return str.substring(k, str.length);
}
function rtrim(str) {
	for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--);
	return str.substring(0,j+1);
}
function trim(str) {
	return ltrim(rtrim(str));
}
function isWhitespace(charToCheck) {
	var whitespaceChars = " \t\n\r\f";
	return (whitespaceChars.indexOf(charToCheck) != -1);
}
