/* * Global variables */ var pages = ["home", "about", "contact", "media", "events", "links", "advertising"]; // ID of each page container var opacity = new Array(); // Array to hold all opacity objects var inProgress = false; // Prevents concurrent page loads var currPage = 0; // Index of current page var DURATION = 450; // Duration of opacity change /* * Creates all the page opacity and height objs */ function init(){ // Create a opacity object for each page for(var i = 0; i < pages.length; i++) opacity[opacity.length] = new fx.Opacity(pages[i], {duration: DURATION}); // Just had a successful contact submission if(getURLParam("contact") == 1){ // Hide every page except contact form for(var i = 0; i < pages.length-1; i++){ opacity[i].hide(); $(pages[i]).style.display = "none"; } // Display success message $('success').style.display = "block"; // Turn the contact menu item on $('link'+currPage).className = ""; $('link3').className = "here"; // Set the currPage currPage = 3; } else { // Hide every page except first one for(var i = 1; i < pages.length; i++){ opacity[i].hide(); $(pages[i]).style.display = "none"; } } } /* * Gets params from the url */ function getURLParam(strParamName){ var strReturn = null; var strHref = window.location.href; if ( strHref.indexOf("?") > -1 ){ var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase(); var aQueryString = strQueryString.split("&"); for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){ if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){ var aParam = aQueryString[iParam].split("="); strReturn = aParam[1]; break; } } } return strReturn; } /* * Loads a new page based on it's index */ function load(page){ // Check to make sure previous page loads have finished if(inProgress) return; // Don't go ahead if it's the same page if(currPage != page){ inProgress = true; $('link'+currPage).className = ""; $('link'+page).className = "here"; opacity[currPage].custom(1,0); setTimeout("$(pages["+currPage+"]).style.display = 'none';completeLoad("+page+");", DURATION); } } /* * Completes the load of a new page (toggle opacity on) */ function completeLoad(page){ // Load the page content $('success').style.display = "none"; $(pages[page]).style.display = "block"; opacity[page].custom(0,1); currPage = page; setTimeout("inProgress=false;", DURATION); } function printEmail(){ var start = "djillions"; var middle = "@"; var end = "sympatico.ca"; document.write(start + middle + end); } /* * Form Validation */ function validateForm(f){ var errors = "ERROR | Please do the following:\n\n"; var count = 0; var errField = null; for(var i = 0; i < f.elements.length; i++){ var field = f.elements[i]; var type = field.type; var value = field.value; var name = field.name; // Not checking optional or disabled if(field.isOptional || field.disabled) continue; if(type == "text" || type == "textarea" || type == "select-one" || type == "password" || type == "file") { // Empty check if(isEmpty(value)) { errors += (++count) + ". " + convertName(name) + " (cannot be left blank)\n"; continue; } // Email check if(field.isEmail && !isEmail(value)) { errors += (++count) + ". " + convertName(name) + " must be a valid address\n"; continue; } errField = (!errField) ? errField = field : errField; } } if(count > 0) { alert(errors); if(errField) errField.focus(); return false; } return true; } function isEmpty(str){ return (str == null) || (trim(str).length == 0); } function isEmail(str){ var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i return re.test(str); } function trim(str){ return str.replace( /\s+$/g, "" ); } function convertName(str){ str = str.charAt(0).toUpperCase() + str.substr(1); return str.replace(/_/g, " "); } function setFieldFocus(form){ if(form != null && form.elements[0] != null) { for(var i = 0; i < form.length; i++){ if(form.elements[i].type != "hidden" && !form.elements[i].disabled && !form.elements[i].readOnly){ form.elements[i].focus(); break; } } } }