function initView(){	try {		$('query').value = LANG_GEN_SEARCH;		$('query').onkeypress = handleSearchReturn;		checkPromoteLinks();		if (window.location.href.indexOf("searchview") == -1 && window.location.href.indexOf("profile?openform") == -1)			initViewNav(5, 20, "viewnav1", "viewnav2");		CheckNoDocuments();		if ($("tagcloud").style.display == "block")			initTagCloud();		initWarnings();	}catch (e){}}var req;var which;var id;var TargetDiv;var currentUNID;  function checkuser(id,target_div) {	currentUNID = id;	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{		if (myvotes[id]){			//do nothing		}else{			TargetDiv = document.getElementById(target_div.id);			var url = dbPath + "/promote?openagent&" + id;			new Ajax(url, {					method: 'get',			          onComplete: processResponse		          }).request();		}	}}function demote(unid){	currentUNID = 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{		if (myvotes[unid]){			//do nothing		}else{			var url = dbPath + "/demote?openagent&" + unid;			new Ajax(url, {					method: 'get',			          onComplete: processResponse    		      }).request();		}	}}function meh(unid){	currentUNID = 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{		if (myvotes[unid]){			//do nothing		}else{			var url = dbPath + "/meh?openagent&" + unid;			new Ajax(url, {					method: 'get',			          onComplete: processResponse    		      }).request();		}	}}function processResponse(originalRequest){	var data = editReplace(originalRequest, "\n", "");	if (data == ""){		doWarning(LANG_FORM_ALREADYVOTED);	}else if (data != "0"){		pos = data.indexOf(" ")		len = data.length;		count = Left(data, pos);		id = Right(data, len - (pos+1));		id = Right(id,32);		document.getElementById(id).innerHTML = count;				doWarningFade(LANG_VIEW_THANKS);				try {			var containers = $$('#view .div_votes_container');			for (var i=0; i<containers.length; i++){				var divs = containers[i].getElementsByTagName("div");				if (divs[1].id == id){					divs[0].innerHTML = "";					divs[0].onclick = "void(0);"					divs[0].href = "javascript:void(0);"					divs[0].style.cursor = "default";					divs[2].innerHTML = "";					divs[2].onclick = "void(0);"					divs[2].href = "javascript:void(0);"					divs[2].style.cursor = "default";					divs[3].innerHTML = "";					divs[3].onclick = "void(0);"					divs[3].href = "javascript:void(0);"					divs[3].style.cursor = "default";					break;				}			}		}catch (e){			//Ignore this, it's a bonus feature anyway!		}		if (window.location.href.toLowerCase().indexOf("stilltovoteon") > -1)			refreshIdeas();	}       }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;         }    }}function editReplace(strTest, strFrom, strTo){	var re = new RegExp(strFrom, "gim");	if ( ! re.exec(strTest) ){		return strTest;	}	return strTest.replace(re,strTo);}/*VIEW NAVIGATIONOriginal code taken from http://quintessens.wordpress.com/2007/03/29/bobs-ultimate-view-navigator-categorized-view/and then adapated to Idea Jam requirements.*/// initViewNav function, loaded at onLoad event of form/************************************************/function initViewNav(range, cache, div1, div2) {	navRange = range;	navCache = cache;	navDiv1 = div1;	navDiv2 = div2;	startDoc = queryString('start');	startDoc = (startDoc == "") ? 1 : parseInt(startDoc);	docsPerPage = queryString('count');	docsPerPage = (docsPerPage == "") ? 20 : parseInt(docsPerPage);	waitForDocCount()}// QueryString function/****************************************************/function queryString(key){	var page = new PageQuery(window.location.search);	return unescape(page.getValue(key.toLowerCase()));}function PageQuery(q) {	try {		if(q.length > 1)			this.q = q.substring(1, q.length);		else			this.q = null;		this.keyValuePairs = new Array();		if(q) {			for(var i=0; i < this.q.split("&").length; i++) {				this.keyValuePairs[i] = this.q.split("&")[i].toLowerCase();			}		}		this.getKeyValuePairs = function() { return this.keyValuePairs; }		this.getValue = function(s) {			for(var j=0; j < this.keyValuePairs.length; j++) {				if(this.keyValuePairs[j].split("=")[0] == s)					return this.keyValuePairs[j].split("=")[1];			}			return "";		}		this.getParameters = function() {			var a = new Array(this.getLength());			for(var j=0; j < this.keyValuePairs.length; j++) {				a[j] = this.keyValuePairs[j].split("=")[0];			}			return a;		}		this.getLength = function() { return this.keyValuePairs.length; }	}catch (e){}}function getExpiryDate(minutes){	var UTCstring;	Today = new Date();	nomilli = Date.parse(Today);	Today.setTime(nomilli + (minutes * 0));	UTCstring = Today.toUTCString();	return UTCstring;}function setCookie(name, value, duration){	cookiestring = name + "=" + escape(value) + "; EXPIRES=" + getExpiryDate(duration);	document.cookie = cookiestring;}function getCookie(cookiename) {	var cookiestring = "" + document.cookie;	var index1 = cookiestring.indexOf(cookiename);	if (index1 == -1 || cookiename == "") return "";		var index2 = cookiestring.indexOf(';', index1);	if (index2 == -1) index2 = cookiestring.length;		return unescape(cookiestring.substring(index1 + cookiename.length + 1, index2));}var startDoc = 0;var docsPerPage = 0;var totalPages = 0;var navRange = 0;var navCache = 0;var navDiv1 = "";var navDiv2 = "";var checkCookie = false;var totalDocs = "";function waitForDocCount() {	if (checkCookie) {		totalDocs = getCookie('totaldocs');		checkCookie = false;	}	if (totalDocs == "") {		getDocCount();	} else {	}}function getDocCount () {	var xmlHttp = getXMLHTTP();	var strURL = dbPath + "/" + viewAlias + "?ReadViewEntries&count=1";	if (Categories != "")		strURL += "&RestrictToCategory="+ Categories;		xmlHttp.open("GET", strURL );		xmlHttp.onreadystatechange = function() {			if (xmlHttp.readyState == 4 && xmlHttp.responseText) {				var resp = xmlHttp.responseText;				var countTag = resp.toLowerCase().indexOf('toplevelentries');				if (countTag > 0) {					resp = resp.substr(resp.indexOf('"', countTag) + 1);					totalDocs = resp.substring(0, resp.indexOf('"'));					setCookie('totaldocs', totalDocs, navCache)				}else{					setCookie('totaldocs', 0, navCache)				}				drawViewNav();			}		};	xmlHttp.send(null);}function getXMLHTTP() {	var xmlHttp = null	try {		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")	} catch(e) {		try {			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")		} catch(oc) {			xmlHttp = null		}	}	if(!xmlHttp && typeof XMLHttpRequest != "undefined") {		xmlHttp = new XMLHttpRequest()	}	return xmlHttp}function drawViewNav() {	try {		partialPages = totalDocs / docsPerPage;		extraPage = (partialPages == Math.floor(partialPages)) ? 0 : 1;		totalPages = Math.floor(partialPages) + extraPage;		if (totalPages == 1)			return;		curPage = Math.floor(startDoc / docsPerPage) + 1		startLink = (curPage < (navRange + 1)) ? 1 : curPage - navRange;		endLink = ((curPage + navRange) > totalPages) ? totalPages : curPage + navRange;		navHTML = "<div class='nav' align='left'><table class='navtable' cellpadding='0\u2032 cellspacing='0\u2032><tr>";		if (startLink > 1) {			navHTML = navHTML + buildLink(1, LANG_VIEW_FIRST);			navHTML = navHTML + buildLink(curPage - (navRange + 1), "<<");		} 		if (curPage > 1) navHTML = navHTML + buildLink(curPage - 1, "<");		for (i = startLink; i <= endLink; i++) {			if (i == curPage) {				navHTML = navHTML + "<td class='navtablecur'>" + i + "</td>"			} else {				navHTML = navHTML + buildLink(i, i);			}		} 		if (curPage < totalPages) navHTML = navHTML + buildLink(curPage + 1, ">");		if (endLink < totalPages) {			navHTML = navHTML + buildLink(curPage + (navRange + 1), ">>");			navHTML = navHTML + buildLink(totalPages, LANG_VIEW_LAST);		}		navHTML = navHTML + "</td>" 		navHTML = navHTML + "<td class='navpagecount'>" + LANG_VIEW_PAGE + " ";		navHTML = navHTML + curPage ;		navHTML = navHTML + " " + LANG_VIEW_OF + " " + totalPages + "</td>";  		navHTML = navHTML + "</tr></table></div>";		document.getElementById(navDiv1).innerHTML = navHTML;		if (typeof navDiv2 != "undefined") document.getElementById(navDiv2).innerHTML = navHTML;		document.getElementById('div_view').style.display = 'block';	}catch (e){}}function buildLink(pageNum, text) {	startLinkDoc = (((pageNum - 1) * docsPerPage) + 1);	endDoc = (pageNum == totalPages) ? totalDocs : startLinkDoc + docsPerPage  // Check for last page when creating tooltip range	linkHTML = "<td class='navtablelink' onmouseover=\"this.className='navtablelink_on'\" onmouseout=\"this.className='navtablelink'\" "	linkHTML = linkHTML + "title='Page " + pageNum + " : " + startLinkDoc + " through " + endDoc + "' ";	if (Categories == "")		linkHTML = linkHTML + "onclick=\"document.location.href='" + dbPath + "/" + viewAlias + "?OpenView&Start=" + startLinkDoc + "&Count=" + docsPerPage + "'\">" + text + "</td>";	else		linkHTML = linkHTML + "onclick=\"document.location.href='" + dbPath + "/" + viewAlias + "?OpenView&restricttocategory=" + Categories + "&Start=" + startLinkDoc + "&Count=" + docsPerPage + "'\">" + text + "</td>";	return linkHTML;}function getPage(event, field) {	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;	if (keyCode == 13) {		newPage = field.value;		if (newPage > totalPages || newPage < 1) {			field.select();			return false;		}		if (Categories == "")			document.location.href = dbPath + viewAlias + "?OpenView&Start=" + (((newPage - 1) * docsPerPage) + 1) + "&count=" + docsPerPage		else			document.location.href = dbPath + viewAlias + "?OpenView&restricttocategory=" + Categories + "&Start=" + (((newPage - 1) * docsPerPage) + 1) + "&count=" + docsPerPage	}}function CheckNoDocuments() { // function to replace the 'No documents found' message	var thetable = $("ideatable");	var rows = thetable.getElementsByTagName("tr");	if (rows.length == 0){		var url = window.location.href.toLowerCase();		if (url.indexOf("complete") > 1)			document.getElementById("view").innerHTML = "<span style=margin-left:10px;>" + LANG_VIEW_NODOCSCOMPLETE + "</span></h2>"		else if (url.indexOf("withdrawn") > 1)			document.getElementById("view").innerHTML = "<span style=margin-left:10px;>" + LANG_VIEW_NODOCSWITHDRAWN + "</span></h2>"		else if (url.indexOf("rejected") > 1)			document.getElementById("view").innerHTML = "<span style=margin-left:10px;>" + LANG_VIEW_NODOCSREJECTED + "</span></h2>"		else if (url.indexOf("comments") > 1)			document.getElementById("view").innerHTML = "<span style=margin-left:10px;>" + LANG_VIEW_NODOCSSPACE + "</span></h2>"		else if (url.indexOf("profile?openform") > 1)			document.getElementById("view").innerHTML = "<span style=margin-left:10px;>" + LANG_VIEW_NODOCSPROFILE + "</span></h2>"		else			document.getElementById("view").innerHTML = "<span style=margin-left:10px;>" + LANG_VIEW_NODOCS + "</a></span></h2>"	} // end if} // end functionfunction checkPromoteLinks(){	try {		var promotelinks = $$('#view .div_votes_container');		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];				var mehdiv = votesdiv[3];				if (myvotes[unid]){					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";					mehdiv.innerHTML = "";					mehdiv.onclick = "void(0);"					mehdiv.href = "javascript:void(0);"					mehdiv.style.cursor = "default";				}else{					promotediv.innerHTML = LANG_GEN_PROMOTE;					demotediv.innerHTML = LANG_GEN_DEMOTE;					mehdiv.innerHTML = "<br />" + LANG_GEN_NOOPINION;				}			}		}	}catch (e){}}function reloadPage(){	window.location.reload();}function loadMyIdeas(){	window.location.href = $("myideaslink").href;}//*************************var txt, log, fx;function initWarnings(){	try {		log = $('warningmessage');		fx = new Fx.Styles(log, {			duration: 1500,			wait: false,			transition: Fx.Transitions.Quad.easeIn		});	}catch (e){}} 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";	fx.set({		'opacity': 1	});	}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 hideWarning(){	fx.set({		'opacity': 0	});}function getOffset(){	if( window.innerHeight && window.scrollMaxY ) {		pageWidth = window.innerWidth + window.scrollMaxX;		pageHeight = window.innerHeight + window.scrollMaxY;	}else if( document.body.scrollHeight > document.body.offsetHeight ){		pageWidth = document.body.scrollWidth;		pageHeight = document.body.scrollHeight;	}else{		pageWidth = document.body.offsetWidth + document.body.offsetLeft; pageHeight = document.body.offsetHeight + document.body.offsetTop;	}}var tags = new Array();function initTagCloud(){	try {		var url = dbPath + "/IdeasByTagAJAX?openview&collapseview&count=1000";		new Ajax(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){}		          	}	          }).request();	}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 + "\">" + tag.toLowerCase() + "</a>  ";	}}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 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;}