// Subscriber Mail Code

function validEmail(email) {

	invalidChars = " /:,;"

	if (email == "") {
		return false
	}
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			return false
		}
	}
	atPos = email.indexOf("@",1)
	if (atPos == -1) {
		return false
	}
	if (email.indexOf("@",atPos+1) > -1) {
		return false
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {
		return false
	}
	if (periodPos+3 > email.length)	{
		return false
	}
	return true
}

// Subscriber Mail Code

function submitIt(subsForm) {
	if (!validEmail(document.subsForm.email.value))
		{
			alert("Invalid email address")
			document.subsForm.email.focus()
			document.subsForm.email.select()
			return false
		}
	
	
	var pref = "";
	var reqfields = new Array();
	
		for(i=0; i < reqfields.length;i++)
			{
				tempfield = "document.subsForm."+pref+reqfields[i]+".value";
				tempid = "document.subsForm."+pref+reqfields[i]+".id";
				tempval = eval(tempfield);
				tempid = eval(tempid);
				
				if(tempval=="")
					{
						alert("Please provide a "+tempid+".");
						return false;
					}
		}

	return true
}

// When the page is ready
$(document).ready(function(){
	// Making sure that there are at least 10 appointments listed
	if ($('#appointments #helpdesk_sidebar_list li').size() > 10) {

		// insert a <ul> after the 10th appointment and hide it
		var $xwrapper = $('<ul id="more"></ul>').insertAfter('#appointments #helpdesk_sidebar_list').hide();

		// append all list items following the 10th list item
		$('#appointments #helpdesk_sidebar_list li:gt(10)').appendTo($xwrapper);
		
		// insert 'More Appointments' link under both lists
		var $more = $('<p class="more"><a href="/helpdesk/helpdesk_appt">View More Appointments &raquo;</a></p>').insertAfter('#more');

		// Toggles the newly made and hidden ul up and down
		$('.more a').click(function(){

			// Slowly expand/collapse
			$xwrapper.slideToggle('slow');

			// Fades out the 'View More' link
			//$('.more').hide("fast");

			// Disables the default HTML behavior of the <a> element
			return false;
		});
		
		// Toggles the text of the 'View More' link
		$('.more a').toggle(function(){
			$(this).text("View Less Appointments »");
		},function(){
			$(this).text("View More Appointments »");
		});
	}
});