///////////////////////////////////////////
//commonFunctions.js
//maintained by stuller
//last updated 1/18/2006
//see Confluence for documentation
//do not modify without permission
///////////////////////////////////////////

///////////////////////////////////////////
//global variables
///////////////////////////////////////////
var imageID = "";
var imageSRC = "";
var ie=document.all
var dom=document.getElementById
var ns4=document.layers

///////////////////////////////////////////
//popup window
///////////////////////////////////////////
function popUpWindow(URL, windowName, width, height, left, top) {
  popUpWin = open(URL, windowName, 'toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=yes,scrollbars=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

///////////////////////////////////////////
//show/hide div
///////////////////////////////////////////
function showHide(elementID) {
		if (document.getElementById(elementID).style.display == 'none') {
			document.getElementById(elementID).style.display = 'block';
		} else {
			document.getElementById(elementID).style.display = 'none';
		}
}

///////////////////////////////////////////
//change css class
///////////////////////////////////////////
function changeClass(myElementID,newClassName) {
document.getElementById(myElementID).className = newClassName;
}

///////////////////////////////////////////
//change image src
///////////////////////////////////////////
function changeImage(oldSrcName, newSrcPath) {
	for(i=0; i<document.images.length; i++) {
		if(document.images[i].src.indexOf(oldSrcName) != -1) {
			document.images[i].src = newSrcPath;
		}
	}
}

///////////////////////////////////////////
//get cookie
///////////////////////////////////////////
function getCookie(name) { 
  var arg = name + "="; 
  var alen = arg.length; 
  var clen = document.cookie.length; 
  var i = 0; 
  while (i < clen) { 
    var j = i + alen; 
    if (document.cookie.substring(i, j) == arg) 
      return getCookieVal (j); 
    i = document.cookie.indexOf(" ", i) + 1; 
    if (i == 0) break; 
  } 
return null; 
} 

///////////////////////////////////////////
//set cookie
///////////////////////////////////////////
function setCookie(name,value,expires,path,domain,secure) { 
  document.cookie = name + "=" + escape (value) + 
    ((expires) ? "; expires=" + expires.toGMTString() : "") + 
    ((path) ? "; path=" + path : "") + 
    ((domain) ? "; domain=" + domain : "") + 
    ((secure) ? "; secure" : ""); 
} 

///////////////////////////////////////////
//delete cookie
///////////////////////////////////////////
function deleteCookie(name,path,domain) { 
  if (getCookie(name)) { 
    document.cookie = name + "=" + 
      ((path) ? "; path=" + path : "") + 
      ((domain) ? "; domain=" + domain : "") + 
      "; expires=Thu, 01-Jan-70 00:00:01 GMT"; 
  } 
} 

///////////////////////////////////////////
//needed for cookie stuff
///////////////////////////////////////////
function getCookieVal (offset) { 
  var endstr = document.cookie.indexOf(";", offset); 
  if (endstr == -1) 
    endstr = document.cookie.length; 
  return unescape(document.cookie.substring(offset, endstr)); 
} 

///////////////////////////////////////////
//first time visitor popup
///////////////////////////////////////////

function firstTimeVisitorPopup(popupURL,width,height) {
  var url = location.href.toLowerCase()
  var index = 0;
  var pos = 0;
  var siteid = 0;
  var cookieyear;
	var popupURL = popupURL;

  if((index = url.indexOf("sid")) != -1 || (index = url.indexOf("SID")) != -1 || (index = url.indexOf("xid")) != -1 || (index = url.indexOf("XID")) != -1) {
    siteid = url.substring(index+4, url.indexOf('&', index+4));
    pos = document.cookie.indexOf("firsttime" + siteid + "=");

    if (pos == -1 && siteid != 0) {
      cookieyear = new Date();
      cookieyear.setFullYear(cookieyear.getFullYear() + 10);
      document.cookie = "firsttime" + siteid + "=1" +
                        "; expires=" + cookieyear.toGMTString();
      window.open(popupURL,'hello','width='+width+',height='+height+',scrollbars=NO,menubar=NO,status=NO,toolbar=NO,location=NO');
    }
  }
}

///////////////////////////////////////////
//dropin
///////////////////////////////////////////

var bouncelimit=0 //(must be divisible by 8)
var direction="up"

function showDropIn(divName){

if (!dom&&!ie&&!ns4)
return
crossobj=(dom)?document.getElementById(divName).style : ie? document.all.dropin : document.dropin
scroll_top=(ie)? document.body.scrollTop : window.pageYOffset
crossobj.top=scroll_top-250
crossobj.visibility=(dom||ie)? "visible" : "show"
dropstart=setInterval("dropin()",50)
}

function dropin(){
scroll_top=(ie)? document.body.scrollTop : window.pageYOffset
if (parseInt(crossobj.top)<100+scroll_top)
crossobj.top=parseInt(crossobj.top)+40
else{
clearInterval(dropstart)
bouncestart=setInterval("bouncein()",50)
}
}

function bouncein(){
crossobj.top=parseInt(crossobj.top)-bouncelimit
if (bouncelimit<0)
bouncelimit+=8
bouncelimit=bouncelimit*-1
if (bouncelimit==0){
clearInterval(bouncestart)
}
}

function dismissbox(){
if (window.bouncestart) clearInterval(bouncestart)
crossobj.visibility="hidden"
}