//Useful functions
function findPosX(obj){
    var curleft = 0;
    if(obj.offsetParent){
		while(1) {
			curleft += obj.offsetLeft;
			if(!obj.offsetParent) break;
			obj = obj.offsetParent;
        }
	}
	else if(obj.x) curleft += obj.x;
    return curleft;
  }

function findPosY(obj){
	var curtop = 0;
	if(obj.offsetParent){
		while(1){
			curtop += obj.offsetTop;
			if(!obj.offsetParent) break;
			obj = obj.offsetParent;
		}
	}
	else if(obj.y) curtop += obj.y;
	return curtop;
}

function center(object){
	var popupW = object.getWidth();
	var popupH = object.getHeight();
	
	object.setStyle({
		top: Math.round((document.viewport.getHeight() - popupH) / 3) + 'px',
		left: Math.round((document.viewport.getWidth() - popupW) / 2) + 'px'
	});
}

function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	return [xWithScroll,yWithScroll];
}

function getWindowSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	
	return [myWidth, myHeight];
}

function isInteger (s){
  var i;

  if (isEmpty(s))
  if (isInteger.arguments.length == 1) return 0;
  else return (isInteger.arguments[1] == true);

  for (i = 0; i < s.length; i++)
  {
	 var c = s.charAt(i);

	 if (!isDigit(c)) return false;
  }

  return true;
}

function isEmpty(s){
  return ((s == null) || (s.length == 0))
}

function isDigit (c){
  return ((c >= "0") && (c <= "9"))
}

function verticalize(){
	var obj = $$('.vert');
	
	for (var i = 0; i < obj.length; i++){
		var text = obj[i].innerHTML;
		var temp = "";
		
		for (var j = 0; j < text.length; j++){
			temp += text[j] + '<br />';
		}
		
		obj[i].innerHTML = temp;
	}
}
