

function refresh() {
	location.reload(true);
}

function redirect(to) {
	window.location = to;
}

function goWizard() {
	window.location=document.getElementById('hiddenFieldSimpleUrl').value + '/simple/faces/tryme/wizard.jsp';
}

function switchImage(imgId, newImage) {
	var oldImage = document.getElementById('index-login:' + imgId).src;
	var prePath = oldImage.substring(0, oldImage.indexOf('/resource'));
	document.getElementById('index-login:' + imgId).src = prePath + newImage;
}

function addNetworksSolutionsHeader() {
	var cot_loc0=(window.location.protocol == "https:")? "https://seals.watchdog-service.com/script/logo.js" : "http://seals.watchdog-service.com/script/logo.js";
	document.writeln('<scr' + 'ipt language="JavaScript" src="'+cot_loc0+'" type="text\/javascript">' + '<\/scr' + 'ipt>');
}

function useHttps() {
	if (window.location.protocol == "http:") {
		var url = window.location.href.replace("http:", "https:").replace("8080", "8443");
		window.location = url;
	}
}

function useHttp() {
	if (window.location.protocol == "https:") {
		var url = window.location.href.replace("https:", "http:").replace("8443", "8080");
		window.location = url;
	}
}

function handleEnterResponse(field, event) {
	document.getElementById('select-form:myresponse').style.backgroundColor="#A4F69D";
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	
	if (keyCode == 13) {
		return false;
	} else {
		return true;
	} 
}

function handleEnter(field, event) {

	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	
	if (keyCode == 13) {
		return false;
	} else {
		return true;
	} 
}

function saveResponse() {
	document.getElementById('select-form:myresponse').style.backgroundColor="#F4F4F5";
}

function iRedirect(iUrl) {
	window.location = document.getElementById('hiddenFieldSimpleUrl').value + '/simple/faces/' + iUrl;
}

//######################################################################################################
// User Home JS
//######################################################################################################

function filterString(param){
	param = param.replace(/%E1/g,"a");
	param = param.replace(/%E9/g,"e");
	param = param.replace(/%ED/g,"i");
	param = param.replace(/%F3/g,"o");
	param = param.replace(/%FA/g,"u");
	param = param.replace(/%F1/g,"n");
	param = param.replace(/%C1/g,"A");
	param = param.replace(/%C9/g,"E");
	param = param.replace(/%CD/g,"I");
	param = param.replace(/%D3/g,"O");
	param = param.replace(/%DA/g,"U");
	param = param.replace(/%%D1/g,"Ñ");
	
	return param;
}

function twitterButton(){
	var simpleURL = document.getElementById('hiddenFieldSimpleUrl').value;
	document.write('<a onclick="twitterWindow(); return false;" href="" style="font-family: Arial, Helvetica, sans-serif;  color: #000000; text-decoration: none" ><img src="' + simpleURL + '/simple/faces/resources/images/twitter.png" alt="twitter" style="border : 0" /></a>');
}

function twitterWindow(){
	var param = document.getElementById('select-form:myresponse').value;
	
	param = filterString(escape(param));
	
	param = unescape(param);
	
	var URL = "http://twitter.com/home?status="+escape(param);
	
	w = screen.width;
	h = screen.height;
	
	day = new Date();
	
	window.open(URL, day.getTime() , 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0');
}

function facebookButton(){
	var simpleURL = document.getElementById('hiddenFieldSimpleUrl').value;
	document.write('<a onclick="facebookWindow(); return false;" href="" style="font-family: Arial, Helvetica, sans-serif;  color: #000000; text-decoration: none" ><img src="' + simpleURL + '/simple/faces/resources/images/facebook.png" alt="facebook" style="border : 0" /></a>');
}

function facebookWindow(){
	var param = document.getElementById('select-form:myresponse').value;
	
	param = filterString(escape(param));
	
	var URL = "http://www.facebook.com/connect/prompt_feed.php?&message="+filterString(param);
	
	w = screen.width;
	h = screen.height;
	
	day = new Date();
	
	window.open(URL, day.getTime() , 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=660,height=220,left = '+ (w/2-330) +',top = '+(h/2 - 110));
}

function asyncRequest(method, uri, callback, postData) {
	
	alert('asyncRequest');
	
	var o = (this._isFileUpload)?this.getConnectionObject(true):this.getConnectionObject();
	var args = (callback && callback.argument)?callback.argument:null;

	alert('asyncRequest 1');
	
	if(!o) {
		return null;
		
	} else {

		// Intialize any transaction-specific custom events, if provided.
		if(callback && callback.customevents){
			this.initCustomEvents(o, callback);
		}

		if (this._isFormSubmit){
			
			if (this._isFileUpload){
				this.uploadFile(o, callback, uri, postData);
				return o;
			}

			// If the specified HTTP method is GET, setForm() will return an
			// encoded string that is concatenated to the uri to
			// create a querystring.
			if(method.toUpperCase() == 'GET'){
				if(this._sFormData.length !== 0){
					// If the URI already contains a querystring, append an
					// ampersand
					// and then concatenate _sFormData to the URI.
					uri += ((uri.indexOf('?') == -1)?'?':'&') + this._sFormData;
				}
			}
			else if(method.toUpperCase() == 'POST'){
				// If POST data exist in addition to the HTML form data,
				// it will be concatenated to the form data.
				postData = postData?this._sFormData + "&" + postData:this._sFormData;
			}
		}

		if(method.toUpperCase() == 'GET' && (callback && callback.cache === false)){
			// If callback.cache is defined and set to false, a
			// timestamp value will be added to the querystring.
			uri += ((uri.indexOf('?') == -1)?'?':'&') + "rnd=" + new Date().valueOf().toString();
		}

		o.conn.open(method, uri, true);

		// Each transaction will automatically include a custom header of
		// "X-Requested-With: XMLHttpRequest" to identify the request as
		// having originated from Connection Manager.
		if(this._use_default_xhr_header){
			if(!this._default_headers['X-Requested-With']){
				this.initHeader('X-Requested-With', this._default_xhr_header, true);
			}
		}

		// If the transaction method is POST and the POST header value is
		// set to true
		// or a custom value, initalize the Content-Type header to this
		// value.
		if((method.toUpperCase() == 'POST' && this._use_default_post_header) && this._isFormSubmit === false){
			this.initHeader('Content-Type', this._default_post_header);
		}

		// Initialize all default and custom HTTP headers,
		if(this._has_default_headers || this._has_http_headers){
			this.setHeader(o);
		}

		this.handleReadyState(o, callback);
		o.conn.send(postData || '');

		// Reset the HTML form data and state properties as
		// soon as the data are submitted.
		if(this._isFormSubmit === true){
			this.resetFormState();
		}

		// Fire global custom event -- startEvent
		this.startEvent.fire(o, args);

		if(o.startEvent){
			// Fire transaction custom event -- startEvent
			o.startEvent.fire(o, args);
		}

		return o;
	}
	
}

function getIFrameDocument(frameName) {

	var previewFrame = document.getElementById(frameName);
	var theDocument;

	try{
		theDocument = previewFrame.contentDocument;
	}catch(e){}
	
	if (theDocument == undefined || theDocument == null) {
		try{
			theDocument = previewFrame.contentWindow.document;
		}catch(e){}
	}
	
	return theDocument;
}

function setLoadingImage() {
	theDocument = getIFrameDocument('previewframe');
	theDocument.open();
	theDocument.writeln('<body bgcolor="white"><center><img src="resources/images/loading.gif" /></center></body>');
	theDocument.close();
	return true;
}

function switchImage(componentId, newImage) {
	var oldImage = document.getElementById(componentId).src;
	var prePath = oldImage.substring(0, oldImage.indexOf('/resource'));
	document.getElementById(componentId).src = prePath + '/resources/images/' + newImage;
}

function removeParameterOnNoOpenedTag(startWith, text, parameter) {

	var index = text.indexOf('<' + startWith);
	var newText = text;

	while (index < newText.length && index != -1) {
		
		var preTag = newText.substring(0, index);
		var tag = newText.substring(index);
		
		var iLimit = tag.indexOf('/>');
		tag = tag.substring(0, iLimit + 2);
		var posTag = newText.substring(index + 2 + iLimit);
		var tl = tag.length;	
		var pLoc = tag.indexOf(parameter + '=\"');
		
		if (pLoc != -1) {
			tag = tag.substring(0, pLoc) + tag.substring(tag.indexOf('\"', pLoc + parameter.length + 2) + 1);
		}
		
		index = newText.indexOf('<' + startWith, index + tl);
		newText = preTag + tag + posTag;
	}

	return newText;	
}

function setPortalPreview(url) {
	
	url = url + '?rnd=' + Math.random();

	var request;
	
	try {
		request = new XMLHttpRequest();
	} catch (e) {
		try {
		    request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
		    alert("XMLHttpRequest error: " + e);
		}
	}

    request.open("GET", url, true);
    request.onreadystatechange = function() {
    	if (request.readyState==4) {
    		
    		td = getIFrameDocument('previewframe');
    		
    		var htmlCode = request.responseText.replace(/<img /g, "<img style=\"max-width:170px; width:expression(this.width > 170 ? 170: true);\" ");
			htmlCode = removeParameterOnNoOpenedTag('img', htmlCode, 'width');
			htmlCode = removeParameterOnNoOpenedTag('img', htmlCode, 'height');
			htmlCode = htmlCode.replace(/font-family:Verdana, Arial/g, "font-family:Verdana, Arial; font-size:9px");
			htmlCode = htmlCode.replace(/href/g, "style=\"font-family:Verdana, Arial; font-size:9px;\" onclick= \"return false;\" href");
			htmlCode = htmlCode.replace(/<input /g, "<input onclick= \"return false;\" ");
			htmlCode = htmlCode.replace("800px", "100%");
			htmlCode = htmlCode.replace(/<div>/g, "<div style=\"font-family:Verdana, Arial; font-size:9px;\" >");

			td.open();
			td.writeln(htmlCode);
			
    	}
    }
    request.send(null);
}

function requestExternal(url, alertMethod) {
	
	var request;

	try {
		request = new XMLHttpRequest();
	} catch (e) {
		try {
		    request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
		    alert("XMLHttpRequest error: " + e);
		}
	}

    request.open("GET", url, true);
    request.onreadystatechange = function() {
    	if (request.readyState==4) {
    		setPortalPreview(request.responseText);
    	}
    }
    request.send(null);
    
}

function retrievePageXML(keyword) {
	url = 'portalservlet?action=internalPortalUrl&keyword=' + keyword + '&r=' + Math.random();
	setLoadingImage();
	requestExternal(url);
}

function buildPreview() {
	retrievePageXML(document.getElementById('selectkeyword').value);
}

function saveResponse() {
	document.getElementById('select-form:myresponse').style.backgroundColor="#F4F4F5";
}

function addEvent(obj, evType, fn){
	
	if (obj.addEventListener){ 
		obj.addEventListener(evType, fn, false); 
		return true; 
	} else if (obj.attachEvent){ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	} else { 
		return false; 
	}
	
}



//######################################################################################################
//Scheduler JS
//######################################################################################################
function disp_prompt() {
	
	var maxLengthAllowed = parseInt(document.getElementById("whenAndMessageForm:maxSizeAllowedHiddenId").value);
	
	maxLengthAllowed = 130;
	
	if(maxLengthAllowed==999999999){
		document.getElementById("whenAndMessageForm:maxSizeAllowedId").value = "";
		return;
	}
		
	var numCharacters = document.getElementById("whenAndMessageForm:message").value.length;
	
	var val = maxLengthAllowed - numCharacters;
	
	if(val<0){
		document.getElementById("whenAndMessageForm:message").value = document.getElementById("whenAndMessageForm:message").value.substring(0,maxLengthAllowed);
	}
	numCharacters = document.getElementById("whenAndMessageForm:message").value.length;
	val = maxLengthAllowed - numCharacters;
	document.getElementById("whenAndMessageForm:maxSizeAllowedId").value = val;
	
	
}

function messages_bar_controller(){
	document.write('<img name="barimage" id="barimage" src="fillBar.gif" height="36" width="100"> ');
}

function cleanDays(){
	document.getElementById('whenAndMessageForm:Mon').checked = false;
	document.getElementById('whenAndMessageForm:Tue').checked = false;
	document.getElementById('whenAndMessageForm:Wed').checked = false;
	document.getElementById('whenAndMessageForm:Thu').checked = false;
	document.getElementById('whenAndMessageForm:Fri').checked = false;
	document.getElementById('whenAndMessageForm:Sat').checked = false;
	document.getElementById('whenAndMessageForm:Sun').checked = false;
}

function cleanWeek(){
	document.getElementById('whenAndMessageForm:Week').checked = false;
}

function checkAvailability(){
	var noRateCheck = document.getElementById('whenAndMessageForm:noRateCheck').checked;
	
	if(noRateCheck){
		document.getElementById('whenAndMessageForm:rate').disabled = 'disabled';
		document.getElementById('whenAndMessageForm:measure').disabled = 'disabled';
	}else{
		document.getElementById('whenAndMessageForm:rate').disabled = '';
		document.getElementById('whenAndMessageForm:measure').disabled = '';
	}
}

function addRestriction(){
	
	var hoursSince = document.getElementById('whenAndMessageForm:hoursSince').value;
	var minutesSince = document.getElementById('whenAndMessageForm:minutesSince').value;
	
	var hoursTill = document.getElementById('whenAndMessageForm:hoursTill').value;
	var minutesTill = document.getElementById('whenAndMessageForm:minutesTill').value;
	
	if(hoursSince == hoursTill && minutesSince == minutesTill){
		Richfaces.showModalPanel('errorRestrictMess');
		return;
	}
	
	var Mon = document.getElementById('whenAndMessageForm:Mon').checked;
	var Tue = document.getElementById('whenAndMessageForm:Tue').checked;
	var Wed = document.getElementById('whenAndMessageForm:Wed').checked;
	var Thu = document.getElementById('whenAndMessageForm:Thu').checked;
	var Fri = document.getElementById('whenAndMessageForm:Fri').checked;
	var Sat = document.getElementById('whenAndMessageForm:Sat').checked;
	var Sun = document.getElementById('whenAndMessageForm:Sun').checked;
	var Week = document.getElementById('whenAndMessageForm:Week').checked;
	
	
	var elSel = document.getElementById('whenAndMessageForm:restrictedList');
	
	var timeLabel = hoursSince + ":" + minutesSince + " - " + hoursTill + ":" + minutesTill;
	var timeCode = hoursSince + ":" + minutesSince + ":" + hoursTill + ":" + minutesTill;
	
	if(Week){
		var optNew = document.createElement('option');
		optNew.text = document.getElementById('Week-label').value + ', '+ timeLabel;
		optNew.value = 'Week:'+timeCode;
		try {elSel.add(optNew, null);}catch(ex) {elSel.add(optNew);}
	}else{
		if(Mon){
			var optNew = document.createElement('option');
			optNew.text = document.getElementById('Mon-label').value + ', '+ timeLabel;
			optNew.value = 'Mon:'+timeCode;
			try {elSel.add(optNew, null);}catch(ex) {elSel.add(optNew);}
		}
		if(Tue){
			var optNew = document.createElement('option');
			optNew.text = document.getElementById('Tue-label').value + ', '+ timeLabel;
			optNew.value = 'Tue:'+timeCode;
			try {elSel.add(optNew, null);}catch(ex) {elSel.add(optNew);}	
		}
		if(Wed){
			var optNew = document.createElement('option');
			optNew.text = document.getElementById('Wed-label').value + ', '+ timeLabel;
			optNew.value = 'Wed:'+timeCode;
			try {elSel.add(optNew, null);}catch(ex) {elSel.add(optNew);}	
		}
		if(Thu){
			var optNew = document.createElement('option');
			optNew.text = document.getElementById('Thu-label').value + ', '+ timeLabel;
			optNew.value = 'Thu:'+timeCode;
			try {elSel.add(optNew, null);}catch(ex) {elSel.add(optNew);}	
		}
		if(Fri){
			var optNew = document.createElement('option');
			optNew.text = document.getElementById('Fri-label').value + ', '+ timeLabel;
			optNew.value = 'Fri:'+timeCode;
			try {elSel.add(optNew, null);}catch(ex) {elSel.add(optNew);}	
		}
		if(Sat){
			var optNew = document.createElement('option');
			optNew.text = document.getElementById('Sat-label').value + ', '+ timeLabel;
			optNew.value = 'Sat:'+timeCode;
			try {elSel.add(optNew, null);}catch(ex) {elSel.add(optNew);}	
		}
		if(Sun){
			var optNew = document.createElement('option');
			optNew.text = document.getElementById('Sun-label').value + ', '+ timeLabel;
			optNew.value = 'Sun:'+timeCode;
			try {elSel.add(optNew, null);}catch(ex) {elSel.add(optNew);}	
		}	
	}

	var i;
	var stringRes = '';
	for(i = 0; i < elSel.length; i++){
		if(i == 0){
			stringRes += elSel.options[i].value;
		}else{
			stringRes += '||'+elSel.options[i].value;
		}
	}
	document.getElementById('whenAndMessageForm:stringRestrictions').value = stringRes;
}

function removeRestriction(){
	var elSel = document.getElementById('whenAndMessageForm:restrictedList');
	var i;
	for (i = 0; i < elSel.length; i++) {
		if (elSel.options[i].selected) {
			elSel.remove(i);
	    }
	}
	
	var i;
	var stringRes = '';
	for(i = 0; i < elSel.length; i++){
		if(i == 0){
			stringRes += elSel.options[i].value;
		}else{
			stringRes += '||'+elSel.options[i].value;
		}
	}
	document.getElementById('whenAndMessageForm:stringRestrictions').value = stringRes;
	
}

function showMessageRecipients(recipientsAsString){
	
	Richfaces.showModalPanel('panelRecip');

	var theDocument = getIFrameDocument('contactsframe');
	theDocument.open();
	
	theDocument.writeln('<head><link href="/simple/resources/css/siMple.css" rel="stylesheet" type="text/css" /></head>');
	
	theDocument.writeln('<body>');
	theDocument.writeln('<div align="center">');
	theDocument.writeln('<table id="recipientsTable" width="200" border="0" cellpadding="0" cellspacing="0" >');
	
	theDocument.writeln('<tr>');
	theDocument.writeln('<td width="20" bgcolor="#F8981D"></td>');
	theDocument.writeln('<td width="80" bgcolor="#F8981D" class="whiteTitleFont" >Mobile</td>');
	theDocument.writeln('<td width="20" bgcolor="#F8981D"></td>');
	theDocument.writeln('<td width="60" bgcolor="#F8981D" class="whiteTitleFont">Status</td>');	
	theDocument.writeln('<td width="20" bgcolor="#F8981D"></td>');
	theDocument.writeln('</tr>');
	
	var contacts = recipientsAsString.split("||");
	var i;
	for ( i = 0; i < contacts.length; i++) {
		theDocument.writeln('<tr>');
		theDocument.writeln('<td width="20"></td>');
		theDocument.writeln('<td width="80" class="blackFont">'+(contacts[i].split("::"))[0]+'</td>');
		theDocument.writeln('<td width="20"></td>');
		theDocument.writeln('<td width="60" class="blackFont">'+((contacts[i].split("::"))[1] == 'true' ? document.getElementById('completed-label').value : document.getElementById('pending-label').value)+'</td>');	
		theDocument.writeln('<td width="20"></td>');
		theDocument.writeln('</tr>');
	}
	
	theDocument.writeln('</table>');
	theDocument.writeln('</div>');
	theDocument.writeln('</body>');
	theDocument.close();  
	
	
}

function getContactsIFrameDocument(frameName) {
	previewFrame = document.getElementById(frameName);

	theDocument = previewFrame.contentDocument;
	if (theDocument == undefined || theDocument == null) {
		theDocument = previewFrame.contentWindow.document;
	}

	return theDocument;
}

//######################################################################################################
//Poll JS
//######################################################################################################
var maxLengthAllowed = 130;

maxLengthAllowed -= 9;

var maxQuestionSize;
var maxOption1Size;
var maxOption2Size;
var maxOption3Size;
var maxOption4Size;
var maxOption5Size;
var maxOption6Size;

function disp_prompt_poll() {
	
	var numCharactersQuestion = document
			.getElementById("newPollForm:pollQuestion").value.length;
	var numCharactersOption1 = document.getElementById("newPollForm:option1").value.length;
	var numCharactersOption2 = document.getElementById("newPollForm:option2").value.length;
	var numCharactersOption3 = document.getElementById("newPollForm:option3").value.length; if(numCharactersOption3>0) numCharactersOption3 += 4;
	var numCharactersOption4 = document.getElementById("newPollForm:option4").value.length; if(numCharactersOption4>0) numCharactersOption4 += 4;
	var numCharactersOption5 = document.getElementById("newPollForm:option5").value.length; if(numCharactersOption5>0) numCharactersOption5 += 4;
	var numCharactersOption6 = document.getElementById("newPollForm:option6").value.length; if(numCharactersOption6>0) numCharactersOption6 += 4;

	var numCharacters = numCharactersQuestion + numCharactersOption1
			+ numCharactersOption2 + numCharactersOption3
			+ numCharactersOption4 + numCharactersOption5
			+ numCharactersOption6;
	var val = maxLengthAllowed - numCharacters;

	
	if (val >= 0) {
		maxQuestionSize = numCharactersQuestion;
		maxOption1Size = numCharactersOption1;
		maxOption2Size = numCharactersOption2;
		maxOption3Size = numCharactersOption3 - 4;
		maxOption4Size = numCharactersOption4 - 4;
		maxOption5Size = numCharactersOption5 - 4;
		maxOption6Size = numCharactersOption6 - 4;
	}

	if (val < 0) {
		
		document.getElementById("newPollForm:pollQuestion").value = document
				.getElementById("newPollForm:pollQuestion").value.substring(0,
				maxQuestionSize);
		document.getElementById("newPollForm:option1").value = document
				.getElementById("newPollForm:option1").value.substring(0,
				maxOption1Size);
		document.getElementById("newPollForm:option2").value = document
				.getElementById("newPollForm:option2").value.substring(0,
				maxOption2Size);
		document.getElementById("newPollForm:option3").value = document
				.getElementById("newPollForm:option3").value.substring(0,
				maxOption3Size);
		document.getElementById("newPollForm:option4").value = document
				.getElementById("newPollForm:option4").value.substring(0,
				maxOption4Size);
		document.getElementById("newPollForm:option5").value = document
				.getElementById("newPollForm:option5").value.substring(0,
				maxOption5Size);
		document.getElementById("newPollForm:option6").value = document
				.getElementById("newPollForm:option6").value.substring(0,
				maxOption6Size);
	}
	numCharactersQuestion = document.getElementById("newPollForm:pollQuestion").value.length;
	numCharactersOption1 = document.getElementById("newPollForm:option1").value.length;
	numCharactersOption2 = document.getElementById("newPollForm:option2").value.length;
	numCharactersOption3 = document.getElementById("newPollForm:option3").value.length; if(numCharactersOption3>0) numCharactersOption3 += 4;
	numCharactersOption4 = document.getElementById("newPollForm:option4").value.length; if(numCharactersOption4>0) numCharactersOption4 += 4;
	numCharactersOption5 = document.getElementById("newPollForm:option5").value.length; if(numCharactersOption5>0) numCharactersOption5 += 4;
	numCharactersOption6 = document.getElementById("newPollForm:option6").value.length; if(numCharactersOption6>0) numCharactersOption6 += 4;

	var numCharacters = numCharactersQuestion + numCharactersOption1
			+ numCharactersOption2 + numCharactersOption3
			+ numCharactersOption4 + numCharactersOption5
			+ numCharactersOption6;
	val = maxLengthAllowed - numCharacters;

	document.getElementById("newPollForm:maxSizeAllowedId").value = val;

}

function changePageIdHidd(pageId){
	document.getElementById("panelForm:pageIdHidd").value = pageId;
	document.getElementById("panelFormDel:pageIdHiddDel").value = pageId;
}

function selectIframeText(){
	document.getElementById("iframeInputText").focus();
	document.getElementById("iframeInputText").select();	
}



//######################################################################################################
//Content management
//######################################################################################################
function showPlayer(fileName) {
	a = window.open(fileName, "Player",
			'width=200,height=200,resizable=yes,scrollbars=yes');
	a.focus();
}

function executeAction(id) {
  var actionEle = document.getElementById(id);
  if (actionEle) {
	  actionEle.click();
  }
  
} 

function CopyToClipboard(text) {

	text = text.replace(/&lt;/g,"<");
	text = text.replace(/&gt;/g,">");
	text = text.replace(/<br>/g,"\n");
	text = text.replace(/&nbsp;/g,"\t");

	if (window.clipboardData) { 
		// Internet Explorer
		window.clipboardData.setData("Text", text);
	} else if (navigator.userAgent.indexOf('Gecko') != -1)  {

		netscape.security.PrivilegeManager.enablePrivilege( 'UniversalXPConnect' );

		if (!window.clipboard) {
			this.clipboardid = Components.interfaces.nsIClipboard;
	        this.clipboard = Components.classes['@mozilla.org/widget/clipboard;1'].getService( this.clipboardid );
	        this.clipboardstring = Components.classes['@mozilla.org/supports-string;1'].createInstance( Components.interfaces.nsISupportsString );
		}
		
		// Mozilla
        this.clipboardstring.data = text;
        var transfer = Components.classes['@mozilla.org/widget/transferable;1'].createInstance( Components.interfaces.nsITransferable );
        transfer.setTransferData( 'text/unicode', this.clipboardstring, text.length*2 );
        this.clipboard.setData( transfer, null, this.clipboardid.kGlobalClipboard );
        
	} else {
		// Other
	}
		
}

//######################################################################################################
//Response
//######################################################################################################

function reponseUpdateCounter(element) {
	var numChar = 130 - element.getElementsByTagName('input')[0].value.length;
	document.getElementById("responseForm:maxSizeAllowedId").value = numChar;
}

function responseCleanCounter(){
	document.getElementById("responseForm:maxSizeAllowedId").value = "";
}


//######################################################################################################
//Trivia JS
//######################################################################################################
var maxLengthAllowedTrivia = 130;

maxLengthAllowedTrivia -= 15;

var maxQuestionSize;
var maxOption1Size;
var maxOption2Size;
var maxOption3Size;
var maxOption4Size;

function disp_prompt_trivia() {
	
	var numCharactersQuestion = document
			.getElementById("triviaQuestionsForm:question").value.length;
	var numCharactersOption1 = document.getElementById("triviaQuestionsForm:triviaAnswer1").value.length;
	var numCharactersOption2 = document.getElementById("triviaQuestionsForm:triviaAnswer2").value.length;
	var numCharactersOption3 = document.getElementById("triviaQuestionsForm:triviaAnswer3").value.length; if(numCharactersOption3>0) numCharactersOption3 += 4;
	var numCharactersOption4 = document.getElementById("triviaQuestionsForm:triviaAnswer4").value.length; if(numCharactersOption4>0) numCharactersOption4 += 4;

	var numCharacters = numCharactersQuestion + numCharactersOption1
			+ numCharactersOption2 + numCharactersOption3
			+ numCharactersOption4;
	var val = maxLengthAllowedTrivia - numCharacters;

	
	if (val >= 0) {
		maxQuestionSize = numCharactersQuestion;
		maxOption1Size = numCharactersOption1;
		maxOption2Size = numCharactersOption2;
		maxOption3Size = numCharactersOption3 - 4;
		maxOption4Size = numCharactersOption4 - 4;
	}

	if (val < 0) {
		
		document.getElementById("triviaQuestionsForm:question").value = document
				.getElementById("triviaQuestionsForm:question").value.substring(0,
				maxQuestionSize);
		document.getElementById("triviaQuestionsForm:triviaAnswer1").value = document
				.getElementById("triviaQuestionsForm:triviaAnswer1").value.substring(0,
				maxOption1Size);
		document.getElementById("triviaQuestionsForm:triviaAnswer2").value = document
				.getElementById("triviaQuestionsForm:triviaAnswer2").value.substring(0,
				maxOption2Size);
		document.getElementById("triviaQuestionsForm:triviaAnswer3").value = document
				.getElementById("triviaQuestionsForm:triviaAnswer3").value.substring(0,
				maxOption3Size);
		document.getElementById("triviaQuestionsForm:triviaAnswer4").value = document
				.getElementById("triviaQuestionsForm:triviaAnswer4").value.substring(0,
				maxOption4Size);
	}
	numCharactersQuestion = document.getElementById("triviaQuestionsForm:question").value.length;
	numCharactersOption1 = document.getElementById("triviaQuestionsForm:triviaAnswer1").value.length;
	numCharactersOption2 = document.getElementById("triviaQuestionsForm:triviaAnswer2").value.length;
	numCharactersOption3 = document.getElementById("triviaQuestionsForm:triviaAnswer3").value.length; if(numCharactersOption3>0) numCharactersOption3 += 4;
	numCharactersOption4 = document.getElementById("triviaQuestionsForm:triviaAnswer4").value.length; if(numCharactersOption4>0) numCharactersOption4 += 4;

	var numCharacters = numCharactersQuestion + numCharactersOption1
			+ numCharactersOption2 + numCharactersOption3
			+ numCharactersOption4;
	val = maxLengthAllowedTrivia - numCharacters;

	document.getElementById("triviaQuestionsForm:maxSizeAllowedId").value = val;
}