// Copyright Acro Media Inc. 1998-2006, www.acromediainc.com

function copyrightYear(){
	if(document.getElementById('insertYear')) document.getElementById('insertYear').innerHTML = new Date().getFullYear();
}


function externalLinks(){
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		if (anchors[i].getAttribute("href") && anchors[i].getAttribute("rel") == "external") anchors[i].target = "_blank";
	}
}

function siteOnLoad () {
	copyrightYear();
	externalLinks();
}

function addLoadEvent(func){
	var oldOnLoad = window.onload;
	if(typeof window.onload != 'function'){
		window.onload = func;
	}
	else{
		window.onload = function(){
			oldOnLoad();
			func();
		}
	}
}


addLoadEvent(siteOnLoad);

function checkRequired(checkform, requiredArray){
	var canAction = "http://www.salesforce.com/servlet/servlet.WebToCase?sup_email=1";
	var usaAction = "http://www.salesforce.com/servlet/servlet.WebToCase?encoding=UTF-8";
	
	var error = "";
	var emailInfo = document.getElementById('emailInfo');
	var errorInfo = document.getElementById('errorInfo');
	
	for(i=0;i<requiredArray.length;i++) {
		var element = checkform[requiredArray[i]];
		if(element.value==""){
			if(element) showError(element);
			error = true;
			if(errorInfo){
				errorInfo.innerHTML = "Fields marked red either have errors or are blank and are required.";
				errorInfo.style.display = "block";
			}
		}
		if(element.name=="email" && element.value != ""){
			if(!validateEmail(element.value)){
				if(emailInfo) emailInfo.innerHTML = "Format: yourname@domain.com";
				showError(element);
				error = true;
			}
			element.onblur = function(){document.getElementById('emailInfo').innerHTML = ""};
		}
	}
	
	var curCountry = $("#countrySel").val();
	if (curCountry == "Canada") {
		$("#frm_survey").attr("action", canAction)
	}
	else {
		$("#frm_survey").attr("action", usaAction)		
	}
	
	if(error) return false; else checkform.submit();
}

/*
function changeAction() {
	var canAction = "http://www.salesforce.com/servlet/servlet.WebToCase?sup_email=1";
	var usaAction = "http://www.salesforce.com/servlet/servlet.WebToCase?encoding=UTF-8";
	var curCountry = $("#countrySel").val();

	if (curCountry == "Canada") {
		$("#frm_survey").attr("action", canAction)
	}
	else {
		$("#frm_survey").attr("action", usaAction)		
	}
}
*/

function showError(element){
	element.style.backgroundColor = "rgb(251, 191, 191)";
	element.onfocus = clearError;
}
function clearError(){
	this.style.backgroundColor = "rgb(255, 255, 255)";
}
function validateEmail(src) {
  var emailReg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|ca))$/;
    var regex = new RegExp(emailReg);
    return regex.test(src);
 }
 
 
function toggleMenu(menu){
 	theMenu = document.getElementById(menu);
 	switch (theMenu.className) {
		case "hiddenMenu":
			theMenu.className = "";
			break;
		case "":
			theMenu.className = "hiddenMenu";
			break;
	}
 }
 
function toggleProvince(menu){
	var provinceArray = ["ontario", "britishColumbia", "novaScotia", "newBrunswick", "arkansas", "sssl", "stpl", "NA"];
	theMenu = document.getElementById(menu);
	theCont = document.getElementById(menu+'Cont');
 	
	switch (theMenu.className) {
		case "hiddenMenu":
			for(i=0; i<provinceArray.length; i++){
				document.getElementById(provinceArray[i]).className = "hiddenMenu";
				document.getElementById(provinceArray[i]+'Cont').className = "hiddenMenu";
			}
			theMenu.className = "";
			theCont.className = "";
			break;
		case "":
			//theMenu.className = "hiddenMenu";
			//theCont.className = "hiddenMenu";
			break;
	}
}

function showInfo(region){
	var text = region.alt;
	var box = document.getElementById('infoBoxRegion');
	box.innerHTML = text;
}
