///////////////////////////////////////////////////
//                                               //
//               Java Library                    //
//                                               //
///////////////////////////////////////////////////


///////////////////////////////////////////////////
// Link Sound & Image Rollovers                  //
///////////////////////////////////////////////////

function canPlay(){
 var mimetype = 'audio/midi'; 
 var result = false;
 
 // nav test
 if (navigator.mimeTypes) {
    if (navigator.mimeTypes[mimetype] != null) {
        if (navigator.mimeTypes[mimetype].enabledPlugin != null) {
         result = true;        
        }
     }
  }
 
 //ie test
 if (document.all) { result = true; }

return result;
}
 
function playSound(idx) {
 var can_play = canPlay();
 var mimetype = 'audio/midi';

     if (document.embeds && can_play) {
         //document.embeds["sound"+idx].play();
     }
 }
 
 function stopSound(idx) {
  var can_play = canPlay();
     if (document.embeds && can_play)
         document.embeds["sound"+idx].stop();
 }
 
 function flip(name,src) {
     if (document.images)
         document.images[name].src = src;
 }

// <A HREF="apage.html" onMouseOver="flip('myImage','on.gif');playSound(2)" 
// onMouseOut="flip('myImage','off.gif')">
// <IMG SRC="off.gif" NAME="myImage" BORDER="0" WIDTH="16" HEIGHT="16"></a>


// Used by the cart to roll over buttons
function setHidden(fieldName){
 document.storeForm.fieldName.value = '1';
 }	  


///////////////////////////////////////////////////
// splash rollover display			 //
///////////////////////////////////////////////////
function rnd() {
 rnd.seed = (rnd.seed*9301+49297) % 233280;
 return rnd.seed/(233280.0);
 }
function rand(number) {
 rnd.today=new Date();
 rnd.seed=rnd.today.getTime();
 return Math.ceil(rnd()*number);
 }
function imageChange(bgImageName, fgImageName, menuImageName, menuStatus){
 if (bgImageName == "random"){ bgImageName = 'background_' + rand(9); } 
 // Background Image
 document.all.bGround.style.background='url(../images/splash_'+bgImageName+'.jpg)';   
 // Foreground Image
 document.images.fGround.src = '../images/splash_'+fgImageName+'.gif'; 
 // Menu Rollover
 if (menuImageName){
  document.images[menuImageName].src = '../images/menu_'+menuImageName+'_'+menuStatus+'.gif';
  }
 } 


///////////////////////////////////////////////////
// onLoad pop-under                              //
///////////////////////////////////////////////////

function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1)
         end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

function loadornot(){
if (get_cookie('popunder')==''){
loadpopunder()
document.cookie="popunder=yes"
}
}

function loadpopunder(){

	// specify page to pop-under
var popunder="popclock.html"

	//specify popunder window features
	//set 1 to enable a particular feature, 0 to disable
var winfeatures="width=150,height=150,scrollbars=0,resizable=0,toolbar=0,location=0,menubar=0,status=0,directories=0"

win2=window.open(popunder,"",winfeatures)
win2.blur()
window.focus()
}


function popUnder() {
	//Pop-under only once per browser session? (0=no, 1=yes)
	//Specifying 0 will cause popunder to load every time page is loaded
var once_per_session=1

///No editing beyond here required/////
 if (once_per_session==0){
  loadpopunder()
  }
 else {
  loadornot()
  }
 }



///////////////////////////////////////////////////
// Floating Logo/Menu Function                   //
///////////////////////////////////////////////////
function setFloat(){
 setVariables();
 checkLocation();
 }

function setVariables(){
 if (navigator.appName == "Netscape") {
 v=".top=";h=".left=";dS="document.";sD="";
 y="window.pageYOffset";x="window.pageXOffset";iW="window.innerWidth";iH="window.innerHeight"
 
 }
else {h=".pixelLeft=";v=".pixelTop=";dS="";sD=".style";
 y="document.body.scrollTop";x="document.body.scrollLeft";iW="document.body.clientWidth";iH="document.body.clientHeight" 
 }
xyz=500
object="logo";
checkLocationA()
}

function checkLocation(){
 movex=0,movey=0,xdiff=0,ydiff=0,ystart=0,xstart=0
 
  var LogoHeight = 42;			// Set this to match your logo Height
  var LogoWidth  = 80;			// Set this to match your logo Width
  var LogoOffset = 10;			// Set the logo distance from the bottom right
  
 innerX=eval(iW)- (LogoWidth + LogoOffset);
 innerY=eval(iH)- (LogoHeight + LogoOffset);
 if (document.layers){innerY-=10;innerX-=10}
 yy=eval(y);
 xx=eval(x);
 ydiff=ystart-yy;
 xdiff=xstart-xx;
 if ((ydiff<(-1))||(ydiff>(1))) movey=Math.round(ydiff/10),ystart-=movey
 if ((xdiff<(-1))||(xdiff>(1))) movex=Math.round(xdiff/10),xstart-=movex
 eval(dS+object+sD+v+(ystart+innerY));
 eval(dS+object+sD+h+(xstart+innerX));
 setTimeout("checkLocation()",10)
 }

function checkLocationA(){ ystart=eval(y);xstart=eval(x); }

function switchLogo(abc){
if (abc=="menu"){                     //to stop the switch logo function
eval(dS+object+sD+v+0);               // just
eval(dS+object+sD+h+(-200));           // slash out these lines
object=abc}                              //at the
else xyz=setTimeout("delayLogo()",2000)   // beginning
}

function delayLogo(){
eval(dS+object+sD+v+0);          //
eval(dS+object+sD+h+(-200));      //and these three too
object='logo'                     //
}




///////////////////////////////////////////////////
// PopUp Function                                //
///////////////////////////////////////////////////
function PopUp(FileName, Width, Height) {
 window.open(FileName,'','width='+Width+',height='+Height+',top=50,left=50,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no,scrollbars=yes');
 }

function PopPic(FileName, Width, Height) {
 window.open(FileName,'','width='+Width+',height='+Height+',top=50,left=50,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no,scrollbars=no');
 }

function PopUpload(FileName, Width, Height) {
 window.open(FileName,'','width='+Width+',height='+Height+',top=50,left=50,toolbar=no,location=yes,directories=no,status=yes,menubar=no,resizable=no,copyhistory=no,scrollbars=no');
 }



function popupwindow (URL,popupWidth,popupHeight) {

 var putItThere = null;
 var chasm = screen.availWidth;
 var mount = screen.availHeight;

 if (popupWidth > chasm) { popupWidth = chasm - 10; }
 if (popupHeight > mount) { popupHeight = mount - 40;}
 putItThere = window.open(URL,"popupWindow","width=" + popupWidth + ",height=" + popupHeight + ",toolbar=no,directories=no,location=no,status=off,menubar=no,resizable=yes,scrollbars=no,left=" + ((chasm - popupWidth - 10) * .5) + ",top=" + ((mount - popupHeight - 30) * .5) + ",screenX=" + ((chasm - popupWidth - 10) * .5) + ",screenY=" + ((mount - popupHeight - 30) * .5)); 
 }



///////////////////////////////////////////////////
// Cookie I/O                                    //
///////////////////////////////////////////////////
function getCookie(name){
 var cname = name + "=";
 var dc = document.cookie;
 if (dc.length > 0) {
  begin = dc.indexOf(cname);
  if (begin != -1) {
   begin += cname.length;
   end = dc.indexOf(";", begin);
   if (end == -1) end = dc.length;
    return unescape(dc.substring(begin, end));
   }
  }
 return null;
 }


function setCookie(name, value, expires) {
 document.cookie = name + "=" + escape(value) + ((expires != null) ? "; expires=" + expires.toGMTString() : "") + "; path=/";
 }


function deleteCookie (name) {
 var exp = new Date();
 exp.setTime (exp.getTime() - 1); 
 var cval = getCookie (name);
 document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString(); 
 }


function fixCookieDate (date) {
 var base = new Date(0);
 var skew = base.getTime(); // dawn of (Unix) time - should be 0
 if (skew > 0) {
  date.setTime (date.getTime() - skew);
  }
 }


///////////////////////////////////////////////////
// Cookie Assisted Login Routine                 //
///////////////////////////////////////////////////
	
	
	// Load the form with the values in the cookie Called when page loads
	// 
function getLogin() {

 if (getCookie('session')){  
  with(document.login){   
   username.value = getCookie('username');
   password.value = "logout";         
   auth_remember_login.value = getCookie( "remember_login" );
   if (auth_remember_login.value == "on") { auth_remember_login.checked = true; }
   master.value = "logout";
   }
  }

 else if (getCookie('username')){  
  with(document.login){
   username.value = getCookie('username');   
   auth_remember_login.value = getCookie( "remember_login" );
   if (auth_remember_login.value == "on") { auth_remember_login.checked = true; }   
   master.value = "login";
   }  
  document.login.password.focus();
  }
  
 
 else {
  with(document.login){
   master.value = "login";
   }
  document.login.username.focus();  
  } 
 } 

// End function getLogin



	// Form Entry Verification - Called when the form is submitted
	// 
function isValid() {
 
 var expDays = 365; // number of days the cookies will last
 var expdate = new Date ();
 fixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
 expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * expDays));
 
 isitValid = true;
 
 with( document.login ) {
  var Username = username.value;

  if(( username.value == "" ) || ( password.value == "" )) {
   window.alert( "You must enter both your user name and your password" );
   isitValid = false;
   }

  if (auth_remember_login.checked) {
   var Remember_login = "on";
   }
  }
 
 	// If it is valid re-write the cookie
 if( isitValid ) {
 
  
  // If they don't want to remember me, set to expire immediately after session
  var Expires = "-1";
  

  // sets expire to expdate!
  if (Remember_login == "on") {   
   document.cookie = "username=" + Username + ";expires=" + expdate.toGMTString() + ";";   
   document.cookie = "remember_login=" + Remember_login + ";expires=" + expdate.toGMTString() + ";";
   }

  // sets expire to now!
  else {
   document.cookie = "username=" + Username + ";expires=" + Expires + ";";
   document.cookie = "remember_login=" + Remember_login + ";expires=" + Expires + ";";
   }

  
  
  return isitValid;
  }
 }
 // End function isValid
 
 
 
 ///////////////////////////////////////////////////
 // Commafy a Number
 ///////////////////////////////////////////////////

 
 function commafy(num){    // adds "," in front of each 3 digits 
    num=num+'';      // convert number to string 
    var re = /(\d+)(\d{3})/      // define regex 
    while (re.test(num)) {       // apply regex, memorize into $1, $2 
       num=num.replace(re, "$1,$2")  // add "," 
    } 
    return num 
 }

function cent(amount) {
// returns the amount in the .99 format 
    amount -= 0;
    amount = (Math.round(amount*100))/100;
    return (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}

function makemoney(num){
 var money = cent(num);
 var final = commafy(money);
 return final
 }
 
 

