//This function, register, creates a cookie with the name and the value passed to it as an argument.
//
function register(name) {
           var today = new Date();
           var expires = new Date();
           expires.setTime(today.getTime() + 60*60*24*1000*1);
           setCookie("Investor", name, expires);
}
function setCookie(name, value, expire) 
{  
  document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()));
}
// MAIN development that is calling the function register to set a cookie here.
//
register("package");
// END
//-------------------------------------------------------------------------------------------------
//  VALIDATING THE FORM 
function validate(theform)
  	{
  	if 	  	(	isName(theform)
			&&  isCompany(theform)
			&&	isStateProvince(theform)
			&&	isCountry(theform)
			&&	isPhone(theform)
			&&	isEmail(theform)

			)   
  	 	{
		   			return true;
         	}
         		return false;
    }
function isEmptyOrBlank(theValue)
{
  if (theValue === "") return true;    
  var allBlank = true;
  var loop = 0;
  while (loop < theValue.length && (allBlank))
  {
 	 	if (theValue.substring(loop , loop + 1) != " ")	allBlank = false;
		loop++
  }
  if (allBlank)	return true;
  return false;   
}
function isEmptyWithAlert(theValue, msg)
{
  if (isEmptyOrBlank(theValue))
  {
    alert(msg + ' must be filled');
    return true;
  }
  if (theValue.substring(0,1) == " ")
  {
  	alert(msg + " must not start with blanks.");
   	return true;
  }
  return false;   
}
// Checks the NAME field.
function isName(theform)
{
   var str = theform.Name.value;
// Return false if Name field is blank.
   if (isEmptyWithAlert(str, "Name"))
	{ 
	     theform.Name.select();
         theform.Name.focus();
		 return false;
	 }
   return true;
}
// Checks the COMPANY field.
function isCompany(theform)
{
   var str = theform.Company.value;
// Return false if Company field is blank.
   if (isEmptyWithAlert(str, "Company"))
	{ 
	     theform.Company.select();
         theform.Company.focus();
		 return false;
	 }
   return true;
}
// Checks the STATE/PROVINCE field.
function isStateProvince(theform)
{
   var str = theform.State-Province.value;
// Return false if name field is blank.
   if (isEmptyWithAlert(str, "State/Province"))
	{ 
	     theform.State-Province.select();
         theform.State-Province.focus();
		 return false;
	 }
   return true;
}
// Checks the COUNTRY field.
function isCountry(theform)
{
   var str = theform.Country.value;
// Return false if name field is blank.
   if (isEmptyWithAlert(str, "Country"))
	{ 
	     theform.Country.select();
         theform.Country.focus();
		 return false;
	 }
   return true;
}
// Checks the PHONE field.
function isPhone(theform)
{
   var str = theform.Phone.value;
// Return false if name field is blank.
   if (isEmptyWithAlert(str, "Phone"))
	{ 
	     theform.Phone.select();
         theform.Phone.focus();
		 return false;
	 }
   return true;
}
//function isDatabase(theform)
//{
//   var str = theform.Database.value;
//   
//   	if (theform.Database.selectedIndex == 0) {
//		alert ('Please choose a Product ');
//		theform.Database.focus();
//		return false;
//	}
//   
//   return true;
//		
// }
// Checks the EMAIL field.
function isEmail(theform)
{
    if (isEmptyWithAlert(theform.Email.value, "Email") )
      {
//      alert("\nThe E-MAIL field is blank.\n\nPlease enter your e-mail address.")
      theform.Email.focus();
      return false; 
      }
   // Return false if e-mail field does not contain a '@' and '.' .
   if (theform.Email.value.indexOf ('@',0) == -1 || theform.Email.value.indexOf ('.',0) == -1)
      {
      alert("\nThis is not a valid email address.\n\nPlease re-enter your e-mail address.")
      theform.Email.select();
      theform.Email.focus();
      return false;
      }
   else
      {
      return true;
      }
}
