// this function can be used to do extra work if desired; for some editors it is requiredfunction doSubmit () {	$("errors").innerHTML = "";	var strError = "";	//if ($("subcategoryholder").style.display == "block" && $("ideaSubProduct").selectedIndex == 0)	//	strError += "<li />Please select a sub IdeaSpace.";	if ($("ideaProduct")[$("ideaProduct").selectedIndex].text == LANG_FORM_SELECTSPACE)		strError += "<li />" + LANG_FORM_SELECTSPACE;	if ($("idea").value == ""){		strError += "<li />" + LANG_FORM_SHORTDESCRIPTION;	}else{		$("idea").value = editReplace($("idea").value, "<", "&lt;");		$("idea").value = editReplace($("idea").value, ">", "&gt;");	}	if ($("ideaCategories").value == "")		strError += "<li />" + LANG_FORM_ENTERTAG;	try {		if (isFCK()){			try {				if (FCKeditorAPI.GetInstance('ideaDescriptionWeb').GetXHTML(true) == "")					strError += "<li />You need to enter a description for your idea.";			}catch (e){				var description = formatComment($("ideaDescription").value);				if (description == "")					strError += "<li />You need to enter a description for your idea.";			}		}else{			var description = formatComment($("ideaDescription").value);			if (description == "")				strError += "<li />You need to enter a description for your idea.";		}	}catch (e){}	if (strError == ""){		$("ideaDescription").value = description;		document.forms[0].submit();	}else{		$("errors").innerHTML = "<ul>" + strError + "</ul>";		return false;	}}function showMatchingCategories(thevalue){	if (thevalue.indexOf(" ") > -1){		var data = thevalue.split(",");		thevalue = trim(data[data.length - 1]);	}	if (thevalue != ""){		var strHTML = "";		for (var i=0; i<categories.length; i++){			if (categories[i].toLowerCase().indexOf(thevalue.toLowerCase()) > -1){				strHTML += "<span class=\"suggestion\" onclick=\"addSuggestion('" + categories[i] + "')\">" + categories[i] + "</span>" + " ";			}		}		$("matchingcategories").innerHTML = strHTML;	}else{		$("matchingcategories").innerHTML = "";	}}function addSuggestion(thevalue){	var newvalue = "";	var current = $("ideaCategories").value;	if (current.indexOf(" ") > -1){		var data = current.split(",");		for (var i=0; i<data.length - 1; i++){			if (i > 0)				newvalue += ", ";			newvalue += trim(data[i]);		}		newvalue += ", " + thevalue;	}else{		newvalue = thevalue;	}	$("ideaCategories").value = newvalue;	$("matchingcategories").innerHTML = "";}function submitInternalComment(){	$("internalflag").value = "1";	submitComment(true);}function submitComment(ignoreInternal){	try {		if (!ignoreInternal)			$("internalflag").value = "0";	}catch (e){}	var comment = $("comment").value;	$("pleasewait").innerHTML = "<img src=\"" + dbPath + "/loading.gif\" />";	$("submitbutton").style.display = "none";	$("comment").value = formatComment(comment);	if(comment == ""){		return false;	}	//document.forms['commentform'].submit();	$('commentform').send({			onComplete: function(data) {				if (data.indexOf("var username = \"Anonymous\";") > -1){					alert("Your session has expired, please log in before posting your comment.");					$("submitbutton").style.display = "block";					$("pleasewait").innerHTML = "";				}else{					var commentdivs = $("commentview").getElementsByTagName("div");					var lastcomment = 0;					if (commentdivs.length > 1){						lastcomment = commentdivs[commentdivs.length - 2].innerHTML;						lastcomment = parseInt(lastcomment.substr(0, lastcomment.indexOf(")")), 10);					}else{						$("commentview").innerHTML = "";					}					var newcomment = "<div class=\"commentby\">" + (lastcomment + 1) + ") " + commonname + "</div><div class=\"comment\">" + $("comment").value + "</div>";					$("commentview").innerHTML += newcomment;					$("submitbutton").style.display = "block";					$("comment").value = "";					$("pleasewait").innerHTML = "";					$("commentpreview").innerHTML = "";				}			}		});}function formatComment(NewText){	//Taken from Blogsphere V3 template, thanks Declan!	var amp = /&/g;	var lt = /</g;	var gt = />/g;	var uri = /(\w+:\/\/[^\s]*)/g;	var newline = /\n/g;	NewText = NewText.replace(amp, "&amp;");	NewText = NewText.replace(lt, "&lt;");	NewText = NewText.replace(gt, "&gt;");	NewText = NewText.replace(uri, "{ <a href=\"$1\" rel=\"nofollow\" target=\"_blank\">Link</a> }");	NewText = NewText.replace(newline, "<br />");	NewText = NewText.replace(/\[b\]/g, "<b>");	NewText = NewText.replace(/\[\/b\]/g, "</b>");	NewText = NewText.replace(/\[i\]/g, "<i>");	NewText = NewText.replace(/\[\/i\]/g, "</i>");	NewText = NewText.replace(/\[u\]/g, "<u>");	NewText = NewText.replace(/\[\/u\]/g, "</u>");	NewText = NewText.replace(/\[s\]/g, "<del>");	NewText = NewText.replace(/\[\/s\]/g, "</del>");	return NewText;}function doPreview(){	var comment = formatComment($("comment").value);	if (comment != "")		$("commentpreview").innerHTML = LANG_FORM_PREVIEW + "<br /><div class=\"comment\">" + comment + "</div>";	else		$("commentpreview").innerHTML = "";}function reloadPage(){	window.location.reload();}function promote(unid){	if (username == "Anonymous"){		var newurl = window.location.href;		if (newurl.indexOf(".nsf") == -1)			newurl = dbPath;		if (newurl.indexOf("?open") == -1)			newurl += "?open";		//doWarning("You need to <a href=\"" + newurl + "&login=1\">login</a> to vote"); 		window.location.href = newurl + "&login=1";	}else{		var url = dbPath + "/promote?openagent&" + unid;		new Ajax(url, {				method: 'get',		          onComplete: processResponse	          }).request();		$("withdrawvotebutton").style.display = "block";		$("noopinionbutton").style.display = "none";		var promotelinks = $$('#view .div_votes_container_idea_form');		var unid = "";		for (var i=0; i<promotelinks.length; i++){			var votesdiv = promotelinks[i].getElementsByTagName("div");			if (votesdiv.length > 0){				var promotediv = votesdiv[0];				var demotediv = votesdiv[2];				promotediv.innerHTML = "";				promotediv.onclick = "void(0);"				promotediv.href = "javascript:void(0);"				promotediv.style.cursor = "default";				demotediv.innerHTML = "";				demotediv.onclick = "void(0);"				demotediv.href = "javascript:void(0);"				demotediv.style.cursor = "default";			}		}	}}function demote(unid){	if (username == "Anonymous"){		var newurl = window.location.href;		if (newurl.indexOf(".nsf") == -1)			newurl = dbPath;		if (newurl.indexOf("?open") == -1)			newurl += "?open";		//doWarning("You need to <a href=\"" + newurl + "&login=1\">login</a> to vote"); 		window.location.href = newurl + "&login=1";	}else{		var url = dbPath + "/demote?openagent&" + unid;		new Ajax(url, {				method: 'get',		          onComplete: processResponse    	      }).request();		$("withdrawvotebutton").style.display = "block";		$("noopinionbutton").style.display = "none";		var promotelinks = $$('#view .div_votes_container_idea_form');		var unid = "";		for (var i=0; i<promotelinks.length; i++){			var votesdiv = promotelinks[i].getElementsByTagName("div");			if (votesdiv.length > 0){				var promotediv = votesdiv[0];				var demotediv = votesdiv[2];				promotediv.innerHTML = "";				promotediv.onclick = "void(0);"				promotediv.href = "javascript:void(0);"				promotediv.style.cursor = "default";				demotediv.innerHTML = "";				demotediv.onclick = "void(0);"				demotediv.href = "javascript:void(0);"				demotediv.style.cursor = "default";			}		}	}}function meh(unid){	if (username == "Anonymous"){		var newurl = window.location.href;		if (newurl.indexOf(".nsf") == -1)			newurl = dbPath;		if (newurl.indexOf("?open") == -1)			newurl += "?open";		//doWarning("You need to <a href=\"" + newurl + "&login=1\">login</a> to vote"); 		window.location.href = newurl + "&login=1";	}else{		var url = dbPath + "/meh?openagent&" + unid;		new Ajax(url, {				method: 'get',		          onComplete: processResponse	          }).request();		$("withdrawvotebutton").style.display = "block";		$("noopinionbutton").style.display = "none";		var promotelinks = $$('#view .div_votes_container_idea_form');		var unid = "";		for (var i=0; i<promotelinks.length; i++){			var votesdiv = promotelinks[i].getElementsByTagName("div");			if (votesdiv.length > 0){				var promotediv = votesdiv[0];				var demotediv = votesdiv[2];				promotediv.innerHTML = "";				promotediv.onclick = "void(0);"				promotediv.href = "javascript:void(0);"				promotediv.style.cursor = "default";				demotediv.innerHTML = "";				demotediv.onclick = "void(0);"				demotediv.href = "javascript:void(0);"				demotediv.style.cursor = "default";			}		}	}}function withdrawvote(unid){	if (username == "Anonymous"){		var newurl = window.location.href;		if (newurl.indexOf("?open") == -1)			newurl += "?open";		doWarning(LANG_GEN_LOGINTOVOTE); 	}else{		var url = dbPath + "/withdrawvote?openagent&" + unid;		new Ajax(url, {				method: 'get',		          onComplete: processResponse	          }).request();		$("withdrawvotebutton").style.display = "none";		$("noopinionbutton").style.display = "block";		var promotelinks = $$('#view .div_votes_container_idea_form');		var unid = "";		for (var i=0; i<promotelinks.length; i++){			var votesdiv = promotelinks[i].getElementsByTagName("div");			if (votesdiv.length > 0){				var promotediv = votesdiv[0];				var demotediv = votesdiv[2];				promotediv.innerHTML = LANG_GEN_PROMOTE;				promotediv.onclick = "promote('" + unid + "');"				promotediv.style.cursor = "pointer";				demotediv.innerHTML = LANG_GEN_DEMOTE;				demotediv.onclick = "demote('" + unid + "');"				demotediv.style.cursor = "pointer";			}		}	}}function processResponse(originalRequest){	var data = editReplace(originalRequest, "\n", "");	if (data == ""){		doWarning(LANG_GEN_NOTALLOWED);	}else if (data != "0"){		//window.location.reload();		var unid = data.split(" ")[1];		var url = dbPath + "/getVoteInfo?open&id=" + unid + "&rnd=" + Math.floor(Math.random()*1001);		new Ajax(url, {				method: 'get',		          onComplete: updateVoteInfo		}).request();		doWarningFade(LANG_FORM_THANKS);	}}function updateVoteInfo(originalRequest){	var data = editReplace(originalRequest, "\n", "");	$("votedetails").innerHTML = data;}function editReplace(strTest, strFrom, strTo){	var re = new RegExp(strFrom, "gim");	if ( ! re.exec(strTest) ){		return strTest;	}	return strTest.replace(re,strTo);}function Left(str, n){	if (n <= 0)	    return "";	else if (n > String(str).length)	    return str;	else	    return String(str).substring(0,n);}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);    }}function trim(str) {     if (str != null) {        var i;         for (i=0; i<str.length; i++) {            if (str.charAt(i)!=" ") {                str=str.substring(i,str.length);                 break;            }         }             for (i=str.length-1; i>=0; i--) {            if (str.charAt(i)!=" ") {                str=str.substring(0,i+1);                 break;            }         }                 if (str.charAt(0)==" ") {            return "";         } else {            return str;         }    }}//*************************var txt, log, fx;function initWarnings(){	log = $('warningmessage');	fx = new Fx.Styles(log, {		duration: 1500,		wait: false,		transition: Fx.Transitions.Quad.easeIn	});} function doWarning(message){	$("warningmessage").innerHTML = message + " <input type=\"button\" onclick=\"hideWarning()\" value=\"OK\" />";	if (currentUNID == "")		$("warningmessage").style.top = window.getScrollTop() + "px";	else{		try {			$("warningmessage").style.top = $(currentUNID).getTop() + "px";		}catch (e){			$("warningmessage").style.top = window.getScrollTop() + "px";		}	}	fx.set({		'opacity': 1	});}function hideWarning(){	fx.set({		'opacity': 0	});}function doWarningFade(message){	$("warningmessage").innerHTML = message;	if (currentUNID == "")		$("warningmessage").style.top = window.getScrollTop() + "px";	else		$("warningmessage").style.top = $(currentUNID).getTop() + "px";	//var myFx = new Fx.Style('warningmessage', {opacity, duration: 1500}).start(1,0);	var myFx = new Fx.Style('warningmessage', 'opacity', {		transition: Fx.Transitions.Back.easeInOut,		duration: 1500	}).start(1, 0);}//*************************function editIdea(){	document.location.href = dbPath + "/0/" + currentUNID + "?editdocument";}function checkPromoteLinks(){		var promotelinks = $$('#view .div_votes_container_idea_form');		var unid = "";		for (var i=0; i<promotelinks.length; i++){			var votesdiv = promotelinks[i].getElementsByTagName("div");			if (votesdiv.length > 0){				unid = votesdiv[1].id;				var promotediv = votesdiv[0];				var demotediv = votesdiv[2];				if (myvotes[unid] | currentStatus == "Complete" | currentStatus == "Rejected" | currentStatus == "Withdrawn"){					promotediv.innerHTML = "";					promotediv.onclick = "void(0);"					promotediv.href = "javascript:void(0);"					promotediv.style.cursor = "default";					demotediv.innerHTML = "";					demotediv.onclick = "void(0);"					demotediv.href = "javascript:void(0);"					demotediv.style.cursor = "default";				}else{					promotediv.innerHTML = LANG_GEN_PROMOTE;					demotediv.innerHTML = LANG_GEN_DEMOTE;				}			}		}}function buildLinkList(){	var currentspacefield = $("ideaProduct");	var currentspace = currentspacefield[currentspacefield.selectedIndex].text;	//Get any sub categories if necessary	var subcategoriesfield = $("ideaSubProduct");	if (subcategories[currentspace] != null){		var thearray = subcategories[currentspace];		subcategoriesfield.length = thearray.length + 1;		subcategoriesfield[0].value = "Other";		subcategoriesfield[0].text = "Other";		for (var i=0; i<thearray.length; i++){			subcategoriesfield[i + 1].text = thearray[i];			subcategoriesfield[i + 1].value = thearray[i];			if (currentsubcategory == thearray[i])				subcategoriesfield.selectedIndex = i + 1;		}		$("subcategoryholder").style.display = "block";	}else{		subcategoriesfield.length = 1;		subcategoriesfield[0].value = "";		subcategoriesfield[0].text = "";		$("subcategoryholder").style.display = "none";	}		//Now build link list	var currentspacefield = $("ideaProduct");	var currentspace = currentspacefield[currentspacefield.selectedIndex].text;	var newlist = new Array();	for (var i=0; i<ideasbyproduct.length; i++){		var data = ideasbyproduct[i].split("@@@");		if (data[0] == currentspace){			newlist.push(new Array(data[1], data[2]));		}	}	var linklist = $("ideaLink");	linklist.length = newlist.length + 1;	linklist[0].value = "";	linklist[0].text = "";	for (var i=0; i<newlist.length; i++){		linklist[i + 1].value = newlist[i][0];		linklist[i + 1].text = unescape(newlist[i][1]);		if (currentlinkedidea == newlist[i][0])			linklist.selectedIndex = i + 1;	}}function handleSearchReturn(event){	var event = new Event(event);	if (event.key == "enter"){		event.stopPropagation();		doSearch();		return false;	}else{		return true;	}}function doSearch(){	if ($("query").value != "" && $("query").value != "Search..."){		var url = dbPath + "/search?searchview&query=" + escape($("query").value) + "&start-0&count=40";		window.location.href = url;	}}function openDoc(url){	window.location.href = url;}function changeSpace(thefield){	var thevalue = thefield[thefield.selectedIndex].value;	window.location.href = thevalue;}function checkForSimilarIdeas(){	if ($("idea").value != "" && window.location.href.indexOf("idea?openform") > -1){		$("similarideas").style.display = "block";		$("similarideas").innerHTML = "<img src=\"" + dbPath + "/ajax-loader.gif\" />";		var url = dbPath + "/checkForSimilarIdeas?openagent&idea=" + escape($("idea").value);		new Ajax(url, {				method: 'get',		          onComplete: processSimilarIdeasResponse	          }).request();	}}function processSimilarIdeasResponse(data){	$("similarideas").innerHTML = "";	if (data == ""){		$("similarideas").style.display = "none";	}else{		$("similarideas").innerHTML = "<b>" + LANG_FORM_SIMILARIDEAS + "</b><br /><ul>" + data;	}}function doLogout(url){	try {		var sender = $("nctRememberMeCheckBox");		if (sender.checked){			sender.checked = false;			nctRememberMeSetCheckBoxPref( sender );			Cookie.remove('nct_remembermetoken');			Cookie.remove('LtpaToken');		}	}catch(e){		//Ignore this, remember me may be turned off	}	window.location.href=url;}function getPreviousIdea(){	var url = dbPath + "/getNextIdea?openagent&action=previous&idea=" + ideaid;	new Ajax(url, {			method: 'get',	          onComplete: processNextIdeaResponse          }).request();}function getNextIdea() {	var url = dbPath + "/getNextIdea?openagent&action=next&idea=" + ideaid;	new Ajax(url, {			method: 'get',	          onComplete: processNextIdeaResponse          }).request();}function processNextIdeaResponse(data){	var newunid = editReplace(data, "\n", "");	if (newunid != "")		document.location.href = dbPath + "/0/" + newunid + "?opendocument";	else		doWarningFade(LANG_FORM_NOMOREIDEAS);}function showVotes(){	$("whohasvoted").innerHTML = "<img src=\"" + dbPath + "/loading.gif\" />";	var url = "/" + votesdb + "/VotesByIdea?open&id=" + currentUNID + "&dbPath=" + dbPath + "&rnd=" + Math.floor(Math.random()*1001);	new Ajax(url, {			method: 'get',	          onComplete: function (data){	          	$("whohasvoted").innerHTML = unescape(data);	          }          }).request();}function toggleFavorite(thestar) {	var id = thestar.id.split("_");	id = id[1];	currentUNID = id;	if (username == "Anonymous"){		doWarningFade("You need to log in to store favorites");	}else{		var favorite = "true";		if (thestar.className != "idea_star_empty"){			favorite = "false";		}		var url = dbPath + "/toggleFavorite?open&id=" + id + "&favorite=" + favorite + "&rnd=" + Math.floor(Math.random()*1001);		new Ajax(url, {				method: 'get',		          onComplete: function (data) {		          		try {			          		if (data.indexOf("error") > -1){								doWarningFade("There was an error storing your favorite");							}else{								if (favorite == "true")									thestar.className = "idea_star";								else									thestar.className = "idea_star_empty";							}						}catch (e){}		          	}	          }).request();	}}function checkFavoriteLinks(){	if (username != "Anonymous"){		var thestars = $$(".idea_star_empty");		for (var i=0; i<thestars.length; i++){			var id = thestars[i].id.split("_");			if (favorites[id[1]])				thestars[i].className = "idea_star";		}	}}function addFile(theButton, fileUploadId){	try {		theButton.style.display = "none";		$(fileUploadId).style.display = "block";		$("button" + fileUploadId).style.display = "block";	}catch (e){}}
