//**********************************************************************
// RICH 10march09
// Javascript library for UI
// Currently used for index, profileinfluence, profilestat, 
// profilecontent, profilesummary, profilenetwork, and compare page
//**********************************************************************

//**********************************************************************
// GENERAL (used in profiledetail, profilesummary, and compare pages)
//**********************************************************************
function loadingStatus(str) 
{
	var str = str;
  	startLoading();
  	loadingMessage(str);
  	disable();
}

// This function is used to disable the Search and Compare buttons when loading
// The enable function is inside the ajax.js, because those buttons will be enabled
// when the AJAX script finish loading
function disable()
{
	var button1 = document.getElementById("btnSearch");
	var button2 = document.getElementById("btnCompare");
	document.body.style.cursor = 'wait';
	document.getElementById("contentPlaceHolder").cursor = 'wait';
}

function startLoading() 
{
  	//Element.show('mainAreaLoading');
	document.getElementById('mainAreaLoading').style.display = 'block';
}

var c=0;
var t;

function loadingMessage(str)
{
	var arrLoadMessages = new Array();
	var strMsg = str;
	
	arrLoadMessages = strMsg.split("|");
	var arrCount = arrLoadMessages.length;
	var j = arrCount - 1;

	if (document.getElementById("loadingMessage"))
	{
		if (c < arrCount)
		{
			document.getElementById("loadingMessage").innerHTML= arrLoadMessages[c];
		}
		else
		{
			document.getElementById("loadingMessage").innerHTML= arrLoadMessages[j];
		}
		c=c+1;
		t=setTimeout("loadingMessage('"+str+"')",1000);
	}
}

function toggle(x)
{
	if (document.getElementById(x).style.display == 'none')
	{
		document.getElementById(x).style.display = '';
	}
	else
	{
		document.getElementById(x).style.display = 'none';
	}
}

/*
 Replaced by jQuery style stuff
function compareTab()
{
	document.getElementById('searchTab').style.display = 'none';
	document.getElementById('compareTab').style.display = 'block';
	document.getElementById('searchNavSearch').style.display = 'none';
	document.getElementById('searchNavCompare').style.display = 'block';
	document.getElementById('searchNavSearch2').style.display = 'none';
}

function searchTab()
{
	document.getElementById('compareTab').style.display = 'none';
	document.getElementById('searchTab').style.display = 'block';

	document.getElementById('searchNavCompare').style.display = 'none';
	document.getElementById('searchNavSearch').style.display = 'block';
	document.getElementById('searchNavSearch2').style.display = 'none';
}

function searchTab2()
{
	document.getElementById('compareTab').style.display = 'none';
	document.getElementById('searchTab').style.display = 'block';

	document.getElementById('searchNavCompare').style.display = 'none';
	document.getElementById('searchNavSearch').style.display = 'none';
	document.getElementById('searchNavSearch2').style.display = 'block';
}
//*/

function redirect(name)
{
	var strName = name;
	window.location = "/profile/summary/"+strName;
}

//**********************************************************************
// PROFILE SUMMARY, COMPARE
//**********************************************************************
function toggleDiv(id,flagit) 
{
	if (flagit=="1")
	{
		if (document.layers) document.layers[''+id+''].visibility = "show"
		else if (document.all) document.all[''+id+''].style.visibility = "visible"
		else if (document.getElementById) document.getElementById(''+id+'').style.visibility   = "visible"
	}
	else if (flagit=="0")
	{
		if (document.layers) document.layers[''+id+''].visibility = "hide"
		else if (document.all) document.all[''+id+''].style.visibility = "hidden"
		else if (document.getElementById) document.getElementById(''+id+'').style.visibility   = "hidden"
	}
}

function hideUserDetail(flag)
{
	if (flag=="0")
	{
		toggleDiv('infodiv',0);
		toggleDiv('leftBorder',0);
		toggleDiv('rightBorder',0);
	}
}

// make sure images are case sensitive
function showUserDetail(userName, image_url, score, location, bio, web, x, y, flag)
{
	if (x > 550)
    {
		x -= 300;
	}

    if (y <= 325)
    {
		y += 20;
    }
    else
    {
        y -= 150;
    }

    infoboxHeight = 26;

    strInfo  = '<div id="infodiv" style="position:absolute; margin-left:' + x + 'px; margin-top:' + y + 'px; width:352px; height:auto; min-height:26px; z-index:0; background-color:#FFFFFF;">';
	strInfo += '	<div style="width:352px; height:14px;">';
	strInfo += '		<div style="width:14px; height:14px; background-image:url(/images/boxes/infoBlueTopLeft.gif); background-repeat:no-repeat; float:left;"></div>';
	strInfo += '		<div style="width:324px; height:14px; background-image:url(/images/boxes/infoBlueTop.gif); background-repeat:repeat-x; float:left;"></div>';
	strInfo += '		<div style="width:14px; height:14px; background-image:url(/images/boxes/infoBlueTopRight.gif); background-repeat:no-repeat; float:left;"></div>';
	strInfo += '	</div>';
	strInfo += '	<div style="width:352px; height:auto; margin-top:-2px; background-color:#FFFFFF;">';
	strInfo += '		<div id="leftBorder" style="width:14px; height:' + infoboxHeight + 'px; padding-bottom:0px; background-image:url(/images/boxes/infoBlueLeft.gif); background-repeat:repeat-y; float:left;"></div>';
	strInfo += '        <div style="margin-left:2px; width:72px; height:auto; font-family:Arial; font-size:10px; float:left; text-align:center;">';
	strInfo += '	    	<a class=\"viewProfile\" href=\"/profile/summary/' + userName + '/"><img src="' + image_url + '" alt="' + userName + '" width="70" height="70" border="0"/></a>';
	strInfo += '			<a class=\"viewProfile\" href=\"/profile/summary/' + userName + '/">view profile</a>';
	strInfo += '        </div>';
	strInfo += '		<div style="margin-left:5px; width:244px; height:auto; background-color:#ffffff; font-family:Arial; font-size:10px; font-weight:bold; text-align:left; float:left;">';
	strInfo += '			<div style=\"color:#0281ca; font-size:16px;\">' + userName + '</div>';
	strInfo += '			<div style=\"color:#7f7f7f;float:left;width:25%\">Location:</div><div style=\"color:#7f7f7f;float:left;width:75%\">' + location + '</div><br>';
	strInfo += '			<div style=\"color:#7f7f7f;float:left;width:25%\">Web:</div><div style=\"color:#7f7f7f;float:left;width:75%\">' + web + '</div><br>';
	strInfo += '			<div style=\"color:#7f7f7f;float:left;width:25%\">Bio:</div><div style=\"color:#7f7f7f;float:left;width:75%\">' + bio + '</div>';
	strInfo += '            <div style=\"float:right; width:100%;\">';
	strInfo += '    	    <div style="font-size:36px; color:#D8D8D8; font-weight:normal; float:right; ">' + score + '</div>';
	strInfo += '	        <img src="/images/buttons/kScore.gif" alt="" width="67px" height="23px" style="padding-right:7px; padding-top:10px; float:right;" />';
	strInfo += '       	</div>';
	strInfo += '	</div>';
	strInfo += '	<div id="rightBorder" style="width:14px; height:' + infoboxHeight + 'px; background-image:url(/images/boxes/infoBlueRight.gif); padding-bottom:0px; background-repeat:repeat-y; float:right;"></div>';
	strInfo += '		<div style="clear:both; margin-top:-14px; float:left;"></div>';
	strInfo += '	</div>';
	strInfo += '	<div style="width:352px; height:14px; margin-top:-4px;">';
	strInfo += '		<div style="width:14px; height:14px; background-image:url(/images/boxes/infoBlueBottomLeft.gif); background-repeat:no-repeat; float:left;"></div>';
	strInfo += '		<div style="width:324px; height:14px; background-image:url(/images/boxes/infoBlueBottom.gif); background-repeat:repeat-x; float:left;"></div>';
	strInfo += '		<div style="width:14px; height:14px; background-image:url(/images/boxes/infoBlueBottomRight.gif); background-repeat:no-repeat; float:left;"></div>';
	strInfo += '	</div>';
	strInfo += '</div>';

	document.getElementById('infobox').innerHTML = strInfo;

	var browser = navigator.appName;
	var myInfobox = document.getElementById('infodiv');

	if (browser == 'Microsoft Internet Explorer')
	{
	    infoboxHeight = document.getElementById('infodiv').offsetHeight;
	    infoboxHeight = infoboxHeight - 26;
	}
	else
	{
	    infoboxHeight = document.defaultView.getComputedStyle(myInfobox,"").getPropertyValue("height");
	    infoboxHeight = (infoboxHeight.replace('px', '') - 26) + 'px';
	}
	document.getElementById('leftBorder').style.height = infoboxHeight;
	document.getElementById('rightBorder').style.height = infoboxHeight;
	
	if (flag=="1")
	{
		toggleDiv('infodiv',1);
		toggleDiv('leftBorder',1);
		toggleDiv('rightBorder',1);
	}
	
}

function hideUserDetail()
{
	if (document.getElementById("infobox"))
	{
		document.getElementById('infobox').innerHTML = '<div style="width:0px; height:0px;"></div>';
	}
}

//**********************************************************************
// PROFILE STATS
//**********************************************************************
function updateSkore(name)
{
	var strName = name;
	var url;
	
	url = document.location.href;
	var intCompareURL = url.search(/update/i);
	
	// For profilestat page with update score calc only
	if (intCompareURL == -1)
	{
		url = url + "update";
	}
	window.location = url;
}