// write "js" class to HTML tag for use by CSS selectors
var HTMLTag = document.getElementsByTagName('html');
HTMLTag[0].setAttribute((document.all ? "className" : "class"),"js");

//function for adding jQuery core script to a page
function loadjQuery() {
    document.write("<scr"+"ipt type=\"text/javascript\" src=\"/au/scripts_jquery_min_12803.js\"></scr"+"ipt>");   
}

//function to open Portal for Feedback Survey
function openSurveyPortal() {
    openPortal('FeedbackSurvey','/us/12145.html','','52','70','0');
}

// preload global nav images
if(document.images) {
    
    image3226 = new Image();
    image3226.src = "/images/bg_menu.gif";
    //
    image3228 = new Image();
    image3228.src = "/images/bg_menu_over.gif";
    //
    image5092 = new Image();
    image5092.src = "/images/bg_topmenu_over.gif";
    //
    image5097 = new Image();
    image5097.src = "/images/bg_currentmenu_over.gif";
    //
    image5098 = new Image();
    image5098.src = "/images/bg_fo-menulnk.gif";
    //
    image5099 = new Image();
    image5099.src = "/images/bg_fo-menulnk_over.gif";
    //
    image5100 = new Image();
    image5100.src = "/images/bg_menu_dotted-line.gif";
    //
    image5101 = new Image();
    image5101.src = "/images/bg_l3menu.gif";
    //
    image5102 = new Image();
    image5102.src = "/images/bg_l3menu_dotted.gif";
    //
    image5103 = new Image();
    image5103.src = "/images/bg_menulogin.gif";
    //
    image12154 = new Image();
    image12154.src = "/images/surveybtn_over.gif";
    //
}
//end


function showDiv (DivID) {
document.getElementById(DivID).style.display = 'block';
}
function hideDiv (DivID) {
document.getElementById(DivID).style.display = 'none';
}

//preferred function for "image" rollovers
/*
    Standards Compliant Rollover Script
    Author : Daniel Nolan
    http://www.bleedingego.co.uk/webdev.php
    
    Implementation: set class="imgover" inside <img> tag. No other classes should be set.
*/
function initRollovers() {
    if (!document.getElementById) return
    
    var aPreLoad = new Array();
    var sTempSrc;
    var aImages = document.getElementsByTagName('img');
    for (var i = 0; i < aImages.length; i++) {        
        if (aImages[i].className == 'imgover') {
            var src = aImages[i].getAttribute('src');
            var ftype = src.substring(src.lastIndexOf('.'), src.length);
            var hsrc = src.replace(ftype, '_over'+ftype);
            aImages[i].setAttribute('hsrc', hsrc);
            
            aPreLoad[i] = new Image();
            aPreLoad[i].src = hsrc;
            
            aImages[i].onmouseover = function() {
                sTempSrc = this.getAttribute('src');
                this.setAttribute('src', this.getAttribute('hsrc'));
            }    
            
            aImages[i].onmouseout = function() {
                if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_over'+ftype, ftype);
                this.setAttribute('src', sTempSrc);
            }
            
            aImages[i].onclick = function() {
                if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_over'+ftype, ftype);
                this.setAttribute('src', sTempSrc);
            }
            
        }
    }
}
//end
 

//navigation from pull-down menus
function forward (whichItem) {
    var whichDest = whichItem[whichItem.selectedIndex].value;
    if (whichDest == "nothing") {
        whichItem.selectedIndex = 0;
    } else {
        document.location = whichDest; 
    }
} 
//end
 

//functions for enlarging/reducing embedded diagrams
var currentDiagram = '';
function showDiagram(DiagramID) {
        currentDiagram=DiagramID;
    
        smDiagramHeight=document.getElementById(currentDiagram+'_sm').height;
        lgDiagramHeight=document.getElementById(currentDiagram+'_lg').height;
        var newTop=smDiagramHeight-lgDiagramHeight+30;    
        
  document.getElementById(currentDiagram+'_popup').style.top=newTop+'px';
  //document.getElementById(currentDiagram+'_popup').style.right=17+'px';
  setTimeout("document.getElementById(currentDiagram+'_popup').style.visibility='visible'",100);
}
function hideDiagram() {
 document.getElementById(currentDiagram+'_popup').style.visibility='hidden';
}
//end

//gets the country name selected
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
//end

//cookie functions for the worldwide pulldown menus
//variables for the cookie functions
var expDays = 365; //sets expiration time
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

//gets the cookie that contains the selection then returns the selected value using getCookieVal()
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + exp)) +
"; path=/" +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
//end

//used to delete the cookie if necessary
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
} 
//end
//end of cookie functions


//FUNCTIONS FOR AUTO-HEIGHT EMBEDDED "Content" IFRAME 
function resizeContentFrame(frame) {
    var currentFrame = frame;
    var iFrameID = document.getElementById(currentFrame);
    iFrameID.style.height = 0;
    var iFrameName = window.frames[currentFrame];
    var iFrameDocBodyHeight = '';        
    var iFrameDoc = iFrameName.document;
    var iFrameDocURL = iFrameDoc.URL;        
    var iFrameDocBody = iFrameDoc.getElementsByTagName('body');
    iFrameDocBodyHeight = iFrameDocBody[0].offsetHeight;
    iFrameID.style.height = parseInt(iFrameDocBodyHeight) + 0 + 'px';
    //top.document.location.hash = '#pgheader';
}
//end
 

// FUNCTIONS FOR POPUP "Portal" IFRAME

// GLOBAL PORTAL VARIABLES
var portalInitStatus = 0;
var portalStatus = '';
var PageMaskOpacity = 0;
var delay;
var thePortal = '';
var thePortalName = '';
var thePortalWindow = '';
var thePortalDoc = '';
var thePortalDocBody = '';
var thePageMask = '';
var thePortalShadow = '';
var thePortalContainer = '';
var thePortalFlash = '';
var theDomainStatus = 0;
    
    
// TURN PAGE MASK ON           
function pageMaskOn() {
        if((portalHeight + scrolledHeight) >= top.document.body.offsetHeight*0.1) {
            top.document.getElementById('pagemask').style.height = portalHeight + scrolledHeight + 7.5 + 'em';
        }
        else {
        thePageMask.style.height = top.document.body.offsetHeight*0.1 + 'em';
    }
    thePageMask.style.display = "block";
    fadeIn();
}
// FADE PAGE MASK ON            
function fadeIn() {
    if(PageMaskOpacity < .75) {
        PageMaskOpacity = PageMaskOpacity + .1;
        thePageMask.style.opacity = PageMaskOpacity;
        thePageMask.style.filter = 'alpha(opacity=' + PageMaskOpacity*100 + ')';
        delay=setTimeout("fadeIn()",10);
    }
}
 
// FADE PAGE MASK OFF           
function pageMaskOff() {
    if(PageMaskOpacity > 0) {
        PageMaskOpacity = PageMaskOpacity - .1;
        thePageMask.style.opacity = PageMaskOpacity;
        thePageMask.style.filter = 'alpha(opacity=' + PageMaskOpacity * 100 + ')';
        delay=setTimeout("pageMaskOff()",10);
    }
    else {
        PageMaskOpacity = 0;
        thePageMask.style.display = "none";
    }
}

// INITIALIZE PORTAL VARIABLES
function initPortalVariables() {
    if(top.document.getElementById('portal')) {
    thePageMask = top.document.getElementById('pagemask');
    thePortalContainer = top.document.getElementById('portalcontainer');
    thePortalShadow = top.document.getElementById('portalshadow');
    thePortal = top.document.getElementById('portal');
    thePortalWindow = top.document.getElementById('portal').contentWindow;     
    //thePortalDoc = thePortalWindow.document;
    }
}     
        
// OPEN NEW DOCUMENT IN PORTAL        
function openPortal(PortalName,PortalFrameURL,PortalPageURL,Width,Height,Padding) { 
    if(portalInitStatus == 0) {
        portalInitStatus = 1;
        document.portal.location.replace('');
        //initPortal(DomainStatus);
    }
   
    portalStatus = 'ready';

    if(portalInitStatus > 1) { 
        initPortalVariables();
    }
            
    if(Width) {
        portalWidth = parseFloat(Width);
    }
    else {
        portalWidth = '';
    }
    
    if(Height) {
        portalHeight = parseFloat(Height);
    }
    else {
        portalHeight = '';
    }
    
    if(Padding) {
        portalPadding = parseFloat(Padding);
    }
    else {
        portalPadding = '';
    }
    
    /*@cc_on
    if(portalInitStatus > 1) thePortalContainer.style.display = 'block';
    @*/
    
    //load the Portal iframe with new URL
    if(PortalFrameURL != '') {
        if(PortalPageURL != '') {
            newURL = PortalFrameURL + '?' + PortalPageURL + '^' + portalHeight;
            thePortalWindow.location.replace(newURL);
        }
        else {
            thePortalWindow.location.replace(PortalFrameURL);
        }
    }
    else {
        thePortalWindow.location.replace(PortalPageURL);
    }
    
    /*@cc_on
    if(portalInitStatus > 1) setTimeout("thePortalContainer.style.display = 'none';",200);
    @*/
}
   
// RESIZE PORTAL   
function resizePortal() {
    if(portalInitStatus <= 1) {
        initPortalVariables();
        if(theDomainStatus == 1) {
            openPortal('InitPortal','/initportal_dd.html','','74','0.1','0');
        }
        else {
            openPortal('InitPortal','/initportal.html','','74','0.1','0');
        }
    }
  
    thePortalContainer.style.display = 'block';
        
    //establish width & height of portal 
    if(portalWidth != '') {
        portalWidth = portalWidth + (2*portalPadding);
    }
    else {
        portalWidth = parseFloat(thePortalWindow.document.body.offsetWidth*0.1)  //converted to em units
    }
                   
    if(portalHeight != '') {
        portalHeight = portalHeight + (2*portalPadding);
    }
    else {
        portalHeight = parseFloat(thePortalWindow.document.body.offsetHeight*0.1)  //converted to em units
    } 
        
    //set new width & height of portal
    //if(portalInitStatus > 0) {
        thePortal.style.width = portalWidth + 'em';           
        thePortal.style.height = portalHeight + 'em';
        thePortalShadow.style.width = portalWidth + 'em';
        thePortalShadow.style.height = portalHeight + 'em';
        thePortalShadow.style.marginLeft = -(portalWidth/2) + 'em';
    //}
    if(portalInitStatus < 2) {
        closePortal();
    }
    else {
        positionPortal();
        pageMaskOn();
    }
}  

// POSITION PORTAL IN WINDOW
function positionPortal() {
    windowHeight = 0;
    if(typeof(top.window.innerHeight) == 'number') {    
      windowHeight = top.window.innerHeight; //Non-IE
  } 
  else {
        if(top.document.documentElement && (top.document.documentElement.clientHeight) ) {        
            windowHeight = top.document.documentElement.clientHeight; //IE 6+ in 'standards compliant mode'
        } 
        else {
            if(top.document.body && (top.document.body.clientWidth || top.document.body.clientHeight) ) {
                windowHeight = top.document.body.clientHeight; //IE 4 compatible
            }
        }
    }      
    windowHeight = windowHeight*0.1;  //convert to em units
      
      
    scrolledHeight = 0;
    if(typeof(top.window.pageYOffset) == 'number') {
        scrolledHeight = top.window.pageYOffset; //Netscape compliant
    } 
    else {
        if(top.document.body && (top.document.body.scrollTop) ) {
             scrolledHeight = top.document.body.scrollTop; //DOM compliant
        } 
        else {
            if(top.document.documentElement && (top.document.documentElement.scrollTop) ) {
                scrolledHeight = top.document.documentElement.scrollTop; //IE6 standards compliant mode
            }
        }
    }
  scrolledHeight = scrolledHeight*0.1;  //convert to em units
    
    
    documentHeight = top.document.body.offsetHeight*0.1;  //convert to em units
       
    
    //position portal in browser window
    if((portalHeight+6) <= windowHeight) {
        thePortalContainer.style.top = scrolledHeight + (windowHeight/2) - (portalHeight/2) - 4 + 'em';
    }
        
    if((portalHeight+6) > windowHeight) {
        thePortalContainer.style.top = scrolledHeight + 'em';
    }
    
    /*@cc_on
        /*@if (@_jscript_version >= 5)
            setTimeout("showPortal();",200);
        @else @*/
            showPortal();
        /*@end
    @*/
    
}

// DISPLAY PORTAL
function showPortal() {
    if(hideSelects) hideSelects();
    thePortalContainer.style.zIndex = 500;
    thePortalContainer.style.overflow = 'visible';
    thePortalContainer.style.display = 'block';
                            
    //pageMaskOn();
    
    if(portalInitStatus < 2) closePortal();
}

// CLOSE PORTAL                       
function closePortal() {
    if(thePortalContainer) {
        thePortalContainer.style.zIndex = -1;
        thePortalContainer.style.overflow = 'hidden';                           
    }
    
    if(portalInitStatus < 2) {
        portalInitStatus = parseInt(portalInitStatus) + 1;
    }
    if(portalInitStatus > 1) {    
        portalStatus = 'closed';
        if(showSelects) showSelects();
        pageMaskOff();
        if(theDomainStatus == 1) {
            thePortalWindow.location.replace('/closeportal_dd.html');
            thePortalContainer.style.display = 'none';
        }
        else {
            thePortalWindow.location.replace('/closeportal.html');
            thePortalContainer.style.display = 'none';
        }
    }
}

// INITIALIZE/RELOAD PORTAL
function initPortal(docDomainSet) {
    if(theDomainStatus == 1 || docDomainSet == 'dd') {
        theDomainStatus = 1;
        document.domain = "sonicwall.com";
    }
    if(portalStatus != 'closed') {
        if(portalInitStatus == 0) portalInitStatus = 1; 
        resizePortal();
    }
}
function loadPortalPage(docDomainSet) {
    if(theDomainStatus == 1 || docDomainSet == 'dd') {
        theDomainStatus = 1;
        document.domain = "sonicwall.com";
    }
    if(portalStatus != 'closed') {
        if(portalInitStatus == 0) portalInitStatus = 1;
        resizePortal();
    }
}


function windowInit() {
    initRollovers();
    initSelects();
}