$(document).ready(function(){
	
	


var referFormOptions = { 
        
		
		//Set 'ajax' variable as form being processed with ajax form query
		//IE doesn't work with live.submit, so this will redirect on save
		data: { ReferSubmit: '1' },
	   
 		beforeSubmit:  referFormRequest,
		success:       referFormResponse  
	
    }; 
 
    // bind to the form's submit event 
	
    $('.referForm').live('submit',function() { 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $(this).ajaxSubmit(referFormOptions); 
 
        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
    }); 
	
	$('.submit').live('click',function(event){
     // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $(this).ajaxSubmit(referFormOptions); 
 
        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
	});
	
	
	


}); 
function referFormRequest(){
	
	if(document.getElementById('toEmail').value=='' || document.getElementById('fromEmail').value=='' || document.getElementById('fromName').value=='' || document.getElementById('referMessage').value=='' || document.getElementById('referSubject').value==''){
		alert('Please Enter All Details');
		return false;
	}
	$.colorbox.close();
	
		$.blockUI({ 
			css: { 
				border: 'none', 
				padding: '15px', 
				backgroundColor: '#000', 
				'-webkit-border-radius': '10px', 
				'-moz-border-radius': '10px', 
				opacity: .5, 
				color: '#fff',
				fontSize: '2em'
				},
			message: 'Sending'	
		}); 
	return true;
}
function referFormResponse(responseText, statusText, xhr, $form){
	//alert(responseText);
	
	$.colorbox.close();
	if (responseText === 'OK'){
		$.blockUI({ 
			css: { 
				border: 'none', 
				padding: '15px', 
				backgroundColor: '#000', 
				'-webkit-border-radius': '10px', 
				'-moz-border-radius': '10px', 
				opacity: .5, 
				color: '#fff',
				fontSize: '2em'
				},
			message: '<img src="images/icons/tick_lrg.png"  /> Referral Sent'	
		}); 
		//setTimeout('window.location.reload();', 1000); 
		//restoreEventsBanner()
		setTimeout('$.unblockUI();', 2000); 
		
		document.getElementById('toEmail').value='';
		
		
		
		//$.colorbox.close()
	} else {
		$.blockUI({ 
			css: { 
				border: 'none', 
				padding: '15px', 
				backgroundColor: '#000', 
				'-webkit-border-radius': '10px', 
				'-moz-border-radius': '10px', 
				opacity: .5, 
				color: '#fff',
				fontSize: '2em'
				},
			message: '<img src="images/icons/cross.png"  /> Save Failed'	
		}); 
		//setTimeout('window.location.reload();', 2000); 
		//setTimeout('$.unblockUI();', 3000); 
		setTimeout('$.unblockUI();', 2000); 
		setTimeout('referPopup();', 3000); 
	}
}
