function se(){return true}
window.onerror = se;

function updatePrice(objectId,product,optionsString)
{
	var o = document.getElementById(objectId);
	
	if ( o )
	{
		var width = ( document.getElementById('width') ) ? document.getElementById('width').value : '';
		var height = ( document.getElementById('height') ) ? document.getElementById('height').value : '';
		
		var additionalHeight = '';
		
		// hacky fix to make guess smallest width / height when none selected
		
		if ( width == '' )
		{
			for ( i in sizes )
			{
				width = i;
				
				break;
			}
		}
		
		if ( height == '' )
		{
			height = sizes[width][0][0];
		}
		
		//
		
		//alert(optionsString);
		
		optionsString = Object.toJSON(optionsString);
		
		//alert(optionsString);

		new Ajax.Request('/ajax/getPrice.php',
		{
			method:'get',
			parameters: { product:product, width:width, height:height ,additionalHeight:additionalHeight, optionsString:optionsString },
			onSuccess: function(transport)
			{
				if ( transport.responseText > 0 )
				{
					o.innerHTML = '&pound;' + transport.responseText;
				}
				else
				{
					//o.innerHTML = '';
				}
			},
			onFailure: function()
			{
				//alert('AJAX Request Failed');
			}
		});
	}
}

function updatePriceOLD(objectId,product,width,height,additionalHeight,fixings,crystals)
{
	var o = document.getElementById(objectId);
	
	if ( o )
	{
		// hacky fix to make guess smallest width / height when none selected
		
		if ( width == '' )
		{
			for ( i in sizes )
			{
				width = i;
				
				break;
			}
		}
		
		if ( height == '' )
		{
			height = sizes[width][0][0];
		}
		
		//
		
		new Ajax.Request('/ajax/getPrice.php',
		{
			method:'post',
			parameters: { product:product, width:width, height:height ,additionalHeight:additionalHeight, fixings:fixings, crystals:crystals },
			onSuccess: function(transport)
			{
				if ( transport.responseText > 0 )
				{
					o.innerHTML = '&pound;' + transport.responseText;
				}
				else
				{
					//o.innerHTML = '';
				}
			},
			onFailure: function()
			{
				alert('AJAX Request Failed');
			}
		});
	}
}

function populateList(elementId,optionArray)
{
	if ( optionArray == undefined )
	{
		optionArray = new Array();	
	}
	
	//alert(optionArray);
	
	var list = document.getElementById(elementId);
	
	if ( list )
	{
		list.options.length = 0;
		
		//alert(optionArray.length);
			
		list.options[list.options.length] = new Option('Please select','');

		for ( i = 0; i < optionArray.length; i++ )
		{
			if ( isArray(optionArray[i]) )
			{
				//alert(optionArray[i]);
				
				list.options[list.options.length] = new Option(optionArray[i][1],optionArray[i][0]);
			}
			else
			{
				list.options[list.options.length] = new Option(optionArray[i],optionArray[i]);
			}
		}
	}
}

function isArray(obj)
{
	if ( obj.constructor.toString().indexOf("Array") == -1 )
	{
		return false;
	}
	else
	{
		return true;
	}
}

function decimalPlaces(num,dec)
{
	var result = Math.round(num*Math.pow(10,dec)) / Math.pow(10,dec);
	return result;
}
