
function flipDisplay(id){
    if (document.getElementById(id).style.display=="none"){
        document.getElementById(id).style.display="block";
    }
    else {
        document.getElementById(id).style.display="none";
    }
}

function arrayPos(theArray, value){
    var i=0;
    while (i<theArray.length){
        if (theArray[i]==value){
            return i;
        }
        i++;
    }
}


function getMouseX(event){
    var x;
    if ( navigator.userAgent.indexOf('MSIE') >= 0 ) {
        x = window.event.clientX + document.documentElement.scrollLeft
        + document.body.scrollLeft;
    }
    else {
        x = event.clientX + window.scrollX;
    }
    return x;
}

function getMouseY(event){
    var y;
    if ( navigator.userAgent.indexOf('MSIE') >= 0 ) {
        y = window.event.clientY + document.documentElement.scrollTop
        + document.body.scrollTop;
    }
    else {
        y = event.clientY + window.scrollY;
    }
    return y;
}

function isMouseOver(element, x,y){
    var elementx = findPosX(element);
    var elementy = findPosY(element);
    var elementx2 = elementx + element.offsetWidth;
    var elementy2 = elementy + element.offsetHeight;
    return (x >= elementx && x<=elementx2 && y >= elementy && y<=elementy2);
}

function clone (deep) {
  var objectClone = new this.constructor();
  for (var property in this)
    if (!deep)
      objectClone[property] = this[property];
    else if (typeof this[property] == 'object')
      objectClone[property] = this[property].clone(deep);
    else
      objectClone[property] = this[property];
  return objectClone;
}
Object.prototype.clone = clone;

function getSplitMinutes(mins) {
    result= (mins - (getSplitHours(mins) * 60)).toString();
        if (result.length==1){
        result="0"+result;
    }
    return result;
}

function getSplitHours(mins) {
    result= (Math.floor(mins / 60)).toString();
    if (result.length==1){
        result="0"+result;
    }
    return result;
}

function getTimeString(start,duration){
    return getSplitHours(start) + ":" + getSplitMinutes(start) + "-" + getSplitHours(start+duration) + ":" + getSplitMinutes(start+duration);
}

function getDurationString(duration){
    var hrs= (Math.floor(duration / 60));
    var mins= duration-(60*hrs);
    
    var result = "";
    
    if (hrs>1){
        result =hrs + " hours";
    }
    else if (hrs==1){
        result =hrs + " hour";
    }

    if (mins>0 && hrs>0){
        result+=" ";
    }
    
    if (mins>1){
        result +=mins + " mins";
    }
    else if (mins==1){
        result +=mins + " min";
    }
    
    return result;
}

function getWindowHeight(){
    var y;
    if (self.innerHeight) // all except Explorer
    {
        y = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
        // Explorer 6 Strict Mode
    {
        y = document.documentElement.clientHeight;
    }
    else if (document.body) // other Explorers
    {
        y = document.body.clientHeight;
    }
    return y;
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop

            
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function replaceAll( str, from, to ) {
    var idx = str.indexOf( from );


    while ( idx > -1 ) {
        str = str.replace( from, to );
        idx = str.indexOf( from );
    }

    return str;
}