/**
 * ...
 * @author me
 */

$(function(){
	initNav();
	initRegistration()
});

function initNav() {
	$('.NavContainer ul li').each(function(){
		var left_pos = ($(this).width() - $(this).find('.tip').width())/2;
		$(this).find('.tip').attr('style','left:'+left_pos+'px;');
	});
	if(navigator.userAgent.indexOf('Windows') < 0) {
		
		if($.browser.webkit) {
			$('.NavContainer ul').addClass('alias_fix');
		} else {
			$('.NavContainer ul').addClass('ff_mac_fix');
		}
	} else {
		if(navigator.userAgent.indexOf('MSIE') > -1) {
			//alert(navigator.userAgent);
			if(navigator.userAgent.indexOf('MSIE 7') > -1)  {
				$('.NavContainer ul').addClass('ie7_fix');
			}
		}		else if(navigator.userAgent.indexOf('Firefox')) {			$('.NavContainer ul').addClass('ff_pc_fix');		}
	}
}

function paymentAmountChange() {
	$('input#pre_tax_amount').live('keyup', function(e){
		var total = roundNumber(($(this).val() * 1)*1.13, 2);
		$('span#total_amount').html(total);
		$('#payment_amount').val(total);
		//alert($('#payment_amount').val())
	});
}

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

function initRegistration(){
paymentAmountChange();
	var displayCount = $("#RegistrantCountSelector option[selected='selected']").val() * 1;
	if(isNaN(displayCount)) displayCount = 1;
	for(var i=1;i<6;i++){
		if(i > displayCount) {
			$('#'+i).attr('style','display:none');
		}
	}
	if($("#PaymentMethodSelector option:selected").val() == 'Visa' || $("#PaymentMethodSelector option:selected").val() == 'Mastercard') {
		$('#BillingInfo').show();
	}
	$('#PaymentMethodSelector').change(function(e){
		if($("#PaymentMethodSelector option:selected").val() == 'Visa' || $("#PaymentMethodSelector option:selected").val() == 'Mastercard') {
			$('#BillingInfo').show();
		} else {
			$('#BillingInfo').hide();
		}
	});
}

function display(obj,id1,id2,id3,id4,id5) {
txt = obj.options[obj.selectedIndex].value;
document.getElementById(id1).style.display = 'block';
document.getElementById(id2).style.display = 'none';
document.getElementById(id3).style.display = 'none';
document.getElementById(id4).style.display = 'none';
document.getElementById(id5).style.display = 'none';
if ( txt.match(id1) ) {
document.getElementById(id1).style.display = 'block';
}
if ( txt.match(id2) ) {
document.getElementById(id1).style.display = 'block';
document.getElementById(id2).style.display = 'block';
}
if ( txt.match(id3) ) {
document.getElementById(id1).style.display = 'block';
document.getElementById(id2).style.display = 'block';
document.getElementById(id3).style.display = 'block';
}
if ( txt.match(id4) ) {
document.getElementById(id1).style.display = 'block';
document.getElementById(id2).style.display = 'block';
document.getElementById(id3).style.display = 'block';
document.getElementById(id4).style.display = 'block';
}
if ( txt.match(id5) ) {
document.getElementById(id1).style.display = 'block';
document.getElementById(id2).style.display = 'block';
document.getElementById(id3).style.display = 'block';
document.getElementById(id4).style.display = 'block';
document.getElementById(id5).style.display = 'block';
}

}
function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}

