// declare variables to be used
var fade = new Array(100);
var timer = "";

// set up some event listeners that we may need to use
$(document).ready(function(){	
						   
	//$('#detailwindow').animate({opacity:.7});

	$("#rsvp").click(function(){
		$("#sneezeguard").load("rsvpform.php",
			function(){
				$("#sneezeguard").fadeIn(fade[0]);
			}
		);
	});

	$("#sponsorship").click(function(){
		location.href='mailto: katie@chicagofortheanimals.com?subject=Chicago For The Animals Sponsors';
		/*$("#sneezeguard").load("sponsorform.php",
			function(){
				$("#sneezeguard").fadeIn(fade[0]);
			}
		);*/
	});
	
	$("#siteby").click(function(){
		location.href="http://webactivedesigns.net";
	});	
	
	$(".footerlink").hover(function(){
	  	$(this).addClass("footerlinkactive");
	},function(){
	  	$(this).removeClass("footerlinkactive");
	});
	
});

// this function will update the number of tickets requested as well as the cost
function cartUpdate(){
	document.getElementById('amount_1').value = (document.getElementById('tix').options[document.getElementById('tix').selectedIndex].value * 25.00);
}

// this function will close a popup window
function closePopup(){
	clearTimeout(timer);
	$("#sneezeguard").fadeOut(fade[0],
		function(){
			$("#sneezeguard").html("");
		}
	);
}

// this funtion will highlight the close button
// a = are we over or out
function closeHover(a){
	if(parseInt(a) == 1){
		$(".closebutton").addClass("closebuttonactive");
	}else{
		$(".closebutton").removeClass("closebuttonactive");
	}
}

// this function will send an email containing the details entered into the sponsorship form
function sponsorEmail(){
	clearTimeout(timer);
	oForm = document.forms['sponsorform'];
	$.post('_libraries/php/sponsoremail.php',{name:oForm.elements['name'].value,company:oForm.elements['company'].value,email:oForm.elements['email'].value,phone:oForm.elements['phone1'].value+"-"+oForm.elements['phone2'].value+"-"+oForm.elements['phone3'].value,comments:oForm.elements['comments'].value},function(data){if(data == "success"){$("#formboxcontentarea").html("<p>Thank you for your support!  We will be in touch regarding your sponsorship interest.</p>"); timer = setTimeout("closePopup()",3000);}});
}

// this function will verify the form and form elements and then either return an error and highlight fields accordingly OR say thank you!
// a = an array of the elements we are making requried
// b = the form name to be verified
function validateForm(a,b){
	
	function validEmail(){
		badEmail = false;
		email = oForm.elements['email'].value;
		var at="@";
		var dot=".";
		var lat=email.indexOf(at);
		var lstr=email.length;
		var ldot=email.indexOf(dot);
		if(email.indexOf("@") == -1){
		   badEmail = true;
		}
		if (email.indexOf(".") == -1){
			badEmail = true;
		}
		if(badEmail == true){
			return false;
		}else{
			return true;
		}
	}
	
	result = 1;
	errorString = '';
	oForm = document.forms[b];
	orig = oForm.elements['go'].value;
	oForm.elements['go'].value = "Please Wait...";
	for(x in a){
		val = oForm.elements[a[x]].value;
		if(val == ""){
			result = 0;
			$("#label_"+[a[x]]).addClass("formgrouplabelerror");
		}else{
			$("#label_"+[a[x]]).removeClass("formgrouplabelerror");
			if([a[x]] == "email"){
				ret = validEmail();
				if(ret == false){
					$("#label_"+[a[x]]).addClass("formgrouplabelerror");
					oForm.elements['email'].value = "";
					oForm.elements['verifyemail'].value = "";
				}else{
					if(val != oForm.elements['verifyemail'].value){
						$("#label_"+[a[x]]).addClass("formgrouplabelerror");
						oForm.elements['email'].value = "";
						oForm.elements['verifyemail'].value = "";
					}
				}				
			}
		}
	}
	if(result == 0){
		oForm.elements['go'].value = orig;
		$("#formerror").html("Please correct the errors above.");
	}else{
		return true;		
	}
}
