  function ToggleSendToFriend() {
    sendToFriendForm = document.getElementById('SendToFriendForm');
    sendToFriendButton = document.getElementById('SendToFriendButton');

    if (sendToFriendForm.style.visibility == "hidden") {
      sendToFriendForm.style.visibility = "visible";
      sendToFriendForm.style.display = 'block';
    } else {
      sendToFriendForm.style.visibility = "hidden";
      sendToFriendForm.style.display = 'none';
    }

    //sendToFriendForm.style.left = getposOffset(sendToFriendButton, "left") - sendToFriendForm.offsetWidth + sendToFriendButton.offsetWidth;
    sendToFriendForm.style.left = getposOffset(sendToFriendButton, "left") - (sendToFriendForm.offsetWidth / 2) + (sendToFriendButton.offsetWidth / 2);
    sendToFriendForm.style.top = getposOffset(sendToFriendButton, "top") + sendToFriendButton.offsetHeight;
  }
  
  function ToggleAddComment() {
    commentMenu = document.getElementById('CommentMenu');
    commentButton = document.getElementById('CommentButton');

    commentMenu.style.left = getposOffset(commentButton, "left");
    commentMenu.style.top = getposOffset(commentButton, "top") + commentButton.offsetHeight;

    if (commentMenu.style.visibility == "hidden") {
      commentMenu.style.visibility = "visible";
      commentMenu.style.display = 'block';
    } else {
      commentMenu.style.visibility = "hidden";
      commentMenu.style.display = 'none';
    }
  }
  
  function ToggleGalleryThumbnail(pictureID) {
    largeThumbDiv = document.getElementById('SecondaryThumbDiv' + pictureID);
    smallThumb = document.getElementById('SmallThumb' + pictureID);

    if (largeThumbDiv.className == "secondaryThumbnailHidden") {
      largeThumbDiv.className = "secondaryThumbnailPopup";
      largeThumbDiv.style.left = getposOffset(smallThumb, "left") - ((largeThumbDiv.offsetWidth - smallThumb.offsetWidth) / 2) + "px";
      largeThumbDiv.style.top = getposOffset(smallThumb, "top")  - ((largeThumbDiv.offsetHeight - smallThumb.offsetHeight) / 2) + "px";
      setTimeout(function() { largeThumbDiv.style.visibility = "visible"; }, 5);
    } else {
	  largeThumbDiv.className = "secondaryThumbnailHidden";
    }
  }
  
  function ToggleRateMenu() {
    rateMenu = document.getElementById('RateMenu');
    rateButton = document.getElementById('RateButton');

    rateMenu.style.left = getposOffset(rateButton, "left");
    rateMenu.style.top = getposOffset(rateButton, "top") + rateButton.offsetHeight;

    if (rateMenu.style.visibility == "hidden") {
      rateMenu.style.visibility = "visible";
      rateMenu.style.display = 'block';
    } else {
      rateMenu.style.visibility = "hidden";
      rateMenu.style.display = 'none';
    }
  }

  function ToggleSearchMenu() {
    searchMenu = document.getElementById('SearchMenu');
    searchButton = document.getElementById('SearchButton');

    searchMenu.style.left = getposOffset(searchButton, "left");
    searchMenu.style.top = getposOffset(searchButton, "top") + searchButton.offsetHeight;

    if (searchMenu.style.visibility == "hidden") {
      searchMenu.style.visibility = "visible";
      searchMenu.style.display = 'block';
    } else {
      searchMenu.style.visibility = "hidden";
      searchMenu.style.display = 'none';
    }
  }

function getposOffset(what, offsettype){
  var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
  var parentEl=what.offsetParent;
  while (parentEl!=null){
    totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
    parentEl=parentEl.offsetParent;
  }
  return totaloffset;
}

function ToggleMenuOnOff (menuName) {
    menu = document.getElementById(menuName);

    if (menu.style.display == 'none') {
      menu.style.display = 'block';
    } else {
      menu.style.display = 'none';
    }

}

function PopupWin(obj)
{
	if (!obj) return;

	if (!obj.src) return;

	var img = new Image();
	img.onload = function()
	{		
		
		sw=(screen.width-this.width)/2;
		sh=(screen.height-this.height)/2;
		title = this.alt =="" ? "Cafico: Image View": "Cafico" + this.alt;
		newwin=window.open('','newwin','width='+this.width+',height='+this.height+',scrollbars=0,menubars=0,toolbars=0,loca tion=0,directories=0,status=0,top='+sh+',left='+sw+'');
		newwin.document.open();
		newwin.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n');
		newwin.document.write('"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');
		newwin.document.write('\n<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />\n');
		newwin.document.write('<meta http-equiv="Imagetoolbar" content="no" />\n');
		newwin.document.write('<title>'+title+'</title>\n');
		newwin.document.write('</head>');
		newwin.document.write('<body style="margin:0;padding:0">\n<img src="'+this.src+'" width="'+this.width+'" height="'+this.height+'" />');
		newwin.document.write('\n</body></html>');
		newwin.document.close();
		newwin.focus();
		
	}
	img.src= obj.src;
	
	
	return false;
}
function OpenWindow (target) { 
	if (target != '')
		window.open(target, "_Child", "toolbar=no,scrollbars=yes,resizable=yes,width=400,height=400"); 
}

function OpenNewWindow (target) { 
	if (target != '')
		window.open(target, "", ""); 
}

function OpenPostWindow (target) { 
	if (target != '')
		window.open(target, "_Child", "resizable=yes,width=500,height=700"); 
}

function showImageDialog(imageGalleryUrl, imageGalleryPath, obj, objImg)
{	
	url = imageGalleryUrl.replace(/\{0\}/g,imageGalleryPath);	
	url = url.replace(/\{1\}/g,'image');	
	url += "&ftb=" + obj + ":" + objImg;

	var gallery = window.open(url,'gallery','width=700,height=600,toolbars=0,resizable=1');
	gallery.focus();	
	
}


function setImage(objId, src)
{
		
	arrayObjs = objId.split(":")	
	
	obj = document.getElementById(arrayObjs[0])
	if (obj)
		obj.value = src;
		
	PreviewImage(src, arrayObjs[1]);		
}

function PreviewImage(imgSrc, objId)
{	
	
	obj = document.getElementById(objId)
	if (obj)
		obj.src = imgSrc;
		
}

// set on event onload of image
function ScaleImage(obj, rectang_width, rectang_height)
{	
	if (rectang_height == 0) return;
	
	var rectang_scale = rectang_width / rectang_height;
		
	var temp = new Array();
	temp[0] = obj.src;	
	
	// resize	
	if (obj.width>rectang_width || obj.height>rectang_height)
	{		
		var scale = obj.width/obj.height;
		if (scale > rectang_scale)
		{
			temp[1] = rectang_width;
			temp[2] = Math.round(rectang_width * obj.height / obj.width);
		} 
		else 
		{
			temp[1] = Math.round(rectang_height * obj.width / obj.height);
			temp[2] = rectang_height;
		}
	} 
	else 
	{
		temp[1] = obj.width;
		temp[2] = obj.height;
		
		
	}	
	
	obj.width = temp[1];	
	obj.height = temp[2];
	
	
}

// add by khuong
// add img src 
function commitFlashObject(_obj, _container){
	_output=""
	_paramoutput=""
	_src=""
	_ver=""
	_imgalt = ""
	for(_cO in _obj){
		if (_cO !="imgalt")
		{
			_output+=_cO+"=\""+_obj[_cO]+"\" "
			_paramoutput+="<param name="+_cO+" value=\""+_obj[_cO]+"\">";
			if(_cO=="movie")_src="src=\""+_obj[_cO]+"\"";
			if(_cO=="version")_ver=_obj[_cO];
		}
		else
		{
			_imgalt = _obj[_cO];
		}
	}
	if(_ver=="")_ver="8,0,0,0"
	ihtm="<object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="+_ver+" "+_output+">\n"
	ihtm+=_paramoutput+"\n"
	ihtm+="<embed "+_src+" pluginspage=http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash type=application/x-shockwave-flash "+_output+">\n";
	ihtm+="</embed>\n";
	if (_imgalt != "")
		ihtm+="<img src=\"" + _imgalt  + "\" border=\"0\" alt=\"\"  />"
		
	ihtm+="</object>\n";
	document.getElementById(_container).innerHTML=ihtm	
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function doFocus(id)
{
	var obj = document.getElementById(id);
	if (obj)
	{
		obj.focus();
	}
}