// JavaScript Document

	rn.pAddRetailerItem = function(retailerid, itemid, url) {
		rn.rmsSend({ mod:'product', tar:'product', op:'pAddRetailerItem', retailerid:retailerid, itemid:itemid, url:url },rn.pAddRetailerItemr);	
	}

	rn.pAddRetailerItemr = function(oRmsR) {
		if (oRmsR['rmsS']==true)
		{
			alert('added');
		}
		else if (oRmsR['rmsS']==false)
		{
			alert(oRmsR['rmsM']);
		}	
		else
		{
			alert('Communication Error');			
		}
    };


	rn.pAddRec = function(itemid, reason) {
		rn.rmsSend({ mod:'product', tar:'product', op:'pAddRec', itemid:itemid, reason:reason },rn.pAddRecr);	
	}
	
	rn.pEditRec = function(itemid, reason) {
		rn.rmsSend({ mod:'product', tar:'product', op:'pEditRec', itemid:itemid, reason:reason },rn.pAddRecr);	
	}
	
	rn.pGetRecs = function(itemid, reason) {
		rn.rmsSend({ mod:'product', tar:'product', op:'pGetRecs', itemid:itemid, pointer:pointer },rn.pGetRecsr);	
	}

	rn.pAddRecr = function(oRmsR) {
		if (oRmsR['rmsS']==true)
		{
			recclickfinish();
		}
		else if (oRmsR['rmsS']==false)
		{
			alert(oRmsR['rmsM']);
		}	
		else
		{
			alert('Communication Error');			
		}
    };
	
	rn.pGetRecsr = function(oRmsR) {
		if (oRmsR['rmsS']==true)
		{
			//alert(oRmsR['rmsD']['recs']);
			
			var i=0;
			$('#opinions').html('');
			for (i=oRmsR['rmsD']['recs'].length-1;i>=0;i--) {
				
				
				if (oRmsR['rmsD']['recs'][i]['reason'].length==0) {
					var newrec = $('#recblanknoquote').clone();
					$(newrec).find('#blankreason').html(oRmsR['rmsD']['recs'][i]['username']+' recommends it');
					$(newrec).find('#headblank').attr('src',oRmsR['rmsD']['recs'][i]['imageurl']);
					$(newrec).find('#profileblank').attr('href',oRmsR['rmsD']['recs'][i]['userurl']);
					
					$(newrec).prependTo('#opinions').show();
				} else {
					var newrec = $('#recblank').clone();
					$(newrec).find('#blankreason').html(oRmsR['rmsD']['recs'][i]['reason']);
					$(newrec).find('#headblank').attr('src',oRmsR['rmsD']['recs'][i]['imageurl']);
					$(newrec).find('#profileblank').attr('href',oRmsR['rmsD']['recs'][i]['userurl']);
					//$(newrec).find('#delbut').attr('onclick','$$.delRec2('+oRmsR['rmsD']['recs'][i]['itemid']+','+oRmsR['rmsD']['recs'][i]['userid']+');');

					$(newrec).find('#delbut').click( function(tint) { 
					  return function() {
						 $$.delRec2(oRmsR['rmsD']['recs'][tint]['itemid'],oRmsR['rmsD']['recs'][tint]['userid']);
					  }
					  //
					  
					}(i)
					);
					
					//alert('$$.delRec2('+oRmsR['rmsD']['recs'][i]['itemid']+','+oRmsR['rmsD']['recs'][i]['userid']+');');
					$(newrec).prependTo('#opinions').show();
				}
				//.children('#blankreason').html(oRmsR['rmsD']['recs'][i]['reason']);
				//alert(oRmsR['rmsD']['recs'][i]['reason']);
			}
			
			$('#otherrecs').fadeIn();
		}
		else if (oRmsR['rmsS']==false)
		{
			alert(oRmsR['rmsM']);
		}	
		else
		{
			alert('Communication Error');			
		}
    };


	function showVideo(obj, vid) {
		$(obj).parent().append("<div style='text-align:center' class='video'></div>");
		$(obj).parent().find("div.video").append("<object height=450 width=400><param name='allowScriptAccess' value='always' /><param name='allowFullScreen' value='true' /><param name='menu' value='false' /><param name='Autoplay' value='true' /><param name='movie' value='http://www.Pinkbike.com/v/"+vid+"/?a=1' /><embed src='http://www.Pinkbike.com/v/"+vid+"/?a=1' type='application/x-shockwave-flash' allowFullScreen='true' Autoplay='true' width='450' height='400'/></object>");
		$(obj).removeAttr("onclick");
		$(obj).click(function() {
			$(obj).parent().find("div.video").toggle();
		});
	}


	rn.pAddActionPhotos = function(userid, itemid, photoids) {
		
		rn.rmsSend({ mod:'product', tar:'product', op:'pAddActionPhotos', uid:userid , itemid:itemid, photos:photoids },rn.pAddActionPhotosr);
    };
	
	rn.pAddActionPhotosr = function(oRmsR) {
		if (oRmsR['rmsS']==true)
		{
	
		}
		else if (oRmsR['rmsS']==false)
		{
			alert(oRmsR['rmsM']);
		}	
		else
		{
			alert('Communication Error');			
		}
    };

	var semaphore = true;
	rn.pSupportMan = function(userid, manid) {
		if (semaphore) {
			semaphore=false;
			rn.rmsSend({ mod:'product', tar:'product', op:'pSupportMan', uid:userid , manid:manid },rn.pSupportManr);
		}
    };
	
	rn.pSupportManr = function(oRmsR) {
		if (oRmsR['rmsS']==true)
		{
			$('#addsupport').fadeOut('fast', function() {
				$('#remsupport').fadeIn('fast'); 
				$('#supportcount').html(parseInt(parseInt($('#supportcount').html()))+1);
				semaphore=true;
			});
			
			
		}
		else if (oRmsR['rmsS']==false)
		{
			alert(oRmsR['rmsM']);
		}	
		else
		{
			alert('Communication Error');	
		}
    };
	
	rn.pDelRec = function(itemid) {
		rn.rmsSend({ mod:'product', tar:'product', op:'pDelRec', itemid:itemid },rn.pDelRecr);
    };
	
	rn.pDelRecr = function(oRmsR) {
		if (oRmsR['rmsS']==true)
		{
		}
		else if (oRmsR['rmsS']==false)
		{
			alert(oRmsR['rmsM']);
		}	
		else
		{
			alert('Communication Error');			
		}
    };
	
	rn.pUnSupportMan = function(userid, manid) {
		if (semaphore) {
			semaphore=false;
			rn.rmsSend({ mod:'product', tar:'product', op:'pUnSupportMan', uid:userid , manid:manid },rn.pUnSupportManr);
		}
    };
	
	rn.pUnSupportManr = function(oRmsR) {
		if (oRmsR['rmsS']==true)
		{
			$('#remsupport').fadeOut('fast', function() {
				$('#addsupport').fadeIn('fast');
				$('#supportcount').html(parseInt($('#supportcount').html())-1);
				semaphore=true;
			});
		}
		else if (oRmsR['rmsS']==false)
		{
			alert(oRmsR['rmsM']);
		}	
		else
		{
			alert('Communication Error');			
		}
    };