



//// comment stuff

function checkCommentOnKey()	{

	if(!loggedin)			{
		
		var div = findObj("comment_fields");
		
		showLogin(div, "comment");
		//div.style.display = "none";
	}
}

function saveComment(itemID, comment, item_type)	{

	if(!loggedin)			return;
		
	if(comment.length==0)	return;

	if(comment.indexOf("We're waiting for")==0)	return;

	xmlconn.request("/explore/save_comment/noheaders?itemID=" + itemID + "&comments=" + escape(comment) + "&item_type=" + escape(item_type));
}


xmlconn.setRespHandler('comment_saved', processNewComment);

function processNewComment(xmldoc) {

	try	{

		var comment_html = xmldoc.getElementsByTagName('comment_html');

		var html = comment_html[0].firstChild.data;

		findObj("comments").innerHTML+=html;
		
		//findObj("comment_fields").style.display = "none";

		findObj("comments_area").value = "";

		// fade

		var div_id = xmldoc.getElementsByTagName('div_id')[0].firstChild.data;

		startFade(div_id);


	} catch(e)	{

		displayError(e);
 	}

}



/////// tag stuff


function saveTagAjax(itemID, tag, category, item_type)	{

	if(!loggedin)			{

		var divID = "tag_fields";
		if(category=="celeb")			divID = "tag2";
		else if(category=="designer")	divID = "tag3";
		
		var div = findObj(divID);
		
		showLogin(div, "tag");
	}

	
	if(tag.length==0)	return;

	if(tag.indexOf("Add a")==0)	return;

	xmlconn.request("/explore/save_tag/noheaders?itemID=" + itemID + "&tag=" + replace(escape(tag), "+", "%2B") + "&category=" + category + "&item_type=" + item_type);
}


xmlconn.setRespHandler('tag_saved', processNewTag);

function processNewTag(xmldoc) {

	try	{

		var tag_html = xmldoc.getElementsByTagName('tag_html');
		var html = tag_html[0].firstChild.data;


		var category = xmldoc.getElementsByTagName('category')[0].firstChild.data;

		findObj(category + "s").innerHTML+=html;


		if(category=='trend')		{
		
			findObj("tag_field").value = "";
			
			var tag_empty = findObj("tags_empty");
			if(tag_empty!=null)	 tag_empty.style.display = "none";
		}
		else if(category=='celeb')	{
		
			findObj("tag2").value = "";

			var celeb_empty = findObj("celeb_empty");
			if(celeb_empty!=null)	 celeb_empty.style.display = "none";
		}
		else if(category=='designer')	{
		
			findObj("tag3").value = "";

			var designer_empty = findObj("designer_empty");
			if(designer_empty!=null)	 designer_empty.style.display = "none";
		}

		// fade

		var div_id = xmldoc.getElementsByTagName('div_id')[0].firstChild.data;

		startFade(div_id);

	} catch(e)	{

		displayError(e);
	}
}


///// jump to a new product

function jump(productID, index)	{

	if(cur_slider_index != index) {
	
		findObj("slideimg_" + index).className = "slider_active";
		
		if(cur_slider_index>0) findObj("slideimg_" + cur_slider_index).className = "slider_inactive";
	
		cur_slider_index = index;
	}

	xmlconn.request("/explore/jump_product/noheaders?productID=" + productID);
}

xmlconn.setRespHandler('product_jump', processJump);

function processJump(xmldoc) {

	try	{

		var product_html = xmldoc.getElementsByTagName('product_html');

		var html = product_html[0].firstChild.data;

		findObj("product_details").innerHTML = html;
		
		// set current status
		
		vote_status_0 = loadOptionalXMLParam(xmldoc, 'love_status');
						
	} catch(e)	{

		displayError(e);
	}
}








///// display hover bubble

var hover_over;

function doHover(div, type, id)	{

	hover_over = div;

	xmlconn.request("/explore/hover_bubble/noheaders?type=" + type + "&id=" + id);
}

xmlconn.setRespHandler('product_hover', processProductHover);

function processProductHover(xmldoc) {

	try	{

		/// set html

		var hover_html = xmldoc.getElementsByTagName('hover_html');

		var html = hover_html[0].firstChild.data;

		findObj("hover_html").innerHTML = html;

		/// display bubble

		var display_div = findObj("hover");

		var div_pos = findPos(hover_over);
		
		display_div.style.left = div_pos[0] + hover_over.width + 10;
		display_div.style.top = div_pos[1] + 8;
		display_div.style.display = "block";
		
		
	} catch(e)	{

		displayError(e);
	}
}





//// utils


function displayError(e)	{

	var msg = "Error processing xml: " + e.name + " - " + e.message;

	alert(e);		

	window.status = msg; 
}





