﻿var lightboxBackground;
var lightboxImage;
var previousDocumentOnclick;

$(document).ready(function() { 
   $("a.lightbox").fancybox();
});

function viewImage(imageUrl)
{	

/*	
	lightboxBackground = document.createElement("div");
	lightboxBackground.className="lightboxBackground";
	
	lightboxImage=document.createElement("img");
	lightboxImage.className = "lightboxImage";
	lightboxImage.src=imageUrl;
    
	document.body.appendChild(lightboxBackground);
	document.body.appendChild(lightboxImage);
	
	previousDocumentOnclick = document.body.onclick;
	
	document.body.onclick=closeImage;
	*/
	
	//window.open(imageUrl, '_image', 'width=500,height=500,status=no');
}
function closeImage()
{
	document.body.onclick = previousDocumentOnclick;
	document.body.removeChild(lightboxBackground);
	document.body.removeChild(lightboxImage);
}

function openWindow(url,title, w, h, center) {
    var options = "width=" + w + ",height=" + h + ",";
    options += "resizable=yes,scrollbars=yes,status=yes,";
    options += "menubar=no,toolbar=no,location=no,directories=no";
    var newWin = window.open(url, 'newWin', options);
    newWin.focus();
 }
 
//Render the content part (between the first and last <!--Content--> comment)of a page into a div 
function renderPageIntoContainerCallback(response, options)
{
	var responseText=response.responseText;
	var cleanedResponseText=responseText.substring(responseText.indexOf('<!--Content-->'),responseText.lastIndexOf('<!--Content-->'));
	options.targetContainer.innerHTML=cleanedResponseText;
	eval(options.callAfterSuccess);
}

function renderPageIntoContainer(pageUrl, container, extraCallback)
{
	Ext.Ajax.request({url: pageUrl, success : renderPageIntoContainerCallback, targetContainer: container, callAfterSuccess: extraCallback});
}

function setInnerHTML(elementId, value)
{
	document.getElementById(elementId).innerHTML = value;
}

function setValue(elementId, value)
{
	document.getElementById(elementId).value = value;
}

function setTextValue(elementId, value)
{
	document.getElementById(elementId).value = value;
}

function getValue(elementId)
{
	return document.getElementById(elementId).value;
}

function clearValue(elementId)
{
	return document.getElementById(elementId).value="";
}

function userToolbox(clientRow, open)
{
	var displayRow=document.getElementById('displayRow'+clientRow);
	var toolboxRow=document.getElementById('toolboxRow'+clientRow);
	if(open)
	{
		displayRow.style.display="none";
		toolboxRow.style.display="block";
	}
	else
	{
		displayRow.style.display="block";
		toolboxRow.style.display="none";
	}
}

function voteRegistred(result)
{
}

function vote(categoryId, voteValue)
{
   Iteam.Trex.Web.Site.Ajax.vote(categoryId, voteValue, function(result)
   {
        if (result.error)
        {
            alert("Fel:\r\n " + result.error.Message);
        } else
        {
            document.getElementById('stars_' + categoryId).style.width = voteValue * 25 + "px";
            document.getElementById('stars_' + categoryId).style.backgroundPosition = "left bottom";
        }
   }
   );
}

//Returns an object with common fields for a user and user profile when you only got a userId
function GetUserProfileInfo(userId)
{
	return Iteam.Trex.Web.Site.Ajax.GetUserProfileInfo(userId);
}