
//=========================================================================================
//*** commonFunctions.js
//***   --> called in header.ch2 & popupheader.ch2
//=========================================================================================


//*****************************************************************************************
//*** Browser Stats
//*****************************************************************************************
var isNav = false;
var isIE  = false;
var isMac = false;
var isWin = false;

var isNS4 = false;
var isNS40 = false;    // NS 4.08 will not displayed QT from  RTSP server so we send a message
var isIE4 = false;
var isIE5 = false;
var isNS6 = false;

//*** Determine Browser Stats

if (navigator.appName == "Netscape") { 
   isNav = true; 
} else { 
   isIE = true; 
}

if (navigator.appVersion.indexOf("Mac") != -1) isMac = true;
if (navigator.appVersion.indexOf("Win") != -1) isWin = true;

//*** Determine Browser version

isNS4 = (document.layers) ? true : false;
isIE4 = (document.all && !document.getElementById) ? true : false;
isIE5 = (document.all && document.getElementById) ? true : false;
isNS6 = (!document.all && document.getElementById) ? true : false;

//*****************************************************************************************
//*** FUNCTIONS: win & smallWin:  open popup windows
//*****************************************************************************************
function win(pagename, scrollbars, width, height) { 
  if (scrollbars=='yes') width = width + 17;
  
  if ((navigator.appVersion.indexOf('Win') != -1) && (navigator.appName == "Netscape")) 
     popWin = window.open(pagename,"indigo","height="+height+",width="+width+",status=no,toolbar=no,menubar=no,resizable=yes,scrollbars="+scrollbars);
  else if (( navigator.appVersion.indexOf('Mac') != -1) && (navigator.appName == "Netscape"))  
     popWin = window.open(pagename,"indigo","height="+height+",width="+width+",status=no,toolbar=no,menubar=no,resizable=yes,scrollbars="+scrollbars);
  else if (( navigator.appVersion.indexOf('Mac') != -1) && (navigator.appName == "Microsoft Internet Explorer"))
     popWin = window.open(pagename,"indigo","height="+(height-16)+",width="+(width-16)+",status=no,toolbar=no,menubar=no,resizable=yes,scrollbars="+scrollbars);
  else popWin = window.open(pagename,"indigo","height="+height+",width="+width+",status=no,toolbar=no,menubar=no,resizable=yes,scrollbars="+scrollbars);
 
  if (popWin.opener == null) popWin.opener = self;    // Give a handle of the current window to the popup, so it can easily call it back.
        
  popWin.focus(); // Switch the focus on the already opened popup
}

// self.name = 'mainWindow';

function smallWin(pagename, scrollbars, width, height) { 
  var winLeft = (screen.width - width) / 2;
  var winTop  = (screen.height - height) / 2;
  
  if (scrollbars=='yes') width = width + 17;
  
  if ((navigator.appVersion.indexOf('Win') != -1) && (navigator.appName == "Netscape")) 
     popSmall = window.open(pagename, "demo", "height=" + height + ",width=" + width + 
                                      ",left=" + winLeft + ",top=" + winTop +
                                      ",status=no,toolbar=no,menubar=no,resizable=no,scrollbars="+scrollbars);
                                      
  else if (( navigator.appVersion.indexOf('Mac') != -1) && (navigator.appName == "Netscape"))  
     popSmall = window.open(pagename, "demo" , "height=" + height + ",width=" + width + 
                                      ",left=" + winLeft + ",top=" + winTop +
                                      ",status=no,toolbar=no,menubar=no,resizable=no,scrollbars="+scrollbars);
                                      
  else if (( navigator.appVersion.indexOf('Mac') != -1) && (navigator.appName == "Microsoft Internet Explorer"))
     popSmall = window.open(pagename, "demo", "height=" + (height-16) + ",width=" + (width-16) + 
                                      ",left=" + winLeft + ",top=" + winTop +
                                      ",status=no,toolbar=no,menubar=no,resizable=no,scrollbars="+scrollbars);
                                      
  else popSmall = window.open(pagename, "demo", "height=" + height + ",width=" + width + 
                                        ",left=" + winLeft + ",top=" + winTop +
                                        ",status=no,toolbar=no,menubar=no,resizable=no,scrollbars="+scrollbars);
 
  if (popSmall.opener == null) popSmall.opener = self;    // Give a handle of the current window to the popup, so it can easily call it back.
        
  popSmall.focus(); // Switch the focus on the already opened popup
}
//**************************************************************************************************
//*** FUNCTION copybillingaddress()
//**** >> Bloodly NS4 exception....
//**************************************************************************************************

function copybillingaddress() {
   if (isNS4) {
      document.topNavMainDiv.document.checkoutform.shippingstreet1.value       = document.topNavMainDiv.document.checkoutform.street1.value;
      document.topNavMainDiv.document.checkoutform.shippingcity.value          = document.topNavMainDiv.document.checkoutform.city.value;
      document.topNavMainDiv.document.checkoutform.shippingregion.value        = document.topNavMainDiv.document.checkoutform.region.value;
      document.topNavMainDiv.document.checkoutform.shippinginternational.value = document.topNavMainDiv.document.checkoutform.international.value;
      document.topNavMainDiv.document.checkoutform.shippingcountryid.value     = document.topNavMainDiv.document.checkoutform.countryid.value;
      document.topNavMainDiv.document.checkoutform.shippingzipcode.value       = document.topNavMainDiv.document.checkoutform.zipcode.value;
   } else {
      document.checkoutform.shippingstreet1.value       = document.checkoutform.street1.value;
      document.checkoutform.shippingcity.value          = document.checkoutform.city.value;
      document.checkoutform.shippingregion.value        = document.checkoutform.region.value;
      document.checkoutform.shippinginternational.value = document.checkoutform.international.value;
      document.checkoutform.shippingcountryid.value     = document.checkoutform.countryid.value;
      document.checkoutform.shippingzipcode.value       = document.checkoutform.zipcode.value;
   }
}

//**************************************************************************************************
//*** FUNCTION submitForm (divName, formName)
//**** >> since NS4 is buggy when Forms are Nested within DIV's these functions were created.
//**************************************************************************************************

function submitForm(divName, formName) {
  if (isNS4 && divName != null) {
    eval('document.' + divName + '.document.' + formName + '.submit()');
  } else {
    eval('document.' + formName + '.submit()');
  }
}

function submitCartForm(divName, formName, fieldValue) {
// document.cartform.destination.value="store.ch2"
  if (isNS4 && divName != null) {
    eval('document.' + divName + '.document.' + formName + '.destination.value="' + fieldValue + '"');
    eval('document.' + divName + '.document.' + formName + '.submit()');
  } else {
    eval('document.' + formName + '.destination.value="' + fieldValue + '"');
    eval('document.' + formName + '.submit()');
  }
}

function submitCheckOutForm(divName, formName, formAction) {
// document.editform.action = 'checkoutinformation.ch2'
  if (isNS4 && divName != null) {
    eval('document.' + divName + '.document.' + formName + '.action="' + formAction + '"');
    eval('document.' + divName + '.document.' + formName + '.submit()');
  } else {
    eval('document.' + formName + '.action="' + formAction + '"');
    eval('document.' + formName + '.submit()');
  }
}

//**************************************************************************************************
//*** Forms: Check length and move to next Field      validChars = "1234567890abcdefghijklmnopqrstuvwxyz";
//**************************************************************************************************

function jumpLicense(formName, currentField, nextField, fixedLen) {  

  if (isNS4) {
    divName = "topNavMainDiv";
    fieldName = eval('document.' + divName + '.document.' + formName + '.' + currentField);
    fieldFocusName = eval('document.' + divName + '.document.' + formName + '.' + nextField);
  } else {
    fieldName = eval('document.' + formName + '.' + currentField);
    fieldFocusName = eval('document.' + formName + '.' + nextField); 
  }
  
  fieldValue = fieldName.value;
  if (fieldValue.length == fixedLen) {
    if (nextField != 'done') {
      fieldFocusName.focus(); 
    } 
  }
}
//**************************************************************************************************
//*** NETSCAPE4 RELOAD [fix for DIV resizing problem with NS4]
/*
if (numChars == fixedLen) {
    if (nextField != 'done')  { 
      eval('document.registerform.' + nextField + '.focus()'); 
    }
    numChars = 0;
  } 
  else { numChars += 1; }
*/  
//**************************************************************************************************

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

MM_reloadPage(true);
