/*
 * Copyright (C) 1995-2011 by 4system Polska Sp. z o.o.
 * All Rights Reserved.
 */
 
componentExit = function(name)
{
	this.componentElement = componentElement;
	this.componentElement(name);
	
	this.popupVisible = false;
};

componentExit.prototype = new componentElement();
componentExit.prototype.type = "componentExit";

componentExit.prototype.onBaseCreate = function(obj)
{
	this.resourcesURL = resourcesURL;
	this.resourcesStatus = "online";
	this.resourcesURL = resourcesURL;
	if (PageInterface.GetValue("state") != psDesigning && lms && lms.name != "lmsOffline") {
		this.resourcesStatus = lms.resourcesStatus();
		if (this.disableOnlineOfflineMix) this.resourcesURL = resourcesURL;
		else this.resourcesURL = lms.resourcesURL();
	}
	this.resourcesURL = unescape(this.resourcesURL);	

	this.imagesNameArr = [this.buttonSrcIn, this.buttonSrcOut, this.buttonYesSrcIn, this.buttonYesSrcOut, this.buttonNoSrcIn, this.buttonNoSrcOut];
	this.getPreloadImagesArr();
};

componentExit.prototype.onCreate = function(text)
{
	this.captureMouseEvents();
	
	this.setImages();
	this.placeHTMLObiects();
	if (PageInterface.GetValue("state") == psDesigning) {
		this.popupShowHide(true);
	};
};

componentExit.prototype.popupShow = function(visible)
{
	var popup = document.getElementById(this.id + "_popup");
	if (popup)
	{
		popup.style.display = "";
	}	
	this.obj.style.clip = 'rect(0px '+this.w+'px '+this.h+'px 0px)';
}
componentExit.prototype.hidePopup = function(visible)
{
	var popup = document.getElementById(this.id + "_popup");
	if (popup)
	{
		popup.style.display = "none";
	}	
	this.setClip();
};

componentExit.prototype.paint = function()
{
	//this.placeHTMLObiects();
	return;
}
componentExit.prototype.popupShowHide = function(show)
{
	if (show) this.popupShow();
	else this.hidePopup();
}

componentExit.prototype.buttonClick = function(e)
{
	this.popupVisible = !this.popupVisible;
	
	this.popupShowHide(this.popupVisible);
};

componentExit.prototype.setClip = function(e)
{
	switch(this.buttonAlign)
	{
		case 0:
			//lt
			this.obj.style.clip = 'rect(0px '+this.buttonW+'px '+this.buttonH+'px 0px)';
			break;
		case 1:
			//rt
			this.obj.style.clip = 'rect(0px '+this.w+'px '+this.buttonH+'px '+eval(this.w-this.buttonW)+'px)';
			break;
		case 2:
			//ld
			this.obj.style.clip = 'rect('+eval(this.h-this.buttonH)+'px '+this.buttonW+'px '+this.h+'px 0px)';
			break;
		case 3:
			//rd
			this.obj.style.clip = 'rect('+eval(this.h-this.buttonH)+'px '+this.w+'px '+this.h+'px '+eval(this.w-this.buttonW)+'px)';
			break;
	}
}

componentExit.prototype.placeHTMLObiects = function(e)
{
	var popupContentTable = document.getElementById(this.id + "_popupContentTable");
	var buttonYes = document.getElementById(this.id + "_buttonYes");
	var buttonNo = document.getElementById(this.id + "_buttonNo");
	var button = document.getElementById(this.id + "_button");
	var popup = document.getElementById(this.id + "_popup");
	
	var popupTitle = document.getElementById(this.id + "_popupTitle");
	popupTitle.style.display = (this.popupPopupTitleVisible)?"":"none";

	buttonNo.style.left = parseInt((this.w-this.popupBorderWidth*2)/4) - parseInt(this.buttonNoW/2);
	buttonNo.style.top = this.h-this.buttonH-this.buttonNoH*2-this.popupBorderWidth*2;
	
	buttonYes.style.left = parseInt((this.w-this.popupBorderWidth*2)*3/4) - parseInt(this.buttonYesW/2);
	buttonYes.style.top = this.h-this.buttonH-this.buttonYesH*2-this.popupBorderWidth*2;
	
	switch(this.buttonAlign)
	{
		case 0:
			//lt
			button.style.left = 0;
			button.style.top = 0;
			popup.style.top = this.buttonH;
			break;
		case 1:
			//rt
			button.style.left = this.w-this.buttonW;
			button.style.top = 0;
			popup.style.top = this.buttonH;
			break;
		case 2:
			//ld
			button.style.left = 0;
			button.style.top = this.h-this.buttonH;
			break;
		case 3:
			//rd
			button.style.left = this.w-this.buttonW;
			button.style.top = this.h-this.buttonH;
			break;
	}
	this.setClip();
	if (is.moz) this.rePlaceElements();
}

componentExit.prototype.rePlaceElements = function()
{
	var popup = document.getElementById(this.id + "_popup");
	var popupTitle = document.getElementById(this.id + "_popupTitle");
	popupTitle.style.width = this.w - this.popupBorderWidth*2-4;
	popup.style.width = this.w - this.popupBorderWidth*2;
	popup.style.height = this.h - this.popupBorderWidth*2-this.buttonH;
}

componentExit.prototype.mouseOverButton = function(obj, imgName)
{
	var button = document.getElementById(this.id + obj);
	if (button) this.setImageSrc(this.resourcesURL + imgName, button);
}

componentExit.prototype.mouseOutButton = function(obj, imgName)
{
	var button = document.getElementById(this.id + obj);
	if (button) this.setImageSrc(this.resourcesURL + imgName, button);
}

componentExit.prototype.setImages = function(e)
{
	var buttonNo = document.getElementById(this.id + "_buttonNoContentObj");
	var buttonYes = document.getElementById(this.id + "_buttonYesContentObj");
	var button = document.getElementById(this.id + "_buttonContentObj");
	
	if (buttonNo) this.setImageSrc(this.resourcesURL + this.buttonNoSrcOut, buttonNo);
	if (buttonYes) this.setImageSrc(this.resourcesURL + this.buttonYesSrcOut, buttonYes);
	if (button) this.setImageSrc(this.resourcesURL + this.buttonSrcOut, button);
}

componentExit.prototype.buttonYesClick = function(e)
{
	this.popupVisible = false;
	this.popupShowHide(this.popupVisible);

	if (this.onYesUrlGo) window.open(this.onYesUrl,this.id,"width="+this.onYesWindowWidth+",height="+this.onYesWindowHeight+",resizable="+this.onYesWindowResize+",scrollbars="+this.onYesWindowScrollbars+",toolbar="+this.onYesWindowToolbar+",location="+this.onYesWindowToolbar+",menubar="+this.onYesWindowToolbar+"");
	//top.opener = "course";
	PlayerInterface.Execute("closeCourse");
};

componentExit.prototype.buttonNoClick = function(e)
{
	this.popupVisible = false;
	this.popupShowHide(this.popupVisible);
};
