// JS UTILS FOR SPEED TEST (www.test-speed.com)
var loc = document.location.href;
function getURLValue(n) {if(loc.indexOf(n+'=') != -1) {v=loc.substring(loc.indexOf(n+'=')+n.length+1,loc.length); if(v.indexOf('&') != -1) v=v.substring(0,v.indexOf('&')); return v;} return '';}
function getCookieValue(nm) {var c=document.cookie; var x=c.indexOf(nm+'='); if(x == -1) return null; var y=x+nm.length; var z=c.indexOf(';',y); if(z == -1) z=c.length; var v=c.substring(y,z); if(v.charAt(0) == '=') v=v.substring(1,v.length); return v;}
// turning off for SP2 fix
// function launchPop(pageid){win = window.open('st-tshirt-pop.html',pageid,'width=210,height=186'); win.focus()}

isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;
isHot=false;

function ddInit(e){
  topDog=isIE ? "BODY" : "HTML";
  whichDog=isIE ? document.all.theLayer : document.getElementById("theLayer");  
  hotDog=isIE ? event.srcElement : e.target;  
  while (hotDog.id!="titleBar"&&hotDog.tagName!=topDog){
    hotDog=isIE ? hotDog.parentElement : hotDog.parentNode;
  }  
  if (hotDog.id=="titleBar"){
    offsetx=isIE ? event.clientX : e.clientX;
    offsety=isIE ? event.clientY : e.clientY;
    nowX=parseInt(whichDog.style.left);
    nowY=parseInt(whichDog.style.top);
    ddEnabled=true;
    document.onmousemove=dd;
  }
}

function dd(e){
  if (!ddEnabled) return;
  whichDog.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx; 
  whichDog.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
  return false;  
}


document.onmousedown=ddInit;
document.onmouseup=Function("ddEnabled=false");

var pop = '';
function launchPop(f){
	if(f){visi="visible";
	} else {visi="hidden";}
		if(document.layers){
		document.theLayer.visibility=visi;
	} if(document.all){
		document.all.theLayer.style.visibility=visi;
	} if(document.getElementById){
		document.getElementById("theLayer").style.visibility=visi;
	}
} 

function jumpTo(pageid) {
	if (pageid != "" ) {
    showorhide1(1);
	}
}

function gotopageid(pageid) {
	document.location.href=pageid;
}

function startTimer(pageid) {
  if(pageid.indexOf('http://www.') == 0) {
   if(loc.indexOf('http://www.local.') == 0 || loc.indexOf('http://my.local.') == 0) {
	pageid = 'http://www.local.'+pageid.substring('http://www.'.length,pageid.length);
   }  
  }
  var start = (new Date()).getTime();
  parent.frames["bottomwindow"].location=pageid+'?start='+start;
}

function stopTimer() {
  var pageid = loc.substring(loc.lastIndexOf("/")+1,loc.lastIndexOf("."));
  var start = getURLValue('start');
  var prev_time = getCookieValue('prev_time_'+pageid+'_'+start);
  
 launchPop(pageid);	

  if(start != null && start.length > 0) {
    var diff = null;
    if(prev_time != null && prev_time > 0) {
      // just a reload or back, use previous cookie value
      diff = prev_time;
    } else {
      var stop = (new Date()).getTime();
      diff = stop - start;
      document.cookie='prev_time_'+pageid+'_'+start+'='+diff;
    }  
    if (document.layers) { 
  	  document.layers['joust'].document.open();
	  document.layers['joust'].document.write("<font face=\"Arial,Helvetica,sans-serif\" size=\"+1\" color=\"#4780D1\"><b>"+diff/1000+"</b> Sec.</font>");
    } else { 
      theSiteName = document.getElementById("joust");
      theSiteName.innerHTML = "<font face=\"Arial,Helvetica,sans-serif\" size=\"+1\" color=\"#4780D1\"><b>"+diff/1000+"</b> Sec.</font>";
    }
  }  
  //if (document.layers) { 
	//document.layers['joust'].document.open();
	//document.layers['joust'].document.write("<font face=\"Arial,Helvetica,sans-serif\" size=\"+1\" color=\"#4780D1\"><b>"+diff/1000+"</b> Sec.</font>");
  //} else { 
    //theSiteName = document.getElementById("joust");
    //theSiteName.innerHTML = "<font face=\"Arial,Helvetica,sans-serif\" size=\"+1\" color=\"#4780D1\"><b>"+diff/1000+"</b> Sec.</font>";
  //}
}
