// JavaScript Document

var theTimer2, theTimer, scrollTimer, contentHeight, scrollStop, currentMenu;

// AJAX INIT STUFF -- START
var xmlhttp=null;

try
{
	xmlhttp = new XMLHttpRequest();
}
catch (error)
{
	try
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (error)
	{
		xmlhttp = null;
	}
}
//  END

function echeck(str){
 var filter=/^.+@.+\..{2,4}$/

 if (filter.test(str))
    result=true
 else {
    result=false
	}
 return (result) }

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function clearInput(input, defaultValue){ //alert(input.value);
	input.style.color = 'black';
	input.style.fontStyle = 'normal';
	input.style.fontWeight = 'normal';
	if(input.value == defaultValue){
		input.value = '';
	}
}

function resetInput(input, defaultValue){ //alert(input.value);
	if(input.value == ''){
		input.value = defaultValue;
		input.style.color = '#999';
		input.style.fontStyle = 'italic';
	}
}

function checkForm(){
	var passedCheck = true;
	var name = document.getElementById('name').value;
	var email = document.getElementById('email').value;
	
	name = jQuery.trim(name);
	email = jQuery.trim(email);
	
	if(name == '' || name == 'Name'){
		document.getElementById('name').style.color = 'red';
		document.getElementById('name').style.fontWeight = 'bold';
		passedCheck = false;
	}else{
		document.getElementById('name').style.color = '#999';
		document.getElementById('name').style.fontWeight = 'normal';
	}
	
	if(email == '' || email == 'Email Address'){
		document.getElementById('email').style.color = 'red';
		document.getElementById('email').style.fontWeight = 'bold';
		passedCheck = false;
	}else{
		document.getElementById('email').style.color = '#999';
		document.getElementById('email').style.fontWeight = 'normal';
	}
	
	return passedCheck; }

function sendform(){
	var formvars = $("#mlform").serialize();
	
	if(checkForm()){
		xmlhttp.open("GET", "/ajaxHandler.php?action=mailinglist&" + formvars + "&time=" + new  Date().getTime());
		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
				var response = xmlhttp.responseText; //alert(response);
				document.getElementById('mlform').innerHTML = '<p style="text-align:center"><br /><br /><em><strong>Thank you for joining our mailing list.</strong></em><br><br><br><br>&nbsp;</p>';
			}
		}
		//setTimeout("contactForm('up')",2500);
		xmlhttp.send(null);
	}
	
	return false; }

function showCD(){
	$('a.2009-cd').click( function (){
		$('#musicplayer').css('display','block');
		$('div.2008-cd').fadeOut('medium', function (){
			$('div.2009-cd').fadeIn('medium');
		});
	});
	
	$('a.2008-cd').click( function (){
		$('#musicplayer').css('display','block');	
		$('div.2009-cd').fadeOut('medium', function (){
			$('div.2008-cd').fadeIn('medium');
		});
	});
}

var player = null;
function playerReady(thePlayer) {
	player = window.document[thePlayer.id];
}

function play(file){
	player.sendEvent('LOAD','/CDs/'+file);
	player.sendEvent("PLAY");
}

function menu(){
	$('ul.navigation > li > a').click( function(){ //alert();
		var linkText = $(this).text();
		$('ul.navigation > li > ul').slideUp('medium');
		$(this).parent(0).find('ul').slideDown('medium');
		
		currentSubMenu = $(this);
		if(linkText != 'Home' && linkText != 'Contact Us') return false;
	});
}

function howPaying(){
	$('#additionalConcertTicket').click( function() {
		var isChecked = false;
		var value = $('#howPaying').val();
		
		if(document.getElementById('additionalConcertTicket').checked){
			$('#totalCost').html('325');
			isChecked = true;
		}else{
			$('#totalCost').html('275');
		}
		
		if(value == 'paypal'){
			$('div.hide').css('display','none');
			if(isChecked){
				$('#usePaypal2').css('display','block');
			}else{
				$('#usePaypal').css('display','block');
			}
		}
	});
	
	$('#howPaying').change( function() {
		$('div.hide').css('display','none');
		var value = $('#howPaying').val(); //alert(value);
		if(value == 'check'){
			$('#byCheck').css('display','block');
		}else if(value == 'paypal' && document.getElementById('additionalConcertTicket').checked){
			$('#usePaypal2').css('display','block');
		}else if(value == 'paypal'){
			$('#usePaypal').css('display','block');
		}
	});
}

function howPaying2(){
	
	$('#howPaying2').change( function() {
		$('div.hide').css('display','none');
		var value = $('#howPaying2').val(); //alert(value);
		
		if(value == 'check'){
			$('#byCheck').css('display','block');
		}else if(value == 'paypal'){
			$('#usePaypal').css('display','block');
		}
	});
}

function checkCondForm(){
	var isGood = true;
	$('.req').each( function (){
		//alert($(this).attr('name'));
		var value = trim($(this).val());
		if(value == ''){
			$(this).parent(0).css({'color':'red','font-style':'italic'});
			isGood = false;
		}else{
			$(this).parent(0).css({'color':'black','font-style':'normal'});
		}
		if($(this).attr('name') == 'email' && !echeck(value)){
			$(this).parent(0).css({'color':'red','font-style':'italic'});
			isGood = false;
		}
	})
	
	if(!isGood){
		alert('Please fix RED errors above');
	}else{
		sendConductorsForm('paypal');
	}
	
	return isGood; //isGood;
}

function sendConductorsForm(formtype){
	var formvars = $("#genform").serialize(); //alert(formvars);
	var registrationID = document.getElementById('registrationID').value;
	
	xmlhttp.open("GET", "/ajaxHandler.php?action=sendConductorsForm&formtype=" + formtype + "&" + formvars + "&time=" + new  Date().getTime());
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			var response = xmlhttp.responseText; //alert(response);
			if(formtype == 'check') document.getElementById('printframe').innerHTML = '<iframe src="/printform.php?&form=summit&registrationID=' + registrationID + '" width="1" height="1" style="visibility:hidden"></iframe>';
		}
	}
	//setTimeout("contactForm('up')",2500);
	xmlhttp.send(null);
	
	return false; }

function printSummit(registrationID){
	var isGood = true;
	$('.req').each( function (){
		//alert($(this).attr('name'));
		var value = trim($(this).val());
		if(value == ''){
			$(this).parent(0).css({'color':'red','font-style':'italic'});
			isGood = false;
		}else{
			$(this).parent(0).css({'color':'black','font-style':'normal'});
		}
		if($(this).attr('name') == 'email' && !echeck(value)){
			$(this).parent(0).css({'color':'red','font-style':'italic'});
			isGood = false;
		}
	})
	
	if(!isGood){
		alert('Please fix RED errors above');
	}else{
		var tempfile = '';
		sendConductorsForm('check');
	}
}

function checkWalkForm(){
	var isGood = true;
	$('#walkform input.req').each( function (){
		//alert($(this).attr('name'));
		var value = trim($(this).val());
		if(value == ''){
			$(this).parent(0).css({'color':'red','font-style':'italic'});
			isGood = false;
		}else{
			$(this).parent(0).css({'color':'black','font-style':'normal'});
		}
		if($(this).attr('name') == 'email' && !echeck(value)){
			$(this).parent(0).css({'color':'red','font-style':'italic'});
			isGood = false;
		}
	})
	
	if(!isGood){
		alert('Please fix RED errors above');
	}else{
		sendWalkForm();
	}
	
	return isGood; //isGood;
}

function sendWalkForm(formtype){
	var formvars = $("#walkform").serialize(); //alert(formvars);
	var registrationID = document.getElementById('registrationID').value;
	
	xmlhttp.open("GET", "/ajaxHandler.php?action=sendWalkForm&formtype=" + formtype + "&" + formvars + "&time=" + new  Date().getTime());
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			var response = xmlhttp.responseText; //alert(response);
		}
	}
	//setTimeout("contactForm('up')",2500);
	xmlhttp.send(null);
	
	return false; }

function checkTeamForm(){
	var isGood = true;
	var teamGood = true;
	
	$('#teamform input.req').each( function (){
		//alert($(this).attr('name'));
		var value = trim($(this).val());
		if(value == ''){
			$(this).parent(0).css({'color':'red','font-style':'italic'});
			isGood = false;
		}else{
			$(this).parent(0).css({'color':'black','font-style':'normal'});
		}
		if($(this).attr('name') == 'email' && !echeck(value)){
			$(this).parent(0).css({'color':'red','font-style':'italic'});
			isGood = false;
		}
	})
	
//	$('#teamform input.team').each( function (){
//		var value = trim($(this).val());
//		if(value == '') teamGood = false; 
//	})
	
	if(!teamGood){
		isGood = false;
		$('#teamnum').css({'color':'red','font-style':'italic'});
	}else{
		$('#teamnum').css({'color':'black','font-style':'normal'});
	}
	
	if(!isGood){
		alert('Please fix RED errors above');
	}else{
		sendTeamForm('paypal');
	}
	
	return isGood; //isGood;
}

function sendTeamForm(formtype){
	var formvars = $("#teamform").serialize(); //alert(formvars);
	var registrationID = document.getElementById('registrationID').value;
	
	xmlhttp.open("GET", "/ajaxHandler.php?action=sendTeamForm&formtype=" + formtype + "&" + formvars + "&time=" + new  Date().getTime());
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			var response = xmlhttp.responseText; //alert(response);
			if(formtype == 'check') document.getElementById('printframe').innerHTML = '<iframe src="/printform.php?&form=team&registrationID=' + registrationID + '" width="1" height="1" style="visibility:hidden"></iframe>';
		}
	}
	//setTimeout("contactForm('up')",2500);
	xmlhttp.send(null);
	
	return false; }

function printTeam(registrationID){
	var isGood = true;
	$('.req').each( function (){
		//alert($(this).attr('name'));
		var value = trim($(this).val());
		if(value == ''){
			$(this).parent(0).css({'color':'red','font-style':'italic'});
			isGood = false;
		}else{
			$(this).parent(0).css({'color':'black','font-style':'normal'});
		}
		if($(this).attr('name') == 'email' && !echeck(value)){
			$(this).parent(0).css({'color':'red','font-style':'italic'});
			isGood = false;
		}
	})
	
	if(!isGood){
		alert('Please fix RED errors above');
	}else{
		var tempfile = '';
		sendTeamForm('check');
	}
}

function showDonateType(value){
	$('#donatetype p').css('display','none');
	if(value != ''){
		$('#donatetype p:eq('+value+')').css('display','block');
	}
}

function showDonateType2(value){
	$('#donatetype2 p').css('display','none');
	if(value != ''){
		$('#donatetype2 p:eq('+value+')').css('display','block');
	}
}

function checkProDevForm(){
	var isGood = true;
	
	$('.req').each( function (){
		//alert($(this).attr('name'));
		var value = trim($(this).val());
		if(value == ''){
			$(this).parent(0).css({'color':'red','font-style':'italic'});
			isGood = false;
		}else{
			$(this).parent(0).css({'color':'black','font-style':'normal'});
		}
		if($(this).attr('name') == 'email' && !echeck(value)){
			$(this).parent(0).css({'color':'red','font-style':'italic'});
			isGood = false;
		}
	})

	
	if(!isGood){
		alert('Please fix RED errors above');
	}else{
		//sendProDevForm('paypal');
	}
	
	return isGood; //isGood;
}

function sendProDevForm(formtype){
	var formvars = $("#genform").serialize(); //alert(formvars);
	
	xmlhttp.open("GET", "/ajaxHandler.php?action=sendProDevForm&formtype=" + formtype + "&" + formvars + "&time=" + new  Date().getTime());
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			var response = xmlhttp.responseText; //alert(response);
			document.getElementById('genform').innerHTML = '<h3 align="center" style="font-size:20px"><strong>June 26 In-Service Professional Registration Form </strong></h3><p align="center"><strong><em><br><br><br>Your registration form has been sent.</em></strong></p>';
		}
	}
	//setTimeout("contactForm('up')",2500);
	xmlhttp.send(null);
	
	return false; }

$(document).ready(function() {
	//$("a.imgbox").imgbox({'alignment':'center'});
	$('a.imgbox').click(function (){
		var href = 'http://www.hbcuchoirs-105voh.com/images-new/photos/rss/' + $(this).attr('rel') + '.rss'; //alert(href);
		PicLensLite.start({feedUrl:href});
		return false;
	});
	
	showCD();  
	menu();
	howPaying();
	howPaying2();
	
	tb_init('a.video');//pass where to apply thickbox
	imgLoader = new Image();// preload image
	imgLoader.src = tb_pathToImage;
});