//ENCODE ALL MAILTO LINKS
//------------------------
function emailLink(linkName) {
    coded = "RVCe@zhuvFRxu-mvh.zeq"
    key = "C9h6mXWkDwR3eLaBp8tHAG52ZqMOnJySPu4vYKcFUfbrQj0NEV1iTo7Ixdlzgs"
    shift=coded.length
    link=""

    for (i=0; i<coded.length; i++) {
        if (key.indexOf(coded.charAt(i))==-1) {
            ltr = coded.charAt(i)
            link += (ltr)
        }
        else {     
            ltr = (key.indexOf(coded.charAt(i))-shift+key.length) % key.length
            link += (key.charAt(ltr))
        }
    }

    //determine links display name
    //----------------------------
    if (linkName == '1') {
        document.write("<a href='http://www.creative-jar.com/start-a-dialogue/enquiry-form'>Email Us</a>");
    }
    else { 
        document.write("<a href='http://www.creative-jar.com/start-a-dialogue/enquiry-form'>"+link+"</a>");
    }
}


/*
    FlashReplace is developed by Robert Nyman, http://www.robertnyman.com. License and downloads: http://code.google.com/p/flashreplace/
*/
// ---
var FlashReplace = {
    elmToReplace : null,
    flashIsInstalled : null,
    defaultFlashVersion : 7,
    replace : function (elmToReplace, src, altsrc, id, width, height, version, params){
        this.elmToReplace = document.getElementById(elmToReplace);
        this.flashIsInstalled = this.checkForFlash(version || this.defaultFlashVersion);
        if(this.elmToReplace && this.flashIsInstalled){
            var obj = '<object' + ((window.ActiveXObject)? ' id="' + id + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" data="' + src + '"' : '');
            obj += ' width="' + width + '"';
            obj += ' height="' + height + '"';
            obj += '>';
            var param = '<param';
            param += ' name="movie"';
            param += ' value="' + src + '"';
            param += '>';
            param += '';
            var extraParams = '';
            var extraAttributes = '';
            for(var i in params){
	            extraParams += '<param name="' + i + '" value="' + params[i] + '">';
	            extraAttributes += ' ' + i + '="' + params[i] + '"';
            }
            var embed = '<embed id="' + id + '" src="' + src + '" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"';
            var embedEnd = extraAttributes + '></embed>';
            var objEnd = '</object>';
            this.elmToReplace.innerHTML = obj + param + extraParams + embed + embedEnd + objEnd;			
        }
        else {
            var imagecntopen = '<div style="width: ' + width + '; height: ' + height + '; position: relative;">';
            var imagecntclose = '</div>';
            var errmsg = '<div id="flash-error-bg" class="error-bg" style="width: ' + width + 'px; display: block;"></div><div id="flash-error-msg" class="error-msg" style="width: ' + width + 'px; display: block;"><span class="closebutton"><a href="javascript:close(\'flash-error-bg|flash-error-msg\')" title="Close"><img src="/themes/cj/img/cross.png" alt="Close" class="img-icon-small" /></a></span><p>You need to install flash to use this page.</p></div>';
            var pic = '<img src="' + altsrc + '" alt="" width="' + width + '" height="' + height + '" class="img" />';
            this.elmToReplace.innerHTML = imagecntopen + errmsg + pic + imagecntclose;	
        }
    },
	
    checkForFlash : function (version){
        this.flashIsInstalled = false;
        var flash;
        if(window.ActiveXObject){
            try{
	            flash = new ActiveXObject(("ShockwaveFlash.ShockwaveFlash." + version));
	            this.flashIsInstalled = true;
            }
            catch(e){
	            // Throws an error if the version isn't available			
            }
        }
        else if(navigator.plugins && navigator.mimeTypes.length > 0){
            flash = navigator.plugins["Shockwave Flash"];
            if(flash){
	            var flashVersion = navigator.plugins["Shockwave Flash"].description.replace(/.*(\d+\.\d+).*/, "$1");
	            if(flashVersion >= version){
		            this.flashIsInstalled = true;
	            }
            }
        }
        return this.flashIsInstalled;
    }
};

/*
    Closing specified range of elements like divs etc.
*/
function close(elementNames) {
    var elementsArray = elementNames.split("|");
    for(var i = 0; i < elementsArray.length; i++)
    {
        document.getElementById(trim(elementsArray[i])).style.display = "none";
    }
}


/*
    Trimming a string 
*/
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


