﻿
//The original javascript came from 
//http://www.sunburnt.com.au/publications/design/javascript-fade-effects
//I modified it to work with my code

//set the opacity of the element (between 0.0 and 1.0)  
//function findPos(obj) {
//	var curleft = curtop = 0;
//        alert(obj)
//    if (obj.offsetParent) {
//        do {
//			curleft += obj.offsetLeft;
//			curtop += obj.offsetTop;
//        } while (obj = obj.offsetParent);
//        
//        alert(curleft)
//	return [curleft,curtop];
//}
//}

     var check1 = 1;
 function getAbsoluteX2(elm) {
	var x = 0;
	if (elm && typeof elm.offsetParent != "undefined") {
	while (elm && typeof elm.offsetLeft == "number") {
	x += elm.offsetLeft;
	elm = elm.offsetParent;
	}
	}
	return x;
	}
	
	function getAbsoluteY2(elm) {
	var y = 0;
	if (elm && typeof elm.offsetParent != "undefined") {
	while (elm && typeof elm.offsetTop == "number") {
	y += elm.offsetTop;
	elm = elm.offsetParent;
	}
	}
	return y;
	}
	
	
function setOpacity(id, level) {
    var element = document.getElementById(id); 
    element.style.display = 'inline';
    element.style.zoom = 1;
    element.style.opacity = level;
    element.style.MozOpacity = level;
    element.style.KhtmlOpacity = level;
    element.style.filter = "alpha(opacity=" + (level * 100) + ");";
//    var element = document.getElementById(id + 3); 
//    if (element != null)
//    {
//        element.style.display = 'inline';
//        element.style.zoom = 1;
//        element.style.opacity = level;
//        element.style.MozOpacity = level;
//        element.style.KhtmlOpacity = level;
//        element.style.filter = "alpha(opacity=" + (level * 100) + ");";
//    }
}

function fadeIn(id, steps, duration, interval, fadeOutSteps, fadeOutDuration, offsety, offsetx, width, messageID){  
    //alert("hey")
    //I need to make the id the control where I want the popup to go, then on down make it
    //ct100_message
    //the timing is still off if you have an allert you will see the message, but I think
    //it just goes to fast, probably in miliscencs
    var element = document.getElementById(id)
    var fadeInComplete;
     var x = getAbsoluteX2(element);
//	alert(x)
	var y = getAbsoluteY2(element);
//	alert(y)
//	alert(id)
//	x=100
//	y=111
	y+=offsety
	x+=offsetx
 id=messageID
 document.getElementById(id).style.top=y + "px"
 document.getElementById(id).style.left=x + "px"
 document.getElementById(id).style.width=width + "px"//y + "px"
 document.getElementById(id).style.visibility="visible"
 document.getElementById(id).style.zIndex=100;
 
    //alert("ad")
    for (i = 0; i <= 1; i += (1 / steps)) 
    {
        if (document.getElementById(id+ "3") != null)
        {
            if (i<=.6)
            {
            setTimeout("setOpacity('" + id + "', " + i + ");setOpacity('" + id + "3', " + i + ")", i * duration); 
            }
            else
            {
            setTimeout("setOpacity('" + id + "3', " + i + ")", i * duration); 
            }
        }
        else
        {
            setTimeout("setOpacity('" + id + "', " + i + ");", i * duration); 
            if (i<=.6)
            {
            i=1
            }
        } 
        fadeInComplete = i * duration;             
    }
    //alert("ad")
    //set the timeout to start after the fade in time and the interval to display the 
    //message on the screen have both completed

    setTimeout("fadeOut('" + id + "', " + fadeOutSteps + 
               ", " + fadeOutDuration + ", 0)", fadeInComplete + interval);
}

    var fadeOutCompleteCheck=0;  

function fadeOut(id, steps, duration, start) {
    var fadeOutComplete;  
    fadeOutCompleteCheck +=1;
    for (i = 0; i <= 1; i += (1 / steps)) 
    {
        if (document.getElementById(id+ "3") != null)
        {
            if (i<=(start))
            {
            setTimeout("setOpacity('" + id + "3', " + (1 - i) + ")", i * duration); 
            }
            else
            {
            setTimeout("setOpacity('" + id + "', " + (1 - i) + ");setOpacity('" + id + "3', " + (1 - i) + ")", i * duration); 
            }
        }
        else
        {
            i=(start);
            setTimeout("setOpacity('" + id + "', " + (1 - i) + ");", i * duration); 
            
        } 
        if(fadeOutCompleteCheck==2)
        {
        fadeOutCompleteCheck=0;
        i=2;
        }
        fadeOutComplete = i * duration;             
    }    
    fadeOutCompleteCheck=0;
    //completely hide the displayed message after the fade effect is complete
    setTimeout("hide('" + id + "')", fadeOutComplete);
    if (document.getElementById( id + "3") != null)
    {
    setTimeout("hide('" + id + "3')", fadeOutComplete);
    //document.getElementById(id + "3").style.zIndex=-1;
    //setTimeout("document.getElementById(id + '3').style.zIndex=-1;", fadeOutComplete);
    }
    //setTimeout("document.getElementById(id).style.zIndex=-1;", fadeOutComplete);
}  

function hide(id){
document.getElementById(id).style.display = 'none';
    document.getElementById(id).style.zIndex=-1;
    changePage = false;
    
    if (id == "jsDisabled2")
    {
	    fadeOut('myLoading', 500, 1000, .60);
    }
}


function fadeIn2(id, steps, duration, interval, fadeOutSteps, fadeOutDuration, offsety, offsetx, width, messageID){  
           
    document.getElementById(id).style.zIndex=100;
           for (i = 0; i <= 1; i += (1 / steps)) {
          setTimeout("setOpacity('" + id + "', " + i + ")", i * duration); 
          fadeInComplete = i * duration;             
        }
}

function fadeOut2(id, steps, duration) {
    var fadeOutComplete;       
    for (i = 0; i <= 1; i += (1 / steps)) {
      setTimeout("setOpacity('" + id + "', "  + 
                (1 - i) + ")", i * duration);
      fadeOutComplete = i * duration;
    //setTimeout("document.getElementById(id).style.zIndex=-1;", i * duration);
    }    
}  

function changeText(id, txt) {
document.getElementById(id).innerHTML=txt; 
}
 function fadeIn3(id, steps, duration, interval, fadeOutSteps, fadeOutDuration, offsety, offsetx, width, messageID)
 {  
    document.getElementById(id).style.zIndex=100;
           for (i = 0; i <= 1; i += (1 / steps)) {
          setTimeout("setOpacity('" + id + "', " + i + ")", i * duration); 
          fadeInComplete = i * duration;             
        }

        setTimeout("fadeOut2('" + id + "', " + fadeOutSteps + 
                   ", " + fadeOutDuration + ")", fadeInComplete + interval);
}


