var LangOptsShow = 'Add to Cart';
var LangOptsHide = 'Hide Options';
var ClassOptsShow = 'AddToCartOver';
var ClassOptsHide = 'HideOptionsOver';
var bClicked = false;

function ToggleOptClass(el,bSet)
{
     if(el.nodeName.toLowerCase()=='li')
     {
          if(bSet)
          {
               var aChildNodes = el.parentNode.childNodes;
               for(var i=0;i<aChildNodes.length;i++)
               {
                    aChildNodes[i].className = 'out';
               }
          }

          if(el.className=='selected'){return;}
          if(!bClicked)
          {
               switch(el.className)
               {
                    case 'over':
                         el.className='out';
                    break;

                    default:
                    if(bSet)
                    {
                         el.firstChild.checked=true;
                         el.className='selected';
                    }
                    else
                    {
                         el.className = 'over';
                    }
                    break;
               }
          }
          else
          {
               bClicked=false;
          }
     }
}
function AddQnty(el,qnty)
{
     var el = document.getElementById(el);
     el.value = parseInt(parseFloat(el.value)+parseFloat(qnty));
     if(el.value<0){el.value=0;}
}

function OpenImagePopup(el,src,width,height)
{
     /*var win = window.open(src,"","height="+height+",width="+width+",status=no,toolbar=no,menubar=no,location=no");
     win.document.writeln('<html>');
     win.document.writeln('<head>');
     win.document.writeln('<title>Image Popup</title>');
     win.document.writeln('<style type="text/css">body{margin:0px;}</style>');
     win.document.writeln('</head>');
     win.document.writeln('<body>');
     win.document.writeln('<img src="'+src+'">');
     win.document.writeln('</body>');
     win.document.writeln('</html>');
     win.document.close();*/
     el.setAttribute('href','javascript:void(0);');
     el.setAttribute('target','');
     var win = window.open('/assets/userfiles/index.php?GetFile='+src,null,"height="+height+",width="+width+",status=no,toolbar=no,menubar=no,location=no");
}
function HideProductOptions()
{
     var opt = 0;
     var aInputs = document.body.getElementsByTagName('INPUT');
     alert('hello');
     for(var i=0;i<aInputs.length;i++)
     {
          if(aInputs[i].name.substr(0,7)=='ProdOpt')
          {
               aInputs[i].style.display = 'none';
               if(!aInputs[i].checked)
               {
                    aInputs[i].parentNode.className = 'out';
               }
          }
     }

     var aDivs = document.body.getElementsByTagName('DIV');
     for(var i=0;i<aDivs.length;i++)
     {
       if(i>1000){break;}
          if(aDivs[i].getAttribute('classname')=='ProdOpts' || aDivs[i].getAttribute('class')=='ProdOpts')
          {
                 var elSpan = document.createElement('span');
                 elSpan.setAttribute('className','ExpandOpts');
                 elSpan.setAttribute('class','ExpandOpts');
                 var elA = document.createElement('a');
                 elA.setAttribute('href','javascript:void(0);');
                 elA.onclick = function(){ToggleOpts(this);};
				 //Only hide options if there are hundreds of the buggers
				 if(aDivs[i].getElementsByTagName('LI').length>10)
				 {
	                 var elT = document.createElement('input');
    	             elT.setAttribute('type','button');
        	         elT.setAttribute('value',LangOptsShow);
            	     elT.setAttribute('className','AddToCartOff');
                	 elT.setAttribute('class','AddToCartOff');
	                 elT.onmouseover = function(){ButtonRollover(this);}
    	             elT.onmouseout = function(){ButtonRollover(this);}
        	         elA.appendChild(elT);
            	     elSpan.appendChild(elA);
                	 aDivs[i].parentNode.appendChild(elSpan);
	                 aDivs[i].style.display = 'none';
				}
                 opt++;
           }
     }
}
function ToggleOpts(el)
{
     var div = el.parentNode.parentNode.firstChild;
     if(div.style.display == 'none')
     {
          div.style.display = 'block';
          el.firstChild.setAttribute('value',LangOptsHide);
          el.firstChild.setAttribute('className',ClassOptsHide);
          el.firstChild.setAttribute('class',ClassOptsHide);
     }
     else
     {
          div.style.display = 'none';
          el.firstChild.setAttribute('value',LangOptsShow);
       el.firstChild.setAttribute('className',ClassOptsShow);
       el.firstChild.setAttribute('class',ClassOptsShow);
     }
}
function ButtonRollover(el)
{
     var strClass = new String(el.getAttribute('className'));
     if(strClass.substr(strClass.length-3,3) == 'Off')
     {
          el.setAttribute('className',strClass.substr(0,strClass.length-3)+'Over');
     }
     else
     {
          el.setAttribute('className',strClass.substr(0,strClass.length-4)+'Off');
     }
}
