﻿// JScript File

var util = {
	cacheVersion: null,
	
	getMSIEVersion: function() {
		if(util.cacheVersion != null) return util.cacheVersion;
		msv = 0;
		if(navigator.appVersion.indexOf('MSIE') > -1) {
			msv = navigator.appVersion.substr(navigator.appVersion.indexOf('MSIE')+5,10);
			msv = msv.substr(0, msv.indexOf(';'));
		}
		util.cacheVersion = msv * 1;
		return util.cacheVersion;
	},
	
	addEvent: function(object, eventName, fn) {
		if (document.addEventListener) object.addEventListener(eventName, fn, false);
		else object.attachEvent('on' + eventName, fn);
	},
	
	byId: function(id) {
		return document.getElementById(id);
	},
		
	findPos: function(obj) {
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}
		return {left:curleft,top:curtop};
	},
	
	toPrice: function(v) {
		v = (Math.round(v * 100) / 100) + '';
		if(v.indexOf('.') == -1) v = v + '.00';
		else if(v.indexOf('.') == v.length-2) v = v + '0';
		dp = v.substring(v.indexOf('.')+1);
		fp = v.substring(0, v.indexOf('.'));
		var nfp = '';
		if(fp.length > 3) {
			var c = 0;
			for(var i=fp.length-1; i>=0; i--) {
				if(c == 3) { nfp = ',' + nfp; c = 0; }
				c++;
				nfp = fp.substr(i,1) + nfp;
			}
			fp = nfp
		}
		return fp + '.' + dp;
	}
}


