/**********************************************************************************
* author:		Christopher Sheldon, www.christophersheldon.ca															
* notes:		Copyright (c) Christopher Sheldon 2006. All Rights Reserved.		
*																									
*				The code contained within this file is not liscensed for public 
*				usage.  Do not reproduce or alter this file complete or in part 
*				without the express written	permission of the author. 													
********/
 
 function classSite() {

	/**********************************************************************************************
	*
	********/
		
	this.errorWindow = 'A required popup window has been blocked by your system.  This may be the result of security or ad blocking software running on your machine.\n\nPlease allow popup windows from this site before attempting to use this function.';
	this.doneLoad = false;	
	this.flashVersion = false;
	
	/**********************************************************************************************
	*
	********/
		
	var strVersion;
	var intPosition;
	var userAgent = navigator.userAgent.toLowerCase();
	
	function searchAgent(strBrowser) {
		intPosition = userAgent.indexOf(strBrowser) + 1;
		strVersion = strBrowser;
		return intPosition;
	};

	/**********************************************************************************************
	*	browser properties
	*
	********/

	this.isIE = false;
	this.isFireFox = false;
	this.isSafari = false;
	this.isOpera = false;
	this.isNS = false;
	this.isMozilla = false;
	
	if(searchAgent('firefox')) {
		this.isFireFox = true;
	} else if(searchAgent('safari')) {
		this.isSafari = true;
	} else if(searchAgent('opera')) {
		this.isOpera = true;
	} else if(searchAgent('msie')) {
		this.isIE = true;
	} else if(searchAgent('netscape')) {
		this.isNS = true;
	} else if(searchAgent('mozilla')) {
		this.isMozilla = true;
	};
	this.browserVersion = userAgent.charAt(intPosition + strVersion.length);

	/**********************************************************************************************
	*	flash properties
	*
	********/
	
	if(navigator.plugins && navigator.plugins.length) {    	 		
   	 	for(var intCounter = 0; intCounter < navigator.plugins.length; intCounter++) {
			if(navigator.plugins[intCounter].name.indexOf('Shockwave Flash') != -1) {
				var strFlashPlugin = navigator.plugins[intCounter].description.split('Shockwave Flash ')[1];
				this.flashVersion = parseInt(strFlashPlugin);
			}; 
		};
	} else if(window.ActiveXObject) { 
		for(var intCounter = 2; intCounter < 10; intCounter++) { 
			try { 
				objFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + intCounter + "');"); 
				if(objFlash) { 
					this.flashVersion = intCounter; 
				};
			} catch(objError) {
			};
		};
	};	
};

var site = new classSite();

/**************************************************************************************************
*	method: injectFlash 2006.07.13
*
********/

classSite.prototype.injectFlash = function(strUrl) {
	if(site.flashVersion) {
		var strHtml = '<object id="flashBanner" type="application/x-shockwave-flash" data="' + strUrl + '">';
		strHtml += '	<param name="movie" value="' + strUrl + '" />';
		strHtml += '	<param name="scale" value="noscale" />';
		strHtml += '	<param name="quality" value="high" />';
		strHtml += '</object>';
		
		document.write(strHtml);
	};
};

/**************************************************************************************************
*	method:	openWindow 2006.04.10
*
********/

classSite.prototype.openWindow = function(strUrl, strName, strFeatures, bReplace) {
	var elWindow = window.open((strUrl ? strUrl : ''), (strName ? strName : ''), (strFeatures ? strFeatures : ''), (bReplace ? bReplace : false));
	if(!elWindow) {
		alert(objDefault.errorWindow);
	};
	return false;
};

/**************************************************************************************************
*	method:	swapClass 2006.07.30
*
********/

classSite.prototype.swapClass = function(elThis, strClassName) {
	elThis = elThis.toString().indexOf('[object') != -1 ? elThis : document.getElementById(elThis);
	if(elThis && strClassName) {
		if(elThis.className != strClassName) {
			elThis.className = strClassName;
		};
	};
};

/**************************************************************************************************
*	method:	buttonOver 2006.07.30
*
********/

classSite.prototype.buttonOver = function() {
	var elItem = site.isIE ? event.srcElement : this;			
	site.swapClass(elItem.tagName == 'LI' ? elItem : elItem.tagName == 'A' ? elItem.parentNode : elItem.parentNode.parentNode, 'over');
};

/**************************************************************************************************
*	method:	buttonOut 2006.07.30
*
********/

classSite.prototype.buttonOut = function() {
	var elItem = site.isIE ? event.srcElement : this;			
	site.swapClass(elItem.tagName == 'LI' ? elItem : elItem.tagName == 'A' ? elItem.parentNode : elItem.parentNode.parentNode, 'out');
};

/**************************************************************************************************
*	method:	buttonClick 2006.07.30
*
********/

classSite.prototype.buttonClick = function() {
	var elItem = site.isIE ? event.srcElement : this;	
	elItem = elItem.tagName == 'DIV' ? elItem.childNodes[1].childNodes[0] : elItem.tagName == 'LI' ? elItem.childNodes[0] : elItem.tagName == 'A' ? elItem : elItem.parentNode;
	if(elItem.className.toLowerCase() == 'externalbutton') {
		site.openWindow(elItem.href);
	} else {
		location.href = elItem.href;
	};
	return false;
};

/**************************************************************************************************
*	method:	getButtons 2006.07.30
*
********/

classSite.prototype.getButtons = function() {
	var elMenu = document.getElementById('menu');
	var elButtons = elMenu.getElementsByTagName('li');
	for(var intCount = 0; intCount < elButtons.length; intCount++) {
		elButtons[intCount].onmouseover = site.buttonOver;
		elButtons[intCount].onmouseout = site.buttonOut;
		elButtons[intCount].onclick = site.buttonClick;
	};
};

/**************************************************************************************************
*	method:	getLinks 2006.07.30
*
********/

classSite.prototype.getLinks = function() {
	var elLinks = document.getElementsByTagName('a');
	for(var intCount = 0; intCount < elLinks.length; intCount++) {			
		if(elLinks[intCount].className.toLowerCase() == 'externallink') {
			elLinks[intCount].onclick = function() {
				site.openWindow(this, '', '');
				return false;
			};
		};
	};
};

/**************************************************************************************************
*	method:	getContactForm 2006.07.30
*
********/

classSite.prototype.getContactForm = function() {
	var elForm = document.getElementById('contactForm');
	if(elForm) {
		var bRates = false;
		var aParams = document.location.search.substring(1).split('&');
		for(var intCount = 0; intCount < aParams.length; intCount++) {
			if(aParams[intCount].toLowerCase() == 'c=rates') {
				bRates = true;
				var elSubject = document.getElementById('subject');
				var elMessage = document.getElementById('message');
				if(elSubject.value == '') {
					elSubject.value = 'Request for Rates Information';
				};
				if(elMessage.value == '') {
					elMessage.value = 'I would like information on rates for your services.';
				};
			};
		};
		
		elForm.onsubmit = function() {
			var elName = document.getElementById('realname');
			var elEmail = document.getElementById('email');
			var elSubject = document.getElementById('subject');
			var elMessage = document.getElementById('message');
			var elRecipient = document.getElementById('recipient');
			
			var reEmail  = /^(\w{1,}\.{0,}){1,}@{1,1}\w{1,}(\.{1,1}[a-z0-9]{1,}){1,}$/i;
			var strError = '';
			
			if(elName.value == '') {
				strError += 'Your name is required\n';
			};
			if(elEmail.value == '' || !reEmail.test(elEmail.value)) {
				strError += 'A valid email address is a required.\n';
			};
			if(elSubject.value == '') {
				strError += 'A subject is required.\n';
			};
			if(elMessage.value == '') {
				strError += 'A message is required.\n';
			};
			
			if(strError) {
				strError = 'The contact form has not been completed properly.  You must enter the following information properly before proceeding.\n\n' + strError;
				alert(strError);
				return false;
			} else {
				var strAddress = 'lbrown';
				if(bRates) {
					strAddress = 'lbrown';
				};
				elRecipient.value = strAddress + '@' + 'lwrs.ca';
				elForm.action = '/cgi-bin/formmail';

				return true;
			};
		};
	};	
};

/**************************************************************************************************
*	method:	getCareersForm 2006.07.30
*
********/

classSite.prototype.getCareersForm = function() {
	var elForm = document.getElementById('careersForm');
	if(elForm) {
		elForm.onsubmit = function() {
			var strAddress = 'lbrown';
			
			var elName = document.getElementById('realname');
			var elEmail = document.getElementById('email');
			var elSubject = document.getElementById('subject');
			var elMessage = document.getElementById('message');
			var elRecipient = document.getElementById('recipient');
			
			var reEmail  = /^(\w{1,}\.{0,}){1,}@{1,1}\w{1,}(\.{1,1}[a-z0-9]{1,}){1,}$/i;
			var strError = '';
			
			if(elName.value == '') {
				strError += 'Your name is required\n';
			};
			if(elEmail.value == '' || !reEmail.test(elEmail.value)) {
				strError += 'A valid email address is a required.\n';
			};
			
			if(strError) {
				strError = 'The careers form has not been completed properly.  You must enter the following information properly before proceeding.\n\n' + strError;
				alert(strError);
				return false;
			} else {
				elRecipient.value = strAddress + '@' + 'lwrs.ca';
				elForm.action = '/cgi-bin/formmail';
				return true;
			};
		};
	};	
};
	

/**************************************************************************************************
*	event: onload
*
********/

window.onload = function() {
	site.getButtons();
	site.getLinks();
	site.getContactForm();
	site.getCareersForm();
};
