function showFaq()
{
	var accordion = new Accordion('p.faqp', 'p.faqo', {
		opacity: false,
		onActive: function(toggler, element){
			toggler.setStyle('color', '#ff3300');
		},
	 
		onBackground: function(toggler, element){
			toggler.setStyle('color', '#222');
		}
	}, $('faq'));
}

function toggleArrow(ele)
{
	if($(ele).className=='downtlo show')
		$(ele).className='downtlo hide';
	else
		$(ele).className='downtlo show';
}

function disableInputs(id)
{
	$(id).getElements('input').each(
		function(element,index)
		{
			if(element.getAttribute('disabled'))
			{
				element.removeAttribute('disabled');
				element.setStyle('background-color','rgb(255, 255, 255)');
			}
			else
			{
				element.setAttribute('disabled','disabled');
				element.setStyle('background-color','rgb(239, 239, 239)');
				element.value = '';
			}
		}
	)
}

function doUknow()
{
	var url = abs_path+'Home/sTxt/';
	new Ajax(url, {	method: 'get',	update: $('cwz')}).request()
}

function recShow()
{
	var url = abs_path+'Home/getRecommended/';
	new Ajax(url, {	method: 'get',	update: $('rec')}).request()
}

function recShow1()
{
	var url = abs_path+'Home/getRecommended/?id=1';
	new Ajax(url, {	method: 'get',	update: $('rec')}).request()
}

function imageShow()
{
	 var postString = "id=" + curr_img_show_folder;

			// set some parameters for the ajax request...
			var myAjax = new Ajax(abs_path+'Home/imageShow/', {
				method: 'post',
				data: postString,
				update: $('output1'),
				onComplete: function(req){
					$('imgshow').innerHTML = req;
                    FadeIn();
				}
			}).request(); // ...and automatically make the ajax request
	(curr_img_show_folder==8)?curr_img_show_folder=0:curr_img_show_folder++;	
}

function FadeIn()
{

var exampleFx = new Fx.Style('pic', 'opacity', {
	duration: 3500,
	transition: Fx.Transitions.Quart.easeOut
});
$('pic').style.display ='';
exampleFx.start(0.1,1); /*fade it in*/

}


/*
	quantity - number of meters, must be >=1
	form_id - id of the form from which we take quantity
	price - price of first meter
	price2 - price of every meter above 1
	price_id - id of td which will be updated with new price
	price_b_id - id of td which will be updated with new gross price
*/
function updatePrice(quantity,form_id,price,price2,price_id,price_b_id)
{
	//removing non-number chars from string
	itemNumber = itemNumber2Number(quantity,'yes','no');
	
	var itemNumberNumeric=itemNumber.toFloat().round(2);
	if(itemNumberNumeric<1) 
	{
		itemNumberNumeric = 1;
		netPrice = price;
		grossPrice = price*1.22;
	}
	else	
	{
		//if price2 > 0 then we use price for meters above 1 
		if(price2>0)
			netPrice= price+ (itemNumberNumeric-1)*price2;
		else
			netPrice = price * itemNumberNumeric;
		
		grossPrice = netPrice * 1.22;
	}
	
	if(itemNumber)
	{
		netPrice = priceFormat(netPrice);
		grossPrice = priceFormat(grossPrice);
		$(price_id).innerHTML=netPrice;
		$(price_b_id).innerHTML=grossPrice;
	}
	
	//changing item number for correct format and showing it on page
	itemNumber = itemNumberFormat(itemNumber);
	$(form_id).getElement('input').value = itemNumber;
}


/*
	quantity - number of items, must by >= 1
	input_id - id of input from wich we take quantity
	price - price of item
	price_id - id of td which will be updated with new price
	price_b_id - id of td which will be updated with new gross price
	item_nr - number of item
*/

function updateQuantity(quantity,input_id,price,price_id,price_b_id,item_nr)
{
	//removing non-number chars from string
	itemNumber = itemNumber2Number(quantity,'no','yes');
	
	var itemNumberNumeric=itemNumber.toFloat().round(2);
	
	if(isNaN(itemNumberNumeric))itemNumberNumeric=1;
	
	
	netPrice = price.replace(',','.').toFloat().round(2)*itemNumberNumeric;
	grossPrice = netPrice * 1.22;
	
	
	netPrice = priceFormat(netPrice);
	grossPrice = priceFormat(grossPrice);
	
	//changing item number for correct format and showing it on page
	itemNumber = itemNumberFormat(itemNumber);
	
	$(price_id).innerHTML=netPrice;
	$(price_b_id).innerHTML=grossPrice;
	
	$(input_id).value = itemNumber;
	Cookie.set(item_nr,itemNumberNumeric,{duration:0.02});
	//removeCookies();
	updateSum();
}
function removeCookies()
{
	jj='';
	i=0;
	temp=document.cookie.split(';');
	for(i=0;i<temp.length;i++)
	{
		if(temp[i].test('nr'))
		{
			tempp=temp[i].split('=');
			temppp=tempp[0].toString();
			Cookie.remove(temppp);
			jj+=Cookie.get(temppp);
		}
	}
	//$('jstest').innerHTML=jj;
}
function updateSum()
{
	var netSum = 0;
	var grossSum = 0;
	$('order_preview').getElementsByClassName('netPrice').each(
		function(element,index)
		{
			netSum+=element.innerHTML.replace(',','.').toFloat().round(2);
		}
	)
	
	grossSum = netSum * 1.22;
	netSum = priceFormat(netSum);
	grossSum = priceFormat(grossSum);
	Cookie.set('netSum',netSum,{duration:0.02});
	Cookie.set('grossSum',grossSum,{duration:0.02});
	//$('netSum').innerHTML = netSum;
	$('grossSum').innerHTML = grossSum;
}

function itemNumber2Number(quantity,doDot,doOne)
{
	//removing non-number chars from string
	var itemNumber = transform2number(quantity,doDot);
	
	
	//making sure that quantity is >= 1
	// first if the quantinty start with '.' or ',' we change it to "1" (string)
	if(doOne=='yes'){
		if(itemNumber.charAt(0)=='.' || itemNumber.charAt(0)==',' || itemNumber.charAt(0)=='0')
			itemNumber = "1";
	}
	
	//transforming ',' into '.' for calculations
	itemNumber=itemNumber.replace(',','.');
	return itemNumber;
}

function itemNumberFormat(itemNumber)
{
	if(itemNumber.indexOf('.')!=-1)
	{
		b=itemNumber.split('.');
		if(b[1].length>2)
			itemNumber=	priceFormat(itemNumber.toFloat());	
	}
	
	itemNumber = itemNumber.replace('.',',');
	return itemNumber;
}

function priceFormat(a)
{
	a=a.round(2).toString().replace('.',',');
	var b=a.split(',');
	var c='';
	
	if(b[1])
	{
		if(!b[1].charAt(1)) b[1]=b[1].charAt(0)+'0';
		c=','+b[1];
	}
	else
	{
		c=',00'
	}
	a=b[0]+c;
	return a;
}

/*
 * formId - id of form
 * minlen - min length
 * inputId - id of input
 * lang - language 
 */

function checkMinLen(formId,minlen,inputId,lang)
{
	if($(inputId).value=='') {
		if(lang=='pl') komunikat='wypełnij pole długość';
		else komunikat='fill lenght field';
		$('b1').style.display='';
		$('b1').innerHTML='<p>'+komunikat+'</p>';
		
		$(inputId).focus();
	}
	else
	{
		itemValue=$(inputId).value;
		itemValue=itemValue.replace(',','.').toFloat().round(2);
		
		if(itemValue<minlen) {
			if(lang=='pl') komunikat='minimalna długość tego produktu jest większa';
			else komunikat='minimum length is bigger then this value';
			$('b1').style.display='';
			$('b1').innerHTML='<p>'+komunikat+'</p>';
			
			$(inputId).focus();
		}
		else
		{
			$(formId).submit();
		}
	}
}

/*
 * a - string
 * d - after . possible
 */
function transform2number(a,d)
{
	var ret='';
	var dot=0;
	
	var len=a.length;
	for (var j = 0; j < len; j++)
    {
        ch=a.charAt(j);
        switch (ch)
                {
                case ",": if(dot++==0 && d=='yes')ret+=ch;break;
                case ".": if(dot++==0 && d=='yes')ret+=ch;break;
                case "0": 
                case "1":
                case "2":
                case "3":
                case "4":
                case "5":
                case "6":
                case "7":
                case "8":
                case "9":
                		ret+=ch;
                        break;    
                default: break;                                
                }
        }
		return ret;
}


function PopUpLnkWS(l, w, h) {
	w = window.open(l,'','resizable=no,location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no,fullscreen=no,dependent=no,width='+w+',height='+h+',left=0,top=0');
	return false;
}

// linki _blank
function externalLinks() { if (!document.getElementsByTagName) return; var anchors = document.getElementsByTagName("a"); for (var i=0; i<anchors.length; i++) {  var anchor = anchors[i];  if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank";}}

