// JavaScript Document
//THE 2 CALENDARS
$(function() {
		$("#dateofservice").datepicker({showOn: 'button', buttonImage: '/wp-content/themes/wellcare.v2/referral/images/calendar.gif', buttonImageOnly: true});
	});
	
$(function() {
	$("#dateofbirth").datepicker({showOn: 'button', buttonImage: '/wp-content/themes/wellcare.v2/referral/images/calendar.gif', buttonImageOnly: true});
});


//form 1 validation/submission
function form1Validation(){
	var formValid = true;
	var formFields = new Array('referrersemail', 'referralfacility', 'dateofservice', 'patientname', 'address', 'insurance', 'dateofbirth', 'phone', 'dx', 'allergies', 'submittedby', 'medprofname');
//'password', 
	//will do a quick validation here
	for(x=0; x< formFields.length; x++){
		if( $('#'+formFields[x]).val() == "" ){
			$('#'+formFields[x]).attr('style','border: 2px solid red; -webkit-border-radius:5px; -moz-border-radius:5px; border-radius:5px');
			formValid = false;
		}
	}
	
	//will check for a proper email address here
	var emailPattern = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
	var email = document.getElementById('referrersemail').value;
	if(!emailPattern.test(email)){
		$('#referrersemail').attr('style','border: 2px solid red; -webkit-border-radius:5px; -moz-border-radius:5px; border-radius:5px');
		formValid = false;
	}

	if(!formValid){
		//echo error message
		alert('Not all required values were filled in properly!');
	}
	else{
		//going to post the form here
		//fade the form out
		$('#wellcare-referral-1').fadeOut('slow');
		$('#imagezeropercent').fadeOut('slow');
		
		//post and get the next form
		$.post(
			'/wp-content/themes/wellcare.v2/referral/form-ajax.php',
			$('#wellcare-referral-1').serialize(),
			
			function(data){
				$('#wellcare-referral-1').html(data)
			}
		);
		
		
		//50% image
		$('#imagezeropercent').attr('src', '/wp-content/themes/wellcare.v2/referral/images/50percentbg.png');
		$('#imagezeropercent').fadeIn('slow');
		//fade in with new form data
		$('#wellcare-referral-1').fadeIn('slow');
	}
}

//form1 validation
function form1Back(){
	//going to post the form here
		//fade the form out
		$('#wellcare-referral-1').fadeOut('slow');
		$('#imagezeropercent').fadeOut('slow');
		
		//post and get the next form
		$.post(
			'/wp-content/themes/wellcare.v2/referral/form-ajax.php',
			$('#wellcare-referral-1').serialize(),
			
			function(data){
				$('#wellcare-referral-1').html(data)
			}
		);
		
		
		//0% image
		$('#imagezeropercent').attr('src', '/wp-content/themes/wellcare.v2/referral/images/zeropercentbg.png');
		$('#imagezeropercent').fadeIn('slow');
		//fade in with new form data
		$('#wellcare-referral-1').fadeIn('slow');
}




//form2 validation
function form2Validation(){
	//going to post the form here
		//fade the form out
		$('#wellcare-referral-1').fadeOut('slow');
		//$('#imagezeropercent').fadeOut('slow');
		
		//post and get the next form
		$.post(
			'/wp-content/themes/wellcare.v2/referral/form-ajax.php',
			$('#wellcare-referral-1').serialize(),
			
			function(data){
				$('#wellcare-referral-1').html(data)
			}
		);
		
		
		//50% image
		//$('#imagezeropercent').attr('src', 'images/50percentbg.jpg');
		//$('#imagezeropercent').fadeIn('slow');
		//fade in with new form data
		$('#wellcare-referral-1').fadeIn('slow');
}


//form2 validation
function form2Back(){
	//going to post the form here
		//fade the form out
		$('#wellcare-referral-1').fadeOut('slow');
		//$('#imagezeropercent').fadeOut('slow');
		
		//post and get the next form
		$.post(
			'/wp-content/themes/wellcare.v2/referral/form-ajax.php',
			$('#wellcare-referral-1').serialize(),
			
			function(data){
				$('#wellcare-referral-1').html(data)
			}
		);
		
		
		//50% image
		//$('#imagezeropercent').attr('src', 'images/50percentbg.jpg');
		//$('#imagezeropercent').fadeIn('slow');
		//fade in with new form data
		$('#wellcare-referral-1').fadeIn('slow');
}


//form2 validation
function form3Validation(){
	//going to post the form here
		//fade the form out
		$('#wellcare-referral-1').fadeOut('slow');
		$('#imagezeropercent').fadeOut('slow');
		
		//post and get the next form
		$.post(
			'/wp-content/themes/wellcare.v2/referral/form-ajax.php',
			$('#wellcare-referral-1').serialize(),
			
			function(data){
				$('#wellcare-referral-1').html(data)
			}
		);
		
		
		//50% image
		$('#imagezeropercent').attr('src', '/wp-content/themes/wellcare.v2/referral/images/100percentbg.png');
		$('#imagezeropercent').fadeIn('slow');
		//fade in with new form data
		$('#wellcare-referral-1').fadeIn('slow');
}
