/********************************************************
Gerneal.js (Last modified: 4/24/09)

available Functions: 
	- position: getX , getY
	- check numeric: isMoney, isNumeric, isDecimal
	- force numeric: toDecimal
	- print: toMoney
	- other: selectAll, setSelect, viewImage, showFlash
********************************************************/
nextline = "\r\n"

function getX(elem) {
	var x = 0;
	while(elem != null) {
		x += elem.offsetLeft;
		elem = elem.offsetParent;
	}
	return x;
}
function getY(elem) {
	var y = 0;
	while(elem != null) {
		y += elem.offsetTop;
		elem = elem.offsetParent;
	}
	return y;
}

function isMoney (amount) {
	// isnumeric && not a negative && decimal points >= 0.01
 	if (!isNumeric(amount) || amount < 0.01)
 		return false;
 	return true;
}
function isDecimal (dec) {
 	if (isNumeric(dec) && parseInt(dec) != parseFloat(dec))
		return true;
	return false;
}

function isNumeric (num) {
 	if (num != "" && (num > 0 || num < 0 || num == 0))
		return true;
	return false;
}


function toDecimal (elem, float_point) {
	if (isNumeric(elem.value)) {
	 	amount = parseFloat(elem.value);
		elem.value = amount.toFixed(float_point);
	} else
		elem.value = "0";
}


function set_select(select, sval) {
 	var options = select.options
 	for (var i=0; i<options.length; i++)
 		if (options[i].value == sval) {
			select.selectedIndex = i
			break
		}
}

function selectAll(max) {
	for (var i=0; i<max; i++) {
		var sel = document.getElementsByName("select"+i)[0]
		sel.checked = document.all.selall.checked
	}
}

function viewImage(url) {
	if (url.length > 0)
		window.open(url, "preview", "toolbar=no,menubar=no")
	else
		alert('Image URL is empty!')
}



////////   show flash
function showFlash(flash_src, flash_w, flash_h){
   document.write('<OBJECT classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" WIDTH="' + flash_w + '" HEIGHT="' + flash_h + '" id="" ALIGN="" VIEWASTEXT>');
   document.write('<PARAM NAME=movie VALUE="' + flash_src + '"> ');
   document.write('<PARAM NAME=quality VALUE=high>');
   document.write('<PARAM NAME=wmode VALUE=transparent>');
   document.write('<PARAM NAME=bgcolor VALUE=#FFFFFF>');
   document.write('<EMBED src="' + flash_src + '" quality=high bgcolor=#FFFFFF  WIDTH="' + flash_w + '" HEIGHT="' + flash_h + '" NAME="" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>');
 document.write('</OBJECT>');    
}

