$().ready(function(){
  $('.name_title').click(function(){
    if ($(this).attr('id') == 'name_title_company') $('.biz').show();
    else jQuery('.biz').hide();
  });
  
  $('.document_attached').click(function(){
		showHideDocs();
    if ($(this).val()=='yes') 
    {
      $('#documents').show();
      $('#documents_no').hide();
    }
    else
    {
      $('#documents').hide();
      $('#documents_no').show();
    }
  });

	$('select#demand').change(function(){
		setDeposit();
	});
  

	$('ul.radio_extra li input[type=radio]').each(function(){
		$(this).click(function() {
			showHideExtra(this);
		})
		showHideExtra(this);
	});
		
  // $('.gexpander').click(function(){
  //   url = $(this).attr('href');
  //   $(url).toggleClass('hide');
  //   return false;
  // });
  // $(document).pngFix(); 
  if ($.fn.cluetip) $('a.load-local').cluetip({local:true, cursor: 'pointer', showTitle: false, cluetipClass: 'jtip', positionBy: 'bottomTop',  width: 200});
  
	showHideDocs();
	setDeposit();
	
	$('.sample_pic,.details').hide();
	
	$('.sample li,p.sample').click(function(){
		$('.sample_pic').hide();
		$('#' + $(this).attr('id') + '_img').show('slow');
		// $('#img_sample').attr('src','/images/cem/form/samples/'+ $(this).attr('id')+'.jpg');
	});
		
});

function showHideExtra(obj) {
	if ($(obj).attr('checked'))
	{
		var extra = '#' + $(obj).attr('name') + '_extra';
		if ($(extra) && $(obj).hasClass('show_extra')) {
			$(extra).show();
		} else { 
			$(extra).hide(); 
		}
	}
}

function showHideDocs () {
	if ($('.document_attached').val()=='yes') 
  {
    $('#documents').show();
    $('#documents_no').hide();
  }
  else
  {
    $('#documents').hide();
    $('#documents_no').show();
  }
}

function setDeposit () {
	if ($('select#demand')) {
		var deposit = 0;
		switch ($('select#demand').val()) {
			case '3.4': deposit = 65; break;
			case '6.9': deposit = 132; break;
			case '11.5': deposit = 219; break;
			case '13.8': deposit = 399; break;
			case '20.7': deposit = 598; break;
			case '34.5': deposit = 854; break;
			case '69': deposit = 1708; break;
			case '100': deposit = 2476; break;
			case '130': deposit = 6437; break;
			case '200': deposit = 9903; break;
			default: break;
		}
		$('#deposit').text(deposit).addClass('form-highlight');
	}
}

function showFormInfo (sel) {
	$('.details').hide();
	
	app = $(sel.options[sel.options.selectedIndex]);
	$('#'+ app.attr('id') + '_details').show('slow');
}

function showFormSample (url) {
	window.open(url,'samples','width=850,height=430,status=0,location=0,menubar=0,toolbar=0,resizable=1');
	return false;
}

function goForm (sel) {
	url = $(sel.options[sel.options.selectedIndex]).attr('value');
	if (url) location.href = url;
}
