$().ready(function(){
    $('#login input[name="login-url"]').val(document.location.href);
	var login = $('#login input[type="text"]');
	login.focus(function(){
		if(!this.orig) this.orig = this.value;
		if(this.orig!==this.value){
			return;
		}
		this.value = '';
		if(this.name.toLowerCase() === 'login-pass'){
			this.type = 'password';
		}
	})
	login.blur(function(){
		if(this.value.length === 0){
			if(this.type.toLowerCase() === 'password') this.type = 'text';
			this.value = this.orig;
		}
	});
	
	$('.teams .skateinfo a').click(function(){
		var cur = $(this).parentsUntil('.headlines').filter('.teams');
		var kid = cur.children('.content');
		if(cur.hasClass('collapsed')){
			kid.slideDown('slow',function(){
				cur.removeClass('collapsed');
			});
		} else {
			kid.slideUp('slow',function(){
				cur.addClass('collapsed');
			});
		}
	});
});

function getHiddenField(name, value) {
    var field = document.createElement("input");
    field.setAttribute("type", "hidden");
    field.setAttribute("name", name);
    field.setAttribute("value", value);
    return field;
}

function paypalPost(itemName, itemNumber, amount, username) {
    var form = document.createElement("form");
    form.setAttribute("method", "POST");
    form.setAttribute("action", "https://www.paypal.com/cgi-bin/webscr");
    form.appendChild(getHiddenField("cmd", "_xclick"));
    form.appendChild(getHiddenField("business", "pickuphockeyfinder@gmail.com"));
    form.appendChild(getHiddenField("item_name", itemName));
    form.appendChild(getHiddenField("item_number", itemNumber));
    form.appendChild(getHiddenField("amount", amount));
    form.appendChild(getHiddenField("no_shipping", "0"));
    form.appendChild(getHiddenField("no_note", "0"));
    form.appendChild(getHiddenField("currency_code", "USD"));
    form.appendChild(getHiddenField("custom", username));
    form.appendChild(getHiddenField("lc", "US"));
    form.appendChild(getHiddenField("bn", "PP-BuyNowBF"));
    form.appendChild(getHiddenField("notify_url", "http://www.hockeyfinder.com/paypal-ipn/"));
    document.body.appendChild(form);
    form.submit();
}

function paypalPostNonIPN(itemName, itemNumber, amount) {
    var form = document.createElement("form");
    form.setAttribute("method", "POST");
    form.setAttribute("action", "https://www.paypal.com/cgi-bin/webscr");
    form.appendChild(getHiddenField("cmd", "_xclick"));
    form.appendChild(getHiddenField("business", "pickuphockeyfinder@gmail.com"));
    form.appendChild(getHiddenField("item_name", itemName));
    form.appendChild(getHiddenField("item_number", itemNumber));
    form.appendChild(getHiddenField("amount", amount));
    form.appendChild(getHiddenField("no_shipping", "0"));
    form.appendChild(getHiddenField("no_note", "0"));
    form.appendChild(getHiddenField("currency_code", "USD"));
    form.appendChild(getHiddenField("lc", "US"));
    form.appendChild(getHiddenField("bn", "HF-BeerLeague"));
    document.body.appendChild(form);
    form.submit();
}

function validatewaivers() {
	
	hf = document.getElementById('hfwaiver');
	org = document.getElementById('orgwaiver');
	
	if(hf && org) {
		if(hf.checked == true && org.checked== true) {
			return true;
		}
	}
	
	alert('Please agree to the terms and waiver to sign-up for this skate time.');
	return false;
}

function getGeoState() {
	if(google.loader.ClientLocation)
	{
		/*visitor_city = google.loader.ClientLocation.address.city;*/
		visitor_region = google.loader.ClientLocation.address.region;

		document.getElementById('geostate').innerHTML = visitor_region;
	}
	else {
		document.getElementById('geostate').innerHTML = "None";
	}
}

function checkAll()
{
	var inputs = document.getElementsByTagName('input');
	var checkboxes = [];
	for (var i = 0; i < inputs.length; i++) {
		if (inputs[i].type == 'checkbox') {
			inputs[i].checked =true;
		}
	}
}

function uncheckAll()
{
	var inputs = document.getElementsByTagName('input');
	var checkboxes = [];
	for (var i = 0; i < inputs.length; i++) {
		if (inputs[i].type == 'checkbox') {
			inputs[i].checked =false;
		}
	}
}

