

var Common = {

	// Common class methods

	matchClass : function(
		oElement,
		sClassName
		) {
	
		return oElement && oElement.className && oElement.className.match(new RegExp('(^|\\s+)' + sClassName + '($|\\s+)'));
		
	},

	addClass : function(
		oElement,
		sClassName
		) {

		if(oElement && !this.matchClass(oElement, sClassName)) {
			oElement.className += ' ' + sClassName;
		}
		
	},
	
	removeClass : function(
		oElement,
		sClassName
		) {
	
		if(oElement && oElement.className) {
			oElement.className = oElement.className.replace(new RegExp('(.*)(^|\\s+)(' + sClassName + ')($|\\s+)(.*)'), '$1$4$5').replace(/(^)\s/, '$1');	
		}

	},
	
	
	// Common event methods
	
	addEvent : function(
		oElement,
		sEventType,
		fEventFunc,
		bCapture
		) {
					
		if(oElement.addEventListener) {
			oElement.addEventListener(
				sEventType,
				fEventFunc,
				bCapture? true : false
				);
		}
		else if(oElement.attachEvent) {
			oElement.attachEvent(
				'on' + sEventType,
				fEventFunc
				);
		}
		
	},

	removeEvent : function(
		oElement,
		sEventType,
		fEventFunc,
		bCapture
		) {
	
		if(oElement.removeEventListener) {
			oElement.removeEventListener(
				sEventType,
				fEventFunc,
				bCapture? true : false
				);
		}
		else if(oElement.detachEvent) {
			oElement.detachEvent(
				'on' + sEventType,
				fEventFunc
				);
		}
			
	},
				
	extend : function(
		oSource,
		oDestination
		) {				
		
		for(var i in oSource) {		
			oDestination[i] = oSource[i];
		}
		
		return oDestination;
		
	},
	
	oPopupDefaults : {	
	
		iWidth      : 900,
		iHeight     : 680,
		sToolbar    : 'no',
		sMenubar    : 'no',
		sResizeable : 'no',
		sScrollbars : 'yes',
		sStatus     : 'no'
	
	},
	
	popup : function(
		sUrl,
		sName,
		oOptions,
		bReplace
		) {
		
		oOptions = this.extend(
			oOptions,
			this.oPopupDefaults
			);
		
		var iLeftOffset = screen.availWidth / 2 - oOptions.iWidth / 2;
		var iTopOffset = screen.availHeight / 2 - oOptions.iHeight / 2;			
		
		oNewWindow = window.open(
			sUrl,
			sName,
			'left=' + iLeftOffset + ', ' +
			'top = ' + iTopOffset + ', ' +
			'width=' + oOptions.iWidth + ', ' +
			'height=' + oOptions.iHeight + ', ' +
			'resizable=' + oOptions.sResizeable + ', ' +
			'toolbar=' + oOptions.sToolbar + ', ' +
			'scrollbars=' + oOptions.sScrollbars + ', ' +
			'status=' + oOptions.sStatus
			);
			
		if(sUrl.match(/\.(gif|jpe?g|png)$/i)) {
		
			oNewWindow.document.open();
			
			oNewWindow.document.write('<html><head></head>' +
				'<body style="background: #FFF; margin: 0px; padding: 0px;">' +
				'<table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%"><tr><td align="center">' + 
				'<img src="' + sUrl + '" </td></tr></table></body></html>'
				);
				
			oNewWindow.document.close();
		
		}
			
		oNewWindow.focus();				

		return false;
		
	}

}
