////////////////////////////////////////
// ALL RIGHTS RESERVED COMTRON d.o.o. //
// COPY OR REDISTRIBUTION OF THIS     //
// CONTENT IS NOT ALLOWED.            //
//									  //
// SANTAS LITLE HELPERS				  //
// Dejan Božič                        //
////////////////////////////////////////

// save clients scroll position
function saveScrollPosition()
{
	var strCookie = "SmartNavigation";
	var scrollx = truebody().scrollLeft;
	var scrolly = truebody().scrollTop;
	var scrollCoords = scrollx + ":" + scrolly;
	
	set_cookie(strCookie, scrollCoords, 1, "", "", false);
}

function resetScrollPosition()
{
	var strCookie = "SmartNavigation";
	set_cookie(strCookie, "", 1, "", "", false);
}

// load clients scroll position
function loadScrollPosition()
{
	var strCookie = "SmartNavigation";
	var scrollCoords = get_cookie(strCookie);

	if (scrollCoords == null)
		return;
	else
		scrollCoords = scrollCoords.split(':');

	truebody().scrollLeft = scrollCoords[0];
	truebody().scrollTop = scrollCoords[1];
	resetScrollPosition();
}

// display a loading in progress window in a iFrame
function loadingProgressIFrame(block, iFrameid)
{
	var IFrame = document.getElementById(iFrameid);
	loadingProgressShow(block, IFrame.contentWindow);
}

// display a loading in progress window
function loadingProgress(block)
{
	loadingProgressShow(block, "");
}

// center and display in progress window
function loadingProgressShow(block, contentWindow)
{
	// disble scrolling
	lockScroll();
	
	// get window div reference
	if (contentWindow == "")
		var elem = document.getElementById('divLoadingProgress');
	else
		var elem = contentWindow.document.getElementById('divLoadingProgress');
		
	// block screen
	if (block)
		blockScreen();
		
	elem.style.display	= 'block';
	elem.style.left		= (getClientWindowDimensions()[0] / 2) - (getElementDimension(elem)[0] / 2) + truebody().scrollLeft; 
	elem.style.top		= (getClientWindowDimensions()[1] / 2) - (getElementDimension(elem)[1] / 2) + truebody().scrollTop; 
}

// show the progress window for onPageLoad events
function loadingProgressOnLoad(elem)
{
	return;
	elem.style.display	= 'block';
	elem.style.left		= (getClientWindowDimensions()[0] / 2) - (getElementDimension(elem)[0] / 2) + truebody().scrollLeft; 
	elem.style.top		= (getClientWindowDimensions()[1] / 2) - (getElementDimension(elem)[1] / 2) + truebody().scrollTop; 
}

// blocks the entire screen
function blockScreen()
{
	var divBlockWindow				= document.getElementById('divBlockWindow');
		divBlockWindow.style.display= '';
		divBlockWindow.style.width	= getClientWidthWScroll() + 'px';
		divBlockWindow.style.height = getClientHeightWScroll() + 'px';
}

// unblock the entire screen
function unblockScreen()
{
	var divBlockWindow					= document.getElementById('divBlockWindow');
		divBlockWindow.style.display	= 'none';
}

// sets the block screen style, for onPageLoad events
function setBlockScreenStyle(elem)
{
	return;
	var elemStyle = elem.style;
		elemStyle.display = 'block';
		elemStyle.position = 'absolute';
		elemStyle.width = getClientWidthWScroll() + 'px';
		elemStyle.height = (getClientHeightWScroll() + 400) + 'px';
		elemStyle.top = '0px';
		elemStyle.left = '0px';
		elemStyle.zIndex = 999;
		elemStyle.background = "url(" + shopURL + "/Images/DisabledBackground.gif)";
}

// return clients window width
function getClientWidth()
{
	var winW
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winW = window.innerWidth-16;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth-20;
		}
	}
	return winW;
}

// return clients window width with scroll offset
function getClientWidthWScroll()
{
	return parseFloat(getClientWidth());
}

// return clients window height
function getClientHeight()
{
	var winH
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winH = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winH = document.body.offsetHeight;
		}
	}
	return winH;
}

// return clients window height with scroll offset
function getClientHeightWScroll()
{
	return parseFloat(getClientWidth());
}

// hide in progress window
function loadingProgressHide()
{
	var elem				= document.getElementById('divLoadingProgress');
		elem.style.display	= 'none';
}

// disables user scrolling
function lockScroll()
{
	//document.body.scroll = "no";
}

// inables user scrolling
function unlockScroll()
{
	document.body.scroll = "";
}

// returns the width and height of the clients window
function getClientWindowDimensions()
{
	if (parseInt(navigator.appVersion)>3) 
	{
		if (navigator.appName == "Netscape") 
		{
			winW = window.innerWidth;
			winH = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft") != -1) 
		{
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
		}
	}
	
	return [winW, winH];
}


// loads visibility of an element
function loadElemeVisible(elem)
{
	var object = document.getElementById(elem);
	if (object == null)
		return;
	
	var state = loadElementState(elem);

	if ((state == '') || (state == 'visible'))
		object.style.display = '';
	else
		object.style.display = 'none';
}

// toggles visibility of an element
function toggleElemeVisible(elem)
{
	var object = document.getElementById(elem);
	var state = loadElementState(elem);

	if ((state == '') || (state == 'visible'))
	{
		object.style.display = 'none';
		state = 'hidden';
	}
	else
	{
		object.style.display = '';
		state = 'visible';
	}
		
	saveElementState(elem, state);
}

// save element state
function saveElementState(elem, state)
{
	if (cookieWindowStates == "") { alert('Window state cookie not defined.\nObvestite administrarja.'); }
	var strElementStates = get_cookie(cookieWindowStates);
	
	if ((strElementStates == null) || (strElementStates == "undefined"))
		strElementStates = "";
	
	if ((strElementStates.indexOf(elem) > -1)  && (strElementStates != ""))
	{
		// update existing collection
		var startIndex = strElementStates.indexOf(elem);
		var endIndex = strElementStates.indexOf(";", startIndex) + 1;
		var oldVal = strElementStates.substring(startIndex, endIndex);
		var newVal = elem + "=" + state + ";";

		strElementStates = strElementStates.replace(oldVal, newVal);
	}
	else
	{
		// add new item to collection
		var newVal = elem + "=" + state + ";";
		strElementStates += newVal;
	}

	set_cookie(cookieWindowStates, strElementStates, 10, "", "", false);
}

// get / load element state
// save element visiblity state
function loadElementState(elem)
{
	if (cookieWindowStates == "") { alert('Window state cookie not defined.\nObvestite administrarja.'); }
	var strElementStates = get_cookie(cookieWindowStates);

	if ((strElementStates == null) || (strElementStates == "undefined"))
		strElementStates = "";

	if ((strElementStates.indexOf(elem) > -1)  && (strElementStates != ""))
	{
		// update existing collection
		var startIndex = strElementStates.indexOf(elem);
			startIndex = strElementStates.indexOf("=", startIndex) + 1;
		var endIndex = strElementStates.indexOf(";", startIndex);
		var strState = strElementStates.substring(startIndex, endIndex);
	}
	else
		strState = "";

	return strState;
}

// change element class name
function changeElemClass(elem, newClass)
{ 
	elem.setAttribute("orgClass", elem.className);
	elem.className = newClass;
}

function restoreElemClass(elem)
{ 
	elem.className = elem.getAttribute("orgClass");
}

// fade element
function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) 
	{
		for(i = opacStart; i >= opacEnd; i--) 
		{
			if (!hasElementOver)
			{
				changeOpac(0, id);
				break;
			}
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} 
	else if(opacStart < opacEnd) 
	{
		for(i = opacStart; i <= opacEnd; i++)
		{
			if (!hasElementOver)
			{
				changeOpac(0, id);
				break;
			}
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}


// GLOBAL HELP VAR
var hasElementOver = false;
	//Events.Register("onmousemove", "mousemoveevent(e)");

// check if we left a element over
function mousemoveevent(e)
{
	if (!hasElementOver)
		changeOpac(0, 'divWindow');
}

//change the opacity for different browsers
function changeOpac(opacity, id) 
{
	if (GetElement(id) != null)
	{
		var object = GetElement(id).style;
			object.opacity = (opacity / 100);
			object.MozOpacity = (opacity / 100);
			object.KhtmlOpacity = (opacity / 100);
			object.filter = "alpha(opacity=" + opacity + ")";
	}
} 

// quick help
function QuickHelp(elem, strHelpTitle, strHelpMessage)
{
	document.getElementById('HelpTitle').innerHTML = strHelpTitle;
	document.getElementById('HelpMessage').innerHTML = strHelpMessage;

	ShowHelp(elem);
	setTimeout("opacity('divWindow',0,100,500);", 200);
}

// quick help
function ShowHelp(elem)
{
	document.getElementById('divWindow').style.display = '';
	hasElementOver = true;

	var window = document.getElementById('divWindow');
	var xpos = ypos = 0;
	var docwidth	= document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight	= document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if ((getElementPosition(elem)[0] + getElementDimension(elem)[0] + 300) > docwidth)
	{
		xpos = getElementPosition(elem)[0] - getElementDimension(elem)[0] - 2;
	}
	else
	{
		xpos = getElementPosition(elem)[0] + getElementDimension(elem)[0];
	}
	ypos = getElementPosition(elem)[1] + 5;

	window.style.left = xpos;
	window.style.top = ypos;
}

// hide quick help
function HideHelp()
{
	hasElementOver = false;
	document.getElementById('divWindow').style.display = 'none';
	document.getElementById('divWindow').style.offsetLeft = -300;
	changeOpac(0, 'divWindow');
}

// get element position
function getElementPosition(obj) {
	try
	{
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}

		return [parseFloat(curleft),parseFloat(curtop)];
	}
	catch(ex){}
}

// get body
function truebody()
{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

// add element to array
function addElementToArray(element, array)
{
	var arrLength = array.length;
		array[arrLength] = element;
	return array;
}

// remove element from array
function removeElementFromArray(element, array)
{
	var newArray = new Array();
	
	for(var i = 0; i < array.length; i++)
	{
		if (array[i] != element)
			addElementToArray(array[i], newArray);
	}

	return newArray;
}

// Set cookie
function set_cookie(name, value, nDays, path, domain, secure)
{
	var cookie_string = name + "=" + escape ( value );
	var today = new Date();
	var expire = new Date();
		expire.setTime(today.getTime() + 3600000*24*nDays);

	cookie_string += "; expires=" + expire.toGMTString();

	if ( path )
			cookie_string += "; path=" + escape ( path );

	if ( domain )
			cookie_string += "; domain=" + escape ( domain );
		
	if ( secure )
			cookie_string += "; secure";

	document.cookie = cookie_string;
}

// Get cookie
function get_cookie( name )
{;
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	
	if ( start == -1 ) return null;
	
	var end = document.cookie.indexOf( ";", len );
	
	if ( end == -1 ) end = document.cookie.length;

	return unescape( document.cookie.substring( len, end ) );
}

// Delete cookie
function delete_cookie( name, path, domain ) 
{
	if (get_cookie(name))
		set_cookie(name, "", -1, path, domain, false);
}

// Returns document element
function GetElement(id)
{
	try
	{
		var elem = document.getElementById(id);
		
		if (elem != null)
			return document.getElementById(id);
		
		var len = document.body.childNodes.length;
		for(var i = 0; i < len; i++)
		{
			if (document.body.childNodes[i].Id == id)
			return document.body.childNodes[i];
		}	
		
		return null;
	}
	catch(ex){}	
}

// Returns document element from parent
function GetParentElement(id)
{
	try
	{
		var elem = parent.document.getElementById(id);
		
		if (elem != null)
			return parent.document.getElementById(id);
		
		var len = parent.document.body.childNodes.length;
		for(var i = 0; i < len; i++)
		{
			if (parent.document.body.childNodes[i].Id == id)
			return parent.document.body.childNodes[i];
		}	
		
		return null;	
	}
	catch(ex){}	
}

// Show hand
function Hand(elem)
{
	if ((elem != null) && elem.style != "undefined")
		elem.style.cursor = 'pointer';
}

// is element in mouse x y
function isMouseBound(elemid, _mousexy)
{
	try
	{
		var _elemxy		= GetElementPos(elemid);
		var _elemdimen	= getElementDimension(elemid);
		
		//_elemxy[0] = parseFloat(_elemxy[0]) - parseFloat(truebody().scrollLeft);
		//_elemxy[1] = parseFloat(_elemxy[1]) - parseFloat(truebody().scrollTop);

		if (((_mousexy[0] >= _elemxy[0]) && (_mousexy[0] <= _elemxy[0] + _elemdimen[0])) && ((_mousexy[1] >= _elemxy[1]) && (_mousexy[1] <= _elemxy[1] + _elemdimen[1]))) 
			return true;
		
		return false;
	} catch(ex) {}
}

// get element poisiton
function GetElementPos(elem)
{
	if (typeof(elem) != "object")
		elem = GetElement(elem);

	if ( ((navigator.appName.indexOf("Microsoft")!=-1) || (navigator.appName.indexOf("Opera")!=-1)) && (shopPREFIX == "ZdravilaB2C") ) {
		return [elem.offsetLeft,elem.offsetTop];
	} 
 
	return findNodePos(elem);
}

// return root position of node
function findNodePos(obj) {
	try
	{
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}

		return [parseFloat(curleft),parseFloat(curtop)];
	}
	catch(ex){}
}

// get element width height
function getElementDimension(elemid)
{
	if (elemid == null)
		return;

	if (typeof(elemid) == "object")
		var elem = elemid;
	else
		var elem = GetElement(elemid);
	
	if (elem != null)
		return [parseFloat(elem.offsetWidth),parseFloat(elem.offsetHeight)];
	else
		return [0, 0];
}

// positions an element to the specified aligment, offset or both.
function SetElementPosition(elem, strAlign, strOffset)
{
	if (typeof(elem) != "object")
		elem = GetElement(elem);

	strAlign					= strAlign.split(",");
	strOffset					= strOffset.split(",");

	if (strAlign[1] == 'top')
		elem.style.top = parseFloat(strOffset[1]) + 'px';
	else if (strAlign[1] == 'bottom')
		elem.style.top = ((parseFloat(getClientWindowDimensions()[1]) - parseFloat(getElementDimension(elem)[1])) + parseFloat(strOffset[1])) + 'px';
	else if (strAlign[1] == 'center')
		elem.style.top = (((parseFloat(getClientWindowDimensions()[1]) - parseFloat(getElementDimension(elem)[1])) / 2) + parseFloat(strOffset[1]) + truebody().scrollTop) + 'px';
	else
		elem.style.top = strOffset[1] + 'px';

	if (strAlign[0] == 'right')
		elem.style.left = ((parseFloat(getClientWindowDimensions()[0]) - parseFloat(getElementDimension(elem)[0])) + parseFloat(strOffset[0])) + 'px';
	else if (strAlign[0] == 'left')
		elem.style.left = parseFloat(strOffset[0]) + 'px';
	else if (strAlign[0] == 'center')
		elem.style.left = (((parseFloat(getClientWindowDimensions()[0]) - parseFloat(getElementDimension(elem)[0])) / 2) + parseFloat(strOffset[0]) + truebody().scrollLeft) + 'px';
	else
		elem.style.left = strOffset[0] + 'px';
}

function SetElementPositionByElement(elem, byElem, strAlign, strOffset)
{
	if (typeof(elem) != "object")
		elem = GetElement(elem);
		
	if (typeof(byElem) != "object")
		byElem = GetElement(byElem);

	strAlign					= strAlign.split(",");
	strOffset					= strOffset.split(",");

	if (strAlign[1] == 'top')
		elem.style.top = parseFloat(strOffset[1]) + 'px';
	else if (strAlign[1] == 'bottom')
		elem.style.top = ((parseFloat(getClientWindowDimensions()[1]) - parseFloat(getElementDimension(byElem)[1])) + parseFloat(strOffset[1])) + 'px';
	else if (strAlign[1] == 'center')
		elem.style.top = (((parseFloat(getClientWindowDimensions()[1]) - parseFloat(getElementDimension(byElem)[1])) / 2) + parseFloat(strOffset[1]) + truebody().scrollTop) + 'px';
	else
		elem.style.top = strOffset[1] + 'px';

	if (strAlign[0] == 'right')
		elem.style.left = ((parseFloat(getClientWindowDimensions()[0]) - parseFloat(getElementDimension(byElem)[0])) + parseFloat(strOffset[0])) + 'px';
	else if (strAlign[0] == 'left')
		elem.style.left = parseFloat(strOffset[0]) + 'px';
	else if (strAlign[0] == 'center')
		elem.style.left = (((parseFloat(getClientWindowDimensions()[0]) - parseFloat(getElementDimension(byElem)[0])) / 2) + parseFloat(strOffset[0]) + truebody().scrollLeft) + 'px';
	else
		elem.style.left = strOffset[0] + 'px';
}

function Timer(classRef)
{
	this.Time = 0;
	
	this.Now = Now;
	function Now()
	{
		return (new Date()).getTime();
	}
	
	this.Start = Start;
	function Start()
	{
		eval(classRef).Time = eval(classRef).Now();
	}
	
	this.Stop = Stop;
	function Stop()
	{
		return eval(classRef).Now() - eval(classRef).Time;
	}
}


// Drag class
function DragElement(classRef)
{
	// ATTRIBUTES SETTINGS
	this.DragItemHeader = null;
	this.DragItem		= null;
	this.mousePos		= new Array();
	this.isMouseDown	= false;
	this.xoffset		= 0;
	this.xoffset		= 0;
	
	// ATTRIBUTES 
	this.CookiePath				= "/";
	this.CookieDomain			= shopDomain;
	this.isSecure				= false;
	this.BasketType				= shopTYPE;
	this.URL					= shopURL;
	this.currxpos				= 0;
	this.currypos				= 0;
	this.DoubleClick			= 0;
	this.ClickTimer				= new Timer(classRef + ".ClickTimer");
	this.isDraggable			= false;

	// Start dragging DragItement
	this.Init = Init;
	function Init()
	{
		eval(classRef).MakeDraggable();
		eval(classRef).Load();
	}
	
	this.MakeDraggable = MakeDraggable
	function MakeDraggable()
	{
		eval(classRef).DragItemHeader.style.cursor = "pointer";
		Events.ElementRegister(this.DragItemHeader, "onmousedown", eval(classRef).Start);
	
		if (Settings.GetSetting("BasketDrag") == "true")
			eval(classRef).isDraggable = true;
		else
		{
			eval(classRef).isDraggable = false;
			return;
		}

		eval(classRef).DragItem.style.width = getElementDimension(eval(classRef).DragItem)[0] + 'px';
		eval(classRef).DragItem.style.height = getElementDimension(eval(classRef).DragItem)[0] + 'px';
		eval(classRef).DragItem.style.position = 'absolute';
		eval(classRef).DragItem.style.zIndex	= 9998;
	}
	
	this.ResetPosition = ResetPosition
	function ResetPosition()
	{
		eval(classRef).DragItem.style.position = '';
	}
	
	this.Start = Start
	function Start()
	{
		Events.Register("onmouseup", classRef + ".Stop()");
		Events.Register("onmousemove", classRef + ".FollowMouse(e)");

		eval(classRef).DoubleClick++;
		if (eval(classRef).DoubleClick == "2")
		{
			eval(classRef).DoubleClick = 0;
			if (parseInt(eval(classRef).ClickTimer.Stop()) > 500) return;
			if (eval(classRef).isDraggable)
			{
				eval(classRef).isDraggable = false;
				Settings.AddSetting("BasketDrag", false);
				eval(classRef).ResetPosition();
			}
			else
			{
				eval(classRef).isDraggable = true;
				Settings.AddSetting("BasketDrag", true);
				eval(classRef).MakeDraggable();
			}

			Settings.Save();
		}
		else
		{
			eval(classRef).ClickTimer.Start();
		}
	}

	// Drag DragItements to mouse coords
	this.FollowMouse = FollowMouse
	function FollowMouse(e)
	{
		var tmpDragItem = eval(classRef + ".DragItem");
		var tmpDrag = eval(classRef);
		
		if (typeof e != "undefined") { tmpDrag.mousePos[0] = e.pageX; tmpDrag.mousePos[1] = e.pageY; } 
		else if (typeof window.event != "undefined") { tmpDrag.mousePos[0] = event.clientX; tmpDrag.mousePos[1] = event.clientY; }
		
		if (!eval(classRef).isMouseDown)
		{
			eval(classRef).xoffset = GetElementPos(eval(classRef).DragItemHeader)[0] - eval(classRef).mousePos[0];
			eval(classRef).yoffset = GetElementPos(eval(classRef).DragItemHeader)[1] - eval(classRef).mousePos[1];
			eval(classRef).isMouseDown = true;
		}
		
		var xpos = eval(classRef).xoffset + tmpDrag.mousePos[0];
		var ypos = eval(classRef).yoffset + tmpDrag.mousePos[1];
		eval(classRef).currxpos = xpos;
		eval(classRef).currypos = ypos;
		
		SetElementPosition(tmpDragItem, "", xpos + "," + ypos);
	}

	// Stop dragging DragItement
	this.Stop = Stop
	function Stop()
	{
		Events.ElementUnregister(eval(classRef).DragItemHeader, "onmouseup", eval(classRef).Stop); 
		Events.UnRegister("onmousemove", classRef + ".FollowMouse(e)");
		eval(classRef).isMouseDown = false;
		eval(classRef).Save();
	}
	
	this.Save = Save
	function Save()
	{
		var Item		= new DragElementItem(classRef);
			Item.ID		= eval(classRef).DragItem.id;
			Item.xpos	= eval(classRef).currxpos;
			Item.ypos	= eval(classRef).currypos;
			Item.Save(eval(classRef).DragItem.id);
	}
	
	this.Load = Load
	function Load()
	{
		var Item = new DragElementItem(classRef);
			Item = Item.Load(eval(classRef).DragItem.id);
			
			if (Item != null)
				SetElementPosition(eval(classRef).DragItem, "", Item.xpos + "," + Item.ypos);
	}
}

function DragElementItem(classRef)
{
	// ATTRBITEUS
	this.ID = null;
	this.xpos = 0;
	this.ypos = 0;
	
	// METHODS
	this.Load = Load;
	function Load(id)
	{
		var newItem	= new DragElementItem(classRef);
		if (Settings.GetSetting(id + "xpos") == null) return newItem;
		
		newItem.ID		= id;
		newItem.xpos	= Settings.GetSetting(id + "xpos");
		newItem.ypos	= Settings.GetSetting(id + "ypos");
		return newItem;
	}
	
	this.Save = Save;
	function Save(id)
	{
		Settings.AddSetting(id + "xpos", eval(classRef).currxpos);
		Settings.AddSetting(id + "ypos", eval(classRef).currypos);
		Settings.Save();
	}
}

// User defined settings
function StoreSettings(classRef)
{
	this.CookieName		= "Settings";
	this.arrSettings	= new Array();
	this.strSettings	= "";
	this.CookiePath		= "/";
	this.CookieDomain	= shopDomain;
	this.isSecure		= false;
	this.BasketValid	= 7;
	
	this.AddSetting = AddSetting
	function AddSetting(id, val)
	{
		var setting = GetSetting(id);
		if (setting == null)
		{
			this.arrSettings.push(id + "=" + val);
		}
		else
		{
			for (i in this.arrSettings)
			{
				var setting = this.arrSettings[i].split('=')[0];
				if (setting == id)
				{
					this.arrSettings[i] = id + "=" + val;
					break;
				}
			}
		}
		eval(classRef).arrSettings = this.arrSettings;
	}
	
	this.RemoveSetting = RemoveSetting
	function RemoveSetting(id)
	{
		var setting = GetSetting(id);
		if (setting == null) return;
		
		for (i in this.arrSettings)
		{
			var setting = this.arrSettings[i].split('=')[0];
			if (setting == id)
			{
				this.arrSettings = this.arrSettings.splice(i, 1);
				break;
			}
		}
		eval(classRef).arrSettings = this.arrSettings;
	}
	
	this.GetSetting = GetSetting
	function GetSetting(id)
	{
		this.arrSettings = eval(classRef).arrSettings;
		for (i in this.arrSettings)
		{
			var setting = this.arrSettings[i].split('=')[0];
			if (setting == id)
				return this.arrSettings[i].split('=')[1];
		}
		
		return null;
	}
	
	this.Load = Load
	function Load()
	{
		this.strSettings = get_cookie(eval(classRef).CookieName);
		if (this.strSettings == null) return;

		this.arrSettings = this.strSettings.split(';');
	}

	this.Save = Save
	function Save()
	{
		this.arrSettings = eval(classRef).arrSettings;
		this.strSettings = this.arrSettings.join(';')
		set_cookie(eval(classRef).CookieName, this.strSettings, eval(classRef).BasketValid, eval(classRef).CookiePath, eval(classRef).CookieDomain, eval(classRef).isSecure); 
	}
}


var objProgress = {
	Total: 0,
	Current: 1,
	ProgressBar: null,
	ProgressBarWidth: 0,
	ProgressBarHeight: 0,
	
	SetTotal: function(intTotal)
	{
		this.Total = parseFloat(intTotal);
	},

	SetProgressBar: function(elemid)
	{
		this.ProgressBar = GetElement(elemid);
		this.ProgressBarWidth = getElementDimension(this.ProgressBar)[0];
		this.ProgressBarHeight = getElementDimension(this.ProgressBar)[1];
	},
	
	SetProgressText: function(strText)
	{
		GetElement("spanProgressText").innerHTML = strText;
	},
	
	Start: function()
	{
		this.ProgressBar.style.width = "0px";
		this.Current = 1;
	},
	
	Reset: function()
	{
		this.Start();
	},
	
	Step: function(intStep)
	{
		if (parseFloat(intStep) < 1) intStep = 1;
		this.Current = parseFloat(intStep);
		
		var percent = ((this.Current / this.Total) * 100) - 1;
		
		GetElement("spanProgressPercent").innerHTML = Math.round(percent) + "%";
		this.ProgressBar.style.width = Math.round((percent * this.ProgressBarWidth) / 100) + "px";
	},
	
	Complete: function()
	{
		var percent = 100;
		
		GetElement("spanProgressPercent").innerHTML = Math.round(percent) + "%";
		this.ProgressBar.style.width = Math.round((percent * this.ProgressBarWidth) / 100) + "px";
		this.ProgressBar.style.display = "none";
	}
}


//vrne datum v obliki: Ponedelje, d.m.yyyy
function getCalendarDate()
{
	var days = new Array(9);
	days[0] = "Nedelja";
	days[1] = "Ponedeljek";
	days[2] = "Torek";
	days[3] = "Sreda";
	days[4] = "Četrtek";
	days[5] = "Petek";
	days[6] = "Sobota";

	var now = new Date();
	var dayname = days[now.getDay()];
	var daynumber = now.getDate();
	var monthnumber = now.getMonth();
	var year = now.getYear();
	if(year < 2000) { year = year + 1900; }
	var dateString = dayname + ', ' + daynumber + '.' + (monthnumber+1) + '.' + year;
	return dateString;
}

function getElementsByClassName(className)
{
	var arr = new Array();
	var elems = document.getElementsByTagName("*");
	
	for(var i = 0; i < elems.length; i++)
	{
		var elem = elems[i];
		var cls = elem.getAttribute("class");
		
		if(cls == className)
		{
			arr[arr.length] = elem;
		}
	}
	return arr;
}

function CheckAndSubmit()
{
	formcontent=document.form1.srchString.value;
	
	if(formcontent.length > 2 )
	{
		document.form1.submit();
	} 
	else
	{
		alert("Za iskanje morate vnesti najmanj tri znake!")
	}
}

function ShowMenu(menu, level)
{	
	document.getElementById(menu.id).style.position = 'absolute';
	document.getElementById(menu.id).style.visibility = 'visible';
	document.getElementById(menu.id).level = level; 
}

function menuout(n)
{	
	document.getElementById(n).style.visibility='hidden'; 
}

function DisplayMenu(n)
{
	document.getElementById(n).style.visibility='visible'; 
}


function ShowSubClassifications(classid)
{
	location = "<%=objShop.URL%>/Classification.asp?ClassID=" + classid;
}

function ShowModelSubClassifications(classid)
{
	location = "<%=objShop.URL%>/ModelClassification.asp?ClassID=" + classid;
}

function SumitSurvey(url)
{
	try
	{
		GetElement("frmSubmitSurvey").action = url;
		GetElement("frmSubmitSurvey").submit();
	}
	catch(ex){};
	
	try
	{
		GetElement("frmSubmitSurvey2").action = url;
		GetElement("frmSubmitSurvey2").submit();
	}
	catch(ex){};
}

function SwitchSurveyDisplay(displayType)
{
	if (displayType == "results")
	{
		var elem = document.getElementById('trSurveyResults');
			elem.style.display = '';
			
			elem = document.getElementById('trSurveyVote');
			elem.style.display = 'none';
	}
	
	if (displayType == "vote")
	{
		var elem = document.getElementById('trSurveyVote');
			elem.style.display = '';
			
			elem = document.getElementById('trSurveyResults');
			elem.style.display = 'none';
	}
	
	if (displayType == "voteButtonFalse")
	{
		var elem = document.getElementById('btSurveyVote');
			elem.style.display = 'none';
	}
	
	if (displayType == "voteButtonTrue")
	{
		var elem = document.getElementById('btSurveyVote');
			elem.style.display = '';
	}
}

function emailCheck (emailStr) 
{
	var f = document.frmLogin;
	var checkTLD=1;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) 
	{
		alert("Elektronski naslov ni pravilen (preveri @ in .)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	for (i=0; i<user.length; i++) 
	{
		if (user.charCodeAt(i)>127) 
		{
			alert("Elektronski naslov: Uporabniško ime uporablja nepravilne znake.");
			return false;
		}
	}
	for (i=0; i<domain.length; i++) 
	{
		if (domain.charCodeAt(i)>127) 
		{
			alert("Elektronski naslov: Ime domene uporablja nepravilne znake.");
			return false;
		}
	}

	if (user.match(userPat)==null) 
	{
		alert("Elektronski naslov: Uporabnisko ime ni pravilno.");
		return false;
	}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) 
	{

		for (var i=1;i<=4;i++) 
		{
			if (IPArray[i]>255) 
			{
				alert("Elektronski naslov: Naslovnikov IP naslov ni pravilen!");
				return false;
			}
		}
		return true;
	}
 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) 
	{
		if (domArr[i].search(atomPat)==-1) 
		{
			alert("Elektronski naslov: Domena ni pravilna.");
			return false;
		}
	}

	if (len<2) 
	{
		alert("Elektronski naslov: Temu naslovu manjka gostitelj!");
		return false;
	}

	return true;
}

function addMailList(email)
{
	if (emailCheck (document.all.Email.value)==true)
	{
		if (shopPrefix == "BABYCenter")
		{
			var winwidth = 500;
			var winheight = 240;
		}
		else
		{
			var winwidth = 500;
			var winheight = 400;
		}
		
		
		var winl = (screen.width - winwidth) / 2;
		var wint = (screen.height - winheight) / 2;
		
		window.open("/Include/MailListAddFrame.asp?Email=" + document.all.Email.value, null, "height=" + winheight + ",width=" + winwidth + ",top=" + wint + ",left=" + winl + ",status=no,toolbar=no,menubar=no,resizable=no,location=no");
		
	}
}

function submitSearch()
	{
		var URL = shopURL + "/" + "search.asp?";
		var SearchString = document.getElementById('srchString').value;

		if ((SearchString != "") )
		{
			    SearchString = escape(SearchString)
			var srchString = "srchString=" + SearchString + "&";
				URL += srchString;
		}

		var RCLClassID = document.getElementById('ddlRCLClass');
			if (RCLClassID != null)
			{
				RCLClassID = RCLClassID.options[RCLClassID.selectedIndex].value;
				var srchRCLClassID = "srchRCLClassID=" + RCLClassID + "&";
				URL += srchRCLClassID;
			}
		
		URL += "submit1=Najdi";
		parent.location = URL;
	}
	
function StringToNode(str)
{
	var el = document.createElement("div");
		el.innerHTML = str;
		
	return el.childNodes[0];
}
	
var SearchNew = {
	////////////// DROPDOWN CONTROL EVENTS ///////////////////////////
	onGroupsChange: function(el)
	{
		this.UpdateClassI();
		this.ResetClassII();
		this.ResetClassIII();
		this.UpdateManufacturer();
		
	},
	onClassIChange: function(el)
	{
		if (GetElement("ddlSearchClassI").value == "-1")
		{
			this.ResetClassII();
			this.ResetClassIII();
			this.UpdateManufacturer();
			return;
		}
		
		this.UpdateClassII();
		this.ResetClassIII();
		this.UpdateManufacturer();
		
	},
	onClassIIChange: function(el)
	{
		if (GetElement("ddlSearchClassII").value == "-1")
		{
			this.ResetClassIII();
			return;
		}
	
		this.UpdateClassIII();
		
	},
	onClassIIIChange: function(el)
	{
		if (GetElement("ddlSearchClassIII").value == "-1")
		{	
			return;
		}
		this.UpdateClassIV();
		
	},
	onManufacturerChange: function(el)
	{
		this.UpdateManufacturer();
	},
	////////////// DROPDOWN CONTROL EVENTS ///////////////////////////
	
	//////////////////// UPDATE CLASS LEVEL 1 /////////////////////////
	UpdateClassI: function()
	{
		var aRequest = new System.Net.Ajax.Request("POST", shopURL + "/Include/SearchNewGet.asp", this.UpdateClassI_Callback, true);			
			aRequest.AddParam("GetClassI", 1);
			aRequest.AddParam("GroupID", GetElement("ddlSearchGroup").value);
			aRequest.AddParam("ManufacturerID", GetElement("ddlSearchManufacturer").value);
			
		var aPageRequest = new System.Net.Ajax.PageRequests(aRequest);
		var aConnection = new System.Net.Ajax.Connection(aPageRequest);
            aConnection.Open();
	},
	UpdateClassI_Callback: function(src)
	{
		if(src.Complete)
		{	
			var el = GetElement("ddlSearchClassI");
			el.parentNode.replaceChild(StringToNode(src.ResponseText), el);
		}
	},
	ResetClassI: function()
	{
		var el = GetElement("ddlSearchClassI");
			el.options.length = 0;
			el.options[0] = new Option("...", "", true, false)
	},
	//////////////////// UPDATE CLASS LEVEL 1 /////////////////////////
	
	//////////////////// UPDATE CLASS LEVEL 2 /////////////////////////
	UpdateClassII: function()
	{
		var aRequest = new System.Net.Ajax.Request("POST", shopURL + "/Include/SearchNewGet.asp", this.UpdateClassII_Callback, true);			
			aRequest.AddParam("GetClassII", 1);
			aRequest.AddParam("GroupID", GetElement("ddlSearchGroup").value);
			aRequest.AddParam("ClassID", GetElement("ddlSearchClassI").value);
			aRequest.AddParam("ManufacturerID", GetElement("ddlSearchManufacturer").value);
			
		var aPageRequest = new System.Net.Ajax.PageRequests(aRequest);
		var aConnection = new System.Net.Ajax.Connection(aPageRequest);
            aConnection.Open();
	},
	UpdateClassII_Callback: function(src)
	{
		if(src.Complete)
		{	
			var el = GetElement("ddlSearchClassII");
			el.parentNode.replaceChild(StringToNode(src.ResponseText), el);
		}
	},
	ResetClassII: function()
	{
		var el = GetElement("ddlSearchClassII");
			el.options.length = 0;
			el.options[0] = new Option("...", "", true, false)
	},
	//////////////////// UPDATE CLASS LEVEL 2 /////////////////////////
	
	//////////////////// UPDATE CLASS LEVEL 3 /////////////////////////
	UpdateClassIII: function()
	{
		var aRequest = new System.Net.Ajax.Request("POST", shopURL + "/Include/SearchNewGet.asp", this.UpdateClassIII_Callback, true);			
			aRequest.AddParam("GetClassIII", 1);
			aRequest.AddParam("GroupID", GetElement("ddlSearchGroup").value);
			aRequest.AddParam("ClassID", GetElement("ddlSearchClassII").value);
			aRequest.AddParam("ManufacturerID", GetElement("ddlSearchManufacturer").value);

		var aPageRequest = new System.Net.Ajax.PageRequests(aRequest);
		var aConnection = new System.Net.Ajax.Connection(aPageRequest);
            aConnection.Open();
	},
	UpdateClassIII_Callback: function(src)
	{
		if(src.Complete)
		{	
			var el = GetElement("ddlSearchClassIII");
			el.parentNode.replaceChild(StringToNode(src.ResponseText), el);
		}
	},
	ResetClassIII: function()
	{
		var el = GetElement("ddlSearchClassIII");
			el.options.length = 0;
			el.options[0] = new Option("...", "", true, false)
	},
	//////////////////// UPDATE CLASS LEVEL 3 /////////////////////////
	
	//////////////////// UPDATE CLASS LEVEL 4 /////////////////////////
	// Actualy just a dummy method to update the session state
	UpdateClassIV: function()
	{
		var aRequest = new System.Net.Ajax.Request("POST", shopURL + "/Include/SearchNewGet.asp", null, true);			
			aRequest.AddParam("GroupID", GetElement("ddlSearchGroup").value);
			aRequest.AddParam("ClassID", GetElement("ddlSearchClassIII").value);
			aRequest.AddParam("ManufacturerID", GetElement("ddlSearchManufacturer").value);
			
		var aPageRequest = new System.Net.Ajax.PageRequests(aRequest);
		var aConnection = new System.Net.Ajax.Connection(aPageRequest);
            aConnection.Open();
	},
	//////////////////// UPDATE CLASS LEVEL 4 /////////////////////////
	
	//////////////////// UPDATE MANUFACTURER /////////////////////////
	UpdateManufacturer: function()
	{
		var aRequest = new System.Net.Ajax.Request("POST", shopURL + "/Include/SearchNewGet.asp", this.UpdateManufacturer_Callback, true);			
			aRequest.AddParam("GetManufacturer", 1);	
			aRequest.AddParam("GroupID", GetElement("ddlSearchGroup").value);
			aRequest.AddParam("ClassID", GetElement("ddlSearchClassI").value);
			aRequest.AddParam("ManufacturerID", GetElement("ddlSearchManufacturer").value);
		
		var aPageRequest = new System.Net.Ajax.PageRequests(aRequest);
		var aConnection = new System.Net.Ajax.Connection(aPageRequest);
            aConnection.Open();
	},
	UpdateManufacturer_Callback: function(src)
	{
		if(src.Complete)
		{
			var el = GetElement("ddlSearchManufacturer");
			el.parentNode.replaceChild(StringToNode(src.ResponseText), el);
		}
	},
	ResetClassI: function()
	{
		var el = GetElement("ddlSearchClassI");
			el.options.length = 0;
			el.options[0] = new Option("...", "", true, false)
	},
	//////////////////// UPDATE MANUFACTURER /////////////////////////
	
	/////////////////////// PERFORM SEARCH ////////////////////////////
	Search: function()
	{
		// Get search conditions
		var iGroupID = GetElement("ddlSearchGroup").value;
		var iClassI = GetElement("ddlSearchClassI").value;
		var iClassII = GetElement("ddlSearchClassII").value;
		var iClassIII = GetElement("ddlSearchClassIII").value;
		var sString = GetElement("SearchString").value;
		var sManufacturer = GetElement("ddlSearchManufacturer").value;
		var URL = shopURL + "/SearchNew.asp";
		var Param = "";
		
		// Add group to search param
		if (iGroupID != '' && iGroupID != -1)
			Param += "&SGID=" + iGroupID;
		
		// Add classifications to search param
		var ClassParam = "";
		if (iClassI != '' && iClassI != -1)
			ClassParam = "&SCID=" + iClassI;
		if (iClassII != '' && iClassII != -1)
			ClassParam = "&SCID=" + iClassII;
		if (iClassIII != '' && iClassIII != -1)
			ClassParam = "&SCID=" + iClassIII;
		Param += ClassParam;
		
		// Add search string to search param
		if (sString != '')
			Param += "&SS=" + sString;
		
		// Add Manufacturer ID to search param
		if (sManufacturer != -1)
			Param += "&SM=" + sManufacturer;
		
			
		// Remove trailing & and replace it with a ?
		if (Param != '')
			Param = "?" + Param.substr(1, Param.length - 1)
		
		// Perform search
		window.location.href = URL + Param;
	},
	
	/////////////////////// PERFORM SEARCH TONERS ////////////////////////////
	SearchToners: function()
	{
		// Get search conditions
		var iGroupID = GetElement("ddlSearchGroup_t").value;
		var iClassI = GetElement("ddlSearchClassI_t").value;
		var iClassII = GetElement("ddlSearchClassII_t").value;
		var iClassIII = GetElement("ddlSearchClassIII_t").value;
		var sString = GetElement("SearchString_t").value;
		var sManufacturer = GetElement("ddlSearchManufacturer_t").value;
		var URL = shopURL + "/SearchToners.asp";
		var Param = "";
		
		// Add group to search param
		if (iGroupID != '' && iGroupID != -1)
			Param += "&SGID=" + iGroupID;
		
		// Add classifications to search param
		var ClassParam = "";
		if (iClassI != '' && iClassI != -1)
			ClassParam = "&SCID=" + iClassI;
		if (iClassII != '' && iClassII != -1)
			ClassParam = "&SCID=" + iClassII;
		if (iClassIII != '' && iClassIII != -1)
			ClassParam = "&SCID=" + iClassIII;
		Param += ClassParam;
		
		// Add search string to search param
		if (sString != '')
			Param += "&SS=" + sString;
		
		// Add Manufacturer ID to search param
		if (sManufacturer != -1)
			Param += "&SM=" + sManufacturer;
			
		// Remove trailing & and replace it with a ?
		if (Param != '')
			Param = "?" + Param.substr(1, Param.length - 1)
		
		
		// Perform search
		window.location.href = URL + Param;
	}
	/////////////////////// PERFORM SEARCH TONERS////////////////////////////
}

// Gets the selcted text
function getSel()
{
	if (document.getSelection) txt = document.getSelection();
	else if (document.selection) txt = document.selection.createRange().text;
	else return;

	return txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
}

function searchOnEnterPressed(e) 
{
	var ENTER_KEY = 13;
	var code = "";
      
    if (window.event) // IE
    {
		code = e.keyCode;
    }
    else if (e.which) // Netscape/Firefox/Opera
    {
		code = e.which;
    }
            
    if (code == ENTER_KEY) {
		SearchNew.Search();
		return false;    
    }
}

function searchTonersOnEnterPressed(e) 
{
	var ENTER_KEY = 13;
	var code = "";
      
    if (window.event) // IE
    {
		code = e.keyCode;
    }
    else if (e.which) // Netscape/Firefox/Opera
    {
		code = e.which;
    }
            
    if (code == ENTER_KEY) {
		SearchNew.SearchToners();
		return false;    
    }
}

function searchOnEnterPressedQuick(e) 
{
	var ENTER_KEY = 13;
	var code = "";
      
    if (window.event) // IE
    {
		code = e.keyCode;
    }
    else if (e.which) // Netscape/Firefox/Opera
    {
		code = e.which;
    }
            
    if (code == ENTER_KEY) {
		document.location = shopURL + '/SearchNew.asp?SGID=1&SS=' + document.getElementById('srchBox').value;
		return false;    
    }
}