function checkEmail(e) {
  ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

  for(i=0; i < e.length ;i++){
    if(ok.indexOf(e.charAt(i))<0){ 
	  //found character not in OK string
      return -1;
      }	
    } 
  
  // Note {2, 4} indicates the length of domain from 2 to 4 characters. For example .com, .tv, .us
  if (document.images) {
   re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
   re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
   if (!e.match(re) && e.match(re_two)) {
     //Everything is OK
     return 1;		
     } 
   }
  
  //Bad by Default
  return -1;
  }
  
function indicateError(el){
  if(document.all || document.getElementByID){
    // change the color of text field
    el.style.background = "yellow"; 
	el.onfocus = new Function("this.style.backgroundColor = '#FFFFFF';this.onfocus='';");
    }
  
  return false;
  }

function indicateErrorSelect(el){
  if(document.all || document.getElementByID){
    // change the color of text field
    el.style.background = "yellow"; 
	el.onchange = new Function("this.style.backgroundColor = '#FFFFFF';");
    }
  
  return false;
  }  
  
function deactivate(el){

  if(document.all || document.getElementByID){
    if(el.style.background == "yellow"){
      // change the color of text field
      el.style.background = "white";
	  } 
	
    }
  
  return false;
  }  


function validateForm(){
  if (window.document.chatForm.firstname.value == ""){
    alert('Please enter your first name.');
	indicateError(window.document.chatForm.firstname);
	return false;
	}
  if (window.document.chatForm.lastname.value == ""){
    alert('Please enter your last name.');
	indicateError(window.document.chatForm.lastname);
	return false;
	}
  if (window.document.chatForm.email.value == ""){
    alert('Please enter your email address so we can send you a reply.');
	indicateError(window.document.chatForm.email);
	return false;
	}
  
  if (checkEmail(window.document.chatForm.email.value) < 0){
    alert('Please enter in a valid email address.');
	indicateError(window.document.chatForm.email);
	return false;
	}

  if(!window.document.chatForm.accept.checked) {
    alert('You must check the checkbox indicating you understand our terms and conditions.');
	indicateError(window.document.chatForm.accept);
	return false;
	}	
	
	var url = 'http://www.healthcentral.com/utils/registration/Backup?' 
	+ 'cm_id=ctca' 
	+ '&firstname=' + escape(document.chatForm.firstname.value) 
	+ '&lastname=' + escape(document.chatForm.lastname.value) 
	+ '&email=' + escape(document.chatForm.email.value) 
	+ '&accept=' + escape(document.chatForm.accept.checked) 
	+ '&ap=' + site_ap;
	document.getElementById('backupdiv').innerHTML = '<IMG SRC="' + url + '" WIDTH=1 HEIGHT=1 BORDER=0>';

  newwin = window.open('', 'chat_window', 'screenX=10,screenY=25,top=25,left=10,width=500,height=320,scrollbars=no,menubar=no,resizable=yes,status=no,toolbar=no');
  
  return true;
  }

function clearAll(){
  deactivate(window.document.chatForm.firstname);
  deactivate(window.document.chatForm.lastname);
  deactivate(window.document.chatForm.email);
  deactivate(window.document.chatForm.accept);
  
  window.document.chatForm.reset();
  }
  
function validateNotAvailableForm(){
  if(window.document.notAvailableForm.preferred.selectedIndex == 0) {
    alert('Please indicate how you would like us to contact you.');
	indicateError(window.document.notAvailableForm.preferred);
	return false;
	}	
	
  if((window.document.notAvailableForm.preferred.selectedIndex == 2) && (window.document.notAvailableForm.phone.value == "")) {
    alert('You indicated to us that you would like us to give you a call, but you did not provide a telephone number to call you at. Please supply a telephone number.');
	indicateError(window.document.notAvailableForm.phone);
	return false;
	}	
  }  