// prepare the form when the DOM is ready 
$(document).ready(function() { 

    var options = {   
        success:		thankyou,  // post-submit callback 
        clearForm: 		true,
        resetForm: 		true
 
        // other available options: 
        //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 
    };
    
    /*
var requestOptions = {   
        success:		requestThankYou,  // post-submit callback 
        clearForm: 		true,
        resetForm: 		true,
        beforeSubmit:	requestReq // pre-submit callback
 
        // other available options: 
        //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 comment form using 'ajaxForm' 
    $('#commentform').ajaxForm(options); 
    
   /*
 //bind request form 
     $('#party-request-form').ajaxForm(requestOptions);
*/
}); 
 
 
function thankyou(){
	var file = '/application/views/default/common/comment-thankyou.php';	
	var height = 300;
	var width =  300;
	var fpos = $('.footer').position();
	
	// Insert loading message
	$().ready(function(){
		$('.modal-ml').height(height-18);
		$('.modal-mr').height(height-18);
		$('.modal-tl').width(width-8);
		$('.modal-ml').width(width-8);
		$('.modal-bl').width(width-8);
		$('#modal').css('top', fpos.top); 
		$('#modal').css('left', $(window).width()/2-width/2); 
		$('.modal-overlay').height($(document).height()); 
		$('.modal-overlay').width($(document).width()); 
		$('.modal-overlay').show();
		$('#modal').show();
		// Ajax request
		$.get(file, function(data){
			$('#modal').show(3000,function(){
				$('#modal-content').empty();
				$(data).appendTo('#modal-content');
			});
		});
	});
	return false;	
}

/*
//Request form validation
function requestReq(){
	//var r = $('input').hasClass('form-req');
	
	alert('beforeSubmit() called!');
	
	return false;
	/*
var l = r.length;
	for(x=0; x<4; x++){
		if($('#' + r[x].id).val('')){
			$('#' + r[x].id).addClass('form-err');
			alert(r[x].length);
			return false;
		}
		
	}

}


//Succesful Submission of the request form.
function requestThankYou(){
	var file = '/application/views/default/common/request-thankyou.php';	
	var height = 300;
	var width =  300;
	var fpos = $('.footer').position();
	
	// Insert loading message
	$().ready(function(){
		$('.modal-ml').height(height-18);
		$('.modal-mr').height(height-18);
		$('.modal-tl').width(width-8);
		$('.modal-ml').width(width-8);
		$('.modal-bl').width(width-8);
		$('#modal').css('top', fpos.top); 
		$('#modal').css('left', $(window).width()/2-width/2); 
		$('.modal-overlay').height($(document).height()); 
		$('.modal-overlay').width($(document).width()); 
		$('.modal-overlay').show();
		$('#modal').show();
		// Ajax request
		$.get(file, function(data){
			$('#modal').show(3000,function(){
				$('#modal-content').empty();
				$(data).appendTo('#modal-content');
			});
		});
	});
	return false;	
}
*/


function message(){
	var file = '/application/views/default/common/alert.php';	
	var height = 400;
	var width =  400;
	var fpos = $('.footer').position();
	
	// Insert loading message
	$().ready(function(){
		$('.modal-ml').height(height-18);
		$('.modal-mr').height(height-18);
		$('.modal-tl').width(width-8);
		$('.modal-ml').width(width-8);
		$('.modal-bl').width(width-8);
		$('#modal').css('top', 100); 
		$('#modal').css('left', $(window).width()/2-width/2); 
		$('.modal-overlay').height($(document).height()); 
		$('.modal-overlay').width($(document).width()); 
		$('.modal-overlay').show();
		$('#modal').show();
		// Ajax request
		$.get(file, function(data){
			$('#modal').show(3000,function(){
				$('#modal-content').empty();
				$(data).appendTo('#modal-content');
			});
		});
	});
	return false;	
}


function modal(file, height, width, position){	
	$(function(){
		$('.modal-ml').height(height-18);
		$('.modal-mr').height(height-18);
		$('.modal-tl').width(width-8);
		$('.modal-ml').width(width-8);
		$('.modal-bl').width(width-8);
		$('#modal').css('top', position.top - (height/2)); 
		$('#modal').css('left', $(window).width()/2-width/2);
		$('.modal-overlay').height($(document).height()); 
		$('.modal-overlay').width($(document).width()); 
		$('.modal-overlay').show();
		$('#modal').show();
		$.get(file, function(data){
			$('#modal').show(3000,function(){
				$('#modal-content').empty();
				$(data).appendTo('#modal-content');
			});
		});	
	});	
}

function closeModal(){
	$('#modal').hide();
	$('.modal-overlay').hide();
	$('modal-content').empty();
}
$(function(){
	$('.modal-close').click(function(){
		closeModal();
		return false;
	});
});

$(function(){
	$('#gmap').click(function(){
		var fpos = $('.footer').position();
		modal('/application/views/default/common/gmap.php', 400, 400, fpos);
		return false;
	});
});