function is_child_of(parent, child) {
	
	if( child != null ) {			
		while( child.parentNode ) {
			if( (child = child.parentNode) == parent ) {
				return true;
			}
		}
	}
	
	return false;
}

function fixOnMouseOut(element, event) {
	var current_mouse_target = null;
	if( event.toElement ) {				
		current_mouse_target 			 = event.toElement;
	} else if( event.relatedTarget ) {				
		current_mouse_target 			 = event.relatedTarget;
	}

	if( !is_child_of(element, current_mouse_target) && element != current_mouse_target ) {
		document.getElementById('addthis_dropdown15a').style.display='none';
	}
}

function at15B( )
{
	at15b( ); 
	at15C( ); 
	var at15o0='<div id="addthis_dropdown15a" onmouseover="addthis_clearclosewin15()" onmouseout="addthis_close()" style="z-index: 1000000; position: absolute; display: none">'; 
	at15o0+='<table width="100%" cellpadding="2" cellspacing="0" style="background-color: #EEEEEE; height: 18px">'; 
	at15o0+='<tr><td style="font-size: 12px; color: #666666; padding-left:3px"><span id="at_caption">Bookmark&nbsp;&amp;&nbsp;Share</span></td><td align="right" style="font-size: 9px; color: #666666; padding-right: 3px">'+addthis_brand+'</td></tr>';
 	at15o0+='</table>';
 	var at15O0= false; 
	at15o0+='<div id="at_share">';
 	at15o0+='<table id="addthis_services" width="100%" cellpadding="0" style="font-family: Verdana, Arial; font-size: 11px">'; 
	at15o0+='<tr><td colspan="2" style="height: 0px"></td></tr>';
	var at15m=addthis_options.split(','); 
	for (var at15P=0; at15P<at15m.length; at15P++)
	{
		var at15L=at15m[at15P]; 
		if (at15L in at15y)
		{	
			if (!at15O0)at15o0+='<tr>';

			at15o0+='\x3ctd width=\"50%\" style=\"height: 19px\">\x3ca href=\"/\" onclick=\"return addthis_sendto(\''+at15L+'\');\">\x3cimg id=\"addthis_'+at15L+'15" alt="" width="16" height="16" />&nbsp; '+at15y[at15L][0]+'</a></td>';
 			if (at15O0)at15o0+='</tr>'; 
			at15O0=!at15O0; 
		}
	}
	if (at15O0)at15o0+='<td></td></tr>';

 	at15o0+='<tr><td colspan="2" style="height: 2px"></td></tr>'; 
	at15o0+='</table>'; 
	at15o0+='\x3c/div>\n'; 
	at15o0+='<div id="at_email" style="display: none; font-size: 11px; padding-left: 20px; padding-top: 6px">'; 
	at15o0+='<table border="0">';
	at15o0+='<tr><td style="font-size: 12px">To:</td><td><input id="at_to" type="text" style="width: 130px; height: 18px; font-size: 11px; font-family: Arial; color: #999999" value=" email address" onfocus="checkto(this)" /></td</tr>';
	at15o0+='<tr><td style="font-size: 12px">From:</td><td><input id="at_from" type="text" style="width: 130px; height: 18px; font-size: 11px; font-family: Arial; color: #999999" value=" email address" onfocus="checkto(this)"/></td</tr>';
	at15o0+='<tr><td style="font-size: 12px" valign="top">Note:</td><td><textarea id="at_msg" style="width: 130px; height: 36px; font-size: 11px; font-family: Arial;"/></textarea></td</tr>';
	at15o0+='<tr><td colspan="2" align="right"><span id="at_success" style="font-size: 10px; color: #777777;"></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="Send" onclick="return addthis_send()" style="font-size: 9px"/></td</tr>'; 
	at15o0+='</table>'; 
	at15o0+='\x3c/div>\n';

 	at15o0+='<table width="100%" cellpadding="0" cellspacing="0" border="0" style="background-color: #EEEEEE">';

 	at15o0+='<tr><td colspan="2" align="right" style="padding: 0px; padding-right: 10px; height: 11px"><img id="at_img" src="'+at15Y+'select_load.png" style="width: 1px; height: 1px" /><a href="http://www.addthis.com" target="_blank" style="height: 6px; padding: 0px"><img src="'+at15o+'addthis-mini.gif" border="0" style="padding: 0px; width: 50px; height: 9px" alt="" /></a></td></tr>'; 
	at15o0+='\x3c/table>\n'; 
	at15o0+='\x3c/div>\n';
 	at15l0=document.createElement('div'); 
	at15l0.innerHTML=at15o0; 
	at15l0.style.zIndex=03641100;
}

/* Issue page code */	

	function issuePageContainersMoveRight(real_max)
	{
		issuePageValidateOfsfet(real_max);
		max=offset+4;
		min=offset-2;

		if(jQuery('#container_'+max).html() && jQuery('#container_'+min).html())
		{
            jQuery('#container_'+min).css('display','none');
            jQuery('#container_'+max).css('display','block');
			offset++; offset++;
		}
		else
		{
			max=offset+2;
			min=offset-4;
		
			if(jQuery('#container_'+max).html() && jQuery('#container_'+min).html())
			{
				jQuery('#container_'+min).css('display','none');
				jQuery('#container_'+max).css('display','block');
				offset++; offset++;
			}
		}
	} 

	function issuePageValidateOfsfet(real_max)
	{
		if(typeof(offset)=='undefined' || offset==null)
			offset=parseInt(jQuery('#pager_offset').html());

		if(parseInt(offset)==1)
			offset=3;

		if(parseInt(offset)>=real_max)
			offset=real_max-2;

		if(parseInt(offset)==real_max-3)
			offset++;
	}

	function issuePageContainersMoveLeft(real_max)
	{
		issuePageValidateOfsfet(real_max);

		max=offset+2;
		min=offset-4;

		if(jQuery('#container_'+min).html() && jQuery('#container_'+max).html())
		{
			jQuery('#container_'+min).css('display','block');
			jQuery('#container_'+max).css('display','none');
			offset--; offset--;
		}
	} 

/* report comment */
function appendReportAnchor(id)
{
	var new_a=document.createElement('a');
	new_a.innerHTML="Report this comment";
	new_a.setAttribute('onClick',"reportComment("+id+")");
	new_a.style.cursor="pointer";
	new_a.setAttribute('class','blue');
	document.getElementById('report_div_'+id).appendChild(new_a);
}

function reportComment(id)
{
	jQuery.get("/Index/ReportComment/"+id, null, function(){ 
        popup_message('This comment will be reviewed by an editor. <br/> Thanks for your feedback.');
	});
}	

function appendBlackBox(object_id)
{
	jQuery('#blackbox').remove();
	jQuery('#'+object_id).append('<div id="blackbox"></div>');
}

/* my archive */

function saveToMyArchive(type,id)
{
	jQuery.get("/MyArchive/SaveTo/"+type+"/"+id+"/", null, function(){
        popup_message('This item has been added to your archive.');
        jQuery('#save_in_my_archive_header').html('Saved in <a href="/MyArchive/">My Archive</a>.');
	});
    
    return false;
}

function openMyArchive(item)
{
	if(jQuery('#'+item+'_open').html())
	{
		jQuery('#'+item+'_open').show();
		jQuery('#'+item+'_closed').hide();
		jQuery('#'+item+'_results').show();
	}
	else alert(item);

	jQuery.get('/MyArchive/Tabs/'+item+'/Open' );
}

function closeMyArchive(item)
{
	if(jQuery('#'+item+'_open').html())
	{
		jQuery('#'+item+'_open').hide();
		jQuery('#'+item+'_closed').show();
		jQuery('#'+item+'_results').hide();
	}
	else alert(item);

	jQuery.get('/MyArchive/Tabs/'+item+'/Close');
}

/* popup */

function blackbox_fade_in(i)
{
	jQuery('embed').css('visibility','hidden');
	jQuery('object').css('visibility','hidden');
	jQuery('#blackbox').attr("onClick","popup_message_close()");
	jQuery('#blackbox').show();

	if(i<50)
	{
		blackboxOpacity(i);
		i+=3;
		setTimeout('blackbox_fade_in('+i+')',25);
	}

}

function blackboxOpacity(i)
{
	if(i>0)
	{
		ie=parseInt(i);
		im=i/100;
		ie_filter="alpha(opacity="+ie+")";
		jQuery('#blackbox').css('filter',ie_filter);
		jQuery('#blackbox').css('mozOpacity',im);
		jQuery('#blackbox').css('opacity',im);
	}
}


function blackbox_fade_out(i)
{
	if(i>0)
	{
		blackboxOpacity(i);
		i-=3;
		setTimeout('blackbox_fade_out('+i+')',25);
	}
	else
	{
		jQuery('#blackbox').hide();
		jQuery('embed').css('visibility','visible');
		jQuery('object').css('visibility','visible');
	}
}

function popup_message(text)
{
	appendBlackBox('popup_message_container');
	blackbox_fade_in(0);
	jQuery('#popup_message').show();//fadeIn('fast');
	jQuery('#popup_message').attr("onClick","popup_message_close()");
    jQuery('#popup_message').html(text);
	setTimeout('popup_message_close();',10000);
}

function popup_message_close()
{
	blackbox_fade_out(51);
	jQuery('#popup_message').fadeOut('fast');
}

// detecting & restricting browsers
function ifNotRestrictedBrowser()
{
	if(navigator.appVersion.indexOf('MSIE 6') || navigator.appVersion.indexOf('MSIE 5') )
	{
		return false;
	}
	else
	{
		return true;
	}
}

/* regions */
function highlightArticle(article)
{
	for(region in artls[article])
	{
		jQuery('#region_'+artls[article][region]).css('opacity',0.4);
		jQuery('#region_'+artls[article][region]).css('MozOpacity',0.4);
		jQuery('#region_'+artls[article][region]).css('filter','alpha(opacity=40)');
	}
	
}

function unhighlightArticle(article)
{
	for(region in artls[article])
	{
		jQuery('#region_'+artls[article][region]).css('opacity',0);
		jQuery('#region_'+artls[article][region]).css('MozOpacity',0);
		jQuery('#region_'+artls[article][region]).css('filter','alpha(opacity=0)');
	}
}

/* error reporting */
function getSelectedText()
{
	var string='';
	if (window.getSelection)
	{
		string=window.getSelection();
	}
	else if (document.getSelection)
	{
		string=document.getSelection();
	}
	else if (document.selection)
	{
		string=document.selection.createRange().text;
	}
	
	return string;
}

function processPreSubmit()
{
	document.getElementById('paragraph_text_to_send').value=document.getElementById('paragraph_text').innerHTML;
	document.getElementById('selected_text').value=getSelectedText();
}

function reportParagraphWindowClose()
{
     $('#report_paragraph').hide();
     blackbox_fade_out(51);
}


function fixOnMouseOutReport(element, event) 
{
	var current_mouse_target = null;
	if( event.toElement ) 
	{				
		current_mouse_target = event.toElement;
	} 
	else if( event.relatedTarget ) 
	{				
		current_mouse_target = event.relatedTarget;
	}

	if( !is_child_of(element, current_mouse_target) && element != current_mouse_target ) 
	{
		jQuery('#'.element).hide();
	}
}

function reportParagraphIcon(i)
{
	jQuery('#article_paragraph_report_link_'+i).show();
}

function reportParagraphIconHide(i)
{
	jQuery('#article_paragraph_report_link_'+i).hide();
}

function reportParagraphWindowOpen(page_id)
{
	appendBlackBox('report_paragraph_container');
	blackbox_fade_in(0);
	jQuery('#report_paragraph').show();
	page=jQuery('#'+page_id).html();
	jQuery('#paragraph_text').html(page);
	blackbox_fade_in(0);
	document.location.href="#report_paragraph";
}

function reportParagraphWindowClose()
{
	$('#report_paragraph').hide();
	blackbox_fade_out(51);
}

 /* article pager */

function articlePageChange(currentPage,newPage,maxPage)
{
	currentPage=parseInt(currentPage);
	newPage=parseInt(newPage);

	if(newPage<=maxPage && newPage>=1 && newPage!=currentPage)
	{
		
		swapArticles(currentPage,newPage);
		$(".article_page_link").removeClass('article_page_link');
		$("#article_page_link_"+newPage).addClass('article_page_link');
		document.location.href="#header-logo";

	}

	return newPage;
}

function swapArticles(currentPage,newPage)
{
	if(currentPage<newPage)
		var direction = 'right';
	else
		var direction = 'left';

    $('#article_page_'+currentPage).hide();
    $('#article_page_'+newPage).show();
}

function slideOutArticlePagesOnLoad(article)
{
	setTimeout("$('"+article+"').hide('slide',{direction:'right'},100)",100);
}
