// JavaScript Document
function getID(id){
	return document.getElementById(id);
}

function phone_CONTACT(e,t,id) {
	var keycode;
	if(window.event)
		keycode = window.event.keyCode;
	else if(e)
		keycode = e.which;		
	if((t.length==3 || t.length==7) && keycode!=8 )
		getID(id).value=t+"-";
}

function isNumberKey(evt){
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;
	return true;
}

function captcha(){
	getID('img_captcha').src=base_url+'front/captcha_load/'+Math.random();	
}

function validatenewsletter()
{
	var email=getID('jemail');
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(email.value=='' || email.value=='Enter Email Address')
	{
		$("#flash1").css({'left':'0px','width':'300px','color':'#ff0000','font-weight': 'bold'});
	    getID('jemail').focus();
		jQuery.flash1.error('', 'Please Enter Your Email Address');
		setTimeout('jQuery.flash1.hide()',2000);
		return false;
	}
	else if(!reg.test(email.value)){
		$("#flash1").css({'left':'0px','width':'300px','color':'#ff0000','font-weight': 'bold'});
	    getID('jemail').focus();
		jQuery.flash1.error('', 'Please Enter Valid Email Address');
		setTimeout('jQuery.flash1.hide()',2000);
		return false;
	}
	$.post(base_url+"front/newsletter", $('#joinus').serialize(),
				   function(data){
				   	if(data==1){
						document.joinus.reset();
						$("#flash1").css({'left':'0px','width':'300px','color':'#ff0000','font-weight': 'bold'});
						jQuery.flash1.error('', 'Already Subscribed');
						setTimeout('jQuery.flash1.hide()',2000);
					} else if(data==3){
						$("#flash1").css({'left':'0px','width':'300px','color':'#ff0000','font-weight': 'bold'});
						getID('jemail').focus();
						jQuery.flash1.error('', 'Please Enter the Correct Email address');
						setTimeout('jQuery.flash1.hide()',2000);
					} else {
						document.joinus.reset();
						$("#flash1").css({'left':'0px','width':'300px','color':'#218202','font-weight': 'bold'});
						jQuery.flash1.error('', 'Thanks for subscribing.');
						setTimeout('jQuery.flash1.hide()',2000);
					}
				   });
	return false;
	
}

function contactus()
{
	var email=getID('email');	
	var phone=getID('phone');	
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var phonevalue=/(^[0-9]{3}\-[0-9]{3}\-[0-9]{4}$)/;
	if(getID('name').value=='')
	{
		$("#flash").css({'padding-top':"10px",'left':'420px','width':'200px','color':'#ff0000','font-weight': 'bold'});
	    getID('name').focus();
		jQuery.flash.error('', 'Please Enter Your Name');
		setTimeout('jQuery.flash.hide()',2000);
		return false;
	}
	if(email.value=='')
	{
		$("#flash").css({'padding-top':"60px",'left':'420px','width':'200px','color':'#ff0000','font-weight':'bold'});
	    getID('email').focus();
		jQuery.flash.error('', 'Please Enter Your Email Address');
		setTimeout('jQuery.flash.hide()',2000);
		return false;
	}
	else if(!reg.test(email.value)){
		$("#flash").css({'padding-top':"60px",'left':'420px','width':'200px','color':'#ff0000','font-weight':'bold'});
	    getID('email').focus();
		jQuery.flash.error('', 'Please Enter Valid Email Address');
		setTimeout('jQuery.flash.hide()',2000);
		return false;
	}
	if(phone.value=='')
	{
		$("#flash").css({'padding-top':"110px",'left':'420px','width':'200px','color':'#ff0000','font-weight':'bold'});
	    getID('phone').focus();
		jQuery.flash.error('', 'Please Enter Your Phone Number');
		setTimeout('jQuery.flash.hide()',2000);
		return false;	
	}
	else if(phonevalue.test(phone.value)!=true)
	{
		$("#flash").css({'padding-top':"110px",'left':'420px','width':'200px','color':'#ff0000','font-weight':'bold'});
	    getID('phone').focus();
		jQuery.flash.error('', 'Enter Valid Phone Number');
		setTimeout('jQuery.flash.hide()',2000);
		return false;	
	}
	if(getID('comments').value=='')
	{
		$("#flash").css({'padding-top':"160px",'left':'420px','width':'200px','color':'#ff0000','font-weight':'bold'});
	    getID('comments').focus();
		jQuery.flash.error('', 'Please Enter Your Comments');
		setTimeout('jQuery.flash.hide()',2000);
		return false;
	}

	var cap=getID('captcha_txt').value;
	if(cap==''){ 
		$("#flash").css({'padding-top':"374px",'left':'420px','width':'200px','color':'#ff0000','font-weight':'bold'});
	    getID('captcha_txt').focus();
		jQuery.flash.error('', 'Please Enter Verification Code');
		setTimeout('jQuery.flash.hide()',2000);
		return false;
	}
	$("#loader_cap").css({'display':'block','padding-top':"10px",'left':'240px'});
	$.post(base_url+"front/contact", $('#frm').serialize(),function(data){	
		$("#loader_cap").css({'display':'none'});
		if(data==0){
			$("#flash").css({'padding-top':"420px",'left':'240px','width':'330px','color':'#ff0000','font-weight':'bold'});
			jQuery.flash.error('', 'Sorry, Your request could not process. Please Try again');
			setTimeout('jQuery.flash.hide()',2000);
			document.frm.reset();
		} else if(data==2){
			$("#flash").css({'padding-top':"420px",'left':'240px','width':'200px','color':'#ff0000','font-weight':'bold'});
			jQuery.flash.error('', 'Invalid Verification Code');
			setTimeout('jQuery.flash.hide()',2000);
			captcha();
		} else {
			$("#flash").css({'padding-top':"420px",'left':'240px','width':'380px','color':'#218202','font-weight':'bold'});
			jQuery.flash.error('', 'Your request has been sent successfully. We will contact you soon');
			setTimeout('jQuery.flash.hide()',2000);
			document.frm.reset();
			captcha();
		}
	});
	return false;
}

function registration(){
	var error=false;
	var foc='';
	var email_reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var phonevalue=/(^[0-9]{3}\-[0-9]{3}\-[0-9]{4}$)/;
	var sname=$('#sname').val();
	var pname=$('#pname').val();
	var r_month=$('#r_month').val();
	var r_date=$('#r_date').val();
	var r_year=$('#r_year').val();
	var email=$('#remail').val();
	var city=$('#city').val();
	var zip=$('#zip').val();
	var hear=$('#hear').val();
	var fchoice=$('#fchoice').val();
	
	if(sname==''){
		error=true;
		$("#flash").css({'padding-top':"10px",'left':'420px','width':'200px','color':'#ff0000','font-weight': 'bold'});
		getID('sname').focus();
		jQuery.flash.error('', 'Please Enter Student Name');
		setTimeout('jQuery.flash.hide()',2000);
		anim('sname');
		return false;
	}
	if(r_month==''){
		error=true;
		$("#flash").css({'padding-top':"60px",'left':'420px','width':'200px','color':'#ff0000','font-weight': 'bold'});
		getID('month').focus();
		jQuery.flash.error('', 'Please Select Month');
		setTimeout('jQuery.flash.hide()',2000);
		anim('month');
		return false;
	}
	if(r_date==''){
		error=true;
		$("#flash").css({'padding-top':"60px",'left':'420px','width':'200px','color':'#ff0000','font-weight': 'bold'});
		getID('date').focus();
		jQuery.flash.error('', 'Please Select Date');
		setTimeout('jQuery.flash.hide()',2000);
		anim('date');
		return false;
	}
	if(r_year==''){
		error=true;
		$("#flash").css({'padding-top':"60px",'left':'420px','width':'200px','color':'#ff0000','font-weight': 'bold'});
		getID('year').focus();
		jQuery.flash.error('', 'Please Select Year');
		setTimeout('jQuery.flash.hide()',2000);
		anim('year');
		return false;
	}
	if(pname==''){
		error=true;
		$("#flash").css({'padding-top':"170px",'left':'420px','width':'250px','color':'#ff0000','font-weight': 'bold'});
		getID('pname').focus();
		jQuery.flash.error('', 'Please Enter Parent/Guardian\'s Name');
		setTimeout('jQuery.flash.hide()',2000);
		anim('pname');
		return false;
	}
	if(email==''){
		error=true;
		$("#flash").css({'padding-top':"222px",'left':'420px','width':'200px','color':'#ff0000','font-weight': 'bold'});
		getID('remail').focus();
		jQuery.flash.error('', 'Please Enter E-Mail Address');
		setTimeout('jQuery.flash.hide()',2000);
		anim('remail');
		return false;
	} else if(!email_reg.test(email)){
		error=true;
		$("#flash").css({'padding-top':"222px",'left':'420px','width':'250px','color':'#ff0000','font-weight': 'bold'});
		getID('remail').focus();
		jQuery.flash.error('', 'Please Enter Valid E-Mail Address');
		setTimeout('jQuery.flash.hide()',2000);
		anim('remail');
		return false;
	}
	if(city==''){
		error=true;
		$("#flash").css({'padding-top':"322px",'left':'420px','width':'200px','color':'#ff0000','font-weight': 'bold'});
		getID('city').focus();
		jQuery.flash.error('', 'Please Enter Your City');
		setTimeout('jQuery.flash.hide()',2000);
		anim('city');
		return false;
	}
	if(zip==''){
		error=true;
		$("#flash").css({'padding-top':"372px",'left':'420px','width':'200px','color':'#ff0000','font-weight': 'bold'});
		getID('zip').focus();
		jQuery.flash.error('', 'Please Enter Your Zip Code');
		setTimeout('jQuery.flash.hide()',2000);
		anim('zip');
		return false;
	}
	if(hear==''){
		error=true;
		$("#flash").css({'padding-top':"668px",'left':'339px','width':'239px','color':'#ff0000','font-weight': 'bold'});
		getID('hear').focus();
		jQuery.flash.error('', 'Please Select How did you hear about us');
		setTimeout('jQuery.flash.hide()',2000);
		anim('hear');
		return false;
	}
	if(fchoice==''){
		error=true;
		$("#flash").css({'padding-top':"907px",'left':'637px','width':'200px','color':'#ff0000','font-weight': 'bold'});
		getID('fchoice').focus();
		jQuery.flash.error('', 'Please Select First Choice');
		setTimeout('jQuery.flash.hide()',2000);
		anim('fchoice');
		return false;
	}
	if(getID('agree').checked==false){
		error=true;
		$("#flash").css({'padding-top':"1015px",'left':'263px','width':'300px','color':'#ff0000','font-weight': 'bold'});
		getID('agree').focus();
		jQuery.flash.error('', 'Please Agree Terms and Conditions');
		setTimeout('jQuery.flash.hide()',2000);
		anim('agree');
		return false;
	}
	if(!error){
		return true;
	}
}

function anim(foc){
	$('html, body').animate({ scrollTop: $("#"+foc).offset().top-80 }, 900, function(){  $("#"+foc).focus(); });		
}

function unsubscribe()
{
	var email=getID('email');
	
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(email.value=='')
	{
	    getID('email').focus();
		getID('sererror').innerHTML='Please enter your Email Address';
		return false;
	}
	else if(!reg.test(email.value)){
		getID('sererror').innerHTML='Please enter a valid Email Address';
		email.focus();
		return false;
	}
	$.post(base_url+"front/removeemail", {email:getID('email').value},
	   function(data){	
		   getID('email').value='';
			if(data==2){
				getID('sererror').innerHTML='Email Address not found!';
			} else if(data==1){
				getID('sererror').innerHTML='You have Successfully Unsubscribed!';
			}
		//alert(data);
	   });
	return false;
	
}



function summer(base_url){
	var error=false;
	var foc='';
	var email_reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var phonevalue=/(^[0-9]{3}\-[0-9]{3}\-[0-9]{4}$)/;
	var sname=$('#sname').val();
	var pname=$('#pname').val();
	var r_month=$('#r_month').val();
	var r_date=$('#r_date').val();
	var r_year=$('#r_year').val();
	var email=$('#remail').val();
	var city=$('#city').val();
	var zip=$('#zip').val();
	var shear=$('#hear').val();
	var fchoice=$('#fchoice').val();
	
	if(sname==''){
		error=true;
		$("#flash").css({'padding-top':"10px",'left':'420px','width':'200px','color':'#ff0000','font-weight': 'bold'});
		getID('sname').focus();
		jQuery.flash.error('', 'Please Enter Student Name');
		setTimeout('jQuery.flash.hide()',2000);
		anim('sname');
		return false
	}
	if(r_month==''){
		error=true;
		$("#flash").css({'padding-top':"60px",'left':'420px','width':'200px','color':'#ff0000','font-weight': 'bold'});
		getID('month').focus();
		jQuery.flash.error('', 'Please Select Month');
		setTimeout('jQuery.flash.hide()',2000);
		anim('month');
		return false
	}
	if(r_date==''){
		error=true;
		$("#flash").css({'padding-top':"60px",'left':'420px','width':'200px','color':'#ff0000','font-weight': 'bold'});
		getID('date').focus();
		jQuery.flash.error('', 'Please Select Date');
		setTimeout('jQuery.flash.hide()',2000);
		anim('date');
		return false
	}
	if(r_year==''){
		error=true;
		$("#flash").css({'padding-top':"60px",'left':'420px','width':'200px','color':'#ff0000','font-weight': 'bold'});
		getID('year').focus();
		jQuery.flash.error('', 'Please Select Year');
		setTimeout('jQuery.flash.hide()',2000);
		anim('year');
		return false
	}
	if(city==''){
		error=true;
		$("#flash").css({'padding-top':"260px",'left':'420px','width':'200px','color':'#ff0000','font-weight': 'bold'});
		getID('city').focus();
		jQuery.flash.error('', 'Please Enter Your City');
		setTimeout('jQuery.flash.hide()',2000);
		anim('city');
		return false
	}
	if(zip==''){
		error=true;
		$("#flash").css({'padding-top':"330px",'left':'420px','width':'200px','color':'#ff0000','font-weight': 'bold'});
		getID('zip').focus();
		jQuery.flash.error('', 'Please Enter Your Zip Code');
		setTimeout('jQuery.flash.hide()',2000);
		anim('zip');
		return false
	}
	if(pname==''){
		error=true;
		$("#flash").css({'padding-top':"600px",'left':'420px','width':'250px','color':'#ff0000','font-weight': 'bold'});
		getID('pname').focus();
		jQuery.flash.error('', 'Please Enter Parent\'s Name');
		setTimeout('jQuery.flash.hide()',2000);
		anim('pname');
		return false
	}
	if(email==''){
		error=true;
		$("#flash").css({'padding-top':"670px",'left':'420px','width':'200px','color':'#ff0000','font-weight': 'bold'});
		getID('remail').focus();
		jQuery.flash.error('', 'Please Enter E-Mail Address');
		setTimeout('jQuery.flash.hide()',2000);
		anim('remail');
		return false
	} else if(!email_reg.test(email)){
		error=true;
		$("#flash").css({'padding-top':"670px",'left':'420px','width':'250px','color':'#ff0000','font-weight': 'bold'});
		getID('remail').focus();
		jQuery.flash.error('', 'Please Enter Valid E-Mail Address');
		setTimeout('jQuery.flash.hide()',2000);
		anim('remail');
		return false
	}
	
	if(shear==''){
	
		error=true;
		$("#flash").css({'padding-top':"789px",'left':'301px','width':'239px','color':'#ff0000','font-weight': 'bold'});
		getID('hear').focus();
		jQuery.flash.error('', 'Please Select How did you hear about us');
		setTimeout('jQuery.flash.hide()',2000);
		anim('hear');
		return false
	}
	if(fchoice==''){
		error=true;
		$("#flash").css({'padding-top':"854px",'left':'750px','width':'200px','color':'#ff0000','font-weight': 'bold'});
		getID('fchoice').focus();
		jQuery.flash.error('', 'Please Select Camp/class Choice');
		setTimeout('jQuery.flash.hide()',2000);
		anim('fchoice');
		return false
	}
	if(getID('agree').checked==false){
		error=true;
		$("#flash").css({'padding-top':"978px",'left':'273px','width':'300px','color':'#ff0000','font-weight': 'bold'});
		getID('agree').focus();
		jQuery.flash.error('', 'Please Agree Terms and Conditions');
		setTimeout('jQuery.flash.hide()',2000);
		anim('agree');
		return false
	}
	$.post(base_url+"front/summerform", $('#frm').serialize(),function(data){	
		if(data==1){
			window.location =base_url+'thank-you';
		}  
		else {error=true;
			$("#flash").css({'padding-top':"1019px",'left':'386px','width':'386px','color':'#ff0000','font-weight':'bold'});
			jQuery.flash.error('', 'Your request has been sent successfully. We will contact you soon');
			setTimeout('jQuery.flash.hide()',2000);
			anim('cverror');
			document.frm.reset();
		}
		//alert(data);
	   });
	return false;
}
