﻿var s1prototype = new Object();
var s1          = s1prototype;
var s1window    = new Object();

s1prototype.WINDOW  = new Object();
s1prototype.EVENTS  = new Object();
s1prototype.VALID   = new Object();
s1prototype.STRINGS = new Object();
s1prototype.NUMBERS = new Object();
s1prototype.DATES   = new Object();
s1prototype.ARRAYS  = new Object();
s1prototype.LOCALE  = new Object();
s1prototype.AJAX    = new Object();
s1prototype.XML     = new Object();
s1prototype.DOM     = new Object();
s1prototype.EFFECTS = new Object();
s1prototype.BROWSER = new Object();

s1window            = new Object();

s1prototype.WINDOW.preload          = WINDOW_preload;
s1prototype.WINDOW.getViewport      = WINDOW_getViewport;          //credits to Andy Langton and Mikhail Valerie : http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/
s1prototype.WINDOW.getScroll        = WINDOW_getScroll;            //credits to Mark "Tarquin" Wilton-Jones      : http://www.howtocreate.co.uk/
s1prototype.WINDOW.htmlToWindow     = WINDOW_htmlToWindow;
s1prototype.WINDOW.printToWindow    = WINDOW_printToWindow;
s1prototype.WINDOW.createIframe     = WINDOW_createIframe;

s1prototype.EVENTS.preventBubbling  = EVENTS_preventBubbling;
s1prototype.EVENTS.getEventSource   = EVENTS_getEventSource;

s1prototype.VALID.validatorStatic   = VALID_validatorStatic();
s1prototype.VALID.validator         = VALID_validator;

s1prototype.STRINGS.mappings        = {greek: ["ΆΑ", "ΈΕ", "ΉΗ", "ΊΙ", "ΌΟ", "ΎΥ", "ΏΩ", "ΪΙ", "ΫΥ",  "άα", "έε", "ήη", "ίι", "ΰυ", "ϊι", "ϋυ", "όο", "ύυ", "ώω"]};

s1prototype.STRINGS.format          = STRINGS_format;
s1prototype.STRINGS.replaceAll      = STRINGS_replaceAll;
s1prototype.STRINGS.getMatchIndices = STRINGS_getMatchIndices;
s1prototype.STRINGS.inject          = STRINGS_inject;   
s1prototype.STRINGS.asciiEncode     = STRINGS_asciiEncode;
s1prototype.STRINGS.asciiDecode     = STRINGS_asciiDecode;
String.prototype.map                = STRINGS_map;
String.prototype.isInteger          = STRINGS_isInteger;
String.prototype.isUnsignedInteger  = STRINGS_isUnsignedInteger;
String.prototype.trim               = STRINGS_trim;
String.prototype.sameText           = STRINGS_sameText;
String.prototype.isIn               = STRINGS_isIn;
String.prototype.truncate           = STRINGS_truncate;

Number.prototype.isInteger          = NUMBERS_isInteger;

s1prototype.DATES.getDiff           = DATES_getDiff; 

s1prototype.ARRAYS.removeDuplicate  = ARRAYS_removeDuplicate;

s1prototype.LOCALE.loadLabels       = LOCALE_loadLabels;
s1prototype.LOCALE.localize         = LOCALE_localize;

s1prototype.AJAX.ajaxCaller         = AJAX_ajaxCaller;

s1prototype.DOM.o                     = DOM_o;
s1prototype.DOM.getDocHeight          = DOM_getDocHeight;       //credits to James Padolsey : http://james.padolsey.com/
s1prototype.DOM.nextElement           = DOM_nextElement;
s1prototype.DOM.previousElement       = DOM_previousElement;
s1prototype.DOM.getPosition           = DOM_getPosition;
s1prototype.DOM.getMousePosition      = DOM_getMousePosition;   //credits to Jan Wolter     : http://unixpapa.com/js/
s1prototype.DOM.getMouseButton        = DOM_getMouseButton;     //credits to Jan Wolter     : http://unixpapa.com/js/
s1prototype.DOM.switchDisplay         = DOM_switchDisplay;
s1prototype.DOM.switchVisibility      = DOM_switchVisibility;
s1prototype.DOM.toggleDisplay         = DOM_toggleDisplay;
s1prototype.DOM.appendStylesheet      = DOM_appendStylesheet;   //credits to Jon Raasch     : http://jonraasch.com/blog/javascript-style-node
s1prototype.DOM.appendClass           = DOM_appendClass;
s1prototype.DOM.removeClass           = DOM_removeClass;
s1prototype.DOM.bubbleToTag           = DOM_bubbleToTag;
s1prototype.DOM.getElements           = DOM_getElements;
s1prototype.DOM.getElementsByClass    = DOM_getElementsByClass;
s1prototype.DOM.getInputsByType       = DOM_getInputsByType;
s1prototype.DOM.getChildrenByTag      = DOM_getChildrenByTag;
s1prototype.DOM.getSelectedOption     = DOM_getSelectedOption;
s1prototype.DOM.removeSelections      = DOM_removeSelections;
s1prototype.DOM.getOptionIndexByText  = DOM_getOptionIndexByText;
s1prototype.DOM.getOptionIndexByValue = DOM_getOptionIndexByValue;
s1prototype.DOM.centerOnScreen        = DOM_centerOnScreen;
s1prototype.DOM.centerOnArea          = DOM_centerOnArea;
s1prototype.DOM.modalize              = DOM_modalize;
s1prototype.DOM.modalizeArea          = DOM_modalizeArea;

s1prototype.XML.loadXml            = XML_loadXml;
s1prototype.XML.loadFromString     = XML_loadFromString;
s1prototype.XML.s1LoadXml          = XML_s1LoadXml;
s1prototype.XML.nodeValue          = XML_nodeValue;

s1prototype.EFFECTS.slider         = EFFECTS_slider;
s1prototype.EFFECTS.hslider        = EFFECTS_hslider;
s1prototype.EFFECTS.fader          = EFFECTS_fader;
s1prototype.EFFECTS.dragHandler    = EFFECTS_dragHandler();   //credits to http://www.webtoolkit.info/


s1prototype.BROWSER.setCookie      = BROWSER_setCookie;
s1prototype.BROWSER.getCookie      = BROWSER_getCookie;

/***************** WINDOW *****************/

function WINDOW_preload(strImgs, strRoot)
{
    var imgNew = null;
    arrImg     = strImgs.split("|");
    
    for (var i=0,j=arrImg.length; i<j; i++)
    {
        imgNew     = new Image;
        imgNew.src = (strRoot || "") + arrImg[i];
        arrImg[i]  = imgNew;
    }
	
    return arrImg;
};

function WINDOW_getViewport() 
{
	var h = window.innerHeight || document.documentElement.clientHeight || document.getElementsByTagName('body')[0].clientHeight;
	var w = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;

	return { width : w , height : h };
};

function WINDOW_getScroll() 
{
	var Xscroll = 0;
	var Yscroll = 0;
	
	if (typeof (window.pageYOffset) == 'number') 
	{
		//Netscape compliant
		Yscroll = window.pageYOffset;
		Xscroll = window.pageXOffset;
	} 
	else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) 
	{
		//DOM compliant
		Yscroll = document.body.scrollTop;
		Xscroll = document.body.scrollLeft;
	} 
	else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) 
	{
		//IE6 standards compliant mode
		Yscroll = document.documentElement.scrollTop;
		Xscroll = document.documentElement.scrollLeft;
	}
	return {left: Xscroll, top: Yscroll};
};

function WINDOW_htmlToWindow(strToPrint, strWindowName, strWindowFeatures, settings)
{
	//Boolean values: { yes | no | 1 | 0 }
	//[status, toolbar, location, menubar, directories, resizable, scrollbars, height, width]
	var w         = null;
	this.settings = settings || {left:0, top:0};

    w = window.open('', strWindowName, strWindowFeatures);
	
	w.moveTo(this.settings.left, this.settings.top);
    w.document.write(strToPrint);
	w.document.close();
	
	return w;
};

function WINDOW_printToWindow(strToPrint, strWindowName, strWindowFeatures, settings)
{
	//Boolean values: { yes | no | 1 | 0 }
	//[status, toolbar, location, menubar, directories, resizable, scrollbars, height, width]
	var w = s1prototype.WINDOW.htmlToWindow(strToPrint, strWindowName, strWindowFeatures, settings);

	w.focus();
    w.print();
	w.close();
};

function WINDOW_createIframe(objAppendTo, strId, strInnerHTML)
{
	var el = document.createElement("iframe");
	el.setAttribute('id', strId);
	el.setAttribute('name', strId);
	document.body.appendChild(el);

	var doc = window.frames[strId].document;

	doc.open();
	doc.close();
	
	doc.body.innerHTML = strInnerHTML;
	
	return el;
};

/***************** EVENTS *****************/

function EVENTS_preventBubbling(e)
{
	var e = e || window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
};

function EVENTS_getEventSource(e) 
{
	var target = null;
	var e      = e || window.event;
	
	if (e.target) target = e.target;
	else if (e.srcElement) target = e.srcElement;
	
	if (target.nodeType == 3) // defeat Safari bug
		target = target.parentNode;

    return target;
};

/***************** VALID *****************/

function VALID_validatorStatic() 
{
	var obj = {
	
		modes 		    : 	{
								required       : {	
													pattern: "\\S",
													error  : "!",
													log    : "You have not filled in a required input field."
												},
								email          : {	
													pattern: "\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*",
													error  : "!",
													log    : "The value of an email input field is not well formatted."
												},
								integer        : {	
													pattern: "^[0-9]+$",
													error  : "!",
													log    : "The value of an integer input field is not well formatted."
												},
								unsignedInteger: {	
													pattern: "^-?[0-9]+$",
													error  : "!",
													log    : "The value of an unsigned integer input field is not well formatted."
												},
								floating      : {	
													pattern: "^((\\d+(\\.\\d*)?)|((\\d*\\.)?\\d+))$",
													error  : "!",
													log    : "The value of a float input field is not well formatted."
												},
								custom         : {	
													error  : "!",
													log    : "An input field has not been filled in properly."
												}	
							},
	
		matchPattern 	: 	function(strText, strPattern, strArgs)
							{
								var re = new RegExp(strPattern, strArgs || "");
								
								return re.test(strText);
							}
	};
	
	return obj;
};

function VALID_validator(objValidatePack)
{
	this.validatePack   = objValidatePack;
	this.watchList      = {};
	this.logArea        = null;
	this.onScanComplete = function(){};

	var validatorStatic = s1.VALID.validatorStatic;
	var self            = this;
	var errorId         = "#validator_{0}_error";
	var logId           = "#validator_{0}_log";

	this.init = function()
				{
					var tempPack  = null;
					var tempField = null;
					var tempRule  = null;
					
					for (var packName in this.validatePack)
					{
						tempPack         = this.validatePack[packName];
						tempPack.fieldId = tempPack.fieldId || packName;
						tempField        = s1.DOM.o(tempPack.fieldId);

						for (var rule in tempPack.rules)
						{
							tempRule = tempPack.rules[rule];
							
							if (tempRule.watchme)
								{this.watchList[packName] = tempRule.watchme;}
							
							switch (tempRule.mode)
							{
								case "required":
									tempRule.error = tempRule.error || validatorStatic.modes.required.error;
									tempRule.log   = tempRule.log || validatorStatic.modes.required.log;
									break;
								case "email":
									tempRule.error = tempRule.error || validatorStatic.modes.email.error;
									tempRule.log   = tempRule.log || validatorStatic.modes.email.log;
									break;
								case "integer":
									tempRule.error = tempRule.error || validatorStatic.modes.integer.error;
									tempRule.log   = tempRule.log || validatorStatic.modes.integer.log;
									break;
								case "unsignedInteger":
									tempRule.error = tempRule.error || validatorStatic.modes.unsignedInteger.error;
									tempRule.log   = tempRule.log || validatorStatic.modes.unsignedInteger.log;
									break;
								case "custom":
									tempRule.error = tempRule.error || validatorStatic.modes.custom.error;
									tempRule.log   = tempRule.log || validatorStatic.modes.custom.log;
									break;
							}
						}
						
						if (tempField)
						{
							tempField.onblur = 	(function(aPackName)
																{return function() 	
																					{
																						self.isFieldValid(aPackName);
																						
																						for (var pack in self.watchList)
																						{
																							if (self.watchList[pack] == 'yes')
																								{self.isFieldValid(pack);}
																							else
																								self.clearField(pack);
																						}
																					};
																}
												)(packName);
						}
						
					}
				};
	
	this.isFieldValid = function(strPackName)
						{
							var pack          = this.validatePack[strPackName],
								objField      = s1.DOM.o(pack.fieldId),
							    _log          = "",
							    divErrorId    = s1.STRINGS.format(errorId, pack.fieldId),
							    divLogId      = s1.STRINGS.format(logId, pack.fieldId),
							    tempRule      = null,
							    tempCheck     = false,
							    tempError     = "",
							    tempLog       = "",
                                tempWrapper   = null;
							
							for (var rule in pack.rules)
							{
								tempRule    = pack.rules[rule];
								tempCheck   = isRuleValid(pack, tempRule);
							
								if (!tempCheck)
								{
									tempError   = tempRule.error;
									tempLog     = tempRule.log;
                                    tempWrapper = s1.DOM.o(tempRule.wrapper);
									/******* error *******/
                                    if (tempWrapper)
                                    {
                                        tempWrapper.style.display = "block";
                                    }
                                    else
                                    {
									    var oldDiv       = s1.DOM.o(divErrorId);
									    var newDiv       = document.createElement("span");
									    newDiv.id        = divErrorId;
									    newDiv.innerHTML = tempError;
									
									    if (objField)
									    {
										    if (!oldDiv)
										    {
											    if (objField.nextSibling)
												    objField.parentNode.insertBefore(newDiv,objField.nextSibling);
											    else
												    objField.parentNode.appendChild(newDiv);
										    }
										    else
										    {
											    objField.parentNode.replaceChild(newDiv, oldDiv);
										    }
									    }
                                    }
									/******* log *******/
									var _logArea  = s1.DOM.o(this.logArea);
									
									if (_logArea)
									{
										var oldLine       = s1.DOM.o(divLogId);
										var newLine       = null;
										
										newLine           = document.createElement("div");
										newLine.id        = divLogId;
										newLine.innerHTML = tempRule.log;
										
										if (!oldLine)
										{
											_logArea.appendChild(newLine);
										}
										else
										{
											oldLine.parentNode.replaceChild(newLine, oldLine);
										}
										
										_logArea.style.display = "block";
									}
									
									return {isValid: false, log: tempLog};
								}
							}
							
							this.clearField(strPackName);
							
							return {isValid: true, log: _log};
						};
						
	this.clearField = function(strPackName)
						{
                            var pack        = this.validatePack[strPackName],
								divErrorId  = s1.STRINGS.format(errorId, pack.fieldId),
							    divLogId    = s1.STRINGS.format(logId, pack.fieldId),
							    divError    = s1.DOM.o(divErrorId),
							    divLog      = s1.DOM.o(divLogId),
                                tempWrapper = null,
							    _logArea    = s1.DOM.o(this.logArea);
                        
                            for (var rule in pack.rules)
                            {
                                tempWrapper = s1.DOM.o(pack.rules[rule].wrapper);
                                if (tempWrapper)
                                {
                                    tempWrapper.style.display = "none";
                                }
                            }
							
							if (divError)
							{
								divError.parentNode.removeChild(divError);
							}
							
							if (divLog)
							{
								divLog.parentNode.removeChild(divLog);
								
								_logArea.style.display = (_logArea.innerHTML.indexOf("<") >= 0 ? "block" : "none" );
							}
						};
						
	this.scan = function()
				{
					var _isValid  = true;
					var _log      = new Array();
					var _hasLogs  = false;
					var tempRule  = null;
					var tempCheck = null;
					
					for (var aPackName in this.validatePack)
					{
						tempCheck = this.isFieldValid(aPackName);
						
						if (!tempCheck.isValid)
						{
							_isValid        = false;
							_log.push(tempCheck.log);
						}
					}
					
					this.onScanComplete(_log);
					
					return {isValid: _isValid, log: _log};
				};
				
	this.clear = function()
				{
					for (var aPackName in this.validatePack)
					{
						this.clearField(aPackName);
					}
				};
						
	function isRuleValid(objPack, objRule)
	{
		var _isValid  = false;
		var _objField = s1.DOM.o(objPack.fieldId);
		
		switch (objRule.mode)
		{
			case "required":
				_isValid = validatorStatic.matchPattern(_objField.value, validatorStatic.modes.required.pattern);
				break;
			case "email":
				_isValid = ((_objField.value.length == 0) || validatorStatic.matchPattern(_objField.value, validatorStatic.modes.email.pattern));
				break;
			case "integer":
				_isValid = ((_objField.value.length == 0) || validatorStatic.matchPattern(_objField.value, validatorStatic.modes.integer.pattern));
				break;
			case "unsignedInteger":
				_isValid = ((_objField.value.length == 0) || validatorStatic.matchPattern(_objField.value, validatorStatic.modes.unsignedInteger.pattern));
				break;
			case "custom":
				_isValid = objRule.func(_objField);
				break;
		};
		
		return _isValid;
	}
	
	this.init()
};
		

/***************** STRINGS *****************/

function STRINGS_map(arrMappings)
{
	var regEx  = null;
	var result = this;

	if (arrMappings)
	{
		for (var i = 0, j = arrMappings.length; i < j; i++)
		{
			tempMapping = arrMappings[i];
			regEx       = new RegExp(tempMapping.charAt(0),"g");

			result      = result.replace(regEx, tempMapping.charAt(1));
		}
	}

    return result;
};

function STRINGS_isInteger()
{
    return (this.search(/^[0-9]+$/) == 0);
};

function STRINGS_format(strIn)
{
	var result = strIn;
	var args   = arguments;

	if (args.length > 1)
	{
		for (var i=1, j=args.length; i<j; i++)
		{
			result = result.replace(new RegExp("\\{" + (i-1) + "\\}","gi"), args[i]);
		}
	}
	
	return result;
};

function STRINGS_isUnsignedInteger()
{
    return (this.search(/^-?[0-9]+$/) == 0);
};

function STRINGS_replaceAll(strInput, arrToReplace, strReplacement, strReplaceArgs)
{
	var regEx         = null;
	strReplaceArgs    = strReplaceArgs || "gi";
	
	for (var i=0, j = arrToReplace.length; i<j; i++)
	{
		regEx    = new RegExp(arrToReplace[i],strReplaceArgs);
		strInput = strInput.replace(regEx, strReplacement);
	}
	
	return strInput;
};

function STRINGS_getMatchIndices(strInput, regExPattern)
{
	var arrIndices  = new Array(),
		tempIndex   = strInput.search(regExPattern),
		len         = 0,
		indexHolder = 0;

	while (tempIndex > -1)
	{
		len = strInput.match(regExPattern)[0].length;

		arrIndices.push(indexHolder + tempIndex);
		strInput    = strInput.substring(tempIndex + len);
		indexHolder = indexHolder + tempIndex + len;
		tempIndex   = strInput.search(regExPattern);
	}

	return arrIndices;
};

function STRINGS_inject(strInput, arrIndices, strPrefix, strSuffix, intLength)
{
	var arrTemp = new Array();
	
	for (var i = 0, j = arrIndices.length; i < j; i++)
	{
		arrTemp.push(strInput.substring((i == 0 ? 0 : arrIndices[i - 1] + intLength), arrIndices[i]));
		arrTemp.push(strPrefix);
		arrTemp.push(strInput.substr(arrIndices[i], intLength));
		arrTemp.push(strSuffix);
		arrTemp.push((i == j-1) ? strInput.substring(arrIndices[i] + intLength) : "");
	}
	
	return arrTemp.join("");
}

function STRINGS_asciiEncode(strInput)
{
	var arrCodes    = new Array();

    for (var i=0,j=strInput.length; i<j; i++)
    {
		arrCodes.push(strInput.charCodeAt(i));
    }
    
    return arrCodes.join(","); 
};

function STRINGS_asciiDecode(strInput, separator)
{
    var chars         = strInput.split(separator);
    var decodedString = "";     

    for (var i=0,j=chars.length; i<j; i++)
    {
        decodedString += String.fromCharCode(chars[i]);
    }
    return decodedString; 
};

function STRINGS_trim()
{
	return this.replace(/^\s+|\s+$/g, '');
};

function STRINGS_sameText()
{
	var isSame    = true;
	var strHolder = null;
	
	for (var i=0, j=arguments.length; i<j; i++)
	{
		if (this.toUpperCase() != arguments[i].toUpperCase())
		{
			isSame = false;
			break;
		}
	}
	
	return isSame;
};

function STRINGS_isIn()
{
	for (var i=0, j=arguments.length; i<j; i++)
	{
		if (this.sameText(arguments[i]))
		{
			return true;
		}
	}
	return false;
};

function STRINGS_truncate(intLength)
{
    return (this.length > intLength ? this.substr(0,intLength) + "..." : this);
};

/***************** NUMBERS *****************/

function NUMBERS_isInteger()
{
    return parseInt(this,10)===this;
};

/***************** DATES *****************/

function DATES_getDiff(date1,date2)
{
	try
	{
		var diff = date1.getTime() - date2.getTime();
		var sec  = 1000;
		var min  = 1000*60;
		var hour = 1000*60*60;
		var day  = 1000*60*60*24;
		
		return {ms: diff, secs:diff/sec, mins:diff/min, hours:diff/hour, days:diff/day};
	}
	catch(e)
	{
		alert("Error\n" + e.description);
		return false;
	}
};

/***************** ARRAYS *****************/

function ARRAYS_removeDuplicate(arrIn)
{
    var holdObj   = new Object();
    var fineArray = new Array();

    for (var j=arrIn.length-1; j>=0; j--)
    {
        if (holdObj[arrIn[j].toUpperCase()]!=1)
        {
            holdObj[arrIn[j].toUpperCase()]=1;
            fineArray.push(arrIn[j]);
        }
    }
	
	return fineArray;
};

/***************** LOCALE *****************/

function LOCALE_loadLabels(strPathToXml)
{
	var xmlDoc = s1prototype.XML.s1LoadXml(strPathToXml);
	var labels = new Object();
	
	if (xmlDoc)
	{
		var items = xmlDoc.getElementsByTagName("item");
		
		for (var i=0, j=items.length; i<j; i++)
		{
			labels[items[i].getAttribute("key")] = s1prototype.XML.nodeValue(items[i]);
		}
	}
	
	return labels;
};

function LOCALE_localize(strInput, objLabels)
{
	var matches = strInput.match(/@s1lb:[^@]*@/gi);
	var labels  = objLabels;
	
	if (matches)
	{
		var matchHolder    = new Object();
		var myRegExp       = null;
		var key            = "";
		var tempMatch      = "";
		var tempMatchUpper = "";
		var val            = "";
		
		for (var i=0, j=matches.length; i<j; i++)
		{
			tempMatch      = matches[i];
			tempMatchUpper = tempMatch.toUpperCase();
			
			if (!matchHolder[tempMatchUpper])
			{
				myRegExp                    = new RegExp(tempMatch,"gi");
				key                         = s1prototype.STRINGS.replaceAll(tempMatch, ["@s1lb:","@"], "", "gi");
				val                         = labels[key];
				if (val)
				{
					strInput = strInput.replace(myRegExp, val);
				}
				matchHolder[tempMatchUpper] = 1;
			}
		}
	}
	return strInput;
};

/***************** AJAX *****************/

function AJAX_ajaxCaller(strRequestUrl)
{
	var self             = this;

	this.errors          =  {
								general           : "An error has occurred",
								requestImpossible : "Your browser does not support AJAX calls",
								badReply          : "There was no successful reply"
							};

	this.requestUrl      = strRequestUrl;
	this.requestMethod   = "POST";
	this.requestVars     = null;
	this.requestAsync    = true;
	this.onProcess       = function(){};
	this.onSuccess       = function(){};
	this.onFailure       = function(){};
	
	this.settings        = 	{
								requestContentType : "application/x-www-form-urlencoded"
							};
						

	this.request         = (function()
							{
								var httpRequest = null;
								
								try
								{
									httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
								}
								catch (e)
								{
									try
									{
										httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
									}
									catch (oc)
									{
										httpRequest = null;
									}
								}
								if(!httpRequest && typeof XMLHttpRequest != "undefined")
								{
									httpRequest = new XMLHttpRequest();
								}
								
								if (!httpRequest) this.onFailure(this.errors.requestImpossible);
								
								return httpRequest;
							}
						)();
					
		this.invoke      =  function()
							{
								if (this.request)
								{
									this.requestUrl = this.requestUrl + (this.requestUrl.indexOf('?') >= 0 ? "&" : "?" ) + "s1tmstmp=" + Date.parse(new Date());
									this.onProcess();
									
									if (this.requestAsync)
									{
										this.request.onreadystatechange = this.responseHandler;
									}
									
									try
									{
										this.request.open(this.requestMethod, this.requestUrl, this.requestAsync);
										
										if (this.requestMethod == "POST")
										{
											this.request.setRequestHeader("Content-type", this.settings.requestContentType);
											this.request.setRequestHeader("Content-length", this.requestVars.length);
											this.request.setRequestHeader("Connection", "close");
										}
										
										this.request.send(this.requestVars);
										
										if (!this.requestAsync)
										{
											this.responseHandler();
										}
									}
									catch (e)
									{
										this.onFailure(this.errors.general + ' - ' + e.description);
									}
								}
							};
						
	this.responseHandler = function()
							{
								var waitReadyState = (self.requestAsync);
								
								if ((self.request.readyState == 4) || (!waitReadyState))
								{
									if (self.request.status == 200)
									{
										self.onSuccess(self.request);
									}
									else
									{
										self.onFailure(self.errors.badReply + ' - ' + self.request.status);
									}
								}
							};
};

/***************** DOM *****************/

function DOM_o(strElement)
{
	return document.getElementById(strElement);
};

function DOM_nextElement(obj) 
{
    do obj = obj.nextSibling;
    while (obj && obj.nodeType != 1);
    return obj;
};

function DOM_previousElement(obj) 
{
    do obj = obj.previousSibling;
    while (obj && obj.nodeType != 1);
    return obj;
};

function DOM_switchDisplay(objElement, bool)
{
	objElement.style.display = (bool ? "block" : "none");
};

function DOM_switchVisibility(objElement, bool)
{
	objElement.style.visibility = (bool ? "visible" : "hidden");
};

function DOM_appendStylesheet(strStyles, strId)
{
	//should be called ONLY after DOM has been completely formed - on onload event or later 

	var css  = document.createElement('style');
	css.id   = strId || "s1_appendedStyleSheet";
	css.type = 'text/css';

	if (!document.getElementById(strId))
	{
		if (css.styleSheet) //IE
		{
			css.styleSheet.cssText = strStyles;
		}
		else 
		{
			css.appendChild(document.createTextNode(strStyles));
		}

		document.getElementsByTagName("head")[0].appendChild(css);
	}
}

function DOM_toggleDisplay(objElement)
{
    objElement.style.display = (objElement.style.display == "none" ? "block" : "none");
};

function DOM_appendClass(objElement, strClass)
{
	objElement.className = strClass + " " + objElement.className;
};

function DOM_removeClass(objElement, strClass)
{
	objElement.className = objElement.className.replace(new RegExp(strClass, "gi"), "")
};

function DOM_getMousePosition(e)
{
	var cursor = new Object();
    var e      = e || event;

    if (e.pageX == null)
    {
       var d = ((document.documentElement && document.documentElement.scrollLeft != null) ? document.documentElement : document.body);
       cursor.x  = e.clientX + d.scrollLeft;
       cursor.y  = e.clientY + d.scrollTop;
    }
    else
    {
       cursor.x = e.pageX;
       cursor.y = e.pageY;
    }

    return cursor;
};

function DOM_getMouseButton(e)
{
    var button = "";
    var e      = e || event;
	
    if (e.which == null)
	{
       button= (e.button < 2) ? "LEFT" : ((e.button == 4) ? "MIDDLE" : "RIGHT");
	}
    else
	{
       button= (e.which < 2) ? "LEFT" : ((e.which == 2) ? "MIDDLE" : "RIGHT");
	}
    
	return button;
};

function DOM_getDocHeight() 
{
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
};

function DOM_getPosition(objElement)
{
    var result    = new Object();

    result.x      = 0;
    result.y      = 0;
    result.width  = 0;
    result.height = 0;
	
    if (objElement.offsetParent) 
	{
        result.x   = objElement.offsetLeft;
        result.y   = objElement.offsetTop;
        var parent = objElement.offsetParent;
		
        while (parent) 
		{
            result.x += parent.offsetLeft;
            result.y += parent.offsetTop;
			
            var parentTagName = parent.tagName.toLowerCase();
			
            if (parentTagName != "table" &&
                parentTagName != "body"  && 
                parentTagName != "html"  && 
                parentTagName != "div"   && 
                parent.clientTop         && 
                parent.clientLeft) 
			{
                result.x += parent.clientLeft;
                result.y += parent.clientTop;
            }
            parent = parent.offsetParent;
        }
    }
    else if (objElement.left && objElement.top) 
	{
        result.x = objElement.left;
        result.y = objElement.top;
    }
    else 
	{
        if (objElement.x) result.x = objElement.x;
        if (objElement.y) result.y = objElement.y;
    }
    if (objElement.offsetWidth && objElement.offsetHeight) 
	{
        result.width  = objElement.offsetWidth;
        result.height = objElement.offsetHeight;
    }
    else if (objElement.style && objElement.style.pixelWidth && objElement.style.pixelHeight) 
	{
        result.width  = objElement.style.pixelWidth;
        result.height = objElement.style.pixelHeight;
    }
    return result;
};

function DOM_bubbleToTag(objBase,strTargetTag)
{
    var target   = objBase;
    strTargetTag = strTargetTag.toUpperCase(); 
    
    while ((target) && (target.tagName.toUpperCase() != strTargetTag))
    {
        target = target.parentNode;
    }
    
    return target;
};

function DOM_getInputsByType(nodeBase,strType)
{
    var result    = new Array();
    var inputs    = nodeBase.getElementsByTagName("input");
    var tempInput = null;

    for (var i=0, j=inputs.length; i<j; i++)
    {
        tempInput = inputs[i];
        try
        {
            if (tempInput.type.toUpperCase() == strType.toUpperCase())
            {
                result.push(tempInput);
            }
        }
        catch (e)
        {

        }        
    }

    return result;
};

function DOM_getElements(nodeBase, arrResult)
{
    var arrResult = (arrResult || new Array());
	var children  = nodeBase.childNodes;
    var tempInput = null;

    for (var i=0, j = children.length; i<j; i++)
    {
        tempInput = children[i];
		
		if (tempInput.nodeType == 1)
		{
			arrResult.push(tempInput);
			
			if (tempInput.childNodes.length > 0)
			{
				tempInput = s1.DOM.getElements(tempInput, arrResult);
			}
		}		
    }

    return arrResult;
}

function DOM_getElementsByClass(nodeBase, strClass)
{
    var arrElements = s1.DOM.getElements(nodeBase);
	var arrResult   = new Array();
    var tempInput   = null;

    for (var i=0, j = arrElements.length; i<j; i++)
    {
        tempInput = arrElements[i];
		
		if (tempInput.className.toUpperCase().indexOf(strClass.toUpperCase()) > -1)
		{
			arrResult.push(tempInput);
		}		
    }

    return arrResult;
}

function DOM_getChildrenByTag(objParent,strTag)
{
    var result    = new Array();
    var children  = objParent.childNodes;
    var tempChild = null;

    for (var i=0, j=children.length; i<j; i++)
    {
        tempChild = children[i];
        try
        {
            if (tempChild.tagName.toUpperCase() == strTag.toUpperCase())
            {
                result.push(tempChild);
            }
        }
        catch (e)
        {

        }        
    }

    return result;
};

function DOM_getSelectedOption(objSelect)
{
    var result = {value : null, text : null};
    var opt    = null;

    try
    {
        if (objSelect)
        {
            opt          = objSelect.options[objSelect.selectedIndex];
            result.text  = opt.text;
            result.value = opt.value;
        }
    }
    catch (e)
    {

    }

    return result;
};

function DOM_removeSelections(objSelect)
{
    for (var i=0, j=objSelect.options.length; i<j; i++)
	{
		options[i].selected = false;
	}
};

function DOM_getOptionIndexByText(objSelect,strText,intDefaultIndex)
{
	var optionIndex = intDefaultIndex || 0;
	
	for (var i=0, j=objSelect.options.length; i<j; i++)
	{
		if (objSelect.options[i].text.sameText(strText))
		{
			optionIndex = i;
			break;
		}
	}
	
	return optionIndex;
};

function DOM_getOptionIndexByValue(objSelect,strValue,intDefaultIndex)
{
	var optionIndex = intDefaultIndex || 0;
	
	for (var i=0, j=objSelect.options.length; i<j; i++)
	{
		if (objSelect.options[i].value.sameText(strValue))
		{
			optionIndex = i;
			break;
		}
	}
	
	return optionIndex;
};

function DOM_centerOnScreen(obj)
{
	var viewport   = s1prototype.WINDOW.getViewport();
	var scroll     = s1prototype.WINDOW.getScroll();
	var inWidth    = parseInt(viewport.width, 10);
	var inHeight   = parseInt(viewport.height, 10);
	var objWidth   = parseInt(obj.offsetWidth, 10);
	var objHeight  = parseInt(obj.offsetHeight, 10);
	
	obj.style.left = (parseInt(scroll.left, 10) + ((inWidth/2) - (objWidth/2))) + "px";
	obj.style.top  = (parseInt(scroll.top, 10) + ((inHeight/2) - (objHeight/2))) + "px";
};

function DOM_centerOnArea(objArea, obj)
{
    var objAreaPos = s1.DOM.getPosition(objArea);
	var objPos     = s1.DOM.getPosition(obj);
	
	obj.style.left = (parseInt(objAreaPos.x, 10) + (parseInt((objAreaPos.width/2), 10) - parseInt((objPos.width/2), 10))) + "px";
	obj.style.top  = (parseInt(objAreaPos.y, 10) + parseInt((objAreaPos.height/2), 10) - parseInt((objPos.height/2), 10)) + "px";
};

function DOM_modalize(boolDim, strColor, intOpacity)
{
	var curtain   = s1.DOM.o("templateModalCurtain");
	var docHeight = parseInt(s1.DOM.getDocHeight(),10);
	strColor      = (strColor || "#000000");
	intOpacity    = parseInt((intOpacity != null ? intOpacity : 20), 10); 
	
	if (!curtain)
	{
		curtain                = document.createElement("div");
		curtain.id             = "templateModalCurtain";
		curtain.style.display  = "none";
		curtain.style.cssText  = s1.STRINGS.format("filter:alpha(opacity={0}); opacity:{1}; ", intOpacity, (intOpacity/100));
		curtain.style.cssText += "left:0px; top:0px; width:100%; height:0px; position:absolute; z-index:1000; ";
		curtain.innerHTML      = "&nbsp;";
		
		document.body.appendChild(curtain);
	}
	
	if (boolDim)
	{
		curtain.style.backgroundColor = strColor;
		curtain.style.height          = docHeight + "px";
		s1.DOM.switchDisplay(curtain,true);
	}
	else
	{
		curtain.style.height = "0px";
		s1.DOM.switchDisplay(curtain,false);
	}
};

function DOM_modalizeArea(obj, boolDim, strColor, intOpacity)
{
    var curtainId = "s1_" + (obj.id || "") + "_" + "modalCurtain";
	strColor      = (strColor || "#000000");
	intOpacity    = parseInt((intOpacity != null ? intOpacity : 20), 10); 
	var curtain   = s1.DOM.o(curtainId);
    var objPos    = s1.DOM.getPosition(obj);
	
	if (!curtain)
	{
		curtain                = document.createElement("div");
		curtain.id             = curtainId;
		curtain.style.display  = "none";
		curtain.style.cssText  = s1.STRINGS.format("filter:alpha(opacity={0}); opacity:{1}; ", intOpacity, (intOpacity/100));
		curtain.style.cssText += "left:0px; top:0px; width:100%; height:0px; position:absolute; z-index:1000; ";
		curtain.innerHTML      = "&nbsp;";
		
		document.body.appendChild(curtain);
	}
	
	if (boolDim)
	{
        curtain.style.left            = parseInt(objPos.x,10) + "px";
        curtain.style.top             = parseInt(objPos.y,10) + "px";
		curtain.style.width           = parseInt(objPos.width,10) + "px";
        curtain.style.height          = parseInt(objPos.height,10) + "px";
		curtain.style.backgroundColor = strColor;

		s1.DOM.switchDisplay(curtain,true);
	}
	else
	{
		curtain.style.height = "0px";
		s1.DOM.switchDisplay(curtain,false);
	}
};

/***************** XML *****************/

function XML_loadXml(strPath)
{
	var request = null;
	
	if (window.XMLHttpRequest)
	{
		request = new XMLHttpRequest();
	}
	else
	{
		request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	request.open("GET", strPath, false);
	request.send("");
	
	return request.responseXML;
};

function XML_loadFromString(strInput)
{
	var xmlDoc = null;
	
	try
	{
		xmlDoc       = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async = false;
		xmlDoc.loadXML(strInput);
	}
	catch (e)
	{
		try
		{
			var parser = new DOMParser();
			xmlDoc     = parser.parseFromString(strInput,"text/xml");
		}
		catch (e)
		{
			
		}
	}
	return xmlDoc;
};

function XML_s1LoadXml(strPath)
{
	var xmlDoc = null;

	try
	{
		xmlDoc       = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async = false;
		xmlDoc.load(strPath);
	}
	catch (e)
	{
	
	}
	
	return xmlDoc;
};

function XML_nodeValue(node)
{
	return (node.childNodes[0] ? node.childNodes[0].nodeValue : "");
};

/***************** EFFECTS *****************/

function EFFECTS_fader(objElement, objSettings, objEvents)
{
		var objElement  = objElement;
		var objSettings = objSettings || new Object();
		var objEvents   = objEvents   || new Object();

		var settings =  { 
						ignorestate : objSettings.ignorestate  || false,
						isFaded     : objSettings.isFaded      || false,
						minOpc      : objSettings.minOpc       || 0,
						maxOpc      : objSettings.maxOpc       || 1,
						interval    : objSettings.interval     || 30,
						step        : objSettings.step         || 0.1
					};
					
		var events  = 	{
						onBegin     : objEvents.onBegin    || function(){},
						onComplete  : objEvents.onComplete || function(){}
					};

		fadeOut = function()
					{
						_fader_init();
					
						clearInterval(objElement.fader_trace);

						if (_fader_nextStep(true, objElement).proceed)
						{
							objElement.fader_isFaded = true;
							_fader_makeStep(true, objElement);
							objElement.style.display = "block";
							objElement.fader_trace   = setInterval(function(){_fader_makeStep(true, objElement)}, objElement.fader_interval);
						}
						else
						{
							_fader_finalize(objElement, true);
						}
					};
					
		fadeIn = function()
					{
						_fader_init();
					
						clearInterval(objElement.fader_trace);
						
						if (_fader_nextStep(false, objElement).proceed)
						{
							objElement.fader_isFaded = false;
							_fader_makeStep(false, objElement);
							objElement.style.display = "block";
							objElement.fader_trace   = setInterval(function(){_fader_makeStep(false, objElement)}, objElement.fader_interval);
						}
						else
						{
							_fader_finalize(objElement, false);
						}
					};
					
		invoke = function(boolFade)
					{
						_fader_init();
						
						clearInterval(objElement.fader_trace);

						if (_fader_nextStep(boolFade, objElement).proceed)
						{
							objElement.fader_isFaded = boolFade;
							_fader_makeStep(boolFade, objElement);
							objElement.style.display = "block";
							objElement.fader_trace   = setInterval(function(){_fader_makeStep(boolFade, objElement)}, objElement.fader_interval);
						}
						else
						{
							_fader_finalize(objElement, boolFade);
						}
					};
					
		toggle = function()
		{
			_fader_init();
			invoke(!objElement.fader_isFaded);
		};
		
		_getCurrentValues = function(objElement)
		{
			var currOpacity = this._fader_getOpac(objElement);
			var newOpacity  = 1;
			var isFaded     = false;
			
			if (objElement.style.display == 'none')
			{
				isFaded    = true;
				newOpacity = 0;
			}
			else
			{
				var fOld = parseFloat(currOpacity);
				
				if (currOpacity === -1)
				{
					isFaded    = false; 
					newOpacity = 1;
				}
				else if (fOld <= parseFloat(objElement.fader_minOpc))
				{
					isFaded    = true; 
					newOpacity = currOpacity;
				}
				else if (fOld >= parseFloat(objElement.fader_maxOpc))
				{
					isFaded    = false; 
					newOpacity = currOpacity;
				}
				else
				{
					isFaded    = objElement.fader_isFaded; 
					newOpacity = currOpacity;
				}
			}

			return {isFaded: isFaded, currOpacity: currOpacity, newOpacity: newOpacity};
		};
		
		_fader_init   = function()
					{
						objElement.fader_ignorestate = settings.ignorestate;     
						objElement.fader_minOpc      = settings.minOpc;
						objElement.fader_maxOpc      = settings.maxOpc;
						objElement.fader_interval    = settings.interval;
						objElement.fader_step        = settings.step;
						objElement.fader_onBegin     = events.onBegin;
						objElement.fader_onComplete  = events.onComplete;
						
						var startValues = _getCurrentValues(objElement);
						
						objElement.fader_onBegin();
						
						objElement.fader_isFaded = startValues.isFaded;
					};
		
		_fader_getOpac = 	function(objElement)
					{
						var opac = -1;
						var val  = s1.VALID.validatorStatic;
						try
						{
							if (objElement.style.opacity != undefined)          {opac = objElement.style.opacity;}
							else if (objElement.style.MozOpacity != undefined)  {opac = objElement.style.MozOpacity;}
							else if (objElement.style.filter != undefined)      {opac = parseInt(objElement.style.filter.replace(/[^0-9]/g,""), 10) / 100;}
						}
						catch(e) {}

						return (val.matchPattern(opac, val.modes.floating.pattern) || (val.matchPattern(opac, val.modes.integer.pattern)) ? opac : -1);
					};

		_fader_setOpac = function (objElement, opac) {
					    if (objElement.style.opacity != undefined) { objElement.style.opacity = opac; }
					    else if (objElement.style.MozOpacity != undefined) { objElement.style.MozOpacity = opac; }
					    else if (objElement.style.filter != undefined) {
					        objElement.style.filter = s1prototype.STRINGS.format("alpha(opacity={0})", Math.round(opac * 100));
					    }
					};
					
		_fader_nextStep = function (boolFade, objElement) 
					{
						var currValues  = _getCurrentValues(objElement);
						var currOpacity = currValues.newOpacity;
						
					    var nextOpacity = (boolFade ? (+currOpacity - +objElement.fader_step) : (+currOpacity + +objElement.fader_step));
					    var proceed     = (boolFade ? nextOpacity >= objElement.fader_minOpc : nextOpacity <= objElement.fader_maxOpc);

					    return { proceed: proceed, currOpacity: currOpacity, nextOpacity: nextOpacity }
					};
		
		_fader_makeStep = function(boolFade, objElement)
		{		
			var nextStep    = _fader_nextStep(boolFade, objElement);
			//window.status = +(window.status.isInteger() ? window.status : 0) + 1
			if (nextStep.proceed)
			{
				_fader_setOpac(objElement, nextStep.nextOpacity);
			}
			else
			{
				_fader_finalize(objElement, boolFade);
			}
		};
		
		_fader_finalize = function(objElement, boolFade)
		{
				clearInterval(objElement.fader_trace);
				_fader_setOpac(objElement, boolFade ? objElement.fader_minOpc : objElement.fader_maxOpc);
				
				//defeat IE distortion bug
				if ((!boolFade) && (objElement.fader_maxOpc >= 1) && (objElement.style.filter != undefined))
				{
					objElement.style.removeAttribute("filter");
				}
				//**********************************************
				if ((boolFade) && (objElement.fader_minOpc == 0))
				{
					objElement.style.display = "none";
					_fader_setOpac(objElement,1);
					
					if (objElement.style.filter)
						objElement.style.removeAttribute("filter");
				}

				objElement.fader_onComplete(boolFade);
		};
	
	return {invoke : invoke, fadeOut: fadeOut, fadeIn: fadeIn, toggle : toggle};
};

function EFFECTS_slider(objElement, objSettings, objEvents)
{
		var objElement  = objElement;
		var objSettings = objSettings || new Object();
		var objEvents   = objEvents || new Object();
		
		var settings =  { 
						isExpanded  : objSettings.isExpanded || false,
						maxHeight   : objSettings.maxHeight,
						interval    : objSettings.interval || 10,
						step        : objSettings.step || 10
					};
					
		var events  = 	{
						onBegin    : objEvents.onBegin || function(){},
						onComplete : objEvents.onComplete || function(){}
					};
					
		invoke = function(boolExpand)
					{
						var nextStep  = _slider_nextStep(boolExpand, objElement);
						clearInterval(objElement.slider_trace);
						
						objElement.slider_isExpanded  = boolExpand;

						if (nextStep.proceed)
						{
							objElement.slider_onBegin(boolExpand);
							
							objElement.style.display     = 'block';
							objElement.slider_trace      = setInterval(function(){_slider_makeStep(boolExpand, objElement)}, settings.interval);
						}
					};
					
		toggle = function()
		{
			invoke(!objElement.slider_isExpanded);
		};
		
		_slider_init   = function()
					{
						objElement.slider_step        = settings.step;
						objElement.slider_onBegin     = events.onBegin;
						objElement.slider_onComplete  = events.onComplete;
						objElement.style.overflow     = 'hidden';
						
						if (!objElement.slider_maxHeight)
						{
							objElement.slider_isExpanded  = settings.isExpanded;
							objElement.slider_maxHeight   = settings.maxHeight || (objElement.style.height ? parseInt(objElement.style.height, 10) : null ) || _slider_evalHeight(objElement);
						}
						if ((!objElement.slider_isExpanded) && (objElement.style.display == 'none'))
						{
							objElement.style.height = '1px';
						}
					};
		
		_slider_nextStep = function(boolExpand, objElement)
		{
			var currHeight  = parseInt(objElement.offsetHeight, 10);
			var nextHeight  = (boolExpand ? currHeight + objElement.slider_step : currHeight - objElement.slider_step);
			var finalHeight = (boolExpand ? objElement.slider_maxHeight : 1);
			var proceed     = (boolExpand ? nextHeight < objElement.slider_maxHeight : nextHeight > 1);
			
			return {proceed:proceed, nextHeight:nextHeight, finalHeight:finalHeight}
		};
	
		_slider_makeStep = function(boolExpand, objElement)
		{
			var nextStep  = _slider_nextStep(boolExpand, objElement);
			//if (window.status.length >= 10){window.status = ""} else {window.status += "s"}
			if (nextStep.proceed)
			{
				objElement.style.height = nextStep.nextHeight + "px";
			}
			else
			{
				clearInterval(objElement.slider_trace);
				
				objElement.style.height  = nextStep.finalHeight + "px";
				objElement.style.display = (boolExpand ? 'block' : 'none');
				
				objElement.slider_onComplete(boolExpand);
			}
		};
		
		_slider_evalHeight = function(objElement)
		{
			var maxHeight               = 0;			
			objElement.style.visibility = "hidden";
			objElement.style.display    = "block";
			maxHeight                   = objElement.offsetHeight;
			objElement.style.display    = "none";
			objElement.style.visibility = "visible";
			
			return parseInt(maxHeight, 10);
		};
		
		_slider_init();
	
	return {invoke : invoke, toggle : toggle};
}

function EFFECTS_hslider(objElement, objSettings, objEvents)
{
		var objSettings = objSettings || new Object();
		var objEvents   = objEvents   || new Object();
		
		var settings =  { 
						isExpanded  : objSettings.isExpanded || false,
						maxWidth    : objSettings.maxWidth,
						minWidth    : objSettings.minWidth,
						interval    : objSettings.interval || 10,
						step        : objSettings.step || 10
					};
					
		var events  = 	{
						onBegin    : objEvents.onBegin || function(){},
						onComplete : objEvents.onComplete || function(){}
					};
					
		invoke = function(boolExpand)
					{
						clearInterval(objElement.hslider_trace);
						
						var nextStep  = _hslider_nextStep(boolExpand, objElement);
						
						objElement.hslider_isExpanded  = boolExpand;

						if (nextStep.proceed)
						{
							objElement.hslider_onBegin(boolExpand);
							
							objElement.style.display     = 'block';
							objElement.hslider_trace      = setInterval(function(){_hslider_makeStep(boolExpand, objElement)}, settings.interval);
						}
					};
					
		toggle = function()
		{
			invoke(!objElement.hslider_isExpanded);
		};
		
		_hslider_init   = function()
					{
						objElement.hslider_step        = settings.step;
						objElement.hslider_onBegin     = events.onBegin;
						objElement.hslider_onComplete  = events.onComplete;
						objElement.style.overflow      = 'hidden';
						
						if (!objElement.hslider_maxWidth)
						{
							objElement.hslider_isExpanded  = settings.isExpanded;
						}
						
						objElement.hslider_maxWidth    = settings.maxWidth || (objElement.style.width ? parseInt(objElement.style.width, 10) : null ) || _hslider_evalWidth(objElement);
						objElement.hslider_minWidth    = settings.minWidth;
					};
		
		_hslider_nextStep = function(boolExpand, objElement)
		{
			var currWidth  = parseInt(objElement.offsetWidth, 10);
			var nextWidth  = (boolExpand ? currWidth + objElement.hslider_step : currWidth - objElement.hslider_step);
			var finalWidth = (boolExpand ? objElement.hslider_maxWidth : objElement.hslider_minWidth);
			var proceed    = (boolExpand ? nextWidth < objElement.hslider_maxWidth : nextWidth > objElement.hslider_minWidth);

			return {proceed:proceed, nextWidth:nextWidth, finalWidth:finalWidth}
		};
	
		_hslider_makeStep = function(boolExpand, objElement)
		{
			var nextStep  = _hslider_nextStep(boolExpand, objElement);
			//if (window.status.length >= 10){window.status = ""} else {window.status += "h"}
			if (nextStep.proceed)
			{
				objElement.style.width = nextStep.nextWidth + "px";
			}
			else
			{
				clearInterval(objElement.hslider_trace);
				
				objElement.style.width  = nextStep.finalWidth + "px";
				
				objElement.hslider_onComplete(boolExpand);
			}
		};
		
		_hslider_evalWidth = function(objElement)
		{
			var baseClone  = objElement.cloneNode(true);
			var baseParent = objElement.offsetParent || document.body;
			var maxWidth  = 0;
			
			baseClone.style.visibility = 'hidden';
			baseClone.style.position   = 'absolute';
			baseClone.style.zIndex     = '2';
			baseClone.style.left       = '0px';
			baseClone.style.top        = '0px';
			baseClone.style.display    = 'block';
			
			baseParent.appendChild(baseClone);
			
			maxWidth = baseClone.offsetWidth;
			
			baseClone.parentNode.removeChild(baseClone);

			return parseInt(maxWidth, 10);
		};
		
		_hslider_init();
	
	return {invoke : invoke, toggle : toggle};
};

function EFFECTS_dragHandler()
{
	var obj =
	{
		attach : function(oElem, handlers)
					{
						if (!s1window.EFFECTS)      s1window.EFFECTS      = new Object();
						if (!s1window.EFFECTS.drag) s1window.EFFECTS.drag = new Object();
						oElem.style.left  = oElem.style.left || "0px";
						oElem.style.top   = oElem.style.top || "0px";
						handlers          = handlers || [oElem];
						for (var i=0, j=handlers.length; i<j; i++)
						{
							handlers[i].onmousedown = function(){obj._dragBegin(arguments[0],oElem)};
						}

						oElem._drag         = obj._drag;
						oElem._dragEnd      = obj._dragEnd;

                        document.body.onmousemove = function(){if (s1window.EFFECTS.drag.current)s1window.EFFECTS.drag.current._drag(arguments[0])};
                        document.body.onmouseup   = function(){if (s1window.EFFECTS.drag.current)s1window.EFFECTS.drag.current._dragEnd(arguments[0])};

						oElem.onDragBegin   = function(){};
						oElem.onDrag        = function(){};
						oElem.onDragEnd     = function(){};
						
						return oElem;
					},
					
		_dragBegin : function (e,oElem)
					{
						s1window.EFFECTS.drag.current = oElem;

						if (isNaN(parseInt(oElem.style.left))) { oElem.style.left = '0px'; }
						if (isNaN(parseInt(oElem.style.top))) { oElem.style.top = '0px'; }
				 
						var x = parseInt(oElem.style.left);
						var y = parseInt(oElem.style.top);
				 
						e = e ? e : window.event;
						oElem.drag_mouseX = e.clientX;
						oElem.drag_mouseY = e.clientY;
				 
						oElem.onDragBegin(oElem, x, y);
				 
						return false;
					},
		
		_drag : function(e) 
					{
						e = e ? e : window.event;
						var objElement = this;
						//if (window.status.length >= 10){window.status = ""} else {window.status += "d"}
						var x = parseInt(objElement.style.left, 10);
						var y = parseInt(objElement.style.top, 10);
				 
						objElement.style.left = x + (e.clientX - objElement.drag_mouseX) + 'px';
						objElement.style.top  = y + (e.clientY - objElement.drag_mouseY) + 'px';
				 
						objElement.drag_mouseX = e.clientX;
						objElement.drag_mouseY = e.clientY;
				 
						objElement.onDrag(objElement, x, y);
				 
						return false;

					},
		
		_dragEnd : function(e) 
					{
						var oElem = this;
						s1window.EFFECTS.drag.current = null;
						
						var x = parseInt(oElem.style.left);
						var y = parseInt(oElem.style.top);
				 
						oElem.onDragEnd(oElem, x, y);
					}
	};
	
	return obj;
};

/***************** BROWSER *****************/

function BROWSER_setCookie(strCookieName,strCookieValue,intExpireDays)
{
    var expDate = new Date();
    
    expDate.setDate(intExpireDays);
    document.cookie = strCookieName + "=" + escape(strCookieValue) + (intExpireDays ? ";expires=" + expDate.toUTCString() : "" );
};

function BROWSER_getCookie(strCookieName,strDefaultValue)
{
    var res            = "";
    var tempCookie     = null;
	var cookie         = new Object();
    var docCookieArray = document.cookie.split(";");

    for (var i=0,j = docCookieArray.length; i < j; i++)
    {
        tempCookie     = docCookieArray[i];
		
        if (tempCookie.trim().indexOf(strCookieName + "=") == 0)
        {
            res        = unescape(tempCookie.split("=")[1]);
            break;
        }
        else
        {
            res        = strDefaultValue || "";
        }
    }

    return res;
};
