// 20091210 MJS added contact form validation
// 20081212 MJS added download links so version numbers can be easily updated
// 20081003 MJS file to store all email addresses in that are used on a website to protect address and also make one location to update addresses
// 20100223 PC added antiSpam()
// 20100303 PC Add functions to allow standard contacts.html and email.js pages at all Acarda sites.
// 20100303 PC added emailSalesSubjectDomain()
// 20100323 Email Validation Script

var support = 'sales05';
var sales = 'sales05';

var domain = 'acarda.com'

var supportEmail = support + '@' + domain;
var salesEmail = sales + '@' + domain;

function emailSupport(subject)
{
	 window.location.href=("mailto:" + supportEmail + "?subject=" + subject);
}

function emailSales(subject)
{
	 window.location.href=("mailto:" + salesEmail + "?subject=" + subject);
}

function emailSalesSubjectDomain()
{
	 window.location.href=("mailto:" + salesEmail + "?subject=" + document.domain + ' Contact Form');
}

function showSalesEmail(subject)
{
	document.open();
	document.write('<a href="mailto:' + salesEmail + "?subject=" + subject + '">' + salesEmail + '</a>');
	document.close();
}

function showSupportEmail(subject)
{
	document.open();
	document.write('<a href="mailto:' + supportEmail + "?subject=" + subject + '">' + supportEmail + '</a>');
	document.close();
}

function getSupportEmail()
{
	return 'mailto:' + supportEmail
}

function justSupportEmail()
{
	return 	supportEmail
}

function test(form)
{
form.recipient.value = salesEmail;
}

function queryString(parameter) { 
  var loc = location.search.substring(1, location.search.length);
  var param_value = false;
  var params = loc.split("&");
  for (i=0; i<params.length;i++) {
      param_name = params[i].substring(0,params[i].indexOf('='));
      if (param_name == parameter) {
          param_value = params[i].substring(params[i].indexOf('=')+1)
      }
  }
  if (param_value) {
      return param_value;
  }
  else {
      return " -- no parameters --"; //Here determine return if no parameter is found
  }
}

function teamMaxDownload(subject)
{
	document.open();
	document.write('<a href="software-download.html?product=TMXAC&version=6.9.3&display=TeamMax Outbound">' + subject + '</a>');
	document.close();	
}

function teamMaxLatestVersion(subject)
{
	document.open();
	document.write(subject + 'v6.9.3');
	document.close();
}

function callAssistDownload(subject)
{
	document.open();
	document.write('<a href="software-download.html?product=CASA&version=7.1.7&display=CallAssist">' + subject + '</a>');
	document.close();	
}

function acardaMessengerDownload(subject)
{
	document.open();
	document.write('<a href="software-download.html?product=AMA&version=6.0.0&display=Acarda Messenger">' + subject + '</a>');
	document.close();	
}

function knowledgeMaxDownload(subject)
{
	document.open();
	document.write('<a href="software-download.html?product=KMXSA&version=1.5.0&display=KnowledgeMax">' + subject + '</a>');
	document.close();	
}

function voxConverterDownload(subject)
{
	document.open();
	document.write('<a href="software-download.html?product=VOXC&version=2.0.0&display=VoxConverter&via=direct">' + subject + '</a>');
	document.close();	
}

function voxPlayerDownload(subject)
{
	document.open();
	document.write('<a href="software-download.html?product=VOXP&version=1.2.0&display=VoxPlayer&via=direct">' + subject + '</a>');
	document.close();	
}

function wavRecorderDownload(subject)
{
	document.open();
	document.write('<a href="software-download.html?product=WARA&version=2.1.1&display=WavRecorder&via=direct">' + subject + '</a>');
	document.close();	
}
function numberGenieDownload(subject)
{
	document.open();
	document.write('<a href="software-download.html?product=NUMG&version=2.2.1&display=NumberGenie&via=direct">' + subject + '</a>');
	document.close();	
}

function redirectDownload(product)
{
	switch(product)
	{
		case null:
			window.location.replace("downloads.html");
		break;
		case 'TMX':
			window.location.replace("software-download.html?product=TMXAC&version=6.9.3&display=TeamMax Outbound");
		break;
		case 'CASA':
			window.location.replace("software-download.html?product=CASA&version=7.1.7&display=CallAssist");
		break;
		case 'AMA':
			window.location.replace("software-download.html?product=AMA&version=6.0.0&display=Acarda Messenger");
		break;
		case 'KMXSA':
			window.location.replace("software-download.html?product=KMXSA&version=1.5.0&display=KnowledgeMax");
		break;
		case 'VOXC':
			window.location.replace("software-download.html?product=VOXC&version=2.0.0&display=VoxConverter&via=direct");
		break;
		case 'VOXP':
			window.location.replace("software-download.html?product=VOXP&version=1.2.0&display=VoxPlayer&via=direct");
		break;
		case 'WARA':
			window.location.replace("software-download.html?product=WARA&version=2.1.1&display=WavRecorder&via=direct");
		break;
		case 'NUMG':
			window.location.replace("software-download.html?product=NUMG&version=2.2.1&display=NumberGenie&via=direct");
		break;
		default:
			window.location.replace("downloads.html");
	}
}

var requestsubmitted = false;
function validate_contactform(theForm) {

	if(requestsubmitted == true)
	{
	   alert("In progress. Please wait.");
	   return false;
	}
	if (theForm.first.value == "")
	{
		alert("Please enter a first name.");
		theForm.first.focus();
		return false;
	}

	if (theForm.last.value == "")
	{
		alert("Please enter a last name.");
		theForm.last.focus();
		return false;
	}
	
	if ((theForm.email.value==null)||(theForm.email.value==""))
	{
		alert("Please enter an email address.");
		theForm.email.focus();
		return false;
	}
	
	if (isValidEmail(theForm.email.value)==false)
	{
		alert("Please enter a valid email address.");
		//theForm.email.value=""
		theForm.email.focus();
		return false;
	}

	if (theForm.telephone.value == "")
	{
		alert("Please enter a telephone number.");
		theForm.telephone.focus();
		return false;
	}
	
	if (theForm.message.value == "")
	{
		alert("Please enter a question.");
		theForm.message.focus();
		return false;
	}
	
	//set redirect
	theForm.redirect.value=getSubmittedRedirect();
	
	//set source
	theForm.source.value=getContactSource();
	
	requestsubmitted = true;
	return true;	
}

/* 20100323 Email Validation Script */

function isValidEmail(elementValue){   
   var emailPattern = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;  
   return emailPattern.test(elementValue);   
 } 


/*20100223 Anti-spam loaded with initial script*/

	var antiSpam = function() {        
		if (document.getElementById("antiSpam")) { 
			a = document.getElementById("antiSpam");
			if (isNaN(a.value) == true) {
				a.value = 0;
			} else {
				a.value = parseInt(a.value) + 1;   
			}  
		}   
		setTimeout("antiSpam()", 1000);
	}
	antiSpam();

// 20100303 Add functions to allow standard contacts.html and email.js pages at all Acarda sites.

function getContactSource()
{
	return document.domain + ' Contact Form'
}

// http://www.acarda.com.au/request-received.html
function getSubmittedRedirect()
{
	return 'http://' + document.domain + '/request-received.html'	
}

// 20100518 MJS catch no www
function nonUSANote()
{
	if (document.domain != 'www.acarda.com' && document.domain != 'acarda.com') 
	{
	document.open();
	document.write('Our New&nbsp;Zealand number is +64&nbsp;7&nbsp;579&nbsp;1153.');
	document.close();
	}
}

// 20100503 MJS added global download processing

function validate_downloadform(theForm) {

	if(requestsubmitted == true)
	{
	   alert("In progress. Please wait.");
	   return false;
	}
	if (theForm.first.value == "")
	{
		alert("Please enter a first name.");
		theForm.first.focus();
		return false;
	}

	if (theForm.last.value == "")
	{
		alert("Please enter a last name.");
		theForm.last.focus();
		return false;
	}
	
	if ((theForm.email.value==null)||(theForm.email.value==""))
	{
		alert("Please enter an email address.");
		theForm.email.focus();
		return false;
	}
	
	if (isValidEmail(theForm.email.value)==false)
	{
		alert("Please enter a valid email address.");
		//theForm.email.value=""
		theForm.email.focus();
		return false;
	}

	//20100518 MJS allow no telephone
	//if (theForm.telephone.value == "")
	//{
	//	alert("Please enter a telephone number.");
	//	theForm.telephone.focus();
	//	return false;
	//}
	
	//set redirect
	theForm.redirect.value=getSubmittedRedirect();
	
	//set source
	theForm.source.value=getDownloadSource();
		
	//not used at for acarda downloads
	//set software version
	//theForm.version.value=engineVersion;
	
	//not used at for acarda downloads
	//set download page
	//theForm.download.value=getDownloadPage();
	
	//not used at for acarda downloads
	//set product
	//theForm.product.value=getProductSource();
	
	requestsubmitted = true;
	return true;	
}

// 20100503 MJS allows backspace,space,(,),+,-,0-9
function isTelephoneNumber(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode
    if ((charCode == 8  || 
		 charCode == 32 || 
		 charCode == 40 || 
		 charCode == 41 || 
		 charCode == 43 || 
		 charCode == 45) || 
		(charCode >= 48 && charCode <= 57))
    	{
		return true;
		}
    return false;
}

// 20100518 MJS catch no www
function getDownloadSource()
{
	switch(document.domain)
	{
		case null:
			return 'unknown';
		break;
		case 'www.acarda.com':
			return 'com';
		break;
		case 'www.acarda.com.au':
			return 'acau';
		break;
		case 'www.acarda.co.nz':
			return 'acnz';
		break;		
		case 'acarda.com':
			return 'com';
		break;
		case 'acarda.com.au':
			return 'acau';
		break;
		case 'acarda.co.nz':
			return 'acnz';
		break;
		default:
			return document.domain;		
	}
}
function validate_receiptform(theForm) {

	if(requestsubmitted == true)
	{
	   alert("In progress. Please wait.");
	   return false;
	}
	if (theForm.first.value == "")
	{
		alert("Please enter a first name.");
		theForm.first.focus();
		return false;
	}

	if (theForm.last.value == "")
	{
		alert("Please enter a last name.");
		theForm.last.focus();
		return false;
	}
	
	if ((theForm.email.value==null)||(theForm.email.value==""))
	{
		alert("Please enter an email address.");
		theForm.email.focus();
		return false;
	}
	
	if (isValidEmail(theForm.email.value)==false)
	{
		alert("Please enter a valid email address.");
		//theForm.email.value=""
		theForm.email.focus();
		return false;
	}

	if (theForm.receipt.value == "")
	{
		alert("Please enter a receipt number.");
		theForm.receipt.focus();
		return false;
	}
	
	//set redirect
	theForm.redirect.value=getSubmittedRedirect();
	
	requestsubmitted = true;
	return true;	
}

//20100505 MJS added validate_ticket
var ticketsubmitted = false;
function validate_ticket(theForm) {

	if(ticketsubmitted == true)
	{
	   alert("In progress. Please wait.");
	   return false;
	}
	if (theForm.first.value == "")
	{
		alert("Please enter a first name.");
		theForm.first.focus();
		return false;
	}

	if (theForm.telephone.value == "")
	{
		alert("Please enter a telephone number.");
		theForm.telephone.focus();
		return false;
	}
	
	ticketsubmitted = true;
	return true;	
}