function tick() {
	if(document.yourcomments.accept.checked)
	{
		document.yourcomments.send.disabled=false;
	}
	else
	{
		document.yourcomments.send.disabled=true;
	}
}

function disableSend() {
	document.yourcomments.send.disabled=true;
}

function backColor() {
	document.yourcomments.email_fname.style.backgroundColor='#FFFF99';
	document.yourcomments.email_lname.style.backgroundColor='#FFFF99';
	document.yourcomments.email_from.style.backgroundColor='#FFFF99';
	document.yourcomments.email_phone.style.backgroundColor='#FFFF99';
	document.yourcomments.email_nickname.style.backgroundColor='#FFFFFF';
	document.yourcomments.email_location.style.backgroundColor='#FFFFFF';
	document.yourcomments.message.style.backgroundColor='#FFFF99';
	document.yourcomments.accept.style.backgroundColor='#FFFF99';
	document.yourcomments.captcha.style.backgroundColor='#FFFF99';
}

function backColorAuthor(){
	document.yourcomments.email_name.style.backgroundColor='#FFFF99';
	document.yourcomments.email_from.style.backgroundColor='#FFFF99';
	document.yourcomments.message.style.backgroundColor='#FFFF99';
	// document.yourcomments.accept.style.backgroundColor='#FFFF99';
	document.yourcomments.captcha.style.backgroundColor='#FFFF99';
}

function backColorEmailAFrnd() {
	document.yourcomments.fromname.style.backgroundColor='#FFFF99';
	document.yourcomments.sender_email.style.backgroundColor='#FFFF99';
	document.yourcomments.recipient_email1.style.backgroundColor='#FFFF99';
	document.yourcomments.captcha.style.backgroundColor='#FFFF99';
}

function checkRequired() {
  var err = false;
  var captchaErr = false;
	if (document.yourcomments.email_lname.value == "") {
    document.yourcomments.email_lname.style.border = '2px solid red';
    err = true;
  }
  if ( document.yourcomments.email_fname.value == "" ) {
    document.yourcomments.email_fname.style.border = '2px solid red';
    err = true;
  }
  if ( document.yourcomments.email_from.value == "" ) {
    document.yourcomments.email_from.style.border = '2px solid red';
    err = true;
  } else if ( echeck(document.yourcomments.email_from.value) == false ) {
    document.yourcomments.email_from.style.border = '2px solid red';
    err = true;
    alert ("Please enter a proper email address (e.g. username@domain.co.nz)");
    return false;
  }
  if ( document.yourcomments.email_phone.value == "" ) {
    document.yourcomments.email_phone.style.border = '2px solid red';
    err = true;
  }
  if ( document.yourcomments.message.value == "" ) {
    document.yourcomments.message.style.border = '2px solid red';
    err = true;
  }
  if ( document.yourcomments.captcha.value == "" ) {
    document.yourcomments.captcha.style.border = '2px solid red';
    captchaErr = true;
	err = true;
  }
  if ( err ) {
  	if (captchaErr)
		alert("Please type the text shown in the image into the highlighted box to help prevent spam!");
	else
		alert ("You must fill out your name, email address, phone number, and your comment to proceed!");
		return false;
	}
	return true;
}

function checkRequiredAuthor() {
  var err = false;
  var captchaErr = false;
  if ( document.yourcomments.email_name.value == "" ) {
    document.yourcomments.email_name.style.border = '2px solid red';
    err = true;
  }
  if ( document.yourcomments.email_from.value == "" ) {
    document.yourcomments.email_from.style.border = '2px solid red';
    err = true;
  } else if ( echeck(document.yourcomments.email_from.value) == false ) {
    document.yourcomments.email_from.style.border = '2px solid red';
    err = true;
    alert ("Please enter a proper email address (e.g. username@domain.co.nz)");
    return false;
  }
  if ( document.yourcomments.message.value == "" ) {
    document.yourcomments.message.style.border = '2px solid red';
    err = true;
  }
  if ( document.yourcomments.captcha.value == "" ) {
    document.yourcomments.captcha.style.border = '2px solid red';
    captchaErr = true;
	err = true;
  }
  if ( err ) {
  	if (captchaErr)
		alert("Please type the text shown in the image into the highlighted box to help prevent spam!");
	else
		alert ("You must fill out your name, email address, phone number, and your comment to proceed!");
		return false;
	}
	return true;
}

function checkRequiredTechnical() {
  var err = false;
  var captchaErr = false;
  var ErrMsg = 'Please attend to the following:\r\n';
  var ErrCount = 1;
  
  if ( document.yourcomments.email_name.value == "" ) {
    document.yourcomments.email_name.style.border = '1px solid red';
	ErrMsg = ErrMsg + ErrCount + '. Enter enter your name\r\n';
	ErrCount++;
    err = true;
  }
  if ( document.yourcomments.email_from.value == "" ) {
    document.yourcomments.email_from.style.border = '1px solid red';
	ErrMsg = ErrMsg + ErrCount + '. Enter an email address\r\n';
	ErrCount++;
    err = true;
  } 
  if ( document.yourcomments.email_phone.value == "" ) {
    document.yourcomments.email_phone.style.border = '1px solid red';
	ErrMsg = ErrMsg + ErrCount + '. Enter your phone number\r\n';
	ErrCount++;
    err = true;
  } 
  /*else if ( echeck(document.yourcomments.email_from.value) == false ) {
    document.yourcomments.email_from.style.border = '1px solid red';
    err = true;
    alert ("Please enter a proper email address (e.g. username@domain.co.nz)");
    return false;
  }*/
  
  if (document.yourcomments.os.selectedIndex == 0){
  	document.yourcomments.os.style.border = '1px solid red';
	ErrMsg = ErrMsg + ErrCount + '. Select the operating system you are using\r\n';
	ErrCount++;
    err = true;
  }
  
  if (document.yourcomments.browser.selectedIndex == 0){
  	document.yourcomments.browser.style.border = '1px solid red';
	ErrMsg = ErrMsg + ErrCount + '. Select the web browser you are using\r\n';
	ErrCount++;
    err = true;
  }
  
  if (document.getElementById('av1').checked && document.yourcomments.avtype.selectedIndex == 0){
  	document.yourcomments.avtype.style.border = '1px solid red';
	ErrMsg = ErrMsg + ErrCount + '. Select the type of antivrus you are using\r\n';
	ErrCount++;
    err = true;
  }
  if ( document.yourcomments.message.value == "" ) {
    document.yourcomments.message.style.border = '1px solid red';
	ErrMsg = ErrMsg + ErrCount + '. Provide some information using the message field\r\n';
	ErrCount++;
    err = true;
  }
  if ( document.yourcomments.captcha.value == "" ) {
    document.yourcomments.captcha.style.border = '1px solid red';
	ErrMsg = ErrMsg + ErrCount + '. Type the text shown in the image into the box provided to help prevent spam\r\n';
	ErrCount++;
    //captchaErr = true;
	err = true;
  }
  if ( err ) {
	alert (ErrMsg);
	return false;
  }
  return true;
}

function checkRequiredEmailAFrnd() {
  var err = false;
  var infoerr = false;
  var captchaErr = false;
  if ( document.yourcomments.fromname.value == "" ) {
    document.yourcomments.fromname.style.border = '2px solid red';
    err = true;
	infoerr = true;
  }
  if ( document.yourcomments.sender_email.value == "" ) {
    document.yourcomments.sender_email.style.border = '2px solid red';
    err = true;
	infoerr = true;
  } /*else if ( echeck(document.yourcomments.sender_email.value) == false ) {
    document.yourcomments.sender_email.style.border = '2px solid red';
    err = true;
	infoerr = true;
    alert ("Please enter a proper email address (e.g. username@domain.co.nz)");
    return false;
  }*/
  if ( document.yourcomments.recipient_email1.value == "" ) {
    document.yourcomments.recipient_email1.style.border = '2px solid red';
    err = true;
	infoerr = true;
  } /*else if ( echeck(document.yourcomments.recipient_email1.value) == false ) {
    document.yourcomments.recipient_email1.style.border = '2px solid red';
    err = true;
	infoerr = true;
    alert ("Please enter a proper email address (e.g. username@domain.co.nz)");
    return false;
  }*/
  if ( document.yourcomments.captcha.value == "" ) {
    document.yourcomments.captcha.style.border = '2px solid red';
    captchaErr = true;
	err = true;
  }
  if ( err ) {
  	if (captchaErr && !infoerr)
		alert("Please type the text shown in the image into the highlighted box to help prevent spam!");
	else if (captchaErr && infoerr)
		alert ("Please type the text shown in the image into the highlighted box to help prevent spam and \n you must also fill out your name, email address and your friend's email address to proceed!");
	else if (!captchaErr && infoerr)
		alert ("You must fill out your name, email address and your friend's email address to proceed!");
	return false;
	}
	return true;
}

function checkLen() {
	var textLen = document.yourcomments.message.value;
	if( textLen.length > 1200 ) {
		document.yourcomments.lenMsg.value = "You have entered more than 1200 characters";
		document.yourcomments.lenMsg.style.color = '#FF0000';
		document.yourcomments.lenMsg.style.fontWeight = 'bold';
	} else {
		document.yourcomments.lenMsg.value = textLen.length;
  }
}

function echeck(str) {
  var at="@";
  var dot=".";
  var lat=str.indexOf(at);
  var lstr=str.length;
  var ldot=str.indexOf(dot);

  if (str.indexOf(at)==-1){
     return false;
  }
  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
     return false;
  }
  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
      return false;
  }
  if (str.indexOf(at,(lat+1))!=-1){
      return false;
  }
  if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
    return false;
  }
  if (str.indexOf(dot,(lat+2))==-1){
    return false;
  }
  if (str.indexOf(" ")!=-1){
    return false;
  }
  return true;
}

function clearForms()
{
  document.yourcomments.reset();
}
