//zmena kategorie
function showCategory( cidselectid )
{
	element = document.getElementById(cidselectid);
	window.location = "http://www.spodni-pradlo-aneta.cz/?view=showCateg&cid=" + element.options[element.selectedIndex].value;	
}

//doplnime funkci trim
function trim(string_to_trim)
{
	return string_to_trim.replace(/^\s+|\s+$/g,"");
}


//fce na otevreni noveho okna bez ovladacich listicek - w=sirka okna, h=vyska okna, x=x-ova souradnice, y-ova
function windowOpen(content,title,w, h){
	newWindow = window.open('','','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+w+',height='+h);
	newWindow.moveTo(0 + (screen.width - w)/2,0 + (screen.height - h)/2);	
	newDoc = newWindow.document;
	newContent = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">';
	newContent += '<title>'+title+'</title><link rel="StyleSheet" href="http://www.levnepocitace.cz/new/graphics/css/styles03.css" type="text/css">';
	newContent += '</head><body id="popup">';
	newContent += '<p class="elementDescpHeader">'+title+':</p>';
	newContent += '<p class="elementDescp">'+content+'</p></body></html>';
	newDoc.write(newContent);
	newDoc.close();
}

//fce na otevreni noveho okna s danym detailem produktu, ktery je oznacen v comboboxu
function windowOpenProduct(objectId){
	component = document.getElementById(objectId);
	componentProductId = component[component.selectedIndex].value;
	productId = compProductIds[componentProductId];
	if ( productId != 0 )
	{
		categoryId = compProductCategories[componentProductId];
		newWindow = window.open('?view=showDetail&cid=' + categoryId + '&pid='+productId,'Produkt');
		//newWindow.moveTo(0 + (screen.width - w)/2 , 0 + (screen.height - h)/2);
	}
	else
	{		
		windowOpen( compProductDesc[componentProductId], 'N?pov?da ke komponent?', 400, 200);
	}
}



//fce na otevreni noveho okna s danym url a na dane pozici
function windowOpenURL(content,title,w, h){
	newWindow = window.open(content,title,'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+w+',height='+h);
	newWindow.moveTo(0 + (screen.width - w)/2 , 0 + (screen.height - h)/2);
}


//fce na zmenu id objektu
function switchObjectId(source_id,target_id){
	obj = document.getElementById(source_id);
	obj.id = target_id;
}

//fce na zmenu css class objektu
function switchCSSClass(source_id,css_class){
	obj = document.getElementById(source_id);
	obj.className = css_class;
}


/**************************************
? Autor: Jonas Raoni Soares Silva
? Site: http://www.joninhas.ath.cx:666
**************************************/

fmtMoney = function( n, c, d, t ) {
	var m = ( c = Math.abs( c ) + 1 ? c : 2, d = d || ",", t = t || ".", /(\d+)(?:(\.\d+)|)/.exec( n + "" ) ), x = m[1].length % 3;
	return ( x ? m[1].substr( 0, x ) + t : "" ) + m[1].substr( x ).replace( /(\d{3})(?=\d)/g, "$1" + t ) + ( c ? d + ( +m[2] ).toFixed( c ).substr( 2 ) : "" );
};



//fce na spocitani ceny konfigurace
function calculatePrice( formId, priceTagId, vatpriceTagId, vatType, vat, discount )
{
	if ( vatType == 0 )
	{
		price = defaultPrice;
		componentPrice = 0;
		form = document.getElementById(formId);		
		for ( i = 0; i < components.length; i++ )
		{
			component = document.getElementsByName(components[i]);
			switch ( component[0].type )
			{
				case "select-one" :	componentPrice = compProductPrices[ component[0][component[0].selectedIndex].value ]; break;
				case "radio" : 
				{
					for ( k = 0; k < component.length; k++ )
						if ( component[k].checked == true )
							componentPrice = compProductPrices[ component[k].value ];
				}
				break;
			}			
			price += componentPrice * ( (100 - discount) / 100);						
		}	
		vatPrice = price * ( 1 + ( vat / 100 ) );
		priceElem = document.getElementById(priceTagId);
		priceElem.value = fmtMoney(Math.round(price),0,',','.');
		vatpriceElem = document.getElementById(vatpriceTagId);
		vatpriceElem.value = fmtMoney(Math.round(vatPrice),0,',','.');		
	}
	else if ( vatType == 1 )
	{
		price = defaultPrice;
		vatprice = defaultPrice  * ( 1 + ( vat / 100 ) );;
		componentPrice = 0;
		form = document.getElementById(formId);		
		for ( i = 0; i < components.length; i++ )
		{
			component = document.getElementsByName(components[i]);
			switch ( component[0].type )
			{
				case "select-one" :
				{
					componentPrice = compProductPrices[ component[0][component[0].selectedIndex].value ];
					componentVat = compProductVats[ component[0][component[0].selectedIndex].value ];
				}
				break;
				case "radio" : 
				{
					for ( k = 0; k < component.length; k++ )
						if ( component[k].checked == true )
						{
							componentPrice = compProductPrices[ component[k].value ];
							componentVat = compProductVats[ component[k].value ];
						}
				}
				break;
			}
			price += componentPrice * ( (100 - discount) / 100);
			vatprice += componentPrice  * ( 1 + (componentVat / 100) );
		}	
		priceElem = document.getElementById(priceTagId);
		priceElem.value = fmtMoney(Math.round(price),0,',','.');
		vatpriceElem = document.getElementById(vatpriceTagId);
		vatpriceElem.value = fmtMoney(Math.round(vatPrice),0,',','.');
	}
}


//fce na nastaveni zakladni ceny konfigurace
function setDefaultPrices(priceTagId, vatpriceTagId )
{
	priceElem = document.getElementById(priceTagId);
	priceElem.value = fmtMoney(Math.round(startPrice),0,',','.');
	vatpriceElem = document.getElementById(vatpriceTagId);
	vatpriceElem.value = fmtMoney(Math.round(startVatPrice),0,',','.');	
}
