// write an email to the screen to prevent spidering
function antiSpamEmail (username, domain, purdyStr, cssClass) {
    domain = (domain == "") ? "cataphora.com" : domain;
    purdyStr = (purdyStr == "") ? (username + "@" + domain) : purdyStr;
    var cssTag = (cssClass == "") ? "" : ("CLASS=\"" + cssClass + "\"");
    document.write("<A " + cssTag + " HREF=\"mailto:" + username + "@" + domain + "\">" + purdyStr + "</A>");
}

function ie6trans () {
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);
	if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
		for(var i=0; i<document.images.length; i++) {
			var img = document.images[i]
			var imgName = img.src.toUpperCase()
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText 
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "vertical-align:middle; width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\');\"></span>" 
				img.outerHTML = strNewHTML
				i = i-1
			}
		}
	}    
}

function openFloatWin (url, w, h, callFunction) {
	var fwEl = $("floatWindow");
    // adjust the size
    fwEl.setStyle('width', w);
    fwEl.setStyle('height', h);    
    // center the float panel
    var cWidth = (document.documentElement.scrollLeft + (document.documentElement.clientWidth / 2));
    var cHeight = (document.documentElement.scrollTop + (document.documentElement.clientHeight / 3));

    fwEl.style.left = Math.floor(cWidth - (w / 2)) + "px";    
    fwEl.style.top = Math.floor(cHeight - (h / 3)) + "px";    
	try {
		var ifEl = getIFrameObject($("fwFrame"));
		if (ifEl.location.href.indexOf(url) == -1) {
			changeIFrame("fwFrame", url);
		} else {
			// if it's just showing it again and callFunction is not null, run said callFunction
			if (callFunction != null) {
				eval("window.frames['fwFrame']." + callFunction);
			}
		}

		// hide the select els for ie6
		toggleFormEls(true);
	} catch(err) {
		alert("changeIFrame and toggleFormEls requires utility.js" + "\n\n" + err.description);
	}

    // show the els
	$("pageMask").setStyle('width', '100%');
	$("pageMask").setStyle('height', (document.documentElement.scrollHeight + "px"));
	$("pageMask").fade(0.8);

	if (document.all) {
		fwEl.setStyle('visibility', 'visible');
	} else {
		fwEl.set('tween', {duration: 3000});
		fwEl.tween('opacity', '100');
	}
}

// hides the "floating window" div.
// if resetIFrame is true the "floating window" will be cleared
//  (prevents that previous contents are shown when opening another window).
//
// NOTE: requires mootools!
//
function closeFloatWin (resetIFrame) {
    // update the url (requires utility.js!!!)
    if (resetIFrame) {
        try {
            changeIFrame("fwFrame", "_filler.html");
        } catch(err) {
            alert("changeIFrame requires utility.js" + "\n\n" + err.description);
        }
    }
    // hide the els
	$("pageMask").fade(0);
	$("pageMask").setStyle('width', '0');
	$("pageMask").setStyle('height', '0');

    // hide the els
	if (document.all) {
		$("floatWindow").setStyle('left', '-9999px');
		$("floatWindow").setStyle('visibility', 'hidden');
	} else {
		$("floatWindow").set('tween', {duration: 100});
		$("floatWindow").tween('opacity', '0');
	}

    // restore the select els for ie6
    try {
        toggleFormEls(false);
    } catch(err) {
        alert("toggleFormEls requires utility.js" + "\n\n" + err.description);
    }
}

// changes the location of an iframe without affecting browser history
function changeIFrame (frID, loc) {

    var ifDoc;
    var fr = document.getElementById(frID);

    if ((! fr) && (document.createElement)) {
        // create the iframe and assign a reference to the object
        var tempIFrame = document.createElement('iframe');
        tempIFrame.setAttribute('id','RSIFrame');
        tempIFrame.style.border='0px';
        tempIFrame.style.width='0px';
        tempIFrame.style.height='0px';
        fr = document.body.appendChild(tempIFrame);

        if (document.frames) {
            // ie5 mac
            fr = document.frames[fr.id];
        }
    }
  
    // the the frame object and update the url
    try {
        ifDoc = getIFrameObject(fr);
        ifDoc.location.replace(loc);
    } catch (err) { }

    return false;
} 

// this will return the iframe object based on browser type
function getIFrameObject (docEl) {

    var rhett = null;

    if (docEl.contentDocument) {
        // ns6
        rhett = docEl.contentDocument; 
    } else if (docEl.contentWindow) {
        // ie5.5 / ie6
        rhett = docEl.contentWindow.document;
    } else if (docEl.document) {
        // ie5
        rhett = docEl.document;
    }

    return rhett;
}

// hide form els and other active-esque for ie 6
function toggleFormEls (status) {
    if ((document.all7) || (! document.all)) {
        return;
    }

    var divs = document.getElementsByTagName("DIV");
    for (d=0; d < divs.length; d++) {
		if (divs[d].innerHTML.toLowerCase().indexOf("iframe") != -1) {
			try {
				for (i=0; i < window.frames[sDiv].document.forms.length; i++) {
					toggleSpecificFormEls(window.frames[divs[d].id].document, status);
				}
			} catch(err) {
				// don't need to catch it, really - just don't show the error
			}
		} else if (divs[d].id.indexOf("HIDE_WHEN_TOGGLING") != -1) {
			divs[d].style.visibility = (status) ? "hidden" : "visible";
		}        
	}

	toggleSpecificFormEls(document, status);

}

// shows a floating shadow box image
function showImage (img, w, h, desc) {

    // blank it out for now
    document.getElementById("imgZoomShadowImage").width = w;
    document.getElementById("imgZoomShadowImage").height = h;
    document.getElementById("imgZoomShadowImage").src = "/images/byte.gif";
    // update description and wrapper
    document.getElementById("imgDesc").innerHTML = "<b>" + desc + "</b>";
    if (w < 400) {
		w = 400;
    }
    document.getElementById("closeMeta").style.width = w + "px";
    // update it
    document.getElementById("imgZoomShadowImage").src = img;
    // move it
	var posData = getSize();
    var cWidth = (document.all) ? (document.body.scrollLeft + (document.body.clientWidth / 2)) : (window.pageXOffset + (innerWidth / 2));
    var cHeight = (posData[2] + (posData[1] / 2));

	
    document.getElementById("imgZoomShadowBox").style.left = Math.floor(cWidth - (w / 2)) + "px";
    document.getElementById("imgZoomShadowBox").style.top = Math.floor(cHeight - (h / 2)) + "px";
    // show it
    document.getElementById("imgZoomShadowBox").style.visibility = "visible";
}

// hides a floating shadow box image
function hideImage () {
    document.getElementById("imgZoomShadowBox").style.visibility = "hidden";
}

// quirksmode.org
function getSize () {

	// Window Size
	var width, height, scroll, sWidth, sHeight;
	
	if (self.innerHeight) { // Everyone but IE
		width = window.innerWidth;
		height = window.innerHeight;
		scroll = window.pageYOffset;
	} else if (document.documentElement && document.documentElement.clientHeight) { // IE6 Strict
		width = document.documentElement.clientWidth;
		height = document.documentElement.clientHeight;
		scroll = document.documentElement.scrollTop;
	} else if (document.body) { // Other IE, such as IE7
		width = document.body.clientWidth;
		height = document.body.clientHeight;
		scroll = document.body.scrollTop;
	}

	// Page size w/offscreen areas

	if (window.innerHeight && window.scrollMaxY) {	
		sWidth = document.body.scrollWidth;
		sHeight = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // All but Explorer Mac
		sWidth = document.body.scrollWidth;
		sHeight = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		sWidth = document.body.offsetWidth;
		sHeight = document.body.offsetHeight;
	}
	
	return [width, height, scroll, sWidth, sHeight];
}


