/*
	app box def: tdcApb(text, title, width [, top, left]);
	text: text of the message in quotes - 'This is the text.'
	title: title of the message in quotes - 'This is my Title'
	width: in quotes - '500'
	top: optional in quotes - '100'
	left: optional in quotes - '200'
*/

apb_pageWidth = function(){
	return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;
}

apb_pageHeight = function(){
	return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;
}

apb_posLeft = function(){
	return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;
}

apb_posTop = function(){
	return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;
}

apb_scrollFix = function(){
	var obol=document.getElementById('apb_ol');
	obol.style.top=apb_posTop()+'px';
	obol.style.left=apb_posLeft()+'px';
}

apb_sizeFix = function(){
	var obol=document.getElementById('apb_ol');
	obol.style.height=apb_pageHeight()+'px';
	obol.style.width=apb_pageWidth()+'px';
}

apb_sm = function(wd, vtp, vlt){
	var b='block';
	var p='px';
	var obol=document.getElementById('apb_ol'); 
	obol.style.height=apb_pageHeight()+p;
	obol.style.width=apb_pageWidth()+p;
	obol.style.top=apb_posTop()+p;
	obol.style.left=apb_posLeft()+p;
	obol.style.display=b;
	
	var obbx=document.getElementById('apb_mbox');
	obbx.style.width=wd+p;
	//var wd = obbx.style.width.substring(0, obbx.style.width.indexOf('p'));
	
	var tp=apb_posTop()+((apb_pageHeight()-500)/2)-12;
	var lt=apb_posLeft()+((apb_pageWidth()-wd)/2)-12;
	
	if(vtp){
		obbx.style.top=vtp+p;
	}else{
		obbx.style.top=(tp<0?0:tp)+p;
	}
	if(vlt){
		obbx.style.left=vlt+p;
	}else{
		obbx.style.left=(lt<0?0:lt)+p;
	}
	
	obbx.style.display=b;
	return false;
}

apb_hm = function(){
	//var v='visible';
	var n='none';
	document.getElementById('apb_ol').style.display=n;
	document.getElementById('apb_mbox').style.display=n;
	//inf(v);
	document.onkeypress=''
}

initapb = function(){
	var ab='absolute';
	var n='none';
	var obody=document.getElementsByTagName('body')[0];
	var frag=document.createDocumentFragment();
	var obol=document.createElement('div');
	obol.setAttribute('id','apb_ol');
	obol.style.display=n;
	obol.style.position=ab;
	obol.style.top=0;
	obol.style.left=0;
	obol.style.zIndex=998;
	obol.style.width='100%';
	frag.appendChild(obol);
	
	var obbx=document.createElement('div');
	obbx.setAttribute('id','apb_mbox');
	obbx.style.display=n;
	obbx.style.position=ab;
	obbx.style.zIndex=999;
	obbx.style.width='300px';
	
	/*var obl=document.createElement('span');
	obbx.appendChild(obl);*/
	
	var obbxd=document.createElement('div');
	obbxd.setAttribute('id','apb_mbd');
	obbx.appendChild(obbxd);
	
	var obbxttl=document.createElement('div');
	obbxttl.setAttribute('id','apb_mbtitle');
	obbx.appendChild(obbxttl);
	
	var obbxtxt=document.createElement('div');
	obbxtxt.setAttribute('id','apb_mbtext');
	obbx.appendChild(obbxtxt);
	
	/*var obbxbtn=document.createElement('div');
	obbxbtn.setAttribute('id','apb_mbbtns');
	obbx.appendChild(obbxbtn);*/
	
	frag.insertBefore(obbx,obol.nextSibling);
	obody.insertBefore(frag,obody.firstChild);
	window.onscroll = apb_scrollFix; 
	window.onresize = apb_sizeFix;
}

tdcApb = function(app, ttl, wd, vtp, vlt){
	document.getElementById('apb_mbtitle').innerHTML = '<div style="float:left;">' + ttl + '</div><div style="float:right;"><button onclick="apb_hm();" class="apb_mbbtnsclass">X</button></div>';
	document.getElementById('apb_mbtext').innerHTML = 'Loading...';
	apb_sm(wd, vtp, vlt);
	Spry.Utils.updateContent('apb_mbtext', app);
}

//window.onload = initmb;
                  