//
//  $RCSfile: g269Emailer.js,v $
//  $Date: 2003/08/20 20:35:02 $
//  $Revision: 1.7 $
//
//########################################
function checkTextSize( text, length ) {

  textLength = text.length;

  if ( textLength > length) {
    alert("We are allowing " + length + " characters per comment.\nYour current character count is " + textLength + ".\n" + "Please shorten your comments by at least " + (textLength - length) + " characters.");
    return false;
  }else{
    return true;
  }
}

function emailFormCheck(page) {
  if( document.layers ) {
    thisForm = eval("document.layers['divCopyContact'].document.emailForm");
  }else{
    thisForm = eval("document.emailForm");
  }
  numberChecked = 0;
  requiredChecks = 0;

  if ( page == "ContactUs" ) {

    requiredChecks = 1;

    for ( i=0; i < thisForm.enquiryNature.length; i++ ) {
      if ( thisForm.enquiryNature[i].checked ) {
        numberChecked++;
        break;
      }
    }
    for ( i=0; i < thisForm.applicationType.length; i++ ) {
      if ( thisForm.applicationType[i].checked ) {
        numberChecked++;
        break;
      }
    }
    for ( i=0; i < thisForm.informationRequest.length; i++ ) {
      if ( thisForm.informationRequest[i].checked ) {
        numberChecked++;
        break;
      }
    }

  } else if (page == "General") {

    requiredChecks = 1;

    for ( i=0; i < thisForm.contactee.length; i++ ) {
      if ( thisForm.contactee[i].checked ) {
        numberChecked++;
        break;
      }
    }
  }

  //Auto populate empty fields to prevent null pointers when getting
  //parameter values and to prevent 'Required Fields'
  for ( i=0; i < thisForm.elements.length; i++ ) {
    if ( ( thisForm.elements[i].type == 'text' ||
           thisForm.elements[i].type == 'textarea') && 
           thisForm.elements[i].value == "" ) {

      if ( thisForm.elements[i].type == 'textarea' && page == 'contactDetails') {
        alert("Please fill in the 'Comments' field.");
        thisForm.emailComments.focus();
        return false;
      } else if ( thisForm.emailAddress.value == "" ) {
          alert("Please enter an email address.");
          thisForm.emailAddress.focus();
          return false;
      } else if ( !emailTest( thisForm.emailAddress.value ) ) {
          alert("This email address appears invalid [ " + thisForm.emailAddress.value + " ], please correct your entry!");
          thisForm.emailAddress.focus();
          return false; 
      }
    }
  }
  if (page == "ContactUs") {
    if ( numberChecked > 0 ) {
      thisForm.submit();
      return true;
    }else{
      alert("You must make a selection in the \"Nature of Enquiry\" or \"Application\" or \"Information Request\" area before submitting.")
      return false;
    }  
  }else if (page == "contactDetails") {
    if ( numberChecked > 0 ) {
      thisForm.submit();
      return true;
    }else{
      alert("You must make a selection in the \"Nature of Enquiry\" area before submitting.")
      return false;
    }
  }
}

function emailTest(src) {
  var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
  var regex = new RegExp(emailReg);
  return regex.test(src);
}
function IndiaEmailCheck(){
  
  frm = eval("document.IndiaReplyForm");
  elem = frm.elements;
  reqFlag = 0;//after looping, if equal to 3, user must
              //enter either email, phone, cellphone value
  
  for (i=0;i<elem.length;i++){
  
    if (( (elem[i].type == "text") && (elem[i].value.length == 0)) ){
      
      //the email call must have values to work so we fill in " " if a 
      //user leaves a field blank instead of requiring all fields

      if(elem[i].name == "email" || 
         elem[i].name == "phone" || 
         elem[i].name == "cellphone")
      {
        reqFlag++;
      }else{
        elem[i].value = " ";
      }
    }
    
  /*
    if (elem[i].name == "email"){
      if ( (elem[i].value.length != 0) && (!emailTest( elem[i].value )) ) {
        alert("This email address appears invalid [ " + elem[i].value + 
              " ], please correct your entry!");
    	elem[i].focus();
    	return false;
      }
    }
  */
  }

  if( reqFlag == 3 ){

    confirm("Data is required in at least one of the following fields: Email, Phone or Cell Phone. If you do not have an email address, leave that field blank and enter a Phone or Cell Phone Number.");
    frm.email.focus();
    return false;

  }else{

    if( !emailTest( frm.email.value ) || ( frm.email.value.length == 0 )){
      frm.email.value = "NO_EMAIL@COMORETEL.COM";
    }

    if (frm.phone.value.length == 0){

      frm.phone.value = " ";
    }

    if (frm.cellphone.value.length == 0){

      frm.cellphone.value = " ";
    }

    frm.submit();
  }
}
function checkTextSize( text, length ) {

  textLength = text.length;

    if ( textLength > length) {
      alert("We are allowing " + length + " characters per Company Profile.\nYour current character count is " + textLength + ".\n" + "Please shorten your entered text by at least " + (textLength - length) + " characters.");    
      return false;

    }else{
    
      return true;
    }
}
