﻿// Common Action For Public Use

//*************************************************************************
// 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;
	}
};

//*************************************************************************
// COOKIES

createCookie = function (name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
};

readCookie = function (name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	return null;
};

//*************************************************************************
// SESSION TRACER

var sessionUIDCookieName = "Session_UID";
var pageUID = "P" + (new Date()).getTime().toString();
var utilityURL = "../utility/SessionTracer.aspx";

sessionTracerLoadPage = function () {
    var userUID = readCookie(sessionUIDCookieName);
    
    if (userUID == null) {
        userUID = (new Date()).getTime();
        createCookie(sessionUIDCookieName, userUID, 365);
    }
        
	var image = new Image();
	var url = utilityURL + "?Mode=Load&Page=" + pageUID + "&User=" + userUID;
	image.src = url;
};

sessionTracerUnloadPage = function () {
	var image = new Image();
	var url = utilityURL + "?Mode=Unload&Page=" + pageUID;
	image.src = url;
	
	SCFramework.sleep(100);
};

SCFramework.attachEvent(window, "load", sessionTracerLoadPage);
SCFramework.attachEvent(window, "unload", sessionTracerUnloadPage);





