/*
 * Copyright ÄŹĹĽËť 1995-2011 by 4system Polska Sp. z o.o.
 * All Rights Reserved. v4
 */

componentSimplePopup = function(name)
{
	this.componentTextWithScroll = componentTextWithScroll;
	this.componentTextWithScroll(name);
	this.staticLibText = new __componentText(null);
	
	this.buttonPadding = 0;
	this.headerHeight = 0;
};

componentSimplePopup.prototype = new componentTextWithScroll();
componentSimplePopup.prototype.type = "componentSimplePopup";

componentSimplePopup.prototype.onBaseCreate = function(obj)
{
	this.resourcesStatus = "online";
	this.resourcesURL = resourcesURL;

	var o = document.getElementById(this.id + "_contentObj");
	if (o) {
		var t = o.innerHTML;
		t = this.staticLibText.initText(t);
		o.innerHTML = t;
	}

	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.arrowTopOver, this.arrowTopOut, this.arrowBottomOver, this.arrowBottomOut, this.sliderOver, this.sliderOut, this.sliderBckg, this.bckgImg, this.buttonOut, this.buttonOver];
	this.getPreloadImagesArr();
	this.setCompleteArrayInfo(this.completeInfoStyleImages);
	
	this.captureMouseEvents();
};

componentSimplePopup.prototype.componentSimplePopupBaseSetHTMLObiects = componentSimplePopup.prototype.setHTMLObiects;
componentSimplePopup.prototype.setHTMLObiects = function(obj)
{
	this.componentSimplePopupBaseSetHTMLObiects();
	
	var trackDiv = document.getElementById(this.id + "_trackDiv");
	var arrowBottomDiv = document.getElementById(this.id + "_arrowBottomDiv");
	var arrowTopDiv = document.getElementById(this.id + "_arrowTopDiv");
	var trackBckgDiv = document.getElementById(this.id + "_trackBckgDiv");
	var tableDiv = document.getElementById(this.id + "_tableDiv");		
	var Table = document.getElementById(this.id + "Table");	
	//var textFieldW = this.w - 2*this.borderWidth - 2*this.contentPadding - this.getImageWidth('sliderBckg') - 2*this.textSpacing;
	var textFieldW = this.w - 2*this.borderWidth - this.textAreaOffsetLeft - this.textAreaOffsetRight - this.getImageWidth('sliderBckg') - 2*this.textSpacing;
		
	if (this.buttonsActive){
		Table.width = textFieldW;
		tableDiv.style.width = textFieldW;
		tableDiv.style.clip = 'rect(0px '+textFieldW+'px '+tableDiv.style.height+' 0px)';	
		
		if (this.dir == "rtl") {
			//tableDiv.style.left = this.borderWidth + this.contentPadding + this.getImageWidth('sliderBckg') + this.textSpacing;
			tableDiv.style.left = this.borderWidth + this.textAreaOffsetRight + this.getImageWidth('sliderBckg') + this.textSpacing;
		}
		
		trackBckgDiv.style.visibility = 'inherit';
		arrowTopDiv.style.visibility = 'inherit';
		arrowBottomDiv.style.visibility = 'inherit';
		trackDiv.style.visibility = 'inherit';
	}else{
		Table.width = '100%';//textFieldW + this.getImageWidth('sliderBckg');//this.w - 2*this.borderWidth - 2*this.contentPadding - 2*this.textSpacing;
		tableDiv.style.width = textFieldW + this.getImageWidth('sliderBckg');
		tableDiv.style.clip = 'rect(0px '+tableDiv.style.width+' '+tableDiv.style.height+' 0px)';	
		if (this.dir == "rtl") {
			//tableDiv.style.left = this.borderWidth + this.contentPadding + this.textSpacing;
			tableDiv.style.left = this.borderWidth + this.textAreaOffsetRight + this.textSpacing;
		}
		
		trackBckgDiv.style.visibility = 'hidden';
		arrowTopDiv.style.visibility = 'hidden';
		arrowBottomDiv.style.visibility = 'hidden';
		trackDiv.style.visibility = 'hidden';
	};
	
	var bckgImg = document.getElementById(this.id + "_bckgImg");
	if (bckgImg) bckgImg.src = this.resourcesURL + this.bckgImg;
	
	var buttonImg = document.getElementById(this.id + "_buttonImg")
	if (buttonImg) buttonImg.src = this.resourcesURL + this.buttonOut;
};

componentSimplePopup.prototype.componentSimplePopupBaseShow = componentSimplePopup.prototype.show;
componentSimplePopup.prototype.show = function(obj)
{
	this.componentSimplePopupBaseShow();
	this.mouseIsDown = true;
	this.moveScroll(0);
	this.mouseIsDown = false;
	if (this.canDragging) {
		if (PageInterface.GetValue("state") != psDesigning) PageInterface.Execute("setOnTop", this);
	};
}

componentSimplePopup.prototype.beginDrag = function(obj)
{
	PageInterface.Execute("setOnTop", this);
}

componentSimplePopup.prototype.placeHTMLObiects = function(obj)
{
	var textTitleDIV = document.getElementById(this.id + "_textTitleDIV");
	var buttonDIV = document.getElementById(this.id + "_buttonDIV");
	var arrowTopDiv = document.getElementById(this.id + "_arrowTopDiv");
	var arrowBottomDiv = document.getElementById(this.id + "_arrowBottomDiv");
	var trackBckgDiv = document.getElementById(this.id + "_trackBckgDiv");
	var trackDiv = document.getElementById(this.id + "_trackDiv");
	var tableDiv = document.getElementById(this.id + "_tableDiv");	
	
	//arrowTopDiv.style.top = this.headerHeight+this.borderWidth+this.contentPadding;
	arrowTopDiv.style.top = this.headerHeight+this.borderWidth+this.textAreaOffsetTop;
	if (this.dir == "rtl") {
		//arrowTopDiv.style.left = this.borderWidth+this.contentPadding;	
		arrowTopDiv.style.left = this.borderWidth+this.textAreaOffsetRight;	
	} else {
		//arrowTopDiv.style.left = this.w - this.getImageWidth('arrowTopOut')-2*this.borderWidth-this.contentPadding;	
		arrowTopDiv.style.left = this.w - this.getImageWidth('arrowTopOut')-2*this.borderWidth-this.textAreaOffsetRight;	
	}
	arrowTopDiv.style.width = this.getImageWidth('arrowTopOut');
	arrowTopDiv.style.height = this.getImageHeight('arrowTopOut');
	arrowTopDiv.style.clip = 'rect(0px '+this.getImageWidth('arrowTopOut')+'px '+this.getImageHeight('arrowTopOut')+'px 0px)';
	
	//arrowBottomDiv.style.top = this.h - this.getImageHeight('arrowBottomOut')-2*this.borderWidth-this.contentPadding;
	arrowBottomDiv.style.top = this.h - this.getImageHeight('arrowBottomOut')-2*this.borderWidth-this.textAreaOffsetDown;
	if (this.dir == "rtl") {
		//arrowBottomDiv.style.left = this.borderWidth+this.contentPadding;
		arrowBottomDiv.style.left = this.borderWidth+this.textAreaOffsetRight;
	} else {
		//arrowBottomDiv.style.left = this.w - this.getImageWidth('arrowBottomOut')-2*this.borderWidth-this.contentPadding;
		arrowBottomDiv.style.left = this.w - this.getImageWidth('arrowBottomOut')-2*this.borderWidth-this.textAreaOffsetRight;
	}		
	
	arrowBottomDiv.style.width = this.getImageWidth('arrowBottomOut');
	arrowBottomDiv.style.height = this.getImageHeight('arrowBottomOut');
	arrowBottomDiv.style.clip = 'rect(0px '+this.getImageWidth('arrowBottomOut')+'px '+this.getImageHeight('arrowBottomOut')+'px 0px)';
	
	//trackBckgDiv.style.top = this.headerHeight+this.borderWidth+this.contentPadding;
	trackBckgDiv.style.top = this.headerHeight+this.borderWidth+this.textAreaOffsetTop;
	if (this.dir == "rtl") {
		//trackBckgDiv.style.left = this.borderWidth+this.contentPadding;
		trackBckgDiv.style.left = this.borderWidth+this.textAreaOffsetRight;
	} else {
		//trackBckgDiv.style.left = this.w - this.getImageWidth('sliderBckg')-2*this.borderWidth-this.contentPadding;
		trackBckgDiv.style.left = this.w - this.getImageWidth('sliderBckg')-2*this.borderWidth-this.textAreaOffsetRight;
	}
	trackBckgDiv.style.width = this.getImageWidth('sliderBckg');
	//trackBckgDiv.style.height = this.h - 2*this.borderWidth - 2*this.contentPadding - this.headerHeight;
	trackBckgDiv.style.height = this.h - 2*this.borderWidth - this.textAreaOffsetTop - this.textAreaOffsetDown - this.headerHeight;
	trackBckgDiv.style.clip = 'rect(0px '+this.getImageWidth('sliderBckg')+'px '+this.h+'px 0px)';
	
	//this.sliderLowOffset = this.getImageHeight('arrowTopOut') + this.contentPadding + this.headerHeight;
	this.sliderLowOffset = this.getImageHeight('arrowTopOut') + this.textAreaOffsetTop + this.headerHeight;
	//this.trackHeight = this.h - 2*this.borderWidth - 2*this.contentPadding - this.headerHeight - this.getImageHeight('arrowTopOut') - this.getImageHeight('arrowBottomOut');
	this.trackHeight = this.h - 2*this.borderWidth - this.textAreaOffsetTop - this.textAreaOffsetDown - this.headerHeight - this.getImageHeight('arrowTopOut') - this.getImageHeight('arrowBottomOut');
	this.sliderHighOffset = this.trackHeight - this.getImageHeight('sliderOut');
	
	trackDiv.style.top = this.sliderLowOffset;
	if (this.dir == "rtl") {
		//trackDiv.style.left = this.borderWidth+this.contentPadding;
		trackDiv.style.left = this.borderWidth+this.textAreaOffsetRight;
	} else {
		//trackDiv.style.left = this.w - this.getImageWidth('sliderOut')-2*this.borderWidth-this.contentPadding;
		trackDiv.style.left = this.w - this.getImageWidth('sliderOut')-2*this.borderWidth-this.textAreaOffsetRight;
	}

	if(buttonDIV)
	{
		buttonDIV.style.top = this.closeButtonOffsetTop;
		if (this.dir == "rtl") {
			buttonDIV.style.left = this.closeButtonOffsetRight;
		}else{
			buttonDIV.style.left = this.w-this.closeButtonOffsetRight-this.buttonW;
		}
	}
	
	if (textTitleDIV)
	{	
		textTitleDIV.style.top = this.headerTextOffsetTop;
		if (this.dir == "rtl") {
			textTitleDIV.style.left = this.headerTextOffsetRight;
		}else{
			textTitleDIV.style.left = this.headerTextOffsetLeft;
		}
		textTitleDIV.style.width = this.w-this.headerTextOffsetLeft-this.headerTextOffsetRight;
	}
	
	trackDiv.style.width = this.getImageWidth('sliderOut');
	trackDiv.style.height = this.getImageHeight('sliderOut');
	trackDiv.style.clip = 'rect(0px '+this.getImageWidth('sliderOut')+'px '+this.getImageHeight('sliderOut')+'px 0px)';
	//var textFieldW = this.w - 2*this.borderWidth - 2*this.contentPadding - this.getImageWidth('sliderOut') - 2*this.textSpacing;
	var textFieldW = this.w - 2*this.borderWidth - this.textAreaOffsetLeft - this.textAreaOffsetRight - this.getImageWidth('sliderOut') - 2*this.textSpacing;
	//var textFieldH = this.h - 2*this.borderWidth - this.headerHeight - 2*this.contentPadding - 2*this.textSpacing;	
	var textFieldH = this.h - 2*this.borderWidth - this.headerHeight - this.textAreaOffsetTop - this.textAreaOffsetTop - 2*this.textSpacing;	
	
	//tableDiv.style.left = this.borderWidth + this.contentPadding + this.textSpacing;
	if (this.dir == "rtl") {
		tableDiv.style.left = this.borderWidth + this.textAreaOffsetRight + this.textSpacing;
	}else{
		tableDiv.style.left = this.borderWidth + this.textAreaOffsetLeft + this.textSpacing;
	}
	//tableDiv.style.top = this.contentPadding + this.borderWidth + this.headerHeight + this.textSpacing;
	tableDiv.style.top = this.textAreaOffsetTop + this.borderWidth + this.headerHeight + this.textSpacing;
	tableDiv.style.width = textFieldW; 
	tableDiv.style.height = textFieldH;	
	tableDiv.style.clip = 'rect(0px '+textFieldW+'px '+textFieldH+'px 0px)';
};

componentSimplePopup.prototype.getTextHeight = function(obj)
{
	var tableDiv = document.getElementById(this.id + "_tableDiv");
	var Table = document.getElementById(this.id + "Table");

	//########
	this.textHeight = Table.scrollHeight;
	
	//var textFieldW = this.w - 2*this.borderWidth - 2*this.contentPadding - this.getImageWidth('sliderOut') - 2*this.textSpacing;
	var textFieldW = this.w - 2*this.borderWidth - this.textAreaOffsetLeft - this.textAreaOffsetRight - this.getImageWidth('sliderOut') - 2*this.textSpacing;
	//var textFieldH = this.h - 2*this.borderWidth - this.headerHeight - 2*this.contentPadding - 2*this.textSpacing;	
	var textFieldH = this.h - 2*this.borderWidth - this.headerHeight - this.textAreaOffsetTop - this.textAreaOffsetDown - 2*this.textSpacing;	
	
	this.buttonsActive = (textFieldH <= this.textHeight) ? true : false;
	if (this.buttonsActive){
		tableDiv.style.width = this.w - 2*this.borderWidth-60; 
	}else{
		tableDiv.style.width = textFieldW; 
	};
	tableDiv.style.height = textFieldH; 
	//########
	tableDiv.style.clip = 'rect(0px '+textFieldW+'px '+eval(this.w - 2*this.borderWidth)+'px 0px)';
};

componentSimplePopup.prototype.changeBtnImage = function(objName, name)
{
	var buttonDIV = document.getElementById(this.id + objName);
	if (buttonDIV) this.setImageSrc(this.resourcesURL + name, buttonDIV);
	//buttonDIV.src = this.resourcesURL + name;
}

























