/*--------------------------------------------------
 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:  screen.availWidth;
var windowHeight = (ns)? window.innerHeight: screen.availHeight;



//------------------------------------------------
// Legal Dislaimer in pop-up window
//------------------------------------------------
function showDisclaimer()
{
   window.open( "disclaimer.html", "disclaimer", "width=600,height="+windowHeight+",scrollbars=yes,resizable=yes,status=yes," );
}

//------------------------------------------------
// Terms of Purchase in pop-up window
//------------------------------------------------
function showTerms()
{
   window.open( "termsofpurchase.html", "disclaimer", "width=600,height="+windowHeight+",scrollbars=yes,resizable=yes,status=yes," );
}

//--------------------------------------
// Pop Up Order Form
//--------------------------------------
function orderform()
{
   window.open( "orderform.php", "", "scrollbars=yes,resizable=yes,status=yes," );
}

//--------------------------------------
// Pop Up Order Form
//--------------------------------------
function paymentform()
{
   location.href = "payment.php?t=form";

//   window.open( "paymentform.php", "", "width=600,height="+windowHeight+",scrollbars=yes,resizable=yes,status=yes," );
}

//--------------------------------------
// Pop Up Tell-a-friend
//--------------------------------------
function tellafriend( prodid )
{
   var url = "tellafriend.php?"+prodid;

   window.open( url, "tellafriend", "width=600,height="+windowHeight+",scrollbars=yes,resizable=yes,status=yes," );
}

//------------------------------------------------
// Review delivery rates
//------------------------------------------------
function showShippingInfo()
{
   window.open( "shippinginfo.php", "rates", "width=630,height="+windowHeight+",scrollbars=yes,resizable=yes,status=yes," );
}

//------------------------------------------------
// Special page for product in pop-up window
//------------------------------------------------
function openspeciallink( linkurl )
{
  var url = linkurl.replace( / /g, "" );

  if (url != "")
     window.open( url, "speciallink", "width=600,height="+windowHeight+",scrollbars=yes,resizable=yes,status=yes," );
}


//-----------------------------------------------
// Is a field empty?
//-----------------------------------------------
function is_empty( fieldname, promptmsg )
{
   if (document.form1[ fieldname ].value == "")
   {
      if (promptmsg != "")
         alert( promptmsg );
      document.form1[ fieldname ].focus();
      return true;
   }

   return false;
}

//-----------------------------------------------
// Is a pull-down menu selected?
//-----------------------------------------------
function is_selected( fieldname, promptmsg )
{
   var i = document.form1[ fieldname ].selectedIndex;

   if (document.form1[ fieldname ][i].value == "")
   {
      if (promptmsg != "")
         alert( promptmsg );
      document.form1[ fieldname ].focus();
      return false;
   }

   return true;
}

//-----------------------------------------------
// Is a field shorter than the specified length?
//-----------------------------------------------
function is_shorter( fieldname, len, promptmsg )
{
   if (document.form1[ fieldname ].value.length < len)
   {
      if (promptmsg != "")
         alert( promptmsg );
      document.form1[ fieldname ].focus();
      return true;
   }

   return false;
}

//-----------------------------------------------
// Is one field same as the other field?
//-----------------------------------------------
function is_same( fieldname1, fieldname2, promptmsg )
{
   if (document.form1[ fieldname1 ].value == document.form1[ fieldname2 ].value)
   {
      if (promptmsg != "")
         alert( promptmsg );
      document.form1[ fieldname1 ].focus();
      return true;
   }

   return false;
}

//-----------------------------------------------
// Is a valid email address?
//-----------------------------------------------
function is_email( fieldname, promptmsg )
{
   if (! document.form1[ fieldname ].value.match( /^[\w\-\.]+\@[\w\-]+\.[\w\-\.]+\w$/i ))
   {
      if (promptmsg != "")
         alert( promptmsg );
      document.form1[ fieldname ].focus();
      return false;
   }

   return true;
}

//------------------------------------------------
// When province/state is changed
//------------------------------------------------
function changestate()
{
   var countryid = document.form1.country[ document.form1.country.selectedIndex ].value;
   var stateitem = document.form1.state[ document.form1.state.selectedIndex ].value.split( "|" );
   var cid       = stateitem[1];

   if (cid != countryid)
   {
      for (var i=0; i<document.form1.country.length; i++)
      {
          if (document.form1.country[ i ].value == cid)
          {
             document.form1.country.selectedIndex = i;
             if (cid != "other")
                document.form1.otherstate.value      = "";
             break;
          }
      }
   }
}

//------------------------------------------------
// When country is changed
//------------------------------------------------
function changecountry()
{
   var countryid = document.form1.country[ document.form1.country.selectedIndex ].value;
   var stateitem = document.form1.state[ document.form1.state.selectedIndex ].value.split( "|" );
   var cid       = stateitem[1];

   if (countryid != cid)
   {
      if ((countryid != "CA")&&(countryid != "US"))
         countryid = "other";

      for (var i=0; i<document.form1.state.length; i++)
      {
          stateitem = document.form1.state[ i ].value.split( "|" );
          cid       = stateitem[1];

          if (cid == countryid)
          {
             document.form1.state.selectedIndex   = i;
             if (cid != "other")
                document.form1.otherstate.value      = "";
             return;
          }
      }
      document.form1.state.selectedIndex = document.form1.state.length - 1;
   }
}
