
/*
function alert(a, width, height)
{
	// a = a.replace(/\n/g, '<br/>');
	
	if ( !width ) width = 400;
	if ( !height ) height = 200;
	
	$('#dialog').html(a);
	$('#dialog').dialog({width: width, height: height});
	$('#dialog').dialog('open');
}*/


function DeliveryAddress_copyBillingAddress()
{
	
	$('input', '#checkout_deliveryAddress').each(function()
	{
		var n = $(this).attr('id').replace(/da_/, '');
		$(this).val( $('#' + n).val() );
	});
	checkRequiredFields();
	
}




function populateProductSelectOptions(theSelect, category_id, selected_product_id)
{
	if ( category_id > 0 )
	{
		$('#' + theSelect).append('<option value="">Loading...</option>');
		$('#' + theSelect).load('/p/populateProducts.php?category_id=' + category_id + '&selected_product_id=' + selected_product_id);
	}
}





function setRequiredFields()
{
	// append a asterisk to the required fields labels
	$('body#front .required').each(function()
	{
		if ( $('img', $(this)).length == 0 )
		{
			$(this).append('<img src="/img/forms/required.gif" alt="Required Field" style="margin:0 0 5px 5px;" />');
		}
	});
	
}


function unsetRequiredFields(fieldset)
{
	$('label.required img', '#' + fieldset).remove();
}






function getGridPrice()
{
	var w = parseInt($('#price_grid_width').val());
	var h = parseInt($('#price_grid_height').val());
	var g = parseInt($('#grid_id').val());
	
	var mw = parseInt($('#maximumWidth').val());
	var mh = parseInt($('#maximumHeight').val());

	if ( w > 0 && w <= mw && h > 0 && h <= mh )
	{
		$.post('/p/get.price.php', {w: w, h: h, g: g}, function(data)
		{
			$('#price_grid_price_display').html('Loading...');
			if ( data.price != '' && data.price_id > 0 )
			{
				$('#price_matrix_prices_id').val(data.price_id);
				$('#price_grid_price_display').html('&pound;' + data.price);
				$('#price_grid_price').val(data.price);
			}
			else
			{
				$('#price_matrix_prices_id').val(0);
				$('#price_grid_price_display').html('<em>Call Us</em>');
				$('#price_grid_price').val(0);
			}
		}, 
		'json'
		);
	}
	else
	{
		alert('Please make sure that you enter valid numbers.\n\nMaximum Width: ' + mw + 'cm\nMaximum Height: ' + mh + 'cm');
	}
}





// pop up help tip

function showTip(what)
{
	switch (what)
	{
		case 'orientation':
			a = $.get('/inc/layout/html/tip.orientation.html', function(a){alert(a, 500, 400);});
			break;
		case 'position':
			a = $.get('/inc/layout/html/tip.position.html', function(a){alert(a, 500, 400);});
			break;
		default:
			alert('error. no content.');
			break;
	}
}





// checkout page / admin create order

function checkRequiredFields()
{
	$('.checkoutBlock').each(function()
	{
		var id = $(this).attr('id');
		var ok = true;

		$('.required', $(this)).each(function()
		{
			eid = $('#' + $(this).attr('for')).attr('id');
			// console.log( 'checking: ' +  eid);
			ev = $('#' + $(this).attr('for')).val();
			// console.log('val: ' + ev);
			if ( ev == '' )
			{
				// console.log(' : EMPTY');
				ok = false;
			}
		});
		if ( ok == true)
		{
			$('#' + id.replace(/checkout_/, 'head_') + ' span').removeClass('fieldsBad').addClass('fieldsGood');
		}
		else
		{
			$('#' + id.replace(/checkout_/, 'head_') + ' span').removeClass('fieldsGood').addClass('fieldsBad');
		}
	});
}


function createAccountOption(me)
{
	if ( $(me).attr('checked') )
	{
		$('#account_username_label, #account_password_label').addClass('required');
		$('#username, #password').attr('disabled', false);
		setRequiredFields();
	}
	else
	{
		unsetRequiredFields('checkout_loginDetails');
		$('#account_username_label, #account_password_label').removeClass('required');
		$('#username, #password').val('').attr('disabled', 'disabled');
	}
}




