// constants
clrBlack = "000000"
clrWhite = "FFFFFF"
clrLiteGreen = "CCff99"
clrBkgd0 = "CCFFCC"
clrText0 = "006600"
clrBkgd1 = clrLiteGreen
clrText1 = "009900"

// Browser Apps
APP_UNKNOWN = 0 ;
APP_MSIE = 1;
APP_NS = 2;
APP_OPERA = 3;
APP_SAFARI = 4;

function browserApp(){
   if (navigator.appName == "Microsoft Internet Explorer")
		return APP_MSIE ;
   if (navigator.appName == "Netscape") // includes Mozilla
		return APP_NS ;
   if (navigator.appName == "Opera")
		return APP_OPERA ;
   if (navigator.appName == "Safari")
		return APP_SAFARI ;
	return APP_UNKNOWN ;
}

// Microsoft browser detection
function browserGetIEVersion()
{
   var ua = navigator.userAgent ;
   var ui = ua.indexOf("MSIE");
   if (ui >= 1) //browser is IE
   {
       var ud = ua.indexOf(".", ui);
      return parseInt(ua.substring(ui+5, ud));
   }
   return 0 ;
}

function browserGetVersion()
{
	switch(browserApp()){
	case APP_MSIE:
		return browserGetIEVersion();
	case APP_NS:
	case APP_OPERA:
	case APP_SAFARI:
	case APP_UNKNOWN:
	default:
      var av = navigator.appVersion ;
      var index = av.indexOf(".", 1);
      return parseInt(av.substring(index-1, index));
   }
   return 0 ;
}

function browserInfo(){
	var msg = "Application: " + navigator.appName + "\n";
	msg += "Version: " + navigator.appVersion + "\n";
	msg += "User Agent: " + navigator.userAgent ;
	alert( msg );
}


/////////////////////////////////////////////

function setstyle(id,n){

   var version = browserGetIEVersion();
   // handle ID
   if( version != 0 )   {
      if( document.all.item(id) == null ) {
      //alert("oops: " + id);
         return;
      }
      if(version >= n ){
         switch( n ){
         case 0:
         default:
            document.all.item(id).style.color=clrText0;
            document.all.item(id).style.borderColor=clrText0;
            document.all.item(id).style.backgroundColor=clrBkgd0;
          	document.all.item(id).style.textDecoration="none";
            break;
         case 1:
            document.all.item(id).style.color=clrText1;
            document.all.item(id).style.backgroundColor=clrBkgd1;
            document.all.item(id).style.borderColor=clrText1;
          	document.all.item(id).style.textDecoration="none";
            document.all.item(id).style.cursor="hand";
            break;
         case 2:
          	document.all.item(id).style.textDecoration="underline";
            document.all.item(id).style.cursor="hand";
            break;
         }
      }
      return;
   }

   //detect other browsers
   version = browserGetVersion();
   if( version < 5 )
      return ;

   if( document.anchors[id] == null ){
      return;
   }

   switch( n ){
   case 0:
   default:
      document.anchors[id].style.color=clrText0;
      document.anchors[id].style.borderColor=clrText0;
      document.anchors[id].style.textDecoration="none";
      //document.anchors[id].style.backgroundColor=clrBkgd0;
      break;
   case 1:
      document.anchors[id].style.hover=clrText1;
      document.anchors[id].style.color=clrText1;
      document.anchors[id].style.borderColor=clrText1;
      document.anchors[id].style.cursor="hand";
      document.anchors[id].style.textDecoration="none";
      break;
   case 2:
      document.anchors[id].style.textDecoration="underline";
		document.anchors[id].style.cursor="hand";
      break;
   }
}

function launch( url ){
   w = window.open( "http://" + url );
   if( null != w )
      w.focus();
}

function ss(index, style )
{
   setstyle('txt'+index.toString(),style);
   setstyle('btn'+index.toString(),style);
}

function swap(index, img )
{
   if( document.images["btn"+index.toString()] ){
      document.images["btn"+index.toString()].src= "images/" + img + ".GIF";
   }
}

function mo(index, style )
{
   setstyle('txt'+index.toString(),style);
}

function mout(index, style )
{
   setstyle('txt'+index.toString(),style);
}

function iswap(i, filename)
{
   if( document.images[i] ){
      document.images[i].src= "images/" + filename;
   }
}

function gif(i, filename){
   iswap(i, filename + ".gif");
}

function jpg(i, filename){
   iswap(i, filename + ".jpg");
}


function dlMp3(file){
   alert("This music is for personal use only. By downloading this file, you agree not to use it for any commercial purpose, including but not limited to selling, distributing, and publishing.");
   if( "" != file )
   {
      w = window.open( "mp3/" + file + ".mp3", "mp3", 'toolbar=no,location=no,width=500,height=400,scrollbars=no,resizable=no' );
      if( null != w )
         w.focus();
   }
}

function popup(file,caption,w,h){
   w = window.open( file + ".html", caption, 'toolbar=no,location=no,width=w,height=h,scrollbars=yes,resizable=yes' );
   if( null != w )
      w.focus();
}

function chimg(prefix,index){
   gif(prefix, prefix + "_" + index);
}

