/*
* Restricts the onkeypress event of the textbox with the given id to only numeric input.
* Optional 3rd, 4th and 5th arguments are the number of decimal places (0 - inf),
* and the min and max values of the textbox, respectively. To leave these
* unrestricted, either do not specify them, or specify them as "".
*/
function okpRestrictNumber(event, id) {
	var decimals='', maxval='', minval='';
	var isIE = typeof(event.which)=="undefined";
	if(typeof(arguments[2])!="undefined")
		decimals=arguments[2];
	if(typeof(arguments[3])!="undefined")
		minval=arguments[3];
	if(typeof(arguments[4])!="undefined")
		maxval=arguments[4];

	if(isIE)
		iKeyCode = event.keyCode;
	else
		iKeyCode = event.which;
	var tbox = document.getElementById(id);
	var thisval = tbox.value;

	var caretStart, caretEnd;
	if(isIE && document.selection) {
		tbox.selectionStart=Math.abs(document.selection.createRange().moveStart("character", -1000000));
		tbox.selectionEnd=Math.abs(document.selection.createRange().moveEnd("character", -1000000));
	}
	caretStart = tbox.selectionStart;
	caretEnd = tbox.selectionEnd;

	var newval = '0';
	var dec=thisval.indexOf('.');
	var neg=thisval.indexOf('-');

	if(decimals == 0) {
		if( (iKeyCode >= 32 && iKeyCode < 48 && (iKeyCode != 45 || neg != -1)) ||
				iKeyCode > 57	)
			return false;
	} else {
		if((iKeyCode >= 41 && iKeyCode < 46 && (iKeyCode != 45 || neg != -1)) ||
				iKeyCode == 47 ||
				 iKeyCode == 36 ||
				iKeyCode > 57 ||
				(iKeyCode == 46 && dec > -1 && (dec < caretStart || dec >= caretEnd)) )
			return false;
		if(decimals != '') {
			if( dec == -1 && thisval.length-caretEnd > decimals )
				return false;
			if( dec > -1 && thisval.length-dec > decimals
					&& iKeyCode >= 32 && (caretStart > dec && caretStart == caretEnd))
				return false;
		}
	}
	if(minval !== '' && minval >= 0 && iKeyCode == 45)
		return false;

	if(iKeyCode-48 >= 0)
		newval=thisval.substring(0,caretStart)+(iKeyCode-48).toString()+thisval.substring(caretEnd, thisval.length);
	if(newval == '' || !isNumeric(newval))
		newval='0';
	newval=parseFloat(newval);
	if(maxval != '') {
		if(newval > maxval)
			return false;
	}
	if(minval != '') {
		if(newval < minval && newval != '')
			return false;
	}

	return true;
}

/*
 * Returns true if inputVal is a number, false otherwise
 */
function isNumeric(inputVal) {
	oneDecimal = false;
	inputStr = inputVal.toString();
	for (var i=0; i<inputStr.length; i++) {
		var oneChar =inputStr.charAt(i);
		if(oneChar == "." && !oneDecimal) {
			oneDecimal = true;
			continue;
		}
		if (oneChar < "0" || oneChar > "9")  {
			if (oneChar != "," && oneChar != "-") {
				return false;
			}
		}
	}
	return true;
}

function registerEvent(element,evtName,evtFunc) {
   evtName = evtName.replace(/^on/,"");
   if(element.attachEvent) {
      element.attachEvent("on"+evtName,evtFunc);
   } else if(element.addEventListener) {
      element.addEventListener(evtName,evtFunc,false);
   } else {
   }
}
function findPos(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 [curleft,curtop];
}
function addEvent( obj, type, fn ) {
        if( obj.attachEvent ) {
                obj["e"+type+fn] = fn;
                obj[type+fn] = function(){obj["e"+type+fn]( window.event );}
                obj.attachEvent( "on"+type, obj[type+fn] );
        } else
                obj.addEventListener( type, fn, true );
}
var contentFixed=false;
function fixContent() {
   if(contentFixed) return;
   var ct=document.getElementById("contentTop");
   if(ct!=null) return;
   var c=document.getElementById("content");
   if(c==null) return;
   var w=document.getElementById("wrapper");
   if(w==null) return;
   ct=c;
   ct.id="contentTop";
   c=document.createElement("DIV");
   c.id="content";
   w.insertBefore(c,ct);
   w.removeChild(ct);
   c.appendChild(ct);
   var ce=document.createElement("DIV");
   ce.id="contentEnd";
   c.appendChild(ce);
   contentFixed=true;
} //function fixContent()
fixContent();
addEvent(window, 'load', fixContent);
