$(document).ready(function() {
	$('#quickChoiceLenses').change(function() {
		url = $(this).attr('value');
		if(url != null && url != '-') {
			window.location.href = $(this).attr('value');
		}
	});

  $("#zobrazit-podrobna-pravidla").click(function() {
    $("#podrobna-pravidla").slideToggle("slow");
		return false;
  });

});

function number_format( number, decimals, dec_point, thousands_sep ) 
{
    // http://kevin.vanzonneveld.net
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://crestidg.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // *     example 1: number_format(1234.5678, 2, '.', '');
    // *     returns 1: 1234.57     
 
    var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
    var d = dec_point == undefined ? "." : dec_point;
    var t = thousands_sep == undefined ? "," : thousands_sep, s = n < 0 ? "-" : "";
    var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
    
    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}


// update product parameters selectbox values
function updateParamValues(json)
{
	var selNames = [];
	var selValues = [];
	var i = 0;

	/*
	$("select option:selected").each(function () {
		selNames[i] = $(this).parent().attr('name');
		selValues[i] = $(this).val();
		i++;
	});
	*/
	
	for(paramName in json.paramValues) {
		values = json.paramValues[paramName];
		id = "lensParam-" + json.ident + "-" + json.productId + "-" + paramName;

		sel = $('#' + id).get(0);
		if(sel == undefined) continue;

		for(i = sel.options.length - 1; i >= 0 ; i--) {
			if(sel.options[i].value != 'null') sel.options[i] = null;
		}

		if(paramName == 'color') {
			values_names = json.paramValues[ 'color_names' ].slice();
		} else {
			values_names = values.slice();
		}
		
		for(i = 0; i < values.length; i++) {
			text = values_names[i];
			if(paramName == 'dpt') {
				text = number_format(text,2,'.',' ');
				if(text > 0) { 
					text = '+'+text;
				}
			}
			if(paramName == 'bc') {
				text = number_format(text,1,'.',' ');
			}
			if(paramName == 'axis') {
				text = text+'°';
			}

			newOption = new Option(text, values[i]);
			try { sel.add(newOption, sel.options[sel.options.length]); }
			catch(ex) { sel.add(newOption); }
		}

		if (values.length == 1) {
			// select selectboxes if only single param value
			$('select[@name$=-'+paramName+'] option[@value='+values[0]+']').attr('selected', true);
		} 		
		
		if(json.action == 'reset') {
			$('select[@name=dpt] option[@value=null]').attr('selected', true);
			//for(i = 0; i < selNames.length; i++) {
				//$('select[@name='+selNames[i]+'] option[@value=null]').attr('selected', true);$('select[@name='+selNames[i]+'] option[@value=null]').attr('selected', true);
			//}
		}

	}

	$('#' + id).attr('disabled', false);
}
