/* Author: Jack Tang
 1) Mouse over text enlargement
 2) Fade Background Popup
 3) Set Main Table Height
 Last updated: Arp 17th, 2010
*/

var mouseoverlarger={}

mouseoverlarger.minsize=12 //set min font size when mouse isn't over element
mouseoverlarger.increment=2 //size to increase after each iteration
mouseoverlarger.maxsize=22

mouseoverlarger.fadeupdown=function(obj, direction){
	var targetobject=obj
	var fadeamount=(direction=="fadeup")? this.increment : -this.increment
	if (targetobject && (direction=="fadeup" && parseInt(targetobject.style.fontSize)<this.maxsize || direction=="fadedown" && parseInt(targetobject.style.fontSize)>this.minsize)){
		var newsize=parseInt(targetobject.style.fontSize)+fadeamount;
		targetobject.style.fontSize=newsize+'px';
		window["opacityfader"+obj._fadeorder]=setTimeout(function(){mouseoverlarger.fadeupdown(obj, direction)}, 50)
	}
}

mouseoverlarger.clearTimer=function(obj){
if (typeof window["opacityfader"+obj._fadeorder]!="undefined")
	clearTimeout(window["opacityfader"+obj._fadeorder])
}

mouseoverlarger.isContained=function(m, e){
	var e=window.event || e
	var c=e.relatedTarget || ((e.type=="mouseover")? e.fromElement : e.toElement)
	while (c && c!=m)try {c=c.parentNode} catch(e){c=m}
	if (c==m)
		return true
	else
		return false
}

mouseoverlarger.fadeinterface=function(obj, e, direction){
	if (!this.isContained(obj, e)){
		mouseoverlarger.clearTimer(obj)
		mouseoverlarger.fadeupdown(obj, direction)
	}
}

mouseoverlarger.collectElementbyClass=function(classname){ //Returns an array containing DIVs with specified classname
	var classnameRE=new RegExp("(^|\\s+)"+classname+"($|\\s+)", "i") //regular expression to screen for classname within element
	var pieces=[]
	var alltags=document.all? document.all : document.getElementsByTagName("*")
	for (var i=0; i<alltags.length; i++){
		if (typeof alltags[i].className=="string" && alltags[i].className.search(classnameRE)!=-1)
			pieces[pieces.length]=alltags[i]
	}
	return pieces
}

mouseoverlarger.init=function(){
	var targetobjects=this.collectElementbyClass("molarger")
	for (var i=0; i<targetobjects.length; i++){
		targetobjects[i].style.fontSize=this.minsize+'px';
		targetobjects[i]._fadeorder=i
		targetobjects[i].onmouseover=function(e){mouseoverlarger.fadeinterface(this, e, "fadeup")}
		targetobjects[i].onmouseout=function(e){mouseoverlarger.fadeinterface(this, e, "fadedown")}
	}
}

mouseoverlarger.init(); //activate

/* ====================================================================================================================
  Fade Background Popup
*/
function virtualPopup_init() {
 darkenobj=document.createElement("div");
 darkenobj.setAttribute("id", "darkenlayer");
 document.body.appendChild(darkenobj);
 $("#darkenlayer").css({'top':'0px','left':'0px','position':'absolute','visibility':'hidden','opacity':'0.6','filter':'alpha(opacity=60)','background':'url("/img/bgfade.gif")','overflow':'hidden'});
 popupobj=document.createElement("div");
 popupobj.setAttribute("id", "popuppanel");
 document.body.appendChild(popupobj);
 $("#popuppanel").css({'position':'absolute','display':'none','visibility':'hidden','background':'#F0F0F0','height':'500px','width':'500px','border':'#C0C0C0 solid 10px'});
}

function resizedarkenlayer(){
 $("#darkenlayer").css('height',$(document).height()+'px');
 $("#darkenlayer").css('width',$(document).width()+'px');
}

function vDarkenPage(){
 var darkenobj = document.getElementById('darkenlayer');
 darkenobj.style.width=$(document).width()+'px';
 darkenobj.style.height=$(document).height()+'px';
 darkenobj.style.visibility='visible';
 darkenobj.style.overflow='hidden';
}
function vPopUpClose(){
 vDarkenPage();
 document.getElementById('darkenlayer').style.visibility='hidden';
 var popupobj = document.getElementById('popuppanel');
 popupobj.innerHTML='';
 popupobj.style.display = 'none';
 popupobj.style.visibility = 'hidden';
 return false;
}
// if w or h is negative, set the size to the screensize less w/h
function vPopUpOpen(w,h){
 vDarkenPage();
 var popupobj = document.getElementById('popuppanel');
 if (w <= 0) w = Math.round($(window).width() + w);
 if (h <= 0) h = Math.round($(window).height() + h);
 xc = Math.round((($(window).width()/2)-(w/2)) + $("html").scrollLeft())
 yc = Math.round((($(window).height()/2)-(h/2)) + $("html").scrollTop())
 popupobj.style.width = w + "px";
 popupobj.style.height = h + "px";
 popupobj.style.left = xc + "px";
 popupobj.style.top = yc + "px";
 popupobj.style.display = 'block';
 popupobj.style.visibility = 'visible';
 popupobj.style.zIndex = '2500';
 popupobj.innerHTML='<A HREF=# ONCLICK="vPopUpClose();">Close</a>';
 return false;
}
function vPopUpUrl(w,h,url){
 vPopUpOpen(w,h);
 document.getElementById('popuppanel').innerHTML='<div class=icoloading></div>';
 ajaxhttp.complete=function(code,response){
  if (code=='200'){
   document.getElementById('popuppanel').innerHTML=response;
  } else {
   document.getElementById('popuppanel').innerHTML='<div class=icoerror></div> Error '+code+' while loading page. Please Report this Error to Customer Service.';
  }
 }
 ajaxhttp.get(url);
}
function vPopUpObj(w,h,idname){
 vPopUpOpen(w,h);
 document.getElementById('popuppanel').innerHTML=document.getElementById('idname').innerHTML;
}
function vPopUpHtml(w,h,htmlstr){
 vPopUpOpen(w,h);
 document.getElementById('popuppanel').innerHTML=htmlstr;
}
function vPopUpPrompt(w,h,htmlstr,icoclass,butreplies,funcreply){
 vPopUpOpen(w,h);
 var butstr='';
 for (var i=0; i<butreplies.length; i++){
  butstr += '<A HREF=# ONCLICK="javascript: vPopUpClose();';
  if (funcreply!='') butstr+=funcreply+'(\''+butreplies[i]+'\');';
  butstr += 'return false;"><SPAN CLASS=txtbutton>'+butreplies[i]+'</SPAN></A> &nbsp;';
 }
 document.getElementById('popuppanel').innerHTML='<div class=dprompt><table width='+(w-2)+' HEIGHT='+(h-2)+' border=0 cellspacing="5" cellpadding="0"><tr valign=middle><td width=70 align=center><div class='+icoclass+'></div></td><TD WIDTH=10>&nbsp;</TD><td WIDTH=520><span class=txttitledred>'+htmlstr+'</td></tr><tr><td></td><td></td><td align=right>'+butstr+'</td></tr></table></div>';
}
// Run init code
jQuery.event.add(window, "resize", resizedarkenlayer);
virtualPopup_init();

/* ====================================================================================================================
  Set Main Table Height to maintain a proper look for short pages
*/
document.getElementById('tblframe').style.height=Math.round($(window).height() - 165) + "px";


