// some information from our users environment
var agt = navigator.userAgent.toLowerCase();
var is_opera = (agt.indexOf('opera') != -1);
var is_msie = (agt.indexOf('msie') != -1 && !is_opera );
var is_safari_103 = (agt.indexOf('safari/312') != -1 );

// alert("DEBUG: " + agt );

var oldBrowser = false;
var isNS4 = false;
var isNS6 = false;
var isIE4 = false;
var isIE5 = false;
var xPosition = 0;

if ( parseInt( navigator.appVersion ) < 4 ) {
   oldBrowser = true
} else {	
   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;
}

// some feature tour/popup variables
document.hasWindow = 0;
var Komodo_Tour_Window;
var PDK_Tour_Window;
var AS_Popup = 'AS_Popup';
var AS_Popup_Window;
var d_win;

function ToggleTab(tabID, contentID, isUpsell){
   if(isUpsell){
      var nextActiveTab = document.getElementById( tabID );
      var nextActiveContent = document.getElementById( contentID );
      
      if( nextActiveTab == currActiveUpsellTab ){ return; }
      
      nextActiveTab.className = "activeTab";
      nextActiveContent.className = "visible";
      
      currActiveUpsellTab.className = "";
      currActiveUpsellContent.className = "hidden";
      
      currActiveUpsellTab = nextActiveTab;
      currActiveUpsellContent = nextActiveContent;
      
   } else {
      var nextActiveTab = document.getElementById( tabID );
      var nextActiveContent = document.getElementById( contentID );
      
      if( nextActiveTab == currActiveTab ){ return; }
      
      currActiveTab.className = "";
      currActiveContent.className = "hidden";
      
      nextActiveTab.className = "activeTab";
      nextActiveContent.className = "visible";
      
      currActiveTab = nextActiveTab;
      currActiveContent = nextActiveContent;
   }
}

function ShowPopup(filepath,h,w){
   var width = 568;
   var height = 420;
   
   if(h > 0){
      height  = h;
   }
   if(w > 0){
      width = w;
   }
   var resize = "yes";
   var scrollbars = "yes";
   var features = 'width='+width+',height='+height+',scrollbars='+scrollbars+',resizable='+resize+'';
   AS_Popup_Window = window.open(filepath,AS_Popup,features);
   AS_Popup_Window.focus;
   
   return false;
}

// Tour Functions
function ShowScreen( my_id, productid, h, w){
   
   var my_options = 'width='+w+',height='+h+',scrollbars=no,resize=no';
   
   //let's set a width/height for the specific tours
   if( productid == 'Komodo' ){
      my_options = 'width=830,height=620,scrollbars=no,resize=no';
      Komodo_Tour_Window = window.open( '/Products/Komodo/Tour/'+my_id+'/',AS_Popup,my_options );
      Komodo_Tour_Window.focus();
      return false;
   } else if ( productid == 'PerlDevKit' ) {
      my_options = 'width=620,height=730,scrollbars=no,resize=no';
      PDK_Tour_Window = window.open( '/Products/Perl_Dev_Kit/Tour/'+my_id+'/',AS_Popup,my_options );
      PDK_Tour_Window.focus();
      return false;      
   }
}

function ShowTour( productid, h, w ){
   
   var my_options = 'width='+w+',height='+h+',scrollbars=no,resize=no';

   //let's set a width/height for the specific tours
   if( productid == 'Komodo' ){
      my_options = 'width=830,height=620,scrollbars=no,resize=no';
      Komodo_Tour_Window = window.open( '/Products/Komodo/Tour/',AS_Popup,my_options );
      Komodo_Tour_Window.focus();
      return false;
      
   } else if ( productid == 'PerlDevKit' ) {
      my_options = 'width=620,height=730,scrollbars=no,resize=no';
      PDK_Tour_Window = window.open( '/Products/Perl_Dev_Kit/Tour/',AS_Popup,my_options );
      PDK_Tour_Window.focus();
      return false;
   }
}

function TabRedirect( baseURL, currentURL ){
   
   var subject  = location.href;

   var escapedCurrentURL = currentURL.replace(/\//,'\/');

   var regexStr = '(.*)' + escapedCurrentURL + '(.+)$';

   var regexStr2 = '(http:\/\/.*?)\/';
   
   var regexObj = new RegExp( regexStr );
   var matches = regexObj.exec( subject );

   var regexObj2 = new RegExp( regexStr2 );
   var matches2 = regexObj2.exec( subject );

   if ( matches == null) {
      if( matches2 != null ){
         var path = matches2[1] + baseURL;
         //alert("match not found... redirecting to: " + path);
         location.href = path;
         return false;
      } else {
         // nothing seemed to work hey? let the html take it then
         return true;
      }
   } else {
      if( matches2 != null ){
         var path = matches2[1] + baseURL + matches[2];
         //alert("match found... redirecting to: " + path);
         location.href = path;
         return false;
      } else {
         // nothing seemed to work, let the HTML take over
         return true;
      }
   }
}

function findPosX(obj) {
   var curleft = 0;
   if (obj.offsetParent)
   {
      while (obj.offsetParent)
      {
         curleft += obj.offsetLeft
         obj = obj.offsetParent;
      }
   }
   else if (obj.x)
      curleft += obj.x;
   return curleft;
}

function GetImageXPos(imgId){
   
   if( isIE5 || isNS6 ){
      
      xPosition = findPosX( document.getElementById(imgId) );
   } else if(isNS4){
      
   } else {
      xPosition = findPosX( document.all[imgId] )
   }
   
   return (xPosition);
}