// NetDocuments (c) 2009 Wil Craig
window.onload = function(){ 
	tgv = new Array();
	if (document.images){
  		pic1= new Image(100,25); pic1.src="images/star_small.png"; 
		pic2= new Image(100,25); pic2.src="images/star.gif";
		}
	bodyonload();
	}

// Default Variables

var xmlhttp;

// Index

function buzz(){get('http://community.netdocuments.com/buzz.php?email='+d('buzzInput').value+'&rand='+Math.random(9999),"d('ndbuzzword').innerHTML = ajax;fadein('ndbuzz');setTimeout(\"hide('ndbuzz')\",2000)");}

function suggest(){get('suggest.php?email='+d('suggestEmail').value+'&s='+d('suggestion').value+'&rand='+Math.random(9999),"d('suggestword').innerHTML = ajax;fadein('suggestbox');setTimeout(\"hide('suggestbox')\",2000)");}

function validate(e){ possible='INPUT SELECT TEXTAREA';formTags=e.getElementsByTagName('*');var fail='0';
	for(f=0;f<formTags.length;f++){if(possible.match(formTags[f].nodeName) && formTags[f].className=='req'){
				if(formTags[f].type=='text'){if(formTags[f].value==''){fail='1';break;}}
				if(formTags[f].type=='checkbox'){if(formTags[f].checked==''){fail='1';break;}}
			}}
		if(fail=='1'){alert('Please complete the form');return false;}else{return true;}
	}

// Basic Functions
function showHide(what)
{
	value = (document.getElementById(what).style.display == 'none') ? 'block' : 'none';
	document.getElementById(what).style.display = value;
	/*clearTimeout(timer[theDiv]);
	delete timer[theDiv];*/

}

function d(t)
	{
		return document.getElementById(t);
	}
function type(td)
	{
		if(typeof(td)=='string')
			{
				e = d(td);
			}
		else
			{
				e = td;
			}
		return e;
	}
function hide3(t)
	{
	document.getElementById("'"+t+"'").style.display='none';
	}
function hide(t)
	{
	e = type(t);
	e.style.display='none';
	}
function unhide(t)
	{
	e = type(t);
	e.style.display='';
	}
function hide2(r,u,v)
	{
	e = type(r);
	e.style.display='none';
	f = type(u);
	g = type(v);
	f.style.display='none';
	g.style.display='none';

	}
function unhide2(r,u,v)
	{
	e = type(r);
	e.style.display='';
	f = type(u);
	g = type(v);
	f.style.display='';
	g.style.display='';
	}

function unhide(t){e = type(t);e.style.display='';}

function on(t){e = type(t);addClass('on',e);}function off(t){e = type(t);removeClass('on',e);}


// Class Methods
function addClass(c,t)
	{
		 e = type(t);
		 e.className += ' '+c;
	}
function removeClass(c,t)
	{ 
		e = type(t);
	var cA = e.className.split(' ');
	var endC = new String();
	for(cN=0;cN<cA.length;cN++)
		{ 
			if(cA[cN]!=c)
			{
				endC += cA[cN]+' ';
			}
		}
	e.className = endC;
	}
function getByClass(theClass,theId,theTag)
{
	if(!theId)
	{
		theId = document;
	}
	else
	{
		theId = type(theId);
	}
	if(!theTag)
	{
		theTag='*';
	}
	var allElements = theId.getElementsByTagName(theTag);
	var allClass = new Array();
	var aC=0;
	for (aT=0;aT<allElements.length;aT++)
	{
		if(allElements[aT].className.match(theClass))
		{
			allClass[aC]=allElements[aT];
			aC++;
		}
	}
	return allClass;
}
function matchClass(e,c){
	ca = d(e).className.split(' ');for(cm=0;cm<ca.length;cm++){if(ca[cm].match(c)){cr=true;break;}cr=false;}return cr;}

// TabGroup
function tg(g,n){
	if(tgv[g])
		{
			var oldTab = d('t-'+g+'-'+tgv[g]);
			var oldPage = d('p-'+g+'-'+tgv[g]);
			removeClass('on',oldTab);removeClass('on',oldPage);
		}
	var newTab = d('t-'+g+'-'+n);
	var newPage = d('p-'+g+'-'+n);
	addClass('on',newTab);addClass('on',newPage);tgv[g] = n;}

function href(t){window.location.assign(t);}
function gif(t){d(t).innerHTML = '<img src="media/load.gif" style="margin:20px" />';}
function new_win(url,w,h,tool,loc,scroll,resize) {var p;
	p = "width="+w+",height="+h+",toolbar="+tool+",location="+loc+",scrollbars="+scroll+",resizable="+resize;window.open(url,'',p);}
function del(url){var d = confirm('Are you sure you want to delete this? \nThis cannot be undone.');if(d==true){href(url);}}

function findLinks(t){
		if(!t){e=document.body;}else{e = d(t);}
		hA = e.innerHTML.split(' ');
			for(n=0;n<hA.length;n++){
				if(hA[n].match('http://') && !hA[n].match('"http://') && !hA[n].match("'http://")){
					hA[n] = '<a class="c1 l1" href="'+hA[n]+'">'+hA[n]+'</a>';}
				
				if(hA[n].match('@') && hA[n].match('.')){
					hA[n] = '<a class="c1 l1" href="mailto:'+hA[n]+'">'+hA[n]+'</a>';}
				}
		document.body.innerHTML = hA.join(' ');
	}
	
// Forums
function iFrameHeight() {
	if(document.getElementById && !(document.all)) {
		h = document.getElementById('theFrame').contentDocument.body.scrollHeight;
		document.getElementById('theFrame').style.height = h+'px';}
	else if(document.all) {
		h = document.frames('theFrame').document.body.offsetHeight+20;
		document.all.theFrame.style.height = h;}}

// IdeaBank
function voteNum(num,multiplier,id)
	{
		var check = false;
		var votesInBank = document.getElementById("myVoteBank").innerHTML;
		var numvotes = num*multiplier;
		for(z=0;z<5;z++)
		{
			if(document.getElementById("s"+id+z).className == "votenum_cur")
				{
				var otherVote = document.getElementById("s"+id+z).innerHTML;
				break;
				}
		}
		if(votesInBank <= 0 && otherVote < numvotes)
		{
			var hiddenId = "alertText"+id;
			document.getElementById("alertText"+id).style.display = "block";
			document.getElementById("alertText"+id).innerHTML = "You have no more votes";
			var timeoutID = window.setTimeout("hide('"+hiddenId+"')",2500);
			check = true;
			if(check == true)
					{
					return;
					}
		}
		else if(otherVote < numvotes)
		{
			voteAdd = numvotes-otherVote;
			if(votesInBank - voteAdd < 0)
				{
				var hiddenId = "alertText"+id;
				document.getElementById("alertText"+id).innerHTML = "You do not have that many votes";
				document.getElementById("alertText"+id).style.display = "block";
				var timeoutID = window.setTimeout("hide('"+hiddenId+"')",2500);
				check = true;
				if(check == true)
					{
					return;
					}
				}
		}
		newid="votes"+id;
		var z=0;
		ajaxUpdate("idea_votenum.php?id="+id+"&numvotes="+numvotes,newid,numvotes);
		dualAjaxUpdate("votesInBank.php?votesInBank="+votesInBank+"&numvotes="+numvotes+"&curVote="+otherVote,"myVoteBank");
		var x=0;
		for(x=0;x<5;x++)
			{
			if(x==num)
				{
				document.getElementById("s"+id+x).className = "votenum_cur";
				}
			else
				{
				document.getElementById("s"+id+x).className = "votenum";
				}
			}
	}

//Ajax Functions
function dualAjaxUpdate(url,elementId)
	{
		xmlhttp2=ajaxXMLObject();
		if(xmlhttp2==null)
			{
			alert ("Your browser is not supported. This website supports IE 5+, Firefox, Chrome, Opera, and Safari.");
			return;
			}
			var newurl2 = url+"&unused="+Math.random();	
			xmlhttp2.onreadystatechange=function()
				{
				if(xmlhttp2.readyState==4)
					{
					if(xmlhttp2.status == 200 || xmlhttp2.status == 304)
						{
						var text2=xmlhttp2.responseText;
						document.getElementById(elementId).innerHTML = text2;
						}
					}
				}
			xmlhttp2.open("GET",newurl2,true);
			xmlhttp2.send(null);
	}

function ajaxUpdate(url,elementId,numvotes)
	{
		xmlhttp=ajaxXMLObject();
		if(xmlhttp==null)
			{
			alert ("Your browser is not supported. This website supports IE 5+, Firefox, Chrome, Opera, and Safari.");
			return;
			}
			var newurl = url+"&unused="+Math.random();	
			xmlhttp.onreadystatechange=function()
				{
				if(xmlhttp.readyState==4)
					{
					if(xmlhttp.status == 200 || xmlhttp.status == 304)
						{
						var text=xmlhttp.responseText;
						document.getElementById(elementId).innerHTML = text;
						}
					}			
				}
			xmlhttp.open("GET",newurl,true);
			xmlhttp.send(null);
			//eval(dothis);
	}			
function ajaxXMLObject()
	{
		if (window.XMLHttpRequest)
			{
			  // code for IE7+, Firefox, Chrome, Opera, Safari
			  return new XMLHttpRequest();
			}
		if (window.ActiveXObject)
			{
			  // code for IE6, IE5
			  return new ActiveXObject("Microsoft.XMLHTTP");
			}
		return null;
	}	
function putByClass(theClass,theContent)
	{
	allThings = getByClass(theClass);
	for(n=0;n<allThings.length;n++)
		{
		allThings[n].innerHTML = theContent;
		}
	}


// Fade In
/*function fadein(imageId)
	{
	image = document.getElementById(imageId);
	setOpacity(image, 0);
	image.style.visibility = "visible";
	init(imageId,0);
	}
function init(objId,opacity)
	{
	if(document.getElementById)
		{
		obj = document.getElementById(objId);
		if(opacity <= 100)
			{
			setOpacity(obj, opacity);
			opacity += 10;
			window.setTimeout("init('"+objId+"',"+opacity+")", 25);
			}
		}
	}
function setOpacity(obj, opacity)
	{
	opacity = (opacity == 100)?99.999:opacity;
	obj.style.filter = "alpha(opacity:"+opacity+")";
	obj.style.KHTMLOpacity = opacity/100;
	obj.style.MozOpacity = opacity/100;
	obj.style.opacity = opacity/100;
	}
*/