﻿//http://blog.stevenlevithan.com/archives/faster-trim-javascript
//RemovesWhite space from ends of strings
function trim(str) {
    return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

//remove to debug js
function silentErrorHandler() { return true; }
window.onerror = silentErrorHandler;

//stop top page margin appearing
var addthis_config = {
    data_use_flash: false
}
var hideOrShow = 'hidden';      //visibility of the element


function CountySelectVisible(visible) {
    if (visible == false) {
        hideOrShow = 'hidden';  
        MM_showHideLayers('iframeDisplayContainer', '', 'hide');    //sets visibility
    }
    else {
        hideOrShow = 'visible';
        MM_showHideLayers('iframeDisplayContainer', '', 'show');
    
    }
}


    function addScrollEvent() {
        //ie8 fix. mouse over scrollbar fires mouse out event. if user scrolls then hideOrShow = 'visible';
        var myFrame = document.getElementById('iframeDisplay');
        myFrame.contentWindow.onscroll = function() {
            hideOrShow = 'visible';
        };
    }



    var iFrameSetup = false;
    
    //add url to iFrame on first time user mouse over 
    function addUrlToIFrame(src) {

        //if iFrame not set up then setup
        if (iFrameSetup == false) {
            //get iframe
            var iFrame = document.getElementById('iframeDisplay');

            //add src
            iFrame.src = src;
 
            //set setup var to true
            iFrameSetup = true;
        }

        //this function is only called by the mosue over event
        hideOrShow = 'visible'; //tell the control to be visible.
    }


 
 //called by country select and body onclick
    function MM_showHideLayers() {
 
        //v9.0
        var i, p, v, obj, args = MM_showHideLayers.arguments;
        for (i = 0; i < (args.length - 2); i += 3)
            with (document) if (getElementById && ((obj = getElementById(args[i])) != null)) {
            v = args[i + 2];
            if (obj.style) { obj = obj.style; v = (v == 'show') ? 'visible' : (v == 'hide') ? 'hidden' : v; }
            obj.visibility = hideOrShow;
        }

        //debug: <div id="testdiv"></div>
        //document.getElementById('testdiv').innerHTML += "<br />hideOrShow";
                
    }



dText = "temp";
    
    
    function tbClick() {        
        //clear the default text
        if (trim(sTextBox.value) == trim(dText)) {
            sTextBox.value = "";
        }
    }
    function tbBlur() {
        //add default text if box empty
        if (trim(sTextBox.value) == "") {
            sTextBox.value = dText;
        }    
    }

    function cleanText() {
        //remove bad chars: 
        var str = trim(sTextBox.value);
        str = str.replace(/</g, " ");        //replace function: global regular expression
        str = str.replace(/>/g, " ");        
        sTextBox.value = str;
    }

    function encodeText() {
        //remove bad chars: 
        var str = trim(sTextBox.value);
        str = str.replace(/</g, "%3C");        //replace function: global regular expression
        str = str.replace(/>/g, "%3E");
        sTextBox.value = str;
    }


    //clears the default text
    function tbClick2(textBoxID) {        
        if (trim(textBoxID.value) == trim(dText)) {
            textBoxID.value = "";
        }
    }



    //If no text will add default Text to text box
    //also 
    //Removes bad chars form any existing text
    //Ttakes the Text Box Object
    function tbBlur2(textBoxID) {
 
        //add default text if box empty
        if (trim(textBoxID.value) == "") {
            textBoxID.value = dText;
        }
        else {
            //If there is text, remove bad chars: 
            var str = trim(textBoxID.value);
            str = str.replace(/</g, " ");        //replace function: global regular expression
            str = str.replace(/>/g, " ");       //opening and closing Code tags
            textBoxID.value = str;
        }
    }


    //removes bad chars from  a text box. Takes the Text Box Unique ID
    function cleanText2(textBoxID) {
        var tBox = document.getElementById(textBoxID);
       
        if (tBox != null) {
            var str = trim(tBox.value);
            str = str.replace(/</g, " ");        //replace function: global regular expression
            str = str.replace(/>/g, " ");
            tBox.value = str;
        }
    }


 