<!-- Idea by:  Nic Wolfe (Nic@TimelapseProductions.com) -->
<!-- Web URL:  http://fineline.xs.mw -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=200');");
}

// Used to setup the ajax for the email compose field
//
function emailinit()
    {
    // initialize the combobox widgets, and pass in the callback function
    var cb = new ComboBox("composeto", updateemailname);
    }


function visibilityToggletextbox(textbox,imgbox)
    {    
	var el=document.getElementById(textbox);
    var im=document.getElementById(imgbox);

   //el.style.display=(el.style.display == 'none')? 'none' : 'block';
    if (im.title=="add")  
        {
        im.src='/images/icons/delete.png';
        im.title='delete';
		el.style.display="block";
        }
    else
        {
        im.src='/images/icons/add.png';
        im.title='add';
		el.style.display="none";
        }
    }

function visibilityboardresponsepost(textbox)
	{
    var el=document.getElementById(textbox);
	if (el.style.display=="none")
		{
    	el.style.display="block";
		}
	else
		{
    	el.style.display="none";
		}
    }


function childrenvisibilityToggletextbox(textbox,imgbox)
    {    
	var el=document.getElementById(textbox);
    var im=document.getElementById(imgbox);

    if (im.title=="add")  
        {
        im.src='/images/levels/LCoordinator.gif';
        im.title='delete';
		el.style.display="block";
        }
    else
        {
        im.src='/images/levels/LCoordinator.gif';
        im.title='add';
		el.style.display="none";
        }
    }

//http://www.somacon.com/p355.php
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}

function reloadImage(image)
{
img = document.getElementById(image);
img.src = "pictures/"+ image + ".jpg";
}

function gethttpobject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

// Function called when changing the unmatched entries on the collaboration
// page.  Highlights the chosen unmatched for the user, his/her previous 
// partner choices and clears anything in the notification div 
// otherunmatchedinfo
function collabchoices(regcollabid)
	{
	for  (var i=0; i<document.collabpartner.mycollabs.length; i++)
		{
		var row = 'row' +i;
		var el=document.getElementById(row);
		if (document.collabpartner.mycollabs[i].checked)
			{
   			el.className='collab_selected';
			}
		else
			{
			el.className='blue';
			}
		}

	// ajax to highlight the potential matches for that option
    http=gethttpobject();
    http.open("GET", "/includes/js/collabsichose.php?regcollabid=" + regcollabid,true);
    http.send(null);
    http.onreadystatechange = handlecollabpartners;

	// ajax to highlight the potential matches for that option
    http2=gethttpobject();
    http2.open("GET", "/includes/js/collabsthatchoseme.php?regcollabid=" + regcollabid,true);
    http2.send(null);
    http2.onreadystatechange = handlecollabpotentialpartners;

	// blank the notification div
	document.getElementById('otherunmatchedinfo').innerHTML = '';


	}

function handlecollabpotentialpartners()
    {
    if (http2.readyState == 4)
        {
        if (http2.responseText.indexOf('invalid') == -1)
            {
            // Split the comma delimited response into an array
            results = http2.responseText.split(",");
            //var results = http2.responseText;
			//alert(http2.responseText);
			if (results['0'] >=1)
				{
				document.getElementById('wantstomatchme').innerHTML = '<br><font class=headersub>Collaboration Matches Made To Your Entry:</font><br><table>';	
				for  (var i=2; i<=results[0]; i=i+2)
					{
					var previousHTML = new String();
					previousHTML = document.getElementById('wantstomatchme').innerHTML;
					document.getElementById('wantstomatchme').innerHTML = previousHTML + results[i];
					//var x=i-1;
					//var check='cbox'+results[x];
					//var cl=document.getElementById(check);
					//cl.style.display='none';
					}

				var previousHTML = new String();
				previousHTML = document.getElementById('wantstomatchme').innerHTML;
				document.getElementById('wantstomatchme').innerHTML = previousHTML + '</table><input type=submit value="Choose a Match Partner">';	
				} // we have results
			else
				{
				document.getElementById('wantstomatchme').innerHTML = '';
				}
			
			}
		}
	}
function handlecollabpartners()
    {
    if (http.readyState == 4)
        {
        if (http.responseText.indexOf('invalid') == -1)
            {
            // Split the comma delimited response into an array
            //results = http.responseText.split(",");
            var results = http.responseText;
			for  (var i=0; i<document.collabpartner.you.length; i++)
				{
				var tosearch = ',' +document.collabpartner.you[i].value +',';
				var strsearch=results.search(tosearch);	
				var row = 'yourow' +i;
				var el=document.getElementById(row);
				if (strsearch !=-1)
					{
					document.collabpartner.you[i].checked=true;
   					el.className='collab_selected';
					}
				else
					{
					document.collabpartner.you[i].checked=false;
					el.className='blue';
					}
				}
					
            }
        }
    }

function test()
	{
	alert('testfunction');
	}

function getmoreevents(logid,boardid,badgeid) 
{
 id= 'nextevents.' + logid;
  document.getElementById(id).innerHTML = ' Fetching data...';
  req=new gethttpobject();
  if (req != undefined) 
	{
    req.onreadystatechange = function() {getmoreeventsdone(id);};
    req.open("GET", "/includes/js/getevents.php?logid=" + escape(logid) + "&boardid=" + escape(boardid) + "&badgeid="+escape(badgeid), true);
    req.send("");
  	}
return false;
}  

function getmoreeventsdone(id) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(id).innerHTML = req.responseText;
    } else {
      document.getElementById(id).innerHTML="Error:\n"+ req.status + "\n" +req.statusText;
    }
  }
}

function handleupdatenamephone() 
	{
  	if (http.readyState == 4) 
		{
		if (http.responseText.indexOf('invalid') == -1) 
			{
			// Split the comma delimited response into an array
			results = http.responseText.split(",");
			if (results[0])
				{
				document.getElementById('name').value = ltrim(results[0]);
				}
			if (results[1])
				{
				document.getElementById('phone').value = results[1];
				}
			}
		}
	}


function updatenamephone()
	{
	http=gethttpobject();
	email=document.getElementById("email").value;
	http.open("GET", "/includes/js/getnamephone.php?email=" + escape(email), true);
	http.onreadystatechange = handleupdatenamephone;
	http.send(null);
	}

	
function like(id,location)
	{
	http=gethttpobject();
	http.open("GET", "/includes/js/regcollabs.php?collabid=" + id+"&loc="+location,true);
	http.send(null);
	http.onreadystatechange = handlecollabupdate;
	}

function handlecollabupdate() 
	{
  	if (http.readyState == 4) 
		{
		if (http.responseText.indexOf('invalid') == -1) 
			{
			// Split the comma delimited response into an array
			results = http.responseText.split(",");
			if (results[0] == 1)
				{
				var previousHTML = new String();
				previousHTML = document.getElementById(results[1]).innerHTML;
				previousHTML = results[3] +'Help others partner with you. Give a bit more info about when you can do it, how you connect (dial in/out), and anything you have to offer as a partner.<br><form method=post><input type=text name=comments size=100 maxlength=100><input type=hidden name=regcollabid value='+results[2]+'><input type=hidden name=loc value=firstcomment><input type=submit value="Add Comments"></form>';
				document.getElementById(results[1]).innerHTML = previousHTML;
			
				} //results passed back
			}// we have a valid response text
		} //readystate =4
	} //handlecollabupdate


function updateverifiernotes(id)
	{
    comments = document.getElementById("verifiertextbox" +id).value;
	//alert(comments);
	http=gethttpobject();
	http.open("GET", "/includes/js/updateverifiernotes.php?id=" + id + "&comments=" + escape(comments),true);
	http.onreadystatechange = handleupdateverifiernotes;
	http.send(null);
	}


function handleupdateverifiernotes() 
	{
  	if (http.readyState == 4) 
		{
		if (http.responseText.indexOf('invalid') == -1) 
			{
			// Split the comma delimited response into an array
			results = http.responseText.split(",");
			if (results[0] == 1)
				{
				document.getElementById(results[1]).innerHTML = "Updated The Verifier Notes";
				} //results passed back
			}// we have a valid response text
		} //readystate =4
	} //handlecollabupdate


function addboardpost(boardid,boardowner)
	{
    comments = document.getElementById(boardid).value;
	http=gethttpobject();
	http.open("GET", "/includes/js/addboardpost.php?boardid=" + boardid + "&boardowner=" + boardowner + "&comments=" + escape(comments),true);
	http.onreadystatechange = handleaddboardpost;
	http.send(null);
	}

function handleaddboardpost()
    {
    if (http.readyState == 4)
        {
        if (http.responseText.indexOf('invalid') == -1)
            {
            // Split the comma delimited response into an array
            results = http.responseText.split(",");
            if (results[0] == 1)
                {
                var updatefield = "bottom" + results[1];
                var el = document.getElementById("bottom" + results[1]);
                document.getElementById(updatefield).innerHTML = results[2];
                } //results passed back
            }// we have a valid response text
        } //readystate =4
    } //handlecollabupdate



function updatecollabinterest(regid)
	{
    comments = document.getElementById(regid).value;
	//alert (comments);
	http=gethttpobject();
	http.open("GET", "/includes/js/updateregcomments.php?regid=" + regid + "&comments=" + escape(comments),true);
	http.onreadystatechange = handlecollabcommentupdate;
	http.send(null);
	}

function handlecollabcommentupdate() 
	{
  	if (http.readyState == 4) 
		{
		if (http.responseText.indexOf('invalid') == -1) 
			{
			// Split the comma delimited response into an array
			results = http.responseText.split(",");
			if (results[0] == 1)
				{
				var updatefield = "commenttextbox" + results[1];
				var el = document.getElementById("comment" + results[1]);
				document.getElementById(updatefield).innerHTML = results[2];
				el.style.display = 'none';
				} //results passed back
			}// we have a valid response text
		} //readystate =4
	} //handlecollabupdate

function updateemailname(value, comboBox) 
	{
	value = value.toLowerCase();
	http=gethttpobject();
	http.open("GET", "/includes/js/emailname.php?name=" + escape(value), true);
	http.onreadystatechange = handleupdateemailname;
	http.send(null);
	results = http.responseText.split(",");

	// could be replaced with "return items;", I'm synthesizing JS remoting
	setTimeout(function() {
		comboBox.setItems(results);
		}, 125);
	}

function handleupdateemailname() 
	{
  	if (http.readyState == 4) 
		{
		if (http.responseText.indexOf('invalid') == -1) 
			{
			// Split the comma delimited response into an array
			results = http.responseText.split(",");
			}
		}
	}


// Found at: 
// http://www.shawnolson.net/a/639/select-all-checkboxes-in-a-form-with-javascript.html
function checkUncheckAll(theElement) {
     var theForm = theElement.form, z = 0;
     for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
      theForm[z].checked = theElement.checked;
      }
     }
    }


function showeventtime(obj) {
	//create a locally scoped variable to hold the currently selected option
var curproject=obj.options[obj.selectedIndex].value

if (curproject!='Project: Participants sign up and CAPspace matches them to partners'){
document.getElementById('eventtimezone').style.display='inline'
document.getElementById('projecttimezone').style.display='none'

//otherwise hide 
}else{
document.getElementById('eventtimezone').style.display='none'
document.getElementById('projecttimezone').style.display='inline'
	}
	} 

function visibilitydeletecollabinterest(textbox,imgbox)
    {
    var el=document.getElementById(textbox);
    var im=document.getElementById(imgbox);

    if (im.title=="delete")
        {
        im.src='/images/icons/delete-rotate.png';
        im.title='keep';
        el.style.display="block";
        }
    else
        {
        im.src='/images/icons/delete.png';
        im.title='delete';
        el.style.display="none";
        }
    }
function visibilitydeleteboardpost(textbox,imgbox)
    {
    var el=document.getElementById(textbox);
    var im=document.getElementById(imgbox);

    if (im.title=="delete")
        {
        im.src='/images/icons/delete-rotate.png';
        im.title='keep';
        el.style.display="block";
        }
    else
        {
        im.src='/images/icons/delete.png';
        im.title='delete';
        el.style.display="none";
        }
    }

function visibilitycollabinterestcomments (commentbox)
	{
   var el=document.getElementById(commentbox);
    if (el.style.display=="none")
        {
        el.style.display="block";
        }
    else
        {
        el.style.display="none";
		}
	}

function getselectedradiobutton(radio)
	{
	for (var i=0; i< radio.length; i++)
		{
		if (radio[i].checked)
			{
			return radio[i].value
			}
		}
	}

function youcollabcheck(row,regcollabid)
	{
	var meradio = document.collabpartner.mycollabs;
	var mevalue = getselectedradiobutton(meradio);
	// if nothing was selected from the radio buttons
	// it is possible that it was the single hidden value
	// so we try.
	if (!mevalue)
		{
		mevalue = meradio.value;
		}
    var yourow = 'yourow' +row;
    var el=document.getElementById(yourow);

	//alert (yourow);
	var youvalue = document.collabpartner.you[row].value;

	if (document.collabpartner.you[row].checked==true)
		{
        el.className='collab_selected';
		var action='add';
        //document.getElementById('otherunmatchedinfo').innerHTML = 'hello world';
		}
	else
		{
        el.className='blue';
		var action='remove';
		}
	http=gethttpobject();
    http.open("GET", "/includes/js/updatecollabpartner.php?you=" + escape(youvalue) + "&me=" +escape(mevalue) + "&action=" + escape(action) + "&regcollabid=" +escape(regcollabid), true);
    http.send(null);
    http.onreadystatechange = handlecollabcheck;

	}

function handlecollabcheck()
    {
    if (http.readyState == 4)
        {
        if (http.responseText.indexOf('invalid') == -1)
            {
            // Split the comma delimited response into an array
            results = http.responseText.split(",");
			if (results[1] == 'add')
				{
				document.getElementById('otherunmatchedinfo').innerHTML = "A request to match for the collaboration has been emailed to  <b>" + results[2] +  "</b>.  If the match is accepted, an email will be sent confirming the details";
				}
			if (results[1] == 'remove')
				{
				document.getElementById('otherunmatchedinfo').innerHTML = "A previous request for match with <b>" + results[2] + "</b> has been removed.";
				}
            }
        }
    }

function participantregistertypes (choice)
	{
	switch (choice)
		{
		// Website
		case 0:
			var updatechoice = "People should register on your website or wiki. This option has no opportunity for the extra interested people to partner with each other.";
			break;
		//Email
		case 1:
			var updatechoice = "People must email you to register. This option has no opportunity for the extra interested people to partner with each other. ";
			break;
		//Exploding Collaboration
		case 2:
			var updatechoice = "<b>Recommended: </b>People can indicate that they are interested in the collaboration. You can select from the interested people to choose your partner. Any extra people who are interested can partner with each other. Then everyone is able to participate even beyond the partners that you need. ";
			break;
		}
		document.getElementById('collabpartnertype').innerHTML = updatechoice;
	
	}

// Updates a div with information based on the radio button chosen.
function collabregtypes (choice)
	{
	switch (choice)
		{
		//Open
		case 1:
			var updatechoice = "<b>Suggested:</b> An open collaboration is one actively looking for partners.  With our new exploding collaborations, not only can you find a partner, but others can connect with each other too!";
			break;
		//Filled
		case 0:
			var updatechoice = "If you have found a partner for your collaboration use filled.";
			break;
		//Past
		case -1:
			var updatechoice = "Use Past when the date of a collaboration has transpired";
			break;
		//Ideas
		case -2:
			var updatechoice = "Ideas are just like open collaborations, but are not posted on the CAPspace twitter feed.";
			break;
		}
		document.getElementById('collabregtypesinfo').innerHTML = updatechoice;
	
	}

function eventcoordinator (coordid,id)
	{
	//alert(id);
    http=gethttpobject();
	if (document.getElementById(coordid).checked==true)
		{
    	http.open("GET", "/includes/js/updateeventcoordinator.php?id=" + id +"&coorid="+coordid+"&checked=true",true);
		//alert ("Checked");
		}
	if (document.getElementById(coordid).checked==false)
		{
    	http.open("GET", "/includes/js/updateeventcoordinator.php?id=" + id +"&coorid="+coordid+"&checked=false",true);
		//alert ("Not Checked");
		}
    http.send(null);
    http.onreadystatechange = handleupdateeventcoordinator;
	}

function handleupdateeventcoordinator()
    {
    if (http.readyState == 4)
        {
        if (http.responseText.indexOf('invalid') == -1)
            {
            var results = http.responseText;
			document.getElementById('coordinatorselected').innerHTML = results;
            }
        }
    }
function statelimitation (state,id)
	{
	//alert(id);
    http=gethttpobject();
	if (document.getElementById(state).checked==true)
		{
    	http.open("GET", "/includes/js/updatestatesselected.php?id=" + id +"&state="+state+"&checked=true",true);
		//alert ("Checked");
		}
	if (document.getElementById(state).checked==false)
		{
    	http.open("GET", "/includes/js/updatestatesselected.php?id=" + id +"&state="+state+"&checked=false",true);
		//alert ("Not Checked");
		}
    http.send(null);
    http.onreadystatechange = handleupdatestate;
	}
function handleupdatestate()
    {
    if (http.readyState == 4)
        {
        if (http.responseText.indexOf('invalid') == -1)
            {
            var results = http.responseText;
			document.getElementById('stateselected').innerHTML = results;
            }
        }
    }
function eventsponsorgrid(id,coordinator,sponsor)
	{
	//alert(id);
    http=gethttpobject();
	if (document.getElementById(id).checked==true)
		{
    	http.open("GET", "/includes/js/updateeventsponsorgrid.php?id=" + id +"&coordinator="+escape(coordinator)+"&sponsor="+escape(sponsor)+"&checked=true",true);
		//alert ("Checked");
		}
	if (document.getElementById(id).checked==false)
		{
    	http.open("GET", "/includes/js/updateeventsponsorgrid.php?id=" + id +"&coordinator="+escape(coordinator)+"&sponsor="+escape(sponsor)+"&checked=false",true);
		//alert ("Not Checked");
		}
    http.send(null);
    http.onreadystatechange = handleupdateeventsponsor;
	}

function handleupdateeventsponsor()
	{
    if (http.readyState == 4)
        {
        if (http.responseText.indexOf('invalid') == -1)
            {
            var results = http.responseText;
            oldresults = document.getElementById('eventsponsorstatus').innerHTML;
            document.getElementById('eventsponsorstatus').innerHTML = oldresults+results;
            }
        }
    }


function countrylimitation (country,id)
	{
	//alert(id);
    http=gethttpobject();
	if (document.getElementById(country).checked==true)
		{
    	http.open("GET", "/includes/js/updatecountryselected.php?id=" + id +"&country="+country+"&checked=true",true);
		//alert ("Checked");
		}
	if (document.getElementById(country).checked==false)
		{
    	http.open("GET", "/includes/js/updatecountryselected.php?id=" + id +"&country="+country+"&checked=false",true);
		//alert ("Not Checked");
		}
    http.send(null);
    http.onreadystatechange = handleupdatecountry;
	}
function handleupdatecountry()
    {
    if (http.readyState == 4)
        {
        if (http.responseText.indexOf('invalid') == -1)
            {
            var results = http.responseText;
			document.getElementById('countryselected').innerHTML = results;
            }
        }
    }

function SelectAllEventTimes(times)
	{
	alert(times);
	}

function acceptdenycollaboration(me,you,reason)
	{
    http=gethttpobject();
    http.open("GET", "/includes/js/acceptdenycollaboration.php?me="+me+"&you="+you+"&reason="+reason, true);
    http.send(null);
    http.onreadystatechange = handleacceptdenycollaboration;
	}

function handleacceptdenycollaboration()
    {
    if (http.readyState == 4)
        {
        if (http.responseText.indexOf('invalid') == -1)
            {
            var results = http.responseText.split(",");
			alert ("Thank you");
			window.location.reload();
            }
        }
    }

function equipmentinfomonitor(id)
	{
	document.getElementById("equipmentactionstatus"+id).innerHTML = "<span class=admin_tools>View Equipment Page</span>"
	}
function equipmentinfodelete(id)
	{
	document.getElementById("equipmentactionstatus"+id).innerHTML = "<span class=admin_tools>Delete Equipment</span>"
	}
function equipmentinfoedit(id)
	{
	document.getElementById("equipmentactionstatus"+id).innerHTML = "<span class=admin_tools>Edit Equipment Details</span>"
	}
function equipmentinfochangeowner(id)
	{
	document.getElementById("equipmentactionstatus"+id).innerHTML = "<span class=admin_tools>Change Equipment Owner</span>"
	}

function equipmentinforeset(id)
	{
	document.getElementById("equipmentactionstatus"+id).innerHTML = "<br>"
	}

function visibilitytablecell(textbox)
    {
    var el=document.getElementById(textbox);
	var browser = navigator.appName;
	if (el.style.display=='table-row' || el.style.display=='block')
		{
   		el.style.display='none';
		}
	else
		{
		if (browser=='Netscape')
			{
		 	el.style.display='table-row';
			}
		else
			{
		 	el.style.display='block';
			}
		}
    }


function updatepersonalnotes(pid)
    {
	var textarea=pid+".textarea";
    comments = document.getElementById(textarea).value;
    http=gethttpobject();
    http.open("GET", "/includes/js/updatepersonalnotes.php?pid=" + pid + "&personalnotes=" + escape(comments),true);
    http.onreadystatechange = handlepersonalnotesupdate;
    http.send(null);
    }

function handlepersonalnotesupdate()
    {
    if (http.readyState == 4)
        {
        if (http.responseText.indexOf('invalid') == -1)
            {
            // Split the comma delimited response into an array
            results = http.responseText.split(",");
            if (results[0] == 1)
                {
                var updatefield = results[1] + ".notice";
				previousHTML = document.getElementById(updatefield).innerHTML;
                document.getElementById(updatefield).innerHTML =previousHTML + "<div class=user_message>Personal Notes Updated<div>";
                } //results passed back
            }// we have a valid response text
        } //readystate =4
    } //handlepersonalnotesupdate


function updatetestcall(pid)
	{
	var textarea=pid+".testcall";
    http=gethttpobject();
    http.open("GET", "/includes/js/updatetestcall.php?pid=" + pid,true);
    http.onreadystatechange = handleupdatetestcall;
    http.send(null);
    }
function handleupdatetestcall()
    {
    if (http.readyState == 4)
        {
        if (http.responseText.indexOf('invalid') == -1)
            {
            // Split the comma delimited response into an array
            results = http.responseText.split(",");
            if (results[0] == 1)
                {
                var updatetext = results[1] + ".testcall";
				var updatetext2 = results[1] + ".testcall2";
				if (results[2] == 0)
					{	
                	document.getElementById(updatetext).innerHTML ="Click to indicate test call made <img src=/images/icons/telephone.png>";
                	document.getElementById(updatetext2).innerHTML ="<b></b>";
					}
				if (results[2] == 1)
					{	
                	document.getElementById(updatetext).innerHTML ="Click to remove test call status <img src=/images/icons/telephone.png>";
                	document.getElementById(updatetext2).innerHTML ="<img src=/images/icons/telephone.png>";
					}
                } //results passed back
            }// we have a valid response text
        } //readystate =4
    } //handleupdatetestcall


function readyboardpost(id)
	{
	picture = "picture" + id;
	el=document.getElementById(picture);
	el.style.display='block';
	document.getElementById(id).select();
	}

