/*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

/*
Make sure that textBox only contain number
*/
function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}

/*
	Check if a form element is empty.
	If it is display an alert box and focus
	on the element
*/
function isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}

/*
	Set one value in combo box as the selected value
*/
function setSelect(listElement, listValue)
{
	for (i=0; i < listElement.options.length; i++) {
		if (listElement.options[i].value == listValue)	{
			listElement.selectedIndex = i;
		}
	}	
}


function isEmail (s) {
    var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/
    return reg.test(s)
}


function isPhone(s) {
    //var reg = /^((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}$/
    var reg = /^(((\(\d{3}\)?)|(\d{3}-))?\d{3}-\d{4}|\d{10})$/
    return reg.test(s)
}
function isFax(s) {
    //var reg = /^((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}$/
    var reg = /^(((\(\d{3}\)?)|(\d{3}-))?\d{3}-\d{4}|\d{10})$/
    return reg.test(s)
}

function isZIPCode(s) {
    var reg = /^\d{5}$/
    return reg.test(s)
}

function isPass(s) {
    var reg = /^[A-Za-z0-9]+$/
    return reg.test(s)
}

function isInteger(s) {
    var reg = /^[0-9]*[1-9][0-9]*$/
    return reg.test(s)
}

var __list_constructor__ = [].constructor
if (!self._PRELOADIMAGES_)
     var _PRELOADIMAGES_ = []
function preLoadImage(p, prefixPath) {
	
     if (p.constructor == __list_constructor__) {
         for (var i=0;i<p.length;i++) {
             preLoadImage(p[i], prefixPath)
         }
     }else {
         var _idx = _PRELOADIMAGES_.length
         _PRELOADIMAGES_[_idx] = new Image()
         if (prefixPath)
             p = prefixPath + p
         _PRELOADIMAGES_[_idx].src = p
     }
}


