/*--------------------------------------------------
 Main Javascript

 Last updated: Aug. 03, 04
--------------------------------------------------*/

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;


//-----------------------------------------------
// Go to page no
//-----------------------------------------------
function gopage( thepage )
{
  document.form1.pageno.value = thepage;
  document.form1.submit();
}


//-----------------------------------------------
// Open special link
//-----------------------------------------------
function openwindow(url,winheight,winwidth)
{
  var wspec = "resizable=yes,scrollbars=yes,status=yes,height="+winheight+",width="+winwidth;
  var wh = window.open(url, "popup", wspec );
}


//-----------------------------------------------
// View/Edit order detail
//-----------------------------------------------
function editorder( oid )
{
  location.href = "myorders_info.asp?ordernumber=" + oid;
}

//-----------------------------------------------
// Print Invoice
//-----------------------------------------------
function printinvoice( oid )
{
   window.open( "myorders_invoice.asp?ordernumber=" + oid, "", "" );
}

//------------------------------------------------------------------------
// Trim the string
//------------------------------------------------------------------------
function trim( st )
{
   var s = st.replace( /^\s/gi, "" );
   s = st.replace( /\s$/gi, "" );
   
   return s;
}

//-----------------------------------------------
// Is a valid email address?
//-----------------------------------------------
function field_is_email( fieldname, displaymessage )
{
   var v = trim( document.form1[ fieldname ].value );

   if (v.match(/^[\w\-\.]+\@[\w\-]+\.[\w\-\.]+\w$/i))
      return true;

   if (displaymessage != "")
      alert( displaymessage );

   document.form1[ fieldname ].focus();
   return false;
}


//------------------------------------------------------------------------
// Empty? display the message, go to the field, return False
//------------------------------------------------------------------------
function field_is_empty( fieldname, displaymessage )
{
   var v = trim( document.form1[ fieldname ].value );

   if (v != "")
      return false;

   if (displaymessage != "")
      alert( displaymessage );

   document.form1[ fieldname ].focus();
   return true;
}


//------------------------------------------------------------------------
// Same? display the message, go to the field, return False
//------------------------------------------------------------------------
function field_is_same( fieldname1, fieldname2, displaymessage )
{
   if (document.form1[ fieldname1 ].value == document.form1[ fieldname2 ].value)
      return true;

   if (displaymessage != "")
      alert( displaymessage );

   document.form1[ fieldname2 ].focus();
   return false;
}


//------------------------------------------------------------------------
// Selected the pull-down? display the message, go to the field, return False
//------------------------------------------------------------------------
function field_is_selected( fieldname, displaymessage )
{
   var i = document.form1[ fieldname ].selectedIndex;
   if (document.form1[ fieldname ][i].value != "")
      return true;

   if (displaymessage != "")
      alert( displaymessage );

   document.form1[ fieldname ].focus();
   return false;
}


//------------------------------------------------------------------------
// Checked the checkbox? display the message, go to the field, return False
//------------------------------------------------------------------------
function field_is_checked( fieldname, displaymessage )
{
   if (document.form1[ fieldname ].checked == true)
      return true;

   if (displaymessage != "")
      alert( displaymessage );

   document.form1[ fieldname ].focus();
   return false;
}
