function getUniqueId()
{
	var stamp = new Date();
	var id = stamp.getMonth().toString() + stamp.getDay() + stamp.getHours() + stamp.getMinutes() + stamp.getSeconds() + stamp.getMilliseconds() ;
	return id;
}

function ajaxPost(url, container, postParams, encoding)
{
	var xmlObj = createXMLRequest();
	if( url.indexOf('?') == -1 )
	{
		url += '?noCache=' + getUniqueId();
	}
	else
	{
		url += '&noCache=' + getUniqueId();
	}
	xmlObj.open('POST', url, false);
	if(encoding)
		xmlObj.setRequestHeader('Content-Type', encoding);
	else 
		xmlObj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
		
	xmlObj.send(postParams);
}

function ajaxLoad(url, container, callBack, imageLoading)/*THIS FUNCTION LOADS A PAGE INTO A DIV*/
{
	var xmlObj = createXMLRequest();
	
	if( imageLoading && imageLoading.length > 0 && $(container) )
	{
		$(container).innerHTML = imageLoading;
	}
	
	xmlObj.onreadystatechange=function(){
			loadPage(xmlObj, container, callBack)
	}
	if( url.indexOf('?') == -1 )
	{
		url += '?noCache=' + getUniqueId();
	}
	else
	{
		url += '&noCache=' + getUniqueId();
	}
	xmlObj.open('GET', url, true) // asignamos los métodos open y send
	xmlObj.send(null)
}

function ajaxLoadSync(url, container)/*THIS FUNCTION LOADS A PAGE INTO A DIV*/
{
	
	var xmlObj = createXMLRequest();
	
	if( url.indexOf('?') == -1 )
	{
		url += '?noCache=' + getUniqueId();
	}
	else
	{
		url += '&noCache=' + getUniqueId();
	}
	
	xmlObj.open('GET', url, false);
	xmlObj.send(null);
	
	if(container)container.innerHTML=xmlObj.responseText;
	return xmlObj.responseText;
}

function loadPage(request, container, callBack){
	if(request.readyState == 4)
	{
		if (container)container.innerHTML=request.responseText
		if(callBack){eval(callBack);}
	}
}

function createXMLRequest(){
var XMLObj;
if(window.XMLHttpRequest) {XMLObj = new XMLHttpRequest()} 
else if(window.ActiveXObject){
	try
	{XMLObj = new ActiveXObject("Msxml2.XMLHTTP")} 
	catch(e){try{XMLObj = new ActiveXObject("Microsoft.XMLHTTP")}catch (e){}}}
else
{
	return false
}
return XMLObj;
}

function loadAjaxFile(nameFile, nameDiv, callBack, ajaxLoading) {
	var div_pointer = $(nameDiv);
	ajaxLoad(nameFile,div_pointer,callBack, ajaxLoading);
}


var basketTime;
var basketDisplay;

function initAsyncBasket()//init vertical movement, transition... of the minibasket
{
	if($('asyncBasketBox')){
		shop.asyncBasketBox = $('asyncBasketBox');
		shop.asyncBasketBox.transition = new Fx.Tween( shop.asyncBasketBox , 'opacity', {duration:700, transition:new Fx.Transition(Fx.Transitions.linear) } );
		basketDisplay = "none";
	}
}

function showMiniBasket(){
	if(basketDisplay == "none"){
		basketDisplay = "";
		clearTimeout(basketTime);
		shop.asyncBasketBox.transition.start('opacity',0,100);
		shop.asyncBasketBox.style.display = '';
		/*setTimeout("shop.asyncBasketBox.transition.start('opacity',100,0);", 4000);
		setTimeout("shop.asyncBasketBox.style.display = 'none';", 4700);*/
		basketTime = setTimeout("hideAsyncBasketInShow()", 4000);
	}
}

function hideAsyncBasketInShow()
{
	if(basketDisplay == ""){
		basketDisplay = "none";
		shop.asyncBasketBox.transition.start('opacity',1,0);
	}
}


function hideAsyncBasket()
{
	if(basketDisplay == ""){
		basketDisplay = "none";
		clearTimeout(basketTime);
		shop.asyncBasketBox.transition.start('opacity',1,0);
	}
}

$(window).addEvent('click', function(){ hideAsyncBasket(); } );

function loadContent(nameFile, nameDiv, callBack, ajaxLoading) {
	if(ajaxLoading != "")
		ajaxLoading = "<img src='" + shop.url + "/ecommerce/images/icons/"+ajaxLoading+"'>";
	if($(nameDiv+'Floater'))$(nameDiv+'Floater').style.top = 30+ (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + 'px';
	loadAjaxFile(nameFile, nameDiv, callBack, ajaxLoading);
}

function closeContent(){
	$('informationBox').innerHTML = '';
	$('informationBox').style.visibility = 'hidden';
}

function submitForm(form, divId, callBack, imageLoading){
	if(imageLoading)
			document.getElementById(divId).innerHTML = "<img src='" + shop.url + "/ecommerce/images/icons/"+imageLoading+"'>";
	Spry.Utils.submitForm(form, function(req){document.getElementById(divId).innerHTML = req.xhRequest.responseText; eval(callBack);} );
}

function initScrollCategoriesLook(step){
	var divId = "indexCategoriesLookContent";
	getWidth(divId);
	interval_IDCategoriesLook = setInterval('startScrollCategoriesLook("'+divId+'",'+step+');',15);
}


function startScrollCategoriesLook(divID, step){
	var the_style = getStyleObject(divID);
	if (the_style)
  {
 		if(the_style.left != "")var current_left = parseInt(the_style.left);
		else var current_left = 0;
		
		var new_left = current_left + step;
		if(step > 0 && current_left < 0 ){ 
			if (document.layers) the_style.left = new_left;
			else the_style.left = new_left + "px";
		} 
		if(step < 0 && current_left >= (-maxWidth + (maxWidthMenuTabs))){
			if (document.layers) the_style.left = new_left;
			else the_style.left = new_left + "px";
		}
  }
}

function stopScrollCategoriesLook(){
	clearInterval(interval_IDCategoriesLook);
}

function loadCategory(obj){
	
	if(obj.value.length)
		window.location.href = obj.value;
}

var menuCategoriesTimeout;
function showSubCategories(categoryId, classDiv){
	contineSubCategoriesInTimeout();
	hideSubCategories();
	
	$('subCategories'+categoryId).className = classDiv;
	$('category'+categoryId).className = 'categoriesMenuActived';
	$('category'+categoryId+'Link').className = 'categoriesMenuActived';
}

function hideSubCategories(){
	$$('.categoryMenuBoxVisibleLeft').each(function(el){el.className = 'categoryMenuBox';});
	$$('.categoryMenuBoxVisibleRight').each(function(el){el.className = 'categoryMenuBox';});
	$$('.categoriesMenuActived').each(function(el){el.className = 'categoriesMenu';});
}

function hideSubCategoriesInTimeout(timeout){
	if(!timeout) timeout = 2000;
	menuCategoriesTimeout = setTimeout('hideSubCategories()', timeout);
}

function contineSubCategoriesInTimeout(){
	clearTimeout(menuCategoriesTimeout);
}

$(window).addEvent('click', function(){contineSubCategoriesInTimeout();hideSubCategoriesInTimeout(1);});


function changeClass(obj, nameClass, nameClass2){
	if(obj.className == nameClass) obj.className = nameClass2;
	else obj.className = nameClass;
}

function restartShadowbox(){
	Shadowbox.setup(); 
}

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject


function cuteAlert(){
	
	this.timeOut = null;
	this.showing = false;
	this.messageQueue = new Array();
	this.addMessage = function(title, content, image, timeout, width, height)
								{
									this.messageQueue.push( {title:title, content:content, image:image, timeout:timeout, width:width, height:height} );
									if(!this.showing)
										this.showMessage();
								}
	this.showMessage = function()
								{
									if(this.messageQueue.length)
									{
										this.showing = true;
										var message = this.messageQueue.shift();
										//document.getElementById('alertTitle').innerHTML = message.title;
										document.getElementById('alertMessage').innerHTML = message.content;
										/*shop.alertBox.transition.start('opacity',0,1);*/
										if(!message.width) message.width = 570;
										if(!message.height) message.height = 93;
										
										Shadowbox.open({
											player:     'html',
											content:    $('alertBox').innerHTML,
											title: 			message.title,
											width:      message.width,
											height: 		message.height
										},
										{
											animate: false,
											onClose: shop.cuteAlert.closeMessage()
										}
										);
										
										if(message.timeout && message.timeout > 0)
										{
											var self = this;
											this.timeOut = setTimeout(function(){ self.closeMessage()}, message.timeout);
										}
										
									}
									else
									{
										this.showing = false;
									}
								}
	this.clear = function()
								{
									this.messageQueue = new Array();
									clearTimeout(this.timeOut);
								}
	this.closeMessage = function()
								{
									clearTimeout(this.timeOut);
									shop.alertBox.transition.start('opacity',1,0);
									var self = this;
									setTimeout(function(){self.showMessage();},700);
								}
};

function cuteQuestion(){
	
	this.timeOut = null;
	this.showing = false;
	this.messageQueue = new Array();
	this.addMessage = function(title, content, textButtonOK, textButtonKO, positionOK, actionNameOK, actionForm, image, timeout)
								{
									this.messageQueue.push( {title:title, content:content, textButtonOK:textButtonOK, textButtonKO:textButtonKO, positionOK:positionOK, actionNameOK:actionNameOK, actionForm:actionForm, image:image, timeout:timeout} );
									if(!this.showing)
										this.showMessage();
								}
	this.showMessage = function()
								{
									if(this.messageQueue.length)
									{
										
										this.showing = true;
										var message = this.messageQueue.shift();
										positionOK = message.positionOK;
										if(positionOK == 1)positionKO = 2;
										else positionKO = 1;

										document.getElementById('questionMessage').innerHTML = message.content;
										document.getElementById('questionForm'+positionOK).action = message.actionForm;
										
										document.getElementById('questionForm'+positionKO).action = "javascript:Shadowbox.close();";
										
										document.getElementById('buttonQuestion'+positionOK).value = message.textButtonOK;
										document.getElementById('buttonQuestion'+positionOK).className = "submitOK";
										document.getElementById('formActionName'+positionOK).value = message.actionNameOK;
										
										document.getElementById('buttonQuestion'+positionKO).value = message.textButtonKO;
										document.getElementById('buttonQuestion'+positionKO).className = "submitKO";
										
										
										Shadowbox.open({
											player:     'html',
											content:    $('questionBox').innerHTML,
											title: 			message.title,
											width:      350,
											height: 		90
										},
										{
											animate: false,
											onClose: shop.cuteQuestion.closeMessage()
										}
										);
										
										if(message.timeout && message.timeout > 0)
										{
											var self = this;
											this.timeOut = setTimeout(function(){ self.closeMessage()}, message.timeout);
										}
										
									}
									else
									{
										this.showing = false;
									}
								}
	this.clear = function()
								{
									this.messageQueue = new Array();
									clearTimeout(this.timeOut);
								}
	this.closeMessage = function()
								{
									clearTimeout(this.timeOut);
									shop.questionBox.transition.start('opacity',1,0);
									var self = this;
									setTimeout(function(){self.showMessage();},700);
								}
};

function initAlert()//init vertical movement, transition... of the minibasket
{
	shop.alertDiv = $('alertFloater');
	//shop.basketDiv.movement = new Fx.Tween( shop.basketDiv , 'top', {duration:20, transition:new Fx.Transition(Fx.Transitions.linear) } );
	shop.alertDiv.style.top = '180px';
	
	/*window.addEvent('scroll', function()
										{
												shop.alertDiv.style.top = 180 + document.documentElement.scrollTop + 'px';
												//shop.basketDiv.movement.start('top', parseInt(shop.basketDiv.style.top), 180 + document.documentElement.scrollTop );
										}
	);*/
	
	shop.alertBox = $('alertBox');
	shop.alertBox.transition = new Fx.Tween( shop.alertBox , 'opacity', {duration:700, wait:true , transition:new Fx.Transition(Fx.Transitions.linear) } );
	
	shop.cuteAlert = new cuteAlert();
}

function initBuyForms()
{
	$$('.buyForm').each(
	function(form)
	{
		if($(form.elements['productId'])){
			getStockByCombination(form);
			showPriceByOption(form);
		}
		form.addEvent('submit', function()
			{
				//overwrite form action
				this.action = shop.url + '/ajaxTemplates/products/addProduct.cfm';
				if( Spry.Widget.Form.validate(this) )
				{
					return Spry.Utils.submitForm(this, validateAddProduct);
				}
			}
		);
	}
	);
}


function validateAddProduct(req)
{
	var objResponse = eval('('+req.xhRequest.responseText+')');
	
	if(objResponse.ADDED)//product added
	{
		
		$('loadingImage'+ objResponse.PRODUCTID).destroy();
		$('addProduct'+objResponse.PRODUCTID).style.display = '';
		ajaxLoad(shop.url+ '/ajaxTemplates/basket/miniBasket.cfm', $('minibasket'), '' ,'');
		shop.cuteAlert.addMessage(languageSheet.lblError, languageSheet.lblProductAdded, 0, 0,350,65);
	}
	else
	{
		shop.cuteAlert.addMessage(languageSheet.lblError, languageSheet.lblProductNotAdded, 0, 0,350,65);
	}
	
}

function getStockByCombination(form)
{
	var element;
	var formParams = new Array();
	
	for (var i = 0; i < form.elements.length; i++ )
	{
		element = form.elements[i];
		if( element.getAttribute('affectsstock') && element.getAttribute('affectsstock') == 1 )
		{
		  if( element.tagName.toUpperCase() != 'INPUT' ||element.type.toUpperCase() != 'CHECKBOX' && element.checked == true  )
      	formParams.push(encodeURIComponent(element.name) + '=' + encodeURIComponent(element.value));
		}
		else if(element.name.toUpperCase() == 'PRODUCTID')
		{
			formParams.push(encodeURIComponent(element.name) + '=' + encodeURIComponent(element.value));
			el = document.getElementById('addProduct'+element.value );
			el.style.display = 'none';
			var loadingImage = document.createElement('img');
			loadingImage.src = shop.url + '/ecommerce/images/icons/smallLoading.gif';
			loadingImage.id = 'loadingImage' + element.value;
			el.parentNode.appendChild(loadingImage);
		}
	}
	formParams = formParams.join("&");
	
	var frmOpts = {};
	frmOpts.method = 'POST';
	frmOpts.url = shop.url + '/ajaxTemplates/products/checkStockByCombination.cfm';
	frmOpts.headers = {};
	frmOpts.headers['Content-Type'] = 'application/x-www-form-urlencoded';
	frmOpts.postData = formParams;
	
	Spry.Utils.loadURL('post', frmOpts.url, true, setStockByCombination, frmOpts);
}
function setStockByCombination(response)
{
	var objResponse = eval('(' + response.xhRequest.responseText + ')');
	var productId = parseInt(objResponse.PRODUCTID);
	var buyButton = document.getElementById('addProduct'+productId );
	var stock = parseInt(objResponse.STOCK);
	
	if( stock == 0 )
	{
		//no stock
		if(objResponse.ALLOWRESERVE)
		{
			//allow reserve
			if(buyButton.className != "prodDetailBuyButton")
				buyButton.value = languageSheet.lblReserve;
			buyButton.disabled = false;
		}
		else
		{
			//disallow buy
			if(buyButton.className != "prodDetailBuyButton")
				buyButton.value = languageSheet.lblInexistentCombination;
			buyButton.disabled = true;
		}
	}
	else if( stock == -1 )
	{
		//disallow buy
		if(buyButton.className != "prodDetailBuyButton")
			buyButton.value = languageSheet.lblInexistentCombination;
		buyButton.disabled = true;
	}
	else
	{
		//stock available	
		if(buyButton.className != "prodDetailBuyButton")
			buyButton.value = languageSheet.lblBuy;
		buyButton.disabled = false;
	}
	
	$('loadingImage' + productId).destroy();
	buyButton.style.display = '';
}

function initFormFields(form)
{
	if(typeof form == "string")var form = document.getElementById(form);
	
	Spry.Widget.Form.destroy(form);

	for (var i = 0; i < form.elements.length; i++ )
	{
			element = form.elements[i];
			
			fieldType = element.getAttribute('fieldType');
			requiredField = element.getAttribute('requiredField');
			
			if( element.getAttribute('affectsstock') == 1 )
			{
				$(element).addEvent('change', function(){ getStockByCombination(form); } );
			}
			
			if(fieldType)
			{
				try
				{
					if(requiredField == 1)
						required = true;
					else
						required = false;
				}
				catch(err){ required = false }
				
				switch(fieldType)
				{
					case 'natural':
						
						element.validate = new Spry.Widget.ValidationTextField(element, "integer", { isRequired:required, validateOn:['blur'], minValue:0 } );
						break;
						
					case 'integer':
						
						element.validate = new Spry.Widget.ValidationTextField(element, "integer", { isRequired:required, validateOn:['blur'] } );
						break;
					
					case 'float':	
					
						element.validate = new Spry.Widget.ValidationTextField(element, "real", { isRequired:required,validateOn:['blur'] } );
						break;
					
					case 'email':	
					
						element.validate = new Spry.Widget.ValidationTextField(element, "email", { isRequired:required,validateOn:["blur"] });
						break;
					
					case 'time':	
					
						element.validate = new Spry.Widget.ValidationTextField(element, "time", { isRequired:required, validateOn:['blur'] , useCharacterMasking:true , format:formats.timeFormat } );
						break;
					
					case 'date':	
					
						element.validate = new Spry.Widget.ValidationTextField(element, "date", { isRequired:required, useCharacterMasking:true, format:formats.dateFormat, hint:formats.dateFormat, validateOn:["blur"]} );
						Calendar.setup({inputField:element, button:element, formats:formats.dateFormat});
						
						break;
						
					case 'phone':	
					
						//element.validate = new Spry.Widget.ValidationTextField(element, "phone_number", { isRequired:required, validateOn:["blur"],format:"phone_custom" , pattern:"000000000"});
						element.validate = new Spry.Widget.ValidationTextField(element, "integer", { isRequired:required, validateOn:["blur"], allowNegative:false, minValue:10000000 });
						break;
					
					case 'url':	
					
						element.validate = new Spry.Widget.ValidationTextField(element, "url", { isRequired:required, validateOn:["blur"]});
						break;
					
					case 'creditcard':
					
						element.validate = new Spry.Widget.ValidationTextField(element, "zip_code", { isRequired:required, useCharacterMasking:true, pattern:'0000-0000-0000-0000' , validateOn:['blur'] } );
						break;
					
					case 'ip':	
					
						element.validate = new Spry.Widget.ValidationTextField(element, "ip", { isRequired:required, validateOn:['blur'] } );
						break;
						
					case 'shortmemo':	
					
						element.validate = new Spry.Widget.ValidationTextarea(element, { isRequired:required, validateOn:['blur'] } );
						break;
						
					case 'checkbox':
      
						var container = element.getAttribute('fieldContainerId')
						if( container )
						 container = $(container);
						else
						 container = $(element);
						
						new Spry.Widget.ValidationCheckbox(container,{isRequired:required});
						break;
					
					case 'checkbox_group':
      
						var container = element.getAttribute('fieldContainerId')

						var minSelections = element.getAttribute('minSelections')
						if( container )
						 container = $(container);
						else
						 container = $(element);
						
						new Spry.Widget.ValidationCheckbox(container,{isRequired:required, minSelections:minSelections});
						break;
						
					case 'radio':
      
						var container = element.getAttribute('fieldContainerId')
						if( container )
						 container = $(container);
						else
						 container = $(element);
						 
 						new Spry.Widget.ValidationRadio(container,{isRequired:required, validateOn:["blur", "change"]});
						break;
					/*case 'longmemo':	
					
						element.validate = new Spry.Widget.ValidationTextarea(element, { isRequired:required, validateOn:['blur'] } );
						break;*/
						
					default:
					
						element.validate = new Spry.Widget.ValidationTextField(element, "none", { isRequired:required, validateOn:['blur'] } );
						break;
					
				}
			}
			
	}
}

function initQuestion(){
	shop.questionBox = $('questionBox');
	shop.questionBox.transition = new Fx.Tween( shop.questionBox , 'opacity', {duration:700, wait:true , transition:new Fx.Transition(Fx.Transitions.linear) } );
	
	shop.cuteQuestion = new cuteQuestion();
}

function sameHeightMain(){
	var heightCenter = $('mainCenterContent').offsetHeight + $('mainMiddleContentInfo').offsetHeight;
	if(heightCenter > $('tableCategoriesMenu').offsetHeight && heightCenter > ($('colRightContent').offsetHeight)){
		$('tableCategoriesMenu').style.height = heightCenter + 'px';
	}
	if(heightCenter < ($('colRightContent').offsetHeight + $('colRightContent').offsetTop)){
		$('tableCategoriesMenu').style.height = ($('colRightContent').offsetHeight + $('colRightContent').offsetTop) + 'px';
		//$('mainMiddleContentInfo').style.height = ($('colRightContent').offsetHeight + $('colRightContent').offsetTop) + 'px';
	}
	if($('tableCategoriesMenu').offsetHeight > ($('colRightContent').offsetHeight + $('colRightContent').offsetTop)){
		$('colRightContent').style.height = ($('tableCategoriesMenu').offsetHeight - $('colRightContent').offsetTop)  + 'px';
	}
}

function initShop()
{
	sameHeightMain();
	
	initBuyForms();
	initAsyncBasket();
	initAlert();
	initQuestion();
	//initPlugins();
	//initCheckout();
	if($('miniSearchForm'))initFormFields("miniSearchForm");
	if($('newsletterForm'))initFormFields('newsletterForm');
}

//THIS FILE CONTAINS SHOPS OWN PLUGINS AND FUNCTIONS. INITPLUGINS FUNCTION IS CALLED ON SOURCE LOADED

function initPlugins()
{

}

var interval_ID;
var maxWidth;
var maxWidthMenuTabs;

var interval_IDVertical;
var maxHeight;
var maxHeightMenuTabs;

var intervals_IDVertical = new Array();
var arrMaxHeight = new Array();
var arrMaxHeightMenuTabs = new Array();

var intervals_ID = new Array();
var arrMaxWidth = new Array();
var arrMaxWidthMenuTabs = new Array();


function getWidth(id){
	if(id){
		if(document.getElementById("menuTabsTable"+id)){ arrMaxWidth[id] = document.getElementById("menuTabsTable"+id).offsetWidth;}
		if(document.getElementById("menuTabs"+id)) { arrMaxWidthMenuTabs[id] = document.getElementById("menuTabs"+id).style.width; arrMaxWidthMenuTabs[id] = parseInt(arrMaxWidthMenuTabs[id].replace("px", ""));	}
	}
	else{
		if(document.getElementById("menuTabsTable")){ maxWidth = document.getElementById("menuTabsTable").offsetWidth;}
		if(document.getElementById("menuTabs")) { maxWidthMenuTabs = document.getElementById("menuTabs").style.width;	maxWidthMenuTabs = parseInt(maxWidthMenuTabs.replace("px", ""));}
	}
}

function getHeight(id){
	if(id){
		if(document.getElementById("menuTabsTableVertical"+id)){ arrMaxHeight[id] = document.getElementById("menuTabsTableVertical"+id).offsetHeight;}
		if(document.getElementById("menuTabsVertical"+id)) { arrMaxHeightMenuTabs[id] = document.getElementById("menuTabsVertical"+id).style.height; arrMaxHeightMenuTabs[id] = parseInt(arrMaxHeightMenuTabs[id].replace("px", ""));}
	}
	else{
		if(document.getElementById("menuTabsTableVertical")){ maxHeight = document.getElementById("menuTabsTableVertical").offsetHeight;}
		if(document.getElementById("menuTabsVertical")) { maxHeightMenuTabs = document.getElementById("menuTabsVertical").style.height; maxHeightMenuTabs = parseInt(maxHeightMenuTabs.replace("px", ""));}
	}
}


function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject



function startMenu(step, id)
{
	var divId = "menuTabs";
	if(id){
		divId = divId +id;
		intervals_ID[id] = setInterval('moveDiv("'+divId+'",'+step+',\''+id+'\');',15);
	}
	else{
		interval_ID = setInterval('moveDiv("'+divId+'",'+step+');',15);
	}
}

function startMenuVertical(step, id)
{
	var divId = "menuTabsVertical";
	if(id){
		divId = divId +id; 
		intervals_IDVertical[id] = setInterval('moveDivVertical("'+divId+'",'+step+',\''+id+'\');',15);
	}
	else{
		interval_IDVertical = setInterval('moveDivVertical("'+divId+'",'+step+');',15);
	}
}

function moveDiv(divID,step, id)
{
  // get the stylesheet
  //
	if(id){ getWidth(id);}
	else getWidth();
  var the_style = getStyleObject(divID);

  if (the_style)
  {
    // get the current coordinate and add 5
    //
    var current_left = parseInt(the_style.left);
		var new_left = current_left + step;

    // set the left property of the DIV, add px at the
    // end unless this is NN4
    //
		if(step > 0 && current_left < 0 ){
			
			if (document.layers)  
			{
				the_style.left = new_left;
			}
			else 
			{  
				the_style.left = new_left + "px";
			}
		}
		if(id){
			if(step < 0 && current_left >= (-arrMaxWidth[id] + arrMaxWidthMenuTabs[id])){
				if (document.layers) 
				{
					the_style.left = new_left;
				}
				else 
				{  
					the_style.left = new_left + "px";
				}
			}
		}
		else{
			 if(step < 0 && current_left >= (-maxWidth + maxWidthMenuTabs)){
				if (document.layers) 
				{
					the_style.left = new_left;
				}
				else 
				{  
					the_style.left = new_left + "px";
				}
			}
		}
		
  }
}

function moveDivVertical(divID,step, id)
{
  // get the stylesheet
  //
 	if(id){ getHeight(id);}
	else getHeight();
  var the_style = getStyleObject(divID);
	if (the_style)
  {
    // get the current coordinate and add 5
    //
		if(the_style.top != "")
	    var current_top = parseInt(the_style.top);
		else
			var current_top = 0;
		
	var new_top = current_top + step;

    // set the left property of the DIV, add px at the
    // end unless this is NN4
    //
		if(step > 0 && current_top < 0 ){ 
			if (document.layers) 
			{
				the_style.top = new_top;
			}
			else 
			{  
				the_style.top = new_top + "px";
			}
		} 
		if(id){
			if(step < 0 && current_top >= (-arrMaxHeight[id] + (arrMaxHeightMenuTabs[id]))){
				if (document.layers) 
				{
					the_style.top = new_top;
				}
				else 
				{  
					the_style.top = new_top + "px";
				}
			}
		}
		else{
			if(step < 0 && current_top >= (-maxHeight + (maxHeightMenuTabs))){
				if (document.layers) 
				{
					the_style.top = new_top;
				}
				else 
				{  
					the_style.top = new_top + "px";
				}
			}
		}
  }
}

function stopMenu(id){
	if(id) clearInterval(intervals_ID[id]);	
	else clearInterval(interval_ID);
}

function stopMenuVertical(id)
{
	if(id) clearInterval(intervals_IDVertical[id]);
	else clearInterval(interval_IDVertical);
}

function validateAccount(req) //gets the response of the customer form and sends an error message or calls next screen.
{
	var objResponse = eval('(' + req.xhRequest.responseText + ')');
	
	if( objResponse.ERROR )
		{
			switch (objResponse.ERROR)
			{
				case 'TLG1000':
				case 'TLG1001':
					shop.cuteAlert.addMessage(languageSheet.lblError, languageSheet.lblUserNotFound,0,0,350,63);
					break;
				case 'TLG1002':
					shop.cuteAlert.addMessage(languageSheet.lblError, languageSheet.lblDifferentPassword,0,0,350,63);
					break;
				case 'TLG1003':
					shop.cuteAlert.addMessage(languageSheet.lblError, languageSheet.lblEmailInUse,0,0,350,63);
					break;
				case 'TLG1004':
					shop.cuteAlert.addMessage(languageSheet.lblError, languageSheet.lblDifferentEmail,0,0,350,63);
					break;
			}
		}
	else
		{
			if( objResponse.ACTION == 'login' )
			{
				location.reload();
				//loadNextCheckoutScreen(1, shop.url+'/ajaxTemplates/shippingZone.cfm' , $('shippingMethodBox') );
			}
			else if( objResponse.ACTION == 'update' && window.location.href.search('users/user.cfm') != -1 ){
				window.location.href = shop.url + '/ecommerce/users/user.cfm';
			}
			else if( objResponse.ACTION == 'signIn' )
			{
				window.location.href = shop.url + '/ecommerce/checkout/checkout.cfm?action=signIn';
				/*$('loadingImage').destroy();
				if($('submitUserCheckoutForm'))$('submitUserCheckoutForm').style.display = '';
				loadNextCheckoutScreen(1, shop.url+'/ajaxTemplates/shippingZone.cfm' , $('shippingMethodBox') );*/
			}
			else
			{
				//$('loadingImage').destroy();
				//if($('submitUserCheckoutForm'))$('submitUserCheckoutForm').style.display = '';
				//loadNextCheckoutScreen(3, shop.url+'/ajaxTemplates/orderConfirm.cfm' , $('orderConfirmationBox') );
				loadNextCheckoutScreen(3, shop.url+'/ajaxTemplates/checkout/orderConfirm.cfm' , $('checkoutDiv'), "if($('userLogin'))$('userLogin').style.display = 'none';" );
			}
		}
}

function loadNextCheckoutScreen(step, path, targetDiv, callBack ){
	
	ajaxLoad(path, targetDiv, "ajaxLoad('"+shop.url+"/ajaxTemplates/checkout/steps.cfm?step="+step+"', $('stepsCheckout'));"+callBack);
}


function validateAccountNewUser(req) //gets the response of the customer form and sends an error message or calls next screen.
{
	
	var objResponse = eval('(' + req.xhRequest.responseText + ')');
	
	if( objResponse.ERROR )
		{
			switch (objResponse.ERROR)
			{
				case 'TLG1000':
				case 'TLG1001':
					shop.cuteAlert.addMessage(languageSheet.lblError, languageSheet.lblUserNotFound,0,0,350,63);
					break;
				case 'TLG1002':
					shop.cuteAlert.addMessage(languageSheet.lblError, languageSheet.lblDifferentPassword,0,0,350,63);
					break;
				case 'TLG1003':
					shop.cuteAlert.addMessage(languageSheet.lblError, languageSheet.lblEmailInUse,0,0,350,63);
					break;
				case 'TLG1004':
					shop.cuteAlert.addMessage(languageSheet.lblError, languageSheet.lblDifferentEmail,0,0,350,63);
					break;
			}
		}
	else{
			//shop.cuteAlert.addMessage(languageSheet.lblDataSavedCorrectly, languageSheet.lblDataSavedCorrectly,0,0);
			if(objResponse.ACTION && objResponse.ACTION == 'signIn')
				window.location = shop.url+'/ecommerce/users/user.cfm?signIn=1';
			else
				window.location = shop.url+'/ecommerce/users/user.cfm';
		}
}

$(window).addEvent('domready', function(){ initShop();} );

/*$(window).addEvent('scroll'), function(){
	if(! $('basketTotals')) return;
	scrollBasketTotals = $('basketTotals');
});*/

//GLOBAL VARIABLES (Some of them are used only to reduce calls to '$ function' to improve javascript performance)
var shop = {};
var ecommerce = location.pathname.split('/');
shop.url = location.protocol +'//'+ location.host;
var mainTargetElement;
//NO MORE VARIABLES

var interval_ID;
var maxHeight = 0;
var maxHeightMenuTabs = 0;
var invertedDirection = 0;

var interval_IDCategoriesLook;
var maxWidth = 0;
var maxWidthMenuTabs = 0;


$(window).addEvent('domready', function(){
	if( document.getElementById('indexLogin') )
		initFormFields('indexLogin');
	if( document.getElementById('indexNewsContent') )
		initScrollNews()
});

function getHeight(id){
	if($(id+'Table')){ 
		maxHeight = $(id+'Table').offsetHeight;
	}
	if($(id)) { 
		maxHeightMenuTabs = $(id).style.height; 
		maxHeightMenuTabs = parseInt(maxHeightMenuTabs.replace("px", ""));
	}
}

function getWidth(id){
	if($(id+'Table')){ 
		maxWidth = $(id+'Table').offsetWidth;
	}
	if($(id)) { 
		maxWidthMenuTabs = $(id).style.width; 
		maxWidthMenuTabs = parseInt(maxWidthMenuTabs.replace("px", ""));
	}
}
	

function initScrollNews(){
	invertedDirection = 0;
	var divId = "indexNewsContent";
	var step = -1;
	getHeight(divId);
	interval_ID = setInterval('startScrollNews("'+divId+'",'+step+');',100);
	/*clearInterval(interval_ID);
	setTimeout('initScrollNews()', 16);
	startScroll(divId,step)*/
}

function startScrollNews(divID, step){
 	var the_style = getStyleObject(divID);
	if (the_style)
  {
 		if(the_style.top != "")var current_top = parseInt(the_style.top);
		else var current_top = 0;

		if(invertedDirection == 0 && (current_top <= (-maxHeight + (maxHeightMenuTabs))))invertedDirection = 1;
		else if(current_top == 0) invertedDirection = 0;
		
		if(invertedDirection)step = -(step);
		else step = +(step);
		
		var new_top = current_top + step;
		
		if(step > 0 && current_top < 0 ){ 
			if (document.layers) the_style.top = new_top;
			else the_style.top = new_top + "px";
		} 
		if(step < 0 && current_top >= (-maxHeight + (maxHeightMenuTabs))){
			if (document.layers) the_style.top = new_top;
			else the_style.top = new_top + "px";
		}
  }
}