//<![CDATA[
<!--


function drawSignup(json, hikekey, objkey){

	var ishike = '1';
	chc_hikename = json.feed.entry[7].content.$t;
	chc_signedup = json.feed.entry[3].content.$t;
	chc_waiting = json.feed.entry[5].content.$t;
	chc_cost = json.feed.entry[9].content.$t;
	chc_max = json.feed.entry[1].content.$t;
	chc_leader = json.feed.entry[11].content.$t;
	chc_driver = json.feed.entry[13].content.$t;
	  
	if (Number(chc_signedup) + Number(chc_waiting) >= 17) {
		ishike = '0';
	} else if (Number(chc_signedup) >= Number(chc_max)) {
		var waitinglist = "<tr><td colspan='3' style='font-size:12px; font-family:verdana, helvetica, arial, sans-serif; text-align:right; font-weight:bold; color:red;'>WAITING LIST ONLY&nbsp;</td></tr>";
		chc_hikesignup = "(WAITING LIST) " + chc_hikename;
	} else {
		var waitinglist = "";
		chc_hikesignup = chc_hikename;
	}
	
	  
	if (ishike == '1') {
		//document.getElementById('hikesignup' + objkey).innerHTML=""
		document.getElementById(objkey).innerHTML=""
			+"<table  border=0 style='width:100%'>"
			+ waitinglist + "<tr><td>"
			+"<form id='signupform" + objkey + "' style='float:right' action='https://www.paypal.com/cgi-bin/webscr' method='post' onsubmit='return checkMembership(" + objkey + ");'>"
			+"<table border='0'><tr>"
			+"<td style='font-size:10px; font-family:verdana, helvetica, arial, sans-serif; font-weight:normal;'><input type='hidden' name='on1' value='UNI' />UNI (e.g. 'bmb2124'): <input type='text' name='os1' size='10' maxlength='10' />&nbsp;&nbsp;</td>"
			+"<td style='font-size:20px; font-family:verdana, helvetica, arial, sans-serif; font-weight:bold; vertical-align:middle; text-align:right;'>$" + chc_cost + "&nbsp;&nbsp;</td>"
			+"<td style='text-align:right'><input align='middle' type='image' src='http://www.columbia.edu/cu/hiking/paypal.gif' border='0' name='submit' alt='Make payment with PayPal' /></td>"
			+"</tr><tr><td>"
			+"<input type='hidden' name='amount' value='" + chc_cost + "' /> <input type='hidden' name='on2' value='Trip' /> <input type='hidden' name='os2' value='" + chc_hikesignup + "' /><input type='hidden' name='on0' value='TripID' /> <input type='hidden' name='os0' value='" + hikekey + "' /> <input type='hidden' name='cmd' value='_xclick' /> <input type='hidden' name='business' value='hiking-payment@columbia.edu' /> <input type='hidden' name='item_number' value='1' /> <input type='hidden' name='item_name' value='Hiking Trip' /> <input type='hidden' name='return' value='http://www.cuhc.net/schedule-and-signup/signup-confirmation/' /> <input type='hidden' name='cancel_return' value='http://www.cuhc.net/' /> <input type='hidden' name='currency_code' value='USD' /> <input type='hidden' name='bn' value='PP-BuyNowBF' /></form>"
			+"</td></tr><tr>"
			+"<td colspan='3' style='font-size:10px; font-family:verdana, helvetica, arial, sans-serif; text-align:right; font-weight:bold'>You must be a <a href='http://www.cuhc.net/membership/'>current member</a> to sign up for hikes.</td>"
			+"</tr><tr>"
			+"<td colspan='3' style='font-size:10px; font-family:verdana, helvetica, arial, sans-serif; text-align:right; font-weight:normal'>Current Signups: " + chc_signedup + "&nbsp;&nbsp;&nbsp;Max: "+ chc_max + "&nbsp;&nbsp;&nbsp;Wait List: "+ chc_waiting
			+"</td></tr></table>"
			+"<table style='width:100%'><tr><td style='text-align:right' id='membership" + objkey + "'></td></tr></table>";//IE is fucking stupid and won't repaint the screen if I add this as part of the prior table. IE sucks rocks.
	} else {
		//document.getElementById('hikesignup' + objkey).innerHTML="<table style='float:right'><tr><td>Signup for this trip is not available.</td></tr></table>";
		document.getElementById('cmQYdT').innerHTML="<table style='float:right'><tr><td>Signup for this trip is not available.</td></tr></table>";
	}
}


function getHikeData(obj) {

//hikekey = obj.parentNode.id;
hikekey = obj;
objkey = hikekey.charCodeAt(hikekey.length-1) 
	+ hikekey.charCodeAt(hikekey.length - 2)
	+ hikekey.charCodeAt(hikekey.length - 3)
	+ hikekey.charCodeAt(hikekey.length - 4)
	+ hikekey.charCodeAt(hikekey.length - 5)
	+ hikekey.charCodeAt(hikekey.length - 6);
	
objkey = hikekey.charAt(hikekey.length-1) 
	+ hikekey.charAt(hikekey.length - 2)
	+ hikekey.charAt(hikekey.length - 3)
	+ hikekey.charAt(hikekey.length - 4)
	+ hikekey.charAt(hikekey.length - 5)
	+ hikekey.charAt(hikekey.length - 6);
	
  //obj.parentNode.id = "hikesignup" + objkey;
  
  var script = document.createElement('script');

  script.setAttribute('id', 'hikeSignup' + objkey + 'Script');
  script.setAttribute('type', 'text/javascript');
  script.text = "function drawSignup" + objkey + "(json){drawSignup(json,'" + hikekey+ "','" + objkey + "');}";
  document.documentElement.firstChild.appendChild(script);
  	
  // Retrieve the JSON feed.
  var script = document.createElement('script');

  script.setAttribute('src', 'http://spreadsheets.google.com/feeds/cells/'
                         + hikekey
                         + '/od4/public/values' +
                        '?alt=json-in-script&callback=drawSignup' + objkey);

  script.setAttribute('id', 'jsonScript');
  script.setAttribute('type', 'text/javascript');
  
  document.documentElement.firstChild.appendChild(script);
  chc_membershipOk = false;
}

function checkMembership(objkey){
	if (chc_membershipOk == true) return true;
	var uni = document.getElementById('hikesignup' + objkey).getElementsByTagName('input')[1].value;
	var messageHtml = '';
	if (uni == "") {
		messageHtml = "<span style='color:red;'>Please enter your UNI to sign up for a hike!</span>";
	} else {
		messageHtml = "<img align=right style='float:right' src='http://www.google.com/ig/images/spinner.gif'>Checking membership status&nbsp;&nbsp;";
		var script = document.createElement('script');
		script.setAttribute('id', 'membership' + objkey + 'Script');
		script.setAttribute('type', 'text/javascript');
		script.text = "function checkMembership" + objkey + "(json){checkMembership2(json,'" + uni + "'," + objkey + ");}";
  		document.documentElement.firstChild.appendChild(script);
  		
  		// Retrieve the JSON feed.
		var script = document.createElement('script');
		
		script.setAttribute('src', 'http://spreadsheets.google.com/feeds/cells'
		                         + '/pmIl-glJJLymtLombYO81GA'
		                         + '/od6/public/values' +
		                        '?alt=json-in-script&callback=checkMembership' + objkey);
		
		script.setAttribute('id', 'jsonScript');
		script.setAttribute('type', 'text/javascript');
  		document.documentElement.firstChild.appendChild(script);
	}
	setSignupMessage(objkey, messageHtml);
	return false;
}

function setSignupMessage(objkey, messageHtml){
	var messageTd = document.getElementById('membership' + objkey);
	messageTd.innerHTML = messageHtml;

}

function checkMembership2(json, uni, objkey){
	if(isMember(json, uni) == true){
		chc_membershipOk = true;
		messageHtml = "<span style='color:green;'>Membership found for '" + uni + "'.<br>Transferring to PayPal.</span>";
		document.getElementById('signupform' + objkey).submit();
	} else {
		messageHtml = "<span style='color:red;'>Membership not found for '" + uni + "'.</span><br>If you think that you have a current club membership,<br>please contact us and we'll figure out what's going on.";
		setSignupMessage(objkey, messageHtml);
	}
}

function isMember(json, uni){
          for (var i=0; i < json.feed.entry.length; i++) {
	    var entry = json.feed.entry[i];
	    if (entry.content.$t == uni) return true;
	  }
	  return false;
}
 
//-->
//]]>


