var d = null
var offsetWidth = 0;
var offsetHeight = 0;
var currTab = null;
var setCount =0;
var menutabs = [
[ 'home', -400, "showOperator()", "hideMedia1()", false, false ],
[ 'about', -368, "", "", false, false ],
[ 'company', -294, "", "", false, false ],
[ 'customers', -200, "", "", false, false ],
[ 'downloads', 111, "", "", false, false ],
[ 'partners', 214, "", "", false, false ],
[ 'onlinedemo', 300, "", "", false, false ]
];
var divs = [
[ 'home-bg', '<img src="images/pc-home-bg.gif">' ],
[ 'home-play', '<img src="images/pc-home-play.gif" style="cursor:pointer;cursor:hand" onclick="showMedia1()" onmouseover="opacity(\'home-play\',100,50,500)" onmouseout="opacity(\'home-play\',50,100,500)">' ],
[ 'about-networking', '<img src="images/pc-networking.gif">' ],
[ 'company-handshake', '<img src="images/pc-handshake.gif">' ],
[ 'customers-teamwork', '<img src="images/pc-teamwork.gif">' ],
[ 'downloads-brochure', '<a href="/resources/PilotYourAdmissionsTeam.pdf" target=_blank><img src="images/pc-brochure-inside.jpg" border="0" style="cursor:pointer;cursor:hand"></a>' ],
[ 'partners-table', '<table border="0" width="360"><tr><td width="180" rowspan="2" valign="top"> <a href="http://www.celsiusmarketing.com" target="_blank"><img src="images/pc-partners-celsiusmarketing.gif" width="150" height="190" border="0" alt="www.CelsiusMarketing.com"></a> </td><td width="180"> <a href="http://www.enrollmentresources.com" target="_blank"><img src="images/pc-partners-enrollmentresources.gif" width="150" height="91" border="0" alt="www.EnrollmentResources.com"></a> </td><tr><td> <a href="http://www.mdtdirect.com" target="_blank"><img src="images/pc-partners-mdtdirect.gif" width="150" height="80" border="0" alt="www.MDTDirect.com"></a> </td></tr><tr><td colspan="2"> <a href="http://www.speak2leads.com" target="_blank"><img src="images/pc-partners-speak2leads.gif" width="318" height="150" border="0" alt="www.Speak2Leads.com"></a> </td></tr></table>' ],
[ 'bottomconsole', '<img src="images/pc-bottomconsole.gif" width="737" height="22" border="0" allowtransparency="true">' ]
];
var randompic = ['pc-operator.gif','pc-operator.gif','pc-operator.gif','pc-operator2.gif','pc-operator3.gif','pc-operator4.gif','pc-operator4.gif','pc-operator4.gif','pc-student.gif','pc-welcome.gif'];
var randomnum = Math.floor(Math.random()*10);
var preloaded = 500;
var preload = [
['HomePage.jpg',new Image(),false],
['offlinehelp.gif',new Image(),false],
['onlinehelp.gif',new Image(),false],
['pc-about.gif',new Image(),false],
['pc-about.jpg',new Image(),false],
['pc-about-socket.gif',new Image(),false],
['pc-bottomconsole.gif',new Image(),false],
['pc-box-bg.gif',new Image(),false],
['pc-box-bottom.gif',new Image(),false],
['pc-box-top.gif',new Image(),false],
['pc-brochure-inside.jpg',new Image(),false],
['pc-company.gif',new Image(),false],
['pc-company.jpg',new Image(),false],
['pc-company-socket.gif',new Image(),false],
['pc-customers.gif',new Image(),false],
['pc-customers.jpg',new Image(),false],
['pc-customers-socket.gif',new Image(),false],
['pc-downloads.gif',new Image(),false],
['pc-downloads.jpg',new Image(),false],
['pc-downloads-socket.gif',new Image(),false],
['pc-handshake.gif',new Image(),false],
['pc-help.jpg',new Image(),false],
['pc-home.gif',new Image(),false],
['pc-home.jpg',new Image(),false],
['pc-home-bg.gif',new Image(),false],
['pc-home-play.gif',new Image(),false],
['pc-home-socket.gif',new Image(),false],
['pc-networking.gif',new Image(),false],
['pc-onlinedemo.gif',new Image(),false],
['pc-onlinedemo.jpg',new Image(),false],
['pc-onlinedemo-socket.gif',new Image(),false],
[randompic[randomnum],new Image(),false],
['pc-partners.gif',new Image(),false],
['pc-partners.jpg',new Image(),false],
['pc-partners-celciusmarketing.gif',new Image(),false],
['pc-partners-enrollmentresources.gif',new Image(),false],
['pc-partners-mdtdirect.gif',new Image(),false],
['pc-partners-socket.gif',new Image(),false],
['pc-teamwork.gif',new Image(),false]
];

function setUI(){
 if(setCount>0) return false;
 setCount++;
 var size = getUIsize();
 offsetWidth = size.width;
 offsetHeight = size.height;
 setPos('loading',offsetWidth/2-40,120);
 setTimeout('loadImages()',1000);
 setTimeout('checkLoad()',5000);
 //setTimeout('writeTabs()',2000);
// if(/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
//  document.getElementById('pc-loading').onload = null;
}

function loadImages(){
 preloaded = 0;
 window.status='Preloading images';
 for(var i=0; i<preload.length; i++){
  preload[i][1].src = 'http://www.precisecontact.com/images/'+preload[i][0];
  preload[i][1].name = preload[i][0]+"|"+i;
  preload[i][1].onload = checkImage;
  preload[i][1].onerror = checkImage;
 }
 writeTabs();
}

function checkImage(e){
 preloaded++;
 window.status = "Preloading images..."+preloaded+" of "+preload.length;
/*
 if(e==null)var e = window.event;
 var el = window.event ? window.event.srcElement : e.target;
 var i = parseInt(new String(el.name).split("|")[1]);
 preload[i][2] = true;
 preload[i][1].onload = null;
*/
}

function checkLoad(){
 if(preloaded<preload.length)
  preloaded = preload.length;
}

function checkImages(){
 if(preloaded<preload.length)//34)
  return false;
/*
 for(var i=0; i<preload.length; i++){
  if(preload[i][2] == false)
   return false;
 }
*/
 return true;
}

function loadDivs(){
 for(var d=0; d<divs.length; d++)
  document.getElementById(divs[d][0]).innerHTML = divs[d][1];
}

function writeTabs(){
 if(!checkImages())
  return setTimeout('writeTabs()',100);
 try{window.status='Done';}catch(e){}
 var szHTML = new String("");
 for(var t=0; t<menutabs.length; t++)
  szHTML += "" +
  "<div id="+menutabs[t][0]+"socket style=\"position:absolute;visibility:hidden;z-index:610;\"><img src='images/pc-"+menutabs[t][0]+"-socket.gif' border=\"0\"></div>\n" +
  "<div id="+menutabs[t][0]+"over style=\"position:absolute;visibility:hidden;z-index:600;\"><img src='images/pc-"+menutabs[t][0]+".gif' border=\"0\" onclick=\"showPage('"+menutabs[t][0]+"')\"></div>\n" +
  "<div id="+menutabs[t][0]+" style=\"position:absolute;visibility:hidden;z-index:500;\"><img src='images/pc-"+menutabs[t][0]+".jpg' onmouseover=\"showTab('"+menutabs[t][0]+"',"+menutabs[t][1]+")\" border=\"0\"></div>\n" +
  "";
 document.body.innerHTML += szHTML;
 loadDivs();
 document.body.background = 'images/HomePage.jpg';
 //alert(randompic[randomnum]);
 document.getElementById('home-operator').style.backgroundImage="url(images/"+randompic[randomnum]+")";
 setUIPosition();
 setTimeout("window.frames['ntr'].src = 'livehelp-home.htm'",5000);
}

function setPos(n,x,y,vis){ 
 try{document.getElementById(n).style.left=x;}catch(e){}
 try{document.getElementById(n).style.top=y;}catch(e){}
 if(vis!=false)
  try{document.getElementById(n).style.visibility = 'visible';}catch(e){}
}

function getUIsize(){
 if( typeof( window.innerWidth ) == 'number' ) {
  //Non-IE
  this.width = window.innerWidth;
  this.height = window.innerHeight;
 } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
  //IE 6+ in 'standards compliant mode'
  this.width = document.documentElement.clientWidth;
  this.height = document.documentElement.clientHeight;
 } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
  //IE 4 compatible
  this.width = document.body.clientWidth;
  this.height = document.body.clientHeight;
 }
 return this;
}

function getQuerystring(key, default_)
{
  if (default_==null) default_=""; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}

function setUIPosition(){
 d = ( document.getElementById('logon').contentDocument ? document.getElementById('logon').contentDocument : document.getElementById('logon').contentWindow.document );
 var size = new getUIsize();
 offsetWidth = size.width;
 offsetHeight = size.height;
 setPos('help',offsetWidth/2-390,46);
 setPos('ntr',offsetWidth/2-389,46);
 setPos('logon',offsetWidth/2+110,42);
 setPos('box',offsetWidth/2-380,80,false);
 setPos('fadeout',offsetWidth/2-357,80,false);
 setPos('home-operator',offsetWidth/2-390,80,false);
 setPos('loading',offsetWidth/2-40,120);
 setPos('bottomconsole',offsetWidth/2-(737/2),offsetHeight-22);
 for(var t=0; t<menutabs.length; t++)
 {
  setPos(menutabs[t][0],offsetWidth/2+menutabs[t][1]-8,0);
  setPos(menutabs[t][0]+'over',offsetWidth/2+menutabs[t][1],0,false);
  setPos(menutabs[t][0]+'socket',offsetWidth/2+menutabs[t][1]-5,0);
  if(t==0){
   setTimeout("showTab('" + menutabs[t][0] + "'," + menutabs[t][1] + ")",1000);
   setTimeout("showPage('" + menutabs[t][0] + "')",1000);
   setPos(menutabs[t][0]+'-bg',offsetWidth/2-400,76,false);
   setPos(menutabs[t][0]+'-play',offsetWidth/2-142,157,false);
  }
 }
 setPos('scroller',offsetWidth/2-357,80,false);
 setPos('scrollbox',offsetWidth/2+361,104,false);
 setPos('scrollline',offsetWidth/2+365,104,false);
 document.getElementById('scroller').style.height = offsetHeight-112;
 document.getElementById('scrollline').style.height = offsetHeight-104-boxOffset*2;

 parent.onresize = setUIPosition;
}

function showTab(name,offset) {
 setPos(name+'over',offsetWidth/2+offset,0);
 for(var t=0; t<menutabs.length; t++)
  if(menutabs[t][0]==name)
  {
   menutabs[t][4] = false;
   currTab = t;
  }
 for(var t=0; t<menutabs.length; t++)
  if(menutabs[t][0]!=name && document.getElementById(menutabs[t][0]+'over').style.visibility=='visible' && !menutabs[t][4])
   hideTab(menutabs[t][0]);
 for(x=1;x<7;x++)
  setTimeout("setPos('"+name+"over',"+(offsetWidth/2+offset)+","+x+")",(500/7)*x);
 setTimeout("parent.onresize = setUIPosition",3000);
}

function hideTab(name) {
 var over = document.getElementById(name+'over');
 var t = parseInt(over.style.top);
 var l = parseInt(over.style.left);
 for(var t=0; t<menutabs.length; t++)
  if(menutabs[t][0]==name)
   menutabs[t][4] = true;
 for(x=t;x>=0;x--)
  setTimeout("setPos('"+name+"over',"+l+","+(x)+")",500+((500/7)*(t-x)));
 setTimeout("document.getElementById('"+name+"over').style.visibility = 'hidden'",500+((500/7)*t));
 setTimeout("parent.onresize = setUIPosition",3000);
}

function showPage(name) {
 opacity('loading',0,100,100);
 document.getElementById('box').style.visibility = name=="home"?'hidden':'visible';
 for(var t=0; t<menutabs.length; t++)
  if(menutabs[t][0]==name){
   if(menutabs[t][2]!="")try{var evals=menutabs[t][2].split("\t");for(var z=0;z<evals.length;z++)eval(evals[z]);}catch(e){}
   menutabs[t][5] = true;
  }
 for(var t=0; t<menutabs.length; t++)
  if(menutabs[t][0]!=name && menutabs[t][5])
   hidePage(menutabs[t][0]);
 opacity(name=='home'?'homepage':'fadein',0,100,750);
 if(name!='home')changeOpac(0,name+'page')
 document.getElementById('fadein').innerHTML = (name=='home'?'':document.getElementById(name+'page').innerHTML);
 addWheel();
 setScrollbox(name);
 setTimeout("opacity('loading',100,0,100)",500);
 setTimeout("parent.onresize = setUIPosition",3000);
}

function hidePage(name) {
 for(var t=0; t<menutabs.length; t++)
  if(menutabs[t][0]==name){
   if(menutabs[t][3]!="")try{var evals=menutabs[t][3].split("\t");for(var z=0;z<evals.length;z++)eval(evals[z]);}catch(e){}
   menutabs[t][5] = false;
  }
 if(name=='home')opacity('homepage',100,0,750);
 setTimeout("parent.onresize = setUIPosition",2000);
}

function showOperator(){
 changeOpac(0,'home-operator');
 setTimeout("document.getElementById('home-operator').style.visibility = 'visible'",1000);
 setTimeout("opacity('home-operator',0,100,3000)",1000);
}

function showHandshake(){
 changeOpac(0,'company-handshake');
 //setTimeout("document.getElementById('company-handshake').style.visibility = 'visible'",1000);
 setTimeout("opacity('company-handshake',0,100,2000)",1000);
}

function showMedia1(){
 var height = offsetHeight-110;//( offsetHeight < 365 ? 265 : ( offsetHeight < 444 ? 344 : ( offsetHeight < 600 ? 385 : 505 ) ) );
 var width  = (offsetHeight-135)/3*4;//( offsetHeight < 365 ? 320 : ( offsetHeight < 444 ? 425 : ( offsetHeight < 600 ? 480 : 640 ) ) );
 document.getElementById('media').innerHTML = "" +
  "<div id=\"darkenpage\" class=\"darkenpage\"></div><div id=\"mediabox\" class=\"mediabox\"><div>";
 document.getElementById('media').style.zIndex = 1899;
 document.getElementById('darkenpage').style.zIndex = 1900;
 opacity('darkenpage',0,50,2000);
 setTimeout('showMediabox1()',500);
/*
 document.getElementById('mediabox').innerHTML = "" +
  "<table border=\"0\" width=\"476\" height=\"380\"><tr><td valign=\"top\" align=\"right\"><b><font face=\"Arial,Helvetica,Sans Serif\" color=\"white\"><span onclick=\"hideMedia1()\" style=\"cursor:pointer;cursor:hand;\">&nbsp;X&nbsp;</span></font></b></td></tr></table>";
 setPos('mediabox',offsetWidth/2-238,65,false);
 document.getElementById('MediaPlayer').innerHTML = "" +
  "<object title=\"double-click for Full Screen View\" id=\"video\" width=466 height=350 classid=\"CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95\" standby=\"Loading Windows Media Player components...\" type=\"application/x-oleobject\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112\">" +
  "<param name=\"filename\" value=\"http://www.precisecontact.com/resources/PMDemo.wmv\">" +
  "<param name=\"autoStart\" value=\"1\">" +
  "<PARAM NAME=\"ClickToPlay\" VALUE=\"1\"> " +
  "<PARAM NAME=\"TransparentAtStart\" VALUE=\"0\">" + 
  "<PARAM NAME=\"EnableFullScreenControls\" VALUE=\"1\"> " +
  "<PARAM NAME=\"ShowControls\" VALUE=\"0\"> " +
  "<embed title=\"double-click for Full Screen View\" type=\"application/x-mplayer2\" src=\"http://www.precisecontact.com/resources/PMDemo.wmv\" width=466 height=350 autostart=1 showcontrols=0 enablefullscreencontrols=1 transparentatstart=1></embed> " +
  "</object>";
 setPos('MediaPlayer',offsetWidth/2-233,90,false);
*/
}

function showMediabox1(){
 var height = offsetHeight-110;//( offsetHeight < 365 ? 265 : ( offsetHeight < 444 ? 344 : ( offsetHeight < 600 ? 385 : 505 ) ) );
 var width  = (offsetHeight-135)/3*4;//( offsetHeight < 365 ? 320 : ( offsetHeight < 444 ? 425 : ( offsetHeight < 600 ? 480 : 640 ) ) );
 document.getElementById('mediabox').innerHTML = "" +
  "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\""+width+"\" height=\"25\"><tr><td class=\"youtube-topleft\">&nbsp;</td><td width=\"240\" class=\"youtube-center\"><b>Precise Contact Overview</b> (click</font>&nbsp;</td><td width=\"21\" class=\"youtube-center\"><img src=\"images/pc-fullscreen.gif\"></td><td class=\"youtube-center\">&nbsp;to view Full Screen)</td><td onclick=\"hideMedia1()\" class=\"youtube-topright\">&nbsp;X&nbsp;</td></tr></table>";
 setPos('mediabox',offsetWidth/2-(width/2),75,false);
 opacity('mediabox',0,100,500);
 document.getElementById('mediabox').style.zIndex = 1950;
 document.getElementById('MediaPlayer').innerHTML = "" +
  "<object width=\""+width+"\" height=\""+height+"\"><param name=\"movie\" value=\"http://www.youtube.com/v/aY3NqB66lj8&hl=en&fs=1&rel=0&color1=0x3a3a3a&color2=0x999999\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/aY3NqB66lj8&hl=en&fs=1&rel=0&color1=0x3a3a3a&color2=0x999999\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\""+width+"\" height=\""+height+"\"></embed></object>";
 setPos('MediaPlayer',offsetWidth/2-(width/2),100,false);
}
function hideMedia1(){
 try{document.getElementById('home-operator').style.visibility = 'hidden';}catch(e){}
 opacity('mediabox',100,0,500);
 setTimeout("try{document.getElementById('MediaPlayer').innerHTML='';}catch(e){}",500);
 setTimeout("opacity('darkenpage',50,0,1000)",500);
 setTimeout("removeChildren('media')",1010);
 setTimeout("document.getElementById('media').innerHTML=''",1020);
 setTimeout("document.getElementById('media').style.zIndex = 0",1030);
}

function removeChildren(id){
 var tag = document.getElementById(id);
 if ( tag.hasChildNodes() )
    while ( tag.childNodes.length >= 1 )
        tag.removeChild( tag.firstChild );       
}

function showMedia2(){
 document.getElementById('MediaPlayer').innerHTML = "" +
  "<object title=\"double-click for Full Screen View\" id=\"video2\" width=320 height=260 classid=\"CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95\" standby=\"Loading Windows Media Player components...\" type=\"application/x-oleobject\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112\">" +
  "<param name=\"filename\" value=\"http://www.precisecontact.com/resources/PMDemo.wmv\">" +
  "<param name=\"ShowControls\" value=\"1\">" +
  "<PARAM NAME=\"PreviewMode\" VALUE=\"1\"> " +
  "<param name=\"autoStart\" value=\"0\">" +
  "<PARAM NAME=\"EnableFullScreenControls\" VALUE=\"1\"> " +
  "<param name=\"uiMode\" value=\"mini\">" +
  "<embed type=\"application/x-mplayer2\" src=\"http://www.precisecontact.com/resources/PMDemo.wmv\" width=320 height=260 autostart=0></embed> " +
  "</object>";
 setPos('MediaPlayer',offsetWidth/2+15,165,false);
}

function opacity(id, opacStart, opacEnd, millisec, delay) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 
    delay = (typeof(delay)=="undefined" ? 0 : delay);

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",delay+(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",delay+(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    try{var object = document.getElementById(id).style;}catch(e){}
    try{object.opacity = (opacity / 100); }catch(e){}
    try{object.MozOpacity = (opacity / 100); }catch(e){}
    try{object.KhtmlOpacity = (opacity / 100); }catch(e){}
    try{object.filter = "alpha(opacity=" + opacity + ")"; }catch(e){}
}

 // Scrollers speed here (larger is faster 1-10) 
 var scrollerspeed=1 ;
 // Scrollers content contained in a div with the id scrollercontent 
 var scrollerwidth =  "730px";
 var scrollerheight = "390px";
 var pauseit=1 ;
 // Change nothing below! 
 scrollerspeed=(document.all)? scrollerspeed : Math.max(1, scrollerspeed-1) ;
 //slow speed down by 1 for NS 
 var copyspeed=scrollerspeed ;
 var iedom=document.all||document.getElementById ;
 var actualheight='' ;
 var cross_scroller ;
 var pausespeed=(pauseit==0)? copyspeed: 0 ;
 var sto=null; //store the setTimeout instance
 function scrollscroller(){
  if (iedom){
   if (parseInt(cross_scroller.style.top)>(actualheight*(-1)+8)) 
    cross_scroller.style.top=parseInt(cross_scroller.style.top)-copyspeed+"px" ;
   else
    cross_scroller.style.top=parseInt(scrollerheight)+8+"px" ;
  } 
 }
 function resetscroller(){
  cross_scroller = document.getElementById('scrollercontent') ;
  actualheight=cross_scroller.offsetHeight ;
  if (iedom)
   cross_scroller.style.top=parseInt(scrollerheight)+8+"px" ;
  sto = setInterval("scrollscroller()",75) ;
 }

 var margin = 20;
 var boxOffset = 24;
 var floor = 27;
 var change = 60;
 var box = null;
 var scr = null;
 var con = null;
 var scrW = null;
 var scrH = null;
 var conH = null;
 var scrArea = null;
 var maxBox = null;
 var XY = null;
 
 function setScrollbox(name){
  box = document.getElementById('scrollbox') ;
  scr = document.getElementById('scroller') ;
  con = document.getElementById('scrollercontent') ;
  con.style.top = margin+'px';
  scrW = scr.offsetWidth;
  scrH = scr.offsetHeight;
  conH = con.offsetHeight;
  scrArea = scrH-margin*2;
  change = scrArea/5;
  maxCon = scrArea-conH;
  XY = fGetXY(scr);
  scr.style.visibility = con.style.visibility = box.style.visibility = document.getElementById('scrollline').style.visibility = name=="home"?'hidden':'visible';
  if(name!="home"){
   if( scrH < conH+floor ){
    box.style.top = XY[1]+boxOffset+'px';
    box.style.height = (scr.offsetHeight-margin*2)*scr.offsetHeight/(con.offsetHeight+floor);
    maxBox = scrArea-box.offsetHeight;
   }else
    box.style.visibility = document.getElementById('scrollline').style.visibility = 'hidden';
   document.getElementById('boxbg').style.height = offsetHeight-177; //scr.offsetHeight < con.offsetHeight ? offsetHeight-177 : con.offsetHeight-25;
   setPos('boxbottom',0,offsetHeight-142,false); //scr.offsetHeight < con.offsetHeight ? offsetHeight-142 : con.offsetHeight+10,false);
  }
 }
 
 function mousescroll(e){
  try{
   if(conH+floor<scrH)return false;
  }catch(e){return false;}
  try{
   if(e==null)var e = window.event;
   var x = (e.pageX?e.pageX:e.clientX)-XY[0];
   var y = (e.pageY?e.pageY:e.clientY)-XY[1];
   if(y>=0 && y<scrH && x>0-margin && x<scrW){
    con.style.top=(margin+(y<margin?0:(y>scrH-margin?maxCon:maxCon*(y-margin)/scrArea)))+"px";
    if(y>=margin && y<=scrH-margin)box.style.top=(XY[1]+boxOffset+maxBox*(y-margin)/scrArea)+"px";
    if(wheelSet)removeWheel();
   }
   else if(!wheelSet)
    addWheel();
   return true;
  }catch(e){return false;}
 }

 function fGetXY(aTag){
   var p=[0,0];
   while(aTag!=null){
   	p[0]+=aTag.offsetLeft;
   	p[1]+=aTag.offsetTop;
   	aTag=aTag.offsetParent;
   }
   return p;
 }

/** This is high-level function.
 * It must react to delta being more/less than zero.
 */
 function handle(delta) {
  try{
   if(conH+floor<scrH) return false;
   var curCon = parseInt(new String(con.style.top=="" ? "0" : con.style.top));
   newCon = ( delta < 0 ? ( curCon-change < maxCon+margin || delta == -100 ? maxCon+margin : ( delta == -10 ? ( curCon-scrArea >= maxCon+margin ? curCon-scrArea : maxCon+margin ) : curCon-change ) ) : ( curCon+change > margin || delta == 100 ? margin : ( delta == 10 ? ( curCon+scrArea <= margin ? curCon+scrArea : margin ) : curCon+change ) ) );
   newBox = XY[1]+boxOffset+maxBox*(newCon-margin)/maxCon;
   con.style.top=newCon+"px";
   box.style.top=newBox+"px";
   return true;
  }catch(e){return false;}
 }
 
/** Event handler for mouse wheel event.
 */
function wheel(event){
        var delta = 0;
        if (!event) /* For IE. */
                event = window.event;
        if (event.wheelDelta) { /* IE/Opera. */
                delta = event.wheelDelta/120;
                /** In Opera 9, delta differs in sign as compared to IE.
                 */
                if (window.opera)
                        delta = -delta;
        } else if (event.detail) { /** Mozilla case. */
                /** In Mozilla, sign of delta is different than in IE.
                 * Also, delta is multiple of 3.
                 */
                delta = -event.detail/3;
        }
        /** If delta is nonzero, handle it.
         * Basically, delta is now positive if wheel was scrolled up,
         * and negative, if wheel was scrolled down.
         */
        if (delta)
                handle(delta);
        /** Prevent default actions caused by mouse wheel.
         * That might be ugly, but we handle scrolls somehow
         * anyway, so don't bother here..
         */
        if (event.preventDefault)
                event.preventDefault();
	event.returnValue = false;
}

var wheelSet = false;
function setMouse(){
 /** Initialization code. 
  * If you use your own event management code, change it as required.
  */
 if(document.all || /Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
  document.onmousemove = mousescroll;
 else
  window.onmousemove = mousescroll;
 addWheel();
}

function addWheel(){
 if (window.addEventListener)
         /** DOMMouseScroll is for mozilla. */
         window.addEventListener('DOMMouseScroll', wheel, false);
 /** IE/Opera. */
 window.onmousewheel = document.onmousewheel = wheel;
 wheelSet = true;
}

function removeWheel(){
 if (window.addEventListener)
         /** DOMMouseScroll is for mozilla. */
         window.removeEventListener('DOMMouseScroll', wheel, false);
 /** IE/Opera. */
 window.onmousewheel = document.onmousewheel = null;
 wheelSet = false;
}

function bind(a,b,c,d){return window.addListener(a,b,function(){d.apply(c,arguments)});}
function handleKeystroke(evt) 
{              
// Grab the cross browser event
if( !evt ) evt = window.event;
// Character code of key pressed
var asc = !evt.keyCode ? (!evt.which ? evt.charCode : evt.which) : evt.keyCode;
// ASCII character of above code
var chr = String.fromCharCode(asc).toLowerCase();
for (var i in this)
{
  if (asc == i)
  {
 this[i](evt);
 break;
  }
}
}
function cancelEvent(evt)
{
 evt.cancelBubble = true;
 evt.returnValue = false;
 if (evt.preventDefault) evt.preventDefault();
 if (evt.stopPropagation) evt.stopPropagation();
 return false;
}
// KEY FUNCTIONS
function Tab(evt){
 try{
  if(Shift)
   var t = currTab-1 < 0 ? menutabs.length-1 : currTab-1;
  else
   var t = currTab+1 >= menutabs.length ? 0 : currTab+1;
  var name = menutabs[t][0];
  var offset = menutabs[t][1];
  showTab(name,offset);
  cancelEvent(evt);
  d.getElementById('enterbutton').focus();
 }catch(e){}
}
function Enter(evt){
 //showPage(menutabs[currTab][0]);
 cancelEvent(evt);
 d.getElementById('logonform').submit();
}
function lineLeft(evt){
  var t = currTab-1 < 0 ? menutabs.length-1 : currTab-1;
  var name = menutabs[t][0];
  var offset = menutabs[t][1];
  showTab(name,offset);
  showPage(menutabs[t][0]);
  cancelEvent(evt);
  d.getElementById('enterbutton').focus();
}
function lineRight(evt){
  var t = currTab+1 >= menutabs.length ? 0 : currTab+1;
  var name = menutabs[t][0];
  var offset = menutabs[t][1];
  showTab(name,offset);
  showPage(menutabs[t][0]);
  cancelEvent(evt);
  d.getElementById('enterbutton').focus();
}
function ShiftDn(evt){
 Shift = true;
}
function ShiftUp(evt){
 Shift = false;
}
function pageDown(evt){
 try{handle(-10);cancelEvent(evt);}catch(e){}
}
function lineDown(evt){
 try{handle(-1);cancelEvent(evt);}catch(e){}
}
function pageUp(evt){
 try{handle(10);cancelEvent(evt);}catch(e){}
}
function lineUp(evt){
 try{handle(1);cancelEvent(evt);}catch(e){}
}
function Home(evt){
 try{handle(100);cancelEvent(evt);}catch(e){}
}
function End(evt){
 try{handle(-100);cancelEvent(evt);}catch(e){}
}
// KEY COMMANDS
var TAB        =  9;
var ENTER      = 13;
var SHIFT      = 16;
var PAGE_UP    = 33;
var PAGE_DOWN  = 34;
var END        = 35;
var HOME       = 36;
var ARROW_LEFT = 37;
var ARROW_UP   = 38;
var ARROW_RIGHT= 39;
var ARROW_DOWN = 40;

var keyMapDown = new Array();
//keyMapDown[TAB] = Tab;
keyMapDown[ENTER] = Enter;
keyMapDown[SHIFT] = ShiftDn;
keyMapDown[PAGE_UP] = pageUp;
keyMapDown[PAGE_DOWN] = pageDown;
keyMapDown[END] = End;
keyMapDown[HOME] = Home;
keyMapDown[ARROW_LEFT] = lineLeft;
keyMapDown[ARROW_UP] = lineUp;
keyMapDown[ARROW_RIGHT] = lineRight;
keyMapDown[ARROW_DOWN] = lineDown;

var keyMapUp = new Array();
keyMapUp[SHIFT] = ShiftUp;

var Shift = false;

setMouse();
 
function addListener(a,b,c,d){if(a.addEventListener){a.addEventListener(b,c,d);return true;}else if(a.attachEvent){var e=a.attachEvent("on"+b,c);return e;}else{alert("Handler could not be attached");}}

//
// Add the keydown listner to the document object for global capture
bind(document, 'keydown', keyMapDown, handleKeystroke);
bind(document, 'keyup', keyMapUp, handleKeystroke);
