

var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}


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

function populateProductSelectOptions(theSelect, category_id, selected_product_id)
{
	if( category_id == ''){
		
		$('#' + theSelect).html('<option value="">-- Select Category First</option>');
		
	}else 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
	$('.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)
{
	// append a asterisk to the required fields labels
	$('label.required img', '#' + fieldset).remove();
}

function OpaqueBackground(selector,hex,opacity){
	
	if($.browser.msie){
		
		var opacDec = parseInt(255 * opacity);
		
		$(selector).css({
			background:'transparent',
			filter:'progid:DXImageTransform.Microsoft.gradient(startColorstr=#'+d2h(opacDec)+cutHex(hex)+',endColorstr=#'+d2h(opacDec)+cutHex(hex)+')',
			zoom:1
		});
	}else{
		$(selector).css('background-color','rgba('+HexToRgb(hex)+','+opacity+')');
	}
}

function HexToR(h) {return parseInt((cutHex(h)).substring(0,2),16)}
function HexToG(h) {return parseInt((cutHex(h)).substring(2,4),16)}
function HexToB(h) {return parseInt((cutHex(h)).substring(4,6),16)}
function cutHex(h) {return (h.charAt(0)=="#") ? h.substring(1,7):h}
function HexToRgb(h){ return HexToR(h)+','+HexToG(h)+','+HexToB(h);}
function d2h(d) {return d.toString(16);}
function h2d(h) {return parseInt(h,16);} 






