// JavaScript Document
var opened;

function showBgSound(){
	var config = 'top=0,left=0,height=50,width=10,toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0';
	opened = window.open('/music.html', '_bg', config);
	opened.focus();
}

function showPopup(url, w, h){
	if (opened ){
		opened.close();
	}
	var config = 'height='+h+',width='+w+',toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1';
	opened = window.open(url, '_popup', config);
	opened.focus();
}

function number_format( number, decimals, dec_point, thousands_sep ) {
	var n = number, prec = decimals;
	
	n = !isFinite(+n) ? 0 : +n;
	prec = !isFinite(+prec) ? 0 : Math.abs(prec);
	
	var sep = (typeof thousands_sep == "undefined") ? ',' : thousands_sep;
	var dec = (typeof dec_point == "undefined") ? '.' : dec_point;
	
	var s = (prec > 0) ? n.toFixed(prec) : Math.round(n).toFixed(prec); //fix for IE parseFloat(0.55).toFixed(0) = 0;
	
	var abs = Math.abs(n).toFixed(prec);
	var _, i;
	
	if (abs >= 1000) {
		_ = abs.split(/\D/);
		i = _[0].length % 3 || 3;
		_[0] = s.slice(0,i + (n < 0)) +
		_[0].slice(i).replace(/(\d{3})/g, sep+'$1');
		s = _.join(dec);
	} else {
		s = s.replace('.', dec);
	}
	
	return s;
}

function isEmail( email ){
	if ( (email != null) && (email.match(/^[a-zA-Z0-9\_\.\-]+@([a-zA-Z0-9\_\-]+\.)+[a-zA-Z0-9]+$/) != null) ){
		return true;
	}
	return false;
}

function checkInputNotEmpty( id ){
	var obj = document.getElementById( id );
	if ( (obj == null) || (obj.value.replace(' ','').length == 0) ){
		return false;
	}
	return true;
}


/*====================================================================
 * Get the bounds
 *====================================================================*/
function getBounds( obj ){
	var t = obj.offsetTop;
	var l = obj.offsetLeft;
	var w = obj.offsetWidth;
	var h = obj.offsetHeight;
	var preObj = null;

	while ( obj=obj.offsetParent ){
		if ( obj.tagName.toUpperCase() == 'TABLE' ){
			var cIndex = preObj.cellIndex;
			for ( var i=0 ; i<obj.rows.length ; i++ ){
				if ( obj.rows[i][cIndex] == preObj ){
					for ( var j=0; j<cIndex; j++){
						l +=  obj.rows[i][j].offsetLeft;
					}					
					break;
				}
			}
		}
		t += obj.offsetTop;
		l += obj.offsetLeft;
		
		if ( obj.tagName.toUpperCase() == 'TD' ){
			preObj = obj;
		}
	}

	return {top:t, left:l, width:w, height:h}
}

