var rhc_rating_lockdown = false;
var rating_connections_type = new uh_social_connection();



jQuery(document).scroll(function(){ rhc_rating_init(); });

jQuery(document).resize(function(){ rhc_rating_init(); });
var i = 0; var paddingForMobile = 0;

var rhc_scroll_lockdown = false;
var rhc_scroll_lockdown_showmore = false;
var rhc_review_lockdown_true = false;

function rhc_rating_init(){
	jQuery(document).ready(function($){
		if(jQuery('.cit_rhc_rating_').is(':visible')){
				
			var rhc_rating_box = jQuery('.cit_rhc_rating_').offset();
			var rhc_rating_showmore = jQuery('.cit_rhc_rating_ .showmore_div').offset();
			if (window.mobile) paddingForMobile = 1000;
			
			if(rhc_rating_showmore != undefined){
				if ( jQuery(document).scrollTop() >= rhc_rating_showmore.top - jQuery(window).height()+300-paddingForMobile && jQuery('.cit_rhc_rating_ #rhc_rating_pos3').is(':visible') && !rhc_scroll_lockdown_showmore){
					rhc_scroll_lockdown_showmore = true;
					rhc_rating_fadingeffect();
				}
			}
	
			
			if ( jQuery(document).scrollTop() >= rhc_rating_box.top - jQuery(window).height()+300-paddingForMobile && !rhc_scroll_lockdown){
				rhc_scroll_lockdown = true;
				rhc_update_count();
			}
		}
	});
}

function rhc_rating_fadingeffect(){
		jQuery('#comment_avatar_place .commentboxs:not(:visible)').eq(0).show().css('opacity',0.0).delay(i*200).animate({opacity: 1.0,marginTop: "-=100px"}, 500);
		
		if(jQuery('#comment_avatar_place .commentboxs:not(:visible)').length > 0){
			setTimeout( function(){
				rhc_scroll_lockdown_showmore = false;
			}, 100 );
		} else {
			if(rhc_review_lockdown_true){
				jQuery('.cit_rhc_rating_ .showmore_div').hide();
			} else {
				rhc_load_data('true',jQuery('#comment_avatar_place .commentboxs').length);	
			}
		}

}



function rhc_update_count(){
	jQuery(".cit_rhc_rating_ .progress-bar-bars ").each(function(){
		jQuery(this).find('.progress-bar').width('0%').delay( 800 ).animate({width: (jQuery(this).attr('data-number')/(parseFloat(jQuery(".cit_rhc_rating_ #rhc_total_count").val()))*100)+"%"}, 1000 );
		jQuery(this).find('.rhc_text').delay( 800 ).animateNumber(parseFloat(jQuery(this).attr('data-number')),{easing:"easeInOutCirc",duration:1000,floatStepDecimals:0});
	});
	var tmp_type = jQuery('.cit_rhc_rating_ #manual_select_show_rating').attr('data-rating-type');
	
	var tmp_total_rating = parseFloat(jQuery(".cit_rhc_rating_ #rhc_total_rating").val());
	var tmp_total_count = parseFloat(jQuery(".cit_rhc_rating_ #rhc_total_count").val());
	var tmp_avarge = 0;
	if(tmp_total_rating != NaN && tmp_total_rating > 0 && tmp_total_count != NaN && tmp_total_count > 0){
		tmp_avarge = tmp_total_rating/tmp_total_count;
	} 
	
	
	for(var i=0;i<jQuery('.cit_rhc_rating_ #main_show_rating div').length;i++){
		var tmp_var = '.cit_rhc_rating_ #main_show_rating div:eq('+i+')';
		var tmp_var2 = jQuery(tmp_var).attr('data-standart-type');
		jQuery(tmp_var).removeClass(tmp_var2).removeClass(tmp_var2+'-2').removeClass(tmp_var2+'-3').css({"font-size":"40px",'opacity':'0.0'});



		if(tmp_type == 'faces') {
			if((i+1) == Math.floor(tmp_avarge)){
					jQuery(tmp_var).addClass(tmp_var2).delay(800+((i*200))).animate({"font-size":"55px",'opacity':'1.0'}, 1000).animate({"font-size":"50px"}, 500);
			} else {
				jQuery(tmp_var).addClass(tmp_var2+'-3').delay(800+((i*200))).animate({"font-size":"55px",'opacity':'1.0'}, 1000).animate({"font-size":"50px"}, 500);;
			}
		} else {
			if(parseFloat(i - 0.25) <= parseFloat(tmp_avarge-1)){
					jQuery(tmp_var).addClass(tmp_var2).delay(800+((i*200))).animate({"font-size":"55px",'opacity':'1.0'}, 1000).animate({"font-size":"50px"}, 500);
			} else if(parseFloat(i - 0.75) <= parseFloat(tmp_avarge-1)){
				jQuery(tmp_var).addClass(tmp_var2+'-2').delay(800+((i*200))).animate({"font-size":"55px",'opacity':'1.0'}, 1000).animate({"font-size":"50px"}, 500);;
			} else {
				jQuery(tmp_var).addClass(tmp_var2+'-3').delay(800+((i*200))).animate({"font-size":"55px",'opacity':'1.0'}, 1000).animate({"font-size":"50px"}, 500);;
			}
		}
	}
	
	if(tmp_total_count == 1){
		jQuery('.cit_rhc_rating_ .totalselect_text').html(rhc_rating_vars.overskrift1);
	} else if(tmp_total_count > 1){
		jQuery('.cit_rhc_rating_ .totalselect_text').html(rhc_rating_vars.overskrift2);
	} else {
		jQuery('.cit_rhc_rating_ .totalselect_text').html(rhc_rating_vars.overskrift0);
	}
	
	
	if(tmp_total_count > 0){
		jQuery('.cit_rhc_rating_ #display_avage').delay( 800 ).animateNumber(tmp_avarge,{easing:"easeInOutCirc",duration:1000,floatStepDecimals:2,floatEndDecimals:2});
		jQuery('.cit_rhc_rating_ #display_big_count').delay( 800 ).animateNumber(parseFloat(jQuery(".cit_rhc_rating_ #rhc_total_count").val()),{easing:"easeInOutCirc",duration:1000,floatStepDecimals:0,floatEndDecimals:0});
	}
}

function rhc_add_count(tmp_rating){
	tmp_rating = parseFloat(tmp_rating);

	jQuery(".cit_rhc_rating_ #rhc_total_count").val(parseFloat(jQuery(".cit_rhc_rating_ #rhc_total_count").val())+1);
	jQuery(".cit_rhc_rating_ #rhc_total_rating").val(parseFloat(jQuery(".cit_rhc_rating_ #rhc_total_rating").val())+parseFloat(tmp_rating));
	
	
	var tmp_type = jQuery('.cit_rhc_rating_ #manual_select_show_rating').attr('data-rating-type');
	
	var tmps_main = Math.floor(tmp_rating+0.5); 

	var tmp_barbar = ".cit_rhc_rating_ .progress-bar-bars:eq("+((jQuery(".cit_rhc_rating_ .progress-bar-bars").length-tmps_main))+") ";
	jQuery(tmp_barbar).attr('data-number',parseFloat(jQuery(tmp_barbar).attr('data-number'))+1);
		
	rhc_update_count();	
}


function rhc_rating_openwindow(tmp_show,tmp_hidden,tmp_toogle,tmp_this){
	var save_tmp_data = tmp_show;


	if(tmp_toogle && jQuery(tmp_show).is(':visible')){
		jQuery(tmp_show).show().css('opacity',1.0).fadeTo( "slow" , 0.0,function(){
			jQuery(this).hide();
		})	
		jQuery(tmp_this).html(jQuery(tmp_this).attr('data-open-name'));
	} else {
		if(tmp_toogle){
			jQuery(tmp_this).html(jQuery(tmp_this).attr('data-close-name'));
		}

		jQuery(tmp_show).show().css({'opacity':0.0,'postion':'relative'}).fadeTo( "slow" , 1.0, function(){
			
			if(save_tmp_data == '#rhc_rating_pos3' && jQuery('#comment_avatar_place .commentboxs:visible').length < 1){
				var tmp_count = jQuery('#comment_avatar_place .commentboxs:not(:visible)').length;
				
				if(tmp_count > 4){
					tmp_count = 5;
				}
				
				for(var b=0;b<tmp_count;b++){
					jQuery('#comment_avatar_place .commentboxs:not(:visible)').eq(0).delay(b*400).show().css('opacity',0.0).animate({opacity: 1.0,marginTop: "-=100px"}, 500);
				}
			}

		});	
	}
	
	if(tmp_hidden != undefined && tmp_hidden != '' ){
		jQuery(tmp_hidden).show().css({'opacity':1.0,'postion':'absolute'}).fadeTo( "slow" , 0.0,function(){
			jQuery(this).hide();
		})		
	}
}



rhc_rating_init();


var rhc_rating_myInterval = false;

jQuery(document).ready(function($){
	
    jQuery(".cit_rhc_rating_ select[name='small']").selectpicker({style: 'btn btn-huge btn-embossed btn-primary'});
    jQuery(".cit_rhc_rating_ .btn-group.select.select-block.mbl.select-multiple .dropdown-menu").click(rhc_rating_click);
    jQuery(".cit_rhc_rating_ #rhc_rating_pos3 .showmore_div").click(rhc_rating_fadingeffect);
    
    
    rhc_load_data('true',jQuery('#comment_avatar_place .commentboxs').length);
    
	window.setTimeout(function() {
		if(jQuery('.cit_rhc_rating_ .btn-group.select.select-block.mbl.select-multiple .filter-option.pull-left').is(':visible')){
			var tmp_content = jQuery('.cit_rhc_rating_ .btn-group.select.select-block.mbl.select-multiple .filter-option.pull-left').html();
			tmp_content = tmp_content.replace(rhc_rating_vars.previousEventRating+', ','')
			jQuery('.cit_rhc_rating_ .btn-group.select.select-block.mbl.select-multiple .filter-option.pull-left').html(tmp_content)
		}
	},10);
    
	
	jQuery('.cit_rhc_rating_ #manual_select_show_rating div').mouseover().mousemove(function(event){
	   var tmp_value = jQuery('.cit_rhc_rating_ #manual_select_show_rating').attr('data-rating-selected');
	   if(tmp_value == undefined){
		   var temp_this = this;
		   var mouserover_pos = (event.pageX - jQuery(temp_this).offset().left)/jQuery(temp_this).width();
		   rhc_rating_icon_selected(jQuery(temp_this).index(),mouserover_pos);
		   clearInterval(rhc_rating_myInterval);
		   rhc_rating_myInterval = false;
	   }
	});
	
	jQuery('.cit_rhc_rating_ #manual_select_show_rating div').click(function(event){
	
		var tmp_type = jQuery('.cit_rhc_rating_ #manual_select_show_rating').attr('data-rating-type');
		
		
		var tmp = parseInt(jQuery(this).index());
	    var mouserover_pos = (event.pageX - jQuery(this).offset().left)/jQuery(this).width();
		
		if(tmp_type == 'faces'){
			tmp += 1;
		} else {
			if(mouserover_pos >= 0.5){
				tmp += 1;
			} else {
				tmp += 0.5;
			}
		}
		jQuery('.cit_rhc_rating_ #manual_select_show_rating').attr('data-rating-selected',tmp);
		
		rhc_rating_icon_selected(jQuery(this).index(),mouserover_pos);
		
	})
	
	jQuery('.cit_rhc_rating_ #manual_select_show_rating div').mouseout(function(){
		rhc_rating_myInterval = setInterval(function(){
		
			var tmps = parseFloat(jQuery('.cit_rhc_rating_ #manual_select_show_rating').attr('data-rating-selected'));
			var tmps_main = Math.floor(tmps); 
			var tmps_sec = tmps-tmps_main; 
			var temp = false;
			
			
			rhc_rating_icon_selected(tmps_main,tmps_sec);
		    clearInterval(rhc_rating_myInterval);
		    rhc_rating_myInterval = false;
		},200);
	});
	
});

var rhc_wait_time_test = '';
function rhc_rating_click(){
	window.setTimeout(function() {
		var tmp_content = jQuery('.cit_rhc_rating_ .btn-group.select.select-block.mbl.select-multiple .filter-option.pull-left').html();
		tmp_content = tmp_content.replace(rhc_rating_vars.previousEventRating+', ','')
		jQuery('.cit_rhc_rating_ .btn-group.select.select-block.mbl.select-multiple .filter-option.pull-left').html(tmp_content);
		
	},10);
	
	if(rhc_wait_time_test != ''){
		window.clearTimeout(rhc_wait_time_test);	
	}
	rhc_wait_time_test = window.setTimeout(function() {

		rhc_load_data();
	},1000);
}

function rhc_load_data(tmp_next,tmp_next_c){
	
	
	var tmp_load = '';
	
	jQuery('.cit_rhc_rating_ #get_loading_data option').filter(':selected').each(function(){
		if(jQuery(this).val() != ''){
			if(tmp_load != ''){
				tmp_load += ';';
			}
			tmp_load += jQuery(this).val();
		}	
	});
	
	jQuery.post(rhc_rating_vars.siteurl+'/?rhc_rating_data=true',{'rhc_rating_data':true,'rhc_rating_fn':'retrive_data_by_date','rhc_rating_postID':rhc_rating_vars.post_id,'rhc_rating_event_rdate':tmp_load,'rhc_rating_next_c':tmp_next_c,'rhc_rating_next':tmp_next},function(data){

			if(data.R=='DONE'){
				jQuery(".cit_rhc_rating_ #rhc_total_count").val(data.COUNT_RATING);
				jQuery(".cit_rhc_rating_ #rhc_total_rating").val(data.AVAGE_RATING);
				
				for(var i=0;i<parseFloat(data.COUNT);i++){
					var tmp_barbar = ".cit_rhc_rating_ .progress-bar-bars:eq("+(jQuery(".cit_rhc_rating_ .progress-bar-bars").length-1-i)+")";
					jQuery(tmp_barbar).attr('data-number',parseFloat(data.BAR['v'+i]));
					jQuery('.cit_rhc_rating_ #comment_avatar_place').html('');
				}
				
				rhc_load_data('true',jQuery('#comment_avatar_place .commentboxs').length);
				jQuery('.cit_rhc_rating_ .showmore_div').show();
				rhc_scroll_lockdown_showmore = false;
				rhc_review_lockdown_true = false;
				rhc_update_count();
			
			} else if(data.R=='REVIEWS'){
				if(data.SHOWMORE == 'more'){
					jQuery('.cit_rhc_rating_ #comment_avatar_place').append(data.REVIEWS);
					rhc_review_lockdown_true = false;
					rhc_scroll_lockdown_showmore = false;
				} else {
					if(data.REVIEWS != ''){
						jQuery('.cit_rhc_rating_ #comment_avatar_place').append(data.REVIEWS);
					}
					
						rhc_review_lockdown_true = true;
						rhc_scroll_lockdown_showmore = false;
				}
				
				if(jQuery('#rhc_rating_pos3').is(':visible') && jQuery('#comment_avatar_place .commentboxs:visible').length < 1){
					var tmp_count = jQuery('#comment_avatar_place .commentboxs:not(:visible)').length;
					
					if(tmp_count > 4){
						tmp_count = 5;
					}
					
					for(var b=0;b<tmp_count;b++){
						jQuery('#comment_avatar_place .commentboxs:not(:visible)').eq(0).delay(b*400).show().css('opacity',0.0).animate({opacity: 1.0,marginTop: "-=100px"}, 500);
					}
					
					
					if(tmp_count < 5){
						rhc_review_lockdown_true = true;
						rhc_scroll_lockdown_showmore = true;
						jQuery('.cit_rhc_rating_ .showmore_div').hide();
					}
				}
			}			
	},'json');
		
}

function rhc_rating_icon_selected(tmp_nr,mouserover_pos){
	var tmp_value = jQuery('.cit_rhc_rating_ #manual_select_show_rating').attr('data-rating-selected');
	for(var i=0;i<jQuery('.cit_rhc_rating_ #manual_select_show_rating div').length;i++){
		var tmp_var = '.cit_rhc_rating_ #manual_select_show_rating div:eq('+i+')';
		var tmp_var2 = jQuery(tmp_var).attr('data-standart-type');
		jQuery(tmp_var).removeClass(tmp_var2+'-2').removeClass(tmp_var2+'-3').removeClass(tmp_var2);

		

		if(tmp_value != undefined && tmp_value != 'undefined' ){
			jQuery(tmp_var).css('opacity',1.0);
		} else {
			jQuery(tmp_var).css('opacity',0.6);
		}

		
		if(i < tmp_nr || (i == tmp_nr && mouserover_pos > 0.5)){
			jQuery(tmp_var).removeClass(tmp_var2+'-2').removeClass(tmp_var2+'-3').addClass(tmp_var2);
		} else if(i == tmp_nr && mouserover_pos <= 0.5 && mouserover_pos != 0){
			jQuery(tmp_var).removeClass(tmp_var2+'-3').removeClass(tmp_var2).addClass(tmp_var2+'-2');
		} else {
			jQuery(tmp_var).removeClass(tmp_var2+'-2').removeClass(tmp_var2).addClass(tmp_var2+'-3');
		}
	}
}



function rhc_rating_error_alert(tmp_msg){
	jQuery('.cit_rhc_rating_ .rhc_rating_alert_dialog').html('<div class="alert alert-error"><button type="button" class="close fui-cross" data-dismiss="alert"></button><div class="text">'+tmp_msg+'</div></div>');
	jQuery('.cit_rhc_rating_ .rhc_rating_alert_dialog').css({ opacity: 0.0 }).show().fadeTo( "slow" , 1.0);
}



function rhc_rating_next(postID){
	if(rhc_rating_lockdown == false){
		rhc_rating_lockdown = true;
		var object = new Object();
		object.firstname = jQuery('.cit_rhc_rating_ #rhc_rating_firstname').val();	
		object.lastname = jQuery('.cit_rhc_rating_ #rhc_rating_lastname').val();
		object.user_email = jQuery('.cit_rhc_rating_ #rhc_rating_email').val();
		object.logintype = 'MANUAL';	
		object.user_url = '';	
		object.user_image_url = '';
		var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);
		
		if(object.firstname == undefined || object.firstname == 'undefined' || object.firstname == '' || object.firstname.length < 2){
			rhc_rating_error_alert(rhc_rating_vars.pleaseFirstName );
			jQuery('.cit_rhc_rating_ #rhc_rating_firstname').focus();
			rhc_rating_lockdown = false;
			return false;
		}
		if(object.lastname == undefined || object.lastname == 'undefined' || object.lastname == '' || object.lastname.length < 2){
			rhc_rating_error_alert(rhc_rating_vars.pleaseLastName);
			jQuery('.cit_rhc_rating_ #rhc_rating_lastname').focus();
			rhc_rating_lockdown = false;
			return false;
		}
		
		if(object.user_email == undefined || object.user_email == 'undefined' || object.user_email == '' || object.user_email.length < 2 || !pattern.test(object.user_email) ){
			rhc_rating_error_alert(rhc_rating_vars.pleaseValitEmail);
			jQuery('.cit_rhc_rating_ #rhc_rating_email').focus();
			rhc_rating_lockdown = false;
			return false;
		}
		
		
		
		rhc_rating_social_connect_done(object,postID,'manual')
	}
	return false;
}

function rhc_rating_social_connect(postID,socialtype){
	if(rhc_rating_lockdown == false){
		if(socialtype == 'twitter' || socialtype == 'wp'){
			var rating = jQuery('.cit_rhc_rating_ #manual_select_show_rating').attr('data-rating-selected');
			var object = new Object();
			object.postID = postID;
			object.rating = rating;
			if(typeof(rhc_rating_vars.event_rdate) !== 'undefined' && rhc_rating_vars.event_rdate != '' && rhc_rating_vars.event_rdate != ',' && rhc_rating_vars.event_rdate != ' ,' && rhc_rating_vars.event_rdate != ' , ' && rhc_rating_vars.event_rdate != ', '){
				object.event_rdate = rhc_rating_vars.event_rdate
			}
			rating_connections_type.loginby(socialtype,'rhc_rating_social_connect_done',object)
		} else {
			rating_connections_type.loginby(socialtype,'rhc_rating_social_connect_done',postID)
		}

		return false;
	}
}

function rhc_rating_social_connect_done(tmpdata,postID,datatype){
	var rating = jQuery('.cit_rhc_rating_ #manual_select_show_rating').attr('data-rating-selected');
	var comment = jQuery('.cit_rhc_rating_ #rhc_rating_comment').val();	
	var firstname = '';	
	var lastname = '';
	var user_email = '';
	var logintype = '';	
	var user_url = '';	
	var user_image_url = '';	


	if(typeof(tmpdata) == 'undefined' || tmpdata == '' || typeof(postID) == 'undefined' || postID == '' || typeof(datatype) == 'undefined' || datatype == ''){
			rhc_rating_error_alert('Error no data resived, try again or contact support');
			rhc_rating_lockdown = false;
			return false;	
	}

	if(datatype =='manual'){
		firstname = tmpdata.firstname;	
		lastname = tmpdata.lastname;
		user_email = tmpdata.user_email;
		logintype = tmpdata.logintype;	
		user_url = tmpdata.user_url;	
		user_image_url = tmpdata.user_image_url;
	} else if(datatype =='facebook'){
		if(typeof (tmpdata.error)  != 'undefined'){
			if(typeof (tmpdata.error.code) != 'undefined'){
				rhc_rating_social_connect(postID,'facebook');
				return false;
			}
		}
		
		firstname = tmpdata.first_name;	
		lastname = tmpdata.last_name;
		user_email = tmpdata.id+'@facebook.com';
		logintype = 'FACEBOOK';	
		user_url = tmpdata.link;	
		user_image_url = tmpdata.picture.data.url;
	} else if(datatype =='googleplus') {
		firstname = tmpdata.name.givenName;	
		lastname = tmpdata.name.familyName;
		user_email = tmpdata.id+'@googleplus';
		logintype = 'GOOGLEPLUS';	
		user_url = tmpdata.url;	
		user_image_url = tmpdata.image.url;
		res = user_image_url.split("?");
		user_image_url = res[0];
	} else if(datatype =='linkedin') {
		firstname = tmpdata.firstName;	
		lastname = tmpdata.lastName;
		user_email = tmpdata.id+'@linkedin';
		logintype = 'LINKEDIN';	
		user_url = tmpdata.publicProfileUrl;	
		user_image_url = tmpdata.pictureUrl;
	} else if(datatype =='twitter') {
		firstname = tmpdata.firstName;	
		lastname = tmpdata.lastName;
		user_email = '@'+tmpdata.screen_name;
		logintype = 'TWITTER';	
		user_url = 'https://twitter.com/'+tmpdata.screen_name;	
		user_image_url = tmpdata.profile_image_url;
	} else if(datatype =='wp') {
		firstname = tmpdata.firstname;	
		lastname = tmpdata.lastname;
		user_email = tmpdata.email;
		logintype = 'WP';	
		user_url = '';	
		user_image_url = '';
	}
	
	
	
	
	if(rating == undefined || rating == 'undefined' || rating == 'NaN' || rating == NaN || rating <= 0 || rating > 10){
		rhc_rating_error_alert(rhc_rating_vars.pleaseRate);
		rhc_rating_lockdown = false;
		return false;
	}
	
	
	
	
	 jQuery('.cit_rhc_rating_ .fc-view-loading').css({ opacity: 0.0 }).show().fadeTo( "slow" , 1.0);
	 jQuery.post(rhc_rating_vars.siteurl+'/?rhc_rating_data=true',{'rhc_rating_data':true,'rhc_rating_fn':'saveanswer','rhc_rating_postID':postID,'rhc_rating_firstname':firstname,'rhc_rating_lastname':lastname,'rhc_rating_email':user_email,'rhc_rating_comment':comment,'rhc_rating_extern':logintype,'rhc_rating_externUrl':user_url,'rhc_rating_externUrlPhoto':user_image_url,'rhc_rating_rating':rating,'event_rdate':rhc_rating_vars.event_rdate},function(data){		 
		var rating = jQuery('.cit_rhc_rating_ #manual_select_show_rating').attr('data-rating-selected');
		rhc_rating_lockdown = false;
		if(datatype == 'facebook' && rhc_rating_vars.fb_pub && parseFloat(rating) > 0){
			rhc_rating_vars.fb_tw_title = rhc_rating_vars.fb_tw_title.replace('[RATING]',rating);
			rhc_rating_vars.fb_tw_subtitle = rhc_rating_vars.fb_tw_subtitle.replace('[RATING]',rating);
			rhc_rating_vars.fb_tw_text = rhc_rating_vars.fb_tw_text.replace('[RATING]',rating);
			FB.ui(
			  {
			    method: 'feed',
			    name: rhc_rating_vars.fb_tw_title,
			    link: rhc_rating_vars.link,
			    picture: rhc_rating_vars.picurl,
			    caption: rhc_rating_vars.fb_tw_subtitle,
			    description: rhc_rating_vars.fb_tw_text
			  }
			);	
		}

		if(data.rating_accept_inputs != true){
			rhc_rating_operatedata_data(data);
		} else {
			rhc_rating_openwindow('#rhc_rating_pos1','#rhc_rating_pos2');
		}
		
	},'json');
}

function rhc_rating_operatedata_data(data){
	if(data.R=='DONE'){
		if(typeof(data.AVATAR) !== 'undefined' && data.AVATAR != '' && data.AVATAR != 'undefined'){
			jQuery('.cit_rhc_rating_ #rhc_rating_pos3 #comment_avatar_place').prepend(data.AVATAR)
		}			
		
		rhc_rating_icon_selected(0,0);
		jQuery('.cit_rhc_rating_ .rhc_rating_alert_dialog').hide();
		jQuery('.cit_rhc_rating_ .rhc_rating_success_dialog').hide();
	
		jQuery('.cit_rhc_rating_ #rhc_rating_firstname').val('');
		jQuery('.cit_rhc_rating_ #rhc_rating_lastname').val('');
		jQuery('.cit_rhc_rating_ #rhc_rating_email').val('');
		jQuery('.cit_rhc_rating_ #rhc_rating_comment').val('');
	
		jQuery('.cit_rhc_rating_ .fc-view-loading').hide();
		jQuery('.cit_rhc_rating_ .rhc_rating_success_dialog .text').html(data.MSG);
		jQuery('.cit_rhc_rating_ .rhc_rating_success_dialog').css({ opacity: 0.0 }).show().fadeTo( "slow" , 1.0);

		
		
		rhc_rating_openwindow('#rhc_rating_pos1','#rhc_rating_pos2');
		 
		jQuery('.cit_rhc_rating_ #manual_select_show_rating').removeAttr('data-rating-selected');
		
		window.setTimeout(function() {
			rhc_add_count(data.RATING);
		}, 1000);
		

		rhc_rating_lockdown = false;
		
		return false;
	} else {
		jQuery('.cit_rhc_rating_ .fc-view-loading').hide();
		rhc_rating_error_alert(data.MSG);
		rhc_rating_lockdown = false;
		return false;
	}
}