/*******************************************************************************************
 * cssjs
 * Written by Christian Heilmann (http://icant.co.uk)
 * Eases the dynamic application of CSS classes via DOM
 * Parameters: action a, object o and class names c1 and c2 (c2 optional)
 * Actions: swap exchanges c1 and c2 in object o
 *			add adds class c1 to object o
 *			remove removes class c1 from object o
 *			check tests if class c1 is applied to object o
 * Example:	cssjs('swap',document.getElementById('foo'),'bar','baz');
 *******************************************************************************************/


	function cssjs(a,o,c1,c2) {
		switch (a){
			case 'swap':
				o.className=!cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
			break;
			case 'add':
				if(!cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
			break;
			case 'remove':
				var rep=o.className.match(' '+c1)?' '+c1:c1;
				o.className=o.className.replace(rep,'');
			break;
			case 'check':
				return new RegExp('\\b'+c1+'\\b').test(o.className)
			break;
		}
		return true;
	}


/*******************************************************************************************
 * addLoadEvent
 * Written by Simon Willison (http://simon.incutio.com/)
 * Takes a function as an argument which should be executed once the page has loaded
 * Parameters: function func
 * Example:	
 *		addLoadEvent(myFunction);
 *		addLoadEvent(function() {
 *			alert ('a');
 *		});
 *******************************************************************************************/


	function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				func();
				oldonload();
			}
		}
	}
	
	/*******************************************************
	 * Uncomment if you need to stop JS Flicker
	 * 
	 *	if (document.getElementsByTagName) {
	 *		addLoadEvent (function() {
	 *			document.body.style.visibility = 'visible';
	 *		});
	 *		document.write ('<style type="text/css"> body { visibility: hidden; } \</style>');
	 *	}
	 *
	 *******************************************************/


/*******************************************************************************************
 * isEmailAddr
 * Written by Christian Heilmann (http://icant.co.uk)
 * Check that the email address matches the correct basic format
 * Parameters: string str
 * Example:	isEmailAddr('1@1.com');
 *******************************************************************************************/
 
 
	function isEmailAddr(str) {
		var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
		return re.test(str);
	}


/*******************************************************************************************
 * isValidDate
 * Written by  Chris Hogben (http://www.codetoad.com)
 * Check that the date is valid
 * Example:	isValidDate(30, 1, 2005);
 *******************************************************************************************/
 

	function isValidDate(day, month, year) {
		month--; // JavaScript takes January as "0"
		var dteDate=new Date(year, month, day);
		return ((day==dteDate.getDate()) && (month==dteDate.getMonth()) && (year==dteDate.getFullYear()));
	}


/*******************************************************************************************
 * printMe
 * Try to run the "print" function, otherwise tell the user how to print correctly.
 * Example:	printMe();
 *******************************************************************************************/


	function printMe () {
		try { 
			print();
		} catch(exception){
			alert("To print this page, click file and\n select 'Print' or 'Print Preview' ");
		}
	}


/*******************************************************************************************
 * fDetectFlash
 * Written by Christopher Sheldon (http://www.microagesolutions.com)
 * Returns 0 if no plugin detected or the version number if plugin is detected
 *******************************************************************************************/


	var oFlashPlugin = new Object(); 
	oFlashPlugin.installed = false; 
	oFlashPlugin.version = '0'; 
	if(navigator.plugins && navigator.plugins.length) { 
    	for (var iCounter = 0; iCounter < navigator.plugins.length && !oFlashPlugin.installed; iCounter++) { 
        	if(navigator.plugins[iCounter].name.indexOf('Shockwave Flash') != -1) {
				var sFlashString = navigator.plugins[iCounter].description.split('Shockwave Flash ')[1];
            	oFlashPlugin.version = sFlashString; 
            	oFlashPlugin.installed = true; 
			} 
		}
	} else if(window.ActiveXObject) { 
    	for(var iCounter = 2; iCounter < 10; iCounter++) { 
        	try { 
            	oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + iCounter + "');"); 
            	if(oFlash) { 
                	oFlashPlugin.installed = true; 
                	oFlashPlugin.version = iCounter; 
				}
	 		} catch(e) {
	 		}
    	} 
	}
	document.f = parseInt(oFlashPlugin.version);
	f = document.f; // Legacy

