//*****************************************************************************
function AddEvent(oEle,EventName,FunctionCall){
	EventName=EventName.toLowerCase();
	if(window.addEventListener)
		oEle.addEventListener(EventName,FunctionCall,true);
	else if(window.attachEvent)
		oEle.attachEvent('on'+EventName,FunctionCall);
}
function RemoveEvent(oEle,EventName,FunctionCall){
	EventName=EventName.toLowerCase();
	if(window.removeEventListener)
		oEle.removeEventListener(EventName,FunctionCall,true);
	else if(window.detachEvent)
		oEle.detachEvent('on'+EventName,FunctionCall);
}
function CancelDefaultEventCascade(event){
	try{
		if(window.addEventListener){
			window.event.cancelBubble=true;
			window.event.returnValue=false;
		}
		else if(window.attachEvent)
			event.preventDefault();
	}
	catch(oErr){
	}
}
function getCursorPos(event,cursorPos){
	if(typeof(window.event)=='object'){
		cursorPos.X=window.event.clientX+document.documentElement.scrollLeft+document.body.scrollLeft;
		cursorPos.Y=window.event.clientY+document.documentElement.scrollTop+document.body.scrollTop;
	}
	else{
		cursorPos.X=event.clientX+window.scrollX;
		cursorPos.Y=event.clientY+window.scrollY;
	}
}
var oDrag=new Object();
oDrag.zIndex=100;
function dragInit(event,id,boundId) {
	oDrag.Ele=document.getElementById(id);

	oDrag.BoundaryExist=(boundId==''||typeof(boundId)=='undefined'||boundId==null)?false:true;
try{

	if(oDrag.BoundaryExist){
		oDrag.EleBound=document.getElementById(boundId);
		oDrag.boundTop=parseInt(oDrag.EleBound.offsetTop);
		oDrag.boundLeft=parseInt(oDrag.EleBound.offsetLeft);
		oDrag.boundRight=oDrag.boundLeft+parseInt(oDrag.EleBound.width,10);
		oDrag.boundBottom=oDrag.boundTop+parseInt(oDrag.EleBound.height,10);
	}
}
catch(oErr){
	alert('error')
}


	// Get cursor position with respect to the page.
	oDrag.cursorPos={X:0,Y:0};
	getCursorPos(event,oDrag.cursorPos);

	// Save starting positions of cursor and element.
	oDrag.cursorInitPosX=oDrag.cursorPos.X;
	oDrag.cursorInitPosY=oDrag.cursorPos.Y;
	oDrag.eleInitLeft=parseInt(oDrag.Ele.style.left,10);
	oDrag.eleInitTop=parseInt(oDrag.Ele.style.top,10);

	if(isNaN(oDrag.eleInitLeft))oDrag.eleInitLeft=0;
	if(isNaN(oDrag.eleInitTop))oDrag.eleInitTop=0;

	// Update element's z-index.
	oDrag.Ele.style.zIndex=oDrag.zIndex++;
	oDrag.Width=parseInt(oDrag.Ele.style.width,10)
	oDrag.Height=parseInt(oDrag.Ele.style.height,10)

  // Capture mousemove and mouseup events on the page.
  AddEvent(document,'mousemove',dragStart);
  AddEvent(document,'mouseup',dragStop);
  CancelDefaultEventCascade(event);
}
function dragStart(event){
	// Get cursor position with respect to the page.
	getCursorPos(event,oDrag.cursorPos);

	var dragLeft=(oDrag.eleInitLeft+oDrag.cursorPos.X-oDrag.cursorInitPosX)
	var dragTop=(oDrag.eleInitTop+oDrag.cursorPos.Y-oDrag.cursorInitPosY)
	var dragRight=dragLeft+oDrag.Width;
	var dragBottom=dragTop+oDrag.Height;
	if(dragLeft<oDrag.boundLeft){
		oDrag.Ele.style.left=oDrag.boundLeft+"px";
		return;
	}
	if(dragTop<oDrag.boundTop){
		oDrag.Ele.style.top=oDrag.boundTop+"px";
		return;
	}
	if(dragRight>oDrag.boundRight){
		oDrag.Ele.style.left=oDrag.boundRight-oDrag.Width+"px";
		return;
	}
	if(dragBottom>oDrag.boundBottom){
		oDrag.Ele.style.top=oDrag.boundBottom-oDrag.Height+"px";
		return;
	}
	// Move drag element by the same amount the cursor has moved.
	oDrag.Ele.style.left=(oDrag.eleInitLeft+oDrag.cursorPos.X-oDrag.cursorInitPosX)+"px";
	oDrag.Ele.style.top=(oDrag.eleInitTop+oDrag.cursorPos.Y-oDrag.cursorInitPosY)+"px";

	CancelDefaultEventCascade(event);
}
function dragStop(event) {
	// Stop capturing mousemove and mouseup events.
	RemoveEvent(document,'mousemove',dragStart);
	RemoveEvent(document,'mouseup',dragStop);
}
// ##########################################################
function showDiv(event,Id){
	var cursorPos={X:0,Y:0};
	getCursorPos(event,cursorPos);
	var oEle=document.getElementById(Id);
	oEle.style.display='block';
	oEle.style.top=cursorPos.Y-(parseInt(oEle.offsetHeight)/2)+'px';
	oEle.style.left=cursorPos.X-parseInt(oEle.offsetWidth)+'px';
	oEle.style.zIndex='100';
}
// ##########################################################
function OpenPrintWindow(ToPrintEleId,PrintTitle){
	var PrintWin = window.open("","PrintWin","width=620,height=650,resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=yes,copyhistory=no");
	if (PrintWin) {
		PrintWin.focus();
	} else {
		alert("Please turn off your PopUp blocking software");
		return;
	}
	if(typeof(PrintTitle)=='undefined'){PrintTitle='Print Version'}
	var PrintHTML=document.getElementById(ToPrintEleId).innerHTML;
	var PrintPopUpHtml=gPrintPopUpHtml.replace('PRINT_CONTENT_HERE',PrintHTML).replace('PRINT_TITLE_HERE',PrintTitle);
	PrintWin.document.body.innerHTML = '';
	PrintWin.document.open();
	PrintWin.document.write(PrintPopUpHtml);
	PrintWin.document.close();
}
var gPrintPopUpHtml = new String("\
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>\
<html>\
<head>\
<style type='text/css'>.printversionnodipslay{display:none;}</style>\
<style type='text/css' media='print'>.printversionnodipslay,.noprint{display:none;}</style>\
<link type='text/css' rel='stylesheet' href='<%=RootPath%>styles/amcmain.css_'></link>\
<title>PRINT_TITLE_HERE</title>\
</head>\
<body>\
PRINT_CONTENT_HERE\
<div class='noprint' style='float:right;margin-right:15px;margin-top:30px;font-size:80%;font-family:verdana, arial;'>\
<a href='#' onclick='window.print();return false;'>print</a> | <a href='#' onclick='window.close();return false;'>close</a>\
</div>\
</body>\
</html>");
// ##########################################################


function initImgCycle(ImgCycle,ImgCycleContainerId){
	var oImgCycle=eval(ImgCycle);
	if(typeof(oImgCycle.LoopInterval)!='number')oImgCycleLoop.LoopInterval=4000;
	if(typeof(oImgCycle.TransitionInterval)!='number')oImgCycleLoop.TransitionInterval=25;
	if(typeof(oImgCycle.TransitionIncrement)!='number')oImgCycleLoop.TransitionIncrement=2;//set between 1 and 100

	oImgCycle.Container=document.getElementById(oImgCycleLoop.ContainerId);
	oImgCycle.Imgs=oImgCycle.Container.getElementsByTagName('IMG');
	oImgCycle.ImgCnt=oImgCycle.Imgs.length;
	if(!oImgCycle.ImgCnt>1){
		return false;
	}
	oImgCycle.DisplayCurrent=0;
	oImgCycle.DisplayNext=((oImgCycle.DisplayCurrent+1)>=oImgCycle.ImgCnt)?0:oImgCycle.DisplayCurrent+1;
	oImgCycle.DisplayPrev=oImgCycle.ImgCnt-1;
	oImgCycle.Imgs[oImgCycle.DisplayCurrent].style.display='block';

	if(oImgCycle.Imgs[oImgCycle.DisplayCurrent].nextSibling.nodeName=='SPAN'){
		oImgCycle.LoopInterval=parseInt(oImgCycle.Imgs[oImgCycle.DisplayCurrent].nextSibling.innerHTML,10);
	}
	oImgCycle.Loop=window.setTimeout("ImgCycleLoop('"+ImgCycle+"')",oImgCycle.LoopInterval);
}
function ImgCycleLoop(ImgCycle){
	var oImgCycle=eval(ImgCycle);
	if(typeof(oImgCycle.Transition)=='number'){
		oImgCycle.DisplayPrev=oImgCycle.DisplayCurrent;
		oImgCycle.DisplayCurrent=oImgCycle.DisplayNext;
		oImgCycle.DisplayNext=((oImgCycle.DisplayCurrent+1)>=oImgCycle.ImgCnt)?0:oImgCycle.DisplayCurrent+1;
	}
	for(var i=0;oImgCycle.Imgs[i];i++){
		if(i==oImgCycle.DisplayCurrent){
			oImgCycle.Imgs[i].style.display='block';
			oImgCycle.Imgs[i].style.zIndex=8;
		}
		else if(i==oImgCycle.DisplayNext){
			oImgCycle.Imgs[i].style.display='block';
			oImgCycle.Imgs[i].style.zIndex=7;
		}
		else{
			oImgCycle.Imgs[i].style.display='none';
		}
	}
	oImgCycle.FadeAmt=0;
	oImgCycle.Transition=window.setTimeout("ImgTrasition('"+ImgCycle+"')",oImgCycle.TransitionInterval);

	if(oImgCycle.Imgs[oImgCycle.DisplayNext].nextSibling.nodeName=='SPAN'){
		oImgCycle.LoopInterval=parseInt(oImgCycle.Imgs[oImgCycle.DisplayNext].nextSibling.innerHTML,10);
	}
	oImgCycle.Loop=window.setTimeout("ImgCycleLoop('"+ImgCycle+"')",oImgCycle.LoopInterval);
}
function ImgTrasition(ImgCycle){
	var oImgCycle=eval(ImgCycle);
	
	var ImgCurrentStyle=oImgCycle.Imgs[oImgCycle.DisplayCurrent].style;
	var ImgNextStyle=oImgCycle.Imgs[oImgCycle.DisplayNext].style;

	ImgNextStyle.opacity=(oImgCycle.FadeAmt/100);
	ImgNextStyle.MozOpacity=(oImgCycle.FadeAmt/100);
	ImgNextStyle.KhtmlOpacity = (oImgCycle.FadeAmt/100);
	ImgNextStyle.filter='alpha(opacity='+oImgCycle.FadeAmt+')';

	ImgCurrentStyle.opacity=((100-oImgCycle.FadeAmt)/100);
	ImgCurrentStyle.MozOpacity=((100-oImgCycle.FadeAmt)/100);
	ImgCurrentStyle.KhtmlOpacity=((100-oImgCycle.FadeAmt)/100);
	ImgCurrentStyle.filter='alpha(opacity='+(100-oImgCycle.FadeAmt)+')';

	if(oImgCycle.FadeAmt>=100){
		window.clearInterval(oImgCycle.Transition);
	}
	else{
		oImgCycle.FadeAmt=oImgCycle.FadeAmt+oImgCycle.TransitionIncrement;
		oImgCycle.Transition=window.setTimeout("ImgTrasition('"+ImgCycle+"')",oImgCycle.TransitionInterval);
	}
}






// ##########################################################
function OpenImgWindow(ImgScr){
	var ImgWin = window.open("","ImgWin","width=1024,height=800,resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=yes,copyhistory=no");
	if (ImgWin) {
		ImgWin.focus();
	} else {
		alert("Please turn off your PopUp blocking software");
		return;
	}
	var ImgHTML='<img src="'+ImgScr+'"/>';
	var ImgPopUpHtml;
	ImgPopUpHtml=gImgPopUpHtml.replace('IMG_HERE',ImgHTML);
	ImgWin.document.body.innerHTML = '';
	ImgWin.document.open();
	ImgWin.document.write(ImgPopUpHtml);
	ImgWin.document.close();
}
var gImgPopUpHtml = new String("\
<html>\
<head>\
<title>Image</title>\
</head>\
<body>\
<div style='margin-bottom:3px;font-size:x-small;'><a href='#' onclick='window.close();return false;'>CLOSE</a></div>\
IMG_HERE\
<div style='margin-top:3px;font-size:x-small;'><a href='#' onclick='window.close();return false;'>CLOSE</a></div>\
</body>\
</html>");
// ##########################################################
