function item(id){return document.getElementById(id)}

function make_bookmark()
{
var name=document.location.host
var url='http://'+name+'/'
try{window.external.AddFavorite(url, name)}
catch(exc){alert("Sorry, your browser doesn't support bookmarks")}
/*try{var img=new Image();img.src=url+'bookmark.php'}
catch(exc){}*/
return false
}

function popImg(src)
{
var w=380,h=350,left=(screen.availWidth-w)/2,top=(screen.availHeight-h)/2
var wnd=window.open("",'blistWind','toolbar=0,location=0,directories=0,menubar=0,resizable,scrollbars=0,width='+w+',height='+h+',top='+top+',left='+left)
wnd.document.write("<title>Click it to close</title><style>html,body,table{margin:0px;padding:0px;height:100%;width:100%;}</style><body name=body><table><tr><th><img src='"+src+"'></table><script>document.body.onclick=function(){close()}</script></body>")
wnd.focus()
return false
}

var async_obj=null
function livechat_check_finish()
{
  if (async_obj.readyState == 4 && async_obj.responseText.indexOf('OK')>=0)
  {
    item('livechat').innerHTML = "<DIV onclick='window.open(\"http://chat.helponclick.com/livechat/livechat.php?usrname=rxpartners&usr_id=5289\",\"chat_login\",\"top=200,left=200,width=450,height=400,scrollbars=no,status=0,toolbar=no,location=no,resizable=no\")' style='cursor:pointer;cursor:hand'><img src='imgs/livechat-on.gif' alt='Click for Live Chat'/></div>"
  }
}

function livechat_check(url)
{
  if (!async_obj)
  {
    try { async_obj = new ActiveXObject("Msxml2.XMLHTTP") }
    catch (e) {
      try { async_obj = new ActiveXObject("Microsoft.XMLHTTP") }
      catch (e) {
	try { async_obj = new XMLHttpRequest() } catch (e) {}
      }
    }
  }

  if (async_obj)
  {
    async_obj.open("GET", 'livechat-status.php', true)
    async_obj.onreadystatechange = livechat_check_finish
    async_obj.send(null)
  }
}


/*  Behaviour v1.1 by Ben Nolan, June 2005. http://ripcord.co.nz/behaviour/ */   

document.Behaviour=new Object({
list: new Array,

register: function(sheet){ document.Behaviour.list.push(sheet) },

start: function(){ document.Behaviour.addLoadEvent(function(){ document.Behaviour.apply() }) },

apply: function(){
  for (h=0;sheet=document.Behaviour.list[h];h++)
    for (selector in sheet){
      var list = document.getElementsBySelector(selector)
      if (list)
	for (i=0;element=list[i];i++)
	  sheet[selector](element)
    }
},

addLoadEvent:function(func){
  var oldonload = window.onload
  if (typeof window.onload != 'function')
    window.onload = func
  else window.onload = function() { oldonload(); func() }
}
})

document.Behaviour.start()

/*   The following code is Copyright (C) Simon Willison 2004.*/

function getAllChildren(e) { return e.all?e.all:e.getElementsByTagName('*') }

document.getElementsBySelector = function(selector) {
if (!document.getElementsByTagName) {
return new Array();
}
var tokens = selector.split(' ');
var currentContext = new Array(document);
for (var i = 0; i < tokens.length; i++) {
token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');;
if (token.indexOf('#') > -1) {
var bits = token.split('#');
var tagName = bits[0];
var id = bits[1];
var element = document.getElementById(id);
if (tagName && element.nodeName.toLowerCase() != tagName) {
return new Array();
}
currentContext = new Array(element);
continue;
}
if (token.indexOf('.') > -1) {
var bits = token.split('.');
var tagName = bits[0];
var className = bits[1];
if (!tagName) {
tagName = '*';
}
var found = new Array;
var foundCount = 0;
for (var h = 0; h < currentContext.length; h++) {
var elements;
if (tagName == '*') {
elements = getAllChildren(currentContext[h]);
} else {
elements = currentContext[h].getElementsByTagName(tagName);
}
for (var j = 0; j < elements.length; j++) {
found[foundCount++] = elements[j];
}
}
currentContext = new Array;
var currentContextIndex = 0;
for (var k = 0; k < found.length; k++) {
if (found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b'))) {
currentContext[currentContextIndex++] = found[k];
}
}
continue; 
}
if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) {//"
var tagName = RegExp.$1;
var attrName = RegExp.$2;
var attrOperator = RegExp.$3;
var attrValue = RegExp.$4;
if (!tagName) {
tagName = '*';
}
var found = new Array;
var foundCount = 0;
for (var h = 0; h < currentContext.length; h++) {
var elements;
if (tagName == '*') {
elements = getAllChildren(currentContext[h]);
} else {
elements = currentContext[h].getElementsByTagName(tagName);
}
for (var j = 0; j < elements.length; j++) {
found[foundCount++] = elements[j];
}
}
currentContext = new Array;
var currentContextIndex = 0;
var checkFunction; 
switch (attrOperator) {
case '=':
checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
break;
case '~':
checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); };
break;
case '|':
checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); };
break;
case '^':
checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
break;
case '$':
checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
break;
case '*':
checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
break;
default :

checkFunction = function(e) { return e.getAttribute(attrName); };
}
currentContext = new Array;
var currentContextIndex = 0;
for (var k = 0; k < found.length; k++) {
if (checkFunction(found[k])) {
currentContext[currentContextIndex++] = found[k];
}
}
continue; 
}

if (!currentContext[0]){
return;
}

tagName = token;
var found = new Array;
var foundCount = 0;
for (var h = 0; h < currentContext.length; h++) {
var elements = currentContext[h].getElementsByTagName(tagName);
for (var j = 0; j < elements.length; j++) {
found[foundCount++] = elements[j];
}
}
currentContext = found;
}
return currentContext;
}

var fn_submit = function(el){ el.onclick=function(){ document.forms[0].submit();return false} }

var common_rules={

'a.edit': function(el)
 { el.onclick=function(){window.open(this.href,'edit','toolbar=0');return false} },

'.quicksearch a': function(el)
 {
  el.onclick=function(){
   document.location.href=document.location.protocol+'//'+document.location.host
   +'/?search='+item('search').value
   return false
  }
 },

'.quicksearch input': function(el)
 {
  el.onclick=function(){if(this.value==this.defaultValue)this.value=""}
  el.onblur=function(){if(this.value=="")this.value=this.defaultValue}
 },

'form tfoot a': fn_submit,
'form tfoot button': fn_submit,

'.cart .checkout': function(el){ el.onclick=function(){document.checkout.submit();return false} },

'.cart .update': function(el){ el.onclick=function(){document.cart.submit();return false} },

'.cart .continue': function(el)
 { el.onclick=function(){document.location.pathname='/';return false} },

'.cart img.photo': function(el)
 {
  el.onclick=function(){ return popImg('imgs/pills/blisters/'+el.getAttribute('prod')+'.jpg') }
  el.title="Click to view pills in blister"
 },

'a.bookmark': function(el){ el.onclick=make_bookmark }

};

document.Behaviour.register(common_rules)