
function revealcode(e,code,id)
{
  e.parentNode.innerHTML = '<b>Code: '+code+'</b>';
  window.open('http://track.backendpro.com/'+id+'/href', "codes","width=200,height=130,menubar=no,resizable=yes,status=no,toolbar=no,scrollbars=yes");
  return false;
}


function AddBookmark()
{
 title = "CouponWalk - Coupon Codes and Discounts";
 url = "http://www.couponwalk.com/";

  var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
  if ( is_chrome || window.opera )
    alert( 'Press Ctrl-D to add a bookmark' );
  else
	if (window.sidebar) // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	else if( window.external ) // IE Favorite
		window.external.AddFavorite( url, title);
	else if(window.opera && window.print) // Opera Hotlist
		return true;
 }

function CreateBookmark()
{
  if (window.external)
    document.write('<img src="/images/folder_add.png"> <a href="javascript:AddBookmark()");">Add to Favorites</a>');
  else  if (window.sidebar)
    document.write('<img src="/images/folder_add.png"> <a href="javascript:AddBookmark()");">Bookmark Page</a>');
  else if (window.opera && window.print)
    document.write('<img src="/images/folder_add.png"> <a href="javascript:AddBookmark()");">Add Bookmark</a>');

  return false;
}

function vote(code,how)
{
  new Ajax.Request( '/ajax/vote', {
                      method: 'get',
                      parameters: { public_id: code, vote: how?'yes':'no' },
                      onComplete: function( transport, json )
                      {
                        //alert(json ? Object.inspect(json) : "no JSON object: "+transport.responseText);
                        if ( !json ) return;

                        d = $('rating_'+code);
                        d.innerHTML = json.rating;
                        if ( 1*json.rating>0 )
                          d.className = 'rating_positive';
                        else
                          d.className = 'rating_negative';
                        d.style.fontWeight = 'bold';
                      }
                  });
  
  return false;
}



var
  addcomment_balloon = null;

function create_addcomment_balloon( divname )
{
  addcomment_balloon = new HelpBalloon({
                          //returnElement: true,
                          titleStyle: 'font: bold 14px Verdana;',
                      		title: 'Add comment',
                      		dataURL: '/addcomment.htm',
                          anchorPosition: 'bottom left',
                      		fixedPosition: HelpBalloon.POS_BOTTOM_LEFT,
                      		icon: $(divname)
                      	});
}

function addcomment( code )
{
  addcomment_balloon.icon = $('icon_'+code);
  addcomment_balloon.show();
  document.form_addcomment.public_id.value = code;
  return false;
}

function addcomment_submit( )
{
  var author = document.form_addcomment.author.value;
  var comment = document.form_addcomment.comment.value;
  var public_id = document.form_addcomment.public_id.value;

  new Ajax.Request( '/ajax/addcomment', {
                      method: 'post',
                      parameters: { public_id: public_id, author: author, comment: comment },
                      onComplete: function( transport, json )
                      {
                        if ( !json ) return;

                        d = $('ajax_status');
                        d.innerHTML = json.response;

                      }
                  });


  return false;
}


function showcomments(code)
{
  new Ajax.Request( '/ajax/getcomments', {
                      method: 'get',
                      parameters: { public_id: code },
                      onComplete: function( transport, json )
                      {

                        //alert(json ? Object.inspect(json) : "no JSON object: "+transport.responseText);
                        if ( !json ) return;

                        d = $('rating_'+code);
                        text = '';
                        
                        for ( i=0; i<json.size(); i++ )
                          text += '<div class="commententry"><i>Posted by '+json[i].author+' on '+json[i].date+'</i><div>'+json[i].comment+'</div></div>';

                        var b = new HelpBalloon({
                          returnElement: true,
                          titleStyle: 'font: 8px;',
                      		title: '',
                      		content: text,
                          anchorPosition: 'bottom left',
                      		fixedPosition: HelpBalloon.POS_BOTTOM_LEFT,
                      		icon: $('icon_'+code)
                      	});

                        //d.appendChild( b.icon );
                        b.show();
                      	b.titleContainer.innerHTML = '<center><a href="#" onclick="return addcomment(\''+code+'\');"><img src="/images/silk/comment_add.png"> Add comment</a></center>';


                      }
                  });

  return false;
}



