/* Generic Aró site scripts */

// Used to trigger events when the page loads
// see http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}



// Attaches a javascript action to an object event
// eg: addEvent(window,"load",function(){ alert('hello!'); });
function addEvent( obj, type, fn ) {
   if ( obj.attachEvent ) {
      obj['e'+type+fn] = fn;
      obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
      obj.attachEvent( 'on'+type, obj[type+fn] );
   } else
      obj.addEventListener( type, fn, false );
}
function removeEvent( obj, type, fn ) {
   if ( obj.detachEvent ) {
      obj.detachEvent( 'on'+type, obj[type+fn] );
      obj[type+fn] = null;
   } else
      obj.removeEventListener( type, fn, false );
}



//Opens links with class="newWindow" in... a new window!
function newWindowSetup() {
  if (!document.getElementsByTagName) return false;
  var links = document.getElementsByTagName("a");
  for (var i=0; i < links.length; i++) {
    if (links[i].className.match("newWindow")) {
      links[i].onclick = function() {
        window.open(this.href);
        return false;
      }
    }
  }
}
addLoadEvent(newWindowSetup);



// Parses email addresses to deter spambots, returns a mailto link
function linkEmailSetup() {
  if(!document.getElementsByTagName) return;
  var allElts = document.getElementsByTagName("*");
  if(allElts.length == 0 && document.all) 
    allElts = document.all; //hack for IE5
  for(var i=0; i<allElts.length; i++) {
    var elt = allElts[i];
    var className = elt.className || elt.getAttribute("class") 
      || elt.getAttribute("className");
    if(className && className.match(/\belectronic-mail\b/)
        && elt.firstChild.nodeType == 3) {
      var addr = elt.firstChild.nodeValue;
      addr = addr.replace(/[ \[\{\(\|\/\\]at[ \]\}\)\|\/\\]/i, "@")
        .replace(/[ \[\{\(\|\/\\](dot|period)[ \]\}\)\|\/\\]/gi, ".");
      var lnk = document.createElement("a");
      lnk.setAttribute("href","mailto:"+addr);
      lnk.appendChild(document.createTextNode(addr));
      elt.replaceChild(lnk, elt.firstChild);
    }
  }
}
addLoadEvent(linkEmailSetup);



// Popup window
function soopaPopSetup() {
	var a;
	for (var i = 0; (a = document.links[i]); i++) {
		if (a.target && a.target.indexOf("_soopaPop") == 0) {
			a.onclick = soopaPop;
		}
	}
}
function soopaPop() {
	var a = this.target.split(":");
	var sFeatures = a[1];
	window.open(this.href, a.length > 2 ? a[2] : String((new Date()).getTime()), sFeatures);
	return false;
	alert("hi")
}
addLoadEvent(soopaPopSetup);



// returns control of document element
function g(o) { return document.getElementById(o); }



// shows a div
function openDiv(obj) { g(obj).style.display = ''; }



// hides a div
function closeDiv(obj) { g(obj).style.display = 'none'; }



// toggles a div
function toggleDiv(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
	
}

// accessible popup
function popUp(strURL,strType,strWidth,strHeight) {
var strOptions="";
if (strType=="console") strOptions="resizable,height="+strHeight+",width="+strWidth;
if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
window.open(strURL, 'newWin', strOptions);
}

// externalLinks - for "target=_blank like" action
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
		anchor.getAttribute("rel") == "external")
		anchor.target = "_blank";
	}
}
window.onload = externalLinks;


function bookmark(url, title){
    if (window.sidebar) window.sidebar.addPanel(title, url,"");
    else if( window.opera && window.print )
    {
    var mbm = document.createElement('a');
    mbm.setAttribute('rel','sidebar');
    mbm.setAttribute('href',url);
    mbm.setAttribute('title',title);
    mbm.click();
    }
    else if( document.all ) window.external.AddFavorite( url, title);
}


/*
 * Clear Default Text: functions for clearing and replacing default text in
 * <input> elements.
 */
addEvent(window, 'load', init, false);

function init() {
    var formInputs = document.getElementsByTagName('input');
    for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];
        
        if (theInput.type == 'text' && theInput.className.match(/\bcleardefault\b/)) {  
            /* Add event handlers */          
            addEvent(theInput, 'focus', clearDefaultText, false);
            addEvent(theInput, 'blur', replaceDefaultText, false);
            
            /* Save the current value */
            if (theInput.value != '') {
                theInput.defaultText = theInput.value;
            }
        }
    }
}

function clearDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == target.defaultText) {
        target.value = '';
    }
}

function replaceDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == '' && target.defaultText) {
        target.value = target.defaultText;
    }
}




/***********************************************
* Sequential Content Revealer- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
***********************************************/

var contentpause = 5000; // interval = 20 seconds //customize time each content should pause for before the next one is revealed (1000=1 second)
var once_session = 0; //Should "reveal" animation only be applied once per browser session? (0=no, 1=yes):

var curobjindex = 0;
var orderoffset = 1000;

function collectElementbyClass(){
   var classname="showNewProduct";
   glidearray = new Array();
   
   var inc = 0;
   var alltags = document.all? document.all : document.getElementsByTagName("*")
   
      for(i=0; i < alltags.length; i++){
         if (alltags[i].className == classname){
            glidearray[inc++] = alltags[i];
            glidearray[inc-1].displayorder=(glidearray[inc-1].getAttribute("displayorder"))? parseInt(glidearray[inc-1].getAttribute("displayorder")) : inc + orderoffset
         }
      }
      
         if (glidearray.length > 0){
            glidearray.sort(compareorder);
            seqreveal();
        }

}

function seqreveal(){
   
   if (curobjindex < glidearray.length){
      
      glidearray[curobjindex].style.visibility="visible";
      
      if(curobjindex > 0)
         glidearray[curobjindex - 1].style.visibility="hidden";
             
      var actualpause=(glidearray[curobjindex].getAttribute("pausesec"))? parseFloat(glidearray[curobjindex].getAttribute("pausesec"))*1000 : parseFloat(contentpause)
         glidetimer = setTimeout("seqreveal()", actualpause);
         curobjindex++;
   }  
   
}




function compareorder(a, b){
   return a.displayorder-b.displayorder
}


function get_cookie(Name) {
   var search = Name + "="
   var returnvalue = ""

      if (document.cookie.length > 0) {
         offset = document.cookie.indexOf(search)
            if (offset != -1) {
               offset += search.length
               end = document.cookie.indexOf(";", offset)
            if (end == -1)
               end = document.cookie.length;
               returnvalue=unescape(document.cookie.substring(offset, end))
      }
}

return returnvalue;
}


if (once_session && get_cookie("textdisplayed")=="" || !once_session){
   if (window.addEventListener)
      window.addEventListener("load", collectElementbyClass, false)
   else if (window.attachEvent)
      window.attachEvent("onload", collectElementbyClass)
   else if (document.getElementById)
      window.onload=collectElementbyClass

   if (once_session)
      document.cookie="textdisplayed=yes"
   }
   else{
      document.write('<style>\n.showNewProduct{visibility:visible;}\n</style>')
   } 
