﻿loadGoogleTrackingJS();
window.onload = init;
var pageTracker;
var bVideoPlayed=false;
function init() {
    
    try {
        pageTracker = _gat._getTracker('UA-8299994-1');
        pageTracker._trackPageview();
        
    } catch(err) {}
}
var bCampaign=false;
$(document).ready(function() {
   fontResizer('1em','1.16em','1.33em');
   
   //prescribing info pdf
   $('a.lnkPrescribingInfo').click(function() {
        /*googlePageView('/pdf/prescribinginformation');
        googleEventTracker('PDF', '0-PDF-PI', 'Download');
        //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() {
        googlePageView('/video/PDF_Prescribing_Info');
        googleEventTracker('PDF', '0-PDF-PI', 'Download');
        //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() {
        /*googlePageView('/link/professional');
        googleEventTracker('OffsiteLink', '1-Lialda-Professional', 'Link');
        //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() {
        googlePageView('/link/shire.com');
        googleEventTracker('OffsiteLink', '1-Shire-Corporate', 'Link');
    });
   
   //inside story video
   $('a.insideStory').click(function() {
        googlePageView('/video/insidestory');
        //atlas tag tracker
        $.ajax({
			type: "POST",
			url: "/handlers/tag-tracker.ashx",
			data: "url=http://view.atdmt.com/action/dihshr_NEWLIC_092009_Inside_Story_Video",
			success: function(msg){
				
		    }
		});
		
		//webtrends tag tracker
        $.ajax({
			type: "POST",
			url: "/handlers/tag-tracker.ashx",
			data: "url=http://statse.webtrendslive.com/dcsi08j5h00000kf5ywwpuv75_2r4x/dcs.gif?&dcsdat=1253116651152&dcssip=localhost&dcsuri=/how-lialda-works.aspx&WT.tz=-4&WT.bh=11&WT.ul=en-US&WT.cd=32&WT.sr=1280x1024&WT.jo=Yes&WT.ti=How%20Lialda%20Works&WT.js=Yes&WT.jv=1.8&WT.ct=unknown&WT.bs=1280x543&WT.fv=10.0&WT.slv=Unknown&WT.tv=8.6.2&WT.dl=0&WT.ssl=0&WT.es=localhost/how-lialda-works.aspx&WT.cg_n=Lialda&WT.vt_f_a=2&WT.vt_f=2",
			success: function(msg){
				
		    }
		});
		
		
		
		
    });
    
   //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){
        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(){
        googlePageView('/video/emailafriend');
    });
   //email a friend box
   $('img#email_submit').livequery('click',function() {
        //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);
		}
		});
        
        
        
        
        
        //$('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');
        googlePageView('/video/emailafriend');
    });
    $('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);
		    }
		});
        
        
        googlePageView('/video/emailafriend');
        
        
        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).val() == "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');
        googlePageView('/video/close');
        tb_remove();
    });
});


function trackLink(thisUrl,linkID){
    switch(linkID){
        case 'pi':
            trackPI();
            break;
        case 'pro':
            trackPro()
            break;
    }
    window.setTimeout("openWin('"+thisUrl+"')",300);
}

function trackPI(){
    googlePageView('/pdf/prescribinginformation');
    googleEventTracker('PDF', '0-PDF-PI', 'Download');
    //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(){
    
    googlePageView('/link/professional');
    googleEventTracker('OffsiteLink', '1-Lialda-Professional', 'Link');
    //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,'_blank');
}
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;
}

function loadGoogleTrackingJS(){
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
}

function googlePageTracker(id){
    
    //stopper for moa
    if(!bVideoPlayed)googleEventTracker('Inside Story', '0-Button Begin', 'Video');
    bVideoPlayed=true;
}
function googleEventTracker(id,sEvent,sType,sNumber){
    try {
        pageTracker._trackEvent(id,sEvent,sType,sNumber);
        
    } catch(err) {}
    
}
function flashTrackEvent(id,sEvent,sType,sNumber){
    try {
        pageTracker._trackEvent(id,sEvent,sType,sNumber);
        
    } catch(err) {}
    
}
function googlePageView(id){
    
     try {
        pageTracker._trackPageview(id);
        
    } catch(err) {}
}
function flashTrackPage(id){
    
     try {
        pageTracker._trackPageview(id);
        
    } catch(err) {}
}
function dartTagBuilder(id){
    var axel = Math.random()+"";
    var a = axel * 10000000000000;
    return id+a+'?';
}
