var xmlHttpEv

function submitEmail()
{ 
  var msg = '';
  
  valid = Validate_Email_Address(document.emailForm.yourEmail.value);

 if (valid != true||document.emailForm.yourName.value==''||document.emailForm.yourEmail.value==''||document.emailForm.subject.value==''||document.emailForm.comments.value==''){

    if (document.emailForm.yourName.value==''){
      document.getElementById("name_error").innerHTML='Name is required!<style>.inputFontName{border-color:red;border-width:1px;}</style><br><br>';
    } else {
      document.getElementById("name_error").innerHTML='';
    }
    if (document.emailForm.yourEmail.value==''){
      document.getElementById("email_error").innerHTML='Email is required!<style>.inputFontEmail{border-color:red;border-width:1px;}</style><br><br>';
    } else {
      document.getElementById("email_error").innerHTML='';
    }
    if (document.emailForm.subject.value==''){
      document.getElementById("subject_error").innerHTML='Subject is required!<style>.inputFontSubject{border-color:red;border-width:1px;}</style><br><br>';
    } else {
      document.getElementById("subject_error").innerHTML='';
    }
    if (document.emailForm.comments.value==''){
      document.getElementById("comments_error").innerHTML='Comments are required!<style>.inputFontComments{border-color:red;border-width:1px;}</style><br><br>';
    } else {
      document.getElementById("comments_error").innerHTML='';
    }
    if (valid != true){
      document.getElementById("email_error").innerHTML='Invalid Email Address!<style>.inputFontEmail{border-color:red;border-width:1px;}</style><br><br>';
    }
 }else{
 
     document.getElementById("name_error").innerHTML='';
     document.getElementById("email_error").innerHTML='';
     document.getElementById("subject_error").innerHTML='';
     document.getElementById("comments_error").innerHTML='';
     
	  msg = 'Ready to send your comments?';

    if( confirm( msg ) )
      {
        xmlHttpEv=GetXmlHttpObject();
        if (xmlHttpEv==null)
          {
          alert ("Your browser does not support AJAX!");
          return;
          } 
        var urlEv="/inc/ajaxWidgets/feedback/sendEmail_action.asp";
        urlEv=urlEv+"?sid="+Math.random();
        
        var strEv='yourName='+Url.encode(document.emailForm.yourName.value)+'&';
        strEv=strEv+'yourEmail='+Url.encode(document.emailForm.yourEmail.value)+'&';
        strEv=strEv+'subject='+Url.encode(document.emailForm.subject.value)+'&';
        strEv=strEv+'comments='+Url.encode(document.emailForm.comments.value);

        xmlHttpEv.onreadystatechange=stateChangedEm;
        xmlHttpEv.open("POST",urlEv,true);
        xmlHttpEv.setRequestHeader("Content-Type", 
        "application/x-www-form-urlencoded; charset=UTF-8"); 
        xmlHttpEv.send(strEv);     
      }
   }
}

function stateChangedEm() 
{ 
  if (xmlHttpEv.readyState==4)
  { 
    document.getElementById("feedback999").innerHTML=xmlHttpEv.responseText;
    resetForm();
  }
}
function Validate_String(string, return_invalid_chars)
         {
         valid_chars = '1234567890-_.^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
         invalid_chars = '';
         
         if(string == null || string == '')
            return(true);
         
         //For every character on the string.   
         for(index = 0; index < string.length; index++)
            {
            char = string.substr(index, 1);                        
            
            //Is it a valid character?
            if(valid_chars.indexOf(char) == -1)
              {
              //If not, is it already on the list of invalid characters?
              if(invalid_chars.indexOf(char) == -1)
                {
                //If it's not, add it.
                if(invalid_chars == '')
                   invalid_chars += char;
                else
                   invalid_chars += ', ' + char;
                }
              }
            }                     
            
         //If the string does not contain invalid characters, the function will return true.
         //If it does, it will either return false or a list of the invalid characters used
         //in the string, depending on the value of the second parameter.
         if(return_invalid_chars == true && invalid_chars != '')
           {
           last_comma = invalid_chars.lastIndexOf(',');
           
           if(last_comma != -1)
              invalid_chars = invalid_chars.substr(0, $last_comma) + 
              ' and ' + invalid_chars.substr(last_comma + 1, invalid_chars.length);
                      
           return(invalid_chars);
           }
         else
           return(invalid_chars == ''); 
         }


function Validate_Email_Address(email_address)
         {
         //Assumes that valid email addresses consist of user_name@domain.tld
         at = email_address.indexOf('@');
         dot = email_address.indexOf('.');
         
         if(at == -1 || 
            dot == -1 || 
            dot <= at + 1 ||
            dot == 0 || 
            dot == email_address.length - 1)
            return(false);
            
         user_name = email_address.substr(0, at);
         domain_name = email_address.substr(at + 1, email_address.length);                  
         
         if(Validate_String(user_name) === false || 
            Validate_String(domain_name) === false)
            return(false);                     
         
         return(true);
         }

var xmlHttp
function getEmailForm(){

document.getElementById("feedbackButton").style.display='none';

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/inc/ajaxWidgets/feedback/getEmailForm.asp";
url=url+"?sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged2;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged2() 
{ 
  var loadingHTML;
  loadingHTML='<table align="center" cellpadding="0" cellspacing="0" border="0" width="200"><tr><td align="center">';
  loadingHTML=loadingHTML+'<div style="height:150px;width:160;background-image:url(/inc/ajaxWidgets/feedback/images/loading_160.jpg);background-position:center top;background-repeat:no-repeat;padding-top:88px;text-align:center;"><img width="95" height="12" src="/inc/ajaxWidgets/feedback/images/ajax-loader2.gif" /></div>';
  loadingHTML=loadingHTML+'</td></tr></table>';
  document.getElementById("feedback999").innerHTML=loadingHTML;
 
  if (xmlHttp.readyState>=4)
  { 
    document.getElementById("feedback999").innerHTML=xmlHttp.responseText; 
  }
  jumpScroll('fbForm');
}

function resetForm(){
   setTimeout('document.getElementById("feedback999").innerHTML="";document.getElementById("feedbackButton").style.display="";',5000);
}
function cancelForm(){
    document.getElementById("feedback999").innerHTML=''; 
    document.getElementById("feedbackButton").style.display='';
    jumpScroll('fbForm');
}
function clearDiv(divID){
  document.getElementById(divID).innerHTML='';
}

function jumpScroll(anchor) {
  window.location.hash = anchor;
}
