function deleteItem(site_url, item_id ,return_url){
	if(confirm("Do you want to delete?")){
		window.location.href = site_url + "petspace_action.php?mode=delete_item&item_id="+item_id+"&url="+return_url;
	}
}
function hideShareImg(site_url, item_id){
	var tbl = document.getElementById("tbl_share_image" + item_id);
	var img = document.getElementById("img_share_image" + item_id);
	tbl.style.display = "none";
	img.src = site_url+"images/down.gif";
}
function showHideMoreInfo(srcObj, item_id)
{
	var div = document.getElementById("view_item_detail" + item_id);
	if(div.style.display == "none")
	{
		div.style.display = "";
		srcObj.innerHTML = "less info";
	}
	else
	{
		div.style.display = "none";
		srcObj.innerHTML = "more info";
	}
}
function showHideShareImg(site_url, item_id)
{
	var tbl = document.getElementById("tbl_share_image" + item_id);
	var img = document.getElementById("img_share_image" + item_id);
	if(tbl.style.display == "none")
	{
		tbl.style.display = "";
		img.src = site_url+"images/up.gif";
	}
	else
	{
		tbl.style.display = "none";
		img.src = site_url+"images/down.gif";
	}
}

function image_load_fadeIn(objId, opacity, maxWidth) {
  if (document.getElementById(objId)) {
    var obj = document.getElementById(objId);
	var holder = document.getElementById(objId+"_holder");
	
	if(obj.width > maxWidth){
		obj.width = maxWidth;
	}
    if (opacity <= 100) {
      image_load_setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("image_load_fadeIn('"+objId+"',"+opacity+","+maxWidth+")", 100);
    }
	if(opacity == 100){		
		holder.style.backgroundImage = "none";
	}
  }
}
function image_load_setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}
function image_load_initImage(imageIdArray, maxWidth) {
  for(var i= 0; i < imageIdArray.length; i++){
	  //imageId = 'thephoto';
	  var image = document.getElementById(imageIdArray[i]);
	  if(image){
		  image_load_setOpacity(image, 0);
		  image.style.visibility = 'visible';
		  image_load_fadeIn(imageIdArray[i],0, maxWidth);
	  }
  }
}
/** comment_line script **/
var comment_line_xmlHttp;
var comment_line_tableId_current;
var comment_line_currentRowId = -1;
function comment_line_deleteComment(site_url, srcCtrl, line_comment_id, tableId, tableRowId, login){
	if(!confirm("Do you want to delete the comment?")){return;}
	if(comment_line_currentRowId > -1){alert("Please try again."); return;}
	var pwd;
	var pwd_val="";
	if(!login){
		pwd = document.getElementById("cmtLineItemPwd_" + line_comment_id);
		if(pwd.value.trim() == ""){
			alert("Please input password.");
			pwd.focus();
			return;
		}
		pwd_val = pwd.value.trim();
	}
	comment_line_xmlHttp=GetXmlHttpObject();
	if (comment_line_xmlHttp==null)
 	{
 		alert ("Browser does not support HTTP Request");
 		return; 
 	}
	comment_line_currentRowId = document.getElementById(tableRowId).id; //srcCtrl.parentElement.parentElement.rowIndex;
	comment_line_tableId_current = tableId;
	var url=site_url+"petspace_action.php";
	url=url+"?mode=delete_line_comment&line_comment_id=" + line_comment_id+ "&pwd="+pwd_val;
	comment_line_xmlHttp.onreadystatechange=comment_line_commentDeleted ;
	comment_line_xmlHttp.open("GET",url,true);
	comment_line_xmlHttp.send(null);
}
function comment_line_commentDeleted(){
	if (comment_line_xmlHttp.readyState==4 || comment_line_xmlHttp.readyState=="complete")
 	{ 
		var txt = comment_line_xmlHttp.responseText;		
		if(txt.length < 1) return;
		if(txt.substring(0,1)=="@"){
			alert(txt.substring(1));
			return;
		}
		if(txt == "true"){
			var tbl = document.getElementById(comment_line_tableId_current);
			var tblRow = document.getElementById(comment_line_currentRowId);
			tbl.deleteRow(tblRow.rowIndex);			
			tblRow.style.display = "none";
			comment_line_currentRowId = -1;
		}
 	}
}

var comment_line_newRowId;
var comment_line_current_item_id;
function comment_line_writeComment(site_url, itemId, tableId, txtId, login){
	var txt_val, name_val="", pwd_val="";
	var txt= document.getElementById(txtId);
	if(txt.value.trim() == ""){
		alert("Please input comment!");
		txt.focus();
		return false;
	}
	txt_val =txt.value.trim();
	var name, pwd;
	if(login != "true"){
		name = document.getElementById("cmt_line_Name_" + itemId);
		pwd = document.getElementById("cmt_line_Pwd_" + itemId);
		if(name.value.trim() == ""){
			alert("Please input name.");
			name.focus();
			return;
		}
		if(pwd.value.trim() == ""){
			alert("Please input password.");
			pwd.focus();
			return;
		}
		name_val = name.value.trim();
		pwd_val = pwd.value.trim();
	}
	comment_line_xmlHttp=GetXmlHttpObject();
	if (comment_line_xmlHttp==null)
 	{
 		alert ("Browser does not support HTTP Request");
 		return false;
 	}
	comment_line_current_item_id = itemId;
	comment_line_tableId_current = tableId;
	comment_line_newRowId = GetUID();
	var url=site_url+"petspace_action.php";
	url=url+"?mode=write_line_comment&item_id="+itemId + "&row_id="+comment_line_newRowId+"&cmtName="+name_val+"&cmtPwd="+pwd_val+"&content=" + encodeURIComponent(txt_val);
	comment_line_xmlHttp.onreadystatechange=comment_line_commentWritten ;
	comment_line_xmlHttp.open("GET",url,true);
	txt.value = "";
	comment_line_xmlHttp.send(null);
}
function comment_line_commentWritten(){
	if (comment_line_xmlHttp.readyState==4 || comment_line_xmlHttp.readyState=="complete")
 	{
		var txt = comment_line_xmlHttp.responseText;
		if(txt.length < 1) return;
		if(txt.substring(0,1)=="@"){
			alert(txt.substring(1));
			return;
		}
		var tbl = document.getElementById(comment_line_tableId_current);
		var row = tbl.insertRow(0);
		row.id = comment_line_newRowId;
		var cell = row.insertCell(0);
		cell.innerHTML = txt;
		var cmtName = document.getElementById("cmt_line_Name_" + comment_line_current_item_id);
		var cmtPwd = document.getElementById("cmt_line_Pwd_" + comment_line_current_item_id);
		if(cmtName){
			cmtName.value = "";
			cmtPwd.value = "";
		}
 	}
}


function showLineCommentPopup(line_cmt_id){
	document.getElementById("sp_lineCommentPopup_"+line_cmt_id).style.display = '';
	document.getElementById("cmtLineItemPwd_"+line_cmt_id).focus();
	
}
function hideLineCommentPopup(line_cmt_id) {
  document.getElementById("sp_lineCommentPopup_"+line_cmt_id).style.display = 'none'; 
};

function sendFriendRequest(site_url, to_petspace_id, from_petspace_id){
	if(!from_petspace_id){
		alert("Please create pet space first!\nTo create pet space, please login and click 'Create pet space' button.");
		return false;
	}
	if(confirm("Do you want to send friend request?")){
		window.location.href = site_url + "petspace_action.php?mode=friend_request&from_petspace_id="+from_petspace_id+"&to_petspace_id="+to_petspace_id;	
	}
	
}
/** End of comment_line script **/
