// JavaScript Document
var OP = ( navigator.userAgent.indexOf( 'Opera' ) != - 1 );
var IE = ( navigator.userAgent.indexOf( 'MSIE' ) != - 1 && ! OP );
var GK = ( navigator.userAgent.indexOf( 'Gecko' ) != - 1 );
var SA = ( navigator.userAgent.indexOf( 'Safari' ) != - 1 );
var DOM = document.getElementById;
var NS4 = document.layers;

var mailfilter  = /^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,6}$/;
var numcheck = /^([0-9])+$/;
var namecheck = /^([a-zA-Z0-9_-])+$/;
var md5code = /^[a-z0-9]{32}$/;
var imgexts = /^.+\.(jpg|gif|png|bmp)$/;

var mouseX = 0;
var mouseY = 0;

var strHref = window.location.href;
if( strHref.indexOf( "?" ) > - 1 )
{
   var strHref_split = strHref.split( "?" );
   var script_name = strHref_split[0];
   var query_string = strHref_split[1];
}

//  ---------------------------------------

else
{
   var script_name = strHref;
   var query_string = '';
}

//  ---------------------------------------

if( typeof( jsi ) == 'undefined' ) var jsi = new Array();
if( ! jsi[0] ) jsi[0] = 'vietnamese';
// SITELANG
if( ! jsi[1] ) jsi[1] = '/';
// SITEROOT
if( ! jsi[2] ) jsi[2] = 'vba';
// NAME_VARIABLE

function nv_getScrX()
{
   var offset = 0;
   if( window.pageXOffset )
   {
      offset = window.pageXOffset;
   }
   else if( document.documentElement && document.documentElement.scrollLeft )
   {
      offset = document.documentElement.scrollLeft;
   }
   else if( document.body && document.body.scrollLeft )
   {
      offset = document.body.scrollLeft;
   }
   return offset;
}

//  ---------------------------------------

function nv_getScrY()
{
   var offset = 0;
   if( window.pageYOffset )
   {
      offset = window.pageYOffset;
   }
   else if( document.documentElement && document.documentElement.scrollTop )
   {
      offset = document.documentElement.scrollTop;
   }
   else if( document.body && document.body.scrollTop )
   {
      offset = document.body.scrollTop;
   }
   return offset;
}

//  ---------------------------------------

function nv_getWinX()
{
   var size = 0;
   if( window.innerWidth )
   {
      size = window.innerWidth;
   }
   else if( document.documentElement && document.documentElement.clientWidth )
   {
      size = document.documentElement.clientWidth;
   }
   else if( document.body && document.body.clientWidth )
   {
      size = document.body.clientWidth;
   }
   else
   {
      size = screen.width;
   }
   return size;
}

//  ---------------------------------------

function nv_getWinY()
{
   var size = 0;
   if( window.innerHeight )
   {
      size = window.innerHeight;
   }
   else if( document.documentElement && document.documentElement.clientHeight )
   {
      size = document.documentElement.clientHeight;
   }
   else if( document.body && document.body.clientHeight )
   {
      size = document.body.clientHeight;
   }
   else
   {
      size = screen.height;
   }
   return size;
}

//  ---------------------------------------

function nv_getMouseXY( e )
{
   if( e && e.pageX != null )
   {
      mouseX = e.pageX;
      mouseY = e.pageY;
   }
   else if( event && event.clientX != null )
   {
      mouseX = event.clientX + nv_getScrX();
      mouseY = event.clientY + nv_getScrY();
   }
   if( mouseX < 0 ) mouseX = 0;
   if( mouseY < 0 ) mouseY = 0;
}

//  ---------------------------------------

function MM_openBrWindow( theURL, winName, features )
{
   window.open( theURL, winName, features );
}

//  ---------------------------------------

function nv_openwindow( theurl, winname, w, h, features )
{
   leftposition = ( nv_getWinX() - w ) / 2;
   topposition = ( nv_getWinY() - h ) / 2;
   settings = 'height=' + h + ',width=' + w + ',top=' + topposition + ',left=' + leftposition;
   if( features != '' )
   {
      settings = settings + ',' + features;
   }
   window.open( theurl, winname, settings );
}

//  ---------------------------------------

function nv_view_siteterms()
{
   var leftposition = ( ( nv_getWinX() - 500 ) / 2 );
   var topposition = ( ( nv_getWinY() - 500 ) / 2 );
   if( IE || GK )
   {
      var wnd = window.showModalDialog( jsi[1] + jsi[0] + '/index.php?siteterms=1', "siteterms",
      'dialogHeight:500px; dialogWidth:500px; dialogTop:' + topposition + 'px;dialogLeft:' + leftposition + 'px;resizable:no;center:yes;help:no;status:no' );
      return wnd;
   }
   else
   {
      var wnd = window.open( jsi[1] + jsi[0] + '/index.php?siteterms=1', "siteterms",
      'menubar=no,toolbar=no,scrollbars=no,location=0, directories=0,copyhistory=0,status=no,modal=yes,dialog=yes,minimizable=no,resizable=no,dependent=yes,width=500,height=500,top=' + topposition + ',left=' + leftposition );
      wnd.focus();
      return wnd;
   }
}

//  ---------------------------------------

function nv_randomPassword( plength )
{
   var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
   var pass = "";
   for( var z = 0; z < plength; z ++ )
   {
      pass += chars.charAt( Math.floor( Math.random() * 62 ) );
   }
   return pass;
}

//  ---------------------------------------

function nv_ismaxlength( obj, mlength )
{
   if ( obj.value.length > mlength )
   {
      obj.value = obj.value.substring( 0, mlength );
   }
}

//  ---------------------------------------

function nv_change_captcha( imgid, seccode )
{
   var vimg = document.getElementById( imgid );
   nocache = nv_randomPassword( 10 );
   vimg.src = jsi[1] + jsi[0] + '/index.php?gfx=gfx&nocache=' + nocache;
   document.getElementById( seccode ).value = '';
   return false;
}

//  ---------------------------------------

function nv_CheckAll( main, fmobj )
{
   var r = document.getElementById( main ).checked;
   var f = document.getElementById( fmobj );
   for ( var i = 0; i < f.elements.length; i ++ )
   {
      var e = f.elements[i];
      if ( e.type == 'checkbox' )
      {
         e.checked = r;
      }
   }
}

//  ---------------------------------------

function nv_stoperror()
{
   return true;
}

//  ---------------------------------------

document.write( '<script type="text/javascript" src="' + jsi[1] + 'js/ajax.js"></script>' );

if( jsi[0] == "vietnamese" )
{
   document.write( '<script type="text/javascript" src="' + jsi[1] + 'js/avim.js"></script>' );
}

//  ---------------------------------------

function nv_addTopBanner()
{
   nocache = nv_randomPassword( 10 );
   nv_ajax( 'post', jsi[1] + jsi[0] + '/index.php?' + jsi[2] + '=Banners&op=ext_top_468_60&nocache=' + nocache, '', 'top_bn', '' );
   setTimeout( 'nv_addTopBanner();', 100000 );
}

//  ---------------------------------------

function nv_addVTV()
{
   nocache = nv_randomPassword( 10 );
   nv_ajax( 'post', jsi[1] + jsi[0] + '/index.php?' + jsi[2] + '=Vtv4&op=dangchieu&nocache=' + nocache, '', 'vtv4_program', '' );
   setTimeout( 'nv_addVTV();', 150000 );
}

function nv_showVTV()
{
   nocache = nv_randomPassword( 10 );
   nv_ajax( 'post', jsi[1] + jsi[0] + '/index.php?' + jsi[2] + '=Vtv4&op=showVTV&nocache=' + nocache, '', 'my_vtv' );
}

function nv_showPROG()
{
    nocache = nv_randomPassword( 10 );
    nv_ajax( 'post', jsi[1] + jsi[0] + '/index.php?' + jsi[2] + '=Vtv4&op=showPROG&nocache=' + nocache, '', 'my_prog' );
    setTimeout( 'nv_showPROG();', 150000 );
}

//  ---------------------------------------

function nv_addWeather()
{
   nocache = nv_randomPassword( 10 );
   nv_ajax( 'post', jsi[1] + jsi[0] + '/index.php?' + jsi[2] + '=Weather&op=inhome&nocache=' + nocache, '', 'weather', '' );
}

//  ---------------------------------------

function nv_checkVoting( voting_id, txt )
{
   var f = document.getElementById( voting_id );
   var r = false;
   for ( var i = 0; i < f.elements.length; i ++ )
   {
      var e = f.elements[i];
      if ( e.type == 'radio' && e.checked == true )
      {
         r = true;
         break;
      }
   }
   if( ! r )
   {
      alert( txt );
      return false;
   }
   else
   {
      f.submit();
      return false;
   }
}

//  ---------------------------------------

// window.onerror = nv_stoperror;
document.onmousemove = nv_getMouseXY;
