var linkedover = null;function initIdea() {    try {        doLoadFCKEditor();    } catch(e) {        //This may error is rich text is disabled    }    try {        $('query').value = get_ents(LANG_GEN_SEARCH);        $('query').onkeypress = handleSearchReturn;        if (window.location.href.toLowerCase().indexOf("editdocument") > -1 || window.location.href.toLowerCase().indexOf("openform") > -1) {        	if (Browser.ie6)	        	$("ideaDescription").value = $("ideaDescription").value.replace(/\n/g,"").replace(/\r/g, "");            $("ideaDescription").value = editReplace($("ideaDescription").value, "<br />", "\n");            buildLinkList();        }        if ($("commentview").innerHTML.indexOf("No documents found") > -1) {            $("commentview").innerHTML = "<div class=\"nocomments\">" + LANG_FORM_NOCOMMENTS + "</div>";        }        initWarnings();        checkPromoteLinks();        checkFavoriteLinks();        if ($("tagcloud").style.display == "block")        initTagCloud();    } catch(e) {}    try {		new DatePicker('.implementationdate', { positionOffset: { x: 0, y: 5 }, inputOutputFormat: 'd M Y', format: "d M Y"});		new DatePicker('.additionaldate', { positionOffset: { x: 0, y: 5 }, inputOutputFormat: 'd M Y', format: "d M Y"});    } catch(e) {    }    try {        var proper = frames['upload_target'].document.getElementById("properfileupload");        $("commentfile").name = proper.name;    } catch(e) {    }        try {		$("linkedideatext").alt = LANG_FORM_LINKEDIDEADEFAULT;		linkedover = new OverText($("linkedideatext"));	}catch (e){}		try{		new Autocompleter.Local('ideaCategories', categories, {			'minLength': 1, // We need at least 1 character			'selectMode': 'type-ahead', // Instant completion			'multiple': true // Tag support, by default comma separated		});	}catch(e){}		initCommentModeration();}// 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").selectedIndex == 0)		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 {		var status = get_radio_value("ideaStatus");		if( $("implementationmanager").value == "" && status!="Open" && status!="Rejected" && status!="Withdrawn" && status!=""){			strError += "<li />" + LANG_FORM_ENTERIMPMANAGER;		}	}catch(e){}	try {		if (isFCK()){			try {				if (FCKeditorAPI.GetInstance('ideaDescriptionWeb').GetXHTML(true) == "")					strError += "<li />" + LANG_FORM_DESCRIPTIONERROR;			}catch (e){				var description = formatComment($("ideaDescription").value);				if (description == "")					strError += "<li />" + LANG_FORM_DESCRIPTIONERROR;			}		}else{			var description = formatComment($("ideaDescription").value);			if (description == "")				strError += "<li />" + LANG_FORM_DESCRIPTIONERROR;		}	}catch (e){}	if (strError == ""){		$("ideaDescription").value = description;				//Now Submit a comment to note the status change if necessary		if (getRadio(document._idea.ideaStatus) != currentstatus && window.location.href.indexOf("openform") == -1){			var url = dbPath + "/tempcomment?createdocument&ParentUNID=" + docUNID;			var data = "comment=" + LANG_FORM_STATUSCHANGEDTO + " " + getStatus(getRadio(document._idea.ideaStatus)) + "&internalflag=0&statuschange=1";			new Request({				url: url, 				method: 'post',		        onComplete: function (data, xml){					try {						var f = document.forms[0];						f.removeChild( f['%%ModDate'] );					}catch (e){						//Ignore					}					document.forms[0].submit();		          }	          }).send(data);		}else{			document.forms[0].submit();		}	}else{		$("errors").innerHTML = "<ul>" + strError + "</ul>";		linkedover.reposition();		return false;	}}function toggleExtraFields(){	try{		var status = get_radio_value("ideaStatus");		if(status=="Open" || status=="Rejected" || status=="Withdrawn")			$("extrafieldscontainer").style.display="none";		else			$("extrafieldscontainer").style.display="block";	}catch(e){}	}function getStatus(status){	if (status == "In Progress")		return LANG_FORM_INPROGRESS;	if (status == "Open")		return LANG_FORM_OPEN;	if (status == "Withdrawn")		return LANG_FORM_WITHDRAWN;	if (status == "Complete")		return LANG_FORM_COMPLETE;	if (status == "Rejected")		return LANG_FORM_REJECTED;}function get_radio_value(id){	try {	    for( var i=0; i < document.forms[0][id].length; i++ )	    {	       if( document.forms[0][id][ i ].checked )	       {	           return document.forms[0][id][ i ].value;	       }	    }	}catch(e){		return "";	}}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 = "";	}	linkedover.reposition();}function addSuggestion(thevalue){	var newvalue = "";	var current = $("ideaCategories").value;	var data = current.split(",");	data.each(function(item, i){		if (i > 0)			newvalue += ", ";		newvalue += trim(item);	});	if(newvalue.trim().length > 0 && Right(newvalue.trim(), 1) != ",")		newvalue += ", " + thevalue;	else		newvalue += thevalue;	$("ideaCategories").value = (newvalue + ", ").clean();	$("matchingcategories").innerHTML = "";}function submitInternalComment(){	$("internalflag").value = "1";	submitComment(true);}function submitComment(ignoreInternal){	try {		if (!ignoreInternal)			$("internalflag").value = "0";	}catch (e){}	var comment = document.getElementById("comment").value;	$("pleasewait").innerHTML = "<img src=\"" + dbPath + "/loading.gif\" />";	$("submitbutton").style.display = "none";	$("comment").value = formatComment(comment);	if(comment == ""){		$("submitbutton").style.display = "block";		$("pleasewait").innerHTML = "";		return false;	}	var now = new Date();	$("datecreatedinmillis").value = now.valueOf();	//document.forms['commentform'].submit();	$('commentform').set('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').getElements('div.commentby');					var lastcomment = 0;					if (commentdivs.length > 0){						lastcomment = commentdivs[commentdivs.length - 1].innerHTML;						lastcomment = parseInt(lastcomment.substr(0, lastcomment.indexOf(")")), 10);					}else{						$("commentview").innerHTML = "";					}					var newcomment = "<div class=\"commentby";					if (fulladmin)						newcomment += " systemadmin";					if (ideaspaceadmin)						newcomment += " ideaspaceadmin";					newcomment += "\">" + (lastcomment + 1) + ") " + commonname + "</div><div class=\"comment\">" + $("comment").value;					try{						newcomment += "<div id=\"attachment_" + $("attachmentid").value + "\"></div>" + "</div>";					}catch(e){}					$("commentview").innerHTML += newcomment;					$("submitbutton").style.display = "block";					$("comment").value = "";					$("pleasewait").innerHTML = "";					$("commentpreview").innerHTML = "";					try{						$("attachmentid2").value = $("attachmentid").value;						fileUpload($('file_upload_form'), dbPath + "/attachment?createdocument", "attachment_" + $("attachmentid").value);						$("attachmentid").value += "1";						$("commentfile").value = "";					}catch(e){}				}			}		}).send();}function fileUpload(form, action_url, div_id) {	// Create the iframe...	var iframe = document.createElement("iframe");	iframe.setAttribute("id","upload_iframe");	iframe.setAttribute("name","upload_iframe");	iframe.setAttribute("width","0");	iframe.setAttribute("height","0");	iframe.setAttribute("border","0");	iframe.setAttribute("style","width: 0; height: 0; border: none;");	// Add to document...	form.parentNode.appendChild(iframe);	window.frames['upload_iframe'].name="upload_iframe";	iframeId = document.getElementById("upload_iframe");	// Add event...	var eventHandler = function()  {			if (iframeId.detachEvent)				iframeId.detachEvent("onload", eventHandler);			else				iframeId.removeEventListener("load", eventHandler, false);				// Message from server...			if (iframeId.contentDocument)				content = iframeId.contentDocument.body.innerHTML;			else if (iframeId.contentWindow)				content = iframeId.contentWindow.document.body.innerHTML;			else if (iframeId.document)				content = iframeId.document.body.innerHTML;						var ret = content;			if (strRight(ret, 7) != "/$FILE/"){				ret = ret.split(">");				ret = ret[1].split("<")[0];				var filename = ret.split("/");				filename = filename[filename.length - 1];				ret = "<a class=\"commentattachment\" target=\"_new\" href=\"" + dbPath + ret + "\">" + filename + "</a>";				document.getElementById(div_id).innerHTML = ret;			}else{				document.getElementById(div_id).innerHTML = "No File Attachment to display";			}			// Del the iframe...			setTimeout('iframeId.parentNode.removeChild(iframeId)', 250);	};	if (iframeId.addEventListener)		iframeId.addEventListener("load", eventHandler, true);	if (iframeId.attachEvent)		iframeId.attachEvent("onload", eventHandler);	// Set properties of form...	form.setAttribute("target","upload_iframe");	form.setAttribute("action", action_url);	form.setAttribute("method","post");	form.setAttribute("enctype","multipart/form-data");	form.setAttribute("encoding","multipart/form-data");	// Submit the form...	form.submit();	$(div_id).innerHTML = "<img src=\"" + dbPath + "/loading.gif\" /> Uploading...";}function formatComment(NewText){	var amp = /&/g;	var lt = /</g;	var gt = />/g;	var uri = /(\w+:\/\/[^\s]*)/g;	var newline = /\r\n?\r\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(/\n/g, "<br />").replace(/\r/g, "");	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(){	try {		var comment = formatComment($("comment").value);		if (comment != "")			$("commentpreview").innerHTML = LANG_FORM_PREVIEW + "<br /><div class=\"comment\">" + comment + "</div>";		else			$("commentpreview").innerHTML = "";	}catch(e){}}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");		newurl = editReplace(newurl, "#votinganc", "");		newurl = editReplace(newurl, "#commentsanc", ""); 		window.location.href = newurl + "&login=1";	}else{		var url = dbPath + "/promote?openagent" + "&rnd=" + Math.floor(Math.random()*1001) + "&id=" + unid;		new Request({				url: url, 				method: 'get',		          onComplete: processResponse	          }).send();		$("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];				howVoted = "promote";				promotediv.innerHTML = LANG_FORM_YOUPROMOTED;				promotediv.className = "howVoted";				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"); 		newurl = editReplace(newurl, "#votinganc", "");		newurl = editReplace(newurl, "#commentsanc", ""); 		window.location.href = newurl + "&login=1";	}else{		var url = dbPath + "/demote?openagent" + "&rnd=" + Math.floor(Math.random()*1001) + "&id=" + unid;		new Request({				url: url, 				method: 'get',		          onComplete: processResponse    	      }).send();		$("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];				howVoted = "demote";				promotediv.innerHTML = LANG_FORM_YOUDEMOTED;				promotediv.className = "howVoted";				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" + "&rnd=" + Math.floor(Math.random()*1001) + "&id=" + unid;		new Request({				url: url, 				method: 'get',		          onComplete: processResponse	          }).send();		$("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];				howVoted = "noopinion";				promotediv.innerHTML = LANG_FORM_YOUNOOPINION;				promotediv.className = "howVoted";				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&rnd=" + Math.floor(Math.random()*1001) + "&id=" + unid;		new Request({				url: url, 				method: 'get',		          onComplete: processResponse	          }).send();		$("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];				howVoted = "";				promotediv.innerHTML = LANG_GEN_PROMOTE;				promotediv.className = "div_promote_idea";				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 Request({				url: url, 				method: 'get',		          onComplete: updateVoteInfo		}).send();		doWarningFade(LANG_FORM_THANKS);	}}function updateVoteInfo(originalRequest){	var data = editReplace(originalRequest, "\n", "");	data = editReplace(data, "LANG_GEN_PROMOTE", LANG_GEN_PROMOTE);	data = editReplace(data, "LANG_GEN_DEMOTE", LANG_GEN_DEMOTE);	data = editReplace(data, "LANG_FORM_PROMOTES", LANG_FORM_PROMOTES);	data = editReplace(data, "LANG_FORM_DEMOTES", LANG_FORM_DEMOTES);	data = editReplace(data, "LANG_FORM_TOTAL", LANG_FORM_TOTAL);	$("votedetails").innerHTML = data;	var promotelinks = $$('#view .div_votes_container_idea_form');	var unid = "";	if (howVoted != ""){		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];				if (howVoted == "noopinion")					promotediv.innerHTML = LANG_FORM_YOUNOOPINION;				else if (howVoted == "promote")					promotediv.innerHTML = LANG_FORM_YOUPROMOTED;				else if (howVoted == "demote")					promotediv.innerHTML = LANG_FORM_YOUDEMOTED;				promotediv.className = "howVoted";				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 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;function initWarnings(){} function doWarning(message){	$("warningmessage").innerHTML = message + " <input type=\"button\" onclick=\"hideWarning()\" value=\"OK\" />";	if (currentUNID == "")		$("warningmessage").style.top = window.getScrollTop() + "px";	else		$("warningmessage").style.top = $(currentUNID).getTop() + "px";	var tween = $('warningmessage').get('tween', {property: 'opacity'});	tween.start(1);	}function doWarningFade(message){	$("warningmessage").innerHTML = message;	if (currentUNID == "")		$("warningmessage").style.top = window.getScrollTop() + "px";	else{		if (currentUNID != null)			$("warningmessage").style.top = $(currentUNID).getTop() + "px";		else			$("warningmessage").style.top = $("viewnav1").getTop() + "px";	}	var tween = $('warningmessage').get('tween', {property: 'opacity'});	tween.start(1).chain(function(){		tween.start(0);	});}function hideWarning(){	var tween = $('warningmessage').get('tween', {property: 'opacity'});	tween.start(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] && !isInReadMode){					if (howVoted == "promote")						promotediv.innerHTML = LANG_FORM_YOUPROMOTED;					else if(howVoted == "demote")						promotediv.innerHTML = LANG_FORM_YOUDEMOTED;					else if(howVoted = "noopinion")						promotediv.innerHTML = LANG_FORM_YOUNOOPINION;					else						promotediv.innerHTML = "";					promotediv.className = "howVoted";					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 if (currentStatus == "Complete" | currentStatus == "Rejected" | currentStatus == "Withdrawn" | isInReadMode){					if (howVoted == "promote")						promotediv.innerHTML = LANG_FORM_YOUPROMOTED;					else if(howVoted == "demote")						promotediv.innerHTML = LANG_FORM_YOUDEMOTED;					else if(howVoted = "noopinion")						promotediv.innerHTML = LANG_FORM_YOUNOOPINION;					else						promotediv.innerHTML = "";					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;					promotediv.title = LANG_GEN_PROMOTEALT;					promotediv.alt = LANG_GEN_PROMOTEALT;					demotediv.title = LANG_GEN_DEMOTEALT;					demotediv.alt = LANG_GEN_DEMOTEALT;				}			}		}}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";	}}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 query = escape($("query").value);		query = editReplace(query.toLowerCase(), "field", "\"field\""); 		var url = dbPath + "/search?searchview&query=" + query + "&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\" />";		linkedover.reposition();		var url = dbPath + "/checkForSimilarIdeas?openagent&idea=" + escape($("idea").value);		new Request({				url: url, 				method: 'get',		        onComplete: function (data){					$("similarideas").innerHTML = "";					if (data == ""){						$("similarideas").style.display = "none";					}else{						var tags = new Array();						var html = "<b>" + LANG_FORM_SIMILARIDEAS + "</b><br /><ul>";						var result = eval("(" + data + ")");						result = result.result;						for(var i=0; i<result.length; i++){							html += "<li /><a href=\"" + result[i].url + "\" target=\"newwin\">" + result[i].title + "</a></li>";							for (var iTag=0; iTag<result[i].tags.length; iTag++){								tags.include(result[i].tags[iTag]);							}						}						html += "</ul>";						$("similarideas").innerHTML = html;						if (result.length == 0)							$("similarideas").style.display = "none";												html = "<b>" + LANG_FORM_SUGGESTEDTAGS + "</b><br />";						for (var i=0; i<tags.length; i++){							html += "<span class=\"suggestion\" onclick=\"addSuggestion('" + tags[i] + "')\">" + tags[i] + "</span>" + " ";						}						if (html != "")							$("suggestedcategories").style.display = "block";						$("suggestedcategories").innerHTML = html;						if (tags.length == 0)							$("suggestedcategories").style.display = "none";					}					linkedover.reposition();				}		}).send();	}}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 Request({			url: url, 			method: 'get',	          onComplete: processNextIdeaResponse          }).send();}function getNextIdea() {	var url = dbPath + "/getNextIdea?openagent&action=next&idea=" + ideaid;	new Request({			url: url, 			method: 'get',	          onComplete: processNextIdeaResponse          }).send();}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 Request({			url: url, 			method: 'get',	          onComplete: function (data){	          	$("whohasvoted").innerHTML = unescape(data);	          }          }).send();}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 Request({				url: 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";									thestar.title = LANG_GEN_UNMARKFAVORITE;								}else{									thestar.className = "idea_star_empty";									thestar.title = LANG_GEN_MARKFAVORITE;								}							}						}catch (e){}		          	}	          }).send();	}}function checkFavoriteLinks(){	var thestars = $$(".idea_star_empty");	for (var i=0; i<thestars.length; i++){		try{			var id = thestars[i].id.split("_");			if (favorites[id[1]]){				thestars[i].className = "idea_star";				thestars[i].title = LANG_GEN_UNMARKFAVORITE;			}else{				thestars[i].title = LANG_GEN_MARKFAVORITE;			}		}catch(e){			thestars[i].title = LANG_GEN_MARKFAVORITE;		}	}}function addFile(theButton, fileUploadId){	try {		theButton.style.display = "none";		$(fileUploadId).style.display = "block";		$("button" + fileUploadId).style.display = "block";	}catch (e){}}function deleteIdea(){	if (confirm("You will not be able to recover this Idea. Continue?")){		currentUNID		var url = dbPath + "/deleteIdea?open&unid=" + currentUNID + "&rnd=" + Math.floor(Math.random()*1001);		new Request({				url: url, 				method: 'get',		          onComplete: function (data) {		          		try {			          		if (data.indexOf("error") > -1){								doWarningFade("There was an error deleting the idea");							}else{								window.location.href = dbPath;							}						}catch (e){}		          	}	          }).send();	}}var tags = new Array();function initTagCloud(){	try {		var url = dbPath + "/IdeasByTagAJAX?openview&collapseview&count=4000";		new Request({				url: url, 				method: 'get',		          onComplete: function (data) {		          		try {			          		eval(editReplace(data, "\n", ""));			          		var arraydata = data.split("\n");			          		var sortdata = new Array();			          		for (var i=0; i<arraydata.length; i++){			          			var temp = arraydata[i].split("=");			          			var key = temp[0].split("\"")[1];			          			tags.push(new tag(key, parseFloat(editReplace(temp[1], ";", ""))));			          		}			          		tags.sort(sortByCount);			          		for (var i=(tags.length - 1); i>=0; i--){			          			if (i < (tags.length - 50))			          				tagMap[tags[i].name] = null;			          		}							drawTagCloud(tagMap,6);						}catch (e){}		          	}	          }).send();	}catch (e){}}function tag (name, count){	this.name = name;	this.count = count;}function sortByCount(a, b) {	var x = a.count;	var y = b.count;	return ((x < y) ? -1 : ((x > y) ? 1 : 0));}function maxArray( arr ) {	var max = 0;	for(var i in arr){  	    if (arr[i] > max)  	    		max = arr[i];  	}  	return max;}function minArray( arr ) {	var min;	var count = 0;	for(var i in arr){		if ("" + (arr[i] / 1) != "NaN"){			if (count==0)				min = arr[i];			if (arr[i] < min)	  	    		min = arr[i];	  	    	count++;		}  	}  	return min;}function drawTagCloud(map, maxStyle) {	var maxEntries = maxArray(map);	var minEntries = minArray(map);		var range = maxEntries - minEntries;	if (range <= 0)		range = 1;		for(var tag in map){				if (tagMap[tag] != null)	  		drawTag(tag, tagMap[tag], minEntries, maxEntries, maxStyle);  	}}function drawTag(tag, count, min, max, maxStyle) {	var sizeTag = Math.round((((maxStyle-1)/(max-min))*count) +(1*max-maxStyle*min)/(max-min));	if ("" + sizeTag != "NaN"){		if ($("tagcloud").innerHTML == "")			$("tagcloud").innerHTML = "<br/><h2>" + LANG_VIEW_TOPIDEATAGS + "</h2><br/>";		$("tagcloud").innerHTML += "<a href=\"" + dbPath + "/ProductByCategory?openview&restricttocategory=" + tag + "&count=1000\" class=\"tag" + sizeTag + "\">" + decodeURIComponent(tag.toLowerCase()) + "</a>  ";	}}function getRadio(radioObj){	if(!radioObj)		return "";	var radioLength = radioObj.length;	if(radioLength == undefined)		if(radioObj.checked)			return radioObj.value;		else			return "";	for(var i = 0; i < radioLength; i++) {		if(radioObj[i].checked) {			return radioObj[i].value;		}	}	return "";}function closeMessage(unid){	try {		var url = dbPath + "/closeMessage?open&unid=" + unid + "&rnd=" + Math.floor(Math.random()*1001);		new Request({				url: url, 				method: 'get',		          onComplete: function (data) {		          		try {			          		if (data.indexOf("error") > -1){								doWarningFade("There was an error closing the message:\n\n" + data);							}else{								$("message_" + unid).style.display = "none";							}						}catch (e){}		          	}   	       }).send();	}catch(e){		doWarningFade("There was an error closing the message:\n\n" + e.getMessage());	}}function get_ents(str){	var temp=document.createElement("pre");	temp.innerHTML=str;	return temp.firstChild.nodeValue;}function tidyLinks(){	var body = $("ideaDescription");	body.value = editReplace(body.value, "{ <a href=\"", "");	body.value = editReplace(body.value, "\" rel=\"nofollow\" target=\"_blank\">Link</a> }", "");}function toggleextrafields(show){	if (show){		$("extrafieldscontainer").style.display = "block";		$("hiddenextrafields").style.display = "none";	}else{		$("extrafieldscontainer").style.display = "none";		$("hiddenextrafields").style.display = "block";	}}function strRight(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 focusLinkedIdeasDialog(thefield){	if (thefield.value == LANG_FORM_LINKEDIDEADEFAULT)		thefield.value = "";}function blurLinkedIdeasDialog(thefield){	if (thefield.value == "")		thefieldvalue = LANG_FORM_LINKEDIDEADEFAULT;}function searchLinkedIdeas(thefield){	var thediv = $("linkedideasuggestions");	thediv.innerHTML = "<img src=\"" + dbPath + "/ajax-loader.gif\" />";	var url = dbPath + "/searchLinkedIdeas?openagent&rnd=" + Math.floor(Math.random()*1001);	new Request({		url: url, 		method: 'post',		link: 'chain', 		onComplete: function (data){			try {				var myObject = eval('(' + data + ')');				var html = "";				if (myObject.result.length > 0){					html = "<ul>";					for (var i=0; i<myObject.result.length; i++){						html += "<li><a href=\"#idealinkanc\" class=\"linkedidea\" onclick=\"storeLinkedIdea('" + myObject.result[i].id;						html += "', \'" + escape(myObject.result[i].title) + "\')\">" + myObject.result[i].title + "</a></li>";					}					html += "</ul>";				}else{					html = "<p>No matching ideas found</p>";				}				thediv.innerHTML = html;				thediv.style.display = "block";			}catch (e){							}		}	}).send("query=" + escape(thefield.value));}function storeLinkedIdea(id, title){	var thefield = $("ideaLink");	if (thefield.value==""){		thefield.value = id;	}else{		thefield.value += "," + id;		}	var list = $("linkedideaslist");	var doclink = new Element('a', {		'href': dbPath + '/0/' + id,		'html': unescape(title), 		'class': 'linkedidea', 		'target': 'newwin'	});	var removeLink = new Element('a', {		'href': "#idealinkanc",		'onclick': "removeLinkedIdea(\'" + id + "\')", 		'html': "<img src=\"" + dbPath + "/cross.png\" />"	});	var el = new Element('li');	el.appendChild(doclink);	el.appendText(" ");	el.appendChild(removeLink);	list.appendChild(el);	list.style.display = "block";	$("linkedideasuggestions").innerHTML = "";	$("linkedideasuggestions").style.display = "none";	$("linkedideatext").value = "";	OverText.update();}function removeLinkedIdea(id) {	var thefield = $("ideaLink");	var ids = null;	thefield.value = editReplace(thefield.value, " ", "");	if (thefield.value.indexOf(",") == -1)		ids = [thefield.value];	else		ids = thefield.value.split(",");	for (var i=0; i<ids.length; i++){		if (ids[i] == id){			var bullets = $("linkedideaslist").getElements("li");			bullets[i].dispose();						ids.splice(i, 1);			thefield.value = ids.join(",")			break;		}	}	}function initCommentModeration(){	try {		var comments = $$("div.commentmoderation");		for (var i=0; i<comments.length; i++){			if (roles.isAdmin || roles.isIdeaSpaceAdmin){				var html = "";				if (comments[i].get("deleted") == null){					html += "<a class=\"button\" href=\"#commentsanc\"";					html += " onclick=\"this.blur();deleteComment('" + comments[i].get("commentid") + "')\">";					html += "<span>" + LANG_FORM_DELETECOMMENT + "</script></span></a>";					html += "<a class=\"button\" href=\"#commentsanc\"";					html += " onclick=\"this.blur();editComment(this, '" + comments[i].get("commentid") + "')\">";					html += "<span>" + LANG_FORM_EDITCOMMENT + "</script></span></a>";				}				comments[i].innerHTML = html;				if (html == "")					comments[i].style.display = "none";			}else if (comments[i].get("createdby") == username){				var html = "";				if (comments[i].get("deleted") == null && isInTimeFrame(comments[i].get("datecreated"))){					html += "<a class=\"button\" href=\"#commentsanc\"";					html += " onclick=\"this.blur();deleteComment('" + comments[i].get("commentid") + "')\">";					html += "<span>" + LANG_FORM_DELETECOMMENT + "</script></span></a>";					html += "<a class=\"button\" href=\"#commentsanc\"";					html += " onclick=\"this.blur();editComment(this, '" + comments[i].get("commentid") + "')\">";					html += "<span>" + LANG_FORM_EDITCOMMENT + "</script></span></a>";				}				comments[i].innerHTML = html;				if (html == "")					comments[i].style.display = "none";			}else{				comments[i].style.display = "none";			}		}	}catch(e){	}}function deleteComment(id){	if (confirm(LANG_FORM_CONFIRMCOMMENTDELETE)){		var url = dbPath + "/deleteComment";		new Request({			url: url, 			method: 'post',			noCache: true, 			onComplete: function (data){				if (data.indexOf("The comment was deleted") > -1)					window.location.reload();				else if(data.indexOf("The comment can not be deleted") > -1)					alert(LANG_FORM_CANTDELETECOMMENT);				else					alert(LANG_FORM_ERRORDELETINGCOMMENT + ": " + data);			}		}).send("id=" + id);	}}function editComment(link, id){	var thediv = null;	try{		thediv = link.getParent(".commentmoderation");	}catch(e){		//Deal with a bug in bloody IE6!		var thedivs = $("commentview").getElements(".commentmoderation");		for (var i=0; i<thedivs.length; i++){			if (thedivs[i].commentid == id){				thediv = thedivs[i];				break;			}		}	}	thediv.innerHTML = "<img src=\"" + dbPath + "/ajax-loader.gif\" />";	var url = dbPath + "/getCommentText?open&id=" + id;	new Request({		url: url, 		method: 'get',		noCache: true,  		onComplete: function (data){			data = data.substring(0, data.length - 1);			var html = "<textarea style=\"height: 200px; width: 90%;\" id=\"comment_" + id + "\"";			html += " name=\"comment_" + id + "\">" + data + "</textarea>";			html += "<a onclick=\"this.blur(); submitEditComment('" + id + "')\" ";			html += "href=\"#commentsanc\" class=\"button\"><span>" + LANG_FORM_SUBMITCOMMENT + "</span></a>";			thediv.innerHTML = html;		}	}).send();}function submitEditComment(id){	var url = dbPath + "/editComment";	new Request({		url: url, 		method: 'post',		noCache: true, 		onComplete: function (data){			if (data.indexOf("The comment was modified") > -1)				window.location.reload();			else				alert(LANG_FORM_ERROREDITINGCOMMENT + ": " + data);		}	}).send("id=" + id + "&comment=" + escape(formatComment($("comment_" + id).value)));}function isInTimeFrame(datestring){	var now = new Date();	now = "" + (now.valueOf() - 900000);	if (datestring > now)		return true;	else		return false;}
