

function request_update_new (what, where, what_prod) {
	if ( (what != '') && (where != '') )

        $('#'+where).load(Path+'_procescomments.php?getSection=' + what + '&what_prod=' + what_prod , {forcePost:1}, function(){
    $('.comment_area').css('display','none');
 });
	//	console.log($('#mainmodules'));

}

function request_update_comm (what, where, what_comm) {
	if ( (what != '') && (where != '') )

        $('#'+where).load(Path+'_procescomments.php?getSection=' + what + '&what_comm=' + what_comm , {forcePost:1})
	//	console.log($('#mainmodules'));

}


function request_update_comanda (what, where) {
	if ( (what != '') && (where != '') )

        $('.'+where).load(Path+'_procescomments.php?getSection=' + what  , {forcePost:1})
	//	console.log($('#mainmodules'));

}



function post_form (what_type, what_to, what_prod, comofcomid) {
   window.wprod = what_prod;
   window.wcomment = comofcomid;
   switch (what_type) {

		case 'trimite_comment':
			if (what_to == 'send_comment') {
				
	msg_alert = '';
	send_form = 'true';
    rating = $('input[name=rating-princ]:checked').val();
	//console.log(rating);

	if (typeof rating ==  'undefined') {
		send_form = 'false';
		msg_alert += "<br />" + 'Va rugam acordati rating produs!';
	}
	
	if ($("#reviewNume").val() == '') {
		send_form = 'false';
		msg_alert += "<br />" + 'Va rugam completati Numele!';
	}
	if ($("#reviewTitle").val() == '') {
		send_form = 'false';
		msg_alert += "<br />" + 'Va rugam completati Titlu review!';
	}	
	if ($("#reviewBody").val() == '') {
		send_form = 'false';
		msg_alert += "<br />" + 'Va rugam completati Review-ul!';
	}
	
	if (send_form == 'true') {
		//submit form
         $.ajax({type: 'POST', url: Path+'_procescomments.php', data: $('#'+what_to).serializeArray(), success: update_comments});
		}
		
		else { alert_x(msg_alert); }
	return false;

			}
		break;
		
		
		case 'trimite_comment_ofcomment':
				
	msg_alert = '';
	send_form = 'true';

  if ($('#reviewNume_comofcom'+comofcomid).val() == '') {
		send_form = 'false';
		msg_alert += "<br />" + 'Va rugam completati Numele!';
	}

	if ($('#commentBody_comofcom'+comofcomid).val() == '') {
		send_form = 'false';
		msg_alert += "<br />" + 'Va rugam completati Comentariul!';
	}
	
	if (send_form == 'true') {
		//submit form
         $.ajax({type: 'POST', url: Path+'_procescomments.php', data: $('#'+what_to).serializeArray(), success: update_comments});
		}
		
		else { alert_x(msg_alert); }
	return false;


		break;
		
		
	case 'vot_pozitiv':

		//submit form				
        $.ajax({type: 'POST', url: Path+'_procescomments.php', data: 'tip_vot=' + what_type + '&id_comment_vot=' + comofcomid, success: update_vot_comm});
	return false;

		break;
		
	case 'vot_negativ':

		//submit form				
        $.ajax({type: 'POST', url: Path+'_procescomments.php', data: 'tip_vot=' + what_type + '&id_comment_vot=' + comofcomid, success: update_vot_comm});
	return false;

		break;
		
		case 'trimite_comanda':
				
	msg_alert = '';
	send_form = 'true';

  if (!isValidEmailAddress($('#qty').val())) {
		send_form = 'false';
		msg_alert += "<br />" + 'Va rugam completati adresa de email!';
	}

	if ($('#qtz').val() == '') {
		send_form = 'false';
		msg_alert += "<br />" + 'Va rugam completati nr. de telefon!';
	}
	
	if (send_form == 'true') {
		//submit form
         $.ajax({type: 'POST', url: Path+'_procescomments.php', data: $('#'+what_to).serializeArray(), success: update_comanda});
		}
		
		else { alert_x(msg_alert); }
	return false;


		break;
		
	case 'trimite_rata':
				
	msg_alert = '';
	send_form = 'true';
	
	rata = parseInt($('#rcost').val());
	
	avans = parseInt($('#ravans').val());

  if ($('#rcost').val() == '' || $('#rcost').val()<=0) {
		send_form = 'false';
		msg_alert += "<br />" + 'Introduceti suma!';
	}

  if ($('#rcost').val()>30000) {
		send_form = 'false';
		msg_alert += "<br />" + 'suma maxima: 20000RON!';
	}
	
  if ($('#rdurata').val()<6) {
		send_form = 'false';
		msg_alert += "<br />" + 'rate minime: 6 rate!';
                             }

  if ($('#rdurata').val()>12) {
		send_form = 'false';
		msg_alert += "<br />" + 'rate maxime: 12 rate!';
                             }
							 
  if (rata<avans) {
		send_form = 'false';
		msg_alert += "<br />" + 'avansul trebuie sa fie mai mic decat suma!';
                             }
	
	if (send_form == 'true') {
		//submit form
         $.ajax({type: 'POST', url: Path+'_processrate.php', data: $('#'+what_to).serializeArray(), success: update_rate});
		}
		
		else { alert_x(msg_alert); }
	return false;


		break;

	}
}


function update_comments(returned_response) {
		//console.log('trece');
		if(returned_response=='') {
		request_update_new('opinia-cumparatorilor', 'opinia-cumparatorilor', wprod);
		request_update_new('product_statistic', 'product_statistic', wprod);
		$(this).delay(200, function(){
		h_eight = $('div#opinia-cumparatorilor').height(); 
		openSlider_x(h_eight);	   })	
							
		}
}


function update_vot_comm(returned_response) {
		//console.log('trece');
		if(returned_response=='') {
		request_update_comm('update_vot_pozitiv', 'thumbs_up_value_' + wcomment , wcomment);
		request_update_comm('update_vot_negativ', 'thumbs_down_value_' + wcomment , wcomment);
		
		}
		
}

function update_comanda(returned_response) {
		//console.log('trece');
		if(returned_response=='') {
		request_update_comanda('update_comanda', 'produs-comanda-rapida');
		}
		
}

function update_rate(returned_response) {

		if(returned_response!='') {
		$('#rezRate').html(returned_response);
		}
		
}

//// de aici -- functii ajutatoare 

	function openSlider_x(h_eight)
    {
    var open_height = h_eight + "px";
    $(".scroll").animate({"height": open_height}, {duration: 200 });
    }

function alert_x(msg) {
		 $('<div id="alert" title="Alerta!">'+msg+'</div>').dialog({
			bgiframe: true,
			modal: true,
			width: 420,
			buttons: {
				Ok: function() {
					$(this).dialog('close');
				}
			}
		});
	}
	

function isValidEmailAddress(emailAddress) {

var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);

return pattern.test(emailAddress);

}

