document.write("<style type=\"text/css\">@import \"/css/profile.new.css?" + ifhy.global_vars.js_css_revision + "\";<\/style>");

var connect = YAHOO.util.Connect;
var dom = YAHOO.util.Dom;

var is_friend = false;
var processHatelistSuccess_NEW = function(o){
	
	rs = o.responseXML;
	member = rs.getElementsByTagName("hate")[0].getAttribute("member");
	who = rs.getElementsByTagName("hate")[0].getAttribute("who");
	hb_count = rs.getElementsByTagName("hate")[0].getAttribute("hated_by");
	hb_percent = rs.getElementsByTagName("hate")[0].getAttribute("hated_by_percent");
	hated = rs.getElementsByTagName("hated")[0].firstChild.nodeValue;
	
	if (document.getElementById("hateListAdding") && document.getElementById("hateListRemoving")) {
		document.getElementById("hateListAdding").style.display = "none";
		document.getElementById("hateListRemoving").style.display = "none";
		
		if (hated == 1) {
			document.getElementById("hateListOn").style.display = "block";
			document.getElementById("hateListOff").style.display = "none";
			document.getElementById("hatebox_nothated").style.display = "none";
			document.getElementById("hatebox_hated").style.display = "block";
			Nifty("div#hatebox_hated","normal");
		} else {
			document.getElementById("hateListOn").style.display = "none";
			document.getElementById("hateListOff").style.display = "block";
			document.getElementById("hatebox_hated").style.display = "none";
			document.getElementById("hatebox_nothated").style.display = "block";
			Nifty("div#hatebox_nothated","normal");
		}
		
		Nifty("div#hate_box","normal");
		Nifty("div#hate_box div","small");
	}
	
	if (document.getElementById("hated_by_percent") && document.getElementById("hated_by_percent_bg")) {
		document.getElementById("hated_by_percent").innerHTML = hb_percent + "%";
		document.getElementById("hated_by_percent_bg").style.width = hb_percent + "%";
		document.getElementById("hated_by_count").innerHTML = hb_count + " member";
		if (hb_count != 1) {
			document.getElementById("hated_by_count").innerHTML = document.getElementById("hated_by_count").innerHTML + "s";
		}
	}
	
	if (hated == 1 && document.getElementById("is_friend")) {
		document.getElementById("is_friend").style.display = "none";
	}
	if (hated == 1 && document.getElementById("profiles_add_to_friends")) {
		document.getElementById("profiles_add_to_friends").style.display = "none";
	}
	
	if (is_friend) {
		document.location.replace(document.location.href);
	}
}

var processHatelistFailure_NEW = function(o){
	document.getElementById("hateListAdding").style.display = "none";
	document.getElementById("hateListRemoving").style.display = "none";
	document.getElementById("hateListOn").style.display = "none";
	document.getElementById("hateListOff").style.display = "block";
}

var processHatelist_NEW = {
	success:processHatelistSuccess_NEW,
	failure:processHatelistFailure_NEW
}

function hateList_NEW(member) {
	var process = true;
	if (document.getElementById("is_friend") && document.getElementById("is_friend").style.display == "block") {
		process = confirm(member + ' is currently on your friends list.\n\nHating them will remove them.\n\nContinue?');
		is_friend = true;
	} else {
		is_friend = false;
	}
	if (process) {
		if (document.getElementById("hateListOn")) {
			if (document.getElementById("hateListOn").style.display == "block") {
				adding = false
			} else {
				adding = true
			}
			document.getElementById("hateListOn").style.display = "none";
			document.getElementById("hateListOff").style.display = "none";
			
			if (adding) {
				document.getElementById("hateListAdding").style.display = "block";
			} else {
				document.getElementById("hateListRemoving").style.display = "block";
			}
		} else {
			adding = true;
		}
			
		var hateListObj_NEW = connect.asyncRequest('GET','/xml/hate_member.xml?member=' + member + '&cache=' + Math.random()*9999,processHatelist_NEW,null);
	}
}

function setDimContent(content) {
	for (x=0; x < content.length; x++) {
		dom.setStyle(document.getElementById(content[x]), "opacity", .4);
	}
}

function profileImageResize(obj) {
	var setWidth = 425
	if (arguments.length > 1) {
		setWidth = arguments[1];
	}
	if (obj.width > setWidth) {
		obj.width = setWidth;
	}
}

var updatePhotoInfoSuccess = function(o){
	rs = o.responseXML;
	member = rs.getElementsByTagName("profile")[0].getAttribute("member");
	document.getElementById("photo_description").innerHTML = rs.getElementsByTagName("description")[0].firstChild.nodeValue.replace(/^\s+|\s+$/g,"");
	document.getElementById("photo_tags").innerHTML = rs.getElementsByTagName("tags")[0].firstChild.nodeValue.replace(/^\s+|\s+$/g,"");
	
	if (document.getElementById("profiles_sidebar_tags")) {
		document.getElementById("profiles_sidebar_tags").innerHTML = rs.getElementsByTagName("tagSource")[0].firstChild.nodeValue.replace(/^\s+|\s+$/g,"");
		
		document.getElementById("profiles_sidebar_tags_total").innerHTML = rs.getElementsByTagName("tagSource")[0].getAttribute("total");
	}
	
	document.getElementById("photo_description").style.display = "inline";
	document.getElementById("photo_description_edit").style.display = "none";
	document.getElementById("photo_tags").style.display = "inline";
	document.getElementById("photo_tags_edit").style.display = "none";
	document.getElementById("photo_edit_button").style.display = "inline";
	document.getElementById("photo_edit_button_save").style.display = "none";
	document.getElementById("photo_edit_button_saving").style.display = "none";
	editPhotoInfoOn = false;
	
	document.getElementById("photo_description_edit_field").disabled = false;
	document.getElementById("photo_tags_edit_field").disabled = false;
	document.getElementById("photo_tags_edit_field").value = rs.getElementsByTagName("tagsEdit")[0].firstChild.nodeValue.replace(/^\s+|\s+$/g,"");
	
	YAHOO.util.Dom.setStyle('photo_description_edit', 'opacity', 1);
	YAHOO.util.Dom.setStyle('photo_tags_edit', 'opacity', 1);
	
}

var updatePhotoInfoFailure= function(o){
	alert('Unable to save your changes.\n\nCheck your internet connection and try again.');
}

var updatePhotoInfo = {
	success:updatePhotoInfoSuccess,
	failure:updatePhotoInfoFailure
}

var editPhotoInfoOn = false;
function editPhotoInfo(photo,member) {
	if (editPhotoInfoOn) {
		if (document.getElementById("photo_description_edit_field").value.length > 500) {
			alert('Description for your photo must be less than 500 characters.');
		} else {
			document.getElementById("photo_description_edit_field").disabled = true;
			document.getElementById("photo_tags_edit_field").disabled = true;
			document.getElementById("photo_edit_button_save").style.display = "none";
			document.getElementById("photo_edit_button_saving").style.display = "inline";
			YAHOO.util.Dom.setStyle('photo_description_edit', 'opacity', .2);
			YAHOO.util.Dom.setStyle('photo_tags_edit', 'opacity', .2);
			
			var postData = "photo_description=" + escape(document.getElementById("photo_description_edit_field").value) + "&photo_tags=" + escape(document.getElementById("photo_tags_edit_field").value);
			var updatePhotoInfoObj = YAHOO.util.Connect.asyncRequest('POST', '/xml/profile.xml?section=updatephoto&member=' + member + '&photo=' + photo + '&cache=' + Math.random()*9999, updatePhotoInfo, postData);
		}
	} else {
		document.getElementById("photo_description").style.display = "none";
		document.getElementById("photo_description_edit").style.display = "inline";
		document.getElementById("photo_tags").style.display = "none";
		document.getElementById("photo_tags_edit").style.display = "inline";
		document.getElementById("photo_edit_button").style.display = "none";
		document.getElementById("photo_edit_button_save").style.display = "inline";
		editPhotoInfoOn = true;
	}
}

function addComment(state) {
	if (state == 'on') {
		document.getElementById("profiles_comments_results").style.display = "none";
		document.getElementById("profiles_comments_add").style.display = "inline";
		if(document.getElementById("new_comment_textarea")) {
			document.getElementById("new_comment_textarea").focus();
		}
	} else {
		document.getElementById("profiles_comments_results").style.display = "inline";
		document.getElementById("profiles_comments_add").style.display = "none";
	}
}

/*function postComment() {
	if (document.getElementById("new_comment_textarea").value.length > 500) {
		alert('The comment you\'re posting needs to be less than 500 characters.\n\nIt\'s currently ' + document.getElementById("new_comment_textarea").value.length + '.');
	} else {
		document.getElementById('new_comment_form').submit();
	}
}*/

function postComment_NEW() {
	var commentLength = document.new_comment_form.new_comment.value.length;
	
	if (commentLength > 500) {
		alert('The comment you\'re posting needs to be less than 500 characters.\n\nIt\'s currently ' + commentLength + '.');
	} else if (commentLength == 0) {
		alert('You might want to try typing in a comment first.');
	} else {
		document.new_comment_form.submit();
	}
}