/* sm_site.js file
 ** Richard Drake
 ** Pacific Consulting Group - pacificcg.com
 ** Update 17Aug05 for splitmaster.com
*/



// validates that field value has one or more characters
function isNotEmpty(elem){
  var str = elem.value;
  var re = /.+/;
  if(!str.match(re)){
    alert("Please fill in the required field.");
    setTimeout("focusElement('" + elem.form.name + "', '" + elem.name + "')",0);
    return false;
    } else {
      return true;
    }
}

//  validates that entry is formatted as e-mail address
function isEMailAddr(elem){
  var str = elem.value;
  var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
      alert("Verify the e-mail address format.");
      return false;
    } else {
      return true;
    }
}

// validate contact form on submission - ref isNotEmpty above
function validContactForm(form){
  if (isNotEmpty(FormMailer.FName)) {
    if (isNotEmpty(FormMailer.LName)) {
      if (isEmailAddr(FormMailer.Email)) {
      	if (isNotEmpty(FormMailer.Comments)){
      return true;
        }
      }
    }
  }
  return false;
}

function validFirstLastEmail(form){
  if (isNotEmpty(FormMailer.First)){
    if (isNotEmpty(FormMailer.Last)){
      if (isEmailAddr(FormMailer.Email)){
    return true;
      }
    }
  }
  return false;
}

// validate access form - ref isNotEmpty above
function validAccessForm(form){
  if (isNotEmpty(from.uname)) {
    if (isNotEmpty(form.pword)) {
    return true;
    }
  }
  return false;
}

// validate login form - check for status
function validMainLogin(form){
  if (isNotEmpty(form.uname)) {
    if (isNotEmpty(form.pword)) {
    return true;
    }
  }
  alert("Invalid Login!");
  return false;
}

// validate TestVars form - util for entereing trial subscriptions
function validTestVarsForm(form){
  if (isNotEmpty(form.bname)) {
    if (isEmailAddr(form.email)) {
    return true;
    }
  }
  return false;
}

// validate ml3_notice form
function valid_ml3Form(form){
	if (isNotEmpty(document.momenform.msgbody)){
		if ((document.momenform.mostatus[0].checked) || (document.momenform.mostatus[1].checked) || (document.momenform.mostatus[2].checked) || (document.momenform.mostatus[3].checked)){
			return true;
		}
	}
	alert("Empty Field or Box!");
	return false;
}

// validate subscription form - ref isNotEmpty above
function validSubscribeForm(form){
  if (isNotEmpty(FormSubscr.name)){
    if (isNotEmpty(FormSubscr.email)){
      if (isNotEmpty(FormSubscr.phone)){
        if (isNotEmpty(FormSubscr.baddr1)){
      return true;
        }
      }
    }
  }
  return false;
}

// validate new message form - ref isNotEmpty above
function valNewMsgForm(form){
  if (isNotEmpty(document.FRM_NEW.mo)){
    if (isNotEmpty(document.FRM_NEW.dom)){
      if (isNotEmpty(document.FRM_NEW.yr)){
        if (isNotEmpty(document.FRM_NEW.mtype)){
      	  if (isNotEmpty(document.FRM_NEW.mbody)){
        return true;
          }
        }
      }
    }
  }
  return false;
}

// validate opt-in form - ref isNotEmpty above
function valOptForm(form){
if (document.FormNews.optbtn[0].checked){
  if (isNotEmpty(document.FormNews.First)){
    if (isNotEmpty(document.FormNews.Last)){
      if (isNotEmpty(document.FormNews.Email)){
    return true;
      }
    }
  } 
  return false;
}else{
  if (document.FormNews.optbtn[1].checked){
    if (isNotEmpty(document.FormNews.Email)){
    return true;
   }
   return false;
  }else{
  if (document.FormNews.optbtn[2].checked){
    if (isNotEmpty(document.FormNews.Email)){
    return true;
   }
   return false;
   }
  } 
 }      
}

// validate FrmNewsUpdt
function valOptEdit(form){
  if (!(document.FrmNewsUpdt.First.value == "")){  
    return true;
  }else{
    if (!(document.FrmNewsUpdt.MI.value == "")){
      return true;
    }else{
      if (!(document.FrmNewsUpdt.Last.value == "")){
        return true;
       }
       alert("Name Element Necessary");
       return false;
     }
   }
}

// prevent erroneous mail delivery prep
function valMsgDeliv(form){
if (isNotEmpty(document.frmprep.nme_send)){
  if (document.frmprep.fldDate.value==" " && document.frmprep.fmo.value==" " && document.frmprep.fdom.value==" " && document.frmprep.fyr.value==" " && document.frmprep.tmo.value==" " && document.frmprep.tdom.value==" " && document.frmprep.tyr.value==" "){
  return true;
    }
   alert("First Alert");
  }
  alert("Stop Action");
  return false;
} 
/*  
  }elseif{ 
  if (isNotEmpty(document.frmprep.fldDate) && isNotEmpty(document.frmprep.fmo) && isNotEmpty(document.frmprep.fdom) && isNotEmpty(document.frmprep.fyr) && isNotEmpty(document.frmprep.tmo) && isNotEmpty(document.frmprep.tdom) && isNotEmpty(document.frmprep.tyr)){
    return true;
      }
    }
    return true;
    }
  }else{   
  alert("Incorrect Entry");
  return false;  
}
*/

  
// ml build link *************************************************
function genLink(){
  var sPath = document.FRM_NEW.clipPath.value;
  var sType = document.FRM_NEW.clipType.value;
  var sText = document.FRM_NEW.clipText.value;
  
  switch (sType) {
    case 'url':
      var sLink = "<a href=\'"+sPath+"\'>"+sText+"</a>";
      document.FRM_NEW.clipLink.value = sLink;
      
      break;
    case 'mailto':
      var sLink = "<a href=\'mailto:"+sPath+"\'>"+sText+"</a>";
      document.FRM_NEW.clipLink.value = sLink;
      break;
    default:
      document.FRM_NEW.clipLink.value = "not yet operable";
    break;
  }
}

// ml build link for Edit******************************************
function genLinkEdit(){
  var sPath = document.FRM_EDIT.clipPath.value;
  var sType = document.FRM_EDIT.clipType.value;
  var sText = document.FRM_EDIT.clipText.value;
  
  switch (sType) {
    case 'url':
      var sLink = "<a href=\'"+sPath+"\'>"+sText+"</a>";
      document.FRM_EDIT.clipLink.value = sLink;
      
      break;
    case 'mailto':
      var sLink = "<a href=\'mailto:"+sPath+"\'>"+sText+"</a>";
      document.FRM_EDIT.clipLink.value = sLink;
      break;
    default:
      document.FRM_EDIT.clipLink.value = "not yet operable";
    break;
  }
}
   

// ml prep form status send to
function setSendStatAll(){
  document.frmprep.nme_send.value="All";
}

function setSendStatVar(){
  if (document.frmprep.nme_send.value=="All" || document.frmprep.nme_send.value==""){
    document.frmprep.nme_send.value="Status = " + "'" + document.frmprep.fldStat.value + "'";
    }else{
      document.frmprep.nme_send.value=document.frmprep.nme_send.value + " OR Status = " + "'" + document.frmprep.fldStat.value + "'";
      }

  }

// validate entries of member edit form
function valMemInfoEdit(){
 var uid_size = document.mem_edit.new_uid.value.length;
 var pas_size = document.mem_edit.new_pword.value.length;
 if (uid_size >= 4 && uid_size <= 6){
   if (pas_size >= 4 && uid_size <= 6){
   return true;
    }
  }else{
 return false;
 }
}

// validate number of chars
function charCtVal(entered, min, max, alertbox){
  if (entered.value.length >= min){
    if (entered.value.length <= max){
    return true;
    }
   }
  alert(alertbox);
  return false;
}

function validMemEditFrom(form){
  if (charCtVal(form.new_uid, 4, 6, 'You must enter 4 to 6 characters.')){
    if (charCtVal(form.new_pword, 4, 6, 'You must enter 4 to 6 characters.')){
      if (isEMailAddr(form.new_email)){
      return true;
      }
    }
  }
  alert("Invalid Entry!");
  return false;
}

function rotate() {
		if (document.images) {
			if (document.adBanner.complete) {
				thisAd++
				if (thisAd == imgCt) {
					thisAd = 0
				}
				document.adBanner.src=adImages[thisAd]
			}
		  	setTimeout("rotate()", 12 * 1000)
	  	}
	}
	
	function newLocation() {
		document.location.href = adURL[thisAd]
	}
