var activeBtn;

function changeBg( button, state )
{	
	if( button == activeBtn ) return;
	if( state == 0 )
	{
		button.style.background="#1A4F85";
		button.style.color="#ffffff";
	}
	else if( state == 1 )
	{
		button.style.background="#1D64AD";
		button.style.color="#ffffff";
	}
	else if( state == 2)
	{
		if( activeBtn != undefined ) 
		{
			activeBtn.style.background="#1A4F85";
			activeBtn.style.color="#ffffff";
		}
		
		button.style.background="#E9E9E9";
		button.style.color="#009900";		
		activeBtn = button;
	}	
}
function modifyPrice( id )
{

	var total  = 0;
	var price  = 0;
	var amount = 0;
	
	for( var i = 0; i < 5; i++ )
	{		
		if( document.getElementById( "price_" + i) == null )
			break;
		
		price  = Number( document.getElementById( "price_" + i).innerHTML );
		amount = Number ( document.getElementById( "value_" + i).value );
		
		total += amount  * price;
	}
	//var price  = Number( document.getElementById( "price_" + id).innerHTML );
	//var amount = Number ( document.getElementById( "value_" + id).value );
	
	//var total = Number( document.getElementById( "price").innerHTML );
	
	document.getElementById( "price").innerHTML = total;
	
	
}
function afterShopping()
{
	alert( "Köszönjük a megrendelést" );
	return true;
}

function search( )
{
	
	var str = document.getElementById( "searchField").value;
	//alert( str );
	return load( "search", "cont",  str );
}

function load(melyik, place, param)
{
	if( melyik == "shop" && param != undefined )
		alert( "A termék bekerült a kosárba. " );
	getHTML('php/loader.php?page=' + melyik + '&param=' + param, place);	
	return false;
}

function do_visible( id, btn )
{		
	var x = document.getElementById( id );	
	var button = document.getElementById( btn );	
	
	
	if( x.style.display == "block" )
	{		
		if( button != null ) 
			button.innerHTML = "Detalii";
		x.style.display = "none";		
	}
	else
	{
		if( button != null ) 
			button.innerHTML = "Înapoi";
		x.style.display = "block";
	}
	/*
	if( visible )
	{		
		x.style.display = "block";
	}
	else
		x.style.display = "none";
	*/
	return false;
}

function getHTML(url,id)
{
  var http_request=false;
  if(window.XMLHttpRequest)
  {
	http_request=new XMLHttpRequest();
	if(http_request.overrideMimeType)
	{
		http_request.overrideMimeType('text/xml');
	}
  }else if(window.ActiveXObject)
  {
    try{http_request=new ActiveXObject("Msxml2.XMLHTTP");}
		catch(e){try{http_request=new ActiveXObject("Microsoft.XMLHTTP");}
		catch(e){}
    }
  }
  if(!http_request){alert('Nem tdz?mogatott bdz?ngdz?szo!');
    return false;
  }
  
  http_request.onreadystatechange = function() { alertContents(http_request,id); };
  
  http_request.open('GET', url, true);
  http_request.setRequestHeader("Content-Type", "text/plain; charset=ISO-8859-2");
  http_request.send(null);
}

function alertContents(http_request, id) 
{
    	var x = document.getElementById(id);
    	var szoveg;
    		
        if (http_request.readyState == 4) 
	{
            if (http_request.status == 200) 
	    {            	                
                szoveg = http_request.responseText;
				//drake decode :)
				szoveg = szoveg.replace(/{{o}}/g,"dz?");
                szoveg = szoveg.replace(/{{O}}/g,"dz?");
                szoveg = szoveg.replace(/{{u}}/g,"dz?");
                szoveg = szoveg.replace(/{{U}}/g,"dz?");
                szoveg = szoveg.replace(/{{a}}/g,"dz?");
                szoveg = szoveg.replace(/{{A}}/g,"dz?");
				szoveg = szoveg.replace(/{{B}}/g,"dz?");
				szoveg = szoveg.replace(/{{a}}/g,"dz?");
				szoveg = szoveg.replace(/{{e}}/g,"dz?");	
		if(szoveg.substring(0, 5) == "code:")
		{	
			var code = szoveg.substring(5, szoveg.length);
			eval(code);
		}
                else if (szoveg != '-none-')
		{
                	x.innerHTML = szoveg;
                }                
            } 
	    else
	    {
                alert('Error!');
            }
        }

}

var Url = {

 	// public method for URL encoding
 	encode : function (string) {
 		 return escape(this._utf8_encode(string));
 	},

 	// public method for URL decoding
	 decode : function (string) {
 	 	return this._utf8_decode(unescape(string));
 	},

 	// private method for UTF-8 encoding
 	_utf8_encode : function (string) {
  		string = string.replace(/\r\n/g,"\n");
 	 	var utftext = "";

  		for (var n = 0; n < string.length; n++) {
   			var c = string.charCodeAt(n);
   			if (c < 128) {
    				utftext += String.fromCharCode(c);
 			} else if((c > 127) && (c < 2048)) {
  				utftext += String.fromCharCode((c >> 6) | 192);
  				utftext += String.fromCharCode((c & 63) | 128);
 			} else {
  				utftext += String.fromCharCode((c >> 12) | 224);
  				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
 	 			utftext += String.fromCharCode((c & 63) | 128);
 			}
 	}

		return utftext;
	},

 	// private method for UTF-8 decoding
 	_utf8_decode : function (utftext) {
 		 var string = "";
 		 var i = 0;
 		 var c = c1 = c2 = 0;

  		while ( i < utftext.length ) {
  			 c = utftext.charCodeAt(i);
   			if (c < 128) {
    				string += String.fromCharCode(c);
    				i++;
  			 } else if((c > 191) && (c < 224)) {
 				   c2 = utftext.charCodeAt(i+1);
    				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
    				i += 2;
  			 } else {
 				   c2 = utftext.charCodeAt(i+1);
    				c3 = utftext.charCodeAt(i+2);
    				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
   				 i += 3;
 			  }
		  }
		return string;
	 }
}
