var iframeids=[]
var childWindows=[]
var iframehide="yes"
var FFextraHeight=0

function resizeCaller() {
	var dyniframe=new Array()
	for (i=0; i<iframeids.length; i++){
		if (document.getElementById){
			resizeIframe(iframeids[i])
		}
		if ((document.all || document.getElementById) && iframehide=="no"){
			var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
			tempobj.style.display="block";
		}
	}
	var script_area = getElement("LPscript");
	if (script_area)
	{
		script_area.innerHTML = "<script language='javascript' src='https://server.iad.liveperson.net/hc/47547643/x.js?cmd=file&file=chatScript3&site=47547643&&category=en;woman;5'></script>";
	}
	//
	// UGP2 : to solve issue with iframe under atlas update pannel behaviour
	//
	if (window != window.top){
		try{
			window.parent.resizeCaller();
		} catch(e){
		}
	}
}

function resizeIframe(frameid){
	var currentfr=document.getElementById(frameid)
		if (currentfr && !window.opera){
			currentfr.style.display="block"
			if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight){ //ns6 syntax
				if (currentfr.contentDocument.body.offsetWidth<1134)
			    {
					currentfr.width = 1134;
			    } else 
				{
					currentfr.width = currentfr.contentDocument.body.offsetWidth;
				}
				currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight;
			}
			else if (currentfr.Document && currentfr.Document.body.scrollHeight){ //ie5+ syntax
				if (currentfr.Document.body.scrollWidth<993)
			    {
					currentfr.width = 993;
			    } else 
				{
					currentfr.width = currentfr.Document.body.scrollWidth;
				}
				currentfr.height = currentfr.Document.body.scrollHeight;
			}
			if (currentfr.addEventListener){
				currentfr.addEventListener("load", readjustIframe, false)
			}
			else if (currentfr.attachEvent){				
				currentfr.detachEvent("onload", readjustIframe) 
				currentfr.attachEvent("onload", readjustIframe)				
			}
			
			if(window!=window.parent) {
				alert("INNER-BUG: iframe within iframe!");
			}

		}
}

function readjustIframe(loadevt) {
	var crossevt=(window.event)? event : loadevt
	var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
	if (iframeroot){
		resizeIframe(iframeroot.id);
	}
}

function loadintoIframe(iframeid, url){
	if (document.getElementById)
		document.getElementById(iframeid).src=url
}

if (window.addEventListener)
	window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent){
	window.attachEvent("onload", resizeCaller)
}
	else
		window.onload=resizeCaller

function AddIFrame(name,mrg,showMessage) {
	if (!alreadyInArray("list",iframeids))  {
		iframeids[iframeids.length]= name;	
	}
	if (showMessage == null || showMessage == true) 	{
		ShowLoadingDiv(name,mrg);

	}

}

function ShowLoadingDiv(name,mrg) {
	var iframe_div	= GetIFrameDiv(name);
	if (iframe_div == null)
		document.write("<DIV class='LoadingDiv' style='margin-bottom:"+mrg+"px' id='iframe_"+name+"_preload'>Loading...</DIV>");
	else iframe_div.style.display="block";
}

function HideLoadingDiv(name) {
	var iframe_div	= GetIFrameDiv(name);
	if (iframe_div != null)
		iframe_div.style.display="none";
}

function IFrameLoadStarted(name) {
	var iframe_div	= GetIFrameDiv(name);
	if (iframe_div != null)
		iframe_div.style.display="block";
}

function IFrameLoadFinished(name) {
	HideLoadingDiv(name);
}

function GetIFrameDiv(name) {
	  var iframe_div = document.getElementById("iframe_"+name+"_preload");				
	  return iframe_div;
}
 
 function RefreshIFrame(name,src)		{		
		if (src==null)
			frames[name].location.reload();
		else 
			frames[name].location.href = src;
}


///Child windows framework
var childWindows=[]
if (window.addEventListener)
	window.addEventListener("load", registerWindow, false)
else if (window.attachEvent){
	window.attachEvent("onload",registerWindow)
}
if (window.addEventListener)
	window.addEventListener("unload", unregisterWindow, false)
else if (window.attachEvent){
	window.attachEvent("onunload",unregisterWindow)
}

function registerWindow() {
	if (window.opener != null)
		window.opener.addChildWindow(window);
}

function addChildWindow(win)	{
	if (!alreadyInArray(win,childWindows))  {
		childWindows[childWindows.length]= win;			
	} else {
		for (i=0;i<childWindows.length ;i++ ) 
			if (childWindows[i]!=null)
				if (win.name==childWindows[i].name) childWindows[i]=win;
	}
}

function getChildWindow(name)	{
	for (i=0;i<childWindows.length ;i++ )
		if (childWindows[i]!=null)
			if (name==childWindows[i].name) return childWindows[i];
	return null;
}

function redirectChildWindow(name, url)	{
	var win = getChildWindow(name);
	if (win!=null)
		win.location.href=url;
}

function unregisterWindow() {
	if (window.opener != null)
		window.opener.removeChildWindow(window);
}

function removeChildWindow(win)	{
	for (i=0;i<childWindows.length ;i++ )  {
			if (childWindows[i]!=null)
				if (win.name==childWindows[i].name) childWindows[i]= null;	
	}
}

function switchView(div,frame,src) {	
	if (document.getElementById(frame)!=null && document.getElementById(frame).getElementsByTagName("IFRAME")[0]!=null) {		
		var startingHeight=document.getElementById(div).scrollHeight;

		document.getElementById(div).innerHTML="";
		document.getElementById(div).style.display="none";		
		document.getElementById(frame).getElementsByTagName("IFRAME")[0].src = src;
		document.getElementById(frame).getElementsByTagName("IFRAME")[0].height = startingHeight;	
		document.getElementById(frame).style.display="block";				

	} else {
		location.href = src;				
	}
}