var errCount = 0;
function errHandler(msg,url,line) {
  if (document.images) {
    var par_url = parent.location.href;
    if (par_url == location.href) par_url = 'no parent';
    query_string = 'http:\/\/adoole.com/osc/javascriptLog.php?url='+escape(location.href)+'&parent='+escape(par_url)+'&referrer='+escape(document.referrer)+'&browser='+escape(navigator.appName+' '+navigator.appVersion)+'&msg='+escape(msg)+'&line='+escape(line)+'&count='+(++errCount);
    var reporter = new Image();
    reporter.src = query_string;
  }
return true;
}
window.onerror = errHandler;


function checkSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

  setCookie('Width', myWidth,6);
  setCookie('Height', myHeight,6);

  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
}


function displayTime(time)
{
  thisdate= new Date();
  thisdate.setTime(time);
  return thisdate.toLocaleString();

}

function initialize(startTime)
{
    checkSize();
     
    speed = readCookie('speed');
    oldSpeed = speed;

    if( speed == null || speed == "")
    {
      speed = (new Date().getTime() - startTime);
    }
    else
    {
      newspeed = (new Date().getTime() - startTime);
      if( ( 3* newspeed ) < speed )
      {
        speed = newspeed;
      }
      else
      {
        speed = ((Number(speed) + Number(newspeed) )/2);
      }
    }
    setCookie('speed', speed,6);

/*
    noapplet = readCookie('noapplet');
    if( (noapplet == null || noapplet == "") && navigator.javaEnabled())
    {
        setCookie('java', 'true',6);
    }
*/
    //window.status="o sp=" + oldSpeed + " n sp=" +speed +  "j=" + readCookie('java') + ' w=' + readCookie('Width');
    //window.alert( readCookie('Width'));
    //window.alert( readCookie('Height'));
    //window.alert( readCookie('speed'));
    //window.alert( readCookie('java'));

}


function setCookie(cookieName,cookieValue,nHours) {
 var today = new Date();
 var expire = new Date();
 if (nHours==null || nHours==0) nHours=1;
 expire.setTime(today.getTime() + 3600000*nHours);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";path=/;expires="+expire.toGMTString();
}


function readCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}


function arrayToOption(dataArray)
{
  for( var i = 0; i< dataArray.length; i = i+2)
    document.write('<OPTION value="' +  dataArray[i] + '">' + dataArray[i+1] + '</OPTION>');
}

function deleteCookie( name )
{
  if ( readCookie( name ) )
  {
    setCookie(name,'',-1);
  }
}


function addBookmark() { 

 title="Adoole.com " + document.title;
 url=window.location.href;

 if (window.sidebar) { 
 window.sidebar.addPanel(title, url,""); 
 } else if( document.all ) { 
 window.external.AddFavorite( url, title); 
 } else if( window.opera && window.print ) { 
 return true; 
 } 

}


function showPage(url) 
{ 
window.open(unescape(url)); 
} 

function open(url)
{
  window.location.href=url;
}

function Banner(totalBoxes, boxName, data)
{
	this.totalBoxes = totalBoxes;
	this.currentStartLoc = 0;
	this.preLoadNeeded = true;
	this.maxIteration =3;
	this.currentIteration=0;
	this.auto = true;
	this.preLoadImageElement = new Array(this.totalBoxes);
	this.data=data
	this.boxName=boxName;
}



Banner.prototype.addToLoadImageQueue = function(){

    if( !this.preLoadNeeded )
      return;

    var loadLoc = this.currentStartLoc;
	for( var i=0; i<this.totalBoxes; i++ )
	{
	        if( this.preLoadImageElement[i] == null )
	        {
	           this.preLoadImageElement[i] = document.createElement("IMG");
	           //imageElement[i].onerror = addToLoadImageQueue;
	        }

	        if( loadLoc == this.data.length)
	        {
	           this.preLoadNeeded = false;
	           return;
	        }

            this.preLoadImageElement[i].src = this.data[loadLoc][1];

	        loadLoc++;
    }
}


Banner.prototype.changeImages = function(eventFromAuto) {

    if(eventFromAuto && (!this.auto))
      return;

    if (!document.getElementById) return;

    for( var i=0; i<this.totalBoxes; i++ )
    {
	        if( this.currentStartLoc == this.data.length)
	        {
	           this.currentStartLoc =0;
	           this.currentIteration++;
	        }

	        var boxHTML = this.getImageHtml(this.data[this.currentStartLoc][0], this.data[this.currentStartLoc][1], this.data[this.currentStartLoc][2], this.data[this.currentStartLoc][3], this.data[this.currentStartLoc][4]);

            var box = document.getElementById(this.boxName +"_"+ i);
            box.innerHTML = boxHTML;

	        this.currentStartLoc++;
    }


    if( eventFromAuto)
    {
       //preload next set of images
       this.addToLoadImageQueue();

       if( this.currentIteration < this.maxIteration )
       {
          var current = this;
	      setTimeout(function(){
	      current.changeImages(true); }, (this.totalBoxes*2000));
       }
    }

}

Banner.prototype.previous = function()
{
        this.auto = false;
        var newStart = this.currentStartLoc - this.data.length;

        if( newStart < 0 )
          newStart = this.data.length + newStart;

        this.currentStartLoc = newStart;
        this.changeImages(false);
}


Banner.prototype.next = function()
{
      this.auto = false;
      var newStart = this.currentStartLoc + this.totalBoxes;

      if( newStart > this.data.length )
        newStart = newStart-this.data.length;

      this.currentStartLoc = newStart;
      this.changeImages(false);
}

Banner.prototype.getImageHtml = function(name, image, url, price, originalPrice){
 return '<a href="' + url + '"><img src="' + image + '" border="0" alt="' + name + '" title="' + name +
        '"/></a><br><a href="'+ url +'">' + name +
        '</a><br><span class="productSpecialPrice">'+ price +'</span><br><s>' + originalPrice + '</s>';
}

