//    spg.js
//    seaportGraphics javascript include
//    nick murray 06/25/06


     var req_obj = null ;       // AJAX - httpxmlrequest object


     function toggleOn(divId){
     // 1. toggle off all level2+ menus as you navigate down the menu
     // 2. toggle on the appropriate L2 submenu
     // 3. if there is no submenu pass the L1 menu item it simply 
     //    redisplays itself in position and obviates throwing errors
             
     if (divId.indexOf('L1')>0) { 
         toggleOff("ddSeaportL2"); toggleOff("ddServicesL2"); toggleOff("ddPriceQuoteL2"); toggleOff("ddUploaderL2"); toggleOff("ddSupportL2"); 
   	} //alert('L2 - ' + divId);}
     if (divId.indexOf('L2')>0) { 
         toggleOff("ddSeaportL2"); toggleOff("ddServicesL2"); toggleOff("ddPriceQuoteL2"); toggleOff("ddUploaderL2"); toggleOff("ddSupportL2"); 
   	} //alert('L2 - ' + divId);}
     if (document.getElementById){
        mnu = document.getElementById(divId);
        mnu.style.display = "block"; 
        }
     divId = '';
      }
             
     function toggleOffMenu(divId){
        toggleOff("ddSeaportL2"); toggleOff("ddServicesL2"); toggleOff("ddPriceQuoteL2"); toggleOff("ddUploaderL2"); toggleOff("ddSupportL2"); 
      }
                
     function toggleOff(divId){
     if (document.getElementById){
       mnu = document.getElementById(divId);
       mnu.style.display = "none"; }
     } 


    function layer_spot_img(L){
       var img1 = document.getElementById('spot_img_1');
       var img2 = document.getElementById('spot_img_2');
       //var txt1 = document.getElementById('spot_txt_1');
       //var txt2 = document.getElementById('spot_txt_2');
       if (L == '1') {img1.style.zIndex = 1010;
                      img2.style.zIndex = 1000;
                      //txt1.style.backgroundColor = '#889';       
                      //txt2.style.backgroundColor = '#aab';
                      }
       if (L == '2') {img1.style.zIndex = 1000;
                      img2.style.zIndex = 1010;
                      //txt1.style.backgroundColor = '#aab';       
                      //txt2.style.backgroundColor = '#889';
                     } 
         } 


    function layer_spot_img_4(L){
       var img1 = document.getElementById('spot_img_4_1');
       var img2 = document.getElementById('spot_img_4_2');
       //var txt1 = document.getElementById('spot_txt_1');
       //var txt2 = document.getElementById('spot_txt_2');
       if (L == '1') {img1.style.zIndex = 1010;
                      img2.style.zIndex = 1000;
                      //txt1.style.backgroundColor = '#889';       
                      //txt2.style.backgroundColor = '#aab';
                      }
       if (L == '2') {img1.style.zIndex = 1000;
                      img2.style.zIndex = 1010;
                      //txt1.style.backgroundColor = '#aab';       
                      //txt2.style.backgroundColor = '#889';
                     } 
         } 


   function layer_spot_img_8(L){
       var img1 = document.getElementById('spot_img_8_1');
       var img2 = document.getElementById('spot_img_8_2');
       //var txt1 = document.getElementById('spot_txt_1');
       //var txt2 = document.getElementById('spot_txt_2');
       if (L == '1') {img1.style.zIndex = 1010;
                      img2.style.zIndex = 1000;
                      //txt1.style.backgroundColor = '#889';       
                      //txt2.style.backgroundColor = '#aab';
                      }
       if (L == '2') {img1.style.zIndex = 1000;
                      img2.style.zIndex = 1010;
                      //txt1.style.backgroundColor = '#aab';       
                      //txt2.style.backgroundColor = '#889';
                     } 
         } 


   function layer_spot_img_9(L){
       var img1 = document.getElementById('spot_img_9_1');
       var img2 = document.getElementById('spot_img_9_2');
       //var txt1 = document.getElementById('spot_txt_1');
       //var txt2 = document.getElementById('spot_txt_2');
       if (L == '1') {img1.style.zIndex = 1010;
                      img2.style.zIndex = 1000;
                      //txt1.style.backgroundColor = '#889';       
                      //txt2.style.backgroundColor = '#aab';
                      }
       if (L == '2') {img1.style.zIndex = 1000;
                      img2.style.zIndex = 1010;
                      //txt1.style.backgroundColor = '#aab';       
                      //txt2.style.backgroundColor = '#889';
                     } 
         } 


   function get_swf(swf,w,h ){

      var agt = navigator.userAgent.toLowerCase();
      var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
      
      // the elements placed in the page using jasvascript are not visisble when viewing source.
      // only the old source is is visible, even when the user-agent overwrites the old source.
      // build a contaimer div id=content; append child elements id=SeaportHome; 
      // remove any element id=SeaportHome and replace it with new content=SeaportHome
      // to swap pages in and out of content div.
      if (document.getElementsByName){
         cn = document.getElementById('content');
         if (sp = document.getElementById('SeaportHome')){ cn.removeChild(sp);}
         cn.style.background = "Url(white.gif)";
         if (is_ie){
            em  = document.createElement('embed');
            em.setAttribute("src", swf);         
            em.setAttribute("menu", "false");         
            em.setAttribute("quality", "high");         
     //     em.setAttribute("bgcolor", "#ffffff");         
            em.setAttribute("wmode", "transparent");         
            em.setAttribute("width", w);         
            em.setAttribute("height", h);
            em.setAttribute("name", "SeaportHome");
            em.setAttribute("align", "top");
            em.setAttribute("name", "SeaportHome");
            em.setAttribute("id", "SeaportHome");
            em.setAttribute("allowScriptAccess", "sameDomain");
            em.setAttribute("type", "application/x-shockwave-flash");
            em.setAttribute("pluginspage", "SeaportHome");
            em.setAttribute("allowScriptAccess", "http://www.macromedia.com/go/getflashplayer");
            fl = cn.appendChild(em);
             } //if is_ie
         else { 
            ob = document.createElement("OBJECT");
            ob.setAttribute("classid", "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000");         
            ob.setAttribute("codebase", "http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0");         
            ob.setAttribute("width", w);         
            ob.setAttribute("height", h);         
            ob.setAttribute("id", "SeaportHome");         
            //ob.setAttribute("align", "top");   
            ob.style.zIndex=-10; 
            p1 = ob.appendChild(document.createElement('param'));
            p1.setAttribute("name", "allowScriptAccess");         
            p1.setAttribute("value", "sameDomain");         
            p2 = ob.appendChild(document.createElement('param'));
            p2.setAttribute("name", "movie");         
            p2.setAttribute("value", swf);         
            p3 = ob.appendChild(document.createElement('param'));
            p3.setAttribute("name", "menu");         
            p3.setAttribute("value", "false");         
            p4 = ob.appendChild(document.createElement('param'));
            p4.setAttribute("name", "quality");         
            p4.setAttribute("value", "high");         
            p5 = ob.appendChild(document.createElement('param'));
            p5.setAttribute("name", "wmode");         
            p5.setAttribute("value", "transparent");         
            p6 = ob.appendChild(document.createElement('param'));
            p6.setAttribute("name", "align");         
            p6.setAttribute("value", "top");         
            em = ob.appendChild(document.createElement('embed'));
            em.setAttribute("src", swf);         
            em.setAttribute("menu", "false");         
            em.setAttribute("quality", "high");         
            em.setAttribute("wmode", "transparent");         
            em.setAttribute("width", w);         
            em.setAttribute("height", h);
            em.setAttribute("name", "SeaportHome");
            em.setAttribute("align", "top");
            em.setAttribute("name", "SeaportHome");
            em.setAttribute("allowScriptAccess", "sameDomain");
            em.setAttribute("type", "application/x-shockwave-flash");
            em.setAttribute("pluginspage", "SeaportHome");
            em.setAttribute("allowScriptAccess", "http://www.macromedia.com/go/getflashplayer");

           fl = cn.appendChild(ob);

         } //else is_ie         
    /*
         hdr = document.getElementById('header');
         if (hdr.hasChildNodes()){
            nl = hdr.childNodes;
            //alert('hdr_child nl len=' + nl.length + '\n');
            msg = '';
            for (var i = 0; i < nl.length; i++){
               msg = msg + i + ' name:' + nl[i].nodeName + '  value:' + nl[i].nodeValue + '\n';
               }
            alert(msg);
           }
         else {
            alert('hdr has NO childnodes');
              }
    */

        } //if getElbyID
      } //function end


   // ---------- AJAX INIT XMLHttpRequest ------------------

   function xmlreqobj(){
      // httpxmlrequest connection object and connection state handler
      // Check existing connections 
     if (req_obj != null && req_obj.readyState != 0 && req_obj.readyState != 4){req_obj.abort();}
     if (window.XMLHttpRequest) { // Mozilla, Safari,...
         req_obj = new XMLHttpRequest();
         }
     else if (window.ActiveXObject) { // IE
         try {req_obj = new ActiveXObject("Msxml2.XMLHTTP");}
         catch (e) {
            try {req_obj = new ActiveXObject("Microsoft.XMLHTTP");}
            catch (e) {}
             }
         }
     if (!req_obj) {
         alert('Cannot create XMLHTTPRequest object');
         return false;
         }
     alert('Created XMLHTTPRequest object');
     return true; 
     }
   

  

  function check_upload(){
         if (xmlreqobj() == true ) {
             alert('check_upload xmlreqobj==true'); 
             req_obj.onreadystatechange = validate_upload;
             req_obj.open('GET', '../upload_1.asp?action=checkupload')
             req_obj.send(null);
             // !! For method=POST !! header placement critical - content must be sent directly after header 
             //   (if placed before obj.open() method asp server will return html to browser
             //    and we want the browser page to remain as is.
             // req_obj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');  
             // req_obj.send('prodsize=' + psize + '&amp;prodqty=' + qty);
               }
     }

   function validate_upload() { 
   //    alert('validate_upload()'); //;, readystate==' + req_obj.readystate +',status==' + req_obj.status );
   /*    var bUpload = null;
       if (req_obj.readyState == 4) { 
          alert('validate_upload() readystate==' + req_obj.readystate);
           if (req_obj.status == 200)  {
              alert('upload status=' + req_obj.responseText());
               //var ret = req_obj.responseText();
               //var p_frm1 = document.forms['cat_frm_' + prod_id].parentNode;
               //if (document.getElementsByName){
               //   //alert ('btn_vc_' + prod_id); 
               //   var btn = document.getElementById('btn_vc_' + prod_id) ;
               //   btn.style.display = "block";    
                  }
              }
      // else {
      //       // var emsg = document.createTextNode('sorry, \'add to cart failed\'. please try again later.');
      //        var emsg = ('sorry, \'add to cart failed\'. please try again later.');
      //        alert(emsg);
      //        return false;
      //        }
      //    } 
   */   }




  /* -------------  window functions ------------------- */


  function popwin(fn, fh, fw){
     //alert('popwin(' + fn + ', ' + fh + ', ' + fw + ')');
     fw = 'width=' + fw ;
     fh = 'height=' + fh;
     args = fh + ',' + fw ;
     win1 = window.open(fn,"",args );
     //win1 = window.open(fn , 'SeaportGraphics Uploading...', args);
     //win1.moveTo(x, y)
     } 




 function getWindowWidth() {
    var w = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
       //Non-IE
       w = window.innerWidth;
       myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
       //IE 6+ in 'standards compliant mode'
       w = document.documentElement.clientWidth;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
       //IE 4 compatible
      w = document.body.clientWidth;
    }
  //  window.alert( 'Width = ' + myWidth );

   return w;
 }


 function getWindowHeight() {
    var ht = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
       //Non-IE
       ht = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
       //IE 6+ in 'standards compliant mode'
       ht = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
       //IE 4 compatible
       ht = document.body.clientHeight;
    }
     //  window.alert( 'Height = ' + myHeight );
   return ht;
 }










