﻿// Common Action For Public Use

//*************************************************************************
// IMAGES BUTTON

initImagesButton = function () {
    SCImageButton.imagesFolder = "";
    SCImageButton.init();
};
SCFramework.attachEvent(window, "load", initImagesButton);

//*************************************************************************
// DIALOGS

showDialog = function (name, title, code) {
	var dialog = eo_GetObject(name);
	if (dialog) dialog.show(true, title, code);
};

closeDialog = function (name) {
	var dialog = eo_GetObject(name);
	if (dialog) dialog.accept();
};

dialogClosing = function (dialog, arg) {
    if (arg.keyCode == 13)
        return 0;
};

openSendToFriendDialog = function (url) {
    var hidden = document.getElementById("ctl00_HFSendToFriend");
    hidden.value = url;
    
    var url = document.getElementById("ctl00_DlgSendToFriend_ctl00_TxtSTFURL");
    if (url) url.value = "";
    
    var message = document.getElementById("ctl00_DlgSendToFriend_ctl00_TxtSTFMessage");
    if (message) message.value = "";
    
	var dialog = eo_GetObject("DlgSendToFriend");
	if (dialog) dialog.show(true);
};

//*************************************************************************
// GALLERY

initGallery = function () {
    try {
        initLightbox();
    } catch (e) {};
};
SCFramework.attachEvent(window, "load", initGallery);

//*************************************************************************
// CALLBACK PANEL

callInfosLoad = function (dialog, arg) {
	var callback = eo_GetObject("CBPSiteInfos");
    if (typeof(arg) == "object") arg = null;
	if (callback) callback.execute(arg, null);
};

callEventLoad = function (dialog, arg) {
	var callback = eo_GetObject("CBPEventInfos");
    if (typeof(arg) == "object") arg = null;
	if (callback) callback.execute(arg, null);
};

//*************************************************************************
// DIV SCROLLER

var intervalId = null;
	
startScrolling = function (id, direction) {
	scrollDiv(id, direction);
	intervalId = window.setInterval("scrollDiv('" + id + "', '" + direction + "')", 10);
};
	
stopScrolling = function () {
	if (intervalId != null) {
		window.clearInterval(intervalId);
		intervalId = null;
	}
};
SCFramework.attachEvent(document, "mouseup", stopScrolling);
	
scrollDiv = function (id, direction) {
	var div = document.getElementById(id);
	var step = 3;
	var nextStep = 0;

	switch (direction) {
	    case "left": 
			var usable = div.scrollWidth - div.clientWidth;
			if (usable < 0) usable = 0;

			nextStep = div.scrollLeft + step;
			if (nextStep > usable) nextStep = usable;
        	div.scrollLeft = nextStep;
			break;
		
		case "right":
			nextStep = div.scrollLeft - step;
			if (nextStep < 0) nextStep = 0;
        	div.scrollLeft = nextStep;
			break;
	        
		case "up": 
			var usable = div.scrollHeight - div.clientHeight;
			if (usable < 0) usable = 0;

			nextStep = div.scrollTop + step;
			if (nextStep > usable) nextStep = usable;
        	div.scrollTop = nextStep;
			break;
				
		case "down":
			nextStep = div.scrollTop - step;
			if (nextStep < 0) nextStep = 0;
        	div.scrollTop = nextStep;
			break;
	}
};

