﻿
var bVideoPlayed=false;
var bCampaign=false;
$(document).ready(function() {
	fontResizer('1em', '1.16em', '1.33em');

	//prescribing info pdf
	$('a.lnkPrescribingInfo').click(function() {
		/*
		//atlas tag tracker
		$.ajax({
		type: "POST",
		url: "/handlers/tag-tracker.ashx",
		data: "url=http://view.atdmt.com/action/dihshr_NEWLIC_092009_Prescribing_Information",
		success: function(msg){
				
		}
		});
		*/
	});
	$('a.lnkPrescribingInfoVideo').livequery('click', function() {
		//atlas tag tracker
		$.ajax({
			type: "POST",
			url: "/handlers/tag-tracker.ashx",
			data: "url=http://view.atdmt.com/action/dihshr_NEWLIC_092009_Prescribing_Information",
			success: function(msg) {

			}
		});

	});


	//professional site link
	$('a.lnkProfessionalSite').click(function() {
		/*
		//atlas tag tracker
		$.ajax({
		type: "POST",
		url: "/handlers/tag-tracker.ashx",
		data: "url=http://view.atdmt.com/action/dihshr_NEWLIC_092009_For_Health_Care_Professionals",
		success: function(msg){
    			
		}
		});
		*/

	});
	//shire corporate site link
	$('a.lnkShireCorporate').click(function() {
	});

	//inside story video
	$('a.insideStory').click(function() {
	});

	//search functionality
	$('input#ctl00_objHeader_objHeaderLinks_searchText').focus(function() {
		if ($(this).attr('value') == 'Search') {
			$(this).attr('value', '');
		}

	});
	$('input#ctl00_objHeader_objHeaderLinks_searchText').blur(function() {	//test to see if the value of our search field is empty, then fill with our holding text
		if ($(this).attr('value') == '') {
			$(this).attr('value', 'Search');
			$(this).css('color', '#777');
		}
	});
	$('input#btnG').click(function() {
		searchFromAppliance();
		return false;
	});
	$('input#q').keypress(function(e) {
		if (e.which == 13) {
			searchFromAppliance();
			return false;
		}

	});

	function searchFromAppliance() {
		var sTerm = $('input#q').val();
		doSearch(sTerm);

	}
	$('input#ctl00_objHeader_objHeaderLinks_searchText').keypress(function(e) {
		if (e.which == 13) {
			var sTerm = $('input#ctl00_objHeader_objHeaderLinks_searchText').val();
			doSearch(sTerm);
			return false;
		}

	});
	$('span#searchIcon').click(function() {
		var sTerm = $('input#ctl00_objHeader_objHeaderLinks_searchText').val();
		doSearch(sTerm);
	});
	function doSearch(thisTerm) {
		TMAN.doTags(TMAN.position.SITE_SEARCH,true);
		var searchTarget = '/search.aspx?q=' + thisTerm;
		window.location = searchTarget;
	}

	$('a.thickbox').click(function() {
		window.scrollTo(0, 0);
	});

	//email a friend link
	$('a#email_friend').click(function() {
		TMAN.doTags(TMAN.position.SHARE, true);
	});
	//email a friend box
	$('img#email_submit').livequery('click', function() {
		TMAN.doTags(TMAN.position.SHARE_SUBMIT, true);
		//validate form
		var mainDiv = $(this).parent().parent().parent();
		var bValid = true;
		var emailFromFName, emailToFName, emailFromAddress, emailToAddress;
		//validate first name
		var fieldValue = mainDiv.find('#email_fname1').val();
		emailFromFName = fieldValue;
		if (fieldValue == '') {
			mainDiv.find('#err_email_fname1').show();
			bValid = false;
		}
		else mainDiv.find('#err_email_fname1').hide();

		//validate first name of to field
		var fieldValue = mainDiv.find('#email_fname2').val();
		emailToFName = fieldValue;
		if (fieldValue == '') {
			mainDiv.find('#err_email_fname2').show();
			bValid = false;
		}
		else mainDiv.find('#err_email_fname2').hide();

		//validate email of sender
		var fieldValue = mainDiv.find('#email_email1').val();
		emailFromAddress = fieldValue;
		if (fieldValue == '') {
			mainDiv.find('#err_email_email1').show();
			mainDiv.find('#err_email_email1_invalid').hide();
			bValid = false;
		}
		else if (!validateEmail(fieldValue)) {
			mainDiv.find('#err_email_email1_invalid').show();
			mainDiv.find('#err_email_email1').hide();
			bValid = false;
		}
		else {
			mainDiv.find('#err_email_email1').hide();
			mainDiv.find('#err_email_email1_invalid').hide();
		}

		//validate email of to field
		var fieldValue = mainDiv.find('#email_email2').val();
		emailToAddress = fieldValue;
		if (fieldValue == '') {
			mainDiv.find('#err_email_email2').show();
			mainDiv.find('#err_email_email2_invalid').hide();
			bValid = false;
		}
		else if (!validateEmail(fieldValue)) {
			mainDiv.find('#err_email_email2_invalid').show();
			mainDiv.find('#err_email_email2').hide();
			bValid = false;
		}
		else {
			mainDiv.find('#err_email_email2').hide();
			mainDiv.find('#err_email_email2_invalid').hide();
		}

		if (!bValid) return;
		//determine what type of email to send
		var sendpage = mainDiv.find('#emailWhat_0').attr('checked');
		var sendtype = 1; //sendtype=0 - send this page only; sendtype=1 - send entire site
		if (sendpage) {
			sendtype = 0;
		}

		mainDiv.addClass('flarehide');
		//send the email w/ ajax call, show success div when the response is received
		$.ajax({
			type: "POST",
			url: "/handlers/email-a-friend.ashx",
			data: "sendtype=" + sendtype + "&emailFromFName=" + emailFromFName + "&emailToFName=" + emailToFName + "&emailFromAddress=" + emailFromAddress + "&emailToAddress=" + emailToAddress + "&pageURL=" + window.location.toString(),
			success: function(msg) {
				mainDiv.parent().parent().find('div#ddg_email_confirmation').removeClass('flarehide');
				window.setTimeout('tb_remove();', 5000);
			},
			error: function(jqXHR, textStatus, errorThrown) {
				mainDiv.parent().parent().find('div#ddg_email_confirmation').removeClass('flarehide');
			}
		});





		//$('div#ddg_emaildiv').removeClass('flareshow');
	});
	$('img#email_cancel').livequery('click', function() {
		tb_remove();

	});
	$('a#email_close_btn').livequery('click', function() {
		try {
			tb_remove();
		}
		catch (e) { }

	});

	//video email
	$('a#lnkEmailVideo').livequery('click', function() {
		var mainDiv = $(this).parent().parent().parent().parent();
		mainDiv.find('#divVideo').css('display', 'none');
		mainDiv.find('#emailVideoDiv').removeClass('hideElement');
	});
	$('a#close_btn2').livequery('click', function() {
		var mainDiv = $(this).parent().parent().parent();
		mainDiv.find('#divVideo').css('display', 'block');
		mainDiv.find('#emailVideoDiv').addClass('hideElement');
	});
	$('input#cancelVideoEmail').livequery('click', function() {
		var mainDiv = $(this).parent().parent().parent().parent().parent().parent();
		mainDiv.find('#divVideo').css('display', 'block');
		mainDiv.find('#emailVideoDiv').addClass('hideElement');
		return false;
	});
	//video email validation
	$('input#submitVideoEmail').livequery('click', function() {
		//validate form
		var mainDiv = $(this).parent().parent().parent().parent().parent().parent();
		var bValid = true;
		var emailFromFName, emailToFName, emailFromAddress, emailToAddress;
		emailToFName = '';
		//validate first name
		var fieldValue = mainDiv.find('#video_email_fname').val();
		emailFromFName = fieldValue;
		if (fieldValue == '') {
			mainDiv.find('#vid_fname_error').show();
			bValid = false;
		}
		else mainDiv.find('#vid_fname_error').hide();

		//validate email of sender
		var fieldValue = mainDiv.find('#video_email_email').val();
		emailFromAddress = fieldValue;
		if (fieldValue == '') {
			mainDiv.find('#vid_email_error1').show();
			mainDiv.find('#vid_email_error2').hide();
			bValid = false;
		}
		else if (!validateEmail(fieldValue)) {
			mainDiv.find('#vid_email_error2').show();
			mainDiv.find('#vid_email_error1').hide();
			bValid = false;
		}
		else {
			mainDiv.find('#vid_email_error1').hide();
			mainDiv.find('#vid_email_error2').hide();
		}

		//validate email of recipient
		var fieldValue = mainDiv.find('#video_email_email2').val();
		emailToAddress = fieldValue;
		if (fieldValue == '') {
			mainDiv.find('#vid_email2_error1').show();
			mainDiv.find('#vid_email2_error2').hide();
			bValid = false;
		}
		else if (!validateEmail(fieldValue)) {
			mainDiv.find('#vid_email2_error2').show();
			mainDiv.find('#vid_email2_error1').hide();
			bValid = false;
		}
		else {
			mainDiv.find('#vid_email2_error1').hide();
			mainDiv.find('#vid_email2_error2').hide();
		}


		if (!bValid) return;
		mainDiv.find('div.forms').addClass('hideElement');
		var sendtype = 5; //
		$.ajax({
			type: "POST",
			url: "/handlers/email-a-friend.ashx",
			data: "sendtype=" + sendtype + "&emailFromFName=" + emailFromFName + "&emailToFName=" + emailToFName + "&emailFromAddress=" + emailFromAddress + "&emailToAddress=" + emailToAddress + "&pageURL=" + window.location.toString(),
			success: function(msg) {
				mainDiv.find('div.confirmation').removeClass('hideElement');
				window.setTimeout('tb_remove();', 5000);
			}
		});

		return false;
		//$('div#ddg_emaildiv').removeClass('flareshow');
	});

	//registration form logic
	$('div#medications').find('input.medcheck').click(function() {
		if ($(this).attr('name') == 'chkLialda') {
			if ($(this).is(':checked')) {
				$('div#uselialda').removeClass('hideElement');
			}
			else $('div#uselialda').addClass('hideElement');
		};
	});

	$('#condition').change(function() {
		if (this.selectedIndex == 1) {
			$("#haveuc").removeClass("hideElement");
		} else {
			$("#haveuc").addClass("hideElement");
		}
	});

	//coupon
	$('#coupon_close_btn').click(function() {
		tb_remove();
	});

	//video
	$('#close_btn3').livequery('click', function() {
		//var objVideoContainer=$(this).parent();

		//var objVideo=objVideoContainer.find('#movie');
		//objVideo.attr('value','test.swf');
		tb_remove();
	});

	//clickable callouts
	$('.callout').not('#isi-rr').addClass('pointer');
	$('.callout').not('#isi-rr').click(function() {
		if ($(this).find('a').length) {
			var linkDest = $(this).find('a').attr('href');
			window.location = linkDest;
		};
	});

});


function trackLink(thisUrl,linkID){
    switch(linkID){
        case 'pi':
            trackPI();
            break;
        case 'pro':
            trackPro()
            break;
    }
    window.setTimeout("return true;",300);
}

function trackPI(){
    //atlas tag tracker
    $.ajax({
		type: "POST",
		url: "/handlers/tag-tracker.ashx",
		data: "url=http://view.atdmt.com/action/dihshr_NEWLIC_092009_Prescribing_Information",
		success: function(msg){
			
	    }
	});
	
}
function trackPro(){
    //atlas tag tracker
    $.ajax({
	    type: "POST",
	    url: "/handlers/tag-tracker.ashx",
	    data: "url=http://view.atdmt.com/action/dihshr_NEWLIC_092009_For_Health_Care_Professionals",
	    success: function(msg){
			
        }
    });
    
}
function openWin(url){
    window.open(url);
}
function closeConfirm(){
    $('div#ddg_email_step1').removeClass('flarehide');
    $('div#ddg_email_confirmation').removeClass('flareshow');
    $('div#ddg_emaildiv').removeClass('flareshow');
}

//show hide unsubscribe

if (!document.getElementById)
{
if (document.all)
{
document.getElementById = function(p_id) { return document.all[p_id]; };
}
}


function hideElement()
{

for (var i = arguments.length - 1; i >= 0; --i)
{
if (document.getElementById(arguments[i]).className != "hideElement")
{
document.getElementById(arguments[i]).className = "hideElement";
}
}
}

function showElement()
{

for (var i = arguments.length - 1; i >= 0; --i)
{
if (document.getElementById(arguments[i]).className != "showElement")
{
document.getElementById(arguments[i]).className = "showElement";
}
}
}

function validateEmail(thisEmail){
    if(thisEmail.search(/^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/) == -1){
        return false;
    }
    else return true;
}

