/* RT Site JavaScript Include */

/* Global Vars */

var settings = {
	tl: { radius: 5 },
	tr: { radius: 5 },
	bl: { radius: 5 },
	br: { radius: 5 }
}

uploadInputCount = 5;

/* Global Functions */

function stripWhiteSpace(string){
	return string.replace(/^\s*|\s*$/g,'');
}

function validateEmail(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)

	if (str.indexOf(at)==-1){
		return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}

	if (str.indexOf(at,(lat+1))!=-1){
		return false
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	}

	if (str.indexOf(dot,(lat+2))==-1){
		return false
	}

	if (str.indexOf(" ")!=-1){
		return false
	}

return true
}

function checkRegForm(){
	var error = false;
	var regForm = document.regForm;

	if(stripWhiteSpace(regForm.fname.value) == "")
		error = true;
	if(stripWhiteSpace(regForm.lname.value) == "")
		error = true;
	if((stripWhiteSpace(regForm.address.value) == "") || (stripWhiteSpace(regForm.city.value) == "") || (stripWhiteSpace(regForm.state.value) == "") || (stripWhiteSpace(regForm.zip.value) == "")){
		if(stripWhiteSpace(regForm.outUS.value) == "")
			error = true;
	}
	if((stripWhiteSpace(regForm.numZip.value) == "") || (stripWhiteSpace(regForm.numF.value) == "") || (stripWhiteSpace(regForm.numL.value) == ""))
		error = true;
	if((stripWhiteSpace(regForm.email.value) == "") || (!validateEmail(regForm.email.value)))
		error = true;
	if(stripWhiteSpace(regForm.numAttend.value) == "")
		error = true;

	if(error){
		alert("Please make sure all required fields are filled in and your e-mail is valid.");
	} else {
		regForm.submit();
	}
}

function checkBioForm(){
	var error = false;
	var bioForm = document.bioForm;

	if(stripWhiteSpace(bioForm.fname.value) == "")
		error = true;
	if(stripWhiteSpace(bioForm.lname.value) == "")
		error = true;

	if(error){
		alert("Please make sure all required fields are filled in.");
	} else {
		bioForm.submit();
	}
}

function checkContactForm(){
	var error = false;
	var contactForm = document.contactForm;
	
	if((!contactForm.rc1.checked) && (!contactForm.rc2.checked) && (!contactForm.rc3.checked) && (!contactForm.wm.checked))
		error = true;	
	if(stripWhiteSpace(contactForm.name.value) == "")
		error = true;
	if((stripWhiteSpace(contactForm.email.value) == "") || (!validateEmail(contactForm.email.value)))
		error = true;
		
	if(error){
		alert("Please make sure all required fields are filled in, at least one recipient is selected, and your e-mail is valid.");
	} else {
		contactForm.submit();
	}
}

function checkPicForm(){
	var error = false;
	var picForm = document.picForm;
	
	if((picForm.email.value != "") && (!validateEmail(picForm.email.value)))
		error = true;
		
	if(error){
		alert("Please make sure your e-mail address is valid.");
	} else {
		picForm.submit();
	}
}

function showUploadForm(){
	if(($("#hiddenForm").css("display")) == "none"){
		$("#hiddenForm").show();
	} else {
		$("#hiddenForm").hide();
	}
}

function addUploadElements(){
	if(uploadInputCount < 25){
		$("#uploadInputs").append('<div class="right noLeft"><input type="file" name="ufile[]" class="text reg" /></div><div class="clear"></div><div class="right noLeft"><input type="file" name="ufile[]" class="text reg" /></div><div class="clear"></div><div class="right noLeft"><input type="file" name="ufile[]" class="text reg" /></div><div class="clear"></div><div class="right noLeft"><input type="file" name="ufile[]" class="text reg" /></div><div class="clear"></div><div class="right noLeft"><input type="file" name="ufile[]" class="text reg" /></div><div class="clear"></div>');
		uploadInputCount = uploadInputCount + 5;
	}
}
