/*
	Utility for the ABW site should go here
*/
// var
function toggleJobPostDisplay(itemNumber){
	var jobDetails = document.getElementById("jobDetails" + itemNumber);
	var jobToggleImage = document.getElementById("jobToggleImage" + itemNumber);
	if(jobDetails.style.display == "block"){
		jobDetails.style.display = "none";
		jobToggleImage.src = "/WwsImages/NewLook/iconPlus.gif";
	}else{
		jobDetails.style.display = "block";
		jobToggleImage.src = "/WwsImages/NewLook/iconMinus.gif";
	}
}

function toggleOurTeamPhoto(obj,contactPhoto){     
 var contactPhoto_obj = document.getElementById("contactPhoto");
 if(contactPhoto_obj.style.display == "none"){
  contactPhoto_obj.style.display = "block";
  try{
   //remove any elements in the object
   while (contactPhoto_obj.firstChild){
    contactPhoto_obj.removeChild(contactPhoto_obj.firstChild);
   }
  }
  catch(err)
  {
  }  
 
  newImg=document.createElement("img");
  newImg.setAttribute("src",contactPhoto);
  newImg.onload = function(){
   var currentMaxWidth = getPos(this).x + this.width;
   if (currentMaxWidth > getBrowserWidth()){
    imgWidthAdjustment = currentMaxWidth - getBrowserWidth() + 20;
    var contactPhoto_obj = document.getElementById("contactPhoto");
    contactPhoto_obj.style.left = (getPos(obj).x - imgWidthAdjustment).toString() + "px";
   }
   newImg.style.display = "block";  
  }  
  contactPhoto_obj.appendChild(newImg);
  contactPhoto_obj.style.top = (getPos(obj).y + obj.getElementsByTagName("img")[0].height + 2).toString() + "px";
  contactPhoto_obj.style.left = (getPos(obj).x).toString() + "px";
  try{
   if (newImg.width > 0){
    var currentMaxWidth = getPos(obj).x + newImg.width;
    if (currentMaxWidth > getBrowserWidth()){
     imgWidthAdjustment = currentMaxWidth - getBrowserWidth() + 20;
     var contactPhoto_obj = document.getElementById("contactPhoto");
     contactPhoto_obj.style.left = (getPos(obj).x - imgWidthAdjustment).toString() + "px";
    }
   }
  }
  catch(err)
  {
  } 
  
  obj.onmouseout = function(){
   var contactPhoto_obj = document.getElementById("contactPhoto");
   contactPhoto_obj.style.display = "none";
  }
 }
}

function msPlayerCreate(mediaURL){ 
 var msPlayerObj = document.getElementById("msPlayer");
 msPlayerObj.style.display = "block";
 while ( msPlayerObj.hasChildNodes() )
 {
  msPlayerObj.removeChild( msPlayerObj.firstChild );       
 }
 var newDiv = document.createElement("div");
 newDiv.style.paddingBottom = "20px";
 newDiv.insertBefore(newCopyEl("div","Sorry, that video format is not supported."),newDiv.firstChild);
 msPlayerObj.appendChild(newDiv);
 setTimeout("msPlayerDelete()",5000);
}
function msPlayerDelete(){ 
 var msPlayerObj = document.getElementById("msPlayer"); 
 msPlayerObj.style.display = "none";
}
function setChartItems(bottle){
	var chartEl = document.getElementById("comparisonChart");
	var bottleAbv = bottle.abv;
	var bottleMalts = bottle.malts;
	var bottleHops = bottle.hops;
	var bottleRecommendedGlassware = bottle.recommended_glassware;
	var bottleBeerCategorystyle = bottle.beer_categorystyle;
	
	setChartItemNum(1,bottleAbv);
	setChartItemNum(2,bottleMalts);
	setChartItemNum(3,bottleHops);
	setChartItemNum(4,bottleRecommendedGlassware);
	setChartItemNum(5,bottleBeerCategorystyle);

	if(bottleAbv == undefined && bottleMalts == undefined && bottleHops == undefined && bottleRecommendedGlassware == undefined && bottleBeerCategorystyle == undefined){
		chartEl.style.display = "none";
	}else{
		chartEl.style.display = "block";
	}
}
function setChartItemNum(itemNum,itemCopy){
	var cItem = document.getElementById("chartItem" + itemNum);
	while (cItem.firstChild){
		cItem.removeChild(cItem.firstChild);
	}
	if (itemCopy != undefined){
		cItem.insertBefore(newCopyEl("div",itemCopy),cItem.firstChild);
	}else{
		cItem.insertBefore(newCopyEl("div"," "),cItem.firstChild);
	}
}
function getPos (obj) { 
	var pos = {
		x: obj.offsetLeft||0, y: obj.offsetTop||0};
		while(obj = obj.offsetParent) { 
			pos.x += obj.offsetLeft||0; 
			pos.y += obj.offsetTop||0;
		} 
	return pos;
}
function newCopyEl(el,copy){
	var newEl = document.createElement(el);
	var newTxt = document.createTextNode(copy);
	newEl.appendChild(newTxt);
	return newEl;
}

function popWin(url,w,h) {
            win=window.open(url, '_blank', 'width='+w+',height='+h+',scrollbars=yes,resizable=1');
}
function delobject() {
		if (confirm("Are you sure you want to delete this?")) { return true; }
		else { return false; }
}
function funcConfirmForward(pMsg, pUrl) {
   if(confirm(pMsg)) {
      location.replace(pUrl);
   }
}

function openAdminWin(strPath,strName){
   var oldWindow, newWindow

   // find browser capabilities
   var ns = (document.layers) ? 1:0;
   var ie = (document.all) ? 1:0;

   if(ie){
      newWindow=window.open(strName,strPath,'width=770,height=520,left=0,top=0,status=yes,menu=no,location=no,toolbar=no,resizable=yes,scrollbars=yes');
   }

   if(ns){
      newWindow=window.open(strName,strPath,'width=770,height=520,left=0,top=0,status=yes,menu=no,location=no,toolbar=no,resizable=yes,scrollbars=yes');
   }

   if (newWindow.opener==null) newWindow.opener = top;
   newWindow.focus();
   return false;
}
      function funcConfirmDeleteGalleryImage(pMsg, pUrl) {
         if(confirm(pMsg)) {
            //win=window.open(pUrl, '_blank', 'width=300,height=300,scrollbars=no,resizable=0');
            location.replace(pUrl);
         }
      }

function getBrowserWidth(){
 if (document.all){
  wW=document.body.offsetWidth;
 }
 else
 {
  wW=window.outerWidth;
 }
 return wW;
}
function getBrowserHeight(){
 if (document.all){
  wH=document.body.offsetHeight;
 }
 else
 {
  wH=window.outerHeight;
 }
 return wH;
}


/*
    New code from Adam Longaway
        - Should put a cap on overly large Partner Logo images, 23 October 2008
        - Revised: 24 October 2008 (Adam Longaway)
*/
var abwUtilites = {
 init : function() {
  var errorMsg = "";
  var partnerLogoDiv = document.getElementById("partnerLogo");
  if (partnerLogoDiv != null){
   var partnerLogoImg = partnerLogoDiv.getElementsByTagName("img");
   if (partnerLogoImg.length > 0){
    if (partnerLogoImg[0].width > 228){   
     errorMsg += "\nThe Partner Logo Image is " + partnerLogoImg[0].width + "px wide. Please use a maximum width of 228 pixels.";
     partnerLogoImg[0].width = 228;
    }
    if (partnerLogoImg[0].height > 54){
     errorMsg += "\nThe Partner Logo Image is " + partnerLogoImg[0].height + "px high. Please use a maximum height of 54 pixels.";
     partnerLogoImg[0].height = 54;    
    }
    if(errorMsg.length > 0){
     alert("Errors: " + errorMsg);
    }
   }
  }
 },
 addEventListener : function (el, event, func) {
  try {
   el.addEventListener(event, func, false);
  } catch (e) {
   try {
    el.detachEvent('on'+ event, func);
    el.attachEvent('on'+ event, func);
   } catch (e) {
    el['on'+ event] = func;
   }
  } 
 }
};
abwUtilites.addEventListener(window, 'load', abwUtilites.init);