function galleryPopup(id,gxmlpath,gmodule,gtype,gid){
	var urlString = "popup.php?id="+id+"&xmlpath="+gxmlpath+"&gmodule="+gmodule+"&gtype="+gtype+"&gid="+gid;
	gallerypopup = window.open(urlString,"gallerywin","scrollbars=no,width=820,height=570,status=no,resizable=yes");
	if (gallerypopup && gallerypopup.focus){
		gallerypopup.focus();
	}else if (galllerywin && gallerywin.focus){
		gallerywin.focus();
	}
}

function toggleComments(){
	showhide('comments');
}
function ajax_update(data, id) {
    var myAjax = new Ajax.Updater(
		id,
        'ajaxsrv.php',
        {method: 'post', parameters: data}
    );
}

Effect.MyScrollTo = function(element) {
  var options = arguments[1] || { },
    scrollOffsets = document.viewport.getScrollOffsets(),
    elementOffsets = $(element).cumulativeOffset(),
    max = (window.height || document.body.scrollHeight) - document.viewport.getHeight();

  if (options.offset) elementOffsets[1] += options.offset;

  return new Effect.Tween(null,
    scrollOffsets.top,
    //elementOffsets[1] > max ? max : elementOffsets[1],
    elementOffsets[1],
    options,
    function(p){ scrollTo(scrollOffsets.left, p.round()) }
  );
};

/* Code to Set Iframe Element Height to Iframe Content Height */
function getDocHeight(doc) {
  var docHt = 0, sh, oh;
  if (doc.height) docHt = doc.height;
  else if (doc.body) {
    if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
    if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
    if (sh && oh) docHt = Math.max(sh, oh);
  }
  return docHt;
}

function setIframeHeight(iframeName) {
  var iframeWin = window.frames[iframeName];
  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
  if ( iframeEl && iframeWin ) {
    iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous
    var docHt = getDocHeight(iframeWin.document);
    // need to add to height to be sure it will all show
    if (docHt) iframeEl.style.height = docHt + 30 + "px";
  }
}

function loadIframe(iframeName, url) {
  if ( window.frames[iframeName] ) {
    window.frames[iframeName].location = url;
    return false;
  }
  else return true;
}

function scrollToFromIframe(element, offsetHeight) {
	new Element.scrollTo(element)
}


	function showhide(id){
		if (document.getElementById){
		obj = document.getElementById(id);
		if (obj.style.display == "none"){
		obj.style.display = "";
		} else {
		obj.style.display = "none";
		}
		}
		}
		
		
// Function to allow ajax delete comment to Admin users
var adminHideComment = function (commentid) {
	//alert(commentid);
	new Effect.Fade($('comment_' + commentid));
	new Ajax.Request( 'ajaxsrv.php', {
		method: 'post',
		parameters: {
			action: 'admin_delete_comment',
			module: 'content_discussion',
			commentid: commentid
		},
		onSuccess: function(transport) {
    		var notice = $('notice');
    		if (transport.responseText=='ok') {
      			//alert('ok');
    		} else {
     			alert(transport.responseText);
    		}
  		}
	});
}

	
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.
   {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
   }
   
var sUserAgent = navigator.userAgent;
var isOpera = sUserAgent.indexOf("Opera") > -1;
if(window.attachEvent && !isOpera){ window.attachEvent("onload", correctPNG);}
