$(document).ready(function(){
    $('.forms').hide();
    $('.formswitch').click(function(){
        
        var name = $(this).attr('id');
        var form = name.replace('open-','');
        
        $('.forms').each(function(){
            if($(this).is(':visible')){
                 $(this).slideUp('slow');
                 $(this).slideUp('slow');
                  var name = $(this).attr('id');
                 $('#open-'+name).html('Open Form');
              }else if(!$(this).is(':visible') && $(this).attr('id') == form){
                $('#'+form).slideDown('slow');
                var name = $(this).attr('id');
                $('#open-'+name).html('Close Form');
             }
        });
        return false
        
    });
    $('#affsend').click(function(){
        var name = $('#affname').val();
        var phone = $('#affphone').val();
        var email = $('#affemail').val();
        var type = $('#afftype').val();
        var emailsubject = "Interest in Webaquest Affiliate.";
        var emailvar = "emailsubject="+emailsubject+"&name="+name+"&phone="+phone+"&email="+email+"&type="+type;
        sendemail(emailvar);
         $('#open-affiliate').html('Close Form');
        $('.forms').slideUp('slow');
    });
    $('#tsend').click(function(){
        var name = $('#tname').val();
        var phone = $('#tphone').val();
        var email = $('#temail').val();
        var level = $('#tlevel').val();
        var subject = $('#tsubject').val();
        var emailsubject = "Interest in Webaquest Content Creation.";
        var emailvar = "emailsubject="+emailsubject+"&name="+name+"&phone="+phone+"&email="+email+"&level="+level+"&subject="+subject;
        sendemail(emailvar);
        $('#open-teacher').html('Close Form');
        $('.forms').slideUp('slow');
    });
    $('#misend').click(function(){
        var name = $('#miname').val();
        var phone = $('#miphone').val();
        var email = $('#miemail').val();
        var question = $('#miquestion').val();
        var emailsubject = "Interest in Webaquest Information Request.";
        var emailvar = "emailsubject="+emailsubject+"&name="+name+"&phone="+phone+"&email="+email+"&question="+question;
        sendemail(emailvar);
        $('#open-moreinfo').html('Close Form');
        $('.forms').slideUp('slow');
    });
    
    function sendemail(emailvar){
            $.ajax({
									url: "include/functions.php",
									type: 'POST',
									data:	"action=emailrequest&"+emailvar,
									async: false,
									error: function(){
												
									},
									success: function(data){
											alert("Your request was "+data);
									}
								});//END AJAX
    
    }
});
