var currentTimeline=0;
var currentChart=0;
var issueRequest;
var legalAgreed=false;
function init(){
	try{
		if(/MSIE/.test(navigator.userAgent)){
			var content=document.getElementById('content');
			var cols=document.getElementById('columns');
			var timeline=document.getElementById('timeline');
			if(timeline || 1){
				var br=document.createElement('BR');
				br.style.clear='both';
				cols.insertBefore(br,timeline);
			}
			var rc1=document.createElement('DIV');
			rc1.className="rounded_colhead";
			content.insertBefore(rc1, content.firstChild);
			var d1l=document.createElement('DIV');
			d1l.className='tl';
			rc1.appendChild(d1l);
			d1l.appendChild(document.createTextNode('\xA0'));
			var d1r=document.createElement('DIV');
			d1r.className='tr';
			rc1.appendChild(d1r);
			var rc2=document.createElement('DIV');
			rc2.className="rounded_colhead";
			cols.appendChild(rc2);
			var d2l=document.createElement('DIV');
			d2l.className='bl';
			rc2.appendChild(d2l);
			var d2r=document.createElement('DIV');
			d2r.className='br';
			rc2.appendChild(d2r);
		}
	}
	catch(x){alert(x)}
	try {
		mainMenu();
	}
	catch(x){ }
	try{
		var opts=document.getElementById('timeline_options').getElementsByTagName('option');
		for(var i=0;i<opts.length;i++){
			if(opts[i].value=="0"){
				opts[i].selected=true;
			}
		}
	}catch(x){}
}
function toggleDesc(l){
	var paras=document.getElementById('menutext').getElementsByTagName('P');
	var u=document.getElementById('nav2').getElementsByTagName('LI');
	var i=0;
	for(;i<u.length;i++){
		if(u[i]==l){
			break;
		}
	}
	for(var j=0;j<paras.length;j++){
		paras[j].style.display=(j==i ? 'block' : 'none');
	}
}
function resetDescr(){
	var paras=document.getElementById('menutext').getElementsByTagName('P');
	for(var i=0;i<paras.length;i++){
		paras[i].style.display= (/active/.test(paras[i].className) ? 'block' : 'none');
	}

}
function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) + ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + ( ( path ) ? ";path=" + path : "" ) + ( ( domain ) ? ";domain=" + domain : "" ) + ( ( secure ) ? ";secure" : "" );
}
function getCookie( check_name ) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ ) {
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name ) {
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) {
		return null;
	}
}				
window.getViewport=function(){
	return new Viewport();
};
function Viewport(){ 
	this.windowX = (document.documentElement && document.documentElement.clientWidth) || window.innerWidth || self.innerWidth || document.body.clientWidth; 
	this.windowY = (document.documentElement && document.documentElement.clientHeight) || window.innerHeight || self.innerHeight || document.body.clientHeight; 
	this.scrollX = (document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft; 
	this.scrollY = (document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop; 
	this.pageX = (document.documentElement && document.documentElement.scrollWidth) ? document.documentElement.scrollWidth : (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth; 
	this.pageY = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
	this.toString=function(){
		return 'windowX=' + this.windowX  + ',' + 'windowY=' + this.windowY  + ',' + 'scrollX=' + this.scrollX  + ',' + 'scrollY=' + this.scrollY  + ',' + 'pageX=' + this.pageX  + ',' + 'pageY=' + this.pageY  ;
	};
}
function IViewport(frm){ 
	var win=frm.contentWindow;
	var doc=win.document;
	this.winX = (doc.docElement && doc.docElement.clientWidth) || win.innerWidth || self.innerWidth || doc.body.clientWidth; 
	this.winY = (doc.docElement && doc.docElement.clientHeight) || win.innerHeight || self.innerHeight || doc.body.clientHeight; 
	this.scrollX = (doc.docElement && doc.docElement.scrollLeft) || win.pageXOffset || self.pageXOffset || doc.body.scrollLeft; 
	this.scrollY = (doc.docElement && doc.docElement.scrollTop) || win.pageYOffset || self.pageYOffset || doc.body.scrollTop; 
	this.pageX = (doc.docElement && doc.docElement.scrollWidth) ? doc.docElement.scrollWidth : (doc.body.scrollWidth > doc.body.offsetWidth) ? doc.body.scrollWidth : doc.body.offsetWidth; 
	this.pageY = (doc.docElement && doc.docElement.scrollHeight) ? doc.docElement.scrollHeight : (doc.body.scrollHeight > doc.body.offsetHeight) ? doc.body.scrollHeight : doc.body.offsetHeight;
	this.toString=function(){
		return 'winX=' + this.winX  + ',' + 'winY=' + this.winY  + ',' + 'scrollX=' + this.scrollX  + ',' + 'scrollY=' + this.scrollY  + ',' + 'pageX=' + this.pageX  + ',' + 'pageY=' + this.pageY  ;
	};
}
function resizeIframe(frm){
	var vp=new IViewport(frm);
	frm.style.height=(vp.pageY + 50) + 'px';
	frm.contentWindow.document.body.style.width=frm.scrollWidth + 'px';
	try{
		mainMenu();
	}
	catch(x){
		//alert(x);
	}
//	scrollTo(0,0);
}
function calcResize(){
	try{
		var vp=contwin.getViewport();
		document.getElementById('container').style.height=vp.pageY + 'px';
	}
	catch(x){}
}
function menuBlockSwitch(){
	var tree=[
		['root',['expertise','projects'],['aboutus',['profiles','news']]],
		'aviationstrategy',
		'aviationinsights',
		'aviationdata'
	];
	
	var l=document.location.pathname;
	var matches=l.match(/(?=aviation(?=(strategy)|(insights)|(data)))|(aboutus|profiles|news)/);
	var i=0;
	if(matches){
		for(i=1;i<matches.length;i++){
			if(matches[i]){

				break;
			}

		}
	}
	else if(/subscribed/.test(l)){
		i=1;
	}
	var mp=document.getElementById('menutext').getElementsByTagName('P');
	var ml=document.getElementById('nav2').getElementsByTagName('LI');
	try{
		if(i>0){
			mp[0].className='';
			mp[i].className='active';
			ml[0].className='';
			ml[i].className='active';
		}
	}
	catch(x){}



}

function toggleTimeline(s){
	var obj=document.getElementById('testSVG');
	var doc=obj.contentDocument;
	var ot =doc.getElementById('timeline' + currentTimeline);
	if(ot){
		ot.style.visibility='hidden';
	}
	var t=doc.getElementById('timeline' + s.value);
	if(t){
		t.style.visibility='visible';
	}
	currentTimeline=s.value;
}
function toggleChart(s){
	var obj=document.getElementById('testSVG');
	var doc=obj.contentDocument;
	var ot =doc.getElementById('graph' + currentChart);
	if(ot){
		ot.style.visibility='hidden';
	}
	var t=doc.getElementById('graph' + s.value);
	if(t){
		t.style.visibility='visible';
	}
	currentChart=s.value;
}
function returnValidClick(b){
	var mh=top.document.getElementById('modal_holder');
	mh.style.display='none';
	
	document.location=issueRequest;
	issueRequest='';
}
function checkLegalSubmit(fm){
	var mh=top.document.getElementById('modal_holder');
	mh.style.display='none';
	if(fm.agree.checked && fm.i.value !=''){
		setCookie('lagreed',1);
		legalAgreed=true;
		return true;
	}
	return false;
}
function checkLegal(l){
	if(getCookie('lagreed') || legalAgreed){
		return true;
	}
	var fm=top.document.forms.legal_form;
	var hb=l.href.split('&');
	for(var i=1;i<hb.length;i++){
		var kv=hb[i].split('=');
		fm.elements[kv[0]].value=kv[1];
	}
	fm.agree.checked=false;
	var mh=top.document.getElementById('modal_holder');
	var vp=top.getViewport();
	var md=top.document.getElementById('modal_dialog');
	md.style.left=((vp.windowX-400)/2) + 'px';
	md.style.top=((vp.windowY - 300)/2)+'px';
	mh.style.display='block';
	
	return false;

	if(confirm('Aviation Strategy is a copywrited, subscription-only publication. The contents, either in whole or in part, may not be copied, stored or reproduced in any format, printed or electronic, without the written consent of the publisher. To subscribe, or obtain further information, please contact:  info@aviationeconomics.com')){
		return true;
	}
	return false;
}
function toggleFpwd(){
	var t=document.getElementById('forgotten_pwd');
	try{
		t.style.display='table';
	}
	catch(x){
		t.style.display='block';
	}
}
function checkChangePwd(fm){
	if(fm.old_pwd.value != fm.cfm_old_pwd.value){
		alert('Old passwords do not match');
		return false;
	}
	if(fm.new_pwd.value != fm.cfm_new_pwd.value){
		alert('New passwords do not match');
		return false;
	}
	if(fm.new_pwd.value.length<6){
		alert('Passwords need to be at least six characters long');
		return false;
	}
	return true;
}
