/*--------------------------------------------------
 Javascript

 Last updated: Nov. 3, 03
--------------------------------------------------*/

var ns  = (navigator.appName == "Netscape" );
var ie  = (navigator.appName == "Microsoft Internet Explorer");
var ver = parseFloat(navigator.appVersion);
var ns4 = (ns && (ver < 5));
var ns6 = (ns && (ver >= 5));

var windowWidth  = (ns)? window.innerWidth:  window.availWidth;
var windowHeight = (ns)? window.innerHeight: window.availHeight;


// right-click status
var rightclickenabled = false;

rightclick( rightclickenabled );


//----------------------------------------------
// Disable right-click
//----------------------------------------------
function rightclick( setenable )
{
   rightclickenabled = setenable;

   if (ns4)
   {
      document.captureEvents(Event.MOUSEDOWN);
      document.onmousedown   = clickNS;
   }
   else
   {
      document.onmouseup     = clickNS;
      document.oncontextmenu = clickIE;
   }

   document.onmouseover   = "window.status=''; return true";

   return rightclickenabled;
}

function clickIE()
{
   if (document.all)
      return rightclickenabled;
}

function clickNS(e)
{
   if (document.layers||(document.getElementById && !document.all))
   {
      if (e.which==2||e.which==3)
         return rightclickenabled;
   }
}




//----------------------------------------------
// Go back home
//----------------------------------------------
function gohome()
{
   location.href = "/home.php";
}


//----------------------------------------------
// Open links
//----------------------------------------------
function gotolink( linkurl )
{
   var wh = window.open( linkurl, "", "width=600,height="+windowHeight+",scrollbars=yes,resizable=yes,locationbar=yes,location=yes,menubar=yes,toolbar=yes,statusbar=yes,status=yes," );
}


//----------------------------------------------
// Open agreement window
//----------------------------------------------
function popup( url )
{
   var wh = window.open( url, "", "width=600,height="+windowHeight+",scrollbars=yes,resizable=yes," );
}


//----------------------------------------------
// Search for idol, by idol name
//----------------------------------------------
function searchidol( ch )
{
   document.searchform.searchkey.value = ch;
   document.searchform.submit();
}


//----------------------------------------------
// Sign up
//----------------------------------------------
function sign_up()
{
   location.href = "/join.php";
}


//----------------------------------------------
// Sign out
//----------------------------------------------
function sign_out()
{
   location.href = "/logout.php";
}


//----------------------------------------------
// Left panel search
//----------------------------------------------
function dosearch()
{
//   if (document.searchform.searchtype.selectedIndex > 0)
//   {
      document.searchform.action = "/searchvideo.php";
//   }
//   else
//   {
//      document.searchform.action = "/searchidol.php";
//   }
   document.searchform.submit();
}


//----------------------------------------------
// Sign in
//----------------------------------------------
function sign_in()
{
   if (document.loginform.username.value == "")
   {
      alert( "Please input your account name" );
      document.loginform.username.focus();
      return;
   }

   if (document.loginform.password.value == "")
   {
      alert( "Please input your password" );
      document.loginform.password.focus();
      return;
   }

   document.loginform.Action.value = "Signin";
   document.loginform.submit();
}


//----------------------------------------------
// Forget password
//----------------------------------------------
function forget_password( whichform )
{
   if (document.forms[ whichform ])
   {
      document.forms[ whichform ].action = "/forgetpassword.php";
      document.forms[ whichform ].submit();
      return;
   }
   else
   {
      location.ref = "/forgetpassword.php";
   }
}


//----------------------------------------------
// Forget PIN
//----------------------------------------------
function forget_pin( whichform )
{
   if (document.forms[ whichform ])
   {
      document.forms[ whichform ].action = "/forgetpin.php";
      document.forms[ whichform ].submit();
      return;
   }
   else
   {
      location.ref = "/forgetpin.php";
   }
}


//----------------------------------------------
// Activate account
//----------------------------------------------
function activate_account()
{
   location.href = "/activate.php";
}


//----------------------------------------------
// Purchase credits
//----------------------------------------------
function usercredit()
{
   location.href = "usercredit.html";
}


//----------------------------------------------
// Add item to cart
//----------------------------------------------
function buyitem( p )
{
   location.href = "/addcart.php?" + p;
}

//----------------------------------------------
// Refer a friend
//----------------------------------------------
function referafriend()
{
   location.href = "/refer.php";
}


//----------------------------------------------
// Open Cover Image
//----------------------------------------------
function showcover( vno )
{
   var wh = window.open( "/showphoto.php?videono="+vno+"&cover=1", "", "width=600,height=480,scrollbars=yes,resizable=yes," );
}


//----------------------------------------------
// Open Screenshot Image
//----------------------------------------------
function showscreenshot( vno )
{
   var wh = window.open( "/showphoto.php?videono="+vno+"&screenshot=1", "", "width=600,height=500,scrollbars=yes,resizable=yes," );
}


//----------------------------------------------
// Popup download window
//----------------------------------------------
function godownload()
{
   window.open( "/dl.php?vcd="+document.form1.vcd.value+"&dvd="+document.form1.dvd.value,
                "Download", "width=450,height=330,scrollbars=yes,resizable=yes," );
}
