﻿var _badge = null;
var _friendsWin = null;
var _emailWin = null;

function showDocumentSwf(server,url,width,height,rotation,docID)
{
	if (width==undefined){width=790;}
	if (height==undefined){height=550;}
	if (width==100){width="100%";};
	if (height==100){height="100%";};
	var docOptions =""
	
	docOptions += "rotation=" + rotation + "&embedCount=0&enableFullScreen=1&site_url=" + escape("http://" + window.location.hostname);
	url = server + 'p2f-wrapper.swf?' + docOptions + '&doc_id=' + docID + '&swf_url=' + escape(server + url +'.swf');
	
	ShowSwf(url,width,height,"flashContainer");
}

function InitBadgeWindow()
{
	//instantiate document window
	_badge = new DocstocWindow();
	//set properties
	_badge.title = '';
	_badge.height = '36px';
	_badge.width = '500px';
	_badge.draggable = false;
	_badge.centered = false;
	_badge.closeOnEsc = true;
	_badge.type = 1;
	_badge.formId = 'aspnetForm';
	_badge.clearContentOnHide = false;
	_badge.instanceName = '_badge';
	_badge.preserveContent = true;
	//initialize our window
	_badge.init('tagWin');
}

function ShowBadgePopup(el,contentLocation)
{
	if (_badge == null)
	{
	 //initialize our window
	 InitBadgeWindow();
	}else{
	  _badge.hide();
	}

	//get pointer to hidden div
	var tagDiv = document.getElementById(contentLocation);
	//set the content of our popup to the div's html
	_badge.setContent(tagDiv.innerHTML);
	_badge.setContentOwner(tagDiv);
	//clear the div's html so as to not have duplicate id's in the html page
	tagDiv.innerHTML = '';	


	//set the location.  should be right below the category link
	_badge.setLocationByElement(el, 'right');
	_badge.show();
}

function SearchPortfolioDocs(baseUrl, elName)
{
	//get value from element
	var searchText = $(elName).value;
	
	//alert(searchText);
	
	//change the location of the window
	window.location.href = baseUrl + searchText;
}

function OnFeaturedChange(el, docID)
{
	//alert($(el).id + " " + $(el).checked);
	
	//if checked add
	if ($(el).checked)
	{
		//alert('on');
		
		//declare object
		var oAjax = new AjaxObject101();
		
		//set response type
		oAjax.returnXml = false;
		//set method delegates
		//oAjax.funcWait = Working;
		oAjax.funcDone = OnResponse;
		
		//set up the data
		var data = "docID=" + docID;
		
		//send the request
		oAjax.sndReq("GET", "/Profiles/AddFeaturedDoc.ashx", data);
	}
	else
	{	//if unchecked delete
		//alert('off');
		
		//declare object
		var oAjax = new AjaxObject101();
		
		//set response type
		oAjax.returnXml = false;
		//set method delegates
		//oAjax.funcWait = Working;
		oAjax.funcDone = OnResponse;
		
		//set up the data
		var data = "docID=" + docID;
		
		//send the request
		oAjax.sndReq("GET", "/Profiles/RemoveFeaturedDoc.ashx", data);
	}
}

function OnPortfolioChange(is_checked, docID)
{
	//declare object
	var oAjax = new AjaxObject101();
	
	//set response type
	oAjax.returnXml = false;
	//set method delegates
	//oAjax.funcWait = Working;
	oAjax.funcDone = OnResponse;
	
	//set up the data
	var data = "docID=" + docID;
	var url = "/Profiles/AddDocToPortfolio.ashx";
	if(!is_checked) { url = "/Profiles/RemoveDocFromPortfolio.ashx"; }
	
	//send the request
	oAjax.sndReq("GET", url, data);

	var btn_show = $("btn-show-"+ docID);
	var btn_hide = $("btn-hide-"+ docID);

	if(is_checked)
	{
		btn_show.src = "http://i.docstoccdn.com/profile/btn-show-on.png";
		btn_hide.src = "http://i.docstoccdn.com/profile/btn-hide-off.png";
	}
	else
	{
		btn_show.src = "http://i.docstoccdn.com/profile/btn-show-off.png";
		btn_hide.src = "http://i.docstoccdn.com/profile/btn-hide-on.png";
	}
}

function OnResponse(data)
{
	if (data.length > 0)
	{
		//something went wrong, notify the user
		alert(data);
	}
}

function MemberRSS(memID)
{
	window.location = "/Feeds/rss.ashx?id=3&memid=" + memID;
}

function InitFriendsWin()
{
	//instantiate document window
	_friendsWin = new DocstocWindow();
	//set properties
	_friendsWin.title = '';
	_friendsWin.height = '60px';
	_friendsWin.width = '350px';
	_friendsWin.draggable = false;
	_friendsWin.centered = true;
	_friendsWin.instanceName = '_friendsWin';
	//initialize our window
	_friendsWin.init('friendsWin');
}

function InitEmailWin()
{
	//instantiate document window
	_emailWin = new DocstocWindow();
	//set properties
	_emailWin.title = '';
	_emailWin.height = '520px';
	_emailWin.width = '770px';
	_emailWin.draggable = true;
	_emailWin.centered = true;
	_emailWin.instanceName = '_emailWin';
	//initialize our window
	_emailWin.init('emailWin');
}

function AddContact(friend_id)
{
	try
	{
		if (_friendsWin == null) InitFriendsWin();

		_friendsWin.setUrl("/Docs/AddToFriends.aspx?friend_id=" + friend_id);
		_friendsWin.center();
		_friendsWin.show();
	}
	catch(err)
	{
		alert(err.message);
	}
}

function SendMessage(member_id)
{
	try
	{
		if (_emailWin == null) InitEmailWin();
		
		_emailWin.setUrl("/Messages/sendmail_window.aspx?mem_id=" + member_id);
		_emailWin.center();
		_emailWin.show();
	}
	catch(err)
	{
		alert(err.message);
	}
}

function showActionsPanel(container, member_id)
{
	var actionsPanel = $("actionsPanel" + member_id);
	actionsPanel.y = container.y;
	actionsPanel.style.display = "block";
}

function hideActionsPanel(member_id)
{
	var actionsPanel = $("actionsPanel" + member_id);;
	actionsPanel.style.display = "none";
}

function handleSearchWithin(e,baseUrl, elName)
{
	var keyPressed;
	
	if (window.event) // IE
	{
		keyPressed = event.keyCode;
	}
	else if(e != undefined && e.which) // Netscape/Firefox/Opera
	{
		keyPressed = e.which;
	}
	
	if (keyPressed == 13)
	{
		SearchPortfolioDocs(baseUrl, elName);
		
		return false;
	}
	
	return true;
}

function EditContact(id)
{
	//show some 
	$('buttonsCA' + id).className = 'visible';
	$('nameEdit' + id).className = 'visible';
	$('emailEdit' + id).className = 'visible';
	//hide others
	$('buttonsED' + id).className = 'invisible';
	$('nameView' + id).className = 'invisible';
	$('emailView' + id).className = 'invisible';
}

function CancelContactChanges(id)
{
	//hide some 
	$('buttonsCA' + id).className = 'invisible';
	$('nameEdit' + id).className = 'invisible';
	$('emailEdit' + id).className = 'invisible';
	//show others
	$('buttonsED' + id).className = 'visible';
	$('nameView' + id).className = 'visible';
	$('emailView' + id).className = 'visible';
}

function ApplyContactChanges(id, memID)
{
	//get name
	var name = $('nameInput' + id).value;
	//get email
	var email = $('emailInput' + id).value;

	//declare object
	var oAjax = new AjaxObject101();
	
	//set response type
	oAjax.returnXml = false;
	//set method delegates
	//oAjax.funcWait = Working;
	oAjax.funcDone = OnApplyContactChangesDone;
	
	//set up the data
	var data = "adrID=" + id + "&memID=" + memID + "&name=" + name + "&email=" + email;
	
	//send the request
	oAjax.sndReq("GET", "/Profiles/ApplyContactChanges.ashx", data);
	
	//hide stuff
	CancelContactChanges(id);
}

function OnApplyContactChangesDone(result)
{
	if (result.length > 0)
	{
		//display the error
		alert(result);
	}
}

function DeleteContact(id, memID)
{
	//ask permission?
	
	//declare object
	var oAjax = new AjaxObject101();
	
	//set response type
	oAjax.returnXml = false;
	//set method delegates
	//oAjax.funcWait = Working;
	oAjax.funcDone = OnDeleteContactDone;
	
	//set up the data
	var data = "adrID=" + id + "&memID=" + memID;
	
	//send the request
	oAjax.sndReq("GET", "/Profiles/DeleteContact.ashx", data);
}

function OnDeleteContactDone(result)
{
	if (result.length > 0)
	{
		//display the error
		alert(result);
	}
}
function setDeleteAction(name){
   $('hidDeleteItem').value = name;
}
        