jQuery.fn.formular = function() {
  
  return this.each(function(){
  $('#kontakt-form .error').hide();
 /* $('#kontakt-form .text-input').css({backgroundColor:"#FFFFFF"});
  $('#kontakt-form .text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('#kontakt-form .text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });*/

  var options = { 
        //target:        '#kontakt-form',   // target element(s) to be updated with server response 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showMessage,  // post-submit callback 
 
        // other available options: 
        url:       '/modules/formpost/formpost.php',      // 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 form using 'ajaxForm' 
    $('#form-post').ajaxForm(options); 

 });
 
 
};

function showRequest(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    
$('.error').hide();
		
	  var name = $("input#name").val();
		if (name == ""  || name == $("input#name")[0].title) {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
		var email = $("input#email").val();
		if (email == ""  || email == $("input#email")[0].title) {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		var text = $("textarea#text").val();
		if (text == ""  || text == $("textarea#text")[0].title) {
      $("label#text_error").show();
      $("textarea#text").focus();
      return false;
    }
    
    return true;
} 
 
 
function showMessage()
{
	inputLabel(".name-input");
    inputLabel(".email-input");
    inputLabel(".text-input");
	$("#inline").click();
} 
// post-submit callback 
/*function showResponse(responseText, statusText)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
 
} 
*/

function inputLabel(tag){
	$(tag).val($(tag)[0].title);
	
	$(tag).focus(function(srcc)
	    {
	          if ($(this).val() == $(this)[0].title)
	          {
	              $(this).val("");
	          }
	    });
	      
	$(tag).blur(function()
	    {
	          if ($(this).val() == "")
	          {
	              $(this).val($(this)[0].title);
	          }
	    });
}



jQuery.fn.formularNewsletter = function() {
  
  return this.each(function(){

  var options = { 
        target:        '#newsletter-message-text',   // target element(s) to be updated with server response 
        //beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showMessageNewsletter,  // post-submit callback 
 
        // other available options: 
        url:       '/modules/newsletter/newsletter.php',      // 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 form using 'ajaxForm' 
    $('#newsletter-form').ajaxForm(options); 

 });
 
 
};

function showRequestNewsletter()
{		
		if ($(".input-newsletter").val() || text == $(".input-newsletter")[0].title) {
      		$(".input-newsletter").val(""); 
		}
}

function showMessageNewsletter()
{
	inputLabel(".input-newsletter");
	$("#newsletter-link").click();
}


/* akreditacie */


function showMessageAkreditacie()
{
	inputLabel(".name-input");
    inputLabel(".surname-input");
    inputLabel(".email-input");
    inputLabel(".tel-input");
    inputLabel(".text-input");
	$("#akreditacia-link").click();
}

jQuery.fn.formularAkreditacie = function() {
  
  return this.each(function(){
  $('#akreditacia-form .error').hide();


  var options = { 
        target:        '#akreditacia-message-text',   // target element(s) to be updated with server response 
        beforeSubmit:  showRequestAkreditacie,  // pre-submit callback 
        success:       showMessageAkreditacie,  // post-submit callback 
 
        // other available options: 
        url:       '/modules/akreditacia/akreditacia.php',      // 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 form using 'ajaxForm' 
    $('#akreditacia-post').ajaxForm(options); 

 });
 
 
};

function showRequestAkreditacie(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    
$('.error').hide();

	          
	 		
	  var name = $("input#name").val();
		if (name == "" || name == $("input#name")[0].title ) {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
    
      var surname = $("input#surname").val();
		if (surname == "" || surname == $("input#surname")[0].title) {
      $("label#surname_error").show();
      $("input#surname").focus();
      return false;
    }
      
	  var tel = $("input#tel").val();
		if (tel == "" || tel == $("input#tel")[0].title) {
      $("label#tel_error").show();
      $("input#tel").focus();
      return false;
    }
		var email = $("input#email").val();
		if (email == "" || email == $("input#email")[0].title) {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		
		var text = $("textarea#text").html();
		if (text == "" || text == $("textarea#text")[0].title) {
      	$("textarea#text").html("");
      
    }
    
    return true;
}



