this.focus();

function show_flash(id) {
	document.getElementById(id).outerHTML = document.getElementById(id).outerHTML;
}

function printerFriendly(urlToOpen) {
		var x = (screen.width-700)/2, y = (screen.height-600)/2;
	  OpenWin = this.open(urlToOpen, "CtrlWindow", "width=700,height=600,toolbar=no,menubar=yes,location=no,scrollbars=yes,resizable=no, screenX="+x+", screenY="+y+", left="+x+", top="+y);
}

function recommend(urlRecommandForThisArticle) {
		var x = (screen.width-400)/2, y = (screen.height-300)/2;
	  OpenWin = this.open(urlRecommandForThisArticle, "CtrlWindow", "width=400,height=400,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no, screenX="+x+", screenY="+y+", left="+x+", top="+y);
}

function gE(el) {
		return document.getElementById(el);
}

//end browser user
var globalTimeout = "";
function showToolTipFader(texty,obj,doNotCloseAfter) {	
	obj = $(obj);

	if($('tooltipX')) {
		document.body.removeChild($('tooltipX'));		
		window.clearTimeout(globalTimeout);	
	}
	
	var newdiv = document.createElement('div');
	newdiv.id="tooltipX";
	newdiv.style.display = "none";
	
	//generating table inside div
	if(document.all) {
		var tbl = document.createElement('<table cellpadding=0 cellspacing=0 border=0>');	
		var tbb = document.createElement("tbody");	
	} else {
		var tbl = document.createElement('table');		
		var tbb = document.createElement("tbody");	
		
		tbl.setAttribute('cellpadding','0');
		tbl.setAttribute('cellspacing','0');
		tbl.setAttribute('border','0');
	}	
	
	
	// create up arrow td
		var row = document.createElement('tr');
			
			if(document.all)
				var cell = document.createElement('<td colspan=3>');
			else 
				var cell = document.createElement('td');	
			cell.setAttribute('colspan','3');
				//create img
				 var nimg = document.createElement('img');
				 if(document.all)
				 	nimg.src="images/pop-up/sageata_sus.gif";
				 else	
				 	nimg.src="images/pop-up/sageata_sus.png";
				 nimg.className="tooltipUpArrow";	
				 nimg.id = "toolArrowU";
				 			 
			cell.appendChild(nimg);			
		row.appendChild(cell);		
	tbb.appendChild(row);
	//end create up arrow td
		
	//create top tooltip
		var row = document.createElement('tr');
			var cell = document.createElement('td');
			cell.className="tooltipCorner_ul";
		row.appendChild(cell);		
		
		
			var cell = document.createElement('td');
			cell.className="tooltipBar_u";
		row.appendChild(cell);
		
		
			var cell = document.createElement('td');
			cell.className="tooltipCorner_ur";
		row.appendChild(cell);
	tbb.appendChild(row);
	//end create top tooltip
	
	if(doNotCloseAfter) {
		var imgClose = "<img src='images/pop-up/icon-close.gif' style='cursor:pointer;float:right; top:-10px;' onClick=\"hidePopup();\"/><b>Detaliu utilizator</b>";
	//create close tooltip
		var row = document.createElement('tr');
			var cell = document.createElement('td');
			cell.className="tooltipBar_l";
		row.appendChild(cell);
		
			var cell = document.createElement('td');
			cell.className="tooltipText";
			cell.innerHTML=imgClose;
		row.appendChild(cell);
				
			var cell = document.createElement('td');
			cell.className="tooltipBar_r";
		row.appendChild(cell);
	tbb.appendChild(row);	
	//end close tooltip		
	}

	//create middle tooltip
		var row = document.createElement('tr');
			var cell = document.createElement('td');
			cell.className="tooltipBar_l";
		row.appendChild(cell);
		
			var cell = document.createElement('td');
			cell.className="tooltipText";			
			cell.innerHTML=texty;
		row.appendChild(cell);
				
			var cell = document.createElement('td');
			cell.className="tooltipBar_r";
		row.appendChild(cell);
	tbb.appendChild(row);	
	//end middle tooltip	
	
	//create bottom tooltip
		var row = document.createElement('tr');
			var cell = document.createElement('td');
			cell.className="tooltipCorner_bl";
		row.appendChild(cell);		
		
		
			var cell = document.createElement('td');
			cell.className="tooltipBar_b";
		row.appendChild(cell);
		
		
			var cell = document.createElement('td');
			cell.className="tooltipCorner_br";
		row.appendChild(cell);
	tbb.appendChild(row);
	//end create bottom tooltip
	
	// create down arrow td
		var row = document.createElement('tr');
			
			if(document.all)
				var cell = document.createElement('<td colspan=3>');
			else 
				var cell = document.createElement('td');	
			cell.setAttribute('colspan','3');
				//create img
				 var nimg = document.createElement('img');
				 if(document.all)
				 	nimg.src="images/pop-up/sageata_jos.gif";
				 else	
				 	nimg.src="images/pop-up/sageata_jos.png";
				 nimg.className="tooltipDownArrow";	
				 nimg.id = "toolArrowD";
				 			 
			cell.appendChild(nimg);			
		row.appendChild(cell);		
	tbb.appendChild(row);
	//end create down arrow td
	
	tbl.appendChild(tbb);
	newdiv.appendChild(tbl);
	
	newdiv.className ="tooltipDiv";
	
	//add tooltip to document
	document.body.appendChild(newdiv);
	
	//position tooltip
	setPopupPosition(obj,newdiv); 
	
	
	Effect.Appear(newdiv.id,{duration:.2});
	
	//set fade out
	if(!doNotCloseAfter)
		globalTimeout = window.setTimeout('Effect.Fade(\'tooltipX\', {duration:.3,from:1.0, to:0.0})',2500);
	
	//========================================	
}

function setPopupPosition(el, x)  {	
				var direction = "up";
        var position = Position.cumulativeOffset(el);
        var scrollY = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
        var viewHeight = (navigator.userAgent.toLowerCase().indexOf("safari") != -1 && window.innerHeight) ? window.innerHeight : document.documentElement.clientHeight;
       	x.style.left = position[0]-40 + "px";	
        var popupTop = position[1] + Element.getHeight(el);
        if((popupTop + x.offsetHeight > scrollY + viewHeight) && (position[1] - x.offsetHeight > scrollY)) {
            popupTop = position[1] - x.offsetHeight ;
        }
        if(popupTop > (scrollY + Element.getHeight(x) + 40  + Element.getHeight(el))) {
        	direction="down";
        	$('toolArrowD').style.visibility = "visible";
        } else {
        	$('toolArrowU').style.visibility = "visible";        	
        }
        if(direction == "up")
        	x.style.top = (popupTop+30) + "px";
        else 
        	x.style.top = (popupTop - Element.getHeight(x) - (document.all ? 15 : 25) - Element.getHeight(el)) + "px";
}

function hidePopup() {
	if($('tooltipX')) {
		document.body.removeChild($('tooltipX'));		
		window.clearTimeout(globalTimeout);			
	}
	
}

String.prototype.trim = function() { var _ret = this.replace(/^\s+|\s+$/g, ''); return _ret.replace(/^(\&nbsp\;)+|(\&nbsp\;)+$/g, ''); }

function getShoppingCart(pID, packID, spID, q) {
	var shoppingCartBox = $('shoppingCartBox');
	shoppingCartBox.innerHTML = '';
	var loading = $(document.createElement('img'));
	//loading = $(loading);
	loading.setStyle({'padding-top': '10px'});
	loading.src = 'images/SCloader.gif';
	shoppingCartBox.appendChild(loading);
	var params = {'returnXML': 1 };
	if(pID) {
			params.pID = pID;
	}
	if(packID) {
			params.packID = packID;
	}
	if(spID) {
			params.spID = spID;
	}
	if(q) {
			params.quantity = q;
	}
	new Ajax.Request(document.getElementsByTagName('base')[0].href+'index.html/shoppingcart|displayShoppingCart',  {
	    method:'post',
	    parameters: params,
	    onSuccess: function(transport){    	 
	    	var response = transport.responseXML;
	    	displayShoppingCart(response);
	    },
	    onFailure: function(){  }
	  });
}

function displayShoppingCart(rXML) {
	var baseHREF = document.getElementsByTagName('base')[0].href;
	
	var shoppingCartBox = $('shoppingCartBox');
	shoppingCartBox.innerHTML = '';
	
	if(rXML) {
		if(document.all)
			root = rXML.childNodes[1];
		else
			root = rXML.childNodes[0];
		
		var items = $A(root.getElementsByTagName('item'));
		if(items.length) {
				items.each( function(item) {
						var iType = item.getElementsByTagName('type')[0].firstChild.nodeValue;
						var iName = item.getElementsByTagName('name')[0].firstChild.nodeValue;
						var iUnitPrice = item.getElementsByTagName('unitPrice')[0].firstChild.nodeValue;
						var iTotalPrice = item.getElementsByTagName('totalPrice')[0].firstChild.nodeValue;
						var iCurrency = item.getElementsByTagName('currency')[0].firstChild.nodeValue;
						var iQuantity = item.getElementsByTagName('quantity')[0].firstChild.nodeValue;
						
						var fieldset = $(document.createElement('fieldset'));
						fieldset.addClassName('cosCumparaturi');
						
						switch(iType) {
								case	'3':
										var packID = item.getElementsByTagName('packID')[0].firstChild.nodeValue;
										fieldset.id = 'scpack_' + packID;
										var _pImageSrc = item.getElementsByTagName('photoPath');
										if(_pImageSrc.length) {
											var pImageSrc = _pImageSrc[0].firstChild.nodeValue;
											var pImage = $(document.createElement('img'));
											pImage.addClassName('produs');
											pImage.src = pImageSrc;
											fieldset.appendChild(pImage);
										}
										
										var a = $(document.createElement('a'));
										a.addClassName('produs');
										a.href = baseHREF + 'index.html/products|pack?packID=' + packID;
										var aText = document.createTextNode(iName);
										a.appendChild(aText);
										fieldset.appendChild(a);
										
										var unitPriceText = document.createTextNode('Pret: ' + number_format(iUnitPrice, 2, ',', '.') + ' ' + iCurrency);
										fieldset.appendChild(unitPriceText);
										var br = $(document.createElement('br'));
										fieldset.appendChild(br);
										var quantity = document.createTextNode('Cantitate: ' + iQuantity);
										fieldset.appendChild(quantity);
										
										var packItemsDL = $(document.createElement('dl'));
										var product = item.getElementsByTagName('product')[0];
										var productName = document.createTextNode(product.getElementsByTagName('name')[0].firstChild.nodeValue);
										var dt = $(document.createElement('dt'));
										var a = $(document.createElement('a'));
										var pID = product.getElementsByTagName('productID')[0].firstChild.nodeValue;
										a.href = baseHREF + 'index.html/products|details?pID=' + pID;
										a.appendChild(productName);
										dt.appendChild(a);
										packItemsDL.appendChild(dt);
										
										var packAccessories = item.getElementsByTagName('accesories')[0];
										var accesories = $A(packAccessories.getElementsByTagName('accessory'));
										accesories.each(function(accessory){
												var aID = accessory.getElementsByTagName('productID')[0].firstChild.nodeValue;
												var aName = document.createTextNode(accessory.getElementsByTagName('name')[0].firstChild.nodeValue);
												var dd = $(document.createElement('dd'));
												var a = $(document.createElement('a'));
												a.href = baseHREF + 'index.html/products|details?pID=' + aID;
												a.appendChild(aName);
												dd.appendChild(a);
												packItemsDL.appendChild(dd);
										});
										
										fieldset.appendChild(packItemsDL);

										var tEm = $(document.createElement('em'));
										
										var removeImg = $(document.createElement('img'));
										removeImg.src = 'images/butoane/sterge.gif';
										removeImg.addClassName('anuleaza');
										removeImg.alt = 'Anuleaza';
										removeImg.title = 'Anuleaza';
										removeImg.setStyle({'cursor':'pointer'});
										removeImg.onclick = new Function('getShoppingCart( \'\', ' + packID + ', \'\',  -' + iQuantity + ');');
										tEm.appendChild(removeImg);
										
										var subtotalText = document.createTextNode('SUBTOTAL: ');
										tEm.appendChild(subtotalText);
										var subtotal = $(document.createElement('span'));
										subtotal.addClassName('rosu');
										var subTotalPrice = document.createTextNode(number_format(iTotalPrice, 2, ',', '.') + ' ' + iCurrency);
										subtotal.appendChild(subTotalPrice);
										tEm.appendChild(subtotal);
										fieldset.appendChild(tEm);
									break;
								case	'4':
										var pID = item.getElementsByTagName('productID')[0].firstChild.nodeValue;
										fieldset.id = 'scspp_' + pID;
										var _pImageSrc = item.getElementsByTagName('photoPath');
										if(_pImageSrc.length) {
											var pImageSrc = _pImageSrc[0].firstChild.nodeValue;
											var pImage = $(document.createElement('img'));
											pImage.addClassName('produs');
											pImage.src = pImageSrc;
											fieldset.appendChild(pImage);
										}
										
										var originalID = item.getElementsByTagName('originalID')[0].firstChild.nodeValue;
										var a = $(document.createElement('a'));
										a.addClassName('produs');
										a.href = baseHREF + 'index.html/products|details?pID=' + originalID;
										var aText = document.createTextNode(iName);
										a.appendChild(aText);
										fieldset.appendChild(a);
										
										var unitPriceText = document.createTextNode('Pret: ' + number_format(iUnitPrice, 2, ',', '.') + ' ' + iCurrency);
										fieldset.appendChild(unitPriceText);
										var br = $(document.createElement('br'));
										fieldset.appendChild(br);
										var quantity = document.createTextNode('Cantitate: ' + iQuantity);
										fieldset.appendChild(quantity);
										
										
										var tEm = $(document.createElement('em'));
										
										var removeImg = $(document.createElement('img'));
										removeImg.src = 'images/butoane/sterge.gif';
										removeImg.addClassName('anuleaza');
										removeImg.alt = 'Anuleaza';
										removeImg.title = 'Anuleaza';
										removeImg.setStyle({'cursor':'pointer'});
										removeImg.onclick = new Function('getShoppingCart(\'\', \'\', ' + pID + ', -' + iQuantity + ');');
										tEm.appendChild(removeImg);
										
										var subtotalText = document.createTextNode('SUBTOTAL: ');
										tEm.appendChild(subtotalText);
										var subtotal = $(document.createElement('span'));
										subtotal.addClassName('rosu');
										var subTotalPrice = document.createTextNode(number_format(iTotalPrice, 2, ',', '.') + ' ' + iCurrency);
										subtotal.appendChild(subTotalPrice);
										tEm.appendChild(subtotal);
										fieldset.appendChild(tEm);
									break;
								default:
										var pID = item.getElementsByTagName('productID')[0].firstChild.nodeValue;
										fieldset.id = 'scp_' + pID;
										var _pImageSrc = item.getElementsByTagName('photoPath');
										if(_pImageSrc.length) {
											var pImageSrc = _pImageSrc[0].firstChild.nodeValue;
											var pImage = $(document.createElement('img'));
											pImage.addClassName('produs');
											pImage.src = pImageSrc;
											fieldset.appendChild(pImage);
										}
										
										var a = $(document.createElement('a'));
										a.addClassName('produs');
										a.href = baseHREF + 'index.html/products|details?pID=' + pID;
										var aText = document.createTextNode(iName);
										a.appendChild(aText);
										fieldset.appendChild(a);
										
										var unitPriceText = document.createTextNode('Pret: ' + number_format(iUnitPrice, 2, ',', '.') + ' ' + iCurrency);
										fieldset.appendChild(unitPriceText);
										var br = $(document.createElement('br'));
										fieldset.appendChild(br);
										var quantity = document.createTextNode('Cantitate: ' + iQuantity);
										fieldset.appendChild(quantity);
										
										
										var tEm = $(document.createElement('em'));
										
										var removeImg = $(document.createElement('img'));
										removeImg.src = 'images/butoane/sterge.gif';
										removeImg.addClassName('anuleaza');
										removeImg.alt = 'Anuleaza';
										removeImg.title = 'Anuleaza';
										removeImg.setStyle({'cursor':'pointer'});
										removeImg.onclick = new Function('getShoppingCart(' + pID + ', \'\', \'\', -' + iQuantity + ');');
										tEm.appendChild(removeImg);
										
										var subtotalText = document.createTextNode('SUBTOTAL: ');
										tEm.appendChild(subtotalText);
										var subtotal = $(document.createElement('span'));
										subtotal.addClassName('rosu');
										var subTotalPrice = document.createTextNode(number_format(iTotalPrice, 2, ',', '.') + ' ' + iCurrency);
										subtotal.appendChild(subTotalPrice);
										tEm.appendChild(subtotal);
										fieldset.appendChild(tEm);
										
									break;
						}
						
						
						shoppingCartBox.appendChild(fieldset);
				});
			
			var currency = root.getElementsByTagName('currency')[0].firstChild.nodeValue;
			var totalPrice = root.getElementsByTagName('totalPrice')[0].firstChild.nodeValue;
			var count = root.getElementsByTagName('count')[0].firstChild.nodeValue;
			
			var fTotalPrice = $(document.createElement('fieldset'));
			var eTotalPrice = $(document.createElement('em'));
			eTotalPrice.setStyle({'padding':'0px'});
			tTotalPrice = document.createTextNode('TOTAL: ');
			eTotalPrice.appendChild(tTotalPrice);
			var sTotalPrice = $(document.createElement('span'));
			sTotalPrice.addClassName('rosu');
			var totalPriceText = document.createTextNode(number_format(totalPrice, 2, ',', '.') + ' ' + currency);
			sTotalPrice.appendChild(totalPriceText);
			eTotalPrice.appendChild(sTotalPrice);
			
			fTotalPrice.appendChild(eTotalPrice);
			shoppingCartBox.appendChild(fTotalPrice);
			var gotoSC = $(document.createElement('img'));
			gotoSC.src = 'images/butoane/mergi_la_casa.gif';
			gotoSC.alt = 'Mergi la casa';
			gotoSC.title = 'Mergi la casa';
			gotoSC.setStyle({'margin':'-2px 0px 0px 7px', 'cursor':'pointer'});
			gotoSC.onclick = new Function("window.location = '" + baseHREF + "/index.html/shoppingcart'");
			shoppingCartBox.appendChild(gotoSC);
			
		} else {
				var emptySC = $(document.createElement('img'));
				emptySC.src = 'images/icons/cos_gol.gif';
				emptySC.alt = 'Momentan cosul dvs. de cumparaturi este gol!';
				emptySC.setStyle({'margin':'20px 0px 0px 0px'});
				shoppingCartBox.appendChild(emptySC);
		}
		
	}
}

function number_format(a, b, c, d) {
 a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
 e = a + '';
 f = e.split('.');
 if (!f[0]) {
  f[0] = '0';
 }
 if (!f[1]) {
  f[1] = '';
 }
 if (f[1].length < b) {
  g = f[1];
  for (i=f[1].length + 1; i <= b; i++) {
   g += '0';
  }
  f[1] = g;
 }
 if(d != '' && f[0].length > 3) {
  h = f[0];
  f[0] = '';
  for(j = 3; j < h.length; j+=3) {
   i = h.slice(h.length - j, h.length - j + 3);
   f[0] = d + i +  f[0] + '';
  }
  j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
  f[0] = j + f[0];
 }
 c = (b <= 0) ? '' : c;
 return f[0] + c + f[1];
}



function addProductToCart(pID, imgSrc, source, noResize) {
		source = $(source);
		if($('floatingDiv')) {
			return false;
		} else {
			if(imgSrc) {
					source.src = imgSrc;
					var floatingDiv = $(document.createElement('div'));
					floatingDiv.id = 'floatingDiv';
					var img = $(document.createElement('img'));
					img.src = imgSrc;
					floatingDiv.appendChild(img);
					var mainPhotoPos = Position.cumulativeOffset(source);
					floatingDiv.setStyle({'position': 'absolute', 'top': mainPhotoPos[1] + 'px', 'left': mainPhotoPos[0] + 'px'});
					document.body.appendChild(floatingDiv);
					var flyTarget = 'shoppingCartBox';
					if($('scp_' + pID)) flyTarget = 'scp_' + pID;
					fly(floatingDiv, flyTarget, noResize);
			}
			getShoppingCart(pID, '', '', 1);
		}
}

function addPackToCart(packID, imgSrc, source, noResize) {
		source = $(source);
		if($('floatingDiv')) {
			return false;
		} else {
			if(imgSrc) {
					source.src = imgSrc;
					var floatingDiv = $(document.createElement('div'));
					floatingDiv.id = 'floatingDiv';
					var img = $(document.createElement('img'));
					img.src = imgSrc;
					floatingDiv.appendChild(img);
					var mainPhotoPos = Position.cumulativeOffset(source);
					floatingDiv.setStyle({'position': 'absolute', 'top': mainPhotoPos[1] + 'px', 'left': mainPhotoPos[0] + 'px'});
					document.body.appendChild(floatingDiv);
					var flyTarget = 'shoppingCartBox';
					if($('scpack_' + packID)) flyTarget = 'scpack_' + packID;
					fly(floatingDiv, flyTarget, noResize);
			}
			getShoppingCart('', packID, '', 1);
		}
}

function fly(elID, target, noResize) {
		elID = $(elID)
		var scPosition = Position.cumulativeOffset($(target));
		new Effect.Move (elID,{ x: scPosition[0], y: scPosition[1], mode: 'absolute', transition: Effect.Transitions.sinoidal});
		if(!noResize)
			new Effect.Scale(elID.firstDescendant(), 20);
		setTimeout('document.body.removeChild($(\'' + elID.id + '\'))', 1000);
}

//COOKIES
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {		
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) 
			return c.substring(nameEQ.length,c.length);
	}
	return '';
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function checkFeedBack(){
		var fEmail = $('fEmail').value;
		var fMessage = $('fMessage').value;
//		alert(fMessage);
		var baseHref = document.getElementsByTagName('base')[0].href;
		var strError = ''; iType = '';
		if(fEmail.length < 6 || fEmail.indexOf('@') == -1 || fEmail.indexOf('.') == -1){
			strError = 'Emailul introdus este invalid';
			iType = 'fEmail';
		}
		
		if(!strError && fMessage < 3){
			strError = 'Mesajul introdus trebuie sa aiba minim 3 caractere';
			var iType = 'fMessage';
		}
		
		if(!strError)
			new Ajax.Request(baseHref+'index.html/articles|feedback',  {
		    method:'post',    
		    parameters: {'email' : fEmail,  'message' : fMessage},
		    onSuccess: function(transport){
		    		var response = transport.responseText;
		    		Effect.Fade($('feedbackBox'), { 'queue': 'start' });
		    		divTag = new Element('div', { 'id':'feedbackSysMsg', 'class':'errorDiv', 'style':'display:none;'}).update(response);
		    		$('dreapta').insert(divTag);
		    		Effect.Appear($('feedbackSysMsg'), { 'queue': 'end'});
		    },
		    onFailure: function(){  }
		  });	
		else
			showToolTipFader(strError, $(iType));
	}

function newsletterSubscribe() {
		var iEmail = $('email').value;
		var iName = $('name').value;
		var baseHref = document.getElementsByTagName('base')[0].href;
		
		new Ajax.Request(baseHref+'index.html/mainpage|AJAXnewsletterSubscribe',  {
		    method:'post',
		    parameters: {'iEmail' : 'email',  'iEmailValue' : iEmail, 'iName' : 'name',  'iNameValue' : iName},
		    onSuccess: function(transport){
						//alert(transport.responseText);
		    		var response = transport.responseXML;
		    		var status = response.childNodes[0].childNodes[0].firstChild.nodeValue;
		    		var iError = response.childNodes[0].childNodes[1].firstChild.nodeValue;
		    			    		
						if(status == 'true') {
							$('newsletterTeaser').style.color = '#6FAB04';
							$('newsletterTeaser').style.fontWeight = 'bold';
							$('newsletterTeaser').innerHTML = iError;
							$('newsletterFieldsContainer').remove();
							$('newsletterSubscribeBtn').remove();
							
							// $('email').value= 'adresa ta de email...';
							// $('name').value= 'numele si prenumele tau...';
							// $('county').value= '';
						}	else {						
							$('newsletterTeaser').innerHTML = '';
							$('newsletterTeaser').style.color = '#AA0000';
							$('newsletterTeaser').style.fontWeight = 'bold';
							$('newsletterTeaser').innerHTML = iError;
						}		
		    },
		    onFailure: function(){  }
		  });
}


function loadConfigurator(){
	var ahrefs = $('pasiconfigurator').select('a');
	
	ahrefs.each(function(item){		
			item.onclick = function(){
				if(item.hasClassName('activ'))	
					loadHttpRequest(item);
				return false;
			};	
	});
	
	loadHttpRequest(ahrefs[0]);
}


configurationParameters = {};

function loadHttpRequest(ahrefEl){
	new Ajax.Updater(
	'scenaConfigurator',
	ahrefEl.getAttribute('href'), 
		{	
		parameters : configurationParameters,
		'evalScripts': true,
		'onComplete' : function(){
			var ahrefs = $('pasiconfigurator').select('a');
			var bFound = false;
			
			ahrefs.each(function(item){
				if(bFound){
					item.removeClassName('activ');
					configurationParameters[item.rel] = '';
				}
				if(ahrefEl.rel == item.rel)
					bFound = true;
			});
			loadShortSummary(ahrefEl.getAttribute('href'));
		}
	});
}


function submitConfiguration(){
	
	var oConfiguratorFrm = $(document.configuratorFrm).serialize({'hash': true});
	configurationParameters = Object.extend(configurationParameters, oConfiguratorFrm);
	
	var ahrefs = $('pasiconfigurator').select('a');
	
	ahrefs.each(function(item){
		if(!item.hasClassName('activ')){
		item.addClassName('activ');
		loadHttpRequest(item);
		throw $break;
		}
	});
}

function loadShortSummary(action){
	var baseHref = document.getElementsByTagName('base')[0].href;
	var optionalConfigurationParameters = configurationParameters;
	
	if((action.indexOf('loadSummary') !=-1))
		optionalConfigurationParameters.thisIsSummary = 1;
	else
		optionalConfigurationParameters.thisIsSummary = 0;
	
	new Ajax.Updater(
	'scenaRezumat',
	baseHref + 'index.html/ajaxgate|loadShortSummary', 
		{	
		parameters : optionalConfigurationParameters,
		'evalScripts': true,
		'onComplete' : function(){
		}
	});
}


function showNewsletterInfo(triggerEl){
	var div = new Element('div', {'id':'newsletterInfo', 'style':'position:absolute;background:#ffffff; border:1px solid #D85A7B; padding:10px;z-index:100;'});
	$('header').insert(div);
	$(div).clonePosition($(triggerEl), {'offsetTop':23,'offsetLeft':-125, 'setWidth':false, 'setHeight': false});
	var baseHref = document.getElementsByTagName('base')[0].href;
	new Ajax.Updater(
	$(div),
	baseHref + 'index.html/ajaxgate|nlSubscribe', 
		{	
		'evalScripts': true,
		'onComplete' : function(){
		}
	});
}

function reverseConfiguration(){
	var ahrefs = $('pasiconfigurator').select('a');
	var nextItem = {};
	ahrefs.each(function(item){
		if(!item.hasClassName('activ')){
		nextItem = item;
		throw $break;
		}
	});
	previousItem = nextItem.up().previous().previous().firstDescendant();
	loadHttpRequest(previousItem);
	
	// console.log(nextItem.up().previous().previous().firstDescendant());
	// console.log(nextItem.up().previous(2).firstDescendant());
	
}
