function trim(str) {
	var	str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}

function IsStrEmpty(strValue) {
	  //strValue = trim(strValue);

      if (strValue==null||strValue=="") {
         return true;
      }
      else {
         return false; 
      }
}
 
 function IsValidEmail(strVal) {
    
    var bln;
	
 
    if (IsStrEmpty(strVal)) {
        return (false);
	} else {
	    bln = true;
	} 

    //No @
    if (strVal.indexOf ('@', 0) == -1) {
	} else {
	    bln = true;
	} 

	//No .
    if (strVal.indexOf ('.', 0) == -1) {
        return ( false);
	} else {
	    bln = true;
	} 

    return bln;
}

function changeTextById(elementId,changeVal){
    var hasInnerText =
    (document.getElementsByTagName("body")[0].innerText != undefined) ? true : false;
    var elem = document.getElementById(elementId);
    if(!hasInnerText){
	   elem.textContent = changeVal;
    }else{
	   elem.innerText = changeVal;
    }
}


function ValidateEmailForm(thisForm)  {
      
	 changeTextById('idErrMail','');
	 changeTextById('idErrFromEmail','');
	 changeTextById('idErrEmailSubject','');
	 changeTextById('idErrEmailBody','');

     if (IsValidEmail(document.forms.frmEmail.idFromEmail.value) == false) {
        changeTextById('idErrMail','Error: Invalid From Email Address.');
        //changeTextById('idErrFromEmail', '*');
        return (false);
	} 

    if (trim(document.forms.frmEmail.idEmailSubject.value) == '[Subject]') {
        changeTextById('idErrMail','Error: Email Subject cannot be blanks.');
        return (false);
	}


    if (IsStrEmpty(document.forms.frmEmail.idEmailBody.value)) {
        changeTextById('idErrMail','Error: Email message cannot be blanks.');
        return (false);
	} 
 

   return (true);
     
}


function clear_contactus() {
   document.getElementById('idFromEmail').value ='[From Email]';
   document.getElementById('idEmailSubject').value ='[Subject]';
   document.getElementById('idEmailBody').value ='';
}


function ValidateNewsletterForm(thisForm)  {
     var bln;
    changeTextById('idErrorNewsletter','');


    if (trim(document.forms.frmNewsletter.idNewsletterName.value) == '[Name]') {
        changeTextById('idErrorNewsletter','Error: Name cannot be blanks.');
        return (false);
	} else {
	    bln = true;
	} 

     if (IsValidEmail(document.forms.frmNewsletter.idNewsletterEmail.value) == false) {
        changeTextById('idErrorNewsletter','Error: Invalid Email Address.');
        return (false);
	 }

   return (bln);
     
}
