
//=========================================================================================
//*** 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();
}


// Random value init
/*var path = new Array("set1","set2","set3","set4");
(path[Math.floor((Math.random()*4))]); 

// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 3000

// Duration of crossfade (seconds)
var crossFadeDuration = 4

// Specify the image files
var Pic = new Array() // don't touch this
// to add more images, just continue
// the pattern, adding to the array below
dir = (path[Math.floor((Math.random()*4))]);

Pic[0] = '/img/promo_box/' + dir + '/01.jpg'
Pic[1] = '/img/promo_box/' + dir + '/02.jpg'
Pic[2] = '/img/promo_box/' + dir + '/03.jpg'
Pic[3] = '/img/promo_box/' + dir + '/04.jpg'
Pic[4] = '/img/promo_box/' + dir + '/05.jpg'

// =======================================
// do not edit anything below this line
// =======================================

var t
var j = 0
var p = Pic.length

var preLoad = new Array()
for (i = 0; i < p; i++){
   preLoad[i] = new Image()
   preLoad[i].src = Pic[i]
}*/

function runSlideShow(){
   if (document.all){
      document.images.SlideShow.style.filter="blendTrans(duration=2)"
      document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)"
      document.images.SlideShow.filters.blendTrans.Apply()      
   }
   document.images.SlideShow.src = preLoad[j].src
   if (document.all){
      document.images.SlideShow.filters.blendTrans.Play()
   }
   j = j + 1
   if (j > (p-1)) j=0
   t = setTimeout('runSlideShow()', slideShowSpeed)
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

// SHOWCASE THUMBNAILS SYSTEM SHOWHIDE
var state = 'hidden';

function showhide(layer_ref) {

if (state == 'visible') {
state = 'hidden';
}
else {
state = 'visible';
}
if (document.all) { //IS IE 4 or 5 (or 6 beta)
eval( "document.all." + layer_ref + ".style.visibility = state");
}
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[layer_ref].visibility = state;
}
if (document.getElementById && !document.all) {
maxwell_smart = document.getElementById(layer_ref);
maxwell_smart.style.visibility = state;
}

}

