/*$(document).ready(function(){
		$("#mr_menu").click(function() { fetchreviews();} );
		fetchreviews();
		 $("#logo")
		 .attr("style","cursor:pointer")
		 .click(function() { window.location="index.htm"
									});
});*/


function fetchreviews () {
    		$.ajax({
   			type: "POST",
   			url: "ajq_getrvw.php",
			dataType: "json",
   			success: function(jr){
     			logthis( "+Data gotten: " + jr.respz.logstring);
				$('#centreblock').html(jr.respz.html);
//				JT_init_additional('rvwimg') ==> moved to setupfetchedanchors
/*				$('#JT').remove()
				$('#JT_copy').remove()*/
				// keeps popups from spilling over, see jtp_bpm.js
/*				JT_init_additional('tipstoo')*/
				$('#centreblock').fadeIn('slow')  // in case it was hidden to show comments
				$('#commentcontainer').remove()

				setupfetchedanchors()
				DoenAjax_logbannerevent('page','rvw','rvw-28')
   			}
 		});
}


function DoenAjax_fetchrvwbypoststring(poststr) {
    		$.ajax({
   			type: "POST",
   			url: "ajq_getrvw.php",
			data: poststr,
			dataType: "json",
   			success: function(jr){
     			logthis( "=Data gotten: " + jr.respz.logstring);
/*				JT_init_additional('rvwimg')*/
				$('#rvwfragment').html(jr.respz.html);
				setupfetchedanchors()
				DoenAjax_logbannerevent('page','rvw','rvw-44')
   			}
 		});
}


function DoenAjax_fetchrvwforpic(picname) {
// first send the request for the review detail, which will return the record_id too
// then get the comments for this, which will send the div #rvwfragment
// slap the review in #rvwfragment, then post the comment for good measure
// ==> doesnt work, race conditions, plus Go Back doesnt have anywhere to go back to
    		$.ajax({
   			type: "POST",
   			url: "ajq_getrvw.php",
			data: "picname="+picname,
			dataType: "json",
   			success: function(jr){
     			logthis( "%Data gotten: " + jr.respz.logstring);
				var artno=jr.respz.record_id
				DoenAjax_fetchcomments_artno(artno,'r')
				DoenAjax_fetchrvwdetail(artno)
				setTimeout("resetgoback()",2000)
				DoenAjax_logbannerevent('page','rvw','rvw-66')
   			}
 		});
}

function resetgoback() {
				$('.goback')
					.attr('style','color:red')
					.unbind("click")
					.click(function() { window.location="index.htm"
							})
}

function DoenAjax_fetchrvwdetail(artno) {  //used to put all detail for review above user comment div
    		$.ajax({
   			type: "POST",
   			url: "ajq_getrvw.php",
			data: "record_id="+artno+"&forcomment=yes",  // allow some custom styling
			dataType: "json",
   			success: function(jr){
     			logthis( "Review fragment gotten: " + jr.respz.logstring);
				$('#rvwfragment').html(jr.respz.html);
				setupfetchedanchors()
				DoenAjax_logbannerevent('page','rvw','rvw-89')
   			}
 		});
}
function DoenAjax_fetchrvwdetail_indiv(artno,targetdiv) {  //used to put all detail for review in a specific targetdiv
    		$.ajax({
   			type: "POST",
   			url: "ajq_getrvw.php",
			data: "record_id="+artno,
			dataType: "json",
   			success: function(jr){
     			logthis( "Review fragment gotten: " + jr.respz.logstring);
				$('#commentcontainer').remove()
				$('#'+targetdiv).html(jr.respz.html).fadeIn("slow");
				setupfetchedanchors()
				DoenAjax_logbannerevent('page','rvw','rvw-89')
   			}
 		});
}


function DoenAjax_fetchrvwdetail_intodiv(artno,archdiv) {  //used to put all detail for review in archive cell
// not suitable for instances where editing is required
    		$.ajax({
   			type: "POST",
   			url: "ajq_getrvw.php",
			data: "record_id="+artno+"&noedit=yes&putcommenttag=yes",
			dataType: "json",
   			success: function(jr){
				archdiv.append(jr.respz.html);
// mini of setupfetchedanchors()
				$('.randc').each(function(){
						$(this).unbind("click")
							.click(function(){
								artno=$(this).parents('.specscontainer').attr('thisrec')

								DoenAjax_fetchcomments_artno(artno,'r')
								DoenAjax_fetchrvwdetail(artno)
							})
						})


				DoenAjax_logbannerevent('arch','rvw','rvw-102')
   			}
 		});
}


function DoenAjax_fetchrvwstep(obj) {
	var poststr="step="+$(obj).attr("step")+"&type="+$(obj).parents('.rvwtopmidcell').attr('rvwtype')//+$(obj).attr("href")
//	alert(poststr)
//	return
    		$.ajax({
   			type: "POST",
   			url: "ajq_getrvw.php",
			data: poststr,
			dataType: "json",
   			success: function(jr){
     			logthis( "147:Data gotten: " + jr.respz.logstring);
				$('#centreblock').html(jr.respz.html);
				setupfetchedanchors()
				DoenAjax_logbannerevent('page','rvw','rvw-106')
   			}
 		});
}


function DoenAjax_fetchrvwtype (rvwtype) {
// 	DoenAjax_fetchrvwbypoststring("type="+rvwtype)
/*	alert(rvwtype)*/
    		$.ajax({
   			type: "POST",
   			url: "ajq_getrvw.php",
			data: "type="+rvwtype,
			dataType: "json",
   			success: function(jr){
     			logthis( "165:Data gotten by rvw type: "+rvwtype+"="+ jr.respz.logstring);
				$('#centreblock').html(jr.respz.html);
				setupfetchedanchors()
				DoenAjax_logbannerevent('page','rvw','rvw-124')
   			}
 		});
}

function setupfetchedanchors() {
	$('#JT').remove() // keeps popups from spilling over, see jtp_bpm.js
	$('#JT_copy').remove()
	$('.navanchoractive_rvwclass').each(function(){
								$(this).unbind("click")
									.click(function(){
										DoenAjax_fetchrvwstep(this)
									return false //SEO cancel a-tag
										})
								})

	$(".redigeer").each(function(i){ setClickable(this, i); })
	//$("select").change(function(){  saveChanges_select(this)  })
	$('.specscontainer').find("select").change(function(){  saveChanges_select(this)  })//.after('!')

	$("#addrec_rvw").unbind().click(function(){addrec_rvw('reviews')})
	$("#reread").unbind().click(function(){
/*			alert('refreshing '+$(this).attr("artno")+"\nto="+"centreblock")*/
			DoenAjax_fetchrvwdetail_indiv($(this).attr("artno"),"centreblock")
		})

	$('.goback')
			.unbind("click")
			.click(function() {
						$('#centreblock').fadeIn('slow')
						$('#commentcontainer').remove()
					})
			.addClass('clickable')


	$('#cdrlink').unbind("click")
			.click(function(){
			DoenAjax_fetchrvwtype('rvw_cd')
	})

	$('#vinyllink').unbind("click")
	 		.click(function(){
			DoenAjax_fetchrvwtype('rvw_vy')
	})
	$(".picform").each(function() {
			$(this).unbind()
			prepareUploadform(this,$(this).attr('id'))})

	$('.randc').each(function(){
						$(this).unbind("click")
							.click(function(){
								artno=$(this).parents('.specscontainer').attr('thisrec')

								DoenAjax_fetchcomments_artno(artno,'r')
								DoenAjax_fetchrvwdetail(artno)
							})
						})

	$('.mtof').unbind()
					.click(function(){
						getmailfriendform(this)
						})
					.addClass('clickable')




	$('.calendarButton')
					.calendar({autoPopUp: 'button',
							buttonImageOnly: true,
							buttonImage: 'calendar.gif',
							buttonText: 'Calendar'})
					.change(function(){saveChanges_direct(this) });

				try {
				if (popUpCal) {
					popUpCal.minDate = new Date(2007, 1 - 1, 26);
					popUpCal.maxDate = new Date(2020, 1 - 1, 26);
					popUpCal.dateFormat = 'YMD/';
				}
				}
				catch (fout) {}

				$("#logoff").click(function(){window.location="admin/logoff.php?dest=../articles.htm"})


	JT_init_additional('rvwimg')

}


