
if (!Number.toFixed) {
    Number.prototype.toFixed = function(x) {
        var temp = this;
        temp = Math.round(temp * Math.pow(10, x)) / Math.pow(10, x);
        return temp;
    };
}

function textRoundDecimal(num, x)
{
    val = new String(Math.round(num * Math.pow(10, x)));
    if (val.length <= x)
    {
        zeroPad = (new String(Math.pow(10, (x + 1 - val.length)))).substring(1);
        val = zeroPad + val;
    }
    p = val.length - x;
    d = val.substring(0, p) + '.' + val.substring(p);
    return d;
}
function popupHotelInfo(hotelCode)
{
    window.open('/online_reservation/main.php?function_id=HIF04&HotelCode=' + hotelCode,'PopupHotelInfo','height=400,width=400,innerHeight=400,innerWidth=400,toolbar=no,scrollbars=no,status=no,hotkeys=no,menubar=no,resizable=no,location=no,screenX=100,screenY=100,left=100,top=100');
}

// params is window parameter string to concat with calculated string from width, height, and isCenter
// do not put any parameter about window dimension into params, otherwise the result will depend on browser's translation
// also for isCenter is specified to true, do not put any parameter about window location
function popupWindow(strUrl, strName, width, height, isCenter, params)
{
    regexpUrl = /^\w+:\/\//;
    if ((strUrl != '') && ! regexpUrl.test(strUrl))
        strUrl = 'http://' + strUrl;
	strParam = 'width=' + width + ',height=' + height + ',innerWidth=' + width + ',innerHeight=' + height;
	if (isCenter)
	{
		x = (screen.availWidth - width) / 2;
		y = (screen.availHeight - height) / 2;
		strParam = strParam + ',screenX=' + x + ',screenY=' + y + ',left=' + x +',top=' + y;
	}
	strParam = params + ',' + strParam;
	return window.open(strUrl, strName, strParam);
}

function closeThisPopup(result)
{
    if ((typeof(window.opener.callbackClosePopup) == 'function') ||
		(typeof(window.opener.callbackClosePopup) == 'object'))			// for IE referencing across window
	    window.opener.callbackClosePopup(result);
    window.opener.focus();
    window.close();
}

function refreshOpener(strUrl)
{
	window.opener.location.replace(strUrl);
}

function printToPrinter()
{
    bV = parseInt(navigator.appVersion)
    if (bV >= 4)
        window.print();
    else
        alert('Your browser does not support printing from within web page. Click menu File > Print...');
}

function parseDelimitFloat(val)
{
	if ((typeof(val) == 'undefined') || (val == ''))
		return 0.00;
    sval = new String(val);
    sval = (sval.split(',')).join('');
    if (isNaN(sval))
        return 0.00;
    return parseFloat(sval);
}

function delimitThousand(val)
{
    val = new String(val);
    if (val.length <= 3)
        return val;
    i = val.length % 3;
    result = val.substring(0, i);
    for (; i + 3 <= val.length; i += 3) {
        result += (',' + val.substring(i, i + 3));
    }
    if ( result.substring(0,1) == ',' )
        result = result.substring(1,result.length);
    return result;
}

function getFormattedPrice(val, delimited)      // do not accept value less than zero
{
    val = (((new String(val)).split(',')).join(''));
    if (isNaN(val) || (parseDelimitFloat(val) < 0))
        return false;
    if (typeof(val) == 'number')
        val = new String(val);
    if ((p = val.indexOf('.')) >= 0) {
        if (val.length < p+3)
            val = val + '00';
        d = val.substring(0, p) + val.substring(p+1, p+3) + '.' + val.substring(p+3);
        val = new String(Math.round(d));
    } else
        val = val.concat('00');
    val = parseInt(val, 10);
    if (val == 0)
        total = '000';
    else
        total = new String(val);
    if (total.length == 2)
        total = '0'.concat(total);
    if (delimited)
        return delimitThousand(total.substring(0, total.length-2)) + '.' + total.substring(total.length-2);
    else
        return total.substring(0, total.length-2) + '.' + total.substring(total.length-2);
}

