if (typeof(FR) == "undefined") {
    FR = {};
}


FR.showModalPopup = function(behaviourID) {
   var modalPopupBehavior = $find(behaviourID);
   if(modalPopupBehavior){
       modalPopupBehavior.show();
   }
}
FR.hideModalPopup = function(behaviourID) {     
   var modalPopupBehavior = $find(behaviourID);
   if(modalPopupBehavior){
       modalPopupBehavior.hide();
   }
}
FR.onLoad = {};
FR.onLoad._aError = [];
FR.onLoad._aSetup = [];
FR.onLoad._aAds = [];
FR.onLoad._aTracking = [];
FR.onLoad.prm = null;
FR.onLoad.bSetupRun = false;
FR.onLoad.runSetup = function() {
    var i;
    //page setup functions
    for (i = 0; i < this._aSetup.length; i++) {
        try {
            this._aSetup[i]();
        } catch (err) {
            this._aError.push('Setup error. index=' + i + ' desc=' + err.description);
        }
    }
    this.bSetupRun = true;
}
FR.onLoad.runTracking = function() {
    var i;
    var oE;
    var aImg = [];
    var head;

    //page tracking
    for (i = 0; i < this._aTracking.length; i++) {
        //break;
        if (this._aTracking[i].indexOf(".js") != -1) {
            if (typeof (head) == 'undefined') head = document.getElementsByTagName('head').item(0);
            var oE = document.createElement('script');
            oE.type = 'text/javascript';
            oE.src = this._aTracking[i];
            //oE.defer = true;
            head.appendChild(oE);

        } else {
            oE = new Image;
            oE.src = this._aTracking[i];
            aImg.push(oE);
        }
    }

}
FR.onLoad.runAds = function() {
    //adverts
    this.loadAds();
    //trap partial postbacks to refresh adverts
    try{ 
        if(Sys && Sys.WebForms && Sys.WebForms.PageRequestManager){
            this.prm = Sys.WebForms.PageRequestManager.getInstance();
            if (this.prm) {
                this.prm.add_pageLoaded(this.reloadAds.bind(this));
            }
        }
    } catch (err) {
        //just continue  
        //window.status = err.description; 
    }
}
FR.onLoad.reloadAds = function(sender,args){ 
    if(this.prm){
        if(this.prm.get_isInAsyncPostBack()){
            this.loadAds();
        }
    }
}

FR.onLoad.loadAds = function(loadAll) {
    if (this._aAds.length <= 0) return;
    if (!arguments.callee.ord) arguments.callee.ord = parseInt(Math.random() * 999999999);
    if (!loadAll) {
        for (i = 0; i < this._aAds.length; i++) {
            //            if (this._aAds[i].id == 'banner') {
            this.loadAd(i);
//            return;
            //            }
        }
        // height is set to 0 while page loads to stop white bg then flicker as add loads
        if (getlayer('banner')) getlayer('banner').style.height = "90px";
    }

    //    for (i = 0; i < this._aAds.length; i++) {
    //        if (this._aAds[i].id != 'banner') {
    //            this.loadAd(i);
    //        }
    //    }


}

FR.onLoad.loadAd = function(i) {
    var oCont = document.getElementById(this._aAds[i].id);
    if (oCont) {
        switch (oCont.tagName.toLowerCase()) {
            case 'script':
                oCont.src = this._aAds[i].url;
                break;
            case 'iframe':
                oCont.src = this._aAds[i].url;
                break;
            default:
                break;
        }
    }

}

FR.onLoad.addLoadSetup = function(func) {
    if (this.bSetupRun) {
        try {
            func();
        } catch (err) {
            //
        }
    } else {
        this._aSetup.push(func);
    }
}
FR.onLoad.addLoadAdvert = function(id, url) {
var oAd = new Object(); oAd.id = id;
    oAd.url = url;
    this._aAds.push(oAd);
}
FR.onLoad.addLoadTracking = function(url) {
    this._aTracking.push(url);
}
FR.test = function() {
    alert('test');
}
//$(FR.onLoad.run.bind(FR.onLoad));

function getOffsetLeft(oNode) {
    var nRet = 0;
    if (oNode.offsetParent) {
        while (oNode.offsetParent) {
            nRet += oNode.offsetLeft;
            if (oNode.scrollLeft) nRet -= oNode.scrollLeft;
            oNode = oNode.offsetParent;
        }
    } else if (oNode.x) {
        nRet = oNode.x;
    }
    return nRet;
}
function getOffsetTop(oNode) {
    var nRet = 0;
    if (oNode.offsetParent) {
        while (oNode.offsetParent) {
            nRet += oNode.offsetTop
            if (oNode.scrollTop) nRet -= oNode.scrollTop;
            oNode = oNode.offsetParent;
        }
    } else if (oNode.y) {
        nRet = oNode.y;
    }
    return nRet;
}
function truebody() {
    return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement: document.body
}
function addClass(element, value) {
    if (!element.className) {
        element.className = value;
    } else {
        element.className = element.className + " " + value;
    }
}
function hasClassName(element, className) {
    return element.className.match(new RegExp('(\\s|^)' + className + '(\\s|$)'));
}
function removeClass(element, className) {
    if (hasClassName(element, className)) {
        element.className = element.className.replace(new RegExp("(^|\\s)" + className + "(\\s|$)"), "");
    }
    window.status = element.className;
}

function removeChildnodes(oNode) {
    if (oNode) {
        while (oNode.childNodes.length > 0) {
            oNode.removeChild(oNode.firstChild);
        }
    }
}
function Mod(X, Y) {
    return X - Math.floor(X / Y) * Y
}

function hidedivs() {
    arOffdivs = getElementsByClassName('off', 'div', document);
    for (i = 0; i < getElementsByClassName.length; i++) {
        oDiv = arOffdivs[i];
        layeroff(oDiv);
    }
}
//addLoadEvent(hidedivs)

function closeTips(theDiv) {
    layeroff(getlayer(theDiv));
    SetCookie('show_' + theDiv, 'N');
}

function checkTips(theDiv) {
    if (GetCookie('show_' + theDiv) == 'N') {
        layeroff(getlayer(theDiv));
        layeroff(getlayer(theDiv + '_clear'))
    }
}

function Right(str, n) {
    if (n <= 0) return "";
    else if (n > String(str).length) return str;
    else {
        var iLen = String(str).length;
        return String(str).substring(iLen, iLen - n);
    }
}

//div switching
var agt = navigator.userAgent.toLowerCase();
var isNN = ((agt.indexOf('mozilla') != -1) && (agt.indexOf('spoofer') == -1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera') == -1) && (agt.indexOf('webtv') == -1) && (agt.indexOf('hotjava') == -1));
var isMajor = parseInt(navigator.appVersion);
var isMinor = parseFloat(navigator.appVersion);
var isNN4 = (isNN && (isMajor <= 4));
var isNN6up = (isNN && (isMajor >= 5));
var isIE = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

function getlayerdisplay(thelayer) {
    if (isNN4) {
        return (thelayer.display)
    } else {
        return thelayer.style.display
    }
}

function getlayervisibility(thelayer) {
    if (isNN4) {
        var vis = (thelayer.visibility == "hide") ? "hidden": "visible"
    } else {
        var vis = thelayer.style.visibility
    }
    return vis
}

function layerdisplayon(slayer) {
    layeron(slayer);
}

function layerdisplayoff(slayer) {
    layeroff(slayer);
}

function changeLayer(theLayer) {
    if (getlayervisibility(theLayer) == 'hidden')

    {
        layerdisplayon(theLayer);
    } else {
        layerdisplayoff(theLayer);
    }
}

function changeLayerOn(theLayer) {
    layerdisplayon(theLayer);
}

function changeLayerOff(theLayer) {
    layerdisplayoff(theLayer);
}

//enter submits forms
function submitter(f) {
    var key;
    if (document.all) {
        e = window.event;
        key = e.keyCode;
        if (key == 13) {
            document.forms(f).submit();
            e.returnValue = false;
        }
    }
    if (document.layers) {
        key = e.which;
        if (key == 13) {
            document.forms[f].submit();
        }
    }
}

//search
var varSrchString = 'Type place here';
var varAllSrchStrings = new Array();
varAllSrchStrings[0] = 'Type your school name here';
varAllSrchStrings[1] = 'Type your division/base here';
varAllSrchStrings[2] = 'Type your college name here';
varAllSrchStrings[3] = 'Type your street name here';
varAllSrchStrings[4] = 'Type your pub name here';
varAllSrchStrings[5] = 'Type your team name here';
varAllSrchStrings[6] = 'Type your work name here';
varAllSrchStrings[7] = 'Type place here';

function flipFields() {
    var nameCat = document.namesearch.category.value;
    var nameSrch = document.namesearch.search;

    if (nameCat == 'name') {
        changeLayerOn(getlayer('twofields'));
        changeLayerOff(getlayer('onefield'));
        changeLayerOff(getlayer('inactive'))
    } else if (nameCat == -1) {
        changeLayerOff(getlayer('onefield'));
        changeLayerOff(getlayer('twofields'));
        changeLayerOn(getlayer('inactive'))
    } else {
        changeLayerOn(getlayer('onefield'));
        changeLayerOff(getlayer('twofields'));
        changeLayerOff(getlayer('inactive'))
    }

    if (nameCat == 'schools') {
        if (nameSrch.value == varAllSrchStrings[0] || nameSrch.value == varAllSrchStrings[1] || nameSrch.value == varAllSrchStrings[2] || nameSrch.value == varAllSrchStrings[3] || nameSrch.value == varAllSrchStrings[4] || nameSrch.value == varAllSrchStrings[5] || nameSrch.value == varAllSrchStrings[6] || nameSrch.value == varAllSrchStrings[7] || nameSrch.value == '') {
            nameSrch.value = varAllSrchStrings[0];
        }
        varSrchString = varAllSrchStrings[0];
    } else if (nameCat == 'army') {
        if (nameSrch.value == varAllSrchStrings[0] || nameSrch.value == varAllSrchStrings[1] || nameSrch.value == varAllSrchStrings[2] || nameSrch.value == varAllSrchStrings[3] || nameSrch.value == varAllSrchStrings[4] || nameSrch.value == varAllSrchStrings[5] || nameSrch.value == varAllSrchStrings[6] || nameSrch.value == varAllSrchStrings[7] || nameSrch.value == '') {
            nameSrch.value = varAllSrchStrings[1];
        }
        varSrchString = varAllSrchStrings[1];
    } else if (nameCat == 'college') {
        if (nameSrch.value == varAllSrchStrings[0] || nameSrch.value == varAllSrchStrings[1] || nameSrch.value == varAllSrchStrings[2] || nameSrch.value == varAllSrchStrings[3] || nameSrch.value == varAllSrchStrings[4] || nameSrch.value == varAllSrchStrings[5] || nameSrch.value == varAllSrchStrings[6] || nameSrch.value == varAllSrchStrings[7] || nameSrch.value == '') {
            nameSrch.value = varAllSrchStrings[2];
        }
        varSrchString = varAllSrchStrings[2];
    } else if (nameCat == 'streets') {
        if (nameSrch.value == varAllSrchStrings[0] || nameSrch.value == varAllSrchStrings[1] || nameSrch.value == varAllSrchStrings[2] || nameSrch.value == varAllSrchStrings[3] || nameSrch.value == varAllSrchStrings[4] || nameSrch.value == varAllSrchStrings[5] || nameSrch.value == varAllSrchStrings[6] || nameSrch.value == varAllSrchStrings[7] || nameSrch.value == '') {
            nameSrch.value = varAllSrchStrings[3];
        }
        varSrchString = varAllSrchStrings[3];
    } else if (nameCat == 'pubs') {
        if (nameSrch.value == varAllSrchStrings[0] || nameSrch.value == varAllSrchStrings[1] || nameSrch.value == varAllSrchStrings[2] || nameSrch.value == varAllSrchStrings[3] || nameSrch.value == varAllSrchStrings[4] || nameSrch.value == varAllSrchStrings[5] || nameSrch.value == varAllSrchStrings[6] || nameSrch.value == varAllSrchStrings[7] || nameSrch.value == '') {
            nameSrch.value = varAllSrchStrings[4];
        }
        varSrchString = varAllSrchStrings[4];
    } else if (nameCat == 'team') {
        if (nameSrch.value == varAllSrchStrings[0] || nameSrch.value == varAllSrchStrings[1] || nameSrch.value == varAllSrchStrings[2] || nameSrch.value == varAllSrchStrings[3] || nameSrch.value == varAllSrchStrings[4] || nameSrch.value == varAllSrchStrings[5] || nameSrch.value == varAllSrchStrings[6] || nameSrch.value == varAllSrchStrings[7] || nameSrch.value == '') {
            nameSrch.value = varAllSrchStrings[5];
        }
        varSrchString = varAllSrchStrings[5];
    } else if (nameCat == 'work') {
        if (nameSrch.value == varAllSrchStrings[0] || nameSrch.value == varAllSrchStrings[1] || nameSrch.value == varAllSrchStrings[2] || nameSrch.value == varAllSrchStrings[3] || nameSrch.value == varAllSrchStrings[4] || nameSrch.value == varAllSrchStrings[5] || nameSrch.value == varAllSrchStrings[6] || nameSrch.value == varAllSrchStrings[7] || nameSrch.value == '') {
            nameSrch.value = varAllSrchStrings[6];
        }
        varSrchString = varAllSrchStrings[6];
    } else {
        if (nameSrch.value == varAllSrchStrings[0] || nameSrch.value == varAllSrchStrings[1] || nameSrch.value == varAllSrchStrings[2] || nameSrch.value == varAllSrchStrings[3] || nameSrch.value == varAllSrchStrings[4] || nameSrch.value == varAllSrchStrings[5] || nameSrch.value == varAllSrchStrings[6] || nameSrch.value == varAllSrchStrings[7] || nameSrch.value == '') {
            nameSrch.value = varAllSrchStrings[7];
        }
        varSrchString = varAllSrchStrings[7];
    }
}

//top search
function checkSrchVal() {
    if (document.namesearch.search.value == varSrchString) {
        document.namesearch.search.value = ''
    }
    if (document.namesearch.search.value == 'surname') {
        alert('No')
    }
}

function submitNameSearch() {
    var nameSrch = document.namesearch.search;
    
    if (document.namesearch.search_forename.value != 'Forename' && document.namesearch.search_forename.value != '') {
        if (document.namesearch.search.value != 'Surname' && document.namesearch.search.value != '') {
            return true;
        } else {
            alert('Please fill in a surname');
            return false;
        }
    } else {
        alert('Please fill in a forename');
        return false;
    }
}

function selectAllBox(formname) {
    for (var i = 0; i < formname.elements.length; i++) {
        var e = formname.elements[i];
        if (e.name.substring(0, 3) == 'del') {
            if (e.checked == false) {
                e.checked = true;
            } else {
                e.checked = false;
            }
        }
    }
}

//bookmark
if (typeof FRsite != 'undefined') {
    switch (FRsite) {
    case 'UK':
        var bmtitle = "Friends Reunited"
        var bmurl = "http://www.friendsreunited.co.uk";
        break;
    case 'NZ':
        var bmtitle = "Find A Kiwi - Friends Reunited"
        var bmurl = "http://www.findakiwi.co.nz";
        break;
    case 'SA':
        var bmtitle = "Friends Reunited"
        var bmurl = "http://www.friendsreunited.com/sa";
        break;
    case 'AU':
        var bmtitle = "Friends Reunited"
        var bmurl = "http://www.friendsreunited.com.au";
        break;
    case 'AS':
        var bmtitle = "Friends Reunited"
        var bmurl = "http://www.friendsreunitedAsia.com";
        break;
    default:
        var bmtitle = "Friends Reunited"
        var bmurl = "http://www.friendsreunited.co.uk";
        break;
    }
}

function addbookmark() {
    if (document.all) window.external.AddFavorite(bmurl, bmtitle)
}

var loadad = false;

var isSmall = false;
//	if ((window.screen.width<=800) && (window.screen.height<=600)){
//		isSmall = true;
//	}
var tooBig = false;

var halfMeg = 524288;
var oneMeg = 1048576;
var twoMeg = 2097152;
var fiveMeg = 5242880;

function checkSize(sFilename) {
    tooBig = false;
    var img = new Image(); //Create a temporary image
    img.src = "file:///" + sFilename;

    var startLoad = new Date(); //store when we start loading the temp image
    var endLoad = new Date(); //store when we finish loading the temp image
    if (img.fileSize == -1) {
        return true;
    }
    do //wait until the image is loaded or we timeout...
    {
        endLoad = new Date();
    }
    while (img.fileSize == -1 && (endLoad.getTime() - startLoad.getTime()) / 1000 < 10) //Timeout after 10 seconds
    if (img.fileSize) {
        if (img.fileSize > 0) //check the size and that the image has loaded properly
        {
            if (img.fileSize > fiveMeg) {
                tooBig = true;
            }
        } else //timed out - proabably due to image being WAY too big, but could be a corrupt image.
        {
            tooBig = true;
        }
    }

    if (tooBig) {
        return false;
    } else {
        return true;
    }
}

//rollover rotating image
function getlayer(layername) {
    if (document.layers) {
        var theLayer = document.layers[layername]
    } else {
        if (document.getElementById) {
            var theLayer = document.getElementById(layername)
        } else {
            var theLayer = document.all[layername]
        }
    };

    return theLayer;

}
function layeron(slayer, dispBlock) {
    if (slayer) {
        if (document.layers) {
            slayer.visibility = "visible";
        } else {
            slayer.style.visibility = "visible";
            if (dispBlock) {
                slayer.style.display = "block";
            } else {
                slayer.style.display = "inline";
            }
        }
    }
}

function layeroff(slayer) {
    if (slayer) {
        if (document.layers) {
            slayer.visibility = "hide"
        } else {
            slayer.style.visibility = "hidden";
            slayer.style.display = "none"
        }
    }
}

function request(var_name) {
    var loc = document.location.href
    if (loc.toLowerCase().indexOf(var_name) <= 0) {
        return '';
    } else if (loc.toLowerCase().indexOf('&', loc.toLowerCase().indexOf(var_name)) <= 0) {
        return loc.substring(loc.toLowerCase().indexOf(var_name) + var_name.length + 1)
    } else {
        return loc.substring(loc.toLowerCase().indexOf(var_name) + var_name.length + 1, loc.toLowerCase().indexOf('&', loc.toLowerCase().indexOf(var_name)))
    }
}

// To cover IE 5.0's lack of the push method
Array.prototype.push = function() {
    var n = this.length >>> 0;
    for (var i = 0; i < arguments.length; i++) {
	this[n] = arguments[i];
	n = n + 1 >>> 0;
    }
    this.length = n;
    return n;
};

function getElementsByClassName(strClassName, strTagName, oElm) {
    var arrElements = (strTagName == "*" && oElm.all) ? oElm.all : oElm.getElementsByTagName(strTagName);
    return $(arrElements).find('.' + strClassName).get();
}

function getWindowSize(c) {
    var W = 0,
    H = 0;
    if (typeof(window.innerWidth) == 'number') {
        W = window.innerWidth;
        H = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        W = document.documentElement.clientWidth;
        H = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        W = document.body.clientWidth;
        H = document.body.clientHeight;
    }
    switch (c) {
    case 'width':
        return W;
        break
    case 'height':
        return H;
        break
    }
}

function tryReload(oImage) {
    if (oImage.src.indexOf('reloaded=y') <= 0) {
        window.status = window.status + ' reloading ' + oImage.src
        var d = new Date();
        if (oImage.src.indexOf('?') > 0) {
            oImage.src = oImage.src + '&reloaded=y&reloadTime=' + d.getTime();
        } else {
            oImage.src = oImage.src + '?reloaded=y&reloadTime=' + d.getTime();
        }

    }
}

function getImagesForReload() {

    var sCommonBitForImages = '/pics1/'

    if (!isIE) {
        for (var i = 0; i < document.images.length; i++) {
            if (document.images[i].src.indexOf(sCommonBitForImages) > 0) {
                if (document.images[i].onerror == undefined) {
                    document.images[i].parentNode.innerHTML = document.images[i].parentNode.innerHTML.replace('<IMG ', '<img ').replace('<Img ', '<img ');
                    document.images[i].parentNode.innerHTML = document.images[i].parentNode.innerHTML.replace('<img ', '<img onerror="tryReload(this)" ');
                }
            }
        }
    } else {
        for (var i = 0; i < document.images.length; i++) {
            if (document.images[i].src.indexOf(sCommonBitForImages) > 0) {
                if (document.images[i].complete == false) {
                    tryReload(document.images[i]);
                }
            }
        }
    }
}

addLoadEvent(getImagesForReload);

function setInputValue(el, sValue) {
    /**************************************
	/
	/	function takes in reference to a form input and the new value
	/	will set the value correctly for textboxes, radios, checkboxes and selectboxes
	/
	**************************************/
    if (el.options) {
        //selectbox
        for (var i = 0; i < el.options.length; i++) {
            if (el.options[i].value == sValue) {
                el.selectedIndex = i;
                break;
            }
        }
    } else if (el.length) {
        //multiple option radio
        for (var i = 0; i < el.length; i++) {
            el[i].checked = false;
            if (el[i].value == sValue) {
                el[i].checked = true;
            }
        }
    } else if (el.type == 'radio') {
        //single option radio
        if (el.value == sValue) {
            el.checked = true;
        }
    } else if (el.type == 'checkbox') {
        //checkbox
        el.checked = false;
        if (el.value == sValue) {
            el.checked = true;
        }
    } else {
        el.value = sValue;
    }
}

var allSelected = true;
function SelectAllOrNone() {
    if (allSelected == true) {
        var allCheckBoxes = document.getElementsByTagName("input")
        for (var i = 0; i < allCheckBoxes.length; i++) {
            if (allCheckBoxes[i].type == 'checkbox') {
                allCheckBoxes[i].checked = false;
            }
        }
        allSelected = false;
    }
    else {
        var allCheckBoxes = document.getElementsByTagName("input")
        for (var i = 0; i < allCheckBoxes.length; i++) {
            if (allCheckBoxes[i].type == 'checkbox') {
                allCheckBoxes[i].checked = true;
            }
        }
        allSelected = true;
    }
}


function URLEncode(sStr)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = sStr;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    var toAlert = "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted.";
		        //alert(toAlert);
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for
	return encoded;
};

function URLDecode(sStr)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = sStr;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
};

function checkImg(img) {
    if(img.width==28 && img.height==28 && img.src.indexOf('reloaded')<=0 ){img.src=img.src+'&reloaded';alert('reloaded - please tell Alex.');}
}

function notSameChar(value) {
    if (value.length == 0) return true;
    var char = value.charAt(0);
    var ret = false;
    for (i = 1; i < value.length; i++) {
        var chartest = value.charAt(i);
        if (char != chartest) {
            ret = true;
            break;
        }
    }
    return ret;
}

$.fn.expandBox = function(minHeight) {
    $(this).parent().append('<div class="expandBox textBox ghostExpandBox"></div>');
    $(this).parent().find('.ghostExpandBox').css('width', $(this).width() - 12 + 'px');
    $(this).parent().find('.ghostExpandBox').css('height', 'auto');
    $(this).parent().find('.ghostExpandBox').css('font-family', $(this).css('font-family'));
    $(this).parent().find('.ghostExpandBox').css('font-size', $(this).css('font-size'));

    var ghostTextLength = 0;
    $(this).keydown(function() {
        if (Math.abs($(this).val().length - ghostTextLength) > 10) {
            $(this).parent().find('.ghostExpandBox').html(convertNL($(this).val()+"<br />"));
            var gb = $(this).parent().find('.ghostExpandBox').height() + 20;
            if (gb > $(this).height()) {
                if (gb < minHeight) { gb = minHeight; }
                $(this).height(gb);
            }
            ghostTextLength = $(this).val().length;
        }
    });
    function convertNL(text) {
        text = escape(text);
        re_nlchar = null;
        if (text.indexOf('%0D%0A') > -1) {
            re_nlchar = /%0D%0A/g;
        } else if (text.indexOf('%0A') > -1) {
            re_nlchar = /%0A/g;
        } else if (text.indexOf('%0D') > -1) {
            re_nlchar = /%0D/g;
        }
        return unescape(text.replace(re_nlchar, '<br />'));
    }
};
FR.onLoad.addLoadSetup(function() {
    var infoLink = null;
    $(".resultlist .info").live('click', function() {
        if (!infoLink) {
            infoLink = $(this).find('a').attr('href');
            if (infoLink) {
                window.location.href = infoLink;
            }
        }
    });
    $(".resultlist .info a.primary-link").live('click', function() {
        infoLink = $(this).attr('href');
    });

    $(".resultlist .listSubForm").hide();
    $(".resultlist .links a.managePlace").live('click', function() {
        if ($(this).parent().parent().parent().find('.listSubForm').is('.shown')) {
            $('.listSubForm').hide().removeClass('shown');
            $('.resultlist li').removeClass('open');
        } else {
            $('.listSubForm').hide().removeClass('shown');
            $('.resultlist li').removeClass('open');
            $(this).parent().parent().parent().find('.listSubForm').before('<div class="clear"></div>').slideDown().addClass('shown');
            $(this).parent().parent().parent().addClass('open');
        }
        return false;
    });

    if (typeof ($.fn.expandBox) == 'function') $(".expandBox").expandBox(70);

    //button pressed recognition
    // $('.listSubForm .primary-button').live('click', function() {
    //     $(this).addClass('buttonPressed').append('<img class="rs" src="/webImage/buttaniRH.gif"/>').prepend('<img class="ls" src="/webImage/buttaniLH.gif"/>').blur();
    // });

    $('.messagelist tbody tr td.mailtype, .messagelist tbody tr td.mailfrom, .messagelist tbody tr td.maildate,  .messagelist tbody tr td.mailsubject').live('click', function() {
        if (!infoLink) {
            infoLink = $(this).parent().find('a').attr('href');
            if (infoLink) {
                window.location.href = infoLink;
            }
        }
    });

    $(".messagelist tbody tr td.mailsubject a").live('click', function() {
        infoLink = $(this).attr('href');
    });

    $('a.bubbleTip').each(function() {
        $(this).append('<div class="bubbleTip"><div class="leftSide"></div><div class="content">' + $(this).attr('title') + '</div></div>').removeAttr('title'); ;
    });

    $('#getBackTogether').live('click', function() {
        window.location.href = $('#getBackTogether a').attr('href');
    });
    $('#tagFriendsInPhotos').live('click', function() {
        window.location.href = $('#tagFriendsInPhotos a').attr('href');
    });

    /* topnav-places hover colour correction  */
    if (typeof document.body.style.maxHeight != "undefined") {//ignore if IE6 or older
        $('#topnav-places li.my').hover(function() {
            $('#topnav-places li.my a, #topnav-places .morelink').css('color', 'white');
        }, function() {
            $('#topnav-places li.my a, #topnav-places .morelink').css('color', '#076CCD');
        });
        $('#topnav-places li.my-place, #topnav-places li.find, #topnav-places li.recently').hover(function() {
            $(this).find('a').css('color', 'white');
        }, function() {
            $(this).find('a').css('color', '#076CCD');
        });
    }
});

function fav() {
    var newT = document.createTextNode('Add to favourites');
    var s = document.getElementById('fav');
    if (window.sidebar) {
    s.appendChild(newT);
    s.style.color = '#076CCD';
    s.style.cursor = 'pointer';
    s.onclick = function() {window.sidebar.addPanel(document.title,self.location,'')};
    } else if (window.external) {
    s.appendChild(newT);
    s.style.color = '#076CCD';
    s.style.cursor = 'pointer';
    s.onclick = function() {window.external.AddFavorite(self.location,document.title)};
    } else if (window.opera) {
    s.appendChild(newT);
    s.style.color = '#076CCD';
    s.style.cursor = 'pointer';
    s.onclick = function() {
         var e = document.createElement('a');
         e.setAttribute('href',self.location);
         e.setAttribute('title',document.title);
         e.setAttribute('rel','sidebar');
         e.click();
      }
    }
}

FR.onLoad.addLoadSetup(fav);

function validateIsGreaterThanValue(value, element, params) {
    if (value.length == 0) return true;

    return (value > params);
}


function showHideTips() {
    $('.Opentipslink').click(function() {
        $('.tipsheader').animate({ height: '6' }, 200, function() {
            $('.tipsheader').toggleClass('toptipsheaderOpen');
        });
        $('.tipscontent').slideDown(200);
        $('.Opentipslink').hide(0);
        $('.Closetipslink').show(0);
        return false
    });

    $('.Closetipslink').click(function() {
        var t = setTimeout("$('.tipsheader').toggleClass('toptipsheaderOpen');", 210);
        var t2 = setTimeout("$('.tipsheader').animate({ height: '10' },200);", 210);
        $('.tipscontent').slideUp(200);
        $('.Closetipslink').hide(0);
        $('.Opentipslink').show(0);

        return false
    });

    $('.tipcontainer .tool').show();

}
FR.onLoad.addLoadSetup(showHideTips);


//FR Dialogue:
function FRdialogueInit(popId) {
    $('body').prepend($('<div id="FRdialogueBg" style="display:none;"></div>'));
    $("#FRdialogueBg").height($(document).height()).show();

    $("html").css('overflow', 'hidden');
    popId.before("<div id='FRdialogueAnchor'></div>").addClass('FRdialogue'); 
    popId.wrap("<div id='FRdialogueContainer'></div>").css({ 'display': 'none', 'visibility': 'visible' });
    popId.before("<iframe id='FRdialogueUnder'></iframe>");
    
    FRdialoguePosition(popId);
    //$("iframe").addClass('hideFrame');
    $(window).resize(function() { FRdialoguePosition(popId) });
    return false;
}
function FRdialoguePosition(popId) {
    var contTop = ($(window).scrollTop() - $("#FRdialogueAnchor").offset().top);
    var contLeft = -$("#FRdialogueAnchor").offset().left;
    if (contTop < 0) {contTop = $(window).scrollTop(); }
    if (contLeft < 0) { contLeft = 0; }
    $("#FRdialogueContainer").height($(window).height()).width($(window).width()).css({ "top": contTop + "px", 'left': contLeft + "px" }).show();
    var top = ($("#FRdialogueContainer").height() / 2) - (popId.height() / 2);
    if (top < 0) { top = 0 }
    var left = ($("#FRdialogueContainer").width() / 2) - (popId.width() / 2);
    if (left < 0) { left = 0; }
    popId.css({ "top": top + "px", "left": left + "px" });
    $("#FRdialogueUnder").css({ "top": top + "px", "left": left + "px", "width": popId.width() + "px", "height": popId.height() + "px", "position" : "absolute", "border" : "0" });
}
function FRdialogueClose(popId) {
    popId.fadeOut('normal', function() {
        popId.remove();
        $("#FRdialogueBg, #FRdialogueContainer, #FRdialogueAnchor").remove();
        $(window).unbind('resize', FRdialoguePosition(popId));
        $("html").css('overflow', 'auto');
    });
}
function FRdialogueHide(popId) {
    popId.fadeOut('normal', function() {
        //if (del) { popId.remove(); }
        $("#FRdialogueBg, #FRdialogueAnchor").remove();
        // popId.unwrap();
        $("#FRdialogueContainer").replaceWith($("#FRdialogueContainer .FRdialogue"));
        $(window).unbind('resize', FRdialoguePosition(popId));
        $("html").css('overflow', 'auto');
    });
}
