﻿
function fadeIn4(id, steps, duration,  offsety, offsetx, width, messageID){ 

	var element = document.getElementById(id)
	var fadeInComplete;
	contentHeight();
	var myWidth = document.getElementById(messageID+"3").offsetWidth;
	var x = getAbsoluteX2(element);
	var y = getAbsoluteY2(element);
	var ImFinished = false;
	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;
	// id=messageID+"2"
	// 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"

	// need to take 1/2 the width of both the id and the message and then need to set as hidden
	id=messageID+"3";
	document.getElementById(id).style.zIndex=100;
	document.getElementById(id).style.visibility="visible"
	var myWidth = document.getElementById(messageID+"3").offsetWidth;
	if (myWidth == 0) 
	{
		myWidth = document.getElementById(id).style.width
		myWidth = parseInt(myWidth)
	}
	myWidth = (width/2) - (myWidth/2);
	x = x + myWidth;
	document.getElementById(id).style.top=y + "px"
	document.getElementById(id).style.left=x + "px"
	id=messageID
	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;             
	}

}
var finishedAnimation = true;
var finishedAnimation2 = false;
function finishAnimation()
{
	finishedAnimation = true;
	finishedAnimation2 = true;
}
function animateBodySmaller()
{
	try
	{
		var onclick = $find("aeBody")//.get_OnClickBehavior().get_animation();

		finishedAnimation = false
		finishedAnimation2 = false
		var on2 = onclick.get_OnClickBehavior()
		var on3 = on2.get_animation()
		on3.set_target("RoundedCorners2");

		on3.play();
	}
	catch(e)
	{
		setTimeout("animateBodySmaller();",300);
	}
}
function animateBodyBigger()
{
	if(finishedAnimation == true)
	{
		try
		{
			//        var onclick = $find("aeBody2")//.get_OnClickBehavior().get_animation();
			//             var on2 = onclick.get_OnClickBehavior()
			//             var on3 = on2.get_animation()
			//             //on3.set_target("RoundedCorners2");MyBody
			//             //on3.set_target("MyBody");

			//            on3.play();
			contentResize();
			//fadeOut('myLoading', 1000, 2000, .60);
		}
		catch(e)
		{
			setTimeout("animateBodyBigger();",300);
		}
	}
	else
	{
		setTimeout("animateBodyBigger();",300);
	}
}

var _popup;
var inproc = false;
//var firstLoad;

function validate(myString){
	//  find the popup behavior
	//this._popup = $find('mdlPopup');
	// show the popup
	//this._popup.show();
	
	if(finishedAnimation2 == true)
	{
		finishedAnimation2 = false
		inproc = false;
	}
	else
	{
		if(inproc != true)
		{
			animateBodySmaller();
			window.location.hash=myString;
			
			recentHash = window.location.hash;
			var myWidth = document.getElementById('tdBody').offsetWidth;
			var myHeight = document.getElementById('tdBody').offsetHeight;
			
			document.getElementById('myLoading').style.width = myWidth + "px";
			document.getElementById('myLoading').style.height = myHeight + "px";
			fadeIn4('updBody',500,500,0,0,myWidth,'myLoading');
			inproc = true;
		}
		
 //alert("nomatch3")
		setTimeout("validate('" + myString.toString() + "');",50);
		return 0; 
		
		
	}
	
	
	
	
	if(myString.indexOf("dbtn") > -1)
	{
		
		//fadeIn4('updBody',500,500,0,0,myWidth,'myLoading');
		window.scrollTo(0, 0);
		__doPostBack(myString,myString)
	}
	else if(myString.indexOf("imagebutton4") > -1)
	{
		//myString.preventDefault();
		// fadeIn4('updBody',500,500,0,0,myWidth,'myLoading');
		window.scrollTo(0, 0);
		
		__doPostBack('myPage1$imagebutton4','')
		
	}
	else if(myString.indexOf("updateInfo") > -1)
	{
		//myString.preventDefault();
		//fadeIn4('updBody',500,500,0,0,myWidth,'myLoading');
		window.scrollTo(0, 0);
		
		__doPostBack('myPage1$updateInfo','')
		
	}
	else if(myString.indexOf("myPage1$") > -1)
	{
		//myString.preventDefault();
		//fadeIn4('updBody',500,500,0,0,myWidth,'myLoading');
		window.scrollTo(0, 0);
		
		__doPostBack(myString,'')
		
	}
	else if(myString.indexOf("myPage1_") > -1)
	{
		//myString.preventDefault();
		// fadeIn4('updBody',500,500,0,0,myWidth,'myLoading');
		window.scrollTo(0, 0);
		
		__doPostBack(myString,'')
		
	}
	else if(myString.indexOf("Logout") > -1) 
	{
		
		//             myWidth = document.getElementById('container').offsetWidth;
		//             myHeight = document.getElementById('container').offsetHeight;
		//            document.getElementById('jsDisabled2').style.width = myWidth + "px";
		//            document.getElementById('jsDisabled2').style.height = myHeight + "px";
		//             fadeIn4('container',500,500,0,0,myWidth,'jsDisabled2');
		//                    var element = document.getElementById("jsDisabled2")
		//                    element.style.visibility="visible"
		//                    element.style.display = 'inline';
		//                    element.style.zoom = 1;
		//                    element.style.opacity = .60;
		//                    element.style.MozOpacity = .60;
		//                    element.style.KhtmlOpacity = .60;
		//                    element.style.filter = "alpha(opacity=" + (.60 * 100) + ");";
		//__doPostBack('dbtnLogin','')
		//fadeIn4('updBody',500,500,0,0,myWidth,'myLoading');
		window.scrollTo(0, 0);
		__doPostBack('UpdatePanel5',myString)
	}
	else
	{
		//fadeIn4('updBody',500,500,0,0,myWidth,'myLoading');
		window.scrollTo(0, 0);
		
		__doPostBack("updBody",myString)
		
	}
	
	
	//            function goHere(  )
	//            {
	//            var x4 = document.getElementById("ddlType").value
	//            var x3 = document.getElementById("ddlCondition").value
	//            var x2 = document.getElementById("ddlSearch").value
	//            var x = document.getElementById("txtSearch").value
	//            __doPostBack('Search1', x2.toString() + "&" + x3.toString() + "&" + x.toString() + "!!!" + x4.toString()); //do a postback to updatepanel1.onload which calls "UpdatePanel1_Load"
	//            }          
}
function pausecomp(millis)
{
	var date = new Date();
	var curDate = null;

	do { curDate = new Date(); }
	while(curDate-date < millis);
} 
function Finish(){
	ImFinished = true;
	setTimeout("animateBodyBigger();",300);
	//fadeOut('myLoading', 1000, 2000, .60);
	
}

function contentHeight()
{
	var theWidth, theHeight;
	// Window dimensions:
	if (window.innerWidth) {
		theWidth=window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
		theWidth=document.documentElement.clientWidth;
	}
	else if (document.body) {
		theWidth=document.body.clientWidth;
	}
	if (window.innerHeight) {
		theHeight=window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) {
		theHeight=document.documentElement.clientHeight;
	}
	else if (document.body) {
		theHeight=document.body.clientHeight;
	}
	theHeight = theHeight - 170;
	document.getElementById("myLoading").style.height = theHeight + "px";
	//theHeight = theHeight - 145;
	//document.getElementById("mainContent2").style.height = theHeight + "px";
	//theHeight = theHeight + 250;
	//document.getElementById("container").style.height = theHeight + "px";
	//theHeight = theHeight - 280;
	////document.getElementById("slider").style.height = theHeight + "px";
	//theHeight = theHeight + 265;
	//document.getElementById("Roundedcorners1").style.height = theHeight + "px";
	//theHeight = theHeight - 360;
	//document.getElementById("scrollBarOuter").style.height = theHeight + "px";
	//theHeight = theHeight - 90;
	//document.getElementById("tblLeftColumn").style.top = "-" + theHeight + "px";


	//    
	//    
	//          limitx
	//          limitx2
	//          div3x = document.getElementById('textslider');
	//          sectionsx = div3x.getElementsByTagName('div');
	//          lengthx = sectionsx.length;
	//         limitx = sectionsx[lengthx-1].offsetTop;
	//         limitx = getAbsoluteY2(div3x)
	//         limitx2 = sectionsx[lengthx-1].offsetHeight - div3x.parentNode.offsetHeight + 20;        

	//                       document.getElementById('textslider').style.width='200px';
	//                       document.getElementById('textsection-1').style.width='200px';
	//                       document.getElementById('slider').style.width='200px'; 
	//autoScroll('textslider2','textsection2',100,true)
	// return theHeight //+ "px";
	//fadeOut('myLoading', 1000, 2000, .60);
}
function contentResize()
{
	var theWidth, theHeight;
	// Window dimensions:
	if (window.innerWidth) {
		theWidth=window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
		theWidth=document.documentElement.clientWidth;
	}
	else if (document.body) {
		theWidth=document.body.clientWidth;
	}
	if (window.innerHeight) {
		theHeight=window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) {
		theHeight=document.documentElement.clientHeight;
	}
	else if (document.body) {
		theHeight=document.body.clientHeight;
	}
	
	if(jQuery.browser.safari == true || jQuery.browser.mozilla == true)
	{
		//theHeight = theHeight - 20

		//document.getElementById("leftcolumnspacer").style.width = "220px";
	}
	else
	{
		//document.getElementById("leftcolumnspacer").style.width = "220px";
	}
	//alert(theHeight)
	theHeight = theHeight + 10;
	if(jQuery.browser.safari == true || jQuery.browser.mozilla == true)
	{
	theHeight = theHeight - 50;
	//document.getElementById("tblmainContent").style.height = theHeight + "px";
	theHeight = theHeight - 0;
	}
	else
	{
	theHeight = theHeight - 50;
	//document.getElementById("tblmainContent").style.height = theHeight + "px";
	theHeight = theHeight - 0;
	}
	theHeight = theHeight - 10;
	
	theHeight = theHeight - 145;
	//document.getElementById("mainContent2").style.height = theHeight + "px";
	
	theHeight = theHeight + 105;
	document.getElementById("updBody").style.height = theHeight + "px";
	document.getElementById("tdBody").style.height = theHeight + "px";
	
	theHeight = theHeight - 105;
	theHeight = theHeight + 250;
	//AjaxControlToolkit.Animation.ResizeAnimation.play($get("container"), 0.5 , 25 ,  600, theHeight, "px");
	
	theHeight = theHeight - 250;
	AjaxControlToolkit.Animation.ResizeAnimation.play($get("slider"), 0.5 , 25 , 665, theHeight,  "px");

//!!!!!!!!!!!!!!!!!take out the top border!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
	theHeight = theHeight -10;
	//document.getElementById("slider").style.height = theHeight + "px";
	//AjaxControlToolkit.Animation.ResizeAnimation.play($get("slider"), 0.5 , 25 , theHeight,500, "px");
	
	theHeight = theHeight + 205;
	//document.getElementById("Roundedcorners1").style.height = theHeight + "px";
	theHeight = theHeight + 50;

	theHeight = (theHeight - 330)/2;
	document.getElementById("scrollBarOuter").style.height = theHeight + "px";

	theHeight = theHeight - 70;
	if(jQuery.browser.safari == true )
	{
	    //document.getElementById("chromeFix").style.height = 25 + "px";
		theHeight = theHeight - 40
	}

	//document.getElementById("mainContent2").style.top= "75px"
	var el = document.getElementById("MyBody")
	var tblmcTop
	//    if(jQuery.browser.mozilla == true)
	//    
	//    {
	//document.getElementById("mainContent2").style.top= "85px"
	
	tblmcTop = getPos(el).y
//	document.getElementById("ScrollBarCover").style.top = tblmcTop + "px";
//	document.getElementById("theScrollBar").style.top = tblmcTop + "px";
	//var el2 = document.getElementById("Roundedcorners1")
	//var tbllcTop = getPos(el2).y;
	var el3 = document.getElementById("tblLeftColumn")
	var tbllcTop2 = getPos(el3).y;
	var leftTop;
	
	
	

	if(tbllcTop2 != tblmcTop)
	{
		leftTop = tblmcTop - tbllcTop2 

		//document.getElementById("tblLeftColumn").style.top =  leftTop + "px";
	}    
	limitx
	limitx2
	div3x = document.getElementById('textslider');
	sectionsx = div3x.getElementsByTagName('div');
	lengthx = sectionsx.length;
	limitx = sectionsx[lengthx-1].offsetTop;
	limitx = getAbsoluteY2(div3x)
	limitx2 = sectionsx[lengthx-1].offsetHeight - div3x.parentNode.offsetHeight + 20;        
	//fadeOut('myLoading', 500, 1000, .60);
	//fadeOut('jsDisabled2', 500, 1000, .60); textslider textsection-1
                                
	
	//                       document.getElementById('textslider').style.width='200px';
	//                       document.getElementById('textsection-1').style.width='200px';
	//                       document.getElementById('slider').style.width='200px'; 
	//autoScroll('textslider2','textsection2',100,true)
	
	if (document.getElementById("textslider").clientHeight < document.getElementById("updBody").clientHeight-95)
	{
		theHeight = document.getElementById("scrollBarOuter").clientHeight + 150;
		document.getElementById("ScrollBarCover").style.height = theHeight + "px";

		document.getElementById("ScrollBarCover").style.visibility="visible";
		//setOpacity("ScrollBarCover", "0.5");
		var level = 0.5
		var element = document.getElementById('ScrollBarCover'); 
		//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) + ");";
	}
	else
	{
	
		document.getElementById("ScrollBarCover").style.visibility="hidden";
	}
	
	
	
	
	fadeOut('jsDisabled2', 500, 1000, .60); 
}



function loadAll()
{
	//fadeOut('jsDisabled2', 500, 1000, .60); 
	
	// removeElement("jsDisabled2")
}

function getPos(el) {
	// yay readability
	for (var lx=0, ly=0;
	el != null;
	lx += el.offsetLeft, ly += el.offsetTop, el = el.offsetParent);
	return {x: lx,y: ly};
}

//addLoadEvent(loadAll);
//addLoadEvent(contentHeight);

//set height of inner table


