// ===============================================================
// This is the www.MINIBOTTLES.com JavaScript-Tools Sourcefile
// (c)opyright 2001-2007 www.MINIBOTTLES.com - All Rights Reserved
// ===============================================================

// ===========================
// TOOLS FOR WINDOW MANAGEMENT
// ===========================

   var popup = null;

   function sPP(pict, w, h)
   {
     if (popup && popup.open && !popup.closed)
     {
       win_name = "pictwin";
       popup = window.open (pict,win_name);
     }
     else
     {
       win_name = "pictwin";
       option   = "'toolbar=no,status=no,width=" + w + ",height=" + h + "'";
       popup    = window.open (pict,win_name,option);
     }
   }

   function showPopup(url, w, h)
   // opens url in popup, w=width, h=height
   {
     var windowparameter = "'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no";
     windowparameter = windowparameter + ",left=18,top=18,width=" + w + ",height=" + h + "'";
     popup_win = window.open(url, '', windowparameter);
   }

   function closePopup()
   // closes the with showPopup opened window
   {
     popup_win.close();
   }

   function preventLoadingIntoFrameset()
   // prevent from being loaded into foreign frameset
   {
     if (top.frames.length > 0)
       { 
         top.location.href = self.location;
       }
   }

  function ChangeTwoFrames(url1,name1,url2,name2)
  {
    Frame1=eval("parent."+name1);
    Frame2=eval("parent."+name2);
    Frame1.location.href = url1;
    Frame2.location.href = url2;
  }

  function ChangeThreeFrames(url1,name1,url2,name2,url3,name3)
  {
    Frame1=eval("parent."+name1);
    Frame2=eval("parent."+name2);
    Frame3=eval("parent."+name3);
    Frame1.location.href = url1;
    Frame2.location.href = url2;
    Frame3.location.href = url3;
  }


// ============================
// TOOLS FOR PICTURE MANAGEMENT
// ============================

   function xc(oldimage,newimage)
   // if mouseover exchange oldimage to newimage
   {
     oldimage.src = newimage.src
   }


// ==============================
// TOOLS FOR DATE-TIME MANAGEMENT
// ==============================

   var timerID = null
   var timerRunning = false

   function startclock ()
   // timer start
   {
     stopclock();
     showtime()
   }
 
   function stopclock ()
   // timer stop
   {
     if(timerRunning)
       clearTimeout(timerID);
     timerRunning = false
   }


   function writeActDateTime()  
   // writes actual date and time  
   {
    var dayArray = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
    var monthArray = new Array("January","February","March","April","May","June","July","August","September","October","November","December")
    var d = new Date();
    var day = d.getDay();
    var month = d.getMonth();
    var hours = d.getHours();
    var minutes = d.getMinutes();
    var timeValue = "";
    timeValue += ((hours < 10) ? "0" : "") + hours;
    timeValue += ((minutes < 10) ? ":0" : ":") + minutes;  
    var dateTimeStr = dayArray[day]+", "+d.getDate()+". "+monthArray[month]+" "+d.getFullYear()+", "+timeValue+"h";
    document.write(dateTimeStr);
   }

   function showtime ()
   // show actual local time
   {
     var now = new Date();
     var year = now.getFullYear();
     var month = now.getMonth() + 1;
     var date = now.getDate();
     var hours = now.getHours();
     var minutes = now.getMinutes();
     var timeValue = "";
     timeValue += ((date < 10) ? "0" : "") + date + ".";
     timeValue += ((month < 10) ? "0" : "") + month + "." + year + " / ";
     timeValue += ((hours < 10) ? "0" : "") + hours;
     timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
     document.form.dateandtime.value = timeValue;
     timerID = setTimeout("showtime()",1000);
     timerRunning = true
   }

  function generateGreeting()
  // print a greeting form (morning/afternoon/evening)
  {
    datetoday = new Date();
    localhour = datetoday.getHours();
    if (localhour > 18)
      {
        display = "evening";
      }
    else
      {
        if (localhour > 11)
          {
            display = "afternoon";
          }
        else
          {
            display = "morning";
          }
       }
    document.write("and good " + display);
  }

  function daysTill()
  {
  //----------  EDIT THE VARIABLES BELOW  ------------------
    var day   = 24 // day
    var month = 12 // month
    var year  = 2007 //year
  //----------  END OF EDIT  -------------------------------

    var daystocount = new Date(year, month -1, day)
    today = new Date()
    if (today.getMonth()==month && today.getDate()>day)
       daystocount.setFullYear(daystocount.getFullYear())
    // var oneday = 1000*60*60*24
    var oneday = 1000*60*60*24
    var write = (Math.ceil((daystocount.getTime()-today.getTime())/(oneday)))
    if (write > 0)
//    document.write('<BR><BR><FONT color=red>... ' + write + ' days up to the <A HREF=site_updates.shtml>10</A> years online anniversary');
  document.write('<BR><BR><FONT color=red>Do not forget: only <A HREF=xmas/index.html>' + write + '</A> days up to Christmas!');
  }


// ===========================
// TOOLS FOR STRING MANAGEMENT
// ===========================

  function isDigit( ch )
  {
    if ( (ch >= '0') && (ch <= '9') )
       return true;
    else
       return false;
  }


  function isAlpha( ch )
  {
    if ( ((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z')) )
       return true;
    else
       return false;
  }


  function isAlnum( ch ) 
  {
    if ( isAlpha( ch ) || isDigit( ch ) )
       return true;
    else
       return false;
  }


  function PruefeObAlphaNumerisch(feld, hinweistext)
  {
    if (feld.value.length>0)
       {
        for(var i=0;i<feld.value.length;i++)
        {
            var abc=feld.value.substring(i,i+1);
            if (!(isAlnum(abc)))
            {
              feld.value=feld.value.substr(0,i);
              feld.focus();
              return false;
            }
        }
       }
     return true;
  }


  function PruefeObReinNumerisch(feld)
  {
    if (feld.value.length>0)
       {
         for(var i=0;i<feld.value.length;i++)
         {
            var abc=feld.value.substring(i,i+1);
            if ( abc<"0" || "9" <abc )
               {
                 feld.value=feld.value.substr(0,i);
                 feld.focus();
                 return false;
               }
            else;
        }
    }
    return true;
  }


  function PruefeObReinNumerischMitKomma(feld)
  {
    var komma=0;
    if (feld.value.length>0)
       {
         for(var i=0;i<feld.value.length;i++)
         {
            var abc=feld.value.substring(i,i+1);
            if (!(abc >= "0" && "9" >= abc) && abc != ",")
               {
                 feld.value=feld.value.substr(0,i);
                 feld.focus();
                 return false;
               }
            else {
                if (abc == ",")
                    komma = komma + 1;
                 }
        }
        if (komma > 1)
           {
             feld.value=feld.value.substr(0,i-1);
             feld.focus();
             return false;
           }
        else;
      }
     return 0;
  }
  

   function pruefePlz(PLZ)
   {
     if (PLZ.value.length!=5)
        return false;
     for (var i=0;i<PLZ.value.length;i++)
       {
         var abc=PLZ.value.substring(i,i+1);
         if (abc<"0" || "9" <abc)
             return false;
         else
             return true;
       }
   }


   function pruefeTagMonat(dd, mm)
   {
     var dd2=strip (dd.value, '0', 'L');
     var mm2=strip (mm.value, '0', 'L');
     tage = new Array( 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
     if (dd.value.length==0 || mm.value.length==0)
        return false;
        else if (parseInt(mm2)<=12 && parseInt(mm2) > 0 && parseInt(dd2)>0 && parseInt(dd2)<=tage[parseInt(mm2) -1 ])
                return true;
        else return false;
   }


   function check_empty(address)
   // if string is not empty the return value is true
   {
     return (address.length > 0);
   }

   function check_email(address)
   // if string seems to be a correct email address the return value is true
   {
     if ((address == "")
       || (address.length < 9)
       || (address.indexOf ('@') == -1)
       || (address.indexOf ('.') == -1))
       return false;
     return true;
   }

   function check_url1(address)
   // if string seems to be a correct url the return value is true
   {
     if ((address == "")
       || (address.length < 12)
       || (address.indexOf ('http') == -1)
       || (address.indexOf ('://') == -1)
       || (address.indexOf ('.') == -1))
       return false;
     return true;
   }

   function check_url2(address)
   // check the string only if it is NOT empty
   // if string seems to be a correct url the return value is true
   {
     if ((address != "")
       && ((address.indexOf ('http') == -1)
       || (address.indexOf ('://') == -1)
       || (address.length < 12)
       || (address.indexOf ('.') == -1)))
       return false;
     return true;
   }
   
   function check_for_ziffern(text, ZugelasseneZeichen)
   {
     for (var Pos = 0; Pos < Feld.value.length; Pos++)
      {
        if (ZugelasseneZeichen.indexOf(Feld.value.charAt(Pos)) == -1)
          return false;
        return true;
      }
   }
   
   
   function validate_form(formtype)
   {
     validity = true; // assume valid
     if (!check_empty(document.form.name.value))
       {
         validity = false; alert('Your name, please ...');
       }
     if (!check_empty(document.form.location.value))
       {
         validity = false; alert('Your location, please ...');
       }
     if (!check_email(document.form.email.value))
       {
         validity = false; alert('Please check your email ...');
       }
     if (formtype=="ring")
       {
         if (!check_url1(document.form.url.value))
           {
             validity = false; alert('Please check the url (http://...) ...');
           }
       }
     if (formtype!="ring")
       {
         if (!check_url2(document.form.url.value))
           {
             validity = false; alert('Please check the url (http://...) ...');
           }
       }
     if (!check_empty(document.form.collect.value))
       {
         validity = false; alert('Your collection speciality, please ...');
       }
     if (formtype=="ring")
       {
         if (!check_empty(document.form.sitetitle.value))
           {
             validity = false; alert('Do not forget your MCR site title!');
           }
       }
     if (!check_empty(document.form.messagetext.value))
       {
         validity = false; alert('Your ad/message/description, please ...');
       }
     if (!check_verification_code(document.form.verification.value))
       {
         validity = false; alert('The verification code is missed or false ...');
       }       
     return validity;
   }

   
// ====================
// TOOLS FOR NEWSTICKER
// ==================== 

   function showNews()
   // call the newsticker
   // the DIV-Tag must be set in HTML code direct before the call:
   // <div id="news"></div> 
   // <SCRIPT TYPE="text/javascript">showNews();</SCRIPT>
   {
     go(msg[0], 0, 1);
   }
   
   function changeNews()
   // changes the newsticker after loading all images
   // (sets a new array and sets the waitfornewmsg from 3 to 10 sec.)
   {
     msg=new Array
     (
      '... your new bottles are just a few clicks away from you ...',
      '... you may order you new collectibles very easy here ...',
      '... check out our ABSINTH collections for sale ...',
      '... thank you for visiting http://www.Mini-Bottle-Shop.com ...'
     );
     waitfornextmsg=10000;
   }

   function go(text, pos, dir)
   // the newsticker code itself
   // the variables var delay=10; var nextm=0; var waitfornextmsg=3000;
   // and var msg=new Array ('...', '...','...');
   // must be set in the calling HTML code
   {
     var out1='&#160;<font face="Verdana,Arial,Helvetica" size=1><b>'+text.substring(0, pos)+'</b></font>';
     var out2='&#160;<font face="Verdana,Arial,Helvetica" size=1><b>'+text.substring(0, pos)+'</b></font>';
     if (navigator.appName=="Netscape")
       with(document.news.document)
       {
         open();
         if (dir>=0)
           { write(out1); }
         else
           { write(out2); }
         close();
       }
     else
       {
         if (dir>=0)
           { news.innerHTML=out1; }
         else
           { news.innerHTML=out2; }
       }
     pos+=dir;
     if (pos>text.length) setTimeout('go("'+text+'",'+pos+','+(-dir)+')', waitfornextmsg);
     else
       {
         if (pos<0)
	   {
             if (++nextm>=msg.length) 
               {
                 nextm=0;
               }
             text=msg[nextm];
             dir=-dir;
           }
         if (dir>=0)
           {
             setTimeout('go("'+text+'",'+pos+','+dir+')', delay);
           }
         else
           {
             setTimeout('go("'+text+'",'+pos+','+dir+')', delay/5);
           }
       }
     }
   
// ========================
// TOOLS FOR EMAIL-ADRESSES
// ========================

  function deCryptEMStr ()
  {
    var n = 0;
    var r = "";
    for (var i = 0; i < ema.length; i++)
      { 
	n = ema.charCodeAt(i); 
	if (n >= 8364) {n = 128;}
	r += String.fromCharCode(n-(rsf)); 
      }
    return r;
  }

  function lnkEMStr()
  {
    location.href=deCryptEMStr ();
  }

  function wrtEMFeedbackStr()
  {
    ema = "thps{vAmllkihjrGtpupiv{{slz5jvt"; // shifted EM address 
    rsf = "7";                               // re-shift factor
    pic = "pict/div_kcabdeef.gif";           // picture to show
    
    document.write ("<a href='javascript:lnkEMStr();'>");
    document.write ("<IMG SRC='" + pic + "'></a>");
  }


// ====================
// TOOLS FOR "GIMMICKS"
// ====================

// --- EARTHQUAKE ----------------------------------------------------------------

   function EarthQuake()
   {
     this.start = 0
   }

   function EarthQuakeStart()
   {
     if (this.running)
       {
         return;
       }
     this.running = true
     this.counter = 0
     if (document[this.id])
       {
         this.pos = parseInt(document[this.id].top);
         setTimeout(this.name + ".end()", this.duration_effect);
       }
     else
       {
         this.pos = parseInt(window[this.id].style.posTop);
         setTimeout(this.name + ".end()", this.duration_effect);
       }
   }

   function EarthQuakeEnd(akt_pos)
   {
     var wave = this.height * Math.sin(Math.PI * this.increment * this.counter) * ((this.max_counter - this.counter) / this.max_counter)
     if (document[this.id])
       { 
         document[this.id].top = this.pos + wave;
       }
     else
       {
         window[this.id].style.posTop = this.pos + wave;
       }
     this.counter++
     if (this.counter == this.max_counter)
       {
         if (document[this.id])
           {
             document[this.id].top = this.pos;
           }
         else
           {
             window[this.id].style.posTop = this.pos;
           }
         setTimeout(this.name + ".running = false", this.duration_wait);
       }
     else
       {
         setTimeout(this.name + ".end()", this.duration_effect);
       }
   }

   function EarthQuake(id, name)
   {
     this.height           = 100;
     this.duration_effect  = 15;
     this.duration_wait    = 500;
     this.running          = false;
     this.id               = id;
     this.name             = name;
     this.increment        = .1;
     this.pos              = 0;
     this.counter          = 0;
     this.max_counter      = 100;
     this.start            = EarthQuakeStart;
     this.end              = EarthQuakeEnd;
   }

   // --- new object earthquake (eq) ---
   var EQ1 = new EarthQuake("EQ", "EQ1");


// --- FADE-IN -----------------------------------------------------------------

  function makearray(n)
  {
    this.length = n;
    for(var i = 1; i <= n; i++);
    this[i] = 0;
    return this;
  }
  
  hexa = new makearray(16);
  for(var i = 0; i < 10; i++)
  hexa[i] = i;
  hexa[10]="a"; hexa[11]="b"; hexa[12]="c";
  hexa[13]="d"; hexa[14]="e"; hexa[15]="f";

  function hex(i)
  {
    if (i < 0)
      {
        return "00";
      }
    else
      {
        if (i > 255)
          {
            return "ff";
          }
        else
          {
            return "" + hexa[Math.floor(i/16)] + hexa[i%16];
          }
      }
  }

  function setbgColor(r, g, b)
  {
    var hr = hex(r); var hg = hex(g); var hb = hex(b);
    document.bgColor = "#"+hr+hg+hb;
  }

  function fade(sr, sg, sb, er, eg, eb, step)
  {
    for(var i = 0; i <= step; i++)
    {
      setbgColor(
      Math.floor(sr * ((step-i)/step) + er * (i/step)),
      Math.floor(sg * ((step-i)/step) + eg * (i/step)),
      Math.floor(sb * ((step-i)/step) + eb * (i/step)));
    }
  }

  function fadein()
  {
    fade(240,232,223,0,0,0,150);
  }
  

// ===========================================
// END OF www.MINIBOTTLES.com JavaScript-Tools
// ===========================================