overPrefs = {
	'showCloseButton': true,
	'showNavArrows' : false,
	'overlayOpacity': .7,
	'autoScale': false,
	'autoDimensions': true,
	'overlayColor': '#000',
	'enableEscapeButton': true,
	'transitionIn': 'none',
	'transitionOut': 'none',
//	'easingIn': 'easeInCirc',
	'speedIn': 200,
	'speedOut': 200,
	'scrolling' : false
}

overPrefsManual = {
    'showCloseButton': true,
    'showNavArrows': false,
    'overlayOpacity': .7,
    'autoScale': false,
    'autoDimensions': true,
    'overlayColor': '#000',
    'enableEscapeButton': true,
    'transitionIn': 'none',
    'transitionOut': 'none',
    //	'easingIn': 'easeInCirc',
    'speedIn': 200,
    'speedOut': 200,
    'scrolling': false,
    'href': '#hcpPop'
}

$(document).ready(function() {
    //$('.signUpBtn').click(hCI.signUpValid);
    //$('.unSubBtn').click(hCI.unSubValid);
    $('input[name="type"]:eq(0)').click();

    /*
    if($('.homePage').length){
    $('#leftLine').css({borderLeft: '2px solid #999', background: '#9f3495'});
    $('#rightLine').css({borderRight: '2px solid #999', background: '#9f3495'});
    $('#main').css('position', 'relative');
    $('#extraBorder').css({width: $('#main').outerWidth()-8, height: $('#main').outerHeight()-4}).fadeIn(200);
    }
    */

    $('.navItem').hover(function(e) {
        if ($(this).hasClass('first'))
            $(this).css('background-position', '-1px 0');
        else
            $(this).css('background-position', '0 0');
    }, function(e) {
        if ($(this).hasClass('first'))
            $(this).css('background-position', '-1px -154px');
        else
            $(this).css('background-position', '0 -154px');
    }).click(function(e) {
        var href = $(this).find('a').attr('href');
        location = href;
    });

    $('#printPage').click(function(e) { window.print(); e.preventDefault(); })

    $('.tSize a').click(function(e) {
        var size = $(this).attr('id');
        $('.tSize a').each(function(i, e) {
            $(this).removeClass('current').attr('title', tSizeTitles[i]);
        })
        $(this).addClass('current').removeAttr('title');
        switch (size) {
            case 'smText':
                $('.pagePane').removeClass('lgText').removeClass('mdText');
                $.cookies.set('textSize', '1');
                break;
            case 'mdText':
                $('.pagePane').removeClass('lgText').addClass('mdText');
                $.cookies.set('textSize', '2');
                break;
            case 'lgText':
                $('.pagePane').removeClass('mdText').addClass('lgText');
                $.cookies.set('textSize', '3');
                break;
        }
        e.preventDefault();
    });

    if ($.cookies.get('textSize') == '1' || $.cookies.get('textSize') == null) {
        $('#smText').click();
    } else if ($.cookies.get('textSize') == '2') {
        $('#mdText').click();
    } else {
        $('#lgText').click();
    }

    $('#emailPage').fancybox(overPrefs).click(function(e) {
        $("#emailPixel").empty().append('<iframe src="https://view.atdmt.com/iaction/SAV_EmailPage_SignUp" width="1" height="1" frameborder="0" scrolling="No" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0"></iframe>');
    });

    $('.hcpLink').fancybox(overPrefs).click(function(e) {
        $("#hcpPixel").empty().append('<iframe src="https://view.atdmt.com/iaction/SAV_HCP_Interstitial" width="1" height="1" frameborder="0" scrolling="No" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0"></iframe>');
    });
    
    //This launches the interstitial from the sitemap, had to go about a different way with hardcoded popup.
    $('.hcpLinkMap').fancybox(overPrefsManual).click(function(e) {
        var newHref = $(this).attr('href');
        
        $("#hcpPixel").empty().append('<iframe src="https://view.atdmt.com/iaction/SAV_HCP_Interstitial" width="1" height="1" frameborder="0" scrolling="No" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0"></iframe>');       
        $('#hcpPop').find('a.yesBtn').attr('href', newHref);
    });

    $('.pregLink').fancybox(overPrefs).click(function(e) {
        $("#pRegPixel").empty().append('<iframe src="https://view.atdmt.com/iaction/SAV_HCP_Interstitial" width="1" height="1" frameborder="0" scrolling="No" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0"></iframe>');
    });

    $('.pregLinkHover').fancybox(overPrefs).click(function(e) {
        $("#pRegPixel").empty().append('<iframe src="https://view.atdmt.com/iaction/SAV_HCP_Interstitial" width="1" height="1" frameborder="0" scrolling="No" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0"></iframe>');
    });


    $('.splashSpaceHCP .pregLink').fancybox(overPrefs).click(function(e) {
        $("#pRegPixelHCP").empty().append('<iframe src="https://view.atdmt.com/iaction/SAV_HCP_Interstitial" width="1" height="1" frameborder="0" scrolling="No" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0"></iframe>');
    });

    $('.leavePop').fancybox(overPrefs).click(function(e) {
        $("#exitPixel").empty().append('<img height="1" width="1" src="https://view.atdmt.com/action/SAV_Global_ExitInterstitial"/>');
        var href = $(this).attr('rel');
        $('#leavePop .contBtn').attr('href', href).click(function(e) {
            $("#exitPixel").empty().append('<img height="1" width="1" src="https://view.atdmt.com/action/SAV_Global_ExitInterstitial_Cont"/>');
        });
    });

    $('.HCPArea').hover(function(e) {
        $('.HCPArea .nonHover').css('left', '-199px');
        $('.HCPArea .hover').css('left', '0');
    }, function(e) {
        $('.HCPArea .nonHover').css('left', '0');
        $('.HCPArea .hover').css('left', '-199px');
    });

    $('.HCPArea2').hover(function(e) {
        $('.HCPArea2 .nonHover').css('left', '-260px');
        $('.HCPArea2 .hover').css('left', '-4px');
    }, function(e) {
        $('.HCPArea2 .nonHover').css('left', '0');
        $('.HCPArea2 .hover').css('left', '-260px');
    });

    $('.HCPAreaPreg').hover(function(e) {
        $('.HCPAreaPreg .nonHover').css('left', '-260px');
        $('.HCPAreaPreg .hover').css('left', '0px');
    }, function(e) {
        $('.HCPAreaPreg .nonHover').css('left', '0');
        $('.HCPAreaPreg .hover').css('left', '-260px');
    });

    $('.pngHover').hover(function(e) {
        $(this).find('.nonHover').css('top', '-145px');
        $(this).find('.hover').css('top', '0');
    }, function(e) {
        $(this).find('.nonHover').css('top', '0');
        $(this).find('.hover').css('top', '-145px');
    });

    $('.bgShift').hover(function(e) {
        bgPos = $(this).css('background-position');
        $(this).css('background-position', '0 top');
    }, function(e) {
        $(this).css('background-position', '0 bottom');
    }).click(function(e) {
        $(this).css('background-position', '0 bottom');
    });

    $('.loBrowPop').click(function(e) {
        window.open($(this).attr('href'), 'popup', 'height=600,width=900,scrollbars=yes,toolbar=no');
        e.preventDefault();
    });

    if ($('.getLegal').length) {
        getXML.getLegal();
    }
    if ($('.getPrivacy').length) {
        getXML.getPrivacy();
    }
});
bgPos = '';
tSizeTitles = ['normal','large','extra large'];

getXML = {
	getLegal: function(){
		
		$.ajax({
		url: 'http://www.frx.com/forestdoc.xml',
			type: 'get',
			dataType: 'xml',
			success: function(xml){
				alert(xml.textResponse);
			}
		});
		//alert('');
	},
	getPrivacy: function(){
		$.ajax({
			url: 'http://www.frx.com/forestdoc.xml',
			type: 'get',
			dataType: 'xml',
			success: function(xml){
				
			}
		});
		$.get('http://www.frx.com/forestdoc.xml',function(xml){
				alert(xml);
			});
	}
}

hCI = {
	emailRegEx: /[^\s]+@[^\s]+([.]\w{2,3})+/,
	
	signUpValid: function(e){
		var isValid = true;
		var em = $('input[name="email"]').val();
		var cem = $('input[name="cemail"]').val();
		var radio = $('input[name="type"]:checked').val();
		var hcp = $('select[name="hcpType"]').val();
		var age = $('input[name="ofAge"]').attr('checked');
		var agree = $('input[name="agree"]').attr('checked');
		$('.error').hide();
		/*alert(
		 'email: '+em+' isEmail: '+hCI.emailRegEx.test(em)+
		 '\nConfirm: '+cem+' isEmail: '+hCI.emailRegEx.test(cem)+
		 '\ntype: '+radio+
		 '\nhcp: '+hcp+
		 '\nage: '+age+
		 '\nagree: '+agree
		 );*/
		if (em == '' || !hCI.emailRegEx.test(em)) {
			$('.emError').show();
			isValid = false;
		}
		
		if (cem == '' || !hCI.emailRegEx.test(cem) || cem != em) {
			$('.cemError').show();
			isValid = false;
		}
		
		if ((radio == 'undefined') || (radio == '3' && hcp == 'XX')) {
			$('.radioError').show();
			isValid = false;
		}
		
		if (!age) {
			$('.ageError').show();
			isValid = false;
		}
		
		if (!agree) {
			$('.agreeError').show();
			isValid = false;
		}
		
		if (!isValid) {
			e.preventDefault();
			return false;
		}
		$('.suForm').submit();
		return true;
	},
	
	unSubValid: function(e){
		var isValid = true;
		var em = $('input[name="email"]').val();
		var cem = $('input[name="cemail"]').val();
		$('.error').hide();
		/*alert(
		 'email: '+em+' isEmail: '+hCI.emailRegEx.test(em)+
		 '\nConfirm: '+cem+' isEmail: '+hCI.emailRegEx.test(cem)
		 );*/
		if (em == '' || !hCI.emailRegEx.test(em)) {
			$('.emError').show();
			isValid = false;
		}
		
		if (cem == '' || !hCI.emailRegEx.test(cem) || cem != em) {
			$('.cemError').show();
			isValid = false;
		}
		
		if (!isValid) {
			e.preventDefault();
			return false;
		}
		$('.unForm').submit();
		return true;
	}
};



function checkAndAddHTTPS(navigateURL) {
    var retNavigateURL;

    retNavigateURL = navigateURL;
    
    if (window.location.protocol.toLowerCase() == "https:" 
        && navigateURL.indexOf("http://") >= 0) {
        retNavigateURL = "https:" + navigateURL.substring(5);
    }
    
    return retNavigateURL;
}
function NavigateTo(url, pageRequiresSSL) {
var useSSL = 'true';

    if (useSSL == 'true' && pageRequiresSSL) {
        location.href = "https://" + location.host + "/" + url;
    }
    else {
        location.href = "http://" + location.host + "/" + url;
    }

    return false;
}
