
function getQueryVariable(variable) {
	
  var query = window.location.search.substring(1);  
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  
  return 0;
} 


function postReview(){
	
	var gid = getQueryVariable('gid');
		var id = getQueryVariable('id');
		var gidLabel = '&gid=';
		var idLabel = '&id=';
	var serializedForm = "";
	
	if (id === 0){
		id = getQueryVariable('id');
		idLabel = '&id=';
	}
	
	var f = $('.formBlue');
	var action = f.attr('action');
//	var serializedForm = f.serialize()+ '&gid=' + id + '&addBtn=true';
	if (/event=view.venuedetails/.test(window.location)){			
		serializedForm = f.serialize()+ idLabel + first_venue_id + '&addBtn=true' + '&cid=' + cid;
	}else{
		serializedForm = f.serialize()+ idLabel + id + gidLabel + gid + '&addBtn=true';
	}
	 	
	//swap progress img with img button
//	$(".addBtn").attr('src', '/images/ajax/ajax-loader.gif');
	$(".addBtn").hide();		
	$(".addBtn").remove();
			
	$('#reviewText').after('<button value="true" name="addBtn" class="addBtnProgress" type="submit" style="border: 0pt none ; height: 27px;" src="/images/ajax/ajax-loader.gif"/>');			
	$('.addBtnProgress').attr("disabled", "true");
										
	$.post(action,
	      serializedForm,
	  function(data){		  	

		//  if(window.console) { window.console.log("Data returned: " + data); }
			retval = eval( "(" + $.trim(data) + ")" );

			// part 2
			
			$('div#ratingsReview').remove();
			$('.comment').remove();			
			
			//
			// get the form and reviews
			//					
			$('.colABoxRight').append(retval.msg);			
			$('.toolsRow div img').attr('src', '/images/starsLg' + retval.rating + '.gif');			
			$('.toolsRow div span').text('('+ retval.votes +')');
						
			// attach the jquery rating stars plugin to the stars on
			// the Ratings & Reviews form  
//			$('input[@type=radio].star').rating();
			$('.ratingStarsContainer').show();
						
			// attach thichbox to login						
//			tb_init('a.thickbox, area.thickbox, input.thickbox');
			
			//pass where to apply thickbox
									
			// global form focus listener - for clearing reviewText area 
			$('.formBlue .clearText').focus(function() {
				if(this.value == this.defaultValue) {
					this.value = '';
				}
			}).blur(function() {
				if(!this.value.length) {
					this.value = this.defaultValue;
				}
			});			
			
	  }); //post
					
	return false;					
}

$(document).ready(
	function(){						
				
		var gid = getQueryVariable('gid');
		var id = getQueryVariable('id');
		var gidLabel = '&gid=';
		var idLabel = '&id=';
		var args = "";  
		
		if (/event=view.venuedetails/.test(window.location)){			
			args = '&event=action.getcomments' + idLabel + id + '&cid=' + cid;
		}
		else{
			args = '&event=action.getcomments' + idLabel + id + gidLabel + gid;
		}
			 
		//
		// get comments/reviews
		//
		$.get( "/",
			   args,					 
			  function(data){				  				  					  		  	
				  	var retval = eval( "(" + $.trim(data) + ")" );
					 					
					try{			
							
						$('.toolsRow div img').attr('src', '/images/starsLg' + retval.rating + '.gif');
						$('.toolsRow div span').text('('+ retval.votes +')');							
										
						//
						// get the form and reviews
						//					
						$('.ratingreviews').replaceWith(retval.msg);
						
						// attach the jquery rating stars plugin to the stars on
						// the Ratings & Reviews form  
						$('input[@type=radio].star').rating();
						$('.ratingStarsContainer').show();
						// attach thichbox to login						
						tb_init('a.thickbox, area.thickbox, input.thickbox');
						
						//pass where to apply thickbox
												
						// global form focus listener - for clearing reviewText area 
						$('.formBlue .clearText').focus(function() {
							if(this.value == this.defaultValue) {
								this.value = '';
							}
						}).blur(function() {
							if(!this.value.length) {
								this.value = this.defaultValue;
							}
						});							
																																																											
					}catch(err){
	//					window.console.log("exception in remove: " + err);	
					}
																																							
		 }); // end GET			
		


	}
);



