function hideForms() {
	$('#noForms').show();
	$('#showForms').hide();
	$.get('formController.php',{pageAction:"updateStudentInfo",buttonAction:"hide"});	
}
function showForms() {
	$('#noForms').hide();
	$('#showForms').show();
	$.get('formController.php',{pageAction:"updateStudentInfo",buttonAction:"show"});	
}
function showUpdateContact() {
	$('.updatePasswordSection').hide();
	//$('.displayContactSection').hide();
	$('.displayPasswordSection').show();
	//$('.updateContactSection').show();

	$('.displayContactSection').hide();
	$('.updateContactSection').show();
}
function hideUpdateContact() {
	$('.updateContactSection').hide();
	$('.displayContactSection').show();
}
function showUpdatePassword() {
	$('.updateContactSection').hide();
	//$('.updatePasswordSection').hide();

	$('.displayContactSection').show();
	//$('.displayPasswordSection').show();

	$('.displayPasswordSection').hide();
	$('.updatePasswordSection').show();
}
function hideUpdatePassword() {
	$('.updatePasswordSection').hide();
	$('.displayPasswordSection').show();
}
function submitContactSection() {
	$('#buttonAction_contact').val('cont');
}
function submitPasswordSection() {
	$('#buttonAction_password').val('pass');
}
function resendConfirmation() {
	$('#buttonAction_contact').val('rese');
	$('#user_contact_email').val('');
    $('#contactForm').submit(); 
}
function cancelRequest() {
	$('#buttonAction_contact').val('canc');
	$('#user_contact_email').val('');
    $('#contactForm').submit(); 
}
function removeContact(id) {
	$('#buttonAction_contact').val('remo');
	$('#user_contact_email').val('');
	$('#in_del_id').val(id);
	$('#contactForm').submit();
}
function setupAjax() {
	//var height1=$("#box1").height();
	//maxheight=height1+5;
	//$("#box1").height(maxheight);
	//$("#box2").height(maxheight);
	//$("#box3").height(maxheight);

	// jquery form
    var options = { 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse  // post-submit callback 
        // other available options: 
		//target:        '#output2',   // target element(s) to be updated with server response 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 
 
    // bind to the form's submit event 
    $('#contactForm').submit(function() { 
		submit_type='cont';
        $(this).ajaxSubmit(options); 
        return false; // !!! Important !!! always return false to prevent standard browser submit and page navigation 
    }); 
    $('#passwordForm').submit(function() { 
		submit_type='pass';
        $(this).ajaxSubmit(options); 
        return false; // !!! Important !!! always return false to prevent standard browser submit and page navigation 
    }); 
}
// pre-submit callback 
function showRequest(formData, jqForm, options) { 
	if (
		(submit_type=='name' && $('#nameForm').valid()) ||
		(submit_type=='pass' && $('#passwordForm').valid())
		) {
		$('#updateContactSection_submit').hide();
		$('#updateContact2Section_submit').hide();
		$('#updatePasswordSection_submit').hide();
		$('#updateContactSection_loading').show();
		$('#updateContact2Section_loading').show();
		$('#updatePasswordSection_loading').show();
		return true;
	} else {
		return false;
	}
} 
// post-submit callback 
function showResponse(responseText, statusText)  { 
	if (responseText.length < 2 || responseText.substr(0,2) !='ok') {
		$('#updateContactSection_loading').hide();
		$('#updateContact2Section_loading').hide();
		$('#updatePasswordSection_loading').hide();
		if (submit_type=='cont') {
			$('#user_contact_email').addClass('error');
		}
		if (submit_type=='pass') {
			if (responseText.indexOf('old pass')>0) {
				$('#password').addClass('error');
				$('#password1').removeClass('error');
				$('#password2').removeClass('error');
			} else {
				$('#password').removeClass('error');
				$('#password1').addClass('error');
				$('#password2').addClass('error');
			}
		}
		$('#in_del_id').val('');
		alert(responseText);
		$('#updateContactSection_submit').show();
		$('#updateContact2Section_submit').show();
		$('#updatePasswordSection_submit').show();
	} else {
		$('#ajaxResponseArea').html(responseText.substr(2));
		setupAjax();    
		//window.location.reload(true);
	}
}
$(document).ready( function () {
	setupAjax();    
});
