// JavaScript Document
$(document).ready(function() {
 
	// email field focus
	//$('#name').focus();
	
   
	// anchor trigger submit
   	$(function() {
  		$("#ahrefsubmit").click(function() {
    		$("form").submit();
    	return false;
  	});
	
	// use this to reset several forms at once
	$("#ahrefreset").click(function() {
		$("form").each(function() {
			this.reset();
		});
	})
}); 

	// prepare the form when the DOM is ready 
	var options = { 
		  beforeSubmit:   validate, 
		  success:       showResponse  
	}; 
 
    // bind to the form's submit event 
    $("#form1").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(options); 
		
        // always return false to prevent standard browser submit and page navigation 	
        return false; 
    }); 	
	
	 $("#form1").ajaxSuccess(function(evt, request, settings){	
	 });
	
});

//pre post validate form values
function validate(formData, jqForm, options) { 
    // jqForm is a jQuery object which wraps the form DOM element 
	 var form = jqForm[0]; 
	 var msgErrorText = "";
	/*
	if validation is NOT OK
	*/	
    if (!form.name.value) { 
		msgErrorText = "Input your Last, First Name <br />";
    } 
	//email
	 if (!form.emailform.value) { 
	 	msgErrorText += "Input your E-Mail <br />";
    } 
	//description
	 if (!form.description.value) { 
	 	msgErrorText += "Input short description <br />";
    } 
	//uploadfile is not *
	
	//print erroe msg
	if(msgErrorText.length!=0){ 
		//FBug debuger:: 
		//console.log(msgErrorText)
		alert_lightbox("<b>Please insert next form data:</b><br />" + msgErrorText);
		return false;
	}
	/*
	if validation is OK
	-----------------------------------------------------
	 if visior choosed to upload file for mail attachment 
	 1 - we need to upload it first on server
	 2 - & then send mail with file attachment
	 
	*/
/*	 if (form.uploadfile.value) { 
	 	//FBug debuger:: 
		console.log(form.uploadfile.value)
	 } */
	
	//alert("validation is OK..");
	return true; 
}
 
// post-submit callback 
function showResponse(responseText, statusText)  { 
	 //alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
       // '\n\nThe output div should have already been updated with the responseText.'); 
	 $('#form1').resetForm();
	 alert_lightbox("Thank you for your request, we'll respond promptly. ");
}

//prompt Fn
function alert_lightbox(msg){
	$.prompt(msg,
	{
		buttons:{'OK':true}, 
		show:'fadeIn',
		opacity: 0.4
	});
}


        