<!--//<![CDATA[

function initActivateLinks()
{
	var links = document.getElementsByTagName("a");
	for(var i=0; i<links.length; i++)
	{
		if(links[i].href && links[i].rel == "external")
		{
			links[i].onclick = function () {window.open(this.href);return false;};
		}
		if(links[i].href && links[i].rel == "parent")
		{
			links[i].onclick = function () {parent.window.location.href = this.href;return false;};
		}
	}
}	

function hideDiv(divId)
{
	var d = document.getElementById(divId);
	if(!d) return;
	if(d.style.display != "none")
		d.style.display = "none";
}
	
function showDiv(divId)
{
	var parentDiv = document.getElementById(divId);
	parentDiv = parentDiv.parentNode;
	while(parentDiv.nodeName != "DIV")
		parentDiv = parentDiv.parentNode;
	var off = getXYOffset(parentDiv);
	var d = document.getElementById(divId);
	d.style.top = off.top+"px";
	if(!d) return;
	if(d.style.display != "block")
	{
		d.style.display = "block";
	}
}

function afaqsSearch()
{
	var obj = document.getElementById("sbox");
	var obj1 = document.getElementById("slist");
	if(obj1.className == "hideslist")
	{
		obj.childNodes[0].src = "/site_images/sboxup.gif";
		obj1.className = "showslist";
	}
	else
	{
		obj.childNodes[0].src = "/site_images/sboxdown.gif";
		obj1.className = "hideslist";
	}
}

function getEventObject(e)
{
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3)
		targ = targ.parentNode;
	return targ;
}

function changeCssClass(eId, className)
{
	var obj = document.getElementById(eId);
	obj.className = className;
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}

function showrightads()
{
		var ww = f_clientWidth();
		if (document.getElementById && ww > 0)
		{
			var mysky = document.getElementById('skyscraper');
			var ff = document.getElementById('np');
			(ww > 1000)?(mysky.style.display = "block"):(mysky.style.display = "none");
			(ww > 1220)?(ff.style.display = "block"):(ff.style.display = "none");
		}
}

// article tools

function setTextSize(e)
{
	var targId = getEventObject(e);
	var fSize = parseInt(document.getElementById("newsstory").style.fontSize);
	if(targId.id == "txtplus")
	{
		if(fSize>=16)
			return false;
		if(document.getElementById("newsstory").style.fontSize == "")
			document.getElementById("newsstory").style.fontSize = "14px";
		else
			document.getElementById("newsstory").style.fontSize = fSize+2+"px";
	}
	else if(targId.id == "txtminus")
	{
		if(fSize<=10)
			return false;
		if(document.getElementById("newsstory").style.fontSize == "")
			document.getElementById("newsstory").style.fontSize = "10px";
		else
			document.getElementById("newsstory").style.fontSize = fSize-2+"px";
	}
	return false;
}

function changeClass(e, cls)
{
	for(var i=0; i<e.childNodes.length; i++)
	{
		var node = e.childNodes[i];
		node.className = cls;
	}
}

function changeDataClass(e, cls)
{
	for(var i=0; i<e.childNodes.length; i++)
	{
		var node = e.childNodes[i];
		if(node.nodeName =="DIV")
		{
			node.className = cls;
		}
	}
}

function handleTab(e)
{
	changeClass(document.getElementById("nsBtnTabContainer"), "dtab");
	changeDataClass(document.getElementById("tc2"), "tcd2inactive");
	var targ = getEventObject(e);
	while(targ.nodeName != "LI")
		targ = targ.parentNode;
	targ.className = "atab";
	var aTabId = parseInt(targ.id.substr(targ.id.length-1,1));
	var e = document.getElementById("tcd2"+aTabId);
	e.className = "tcd2active";
	var bc = document.getElementById("nsBtnTabContainer");
	if(aTabId == 1 || aTabId == 2)
		document.getElementById("tb"+3).style.borderRight = "none";
	//if(aTabId == 3)
//		document.getElementById("tb"+3).style.borderRight = "1px solid #a1a1a1";
	return false;
}

function handlePS(e)
{
	var targ = getEventObject(e);
	while(targ.nodeName != "DIV")
		targ = targ.parentNode;
	if(targ.id == "spliton")
	{
		document.getElementById("newsstory").className = "nstory";
		this.style.display = "none";
		document.getElementById("splitoff").style.display = "block";
	}
	else if(targ.id == "splitoff")
	{
		document.getElementById("newsstory").className = "nstory1";
		this.style.display = "none";
		document.getElementById("spliton").style.display = "block";
	}
	return false;
}

function printThisStory()
{
	javascript:window.print()
}

function createXMLHTTPObject() {
  var XMLHttpFactories = [
    function () {return new XMLHttpRequest()},
    function () {return new ActiveXObject("Msxml2.XMLHTTP")},
    function () {return new ActiveXObject("Msxml3.XMLHTTP")},
    function () {return new ActiveXObject("Microsoft.XMLHTTP")}
	];
	var xmlhttp = false;
   for (var i=0;i<XMLHttpFactories.length;i++) {
           try{
                  xmlhttp = XMLHttpFactories[i]();
          }
          catch (e) {
                  continue;
          }
          break;
    }
    return xmlhttp;
}

function submitForm()
{
	var xhr = createXMLHTTPObject();
	if(xhr)
	{
		var poststr = "headline=" + encodeURI(document.getElementById('subject').value) + "&toemail=" + encodeURI(document.getElementById("toemail").value) + "&fromname=" + encodeURI(document.getElementById("fromname").value) + "&fromemail=" + encodeURI(document.getElementById("fromemail").value) + "&message=" + encodeURI(document.getElementById("message").value) + "&mlink=" + encodeURI(document.getElementById('mlink').value);
		xhr.open("POST", "/perl/news/maillink.html", true);
		xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xhr.setRequestHeader('Content-length', poststr.length);
		xhr.setRequestHeader('Connection', 'close');
		xhr.onreadystatechange = function()
		{
			if (xhr.readyState == 4) {
        		if (xhr.status == 200)
				{
           			result = xhr.responseText;
            		document.getElementById('mailform').innerHTML = result; 
					document.getElementById("rta").onclick = removeMtp;
         		}
			}
		}
		xhr.send(poststr);
	}
	return false;
}

function remove_text()
{
	if(this.value!="" && (this.value == '[Enter your name]' || this.value == '[Enter your email address]' || this.value == '[Recipient Email(s)]'))
		this.value="";
}

function add_name()
{
	if(this.value =="")
		this.value="[Enter your name]";
}

function add_email()
{
	if(this.value =="")
		this.value="[Enter your email address]";
}

function add_remail()
{
	if(this.value =="")
		this.value="[Recipient Email(s)]";
}

function removeMtp()
{
	var m = document.getElementById("mailwrapper");
	document.body.removeChild(m);
	return false;
}

function mailThisPage()
{
	if(!document.createElement && !document.getElementById) return;
	var mtp = document.createElement("DIV");
	mtp.setAttribute("id", "mailwrapper");
	mtp.innerHTML = '<div id="bluestrip"><a id="mtpclose" href="#">Close [X]</a></div><div id="mailtop"><img src="http://www.afaqs.com/grfx/logosmall.gif" alt="afaqs" width="131" height="51" /></div><div id="mailform"><span id="headline" class="topheadline"></span><form><label for="toemail">To:</label><input type="text" id="toemail" name="toemail" value="[Recipient Email(s)]"/><br /><small>Separate multiple addresses with commas.</small><br /><br><label for="fromname">From:</label><input type="text" id="fromname" name="fromname" value="[Enter your name]"/><br /><br /><label for="fromemail">&nbsp;</label><input type="text" id="fromemail" name="fromemail" value="[Enter your email address]"/><br /><br /><small><strong>If you would like to include a message, type it here:</strong></small><label for="message">&nbsp;</label><textarea id="message" name="message" class="msgbox"></textarea><br /><input type="hidden" id="mlink" name="mlink" value="" /><input type="hidden" id="subject" name="subject" value="" /><button type="submit" id="send" name="send">Send</button></form></div>';
	document.body.appendChild(mtp);
	var u = document.URL;
	document.getElementById('mlink').value = document.URL;
	var xhr = createXMLHTTPObject();
	if(xhr)
	{
		xhr.open("GET", "/perl/news/maillink.html?value="+1+"&url="+u, true);
		xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xhr.setRequestHeader('Content-length', u.length);
		xhr.setRequestHeader('Connection', 'close');
		xhr.onreadystatechange = function()
		{
			if (xhr.readyState == 4) {
        		if (xhr.status == 200)
				{
					document.getElementById('headline').innerHTML = document.getElementById('subject').value = xhr.responseText;
         		}
			}
		}
	xhr.send(null);
	}

	document.getElementById("send").onclick = submitForm;	
	document.getElementById("mtpclose").onclick = removeMtp;
	document.getElementById("fromname").onfocus = remove_text;
	document.getElementById("fromemail").onfocus = remove_text;
	document.getElementById("toemail").onfocus = remove_text;
	document.getElementById("fromname").onblur = add_name;
	document.getElementById("fromemail").onblur = add_email;
	document.getElementById("toemail").onblur = add_remail;
	return false;
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function showFloater()
{
	if(document.getElementById)
	{
		var x = readCookie('floater');
		if(!x)
		{
			createCookie('floater', 'flNews', 0);
			var fl = document.getElementById("floater");
			fl.style.display = "block";
		}
	}
}

//menu bar js
var mmArray = new Array();
	var smArray = new Array();
	var whichMenu;
	var timeout;
	
	function $_(id)
	{
		if(document.getElementById(id))
			return document.getElementById(id);
		else
			return false;
	}
	
	function extractNodes(pnode, nodeName)
	{
		var elArr = new Array();
		for(var i=0, j=0; i<pnode.childNodes.length; i++)
		{
			if(pnode.childNodes[i].nodeName == nodeName)
				elArr[j++] = pnode.childNodes[i];
		}
		return(elArr);
	}
	
	function getXYOffset(what) {
		var totalOffset = new Object();
		totalOffset.left = what.offsetLeft;
		totalOffset.top = what.offsetTop;
		var parentEl = what.offsetParent;
		while (parentEl!=null){
			totalOffset.left = totalOffset.left+parentEl.offsetLeft;
			totalOffset.top = totalOffset.top+parentEl.offsetTop;
			parentEl = parentEl.offsetParent;
		}
		return totalOffset;
	}
	
	function showSubMenu()
	{
		if(whichMenu)
		{
			clearTimeout(timeout);
			hidesubMenu();
		}
		var count = parseInt(this.id.substr(2, this.id.length));
		whichMenu = smArray[count];
		whichMenu.style.visibility = "visible";
		if($_("iframeshim"))
		{
			offSetX = whichMenu.style.left;
			offSetY = whichMenu.style.top;
			shimobject = $_("iframeshim");
			shimobject.style.left = offSetX;
			shimobject.style.top = offSetY;
			shimobject.style.width = whichMenu.offsetWidth+"px";
			shimobject.style.height = whichMenu.offsetHeight+"px";
			shimobject.style.display = "block";
		}
	}
	
	function clearSubMenu() 
	{
		timeout = setTimeout("hidesubMenu()", 500);
	}
	
	function cancelClearMenu()
	{
		clearTimeout(timeout);
	}
	
	function hidesubMenu()
	{
		if(whichMenu)
			whichMenu.style.visibility = "hidden";
		if($_("iframeshim"))
		{
			shimobject = $_("iframeshim");
			shimobject.style.display = "none";
		}
	}

function addRollover(pdid, did, cssClassName, src, width, height)
{
	var myDiv = document.createElement("DIV");
	myDiv.setAttribute("id", did);
	myDiv.className = cssClassName;
	myDiv.innerHTML = "<object type='application/x-shockwave-flash' data='"+src+"' width='"+width+"' height='"+height+"'><param name='movie' value='"+src+"' /><param name='quality' value='high' /><param name='allowscriptAccess' value='always' /><param name='wmode' value='transparent' /></object>";
	var parentDiv = document.getElementById(pdid);
	var off = getXYOffset(parentDiv);
	myDiv.style.top = off.top+"px";
	parentDiv.appendChild(myDiv);
}

function init(pageId)
{
	var W3CDOM = document.createElement && document.getElementById;
	if(!W3CDOM) return;
	//init drop down menu
	var browser = navigator.appName;
		var el = $_("mainmenu");
		for(var i=0; i<el.childNodes.length; i++)
		{
			if(el.childNodes[i].nodeName == "UL")
			{
				el = el.childNodes[i];
				break;
			}
		}
		mmArray = extractNodes(el, "LI");
		smArray = extractNodes($_("submenu"), "DIV");
		for(var i=0; i<mmArray.length; i++)
		{
			mmArray[i].id = "mm"+i;
			var offset = getXYOffset(mmArray[i]);
			smArray[i].style.left = offset.left+"px";
			smArray[i].style.top = offset.top+mmArray[i].offsetHeight+"px";
			mmArray[i].onmouseover = showSubMenu;
			mmArray[i].onmouseout = clearSubMenu;
			smArray[i].onmouseover = cancelClearMenu;
			smArray[i].onmouseout = clearSubMenu;
		}
		document.onclick = function() {
			clearTimeout(timeout);
			hidesubMenu();
		}
		if(browser == "Microsoft Internet Explorer")
		{
			document.write('<IFRAME id="iframeshim" src="about:blank" frameBorder="0" scrolling="no" style="position:absolute; display:none;z-index:999; background: transparent;"></IFRAME>');
		}
	initActivateLinks();
	var e = document.getElementById("sbox");
	if(e){	e.onclick = afaqsSearch;}
	document.getElementById("mtp").onclick = mailThisPage;
	showrightads();
	window.onresize = showrightads;
	if(pageId == "newsIndex")
	{
		//
	}
	if(pageId == "newsInside")
	{
		if(document.getElementById("txtminus"))
			document.getElementById("txtminus").onclick = document.getElementById("txtplus").onclick = setTextSize;
		if(document.getElementById("nsBtnTabContainer"))
		document.getElementById("nsBtnTabContainer").onclick = handleTab;
		if(document.getElementById("pts"))
			document.getElementById("pts").onclick = printThisStory;
		if(document.getElementById("spliton"))
			document.getElementById("spliton").onclick= document.getElementById("splitoff").onclick =handlePS;
	}
}

function initSplitter(pState)
{
	if(pState == false)
	{
		document.getElementById("newsstory").className = "nstory";
		document.getElementById("splitoff").style.display = "none";
		document.getElementById("spliton").style.display = "none";
		document.getElementById("psplit").style.paddingTop = "4px";	
	}
}

//]]>-->