$('document').ready(function()
{
  $(".button").click(function() {
	if($(this).attr("href")=='#form' ||  $('input[type="image"]') )
	{
	    if($("input[id$='callAction']").length != 0) $("input[id$='callAction']").val($(this).attr("name"));
	    $("form[id='"+$(this).parents("form").attr("id")+"']").submit();return false;
	}
	return true;
    });

    $('.flashMessages').delay('5000',function()
    {
	$('.flashMessages').fadeOut('slow');
    })

    $('.formErrorMessage').hide();
    $('.formErrorMessage').fadeIn(2000);
    $('.stepsPromoSudbmit').click(function(){
	window.location=this.rel;
        return false;
    });
	$(function(){
			$(".popupwindow").popupwindow();
	});
	
	// coreg specific JS

	$("#coregContainer input:radio.regSelect").each(function()
	{
            
		$(this).click(function()
		{
            container = $(this).parent().parent();
			value = $(this).attr("value");
			
			if(value == 'Yes')
			{
				container.addClass('border');
				container.find(".content_long").show();
			}
			else
			{
				container.removeClass('border');
				container.find(".content_long").hide();
			}
		});
		
		// check if radio button is set at 'Yes'
		if($(this).parent().find("input:radio.regSelect:checked").val() == 'Yes')
		{
            container = $(this).parent().parent();
			container.find(".content_long").show();
			container.addClass("border");
			
		}
	});

	// privacy policy links
	$("a.privacyPolicy").each(function()
	{
		url = $(this).attr('href');
		
		// add attributes width and/or height to the anchor tag to set them dynamically (NOT TESTED IN INTERNET EXPLODER)
		width = $(this).attr('width');
		height = $(this).attr('height');
		
		$(this).attr("href", "javascript:void(0)");
		$(this).click(function()
		{
			privacyPopup(url, $(this).attr("name"), width, height);
		});
	});
});

function privacyPopup(URL, name, width, height)
{
	if(width == null)
	{
		width = 805;
	}
	if(height == null)
	{
		height = 500;
	}
	
	eval("var poppriv = window.open(URL, '"+name+"','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height+",left = 0,top = 0');");
	
	if(poppriv != null)
	{
		poppriv.focus();
	}
}

