//reset form fields
function resetForm( form ) {
  for(var x in form.elements) {
		if(form[x] && form[x].type) {
			switch( form[x].type) {
				case "text":
				case "textarea":
				case "password":
					form[x].value = "";
					break;
				case "checkbox":
				case "radio":
					form[x].checked = false;
					break;
				case "select-one":
					form[x].selectedIndex = 0;
					break;
			}
		}
	}
}

function initSubscriptionLists() {
	$(".newsletter .description").each( function() {
		$(this).hide();
	});
	$(".newsletter label").after("<a href=\"#\" class=\"showHide\">More&hellip;</a>");
	$(".newsletter a").each( function() {
		$(this).click(function(e) {
			if($(this).hasClass("active")) {
				$(this).next().slideUp(350, function() { $(this).prev().removeClass("active"); });
				$(this).get(0).innerHTML = "More&hellip;";
			} else {
				$(this).next().slideDown(350, function() { $(this).prev().addClass("active"); });
				$(this).get(0).innerHTML = "less&hellip;"
			}
//			$(this).next().slideToggle();
			e.stopPropagation();
			e.preventDefault();
		});
	});
}

function initModify() {
	$("#emailPermission").click(function(e) {
		$("input[type=checkbox]").each(toggleLists);
	});
	initSubscriptionLists();
	toggleLists();
}

function toggleLists(e) {
	var checked =  $("#emailPermission").get(0).checked;
	$("input[type=checkbox]").each(function(index, element) {
		if(element.id != "emailPermission" && element.id != "mobilePermission") {
			element.disabled = !checked;
		}
	});
}

function pop(url, width, height){
	var scrWidth = 0;
	var scrHeight = 0;
	if(window.screen){
		if(window.screen.availWidth){
			scrWidth = window.screen.availWidth;
			scrHeight = window.screen.availHeight
		}
	}
	var left = (scrWidth - width) / 2;
	var top = (scrHeight - height) / 2;
	window.open(url, "" , "left=" + left + ",top=" + top + ",screenX=0,screenY=0,width=" + width + ",height=" + height +
							",scrollbars=yes,resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,copyhistory=0")
}
$(document).ready( function() {
	$(".popup-link").click(function(e) {
			pop(this.href, 635, 430);
			e.preventDefault();
			return false();
	});
});
