/**
 * functions for the comments functionality
 *
 * [2007-10-01 as] created
 *
 * $Rev: 981 $ Revision of last commit
 * $Author: jan $ Author of last commit
 * $Date: 2009-05-26 13:59:49 +0200 (Di, 26 Mai 2009) $ Date of last commit
 */


/**
 * Comment functionality
 *
 * [2007-10-02 as] created
 *
 * @since 0.1
 */
function showComments(rel2root, sid, type, pi, vi, area_id, evi, mid, page, lang, shop)
{
  // changing parameter because of caching problem ie 6: t
  var tmp = new Date(), ext;
  var t = tmp.getSeconds();

  // Typ übertragen
  renderCommentForm.box.ext = arguments[11];

  document.onload = JSONRequest( rel2root+'_inc/json/comments.php?action=show_comments&language='+lang+'&shop='+shop+'&sid='+sid+'&type='+type+'&product_id='+pi+'&variation_id='+vi+'&area_id='+area_id+'&event_id='+evi+'&mid='+mid+'&page='+page+'&'+t+'&uKey='+renderCommentForm.getExt(), renderComments);
}

// own profile
function showCommentsUser(rel2root, sid, page, lang, shop)
{
  // changing parameter because of caching problem ie 6: t
  var tmp = new Date();
  var t = tmp.getSeconds();

  document.onload = JSONRequest( rel2root+'_inc/json/comments.php?action=show_comments_user&language='+lang+'&sid='+sid+'&page='+page+'&shop='+shop+'&'+t, renderComments );
}

// viewprofile
function showCommentsOtherUser(rel2root, sid, uid, page, lang, shop)
{
  // changing parameter because of chaching problem ie 6: t
  var tmp = new Date();
  var t = tmp.getSeconds();

  document.onload = JSONRequest( rel2root+'_inc/json/comments.php?action=show_comments_user&language='+lang+'&sid='+sid+'&uid='+uid+'&page='+page+'&shop='+shop+'&'+t, renderComments );
}

function renderComments( requestObject )
{
  var dataHTML = '';

  // building an object called data
  var data = JSON.parse(requestObject.responseText);

  var el = document.getElementById('box_comments'+((data.ukey != null) ? data.ukey : ""));

  // you can get data by using the DOM syntax
  dataHTML = data.comments;

  el.innerHTML = dataHTML;

	// shadow layout resize if in shop
	if(shop == true) {
		resize_layout(); // new Array("FF 3", "FF 2")		
	}
}

function showCommentForm(rel2root, sid, type, pi, vi, area_id, evi, mid, page, lang, shop)
{
  // changing parameter because of caching problem ie 6: t
  var tmp = new Date();
  var t = tmp.getSeconds();

  // Typ übergeben
  renderCommentForm.box.ext = arguments[11];
  document.onload = JSONRequest( rel2root+'_inc/json/comments.php?action=comment_form&language='+lang+'&sid='+sid+'&type='+type+'&product_id='+pi+'&variation_id='+vi+'&area_id='+area_id+'&event_id='+evi+'&mid='+mid+'&page='+page+'&shop='+shop+'&'+t+'&uKey='+renderCommentForm.getExt(), renderCommentForm.request );

  setTimeout("document.getElementById('comment"+renderCommentForm.getExt()+"').focus()", 500);
}

var renderCommentForm = {

	box: {
		    name: "comment_form_box",
		    ext: ""
	     },

	getExt: function() {

		return ( (typeof renderCommentForm.box.ext != "undefined") ? renderCommentForm.box.ext : "" );
	},

	getBoxName: function() {

		return (renderCommentForm.box.name+renderCommentForm.getExt());
	},

	request: function(requestObject) {

	    var dataHTML = '';

        // building an object called data
        var data = JSON.parse(requestObject.responseText);

        var el = document.getElementById(renderCommentForm.getBoxName());

        if ( data.comment_form )
  		{
    	  dataHTML = data.comment_form;
          el.innerHTML = dataHTML;
  		}

  		if ( data.redirect )
  		{
    	  dataHTML = data.redirect;
    	  window.location.href = dataHTML;
  		}

			// shadow layout resize if in shop
			if(shop == true) {
				resize_layout(); // new Array("FF 3", "FF 2")				
			}
	}
};

function reqtest(requestObject) {

  //alert(requestObject.responseText);
}

function submitComment(rel2root, sid, type, pi, vi, area_id, evi, mid, page, lang, shop)
{
  // changing parameter because of caching problem ie 6: t
  var tmp = new Date();
  var t = tmp.getSeconds();

  // Typ übergeben
  renderCommentForm.box.ext = arguments[11];

  if ( !lang ) lang='de';
  comment = document.getElementById("comment"+renderCommentForm.getExt()).value;

  // Form hiden
  if(renderCommentForm.getExt().length > 0) {
  	document.getElementById(renderCommentForm.getBoxName()).innerHTML = "";
  }

  document.onload = JSONRequest( rel2root+'_inc/json/comments.php?action=submit_comment&sid='+sid+'&type='+type+'&product_id='+pi+'&variation_id='+vi+'&area_id='+area_id+'&event_id='+evi+'&mid='+mid+'&language='+lang+'&shop='+shop+'&comment='+encodeURIComponent(comment)+'&'+t , reqtest);

  window.setTimeout("showComments('"+rel2root+"', '"+sid+"', '"+type+"', '"+pi+"', '"+vi+"', '"+area_id+"', '"+evi+"', '"+mid+"', '"+page+"', '"+lang+"', '"+shop+"', '"+renderCommentForm.getExt()+"')", 100);
}

