var TabHTMLs = new Array(5);

function getImage(id, selected) {
    var image = '/images/tabs/tab_';
    switch(id)
    {
    	case 0:   
    		image = image + 'favorites_'; 
    		break;
    	case 1:   
    		image = image + 'identities_'; 
    		break;
    	case 2:   	
    		image = image + 'fans_'; 
    		break;
    	case 3:   
    		image = image + 'reviews_'; 
    		break;
    	case 4:   
    		image = image + 'niftynotes_'; 
    		break;
	case 5:   
    		image = image + 'friends_'; 
    		break;
    	default:    
    		image = image + 'favorites_';      
    }
    if (selected) {
    	image = image + 'blue.gif'
    } else {
    	image = image + 'white.gif'
    }
    return image;
}

function switchTab(id)
{
	for (i = 0; 5 >= i; i++)
	{
		var img = 'img' + i;
		if (id != i) {
			if (null != document.images[img]) 
				document.images[img].src = getImage(i, false);
		} else {
			document.images[img].src = getImage(i, true);
		}
	}
}

function displayTab(id, user_id) 
{
	switchTab(id);

	if (null != TabHTMLs[id]) {
		displayContent(id, TabHTMLs[id], false);
	} else {
		var url;
		switch(id)
    		{
    		case 0:   
    			url = '/userprofile.php?p=favorites&uid=' + user_id; 
    			break;
    		case 1:   
    			url = '/userprofile.php?p=identities&uid=' + user_id; 
    			break;
    		case 2:   	
    			url = '/userprofile.php?p=fans&uid=' + user_id; 
    			break;
    		case 3:   
    			url = '/userprofile.php?p=reviews&uid=' + user_id; 
    			break;
    		case 4:   
    			url = '/userprofile.php?p=niftynotes&uid=' + user_id; 
    			break;
		case 5:   
    			url = '/userprofile.php?p=friends&uid=' + user_id; 
    			break;
			default:    
    			// Do nothing    
    		}
		getContent(url);
	}
}

function getContent(url)
{
	var waitImage = '<img name=\"img0\" alt=\"...\" src=\"/images/refresh.gif\" width=\"50\" height=\"10\" />';
	var waitTable = '<table cellpadding=\"10\" width=\"100%\" height=\"120\"><tr><td>Please wait'
			+ waitImage + '</td></tr></table>';
	var div = document.getElementById('box_content');
	if (div == 'undefined') {
		div.innerHTML = waitTable;
	}
	var iframe =  frames['ajaxFrame'];
	iframe.location.href = url;
}

function displayServicesContent(id, html)
{
	document.getElementById('content_' + id).innerHTML =  html;
}

function displayContent(id, html, replace)
{
	document.getElementById('box_content').innerHTML =  html;
	if (replace) {
		TabHTMLs[id] = html;
	}
}

function addComment(url)
{
	switchTab(4);
	getContent(url);
}


function deleteComment(url)
{
	if (confirm('Are you sure you want to delete this comment?')) {
		getContent(url);
	}
}

function removeFriend(user_id)
{
	if (confirm('Are you sure you want to remove this friend?')) {
		getContent('/userprofile.php?p=friends&a=remove&uid=' + user_id);
	}
}


function getElement(id, d) {
	if (!d) 
		d = document;
	if (d.getElementById) {
		return d.getElementById(id);
	}
	if (d.layers && d.layers[id]) {
		return d.layers[id];
	}
	if (d.all && d.all[id]) {
		return d.all[id];
    }
}

function removeFavoriteUser(user_id) {
	var waitImage = '<img name=\"img0\" alt=\"...\" src=\"/images/refresh.gif\" width=\"50\" height=\"10\" />';
	var waitTable = '<table border=\"0\" width=\"100%\" height=\"120\"><tr><td>Please wait'
			+ waitImage + '</td></tr></table>';
	document.getElementById('box_content').innerHTML = waitTable;
	var voteLayer = getElement('FavoritesControlFrame');
	voteLayer.src = '/favorites.php?a=remove&uid=' + user_id;
	var iframe =  frames['ajaxFrame'];
	iframe.location.href = '/userprofile.php?p=fav_users';
}

function removeFavoriteSP(service_provider_id) {
	var waitImage = '<img name=\"img0\" alt=\"...\" src=\"/images/refresh.gif\" width=\"50\" height=\"10\" />';
	var waitTable = '<table border=\"0\" width=\"100%\" height=\"120\"><tr><td>Please wait'
			+ waitImage + '</td></tr></table>';
	document.getElementById('box_content').innerHTML = waitTable;
	var voteLayer = getElement('FavoritesControlFrame');
	voteLayer.src = '/favorites.php?a=remove&spid=' + service_provider_id;
	var iframe =  frames['ajaxFrame'];
	iframe.location.href = '/userprofile.php?p=fav_sps';
}

function showNiftyCard(service_provider_id) {
	 window.open("/syndicate.php?p=pop_full&spid=" + service_provider_id, 
	 	"spid" + service_provider_id, 
	 	"toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=297,height=157");
}

function showfull(spid) {
	document.niftycard.src='/syndicate.php?p=image_full&spid=' + spid;
	document.SyndicateForm.code.value=
		'<map name="reviewmaplg-' + spid + '"><area href="http://www.niftyguy.com/" alt="NiftyGuy.com" shape=rect coords="16,12,81,78"></area><area href="http://www.niftyguy.com/identityprofile.php?spid=' + spid + '" alt="My Reviews" shape=rect coords="156,106,256,122"></area><area href="http://www.niftyguy.com/postfeedback.php?step=3&spid=' + spid + '" alt="Post Feedback" shape=rect coords="91,106,152,122"></area></map><img src="http://www.niftyguy.com/syndicate.php?p=image_full&spid=' + spid + '" border="0" usemap="#reviewmaplg-' + spid + '" alt="NiftyCard" />';
}

function showsmall(spid) {
	document.niftycard.src='/syndicate.php?p=image_small&spid=' + spid;
	document.SyndicateForm.code.value=
		'<map name="reviewmapsm-' + spid + '"><area href="http://www.niftyguy.com/" alt="NiftyGuy.com" shape=rect coords="11,11,76,76"></area><area href="http://www.niftyguy.com/identityprofile.php?spid=' + spid + '" alt="My Reviews" shape=rect coords="156,59,256,76"></area><area href="http://www.niftyguy.com/postfeedback.php?step=3&spid=' + spid + '" alt="Post Feedback" shape=rect coords="91,59,152,76"></area></map><img src="http://www.niftyguy.com/syndicate.php?p=image_small&spid=' + spid + '" border="0" usemap="#reviewmapsm-' + spid + '" alt="NiftyCard" />';
}
