function trim(s)
{
if (typeof(s)=='string'){
var i,len=s.length;
for (i=len-1;i>=0 && s.charAt(i)<=' ';--i){}
len=i+1;
for (i=0;i<len && s.charAt(i)<=' ';++i){}
if (i<len) s=s.substring(i,len);
else s="";
}
return s;
}
function isNumber(str,allowFP)
{
if (typeof(allowFP)=='undefined') allowFP=false;
if (typeof(str)=='number'){
if (allow_fp) return true;
else return str==Math.floor(str);
}
if (typeof(str)!='string') return false;
str=trim(str);
if (str.length==0) return false;
var result=true;
if (window.RegExp){
var regstr="^[+-]?[0-9]*";
if (allowFP) regstr+="\\.?[0-9]*([eE][+-]?[0-9]+)?";
regstr+="$";
var reg = new RegExp(regstr);
result=reg.test(str);
}else{
result=false;
}
return result;
}
function isDate(str)
{
var milliseconds=Date.parse(str);
return !(isNaN(milliseconds));
}
function isZIPCode(str)
{
return isValidText(str,"^\\d{5}(-\\d{4})?$");
}
function isExpirationDate(str)
{
if (isValidText(str,"^\\d{1,2}/\\d{2}$"))
{
var month=parseInt(str.substring(0,2));
var year=parseInt(str.substring(3));
if (month>=1 && month<=12 && year>=0 && year<=99) return true;
else return false;
}else return false;
}
function isCreditCardNumber(str)
{
return isValidText(str,"^\\d{12}(\\d{4})?$");
}
function isEMailAddress(str)
{
return isValidText(str,"^([\\w\\._-]+)@([\\w_]+\\.)+([\\w_]+)$");
}
function isPhoneNumber(str)
{
return isValidText(str,"^\\(?\\d{3}\\)?[-\\. ]?\\d{3}[-\\. ]?\\d{4}$");
}
function isAlpha(str)
{
return isValidText(str.toUpperCase(),"^[ABCDEFGHIJKLMNOPQRSTUVWXYZ]+$");
}
function isAlphaNumeric(str)
{
return isValidText(str.toUpperCase(),"^[ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890]+$");
}
function isValidText(str,regex)
{
if (window.RegExp){
if (typeof(regex)=='string')
regex=new RegExp(regex);
return regex.test(str);
}else{
window.alert("RegExp not available!");
return true;
}
}
function isDefined(obj)
{
if (obj==null || (""+eval("obj"))=="undefined"){
return false;
}else{
return true;
}
}
function showProperties(obj,obj_name)
{
if (obj == null) return obj_name+" is null!";
var result;

if (obj_name) result="Name: "+obj_name+"\n";
result+="Type: "+typeof(obj)+"\n";
result+="Value: "+obj+"\n\n";
var keys=new Array();
var j=0;
for (var i in obj) keys[j++]=i;
keys.sort();
if (keys.length>0)
{
result+="Properties:\n";
for (var i in keys) result+=keys[i]+":"+obj[keys[i]]+"\n";
}
if (obj_name) window.alert(result);
return result;
}
function inspect(elm)
{
var str = "";
for (var i in elm)
str += i + ": " + elm.getAttribute(i) + "\n";
window.alert(str);
}
function inspectAttribute(elm,attr)
{
var str = "";
str = attr + ": " + elm.getAttribute(attr) + "\n";
window.alert(str);
}
function inspectStyle(elm)
{
if (elm.style)
{
var str = "";
for (var i in elm.style)
str += i + ": " + elm.style[i] + "; ";
window.alert(str);
}
}
function inspectStyleAttributeByID(id,attr)
{
var str = "";
str = attr + ": " + getStyleById(id,attr) + "\n";
window.alert(str);
}
function getObjectByID(id)
{
var o = null;
if (document.getElementById) {o = document.getElementById(id);}
else if (document.all){o = document.all[id];}
else if (document.layers){o = document.layers[id];}
return o;
}
function toggleVisibility(id)
{
var o = getObjectByID(id)
if (isDefined(o))
{
if (o.style)
{
if (o.style.visibility == "hidden") o.style.visibility = "visible";
else o.style.visibility = "hidden";
}
}
}
function setVisibility(id,state)
{
var o = getObjectByID(id)
if (isDefined(o))
{
if (o.style)
{
if (isDefined(state))
{
if (state) o.style.visibility = "visible";
else o.style.visibility="hidden";
}
else o.style.visibility = "visible";
}
}
}
function setState(id,state)
{
var o = getObjectByID(id)
if (isDefined(o))
o.disabled = !state;
}
function delayedAction(actionStr,milliseconds)
{
setTimeout(actionStr,milliseconds);
}
function delayedAlert(text,milliseconds)
{
setTimeout("alert(\""+text+"\");",milliseconds);
}
function popupWindow(windowName,URL,width,height)
{
var left = (screen.availWidth-width)/2;
var top = (screen.availHeight-height)/2;
height+=40;		// Add extra height for status bar, title bar, etc.
width+=20;		// Add extra width for margins
var w = this.open(URL, windowName, "statusbar=yes,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width="+(width)+",height="+(height)+",top="+(top)+",left="+(left));
if (w)
{

w.location.href=URL;
w.resizeTo(width,height);
w.moveTo(left,top);



w.focus();
}
return w;
}
function changeImage(objID,URL)
{
var img=getObjectByID(objID);
if (isDefined(img)) img.src=URL;
}
function pickImage(objID,imgPath,imgCount,delay)
{
var imageIdx=(Math.floor(Math.random()*imgCount)+1);
var URL=imgPath+imageIdx+".jpg";
changeImage(objID,URL);
if (delay>0) delayedAction("pickImage('"+objID+"','"+imgPath+"',"+imgCount+","+delay+")",delay);
}

function format_number(x0,fp)
{
var x = x0.toString();
var len = x.length;
var dot = x.lastIndexOf('.');
if (dot<0) dot=len;
var i=dot%3;
var y=x.substr(0,i);
while (i<dot)
{
if (i>0) y+=",";
y+=x.substr(i,3);
i+=3;
}
if (len>dot && fp) y+=x.substr(dot,len);
return y;
}
