if(typeof sIFR == "function"){
    sIFR.replaceElement("#mainbar_header", named({sFlashSrc: "/js/avenir_light.swf", sColor: "#FCE094", sWmode: "transparent"}));
};

var base_url = "/";
var active_tab = "personal_information";

var editoff = new Image();
editoff.src = '/gfx/comment_edit_off.gif';

var editon = new Image();
editon.src = '/gfx/comment_edit.gif';

var deloff = new Image();
deloff.src = '/gfx/comment_delete_off.gif';

var delon = new Image();
delon.src = '/gfx/comment_delete.gif';

var collapse = new Image();
collapse.src = '/gfx/collapse.gif';

var hide = new Image();
hide.src = '/gfx/hide.gif';

var closeoff = new Image();
closeoff.src = '/gfx/close_off.jpg';

var closeon = new Image();
closeon.src = '/gfx/close_ON.jpg';

var respect_btnoff = new Image();
respect_btnoff.src = '/gfx/respect.gif';

var respect_btnon = new Image();
respect_btnon.src = '/gfx/respect_hover.gif';

var disrespect_btnoff = new Image();
disrespect_btnoff.src = '/gfx/disrespect.gif';

var disrespect_btnon = new Image();
disrespect_btnon.src = '/gfx/disrespect_hover.gif';

var hide_all_iconoff = new Image();
hide_all_iconoff.src = '/gfx/hide_all.gif';

var hide_all_iconon= new Image();
hide_all_iconon.src = '/gfx/hide_all_hover.gif';

var show_all_iconoff = new Image();
show_all_iconoff.src = '/gfx/show_all.gif';

var show_all_iconon= new Image();
show_all_iconon.src = '/gfx/show_all_hover.gif';


var staron = new Image();
staron.src = '/gfx/star_on.gif';

var staroff = new Image();
staroff.src = '/gfx/star.gif';

function changeImg(imgname, img, state) {	
	var name = img+state;
	document.images[imgname].src = eval(name+".src");
}

function getElementsByClassName(className) {
  var a = [];
  var els = document.getElementsByTagName("div");
  for ( var i = 0, j = els.length ; i < j ; i++ ) {
    if (els.item(i).className == className)
      a.push(els.item(i));
  }
  return a;
}

var errFunc = function(t) {
	alert("ShadoWeb is having some technical problems at the moment. Please try again later. If the problem exists please contact the admin.");
	document.getElementById('loader').style.display = 'none';
}

function findCenter() {
	
var x,y;
if (self.pageYOffset) // all except Explorer
{
	y = self.pageYOffset;
}
else if (document.documentElement && document.documentElement.scrollTop)
{
	y = document.documentElement.scrollTop;
}
else if (document.body) // all other Explorers
{
	y = document.body.scrollTop;
}

if (self.innerHeight) // all except Explorer
{
	y += self.innerHeight / 2;
}
else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
{
	y += document.documentElement.clientHeight / 2;
}
else if (document.body) // other Explorers
{
	y += document.body.clientHeight / 2;
}

return y;
	
}

function showLoader() {
	var loader_y = findCenter();
	document.getElementById('loader').style.top = loader_y + "px";
	document.getElementById('loader').style.display = 'block';	
}

function collapseAll() {
	var comments_min = getElementsByClassName("comment_min");
	for(i=0; i < comments_min.length; i++) {
		comments_min[i].style.display = "none";
	}

	var comments_max = getElementsByClassName("comment_max");
	for(i=1; i < comments_max.length; i++) {
		comments_max[i].style.display = "block";	
	}

	document.getElementById('show_all_comments_icon').style.display = 'none';
	document.getElementById('show_all_comments_text').style.display = 'none';
	
	document.getElementById('hide_all_comments_icon').style.display = 'inline';
	document.getElementById('hide_all_comments_text').style.display = 'inline';
			
}

function hideAll() {
	var comments_min = getElementsByClassName("comment_min");
	for(i=1; i < comments_min.length; i++)
		comments_min[i].style.display = "block";

	var comments_max = getElementsByClassName("comment_max");
	for(i=1; i < comments_max.length; i++)
		comments_max[i].style.display = "none";
		
	if(document.getElementById('comment_form'))
		document.getElementById('comment_form').style.display = 'block';		
	
	document.getElementById('hide_all_comments_icon').style.display = 'none';
	document.getElementById('hide_all_comments_text').style.display = 'none';

	document.getElementById('show_all_comments_icon').style.display = 'inline';
	document.getElementById('show_all_comments_text').style.display = 'inline';
				
}

function collapseComment(num) {
	// <![CDATA[
		Effect.BlindUp("comment_min_"+num, {duration: 0.5, afterFinish: function() { new Effect.BlindDown("comment_max_"+num, {duration: 0.5}); }});
	// ]]>	
}

function hideComment(num) {
	// <![CDATA[
		Effect.BlindUp("comment_max_"+num, {duration: 0.5, afterFinish: function() { new Effect.BlindDown("comment_min_"+num, {duration: 0.5}); }});
	// ]]>
}

function delfav(doc) {
	var mother = doc.parentNode.parentNode;
	mother.style.display = 'none';
}

function trhover(doc) {
	tds = doc.getElementsByTagName("td");
	for (var i = 1; i < tds.length; i++) { 
	    tds[i].className = 'tr_hover';
	}
}

function trout(doc) {
	tds = doc.getElementsByTagName("td");
	for (var i = 1; i < tds.length; i++) { 
	    tds[i].className = 'tr_out';
	}
}
		
function show() {
	// <![CDATA[
		Effect.SlideDown('shadow_slider', {duration: 3, afterFinish: function() { new Effect.Appear('content_left', {duration: 1}); new Effect.Appear('content_right', {duration: 1}); }});
	// ]]>
}

function favourite(doc, on) {
	if(on == 1)
		doc.className = 'favourite_hover';
	else
		doc.className = 'favourite';
}

function tabHover(doc) {
	if(doc.className != 'tab_on')
		doc.className = 'tab_red';
}

function tabOut(doc, num) {
	if(num == 0)
		doc.className = 'tab_on';
	else
		if(doc.className != 'tab_on')
		doc.className = 'tab_gray';
}

function adhover(doc, hov_state) {
	if(hov_state == 0)
		doc.className = 'google_ad';
	else
		doc.className = 'google_ad_hover';
}

function userpopup(doc, user, state) {
	if(state == 1) {
		if(doc.offsetParent) {
			
			var top = doc.offsetTop;
			var left = doc.offsetTop;
			while(doc = doc.offsetParent) { 
				top += doc.offsetTop;
				left += doc.offsetLeft;
			}
	
			document.getElementById("popup_"+user).style.top = top + "px";
			document.getElementById("popup_"+user).style.left = left + 20 + "px";
			document.getElementById("popup_"+user).style.display = 'block';
		}	
	}
	else
		document.getElementById("popup_"+user).style.display = 'none';
}

var favaddSuccess = function(t) {
	if(t.responseText !="") {
		document.getElementById('favourite_add').style.display = 'block';
		// <![CDATA[
		Effect.Appear('favourite_info', {duration: 0.8, afterFinish: function() { new Effect.Fade('favourite_info', {duration: 0.8, afterFinish: function() { document.getElementById('favourite_add').style.display = 'none'; document.getElementById('favourite_remove').style.display = 'none'; }}); }});
		// ]]>		
	}
}

var favremoveSuccess = function(t) {
	if(t.responseText !="") {
		document.getElementById('favourite_remove').style.display = 'block';
		// <![CDATA[
		Effect.Appear('favourite_info', {duration: 0.8, afterFinish: function() { new Effect.Fade('favourite_info', {duration: 0.8, afterFinish: function() { document.getElementById('favourite_add').style.display = 'none'; document.getElementById('favourite_remove').style.display = 'none'; }}); }});
		// ]]>		
	}
}

var star_off = new Image();
star_off.src = base_url+'gfx/star_off.gif';

var star_on = new Image();
star_on.src = base_url+'gfx/star_yellow.gif';

var star_del = new Image();
star_del.src = base_url+'gfx/star_on.gif';

function star_hover(img, color) {
	var star = document.getElementById(img);

	if(star.src == star_on.src)
		star.src = star_del.src;
	else
		star.src = star_on.src;

}

function star_out(img, color) {
	
}



function star(id, on) {
	/*
	var star = document.getElementById(img);
	var on = 1;
	
	if(star.src == star_off.src) {
		star.src = star_on.src;
		if(document.getElementById('add_to_favourites') != null)
			document.getElementById('add_to_favourites').innerHTML = "Remove from favourites";
	}
	else {
		star.src = star_off.src;
		on = 0;
		if(document.getElementById('add_to_favourites') != null)
			document.getElementById('add_to_favourites').innerHTML = "Add to favourites";
	}*/
		

	var top = findCenter();
	document.getElementById('favourite_info').style.top = top + "px";

		if(on == 1) {
			new Ajax.Request(base_url+'favourite/add', {asynchronous:true, method:'post', postBody:'conversation_id='+id, onSuccess:favaddSuccess, onFailure:errFunc });

			document.getElementById('add_favourite_icon').style.display = 'none';
			document.getElementById('add_favourite_text').style.display = 'none';			
			document.getElementById('remove_favourite_icon').style.display = 'inline';
			document.getElementById('remove_favourite_text').style.display = 'inline';
		}
		else {
			new Ajax.Request(base_url+'favourite/remove', {asynchronous:true, method:'post', postBody:'conversation_id='+id, onSuccess:favremoveSuccess, onFailure:errFunc });
			
			document.getElementById('remove_favourite_icon').style.display = 'none';
			document.getElementById('remove_favourite_text').style.display = 'none';
			
			document.getElementById('add_favourite_icon').style.display = 'inline';
			document.getElementById('add_favourite_text').style.display = 'inline';		
		}

}
function fstar(img, id) {
	var star = document.getElementById(img);
	var on = 1;
	
	var top = findCenter();
	document.getElementById('favourite_info').style.top = top + "px";	
	
	if(star.src == star_off.src) {
		star.src = star_on.src;
		new Ajax.Request(base_url+'favourite/add', {asynchronous:true, method:'post', postBody:'conversation_id='+id, onSuccess:favaddSuccess, onFailure:errFunc });
	}
	else {
		star.src = star_off.src;
		on = 0;
		new Ajax.Request(base_url+'favourite/remove', {asynchronous:true, method:'post', postBody:'conversation_id='+id, onSuccess:favremoveSuccess, onFailure:errFunc });

	}
	
}

function hiderespect(id) {
document.getElementById('respect_btns_'+id).style.display = 'none';
}

var respectSuccess = function(t) {
	if(t.responseText !="") {
		document.getElementById('loader').style.display = 'none';

		var top = findCenter();
		document.getElementById('respect_info').style.top = top + "px";						
		
		// <![CDATA[
		Effect.Appear('respect_info', {duration: 0.8, afterFinish: function() { new Effect.Fade('respect_info', {duration: 0.8}); }});
		// ]]>		
	}
}

function respect(vote, conversation_id, conversation_subject) {
	if(vote > 0) {
		document.getElementById('respect_info_text').innerHTML = "Thanks for respecting " + conversation_subject;
		new Ajax.Request(base_url+'respect/up', {asynchronous:true, method:'post', postBody:'digg=-1&conversation_id='+conversation_id, onSuccess:respectSuccess, onFailure:errFunc });
	}	
	else {
		document.getElementById('respect_info_text').innerHTML = "You have disrespected " + conversation_subject;
		new Ajax.Request(base_url+'respect/down', {asynchronous:true, method:'post', postBody:'digg=-1&conversation_id='+conversation_id, onSuccess: respectSuccess, onFailure:errFunc });
	}

}

var friendSuccess = function(t) {
	if(t.responseText !="") {
		document.getElementById('loader').style.display = 'none';
		
		// <![CDATA[
		Effect.Appear('friend_info', {duration: 0.8, afterFinish: function() { new Effect.Fade('friend_info', {duration: 0.8, afterFinish: function() { document.getElementById('friend_add').style.display = 'none'; document.getElementById('friend_remove').style.display = 'none'; }}); }});
		// ]]>	
	}
}

var friend_remove = new Image();
friend_remove.src = base_url+'gfx/heart_remove.gif';

var friend_remove_on = new Image();
friend_remove_on.src = base_url+'gfx/heart_remove_on.gif';

var friend_add = new Image();
friend_add.src = base_url+'gfx/heart_add.gif';

var friend_add_on = new Image();
friend_add_on.src = base_url+'gfx/heart_add_on.gif';

function friend(friend_id, img_id) {
	var friend = document.getElementById('friend_'+img_id);
	var on = 1;
	
	if(friend.src == friend_add_on.src || friend.src == friend_add.src) {
		friend.src = friend_remove.src;
		document.getElementById('friend_txt_'+img_id).innerHTML = "Remove friend";
	}
	else {
		friend.src = friend_add.src;
		on = 0;
		document.getElementById('friend_txt_'+img_id).innerHTML = "Add friend";
	}

	showLoader();
	if(friend.offsetParent) {

	var top = findCenter();
	document.getElementById('friend_info').style.top = top + "px";

		if(on == 1) {
			document.getElementById('friend_add').style.display = 'block';
			new Ajax.Request(base_url+'friend/add', {asynchronous:true, method:'post', postBody:'friend_id='+friend_id, onSuccess:friendSuccess, onFailure:errFunc });
		}
		else {
			document.getElementById('friend_remove').style.display = 'block';
			new Ajax.Request(base_url+'friend/remove', {asynchronous:true, method:'post', postBody:'friend_id='+friend_id, onSuccess:friendSuccess, onFailure:errFunc });
		}
	}
}

function friend_hover(img_id) {
	var friend = document.getElementById('friend_'+img_id);
	if(friend.src != friend_add_on.src && friend.src != friend_remove_on.src) {
		if(friend.src == friend_add.src)
			friend.src = friend_add_on.src;
		else
			friend.src = friend_remove_on.src;
	}
}


function friend_hover_out(img_id) {
	var friend = document.getElementById('friend_'+img_id);
	if(friend.src != friend_add.src && friend.src != friend_remove.src) {
		if(friend.src == friend_add_on.src)
			friend.src = friend_add.src;
		else
			friend.src = friend_remove.src;
	}
}

function friend_del(friend_id) {
	showLoader();
	new Ajax.Request(base_url+'friend/remove', {asynchronous:true, method:'post', postBody:'friend_id='+friend_id, onSuccess: function() { new Effect.Fade("friend_div_"+friend_id, {duration: 1}); document.getElementById('loader').style.display = 'none'; }, onFailure:errFunc });
}

function reply(parent_id, depth) {
	document.getElementById('parent_id').value = parent_id;
	document.getElementById('depth').value = depth + 1;
}

var tab_active = '';

function changeTab(tab) {
	if(tab_active != '')
		document.getElementById(tab_active).className = 'tab_gray';
	tab_active = tab;
	document.getElementById(tab).className = 'tab_on';
}

var p_conversations = "";
function popular_conversations() {
	changeTab('tab_popular_conversations');
	
	if(p_conversations == "") {
		showLoader();
		document.getElementById('ajax_div').innerHTML = "<h1>Loading...</h1>";


		var ajax = new Ajax.Updater(
     	    'ajax_div',
    	     base_url+'ajax/popular_conversations',
     	    {
     	    method:'get',
    	         onComplete: p_conversations_Response
        	 });
	}
	else {
		document.getElementById('ajax_div').innerHTML = p_conversations;
	}
}

function p_conversations_Response(req) {
	p_conversations = req.responseText;
	document.getElementById('ajax_div').innerHTML = p_conversations;
	document.getElementById('loader').style.display = 'none';
}


var p_shadows = "";
function popular_shadows() {
	changeTab('tab_popular_shadows');
	
	if(p_shadows == "") {
		showLoader();
		document.getElementById('ajax_div').innerHTML = "<h1>Loading...</h1>";
		
		var ajax = new Ajax.Updater(
     	    'ajax_div',
    	     base_url+'ajax/popular_shadows',
     	    {
     	    method:'get',
    	         onComplete: p_shadows_Response
        	 });
	}
	else {
		document.getElementById('ajax_div').innerHTML = p_shadows;
	}
}

function p_shadows_Response(req) {
	p_shadows = req.responseText;
	document.getElementById('ajax_div').innerHTML = p_shadows;
	document.getElementById('loader').style.display = 'none';
}



var tags = "";
function tag_cloud_Response(req) {
	tags = req.responseText;
	document.getElementById('ajax_div').innerHTML = tags;
	document.getElementById('loader').style.display = 'none';
}


function popular_tags() {
	changeTab('tab_popular_tags');
	
	if(tags == "") {
		showLoader();
		document.getElementById('ajax_div').innerHTML = "<h1>Loading...</h1>";
		var ajax = new Ajax.Updater('ajax_div',base_url+'ajax/popular_tags', {method:'get',onComplete: tag_cloud_Response});
	}
	else {
		document.getElementById('ajax_div').innerHTML = tags;
	}
}

function change_passwd() {
	// <![CDATA[
		Effect.Fade(active_tab, {duration: 0.8, afterFinish: function() { new Effect.Appear('change_password', {duration: 0.8}); active_tab = 'change_password'; }});
	// ]]>	
		
	changeTab('tab_change_password');/*
	document.getElementById('personal_information').style.display = 'none';
	document.getElementById('change_avatar').style.display = 'none';
	document.getElementById('change_password').style.display = 'block';*/
}

var passwdSuccess = function(t) {
	if(t.responseText !="") {	
		var top = findCenter();
		document.getElementById('usersettings_info').style.top = top + "px";		
			
		document.getElementById('loader').style.display = 'none';
		if(t.responseText == "success") {
			document.getElementById('usersettings_info_text').innerHTML = "Password changed";	
		}
		else {
			document.getElementById('usersettings_info_text').innerHTML = "Password change failed.";
		}

		// <![CDATA[
		Effect.Appear('usersettings_info', {duration: 0.8, afterFinish: function() { new Effect.Fade('usersettings_info', {duration: 0.8}); }});
		// ]]>
	}
}


function change_password() {
	showLoader();
	var ajax = new Ajax.Request(base_url+'usersettings/change_passwd', {asynchronous:true, method:'post', postBody:'password='+$F('password')+'&password2='+$F('password2')+'&old_password='+$F('old_password'), onSuccess:passwdSuccess, onFailure:errFunc });
}


var updateinfoSuccess = function(t) {
	if(t.responseText !="") {

	var top = findCenter();//document.documentElement.clientHeight / 2 + document.documentElement.scrollTop - 50;
	document.getElementById('usersettings_info').style.top = top + "px";					
		
		document.getElementById('loader').style.display = 'none';
		if(t.responseText == "success") {
			document.getElementById('usersettings_info_text').innerHTML = "Information updated.";	
		}
		else {
			document.getElementById('usersettings_info_text').innerHTML = "Information update failed.";
		}

		// <![CDATA[
		Effect.Appear('usersettings_info', {duration: 0.8, afterFinish: function() { new Effect.Fade('usersettings_info', {duration: 0.8}); }});
		// ]]>
	}
}

function update_information() {
	showLoader();
	var ajax = new Ajax.Request(base_url+'usersettings/update_information', {asynchronous:true, method:'post', postBody:'email='+$F('email'), onSuccess:updateinfoSuccess, onFailure:errFunc });

}

function avatar_Response(req) {
	var top = findCenter();
	document.getElementById('usersettings_info').style.top = top + "px";		
	
	if(req.responseText == "success")
		document.getElementById('usersettings_info_text').innerHTML = "Avatar uploaded!";
	else
		document.getElementById('usersettings_info_text').innerHTML = req.responseText;

		
		// <![CDATA[
		Effect.Appear('usersettings_info', {duration: 0.8, afterFinish: function() { new Effect.Fade('usersettings_info', {duration: 0.8}); }});
		// ]]>
	document.getElementById('loader').style.display = 'none';
}

function upload_avatar() {
	showLoader();

	var ajax = new Ajax.Request(base_url+'usersettings/do_upload', {asynchronous:true, method:'post', postBody:'userfile='+$F('userfile'), onComplete:avatar_Response, onFailure:errFunc });
}

function lclear() {
	doc = document.getElementById('username');
	if(doc.value == "Your email")
		doc.value = "";
}

function showRefine() {
	document.getElementById('search_help').style.display = 'none';
	// <![CDATA[
	Effect.Appear('refine_search', {duration:1});
	// ]]>
}

function showHelp() {
	document.getElementById('refine_search').style.display = 'none';
	// <![CDATA[
	Effect.Appear('search_help', {duration:1});
	// ]]>
}

var csubject = 0;
function clearsubject() {
	if(csubject == 0) {
		document.getElementById('comment_form_subject').value = '';
		csubject = 1;
	}
}

var ctext = 0;
function cleartext() {
	if(ctext == 0) {
		document.getElementById('comment_form_text').value = '';
		ctext = 1;
	}
}

var ctags = 0;
function cleartags() {
	if(ctags == 0) {
		document.getElementById('comment_form_tags').value = '';
		ctags = 1;
	}
}

function hover_text_input(doc, num) {
	if(doc.className == 'wide_text_input' && num == 1) {
		doc.className = 'wide_text_input_hover';
	} 
	if(doc.className == 'wide_text_input_hover' && num == 0) {
		doc.className = 'wide_text_input';
	}	
	if(doc.className == 'wide_textarea_input' && num == 1) {
		doc.className = 'wide_textarea_input_hover';
	}
	if(doc.className == 'wide_textarea_input_hover' && num == 0) {
		doc.className = 'wide_textarea_input';
	}		
	
	if(doc.className == 'login_text_input' && num == 1) {
		doc.className = 'login_text_input_hover';
	}
	if(doc.className == 'login_text_input_hover' && num == 0) {
		doc.className = 'login_text_input';
	}
}

function confirmDel()
{
	var del =confirm("Do you really want to delete this post?");
	if (del)
		return true ;
	else
		return false ;
}


var checkusernameSuccess = function(t) {

	if(t.responseText !="") {

		var top = findCenter();
		document.getElementById('username_info').style.top = top + "px";					
		
		document.getElementById('loader').style.display = 'none';
		if(t.responseText == "available") {
			document.getElementById('username_info_text').innerHTML = "Username '"+document.getElementById('reg_username').value+"' is available!";	
		}
		else {
			document.getElementById('username_info_text').innerHTML = "Unfortunately username '"+document.getElementById('reg_username').value+"' is unavailable.";
		}

		// <![CDATA[
		Effect.Appear('username_info', {duration: 1.5, afterFinish: function() { new Effect.Fade('username_info', {duration: 1.5}); }});
		// ]]>
	}
}

function checkusername() {
	
	var username = document.getElementById('reg_username').value;

	if(username != "") {
		showLoader();
		var ajax = new Ajax.Request(base_url+'checkusername', {asynchronous:true, method:'post', postBody:'username='+username, onSuccess:checkusernameSuccess, onFailure:errFunc });	
	} else {
		var top = findCenter();
		document.getElementById('username_info').style.top = top + "px";
		document.getElementById('username_info_text').innerHTML = "Username can't be left empty.";
		// <![CDATA[
		Effect.Appear('username_info', {duration: 0.8, afterFinish: function() { new Effect.Fade('username_info', {duration: 0.8}); }});
		// ]]>		
	}

}

var formatting = 0;
function showformatting() {
	
	if(formatting == 0) {
	// <![CDATA[
		Effect.BlindDown("text_formatting", {duration: 1});
	// ]]>	
		formatting = 1;
	}
	else {
	// <![CDATA[
		Effect.BlindUp("text_formatting", {duration: 1});
	// ]]>	
		formatting = 0;		
	}
}

function hover(doc, stat) {
	if(stat == 1)
		doc.className = 'list_view_hover';
	else
		doc.className = 'list_view';
}

function getFirefox() {
	document.getElementById('market_text_2').style.display = 'none';
	document.getElementById('market_text_4').style.display = 'none';	
	document.getElementById('market_text_5').style.display = 'none';
	document.getElementById('market_text_6').style.display = 'block';
}

function showfaq(id) {
	if(document.getElementById(id).style.display == 'block')
		document.getElementById(id).style.display = 'none';
	else
		document.getElementById(id).style.display = 'block';
}
