function $(id){
	return document.getElementById(id);
}
var Common = {
	matchClass : function(
		oElement,
		sClassName
		) {
	
		return oElement && oElement.className && oElement.className.match(new RegExp('(^|\\s+)' + sClassName + '($|\\s+)'));
		
	},
	switchClass : function(
		oElement, strCurrClass, strNewClass ) {
		if ( this.matchClass( oElement, strNewClass ) ) this.replaceClass( oElement, strCurrClass, strNewClass ); else this.replaceClass( oElement, strNewClass, strCurrClass );
	},
    replaceClass : function ( objNode, strNewClass, strCurrClass ) {
	var strOldClass = strNewClass;
	if ( strCurrClass && strCurrClass.length ){
		strCurrClass = strCurrClass.replace( /\s+(\S)/g, '|$1' );
		if ( strOldClass.length ) strOldClass += '|';
		strOldClass += strCurrClass;
	}
	objNode.className = objNode.className.replace( new RegExp('(^|\\s+)(' + strOldClass + ')($|\\s+)', 'g'), '$1' );
	objNode.className += ( (objNode.className.length)? ' ' : '' ) + strNewClass;
	},
	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      : 600,
		iHeight     : 400,
		sToolbar    : 'no',
		sMenubar    : 'no',
		sResizeable : 'yes',
		sScrollbars : 'yes',
		sStatus     : 'yes'
	
	},
	
	popupNew : function(
		sUrl,
		sName,
		sWidth,
		sHeight
		) {
		var objOverlay = document.getElementById('overlay_w');
		var objLightbox = document.getElementById('lightbox_w');
		var objCaption = document.getElementById('lightboxCaption');
		var objImage = document.getElementById('lightboxImage');
		var objLoadingImage = document.getElementById('loadingImage');
		var objLightboxDetails = document.getElementById('lightboxDetails');
		var objFrame = document.getElementById('pop');
		
		var arrayPageSize = this.getPageSize();
		var arrayPageScroll = this.getPageScroll();
		
		objOverlay.style.height = (arrayPageSize[1] + 'px');
		
		objLightbox.style.width = sWidth;
		if(sHeight == '100%'){
		BodyHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
		sHeight = BodyHeight - 100;
		}
		var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - sHeight) / 2);
		var lightboxLeft = ((arrayPageSize[0] - 20 - sWidth) / 2);
		objFrame.style.width  = sWidth;
		objFrame.style.height = sHeight;
		objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
		objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
		objFrame.style.width = sWidth + 'px';
		objFrame.style.height = sHeight + 'px';
		objLightbox.style.height = sHeight + 'px';
		
		if(sUrl == '/flash.htm'){
		objFrame.src = sUrl + '?r=' + Math.random();
		}else{
		objFrame.src = sUrl;
		}
		objOverlay.style.display = 'block';
		objLightbox.style.display = 'block';
	},
	hidePopup : function()
	{
		objOverlay = document.getElementById('overlay_w');
		objLightbox = document.getElementById('lightbox_w');
		objOverlay.style.display = 'none';
		objLightbox.style.display = 'none';
		document.onkeypress = '';
	},
	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;
		
	},
	EvaluateHeight : function(
		objidParent,
		objidChild
		) {
		Parent = document.getElementById(objidParent);
		Child = document.getElementById(objidChild);
		if(Parent && Child){
			if(Parent.offsetHeight){
			Child.style.height = Parent.offsetHeight + 'px';
			}
		}
	},
	getPageScroll : function()
	{
		var yScroll;

		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
		} else if (document.body) {// all other Explorers
			yScroll = document.body.scrollTop;
		}

		arrayPageScroll = new Array('',yScroll) 
		return arrayPageScroll;
	},
	getPageSize : function()
	{
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else {
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		if (self.innerHeight) {
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) {
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}

		if(xScroll < windowWidth){	
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}
		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
		return arrayPageSize;
	}
}



function addLoadEvent(func)
{	
	var oldonload   = window.onload;
	var oldonresize = window.onresize;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}
	if (typeof window.onresize != 'function'){
    	window.onload = func;
	} else {
		window.onresize = function(){
		oldonresize();
		func();
		}
	}
}



function PopupMail(){
	Common.popup('/mail.htm', 'Mail', {iWidth: 500, iHeight: 400}, null);
}