/**
 * @author Adam McIntyre
 * Utilities for the Nikon High- and Low-bandwidth homepages
 */
function format(str) {
    return str.replace(/&gt;/g, '>').replace(/&lt;/g, '<').replace(/&amp;lt;/g, '<').replace(/&amp;gt;/g,
            '>').replace(/'/g, "&#39;").replace(/"/g, "&quot;").replace(/=&quot;/g, "='").replace(/&quot;\s/g,
            "' ").replace(/&quot;>/g, "'>").replace(/&quot;\/>/g, "'/>").replace(/&quot;\?/g, "'?").replace(/=&#39;/g,
            "='").replace(/&#39;\s/g, "' ").replace(/&#39;>/g, "'>").replace(/&amp;#39;/g, "'").replace(/&amp;quot;/g,
            '"').replace(/" /g, "' ").replace(/<subTitle\/>/g, "<subTitle></subTitle>").replace(/<p>/g,
            "").replace(/<\/p>/g, "").replace(/<text>/g, '<text><![CDATA[').replace(/<\/text>/g,
            ']]></text>').replace(/\/NikonUSA/g, "").replace(/ C:ProjectsNikonXMLHomepagePromos.xsd/g,
            " C:\\Projects\\Nikon\\XML\\HomepagePromos.xsd");
}
function getLearnXmlStr() {
    var learnXML = '';
    learnXML += '<?xml version="1.0" encoding="UTF-8"?>';
    learnXML += "<learn xmlns='http://www.nikonusa.com' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.w3schools.com C:\Projects\Nikon\XML\HomepagePromos.xsd'>";
    learnXML += "<learnExplore>";
    learnXML += "<title>Learn and be inspired</title>";
    learnXML += "<bio><![CDATA[Learn & Explore is your gateway to educational and editorial material that will increase your knowledge of photography and inspire you to make more and better images.]]></bio>";
    learnXML += "<imagePath>assets/promo/learnExplore.jpg</imagePath>";
    learnXML += "<link>http://www.nikonusa.com/Learn-And-Explore/index.page</link>";
    learnXML += "<linkTitle>Visit Learn & Explore</linkTitle>";
    learnXML += "</learnExplore>";
    learnXML += "</learn>";
    return learnXML;
}
function getXmlStr() { return xmlStr; }
function getNewsXmlStr() { return format(newsXmlStr); }
/*
 function resize ( ) {
 var isWideScreen = true;
 var isTallScreen = true;
 if(document.body.clientWidth && document.body.clientWidth <= 1024){
 isWideScreen = false;
 }
 else if(window.innerWidth && window.innerWidth <= 1024){
 isWideScreen = false;
 if(window.innerHeight <= 1054){
 isTallScreen = false;
 }
 }

 // IE6 et al
 if(document.documentElement && document.documentElement.clientHeight <= 1054){
 isTallScreen = false;
 }
 else if(window.innerHeight && window.innerHeight <= 1054){
 isTallScreen = false;
 }

 var minLeft = 0 ;
 var minBottom = 650 ;
 var maxBottom = 800 ;
 var bottomPos = 802;
 var leftPos;
 var header = document.getElementById('header');
 var topNav = document.getElementById('topNav');
 var footer = document.getElementById('footer');
 var swf = document.getElementById('flash');

 // Conditional compilation to target IE and everyone else
 /*@cc_on
 /*@if(@_jscript_version <= 5.7)
 if(document.getElementsByTagName('object').length > 0){
 swf = document.getElementsByTagName('object')[ 0 ] ;
 }

 if(isTallScreen) {
 bottomPos = document.body.clientHeight - 80;
 }

 leftPos = ( document.body.clientWidth - 1000 ) / 2 ;
 @else @*/
/*
 if(document.getElementsByTagName('embed').length > 0){
 swf = document.getElementsByTagName('embed')[ 0 ];
 }

 if(isTallScreen) {
 bottomPos = window.innerHeight - 80 ;
 }

 leftPos = ( window.innerWidth - 1000 ) / 2 ;
 */
/*@end
 @*/
/*
 if(isWideScreen){
 swf.style.position = "absolute" ;
 swf.style.zIndex = "42";
 header.style.position = "absolute" ;
 topNav.style.position = "absolute";
 topNav.style.zIndex = "99";
 topNav.style.top = "100px"

 if ( leftPos < minLeft ) leftPos = minLeft ;

 if ( bottomPos < minBottom ) bottomPos = minBottom ;
 else if ( bottomPos > maxBottom ) bottomPos = maxBottom ;

 swf.style.left = leftPos + 'px';
 swf.style.top = '149px' ;

 var swfHeight = bottomPos - 149;
 swf.height = swfHeight ;
 swf.style.height = swfHeight + 'px' ;

 topNav.style.left = leftPos + 17 + 'px';
 header.style.left = leftPos + 17 + 'px';
 }

 footer.style.position = "absolute" ;
 if(isWideScreen) footer.style.left = leftPos + 17 + 'px';
 footer.style.top = bottomPos + 'px';
 }
 */
/***
 * Clears a text input of default text
 * @param {Object} el Input we're working with
 * @param {String} txt Default text to compare against
 */
function clearInput(el, txt) {
    if(el.value == txt) {
        el.value = '';
        el.style.color = '#000';
    }

}
var LB = 'lobandwidth';
var DUR = 14;
/***
 * Set a cookie with a value of true.
 * @param {String} name Name of cookie to set
 * @param {Number} duration Duration to set cookie for
 * @see Quirksmode's cookie page -- http://www.quirksmode.org/js/cookies.html
 */
function MO__setCookie(name, duration) {
    var d = new Date();
    d.setTime(d.getTime() + (duration * 24 * 60 * 60 * 1000));
    document.cookie = name + '=true;Expires=' + d.toGMTString();
}

/***
 * Determines if cookie of 'name' has been set on page.
 * @param {String} name Name of cookie to test
 * @see Quirksmode's cookie page -- http://www.quirksmode.org/js/cookies.html
 */
function MO__readCookie(name) {
    var nameE = name + '=';
    var cookies = document.cookie.split(';');
    for(var i = 0; i < cookies.length; i++) {
        var c = cookies[i];
        while(c.charAt(0) == ' ') {
            c = c.substr(1, c.length);
        }
        if(c.indexOf(nameE) == 0) {
            return true;
        }
    }
    return false;
}

/***
 * Removes cookie
 * @see Quirksmode's cookie page -- http://www.quirksmode.org/js/cookies.html
 */
function MO__removeCookie(name) {
    MO__setCookie(name, -1);
    return true;
}

// Test for lo-bandwidth cookie, redirect if present
if(MO__readCookie(LB)) {
    if(window.location.href.indexOf('-lo') < 0) {
        window.location.href = '/Homepage-lo.page';
    }
}

window.onload = function() {
    if(window.location.href.indexOf('-lo') < 0) {
        /*
         var f = window.resize;
         if (typeof f == 'function') {
         f();
         }
         resize();
         */
        document.getElementById('footer').style.position = 'absolute';
        document.getElementById('footer').style.top = '928px';
    }
}

