/*
 * Java Functions
 *
 * (C) Copyright 2007 Adam Haas
 * All rights reserved.
 */
/* ------------------------------------------------------------------------- */
function getObj(sId){return document.getElementById(sId);}

/*
 * Creates a popup window, centred in the middle of the screen and focused
 *
 * @param url - Url to launch in window
 * @param hWnd - name of popup window (used to reference from callee window)
 * @param w - width of window
 * @param h - height of window
 * @param params - parameters for the window, a string, i.e. "scrollbars=yes,toolbars=no" etc.
 */
function popUpWindow(url,hWnd, w, h,params) {
	x = (screen.width - w) /2;
	y = (screen.height - h) /2;
	
	if (params != null) params = "," + params;
	popWin = window.open(url,hWnd,"top="+y+",left="+x+",width="+w+",height="+h+params);
	popWin.focus();
}


/*
 * Places the emoticon code in the textbox
 *
 * @param text - the textarea
 */
function emoticon(text) {
	text = ' ' + text + ' ';
	if (this.document.forms['fcomment'].comments.createTextRange && this.document.forms['fcomment'].comments.caretPos) {
		var caretPos = this.document.forms['fcomment'].comments.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		this.document.forms['fcomment'].comments.focus();
	} else {
	this.document.forms['fcomment'].comments.value  += text;
	this.document.forms['fcomment'].comments.focus();
	}
}

/*
 * Copy Highlighted Text
 */
function highlight(field) {
    field.focus();
    field.select();
    var urlSwf = "http://www.efantileech.com/includes/copy.swf";

    window.status = 'Copied text to clipboard';

    // Copy the text inside the text box to the user's clipboard
    var flashcopier = 'flashcopier';
    var divholder = document.createElement('div');
    divholder.id = flashcopier;
    document.body.appendChild(divholder);

    divholder.innerHTML = '';
    var divinfo = '<em'+'bed src="' + urlSwf + '" FlashVars="clipboard='+escape(field.value)+'" width="0" height="0" type="application/x-shockwave-flash"></em'+'bed>';
    divholder.innerHTML = divinfo;

    return false;
}

/*
 * Help Popup
 */
function getposOffset(overlay, offsettype) {
	var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
	var parentEl=overlay.offsetParent;
	while (parentEl!=null) {
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function overlay(curobj, helptext) {
	var opt_position = "bottomleft";
	var subobjstr = "help";
	if (document.getElementById) {
		var subobj=document.getElementById(subobjstr)
		subobj.style.display=(subobj.style.display!="block")? "block" : "none"
		var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0) 
		var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
		subobj.style.left=xpos+"px"
		subobj.style.top=ypos+"px"
		subobj.style.zIndex=2
		subobj.innerHTML='<font face=arial size=2>'+helptext+'</font>';
		var iframe = document.getElementById("ifr")
		iframe.style.display="block"
		iframe.style.top=ypos+"px"
		iframe.style.left=xpos+"px"
		iframe.style.width=250
		iframe.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)'
		iframe.style.zIndex=1
		return false
	} else {
		return true
	}
}

function overlayclose() {
	var subobj = "help";
	document.getElementById(subobj).style.display="none"
	document.getElementById("ifr").style.display="none"
}