/*
 * we use the cookie to store user screen resolution
 */
//writeCookie();
function writeCookie() {
    try {
        var today = new Date();
        var the_date = new Date("December 31, 2023");
        var the_cookie_date = the_date.toGMTString();
        var the_cookie = "screenWidth=" + screen.width;
        the_cookie += ";screenHeight=" + screen.height;
        the_cookie += ";expires=" + the_cookie_date;
        document.cookie=the_cookie;
    } catch (e) {
    }
}

/**
 * placeholder for future
 */
function myonload() {

}

/*
 * this function is called every time the user clicks on the navigation buttons
 * input example: "home.html"
 */
function nav(location) {
    document.getElementById("myIframe").src=location;
}

/*
 * this function is called only once, when the document loads.
 * checks for parameters in the URL. if found a parameter "PAGE" or "page",
 * it takes the value and loads it in the iframe.
 */
 function navToPage() {
    var qs = location.search.substring(1);
    var nv = qs.split('&');
    var url = new Object();  
    
    for(i = 0; i < nv.length; i++) {
        eq = nv[i].indexOf('=');
        url[nv[i].substring(0,eq).toLowerCase()] = unescape(nv[i].substring(eq + 1));
    }
    
    /*
     * we may pass in a parameter for the page to load from the URL
     * for example: planethiker.com?page=20040821.html
     * an email could have such a link for a person to follow.
     * so we want to load the corresponding page.
     */
    if (url.page) {       
/*
        if (url.page == "support.html") {
            navToSupport()
        } else if (url.page == "support_paypal_return.html") {
            navToSupportReturnFromPayPal();
        } else {           
            nav(url.page);              
        }
*/        
        nav(url.page);              
    } else {
        /**
         * no parameter was passed in, so we load the home page.
         */
        nav("home.html");       
    }  
}  

/**
 * called when clicking on the Support navigation button
 */
function navToSupport() {
    var f = document.getElementById("myIframe");
        
    f.scrolling="Auto";            
    f.width="100%";
    f.height="1500"; 
 //   f.frameborder="0"; 
 //   f.marginwidth="0";
    f.src="https://secure.suntoria.com/snt/donate/PageFlowDirector.jsp?LINK_ID=2250175&ACTION=NEW&FORCE_SESSION_EXPIRE=Y";  
}

/**
 * this function never gets called because there is an actual support_paypal_return.html that 
 * gets called by paypal instead.
 */
function navToSupportReturnFromPayPal() {
    var f = document.getElementById("myIframe");
        
    f.scrolling="Auto";            
    f.width="100%";
    f.height="1000"; 
//    f.frameborder="0"; 
//    f.marginwidth="0";
    f.src="https://secure.suntoria.com/snt/donate/PageFlowDirector.jsp?LINK_ID=2250175&ACTION=DONATE";    
}

/**
 * trims leading and trailing white spaces
 */
function trimString (str) {
    str = this != window ? this : str;
    return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
String.prototype.trim = trimString;
/**
 * usage example:
 *      var s = '  Kibo  ';
 *      s = s.trim();
 */

/**
 * @param elementId - get's element by id and toggles its style.display
 */
function showHide(elemId) {
    var elem = document.getElementById(elemId);

    if (elem != null && elem != undefined) {    
        if (elem.style.display == "none") {
            elem.style.display = "block";                        
        } else {
            elem.style.display = "none";
        }
    }
}

/**
 * same thing as toggleElement but with a slightly better name
 * and you can input a comma delimited list of ids that all need
 * to be toggled. for example: 'elem1Id, elem2Id, elem3Id'
 */
function showHideAll(elemIds) {
    var idArray = new Array();
    idArray = elemIds.split(',');
    
    var i = 0
    for (i = 0; i < idArray.length; i++) {
        showHide(idArray[i].trim());    
    }    
}

/**
 * write out the whole HTML text needed to embed the google flash player
 */
function startSlideShow(flashvars) {
    document.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">");
    document.write("<html><head>");
    document.write("    <title>Planet Hiker Slide Show</title>");
    document.write("    <link rel=stylesheet href='/style/planetHiker.css' type='text/css'>     ");
    document.write("    <link rel=stylesheet href='/style/navmenu.css' type='text/css'> ");
    document.write("    <script language=\"JavaScript\" src=\"/js/lib.js\" type=\"text/javascript\"></script>      ");
    document.write("</head>");
    document.write("<body>");
    
    writeNavMenu();
    
    document.write("<embed id=\"slideShow\" type=\"application/x-shockwave-flash\" src=\"http://picasaweb.google.com/s/c/bin/slideshow.swf\" "); 
    document.write("width=\"800\" height=\"533\" flashvars=\"" + flashvars + "\" ");
    document.write("pluginspage=\"http://www.macromedia.com/go/getflashplayer\"></embed>");    
    
    document.write("<br><br><a href=\"photo.php\"><img src=\"/style/arrow.gif\" border=\"0\" align=\"middle\"></b>Back to Photo Gallery</a><br>");
    
    writeFooter();
    
    document.write("</body>");
    document.write("</html>");
}

/**
 * writes into the document the navigation menu as well as the decoration immages
 * that appear that the very top and the left side of the page.
 */
function writeNavMenu() {
    //------------------left border with orange web design--------------------------------
    document.write('<DIV class="med" style="LEFT: 0px; TOP: 0px; POSITION: absolute;">');
    document.write('   <img src="/style/leftBorder.gif" border="0">');
    document.write('</div>');
    
    //------------------left border with orange web design--------------------------------
    document.write('<DIV class="med" style="LEFT: 0px; TOP: 0px; POSITION: absolute;">');
    document.write('    <img src="/style/topBorder.gif" border="0">');    
    document.write('</div>');
    
    //------------------compas------------------------------------------------------------
    document.write('<DIV class="med" style="LEFT: 30px; TOP: 20px; POSITION: absolute;">');
    document.write('    <a href="index.php">');
    document.write('        <img src="/style/compass.gif" border="0">');
    document.write('    </a>');    
    document.write('</div>');
        
    //------------------navigation menu---------------------------------------------------
    document.write('<div id="nav-menu" style="left:130px; top:60px; position:absolute; width:750px">');
    document.write('<ul>');
    document.write('<li><a href="/index.php">Home</a></li>');
    document.write('<li><a href="/photo.php">Photos</a></li>');
    document.write('<li><a href="/log.php">Log</a></li>');
    document.write('<li><a href="/travel-route-though-centeral-south-america-south-east-asia.php">Route</a></li>');
    document.write('<li><a href="/packing-list-for-backpacking-in-south-america.php">Packing List</a></li>');
    document.write('<li><a href="/contact.php">Contact</a></li>');
    document.write('</ul>');
    document.write('</div>');

    //---- shift position of content so as not to overlap the navigation menu -----------
    document.write('<div class="contentDiv">');
}

/**
 * writes into the document the navigation links at the very bottom of the page
 */
function writeFooter() {
    //-------------links in the footer----------------------------
    document.write('<br><br><br><br>');
    document.write('<div id="footer">');
    document.write('<ul>');
    document.write('<li><a href="/index.php">Home</a></li>');
    document.write('<li><a href="/photo.php">Photos</a></li>');
    document.write('<li><a href="/log.php">Log</a></li>');
    document.write('<li><a href="/travel-route-though-centeral-south-america-south-east-asia.php">Route</a></li>');
    document.write('<li><a href="/packing-list-for-backpacking-in-south-america.php">Packing List</a></li>');
    document.write('<li><a href="/contact.php">Contact</a></li>');
    document.write('</ul>');
    document.write('</div>');

    // closing DIV tag which shifts all of the body contents so as not to overlap with navigation menu
    document.write('</div>');
}