/*
======================================
execute when DOM is ready...
======================================
*/
$(function() {
	$QuickCallForm = $('#quickcall-form');
	
	var $QuoteFields = $("#quote-formfields", $QuickCallForm);
	$QuoteFields.hide();
	
	var $Quote = $("#quote_me");
	
	$Quote.click(function() {
		if ($Quote.is(':checked')) {
			$QuoteFields.slideDown(500);
		}
		else {
			$QuoteFields.slideUp(500);
		}
	});
	
	if ($QuickCallForm.size()>0) {			

		var $Name = $("#name");
		var $Phone = $("#phone");
		var $Company = $("#company");
		var $Address = $("#company_address");
		var $Website = $("#website");
		var $Email = $("#email");

		$('.textField', $QuickCallForm).focus(function(){
			if ($(this).val() == $(this).attr('title')) {
				$(this).val('');
			}			
		}).blur(function(){
			if ($(this).val() == '') {
				$(this).val($(this).attr('title'));
			}
		});

		$QuickCallForm.submit(function(){
			var bErrors = false;
			if ($Name.val()==$Name.attr('title')||$Name.val()=='') {
				alert('Please enter your name');
			}
			else if ($Phone.val()==$Phone.attr('title')||$Phone.val()=='') {
				alert('Please enter your phone');		
			}
			else if ($Quote.is(':checked') && ($Company.val()==$Company.attr('title')||$Company.val()=='')) {
				alert('Please enter your company name');		
			}
			else if ($Quote.is(':checked') && ($Address.val()==$Address.attr('title')||$Address.val()=='')) {
				alert('Please enter your company address');		
			}
			else if ($Quote.is(':checked') && ($Email.val()==$Email.attr('title')||$Email.val()=='')) {
				alert('Please enter your email address');		
			}
			else {
				$.getJSON(
				  'quickcall.cfc?wsdl',
				  {method:'CallBack', returnformat:'json', queryformat:'column', name:$Name.val(), phone:$Phone.val(), quote_me:$Quote.is(':checked'), company:$Company.val(), company_address:$Address.val(), website:$Website.val(), email:$Email.val()},
				  doEchoResult
				);
			}
			return false;
		});
	}

	$('#newsletter_signup').find(':text')
		.each(function(){
			$self = $(this);								  	
			$self.val($self.attr('title'));
		})
		.click(function(){
			$(this).val('')
		})
		.end()
		.submit(function(){
			var $emailaddressbox = $('#newsletter_email');
			var $newslettername = $('#newsletter_name');
			var $newslettercompany = $('#newsletter_company');
			
			if ($emailaddressbox.val()==''||$emailaddressbox.val()==$emailaddressbox.attr('title')){
				alert('Please enter ' + $emailaddressbox.attr('title'));
				$emailaddressbox.val('').focus();
				return false;
			}
			else {
				if ($newslettername.val()==''||$newslettername.val()==$newslettername.attr('title')){
					$newslettername.val('');
				}
				if ($newslettercompany.val()==''||$newslettercompany.val()==$newslettercompany.attr('title')){
					$newslettercompany.val('');
				}
				return true;
			}
		});
	
	/*
	var $siteMapLayer = $('#sitemaplayer').hide().appendTo('#tNavigation');
	
	$('#sitemaplink').click(function(){
		$siteMapLayer.slideToggle(500);
		return false;
	});
	*/

});

// call back function
function doEchoResult (r) {
	if (r.SUCCESS==true) {
		$('#quickcall-form').empty().fadeIn(2000).append('<p class="response">' + r.MESSAGE + '<\/p><p class="divider">&nbsp;<\/p>');
	}
	else {
		// failed...
		//alert(r.MESSAGE + " " + r.SUCCESS);
		document.location.href = 'index.cfm/webdesign/Contact.Home?name=' + $("#name").val() + '&phone=' + $("#phone").val();
	}
}

/* ============= john's rollover code [v1.0] (much better than that dreamweaver generated stuff!) ============= */
var bHover = false;
function swapImage(oLink, bOver){
	if(document.images){
		var oImage = oLink.childNodes[0];
		var imageName = oImage.src.substring(0, oImage.src.lastIndexOf("."));
		var imageExtension = oImage.src.substring(oImage.src.lastIndexOf("."));
		if (bOver) {
			if (oImage.src.lastIndexOf("-over")==-1) {
				oImage.src = imageName + "-over" + imageExtension;
				bHover = false;
			}
			else {
				bHover = true;
			}
		}
		else {
			if (!bHover) {
				oImage.src = imageName.substring(0, imageName.lastIndexOf("-")) + imageExtension;
			}
		}
	}
}

/* ============= john's optional modal popup window code [v1.3] ============= */
function popupWindow(sUrl, iWidth, iHeight) {
	if (arguments.length>=4) {
		// zero based array so 3 not 4!
		bModal = arguments[3];
	}
	else if (sUrl.indexOf('google')>0) {
		// google maps doesn't like modal on IE
		bModal = false;
	}
	else {
		// default to modal...
		bModal = true;		
	}

	if (window.showModalDialog && bModal) {
		iWidth = iWidth + 8;
		iHeight = iHeight + 48;
		sWindowFeatures = "dialogTop:10px;dialogLeft:10px;dialogWidth:" + iWidth + "px;dialogHeight:" + iHeight + "px";
		oWindowReference = window.showModalDialog(sUrl, window, sWindowFeatures);
	}
	else {
		if (document.all) {
			iWidth = iWidth + 40;
			iHeight = iHeight + 20;
		}
		else {
			iWidth = iWidth + 20;
			iHeight = iHeight + 20;
		}
		sWindowName = 'popupwindow';
		sWindowFeatures = "left=10,top=10,height=" + iHeight + ",width=" + iWidth + ",location=no,menubar=no,directories=no,toolbar=no,status=yes,titlebar =yes,resizable=yes,scrollbars=yes";
		if (bModal) {
			sWindowFeatures = sWindowFeatures + "dependent=yes.modal=yes,dialog=yes,minimizable=no,alwaysRaised=yes";
		}
		if (window.oWindowReference) {
			try {
				oWindowReference.close();
			}
			catch(e) {
				// handle silently...	
			}
		}
		oWindowReference = window.open(sUrl, sWindowName, sWindowFeatures);
	}
	return false;
}


/*
-------------------------------------------------------- 
-------------------------------------------------------- 
Form validation
-------------------------------------------------------- 
-------------------------------------------------------- 
*/

/*
-------------------------------------------------------- 
RequiredFields [v2.0]
john's big hairy form validato
-------------------------------------------------------- 
*/
function RequiredFields(oForm) {
	var bCompleted = true;
	var bValidEmail = true;
	var oField;
	var oEmailRegExp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
	var bChecked = false;
	var bRequired = false;
	
	
	// loop through all form fields...
	for (var i=0; i<oForm.elements.length; i++) {
		oField = oForm.elements[i];
		if (oField!=undefined && oField!=null && oField.id.length) {		
			// check if the field is required...
			bRequired = Array.find(aRequired, oField.name)!=-1;
			
			if (bRequired) {
				// required field...
				if (oField.type=='text'||oField.type=='textarea'||oField.type=='password'||oField.type=='hidden') {
					if (oField.value.length==0) {
						bCompleted = false;
						highlight(oField);
					}
					else if (oField.name=='email') {
						if (!oEmailRegExp.test(oField.value)) {
							bValidEmail = false;
							highlight(oField);
						}
					}
				}
				else if (oField.type=='radio') {
					bChecked = false;
					for (j=0;j<oField.length;j++) {
						if (oField[j].checked) {
							bChecked = true;
						}
					}
					if (!bChecked) {
						highlight(oField);
						bCompleted = false;
					}
				}
				else if (oField.type=='select'||oField.type=='select-one') {
					if (oField.options[oField.selectedIndex].value.length==0) {
						bCompleted = false;
						highlight(oField);
					}
				}
				else if (oField.type=='checkbox') {
					if (!oField.checked) {
						bCompleted = false;
						highlight(oField);
					}
				}
				else {
					bChecked = false;
					for (j=0;j<oField.length;j++) {
						if (oField[j].checked) {
							bChecked = true;
						}
					}
					if (!bChecked) {
						highlight(oField);
						bCompleted = false;
					}
				}
			}
			if (bCompleted) {
//			else {
				// check that value is not the default value...	
				if (oField.type=='text'||oField.type=='textarea'||oField.type=='password'||oField.type=='hidden') {
					if (oField.title&&oField.title.length) {
						if (oField.title.toLowerCase()==oField.value.toLowerCase()) {
							highlight(oField);
							bCompleted = false;
						}
					}
					else if (oField.alt&&oField.alt.length) {
						if (oField.alt.toLowerCase()==oField.value.toLowerCase()) {
							highlight(oField);
							bCompleted = false;
						}
					}
				}
			}
		}
		if (!bCompleted) {
			if (bRequired) {
				if (oField.title&&oField.title.length) {
					alert('Please enter ' + oField.title);
				}
				else if (oField.alt&&oField.alt.length) {
					alert('Please enter ' + oField.alt);
				}
				else {
					alert('Please complete all required fields');
				}
			}
			else {
				if (oField.title&&oField.title.length) {
					alert('Please enter ' + oField.title + ' or leave blank');
				}
				else if (oField.alt&&oField.alt.length) {
					alert('Please enter ' + oField.alt + ' or leave blank');
				}
				else {
					alert('Please set blank any non essential information you prefer not to provide');
				}
			}
			break;
		}
	} // end loop
	

	if (bCompleted&&!bValidEmail) {
		alert('Please check your email address');
	}
	var bResult = bCompleted && bValidEmail;

	if (bResult) {
		// loop through fields and find submit buttons then disable....
		// we have an issue where a disabled field is not passed back in the form so need to check that only one submit button...
		var aSubmitButtons = new Array();
		for (i=0;i<oForm.elements.length;i++) {
			if (oForm.elements[i].type=='submit') {
				aSubmitButtons[aSubmitButtons.length] = oForm.elements[i];
;
			}
		}
		if (aSubmitButtons.length==1) {
			// only one submit button so OK to disable...
			aSubmitButtons[0].style.cursor = 'wait';
			aSubmitButtons[0].disabled = true;	
			aSubmitButtons[0].value = "sending";
		}
		else {
			// more than one submit button so disable each psuedo style...
			for (i=0;i<aSubmitButtons.length;i++) {
				oForm.elements[i].style.color = "#C4C0C8";
				oForm.elements[i].style.backgroundColor = "#E4E4E4";
				aSubmitButtons[i].style.cursor = 'wait';
				aSubmitButtons[i].value = "sending";
			}
		}
	}
	return bResult;
}

/*
-------------------------------------------------------- 
highlight [v1.2]
john's highlight form elements
-------------------------------------------------------- 
*/
function highlight(oField) {
	// pick mode - highlight table cell (true) or form field (false)...
	var bHighlightTd = true;
	var sStyleParentBorder = '';
	var sStyleParentBackgroundColor = '';
	var sStyleFieldBorder = '1px solid #585EAA';
	var sStyleFieldBackgroundColor = '#FFFFFF';
	
	if (oField.type=='select'||oField.type=='select-one'||oField.type=='text'||oField.type=='textarea'||oField.type=='password') {
		if (bHighlightTd && oField.id) {
			if (sStyleParentBackgroundColor.length) {
				document.getElementById(oField.id).parentNode.style.backgroundColor = sStyleParentBackgroundColor;
			}
			if (sStyleParentBorder.length) {
				document.getElementById(oField.id).parentNode.style.border = sStyleParentBorder;
			}
			if (sStyleFieldBackgroundColor.length) {
				document.getElementById(oField.id).style.backgroundColor = sStyleFieldBackgroundColor;
			}
			if (sStyleFieldBorder.length) {
				document.getElementById(oField.id).style.border = sStyleFieldBorder;
			}
		}
		else {
			if (sStyleFieldBackgroundColor.length) {
				oField.style.backgroundColor = sStyleFieldBackgroundColor;
			}
			if (sStyleFieldBorder.length) {
				oField.style.border = sStyleFieldBorder;
			}
		}
	}
	else {
//		oField.parentNode.style.backgroundColor = 'lightyellow';
//		oField.parentNode.style.border = '1px solid red';
		// radio...
		for (var i=0;i<oField.length;i++) {

			if (bHighlightTd && oField[i].id) {
				if (sStyleParentBackgroundColor.length) {
					document.getElementById(oField[i].id).parentNode.style.backgroundColor = sStyleParentBackgroundColor;
				}
				if (sStyleParentBorder.length) {
					document.getElementById(oField[i].id).parentNode.style.border = sStyleParentBorder;
				}
				if (sStyleFieldBackgroundColor.length) {
					oField[i].style.backgroundColor = sStyleFieldBackgroundColor;
				}
				if (sStyleFieldBorder.length) {
					oField[i].style.border = sStyleFieldBorder;
				}
			}
			else {
				if (sStyleFieldBackgroundColor.length) {
					oField[i].style.backgroundColor = sStyleFieldBackgroundColor;
				}
				if (sStyleFieldBorder.length) {
					oField[i].style.border = sStyleFieldBorder;
				}
			}
		}
	}
//	alert(oField.name);
}


/*
-------------------------------------------------------- 
clearFieldValues [v1.0]
use for 'AAA' compliant sites
-------------------------------------------------------- 
*/
function clearFieldValues(oForm) {
	for (var i=0; i<oForm.elements.length; i++){
		oField = oForm.elements[i];
		if (oField!=undefined && oField!=null && oField.id.length) {	
			addEvent(
				document.getElementById(oField.id), 
				'focus', 
				function() { 
					if (this.id!=undefined && this!=null) {
						if (this.title==this.value) { 
							this.value='';
						}
					}
					else if (event.srcElement) {
						oElement = event.srcElement;
						if (oElement.title==oElement.value) { 
							oElement.value='';
						}
					}
					else {
						// not DOM or IE5.5+
					}
				}
				, false 
			);
		}
	}
}
//var aRequired = new Array();

/*
-------------------------------------------------------- 
extend Array with Find Method [v1.0]
-------------------------------------------------------- 
*/
Array.find = function(ary, element){
	for(var i=0; i<ary.length; i++){
		if(ary[i] == element){
			return i;
		}
	}
	return -1;
}

//var aRequired = new Array();

/* ============= add To Favourites if you really want it [v1.0] ============= */
function addToFavourites() {
	if (navigator.userAgent.indexOf("Opera")>-1) {
		window.alert('The Opera web browser does not support this feature.');
	}
	else if (document.all&&navigator.userAgent.indexOf("Opera")<0) {
		window.external.AddFavorite(location.href, document.title);
	}
	else {
		window.alert('Your browser does not support this feature.\nPressing Ctrl + D will bookmark this page.');
	}
}


/* ============= John's not quite so hairy flash detect [v1.0] ============= */
var iRequiredVersion = 7;
var bShowFlash = false;

// standard IE & windows detection...
var bIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var bOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
var bWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false; 

if (bIE && bWin && !bOpera) {
	// Internet Explorer on Windows platform...
	document.write('<scr' + 'ipt language="vbscript"> \n');	
	document.write('On Error Resume Next \n');	
	document.write('	bShowFlash = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & iRequiredVersion)) \n');	
	document.write('On Error Goto 0 \n');	
	document.write('</scr' + 'ipt> \n');	
}
else if (navigator.plugins) {
	// looking at mozilla/netscape browser...
	var sFlashVersion = navigator.plugins["Shockwave Flash"].description;
	var iMajorVersion = parseInt(sFlashVersion.charAt(sFlashVersion.indexOf(".") - 1));
	if (iMajorVersion >= iRequiredVersion) {
		bShowFlash = true;
	}
}
else if (bOpera) {
	// wing it and hope that it has flash!
	bShowFlash = true;
}


/* ============= writes out the movie to the browser [v1.3] ============= */
function writeMovieHtml(sMovieUrl, iWidth, iHeight, sAlign, aPassedParams, sStyle, sAltImage) {
	if (iWidth==null) {iWidth = '100%';}
	if (iHeight==null) {iHeight = '100%';}
	if (sAlign==null) {sAlign = 'middle';}
	if (aPassedParams==null) {sPassedParams = new Array();}
	if (sStyle==null) {sStyle = ""};
	if (sAltImage==null) {sAltImage = sMovieUrl.replace('swf','jpg');}
	
	if (bShowFlash) {
	
		var aDefaultParams = new Array('allowscriptaccess=samedomain','wmode=transparent','quality=high','menu=false');
		var aMovieParams = new Array();
		
		if (aPassedParams.length>0) {
			for (i=0;i<aDefaultParams.length;i++) {
				aValuePairDefault = aDefaultParams[i].split('=');
				bFound = false;
				for (j=0;j<aPassedParams.length;j++) {
					aValuePairPassed = aPassedParams[j].split('=');
					if (aValuePairPassed[0]==aValuePairDefault[0]) {
						aMovieParams[i] = aPassedParams[j];
						bFound = true;
						break;
					}
				}
				if (!bFound) {
					aMovieParams[i] = aDefaultParams[i];
				}
			}
		}
		else {
			aMovieParams = aDefaultParams;
		}
		
		if (sStyle.length) {
			if (sStyle.indexOf(':')!=-1) {
				document.write('<div style="' + sStyle + '">');
			}
			else {
				document.write('<div class="' + sStyle + '">');
			}
		}
	
		document.write('<object');
		document.write(' classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ');
		document.write(' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + iRequiredVersion + ',0,0,0" ');
		document.write(' width="' + iWidth + '" ');
		document.write(' height="' + iHeight + '" ');
		document.write(' align="' + sAlign + '" ');
		document.write('>');
		
		document.write('<param name="movie" value="' + sMovieUrl + '" />');
		
		for (i=0;i<aMovieParams.length;i++) {
			aValuePair = aMovieParams[i].split('=');
			document.write('<param name="' + aValuePair[0] + '" value="' + aValuePair[1] + '" />');
		}
		
		document.write('<embed ');
		document.write('	src="' + sMovieUrl + '" ');
		document.write('	pluginspage="http://www.macromedia.com/go/getflashplayer" ');
		document.write('	type="application/x-shockwave-flash" ');
		document.write('	align="' + sAlign + '" ');
		document.write('	width="' + iWidth + '" ');
		document.write('	height="' + iHeight + '" ');
		
		for (i=0;i<aMovieParams.length;i++) {
			aValuePair = aMovieParams[i].split('=');
			document.write(' ' + aValuePair[0] + '="' + aValuePair[1] + '" ');
		}
		document.write(' />');
		document.write('<\/object>');
		if (sStyle.length) {
			document.write('<\/div>');
		}
	}
	else {
		// bShowFlash = false
		if (sStyle.length) {
			if (sStyle.indexOf(':')!=-1) {
				document.write('<div style="' + sStyle + '">');
			}
			else {
				document.write('<div class="' + sStyle + '">');
			}
		}
		document.write('<img src="' + sAltImage + '" alt="" />');
		if (sStyle.length) {
			document.write('<\/div>');
		}
	}
}

/* ====================================================================== */
/* ========================== cookie handlers =========================== */
/* ====================================================================== */

/* ============= setCookie [v1.0] ============= */
function setCookie(sKey, sValue) {
	var futdate = new Date()		//Get the current time and date
	var expdate = futdate.getTime()  //Get the milliseconds since Jan 1, 1970
	expdate += 3600*1000  //expires in 1 hour(milliseconds)
	futdate.setTime(expdate)
	var newCookie = sKey + "=" + escape(sValue) + "; path=/;"	//Set the new cookie values up
//	newCookie += " expires=" + futdate.toGMTString()
	window.document.cookie=newCookie //Write the cookie
}
/* ============= getCookie [v1.0] ============= */
function getCookie(sKey) {
	var oCookie = document.cookie;
	var sKey = sKey + "=";
	var iBegin = oCookie.indexOf("; " + sKey);
	if (iBegin == -1) {
		iBegin = oCookie.indexOf(sKey);
		if (iBegin != 0) {
			return null;
		}
	} 
	else {
		iBegin = iBegin + 2;
	}
	var iEnd = oCookie.indexOf(";", iBegin);
	if (iEnd == -1) {
		iEnd = oCookie.length;
	}
	return unescape(oCookie.substring(iBegin + sKey.length, iEnd));
}
/* ============= clearCookie [v1.0] ============= */
function clearCookie(sKey) {
	setCookie(sKey, '');
	alert('Information has been deleted');
	return false;
}
/* ============= acceptsCookie [v1.0] ============= */
function acceptsCookie() {
	sCookieKey = 'cookiesenabled';
	setCookie(sCookieKey, true);
	var result = getCookie(sCookieKey);
	if (result==null||!result.length) {
		return false;
	}
	else {
		return true;
	}
}


/*
======================================================
John's fantastic alternative stylesheet switcher!
======================================================
version 1.3
======================================================
*/
var sCookieName = 'altStylesheet';
var aAltStylesheets = new Array('mediumFont','largeFont');

// check for style cookie apply...
addOnloadEvent(HasStyle);
addOnloadEvent(WriteAltStyleSheets);

function ActivateStyleSheet(sTitle, bActive) {
	if (document.getElementById) {
		document.getElementById(sTitle).disabled = !bActive;
//		alert(document.getElementById(sTitle).href);
//		alert(sTitle + ' = ' + document.getElementById(sTitle).disabled);
		if (bActive) {
			// set cookie...
			setCookie(sCookieName, sTitle);
		}
	}
}
function SetDefaultStyle() {
	setCookie(sCookieName, '');
	DisableAltStyles();
	WriteAltStyleSheets();
}
function DisableAltStyles() {
	for (i=0;i<aAltStylesheets.length;i++) {
		ActivateStyleSheet(aAltStylesheets[i], false);
	}
}

function HasStyle() {
	var sDefaultStyle = '';
	if (document.cookie) {
		sDefaultStyle = getCookie(sCookieName);
		if (sDefaultStyle) {
			DisableAltStyles();
			if (sDefaultStyle.length) {
				ActivateStyleSheet(sDefaultStyle, true);
			}
		}
	}
}

function SwitchStyle(sTitle) {
	DisableAltStyles();
	ActivateStyleSheet(sTitle,true);
	WriteAltStyleSheets();
}
function WindowStatus(sText) {
	window.status = sText;
	return true;
}
function WriteAltStyleSheets() {
	if (document.getElementById && document.getElementById('altStyleSheets')) {
		var oAltStylesDiv = document.getElementById('altStyleSheets');
		var sInnerHtml = '';
		var iFontSize = 9;
		var sCurrentStyle = '';	
		
		// current style...
		if (document.cookie) {
			sCookieStyle = getCookie(sCookieName);
			if (sCookieStyle!="undefined" && sCookieStyle!=null && sCookieStyle.length) {
				sCurrentStyle = sCookieStyle;
			}
			else {
				sCurrentStyle = '';	
			}
		}
		
		// link for default style...
		

		if (sCurrentStyle=="") {
			sInnerHtml = sInnerHtml + '<span class="activeStyle" style="font-size:' + iFontSize + 'px;">standard font size<\/span>';
		}
		else {
			sInnerHtml = sInnerHtml + '<a href="#" onclick="SetDefaultStyle();return false;" onmouseover="return WindowStatus(this.title)" onmouseout="return WindowStatus(\'\')" style="font-size:' + iFontSize + 'px;" title="Standard font size">standard font size<\/a>';
		}
		
		for (i=0;i<aAltStylesheets.length;i++) {
			iFontSize = iFontSize+2;
			sStyleFriendlyName = aAltStylesheets[i].replace('Font','');

			if (sCurrentStyle==aAltStylesheets[i]) {
				// current style sheet...
				sInnerHtml = sInnerHtml + ' | <span class="activeStyle" style="font-size:' + iFontSize + 'px;">' + sStyleFriendlyName + ' font size<\/span>';
			}
			else {
				sInnerHtml = sInnerHtml + ' | <a href="#" onclick="SwitchStyle(\'' + aAltStylesheets[i] + '\');return false;" onmouseover="return WindowStatus(this.title)" onmouseout="return WindowStatus(\'\')" style="font-size:' + iFontSize + 'px;" title="' + sStyleFriendlyName + ' font size">' + sStyleFriendlyName + ' font size<\/a>';
			}
		}
		
		oAltStylesDiv.innerHTML = sInnerHtml;

	}
}



/* ============= add getElementById functionality to IE4 ============= */
if (!document.getElementById && document.all) { 
	document.getElementById = new Function('id', 'return document.all[id]') 
}

/* ============= handle multiple onload events... ============= */
/* 
http://www.tek-tips.com/faqs.cfm?fid=4862

usage:

addOnloadEvent(myFunctionName);

Or to pass arguments

addOnloadEvent(function(){ myFunctionName('myArgument') });
*/
function addOnloadEvent(fnc){
	if ( typeof window.addEventListener != "undefined" ) {
		window.addEventListener( "load", fnc, false );
	}
	else if ( typeof window.attachEvent != "undefined" ) {
		window.attachEvent("onload", fnc );
	}
	else {
    	if ( window.onload != null ) {
			var oldOnload = window.onload;
			window.onload = function ( e ) {
				oldOnload(e);
				window[fnc]();
			};
		}
    	else {
			window.onload = fnc;
		}
	}
}