// pop up window
// javascript: popup(name,page_url,width,height)
function popup (name,page,width,height){
  id = window.open(page,name,'toolbar=no,location=no,scrollbars=yes,width='+width+',height=' +height);
  id.focus();
}

/// TOGGLE LAYER
function toggleLayer(whichLayer){
  if (document.getElementById){
    // this is the way the standards work
    var style2 = document.getElementById(whichLayer).style;
    style2.display = style2.display? "":"block";
  }
  else if (document.all){
    // this is the way old msie versions work
    var style2 = document.all[whichLayer].style;
    style2.display = style2.display? "":"block";
  }
  else if (document.layers){
    // this is the way nn4 works
    var style2 = document.layers[whichLayer].style;
    style2.display = style2.display? "":"block";
  }
}

// Check for Details Page
var _item_details = document.getElementById("ctl00_centerColumn");

if(_item_details && _item_details.innerHTML.match(/product\-detail/)){
  var IDdisc = new Array();
  var IDnew_html = '';
  var IDmodified = false;
   
  if(disclaimers){
    for(_d in disclaimers){
      IDdisc[_d] = new Array(4); 
      IDdisc[_d]["active"] = false;
      IDdisc[_d]["name"] = disclaimers[_d]; 
      IDdisc[_d]["skus"] = disc_skus[_d];
      IDdisc[_d]["html"] = disc_html[_d];	  
    }
    for(_x in IDdisc){IDdisclaimer_check(_x);}
  }
  if(IDmodified){
    var centerColumn = document.getElementById("ctl00_centerColumn");
    if(centerColumn){centerColumn.innerHTML = IDnew_html + centerColumn.innerHTML;}
  }
}
///////////////////
// IDdisclaimer_check
function IDdisclaimer_check(_xd){
  // prod-detail-part-value">01200-0000
  // catch prescription items (SKU starts with 012)

  var patt1=new RegExp(">012");
  var patt2=new RegExp(">003");
  var patt3=new RegExp(">007");

  if(_item_details.innerHTML.match(patt1) && IDdisc[_xd].name == 'prescriptions'){
    IDdisc[_xd].active=true;
  }	
  else if(_item_details.innerHTML.match(patt2) && IDdisc[_xd].name == 'vaccines'){
    IDdisc[_xd].active=true;
  }	
  else if(_item_details.innerHTML.match(patt3) && IDdisc[_xd].name == 'vaccines'){
    IDdisc[_xd].active=true;
  }	
  else{
    for(_sku in IDdisc[_xd].skus){
      if(_item_details.innerHTML.indexOf(IDdisc[_xd]["skus"][_sku]) >= 0){
        IDdisc[_xd].active=true;
	break;
      }
    }
  }

  if(IDdisc[_xd].active){
    IDnew_html += IDdisc[_xd].html;
    IDmodified = true;
  }	
}

///////////////////
// getElementsByClassfunction getElementsByClass(searchClass,node,tag){
  var classElements = new Array();
  if (node == null){node = document;}
  if (tag == null){tag = '*';}
  var els = node.GetElementsByTagName(tag);
  var elsLen = els.Length;
  var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
  for (I = 0, j = 0; I < elsLen; I++){
    if (pattern.Test(els[I].ClassName)){
      classElements[j] = els[I];
      j++;
    }
  }
  return classElements;
}
