var popupDiv, fader;

SyncAjaxHandler = new cpaint(); //ajax for MOZ+IE
SyncAjaxHandler.set_transfer_mode('post');
SyncAjaxHandler.set_async(true);
	
function ShowForm(url) {
	window.open(url, "_blank", "toolbar=yes,menubar=yes,resizable=yes,status=yes,scrollbars=yes");
}


function showPopDiv(url)
{				
	SyncAjaxHandler.call(url, "", "popup"); 
}

function toggleFadeScreen()
{
	if (fader!=null)
	{
		fader.parentNode.removeChild(fader);
		fader=null;
	}
	else
	{
		fader=document.createElement("div");
		fader.style.width=document.body.scrollWidth;
		fader.style.height=document.body.scrollHeight;
		fader.style.filter = "alpha(opacity:50)";
		fader.style.MozOpacity = 0.50;
		fader.style.opacity = 0.5;

		fader.className="fader";
		document.body.appendChild(fader);
	}
}

function popup(response)
{	
	popupDiv=document.createElement('div');
	popupDiv.id="actDiv";
	popupDiv.className="newDiv"
	popupDiv.innerHTML=response;
	
	
	setElemOpacity(0);
	
	doFading(true);
	toggleFadeScreen();	
	document.body.appendChild(popupDiv);
	
	//popup size
	popupDiv.style.left=document.body.scrollLeft+(document.body.clientWidth-popupDiv.clientWidth)/2;
	
	if (popupDiv.clientHeight>document.body.clientHeight)
		popupDiv.style.top=document.body.scrollTop;
	else
		popupDiv.style.top=document.body.scrollTop+(document.body.clientHeight-popupDiv.clientHeight)/2;
		
}

function doFading(toAppear, onFinish)
{
	currOpac=parseInt(popupDiv.getAttribute("opacity"),10);
	
	if (currOpac<=100 && currOpac>=0)
	{
		//true=open popup/ false=close popup
		(toAppear) ? setElemOpacity(currOpac+20) : setElemOpacity(currOpac-20);
		window.setTimeout('doFading('+toAppear+', "'+onFinish+'")',100)
	}
	else
	{
		(toAppear) ? setElemOpacity (100) : setElemOpacity(0);
		
		if (onFinish!=null) //if popup closed
			eval(onFinish); //run script that removeChild
	}
}


function closePopUpDiv()
{
	setElemOpacity(100);
	doFading(false, "popupDiv.parentNode.removeChild(popupDiv);toggleFadeScreen();" );
}

function setElemOpacity(opacity) {

	// IE/Win
	popupDiv.style.filter = "alpha(opacity:"+opacity+")";
	
	// Safari<1.2, Konqueror
	popupDiv.style.KHTMLOpacity = opacity/100;
	
	// Older Mozilla and Firefox
	popupDiv.style.MozOpacity = opacity/100;
	
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	popupDiv.style.opacity = opacity/100;
	
	popupDiv.setAttribute("opacity",opacity);
}

//Text-Decoration UnderLine
function TextDecorationOn(ID)
{
	document.getElementById(ID).className = "action_link_on";
}
//Text-Decoration none
function TextDecorationOff(ID)
{
	document.getElementById(ID).className = "action_link";
}

