agt = navigator.userAgent.toLowerCase();
is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
is_ie5 = ( is_ie && /msie 5\.0/i.test(navigator.userAgent) );
is_ie55 = ( is_ie && /msie 5\.5/i.test(navigator.userAgent) );
is_opera = ( /opera/i.test(navigator.userAgent) );

function onErrorNew() {
}
function resizeFrame(bHorizontal, bVertical, dReferer) {
	//opera does not handle correctly resize functions, so skip it.
	if (is_opera) return;
	resizeWidth = true;
	resizeHeight = true;
	if (arguments.length > 0) {
		resizeWidth = (arguments[0] == true);
		resizeHeight = (arguments[1] == true);
	}
	window.onerror = onErrorNew;
	if (resizeWidth) {
		resizeFrameWidth();
	}

	if (dReferer=='ariva' || dReferer=='vhb' || dReferer=='cp' || dReferer=='channelpartner')
	{
		document.getElementById('iframetd').style.width=document.getElementById('wai_newsletter').width+'px';
	}
	if (resizeHeight) {
		resizeFrameHeight();
	}
	if (cnt==29)
	{
		/*try
		{alert(cnt);
			if (document.getElementById('wai_newsletter').contentWindow.document.body.clientWidth < document.getElementById('wai_newsletter').contentWindow.document.body.scrollWidth)
			{
				document.getElementById('wai_newsletter').contentWindow.document.body.clientWidth = document.getElementById('wai_newsletter').contentWindow.document.body.scrollWidth + 20;
			}
			if (document.getElementById('wai_newsletter').contentWindow.document.body.clientHeight < document.getElementById('wai_newsletter').contentWindow.document.body.scrollHeight)
			{
				document.getElementById('wai_newsletter').contentWindow.document.body.clientHeight = document.getElementById('wai_newsletter').contentWindow.document.body.scrollHeight + 220;
			}			
		}
		catch (err)
		{alert(err.description + ',' + err[0].description);
			document.getElementById('wai_newsletter').style.width = '980px';
			document.getElementById('wai_newsletter').style.height = '2000px';
		}*/
	}
	if (cnt==0)
	{
		if (isPdfInFrame())
		{
			dummyHREF = window.location.href;
			waiFrame.contentWindow.document.onreadystatechange=fnStartInit;
		}
	}
	if(cnt < 30) {
		cnt++;
		window.setTimeout("resizeFrame(" + resizeWidth + ", " + resizeHeight + ")", 300);
	}
	//alert(document.getElementById('NewsContentDiv').clientHeight + " , " + document.getElementById('wai_newsletter').contentWindow.document.body.height);
	//document.getElementById('NewsContentDiv').style.width = document.getElementById('wai_newsletter').contentWindow.document.body.width;
}

function checkResize()
{
	var hTbl = document.getElementById('HeaderMainTable');
	var moveWith = getAbsolutePos(hTbl).x;
	document.getElementById('NewsContentDiv').style.left = moveWith - 20;
}
var dummyHREF='';
function fnStartInit()
{
	var waiFrame = document.getElementById('wai_newsletter');
   if (waiFrame.document.readyState=="complete")
   {
      //window.top.location.reload();
	  window.top.location.assign = dummyHREF;
   }
}

//this function tries to resize the iframe, but not exceed the page width
function setFrameWidth(newWidth){
	if (waiFrame = document.getElementById('wai_newsletter')) {
		if ((document.body.scrollWidth - newWidth) > 20) {
			waiFrame.width = newWidth;
		} else {
			waiFrame.width = document.body.scrollWidth - 20;
		}
	}
}

//resizes the NL iframe to show it in full width
function resizeFrameWidth() {
	//alert(waiFrame.height);
	if (is_ie5) {
		//IE 5.0 does not handle correctly scrollWidth, so no resize
		return;
	}
	if (waiFrame = document.getElementById('wai_newsletter')) {
		try {
			waiFrameDoc = false;
			if (waiFrame.contentWindow) {
				if(waiFrame.contentWindow.document) {
					waiFrameDoc = waiFrame.contentWindow.document;
				}
			} else {
				if(waiFrame.document) {
					waiFrameDoc = waiFrame.document;
				}
			}
			if (!waiFrameDoc) {
				return;
			}
			if(waiFrameDoc) {
				if(waiFrameDoc.body) {
					waiFrameDoc.body.style.textAlign='left';
					width = waiFrame.width;
					scrollWidth = waiFrameDoc.body.scrollWidth;
					if ((width > 0) && (scrollWidth > 0)) {
						if (scrollWidth > width) {
							setFrameWidth(waiFrameDoc.body.scrollWidth+1);
						}
					}
				}
			}
		}
		catch (err) {
			return ;
		}
	}
}

//resizes the NL iframe to show it in full height
function resizeFrameHeight() {
	if (waiFrame = document.getElementById('wai_newsletter')) {
		try {
			waiFrameDoc = false;
			if (waiFrame.contentWindow) {
				if(waiFrame.contentWindow.document) {
					waiFrameDoc = waiFrame.contentWindow.document;
				}
			} else {
				if(waiFrame.document) {
					waiFrameDoc = waiFrame.document;
				}
			}
			if (!waiFrameDoc) {
				return;
			}

			if(waiFrameDoc) {
				if(waiFrameDoc.body) {
					height = waiFrame.height;
					scrollHeight = waiFrameDoc.body.scrollHeight;
					//alert(height + ' ' + scrollHeight);
					if ((scrollHeight > 0)) {
						if ((scrollHeight > height) || (height=='100%')) {
							waiFrame.height = waiFrameDoc.body.scrollHeight + 100; //era 10(280)inainte(Pascu Nicoleta 05.06.2007)
						}
					}

				}
			}
		}
		catch (err) {
		}
	}
}

function setTargetInFrame() {
	if (waiFrame = document.getElementById('wai_newsletter')) {
		//try {
			theHead = waiFrame.contentWindow.document.getElementsByTagName('HEAD');
			if(theHead && theHead.length) {
				theHead = theHead.item(0);
				if(theHead.base) {
					theHead.base.target= '_blank';
				} else {
					theHead.insertBefore(waiFrame.contentWindow.document.createElement('<base target="_blank">'));
				}
			}
		/*}
		catch (err) {
		}*/
	}
}


function getAbsolutePos(el) {
	var SL = 0, ST = 0;
	var is_div = /^div$/i.test(el.tagName);
	if (is_div && el.scrollLeft)
		SL = el.scrollLeft;
	if (is_div && el.scrollTop)
		ST = el.scrollTop;
	var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
	if (el.offsetParent) {
		var tmp = this.getAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}
function showAt(el, x, y) {
	var s = el.style;
	s.left = x + "px";
	s.top = y + "px";
};
function isPdfInFrame() {
	if(waiFrame = document.getElementById('wai_newsletter')) {
		try {
			waiFrameDoc = false;
			if (waiFrame.contentWindow) {
				try {
					if(waiFrame.contentWindow.document) {
						waiFrameDoc = waiFrame.contentWindow.document;
					}
				}
				catch (err) {
					waiFrameDoc = false;
				}
			} else {
				try {
					if(waiFrame.document) {
						waiFrameDoc = waiFrame.document;
					}
				}
				catch (err) {
					waiFrameDoc = false;
				}
			}
			if (!waiFrameDoc) {
				//force the iframe to go lower, as probably the script cannot acces the document's object model
				return true;
			}

			if(waiFrameDoc) {
				if(waiFrameDoc.location.href.indexOf('.pdf') > 0) {
					return true;
				}
				if(waiFrameDoc.location.href.indexOf('%2Epdf') > 0) {
					return true;
				}
			}
		}
		catch (err) {
		}
	}
	return false;
}


