/* Setup global settings for AJAX requests for selected URL */

$.ajaxSetup({
  url: "/@ajax.php/",
  type: "POST",
  async: true,
  error: function (XMLHttpRequest, textStatus, errorThrown) {
     alert(XMLHttpRequest+' - '+textStatus+' - '+errorThrown);
  }
});


function replaceBox(data, place)
{
	$('#'+place).html(data);
}

function showMsg(data, place) {
   $('#comment'+place).html(data);
   $('.comment').removeClass('db');
   $('#comment'+place).addClass('db');
}


function dummy() {
   return 'dummy function';
}


function msgSent(data, place) {

   var cssClasses;
   var data = 1; // delete this row after php will return status
    
   if(data == 1) {
      cssClasses = 'ok-message db fixpng-ajax';
      innerText = 'Message has been sent';
   }
   else if (data == 0) {
      cssClasses = 'error-msg db fixpng-ajax';
      innerText = 'Message has not been sent';
   }

   $('#sentMessage'+place).html(innerText);
   $('#sentMessage'+place).addClass(cssClasses);


   $('#comment'+place).removeClass('db');
   $('#comment'+place).html('');
   
   //$('.fixpng-ajax').ifixpng();

   jQuery('#sentMessage'+place)
   .animate({opacity: 1.0}, 5000)
   .fadeOut('slow', function() {
      $(this).remove();
   });

}

function msgFormSent(data, place) {

   var cssClasses;
   var data = 1; // delete this row after php will return status

   if(data == 1) {
      cssClasses = 'ok-message db fixpng-ajax';
      innerText = 'Message has been sent';
   }
   else if (data == 0) {
      cssClasses = 'error-msg db fixpng-ajax';
      innerText = 'Message has not been sent';
   }

   $('#sentFormMessage'+place).addClass(cssClasses);
   $('#sentFormMessage'+place).html(innerText);

   $('#commentform'+place).removeClass('db');

   $('.fixpng-ajax').ifixpng();

   jQuery('#sentFormMessage'+place)
   .animate({opacity: 1.0}, 5000)
   .fadeOut('slow', function() {
      $(this).remove();
   });
}

function favOperation(data, place) {

   var data = 1;
   if(data == 1) {
  // var test = place+' a';
   
   $('#'+place+' a').html('Remove from favorites');

   } else if (data == 0) {
   }
}

function rated(data, place) {
   $('#'+place).html(data);
}

function doAjax(sentdata, callback, place , url , id_loader) {

	var loader = jQuery('<div class="'+ id_loader +'"><img src="/images/loading.gif" alt="loading..." /></div>')
		.hide()
		.appendTo("#"+id_loader);
	
	jQuery().ajaxStart(function() {
		loader.show();
	}).ajaxStop(function() {
		$("#" + id_loader ).html('');
	});

   // If form object is passed to var sentdata
   if(typeof(sentdata) == 'object') {
       var dataforscript = '';
       jQuery.each(sentdata, function() {
         dataforscript += this.name+'='+encodeURIComponent(this.value)+'&';
       });
    } else {
    // If string is sent
      dataforscript = ''+sentdata;
      
    }

   $.ajax({
      url: url,
      data: dataforscript,
      success:  function(data){
        callback(data, place);
      }
   });
}



/*
function response(response) {
   html = createElement('DIV').innnerHTML(response);
   foreach(key in html) {
      child = html[ key ];
      error = (child.style = 'default-msg');
      if(error) {
         error_placeholder.appendChild(child);
         html.removeChild(child);
      }
   }
   
   ok_placeholder.appendChild(html);
}
*/

