window.root = '/';
var plIsAutoLoad = false;
var imgswaps = new Array();
var clientid = '';

function rollOn(imageName)
{
	document.images[imageName].src = eval('img_' + imageName + '_over').src;
}

function rollOff(imageName)
{
	document.images[imageName].src = eval('img_' + imageName + '_off').src;
}

//document.observe("dom:loaded", function() {
Event.observe(window, 'load', function() {
    var u = undefined;

    if (plIsAutoLoad != u && plIsAutoLoad) {
        plAutoLoad();      
    }

});

function validateSearchForm(searchTerm)
{
    var valid = true;
    if (document.getElementById(searchTerm).value == "Enter search term" || 
    document.getElementById(searchTerm).value.length == 0 ) {
 	    window.alert ("Please enter a search text.");
  		valid = false;
 	}
 	else
 	{
 	    var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
 		for (var i = 0; i < document.getElementById(searchTerm).value.length; i++) {
  		    if (iChars.indexOf(document.getElementById(searchTerm).value.charAt(i)) != -1) {
  			    window.alert ("Your search text has special characters. \nThese are not allowed.\nPlease remove them and try again.");
  			    valid = false;
  			    break;
  	        }
        }
     }
     return valid;
}

function toggleSculptraTreatmentQ(o)
{
    if (o.checked)
        Effect.BlindDown('SignUpFormSculptraTreatment');
    else
        Effect.BlindUp('SignUpFormSculptraTreatment');
}

/*
    General functions
*/
//swapImg(this.id, '/images/button_dk_submit.png', '/images/button_dk_submit_over.png')"
function swapImg(i, s1, s2) 
{
    isIE6 = /msie|MSIE 6/.test(navigator.userAgent);

    if (isIE6) 
    {
        //until supersleight issues get resolved swapImgIE6(i, s2);
        $(i).src = s2;      
    }
    else
    {        
        $(i).src = s2;
    }
    imgswaps[i] = s1;
}

function restoreImg(i) {

    var s1 = imgswaps[i];

    if (isIE6) {
        //until supersleight issues get resolved  swapImgIE6(i, s1);
        $(i).src = s1;
    }
    else {
        $(i).src = s1;
    }
}
function swapImgIE6(i, path)
{
    var shim = window.root + 'images/x.gif';
    var img = $(i);

    var _img = new Image();
    _img.src = path;

    img.style.width = (img.width || _img.width) + "px";
    img.style.height = (img.height || _img.height) + "px";

    img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + path + "', sizingMethod='scale')";        
    img.src = shim; 
}

function showPI() {
    window.open(' http://products.sanofi-aventis.us/sculptra_aesthetic/sculptra_aesthetic.pdf', 'pi', 'width=440,height=500,resizable=1,scrollbars=1');
}

function showHcpPI() {
    window.open('/docs/Sculptra clean PHYSICIAN June 15 2009.pdf', 'pi', 'width=440,height=500,resizable=1,scrollbars=1');
}


function hcpConfirmCancel() {
    jQuery("#hcp-confirm").fadeOut(); 
    return false;
}
function isHCP(url)
{
    var ret = false;
    jQuery("#hcp-confirm").fadeIn(); 
	return ret;
}

/*
    Physician locator functions - global nav
*/
var plGNDefaultValue = 'Enter zip code';
var plGNTransDuration = 0.5; // Seconds

function findPhysician()
{
    plGNShowOptions();
}

function plGNShowOptions(o)
{
    try {
	hideOpenBoxes("findPhys");
} catch(e) {}
	if ($('tools-wrapper-wide'))
	    Effect.Fade('tools-wrapper-wide', { duration: 0 });

	if ($('SSSwide'))
	    Effect.Fade('SSSwide', { duration: 0 });


	s.linkTrackVars = 'events'; s.linkTrackEvents = 'event23'; s.events = 'event23'; (s.tl(this, 'o', 'physcian locator initiations'));
    $('nav-locator-rollout-wrapper').style.zIndex = 22;
    Effect.Appear('nav-locator-rollout', { duration: plGNTransDuration });
    spotlight('scu154');
}

function plGNHideOptions(el)
{
    Effect.Fade('nav-locator-rollout', {duration: plGNTransDuration});
    
    if ($('tools-wrapper-wide'))
        Effect.Appear('tools-wrapper-wide', {duration: 0});

    if ($('SSSwide'))
        Effect.Appear('SSSwide', { duration: 0 });
        
    $('nav-locator-rollout-wrapper').style.zIndex = 12;
}

function plGNRestoreZipCodePrompt(el)
{
    if ($(el).value == '')
        $(el).value = plGNDefaultValue;
}

function plGNHideRollout(el)
{
    Effect.Fade('nav-locator-rollout', {duration: plGNTransDuration});
    $(el).blur();
}

/*
    Tabbed content layout
*/
var currentTab = 1;
var tabNavigation = true;

function rollLinkOn(el)
{
    $(el).style.cursor = 'pointer';
}

function rollLinkOff(el)
{
    $(el).style.cursor = 'default';
}

function layoutTabs(tabsNavigable)
{
    if (tabsNavigable)
        tabNavigation = true;
    else
        tabNavigation = false;
        
    var tabs = document.getElementsByClassName('tab-label');
    var labelContainer = $('tab-label-container');
	for (var i = 0; i < tabs.length; i++)
	{
	    if (tabNavigation)
	    {
    		$(tabs[i].id).onclick = function () {
	    		showTab(this.id);
		    	}
    		$(tabs[i].id).onmouseover = function () {
	    		rollLinkOn(this);
		    	}
    		$(tabs[i].id).mouseout = function () {
	    		rollLinkOut(this);
		    	}
        }
        else
        {
            changeClass(tabs[i].id, 'tab-disabled');
            $(tabs[i].id).onclick = function() {                
                TagToTip('tip-required', BORDERWIDTH, 0, OPACITY, 90, FADEIN, 250, FADEOUT, 250, PADDING, 0, FOLLOWMOUSE, false);
                setTimeout('UnTip()', 2000);
            }
        }
        var h = tabs[i].innerHTML;
        var p = h.split('++');
        tabs[i].innerHTML = '<span class="tab-label1">' + p[0] + '</span>' + '<br/><span class="tab-label2">' + p[1] + '</span>';        
        ////labelContainer.appendChild(tabs[i]);    
	}
	changeClass(tabs[0].id, 'tab-selected');
}

function selectTab(i)
{
}

function showTab(i)
{
    if (i.length > 1)
        i = i.substr(3, 1);
    hideTab(currentTab);
	changeClass('tab' + i + '-label', 'tab-selected');
    Effect.Appear('tab' + i, {duration: 0.7, queue: 'end'});
    addTabNavigation(currentTab);
    currentTab = i;

    var category = 'faq147';
    var intI = parseInt(i);
    
    switch(intI){
        case 1: category = 'faq147'; break;
        case 2: category = 'scu148'; break;
        case 3: category = 'faq149'; break;
        case 4: category = 'scu150'; break;
        case 5: category = 'scu151'; break;
        case 6: category = 'scu153'; break;
        case 7: category = 'scu152'; break;                    
    }    
    spotlight(category);
}

function hideTab(i)
{
    changeClass('tab' + i + '-label', 'tab-label');
    Effect.Fade('tab' + i, {duration: 0.7, queue: 'end'});
}

function addTabNavigation(i)
{
    if (!tabNavigation)
    {
        $('tab' + i + '-label').onclick = function () {
                showTab(i);
        }
    }
}

/*
    Utility functions
*/
function changeClass(elementId, toClass) {
    
    $(elementId).setAttribute('class', toClass);
    $(elementId).setAttribute('className', toClass);
}

function roundNumber(num, dec)
{
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function findPos(obj) {
	var curleft = curtop = 0;
    if (obj.offsetParent)
    {
        do
        {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
    return [curleft,curtop];
}

function setCookie(name, value, expires, path, domain, secure)
{
	var today = new Date();
	today.setTime(today.getTime());

	if (expires)
		expires = expires * 1000 * 60 * 60 * 24;
	var expireDate = new Date(today.getTime() + (expires));

	document.cookie = name + "=" + escape(value) +
		((expires) ? ";expires=" + expireDate.toGMTString() : "") + 
		((path) ? ";path=" + path : "") + 
		((domain) ? ";domain=" + domain : "") +
		((secure) ? ";secure" : "");
}

function getCookie(name)
{
	var start = document.cookie.indexOf(name + "=");
	var len = start + name.length + 1;
	if ((!start ) && (name != document.cookie.substring(0, name.length)))
		return null;

	if (start == -1)
		return null;

	var end = document.cookie.indexOf(";", len);
	if (end == -1)
		end = document.cookie.length;
	
	return unescape(document.cookie.substring(len, end));
}
/*-- physician profile--*/
var emailOpen = false;
var directionsOpen = false;
var peTimer, deTimer;

function attachProfileEvents() 
{
    if ($('email-physician-toggle')) {
        $('email-physician-toggle').observe("click", function(event) {            
            plShowPhysicianEmail();
        });
    }
    if ($('get-directions-toggle')) {
        $('get-directions-toggle').observe("click", function(event) {
            plShowGetDirections();
        });
    }    

}
function plShowPhysicianEmail() {    
    clearTimeout(peTimer);
    try {
        hideOpenBoxes("emailPhys");
    } catch (e) { };
        
    if ($('pl-profile-name') && $('profile-physician-name'))
        $('profile-physician-name').innerHTML = $('pl-profile-name').innerHTML
    if ($('email-physician-toggle'))
        $('email-physician-toggle').addClassName("active")

    Effect.Appear('pl-profile-physician', { duration: .5 });
    updateEmailPhysStatus();

    $('pl-profile-physician').observe('click', updateEmailPhysStatus);

    s.linkTrackVars='events';s.linkTrackEvents='event13';s.events='event13';(s.tl(this,'o','request consultation initiation'));    
}
function plHidePhysicianEmail() 
{    
    if ($('email-physician-toggle'))
        $('email-physician-toggle').removeClassName("active")
    Effect.Fade('pl-profile-physician', { duration: 0.5 });

    Effect.Fade('profile-physician-confirm', { duration: 0.5 });
    Effect.Appear('profile-physician-open', { duration: 0.5 });

    clearTimeout(peTimer);
    $('pl-profile-physician').stopObserving('click', updateEmailPhysStatus);
}

function showEmailPhysConfirm() 
{
    dcsMultiTrack('DCS.dcsuri', 'consumer/requestaconsulation.aspx', 'WT.registration', '1', 'WT.ti', 'Request a Consultation Success');
    spotlight('sculp164');
    //submit click    
    s.linkTrackVars='events';s.linkTrackEvents='event14';s.events='event14';void(s.tl(this,'o','request consultation completion'));            
    
    clearTimeout(peTimer);
    Effect.Fade('profile-physician-open', { duration: 0.5});
    Effect.Appear('profile-physician-confirm', { duration: 0.5});
    setTimeout('plHidePhysicianEmail()', 10000);

    //$('plEmailPhySubmit').writeAttribute('onclick', 'RequestConsultationConfirm(this)');
    //$('plEmailPhySubmit').setOpacity(1);            
}

function updateEmailPhysStatus() {    
    clearTimeout(peTimer);
    peTimer = setTimeout('plHidePhysicianEmail()', 50000);
    
}
function runEmailPhysician(o) {
    clearTimeout(peTimer);
    
    var items = $("pl-profile-physician").getElementsBySelector(".form-item");
    
    var valid = true;
    
    items.each(function(item, i) {
		var itemValid = true;
    	
    	var inputs = item.getElementsBySelector("input[type=text]");
	    var selects = item.getElementsBySelector("select");    		
	    
	    inputs.each(function(input, index) {	    	
	    	var v = input.value, e, d;
	    	if (v == "" || v.length == 0) {				    		
	    		itemValid = false;			
	    	};
	    	if (input.hasClassName("email-field")) {
	    		if (!/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(v)) itemValid = false;
	    	}
	    	if (input.hasClassName("num-field")) {
	    		if (!(!isNaN(v) && !/^\s+$/.test(v))) itemValid = false;
	    	}
	    		    		
	    });
	    selects.each(function(select, index) {
	    	if (select.selectedIndex <= 0) {				    		
	    		itemValid = false;			
	    	}
	    });	       	    
	    
	    item[(itemValid) ? "removeClassName" : "addClassName"]("invalid");	    
	    
	    if (!itemValid) valid = false;
    });
	var emails = $("pl-profile-physician").getElementsBySelector("input.email-field");
	if (emails.length == 2) 
    {
        if (emails[0].value != emails[1].value) 
        {
	        emails.each(function(el, i) {
	           el.up(".form-item").addClassName("invalid");
	       })
	       valid = false;
	    }
    }
	if (!valid) {
	    $('pl-profile-physician-validation').style.display = 'block';
	}

    if (valid) {
        $('pl-profile-physician-validation').style.display = 'none';

        var busname = $(clientid + 'pl_profile_practice');

        if (busname != null) {
            practice = busname.innerHTML;                    
        }

        var physfirstname = '';
        var physlastname = '';        
        
        if( $(clientid + 'pl_profile_firstname') != null )        
        {
            physfirstname = $(clientid + 'pl_profile_firstname').value;
        }

        if ($(clientid + 'pl_profile_lastname') != null) {
            physlastname = $(clientid + 'pl_profile_lastname').value;
        }
                        
        var toEmail =  document.getElementById(clientid + 'pl_profile_email').value;
        var data = '';
        data += 'firstName=' + escape(o.FirstName.value);
        data += '&lastName=' + escape(o.LastName.value);
        data += '&email=' + escape(o.Email.value);
        //simply the repeat email data += '&reEmail=' + escape(o.ReEmail.value);
        data += '&phone1=' + escape(o.Phone1.value);
        data += '&phone2=' + escape(o.Phone2.value);
        data += '&phone3=' + escape(o.Phone3.value);
        data += '&contactMethod=' + escape(o.ContactMethod.options[o.ContactMethod.selectedIndex].value);
        //data += '&interestedIn=' + escape(o.InterestedIn.options[o.InterestedIn.selectedIndex].value); ;
        data += '&toEmail=' + toEmail;
        data += '&practice=' + practice;
        data += '&physfirstname=' + physfirstname;
        data += '&physlastname=' + physlastname;     
        data += '&physID=' + ((window.location.href.indexOf("id=") != -1) ? window.location.href.split("id=")[1] : "");
        
        var urlForEmail = document.getElementById("SendToPhys");
        if (urlForEmail == '')
            var urlForEmail = '/util/send-to-physician.aspx';
                
        new Ajax.Request(urlForEmail, { method: 'post', parameters: data, onSuccess: function(transport) { showEmailPhysConfirm() } });
        
        $('confirm-msg').innerHTML = "Your email has been sent to Dr. " + physlastname;
        
    }
    return false;
}

function togglePhysTabs(index) {    
    var togs = $$("#pl-tabbed-nav .toggle"),
        contents = $$("#pl-tabbed-content .tabbed"),
        activeClass = "active-toggle",
        activeTab = $$("#pl-tabbed-nav .active-toggle");

    if (!!activeTab.length && activeTab[0] != togs[index]) {        
        activeTab[0].removeClassName(activeClass);
    }
    
    togs[index].addClassName(activeClass);

    var shown = contents.splice(index, 1)[0];

    contents.each(function(el, i) {
        el.hide();
    });
    shown.show();
    
}

function showMapPanel() {
    if ($('get-directions-toggle'))
        $('get-directions-toggle').removeClassName("active")
    
    togglePhysTabs(0);
}

function mapChangeLocation() {
    $('pl-tabbed-nav-util').hide();
    $('pl-map-tab').hide();
    $('pl-driving-map-wrapper').hide();
    $('pl-profile-map-wrapper').show();
            
    $('resultsDiv').hide();
    $('pl-profile-directions').show();
    $('pl-directions-tab').show();
}

function plShowGetDirections() {
    
    s.linkTrackVars = 'prop34,eVar26,events'; s.prop34 = "initiation"; s.eVar26 = "pl-driving-directions-initiation"; s.linkTrackEvents = 'event18'; s.events = 'event18'; (s.tl(this, 'o', 'pl-driving-directions-initiation'));
    
	try {
		hideOpenBoxes("directions");
	} catch(e) {}

    if ($('get-directions-toggle'))
        $('get-directions-toggle').addClassName("active")

    togglePhysTabs(1);    
    
    var busname = $(clientid + 'pl_profile_practice');   
    
    var street = $(clientid + 'pl_profile_street');
    if (street != null)
        $('Tstreet').value = street.innerHTML;

    var city = $(clientid + 'pl_profile_city');    
    if (city != null)
        $('Tcity').value = city.innerHTML;

    var state = $(clientid + 'pl_profile_state');
    if (state != null)
        $('Tstate').value = state.innerHTML;

    var zip = $(clientid + 'pl_profile_zip');
    if (zip != null)
        $('Tpostalcode').value = zip.innerHTML;
        
    updateEmailPhysStatus();    
}
function plHideGetDirections() 
{
    if ($('get-directions-toggle'))
        $('get-directions-toggle').removeClassName("active")
    
    if( $('pl-profile-directions'))
        $('pl-profile-directions').hide();

    if ($('profile-directions-confirm'))
        $('profile-directions-confirm').hide();
            
    if( $('profile-directions-open'))
        $('profile-directions-open').show();  
    
    //clearTimeout(deTimer);
}
function updateDirectionsStatus() {
    clearTimeout(deTimer);
    deTimer = setTimeout('plHideGetDirections()', 30000);
}

function swapDirections() 
{
    var leftputs = $$("#form-swap-left input[type=text]");
    var rightputs = $$("#form-swap-right input[type=text]");

    if (leftputs.length != rightputs.length) return;

    leftputs.each(function(item, index) {
        var val1 = leftputs[index].value;
        var val2 = rightputs[index].value;

        leftputs[index].value = val2;
        rightputs[index].value = val1;
    });

}
function showDirectionsConfirm() {
    //clearTimeout(deTimer);
    s.linkTrackVars = 'prop35,events'; s.prop35 = "submit"; s.linkTrackEvents = 'event19'; s.events = 'event19'; (s.tl(this, 'o', 'pl-driving-directions-submit'));
    
    $('profile-directions-open').hide();
    $('profile-directions-confirm').show();
   // setTimeout('plHidePhysicianEmail()', 3000);
}
function spotlight(category) {
    var axel = Math.random() + "";
    var a = axel * 10000000000000;
                                                          
    var mysrc = 'http://fls.doubleclick.net/activityi;src=3012733;type=scu163;cat=' + category + ';ord=1;num=' + a + '?';    
    var iframe = new Element("iframe", {
        src: mysrc,
        scrolling: 'no',
        frameborder: 0,
        width: 1,
        heigh: 1
    });

    Element.insert(document.body, iframe);
    
    if (category == 'phelissa' || category == 'scu144') {
        s.linkTrackVars = 'prop28,eVar21,events'; s.prop28 = "Video-BeforeAfter-Elissa"; s.eVar21 = "Video-BeforeAfter-Elissa"; s.linkTrackEvents = 'event15'; s.events = 'event15'; (s.tl(this, 'o', 'video-beforeafter-elissa'));              
    }

    if (category == 'phfranca' || category == 'scu143') {
        s.linkTrackVars = 'prop29,eVar22,events'; s.prop29 = "Video-BeforeAfter-Franca"; s.eVar22 = "Video-BeforeAfter-Franca"; s.linkTrackEvents = 'event16'; s.events = 'event16'; (s.tl(this, 'o', 'video-beforeafter-franca'));
    }
    if (category == 'phrenata' || category == 'scu145') {
        s.linkTrackVars = 'prop30,eVar23,events'; s.prop30 = "Video-BeforeAfter-Renata"; s.eVar23 = "Video-BeforeAfter-Renata"; s.linkTrackEvents = 'event17'; s.events = 'event17'; (s.tl(this, 'o', 'video-beforeafter-renata'));
    }

    /*Receipe A*/
    if (category == 'elissaA' ) {
        s.linkTrackVars = 'prop28,prop31,eVar21,eVar24,events'; s.prop28 = 'Video-BeforeAfter-Elissa'; s.prop31 = 'BTA-A'; s.eVar21 = 'Video-BeforeAfter-Elissa'; s.eVar24 = 'BTA-A'; s.linkTrackEvents = 'event15,event28'; s.events = 'event15,event28'; (s.tl(this, 'o', 'video-beforeafter-elissa'));
    }
    if (category == 'francaA') {
        s.linkTrackVars = 'prop29,prop31,eVar22,eVar24,events'; s.prop29 = 'Video-BeforeAfter-Franca'; s.prop31 = 'BTA-A'; s.eVar22 = 'Video-BeforeAfter-Franca'; s.eVar24 = 'BTA-A'; s.linkTrackEvents = 'event16,event28'; s.events = 'event16,event28'; (s.tl(this, 'o', 'video-beforeafter-franca'));
    }
    if (category == 'renataA' ) {
        s.linkTrackVars = 'prop30,prop31,eVar23,eVar24,events'; s.prop30 = 'Video-BeforeAfter-Renata'; s.prop31 = 'BTA-A'; s.eVar23 = 'Video-BeforeAfter-Renata'; s.eVar24 = 'BTA-A'; s.linkTrackEvents = 'event17,event28'; s.events = 'event17,event28'; (s.tl(this, 'o', 'video-beforeafter-renata'));
    }
    /*Receipe B*/
    if (category == 'elissaB') {
        s.linkTrackVars = 'prop28,prop32,eVar21,eVar25,events'; s.prop28 = 'Video-BeforeAfter-Elissa'; s.prop32 = 'BTA-B'; s.eVar21 = 'Video-BeforeAfter-Elissa'; s.eVar25 = 'BTA-B'; s.linkTrackEvents = 'event15,event29'; s.events = 'event15,event29'; (s.tl(this, 'o', 'video-beforeafter-elissa'));
    }
    if (category == 'francaB') {
        s.linkTrackVars = 'prop29,prop32,eVar22,eVar25,events'; s.prop29 = 'Video-BeforeAfter-Franca'; s.prop32 = 'BTA-B'; s.eVar22 = 'Video-BeforeAfter-Franca'; s.eVar25 = 'BTA-B'; s.linkTrackEvents = 'event16,event29'; s.events = 'event16,event29'; (s.tl(this, 'o', 'video-beforeafter-franca'));
    }
    if (category == 'renataB') {
        s.linkTrackVars = 'prop30,prop32,eVar23,eVar25,events'; s.prop30 = 'Video-BeforeAfter-Renata'; s.prop32 = 'BTA-B'; s.eVar23 = 'Video-BeforeAfter-Renata'; s.eVar25 = 'BTA-B'; s.linkTrackEvents = 'event17,event29'; s.events = 'event17,event29'; (s.tl(this, 'o', 'video-beforeafter-renata'));
    }
}

/*-- physician profile email directions --*/
var viewPxPin = "pl_profile_sitelink_wrapper";
var viewPxDiv = "pl-profile-extwarn";
var extUrl = '';

function hidePxWebsite() {
    Effect.Fade(viewPxDiv, { duration: 0.5 }); 
};

function showPxWebsite(url) {
    hideOpenBoxes('physExitSite');

    extUrl = url;

    var pinned = $(viewPxPin);
    $(document.body).insert({ bottom: $(viewPxDiv) });
        
    var pos = Element.cumulativeOffset(pinned),
        pinsize = [pinned.getWidth(), pinned.getHeight()];

    offset = {
        x: pos[0] + "px",
        y: pos[1] + pinsize[1] + "px"
    };

    $(viewPxDiv).setStyle({
        left: offset.x,
        top: offset.y
    });
    
    Effect.Appear(viewPxDiv, { duration: 0.5 });

    return false;
};


function continuePxWebsite() {
    dcsMultiTrack('DCS.dcssip', extUrl, 'DCS.dcsuri', '', 'WT.ti', 'Outside Link', 'WT.dl', "24");
    window.open(extUrl);
    Effect.Fade(viewPxDiv, { duration: 0.5 });
}

/*-- physician profile email directions --*/
var emailPhyDirectionsOpen = false,
    emailPhyDirections = "profile-tools-email-open",
    emailPhyDirectionsBody = "profile-tools-email-open-body",
    emailPhyDirectionsConfirm = "profile-tools-email-open-confirm",
    emailPhyDirectionsProgress = "profile-tools-email-open-confirm",
    emailPhyDirectionsValidateDiv = "profile-tools-email-validate",
    emailPhyDirectionsValid = true,
    pdtimer = null;

function hideEmailPhysicianDirections() {
    Effect.Fade('profile-tools-email-open', { duration: 0.5 });
};

function emailPhysicianDirections(how) {
    hideOpenBoxes('physDirections');

    var div = $(emailPhyDirections),
        size = {x: 297, y: 255},
        offset;

    if (!emailPhyDirectionsOpen) {        
        
        $(document.body).insert({ bottom: div });

        how = (how && typeof how === "string") ? how : "top";
        switch(how){
            case "top":

                var pinned = $('pl-tabbed-nav'),
                    pos = Element.cumulativeOffset(pinned),
                    pinsize = [pinned.getWidth(), pinned.getHeight()];

                offset = {
                    x: pos[0] + pinsize[0] - size.x + "px",
                    y: pos[1] + pinsize[1] + "px"
                };

            break;
            case "bottom":
                var pinned = $('resultUtility'),
                    pos = Element.cumulativeOffset(pinned),
                    pinsize = [pinned.getWidth(), pinned.getHeight()];

                offset = {
                    x: pos[0] + pinsize[0] - size.x + "px",
                    y: pos[1] - size.y + "px"
                };        
            
                break;            
        }

        div.setStyle({
            left: offset.x,
            top: offset.y
        });
        
        Effect.Appear(div, { duration: 0.5 });
        if (!emailPhyDirectionsValid)
            Effect.Appear(emailPhyDirectionsValidateDiv, { duration: 0.0 })

    }
    else
        closeEmailPhyDirections();    
        
};


function resetEmailPhyDirectionsValidation() {
    var inputs = $("profile-tools-email-open-body").select('input');
    inputs.each(function(input, index) {
        input.removeClassName("invalid");
    });
}

function updateEmailPhyDirectionsPageStatus() {
    clearTimeout(pdtimer);
    pdtimer = setTimeout('closeEmailPhyDirections()', 15000);
}

function closeEmailPhyDirections() {
    clearTimeout(pdtimer);
    Effect.Fade(emailPhyDirections, { duration: 0.5 });
    emailPhyDirectionsValid = true;
    Effect.Fade(emailPhyDirectionsConfirm, { duration: 0.0, queue: 'end' });
    Effect.Fade(emailPhyDirectionsValidateDiv, { duration: 0.0, queue: 'end' });
    Effect.Appear(emailPhyDirectionsBody, { duration: 0.0, queue: 'end' });
}

function showEmailPhyDirectionsPageProgress() {
    document.getElementById(emailPhyDirectionsBody).style.display = 'none';
    document.getElementById(emailPhyDirectionsConfirm).style.display = 'none';
    document.getElementById(emailPhyDirectionsProgress).style.display = 'block';
}

function showEmailPhyDirectionsPageConfirm() {
    Effect.Fade(emailPhyDirectionsBody, { duration: 0.5, queue: 'end' });
    Effect.Appear(emailPhyDirectionsConfirm, { duration: 0.5, queue: 'end' });
    setTimeout('closeEmailPhyDirections()', 3000);
}

function runEmailPhysDirectionsSendToAFriend(o) {
    clearTimeout(pdtimer);
    s.linkTrackVars = 'prop37,events'; s.linkTrackEvents = 'event31'; s.prop37 = 'email'; s.events = 'event31'; (s.tl(this, 'o', 'pl-driving-directions-email'));
    
    var inputs = $(emailPhyDirectionsBody).select('input');
    var valid = true;
    var emailto = '';
   
    inputs.each(function(input, index) {
        var itemValid = true;
        var v = input.value, e, d;

        if (v == "" || v.length == 0) {
            itemValid = false;
        };

        if (input.hasClassName("email-field")) {
            if (!/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(v)) itemValid = false;

            emailto = input.value;
        }

        if (!itemValid) valid = false;
        input[(itemValid) ? "removeClassName" : "addClassName"]("invalid");

    });

    if (!valid) {
        emailPhyDirectionsValid = false;
        $(emailPhyDirectionsValidateDiv).show();
    }  
    if (valid) {
        //emailPhyDirectionsValid = false;
        $(emailPhyDirectionsValidateDiv).hide();
        var title = (document.title.indexOf(' | ') != -1 ? escape(document.title.split(' | ')[0]) : escape(document.title));
       
        var data = getDirectionData();            
        data += '&pageTitle=' + title;
        data += '&pageLink=' + escape(window.location.href);        
        data += '&toEmail=' + escape(emailto);
        
        var urlForEmail = '/util/send-driving-directions.aspx';

        new Ajax.Request(urlForEmail, { method: 'post', parameters: data, onSuccess: function(transport) { showEmailPhyDirectionsPageConfirm() } });

    }

    return false;
}


/*-- overlay class --*/
var myFlashBox;
var mytvFlashBox;

Event.observe(window, 'load', function() {
    myFlashBox = new FlashBox();
    // determine whether to launch overlay immediately
    var querystrs = window.location.href.toQueryParams();
    if (querystrs.overlay) {
        window.location.href = "/consumer/patient-testimonial.aspx";
        //no longer show overlay        
        //myFlashBox.show();
    };

    mytvFlashBox = new tvFlashBox();
    // determine whether to launch overlay immediately
    var querystrs = window.location.href.toQueryParams();
    if (querystrs.tvoverlay) {
        window.location.href = "/consumer/television-commercial.aspx";
        mytvFlashBox.show();
    };
    
    if (querystrs.pi)
        pirequest();

});
function showFlashOverlay() {
    try {               
        myFlashBox.show();        
    } catch (e) { }

}

//DS
//var mytvFlashBox;

//Event.observe(window, 'load', function() {
//    mytvFlashBox = new tvFlashBox();
//    // determine whether to launch overlay immediately
//    var querystrs = window.location.href.toQueryParams();
//    if (querystrs.tvoverlay) {        
//        mytvFlashBox.show();
//    };
//});
function showFlashTV() {
    try {
        mytvFlashBox.show();
    } catch (e) { }

}
// end DS
function videoOnLoad(i) {
    //franca video
    if (i == 2) {
        s.linkTrackVars = 'prop6,eVar1,events'; s.prop6 = "Video-Franca"; s.eVar1 = "Video-Franca"; s.linkTrackEvents = 'event5'; s.events = 'event5'; (s.tl(this, 'o', 'video-franca'));
    }

    //tv video
    if (i == 3) {
        s.linkTrackVars = 'prop27,eVar14,events'; s.prop27 = "Video-TV-Commercial"; s.eVar14 = "Video-TV-Commercial"; s.linkTrackEvents = 'event12'; s.events = 'event12'; (s.tl(this, 'o', 'video-tv-commercial'));
    }
    if (i == 4) {
        s.linkTrackVars = 'prop33,eVar19,events'; s.prop33 = "Video-Beauty_Conversations"; s.eVar19 = "Video-Beauty_Conversations"; s.linkTrackEvents = 'event30'; s.events = 'event30'; (s.tl(this, 'o', 'video-beauty_conversations'));
    }
}
function videoOnPlay(i) {
    
    //how sculptra works
    if (i == 1) {
            s.linkTrackVars = 'prop25,eVar11,events'; s.prop25 = "Video-Moo"; s.eVar11 = "Video-Moo"; s.linkTrackEvents = 'event6'; s.events = 'event6'; (s.tl(this, 'o', 'video-moo'));
        }
    }
function videoOnStop(i) {

    //how sculptra works
    if (i == 1) {
        spotlight('how137');
    }
    //franca video
    if (i == 2) {
        spotlight('scu161'); 
    }
    //tv video
    if (i == 3) {
        spotlight('sculp872');
    } 
}
var FlashBox = Class.create({
    options: {
        src: 'javascript:false;' //javascript:false;document.write("");
    },
    visible: false,
    flashEmbed: function() { },
    bound: null,

    initialize: function() {
        this.isMac = (navigator.appVersion.indexOf("Mac") != -1) ? true : false;
        if (this.isMac) $(document.body).addClassName("mac-user");
        
        this.flashEmbed = function() {
            $("flashBox").update("" +
		        "<div class='boxPad'>" +
		        "<div id='flashOverlayHolder'></div>" +
		        "<div id='flashOverlayClose'><a href='javascript:myFlashBox.hide();'>close</a></div>" +
		        "</div>"
	        ); 	        

	        var flashvars = {	            	            
                autoStart: "true",
                autoStartId: 2,
                showVolume: "true"
            };

            var params = {
                wmode: 'transparent',
                base: '../docs',
                allowscriptaccess: "always",
                allowfullscreen: "true"
            };

            swfobject.embedSWF('../docs/videoSection.swf', 'flashOverlayHolder', '648', '513', '9.0.0', false, flashvars, params, false);

        }
        this.build();
    },

    build: function() {
        this.overlay = new Element("div", {
            "id": "flashBoxOverlay"
        }).hide();
        this.box = new Element("div", {
            "id": "flashBox"
        }).hide();
        this.boxFrame = new Element("iframe", {
            id: "flashBoxFrame",
            src: this.options.src,
            scrolling: 'no',
            frameborder: 0
        }).hide();
        this.boxFrame.setStyle({
            position: 'absolute',
            border: 'none',
            filter: 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)'
        });

        Element.insert(document.body, this.overlay);
        Element.insert(document.body, this.boxFrame);
        Element.insert(document.body, this.box);
    },

    show: function() {
        if (this.visible) return;
        this.visible = true;

        if (this.isMac) $(document.body).addClassName("overlay-mac");

        try {
            stopVideo();
        } catch (e) { }

        $(document.body).scrollTo();
        //Effect.ScrollTo(document.body);

        this.bound = this.bound || this.resize.bind(this);

        Event.observe(window, "resize", this.bound);
        Event.observe(window, "scroll", this.bound);

        this.resize();

        this.overlay.appear({ duration: 0.5, to: 0.85 })
        this.box.appear({ duration: 0.5 })
        this.boxFrame.show();

        this.flashEmbed();
        spotlight('scu160');
    },

    hide: function() {
        this.visible = false;

        if (this.isMac) $(document.body).removeClassName("overlay-mac");
        try {
            resumeVideo();
        } catch (e) { }

        Event.stopObserving(window, "resize", this.bound);
        Event.stopObserving(window, "scroll", this.bound);

        this.overlay.fade({ duration: 0.5 })
        this.box.fade({ duration: 0.5 })

        this.overlay.hide();
        this.box.update();
        this.box.hide();
        this.boxFrame.hide();
    },

    resize: function() {
        this.overlayOffset = (this.overlayOffset) ? this.overlayOffset : $("sectionbar");
        this.boxOffset = (this.boxOffset) ? this.boxOffset : $("subnav-wrapper");

        var overlayTopOffset = this.overlayOffset ? parseInt(this.overlayOffset.cumulativeOffset().top) : 100;
        var overlayBoxOffset = this.boxOffset ? parseInt(this.boxOffset.cumulativeOffset().top + this.boxOffset.getDimensions().height) : 100;

        var win = document.viewport.getDimensions();
        var doc = $(document.body).getDimensions();

        var box = {};
        box.width = parseInt(this.box.getStyle("width"));
        box.height = parseInt(this.box.getStyle("height"));

        var wrap = $("page");
        var wrapPos = wrap.getDimensions();
        wrapPos.offset = wrap.cumulativeOffset();

        var boxStyles = {};
        boxStyles.left = (parseInt(wrapPos.width) / 2) - (parseInt(box.width) / 2) + parseInt(wrapPos.offset.left) + "px";
        boxStyles.top = overlayBoxOffset + 35 + "px";

        this.overlay.setStyle({ height: doc.height - overlayTopOffset + "px", top: overlayTopOffset + "px" });
        this.box.setStyle(boxStyles);
        this.boxFrame.setStyle(boxStyles);

    }
});
//added DS

var tvFlashBox = Class.create({
    options: {
        src: 'javascript:false;' //javascript:false;document.write("");
    },
    visible: false,
    flashEmbed: function() { },
    bound: null,

    initialize: function() {
        this.isMac = (navigator.appVersion.indexOf("Mac") != -1) ? true : false;
        if (this.isMac) $(document.body).addClassName("mac-user");
        
        this.flashEmbed = function() {
            $("tvflashBox").update("" +
		        "<div class='tvboxPad'>" +
		        "<div id='tvflashOverlayHolder'></div>" +
		        "<div id='tvflashOverlayClose'><a href='javascript:mytvFlashBox.hide();'>close</a></div>" +
		        "</div>"
	        );

            var flashvars = {
                autoStart: "true",
                autoStartId: 3,
                showVolume: "true"
            };

            var params = {
                wmode: 'transparent',
                base: '../docs',
                allowscriptaccess: "always",
                allowfullscreen: "true"

            };

            swfobject.embedSWF('../docs/videoSection.swf', 'tvflashOverlayHolder', '640', '360', '9.0.0', false, flashvars, params, false);

        }
        this.build();
    },

    build: function() {
        this.overlay = new Element("div", {
            "id": "tvflashBoxOverlay"
        }).hide();
        this.box = new Element("div", {
            "id": "tvflashBox"
        }).hide();
        this.boxFrame = new Element("iframe", {
            id: "tvflashBoxFrame",
            src: this.options.src,
            scrolling: 'no',
            frameborder: 0
        }).hide();
        this.boxFrame.setStyle({
            position: 'absolute',
            border: 'none',
            filter: 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)'
        });

        Element.insert(document.body, this.overlay);
        Element.insert(document.body, this.boxFrame);
        Element.insert(document.body, this.box);

    },

    show: function() {
        if (this.visible) return;
        this.visible = true;

        if (this.isMac) $(document.body).addClassName("overlay-mac");

        try {
            stopVideo();
        } catch (e) { }

        $(document.body).scrollTo();
        //Effect.ScrollTo(document.body);

        this.bound = this.bound || this.resize.bind(this);

        Event.observe(window, "resize", this.bound);
        Event.observe(window, "scroll", this.bound);

        this.resize();

        this.overlay.appear({ duration: 0.5, to: 0.85 })
        this.box.appear({ duration: 0.5 })
        this.boxFrame.show();

        this.flashEmbed();
        spotlight('sculp540');
    },

    hide: function() {
        this.visible = false;

        if (this.isMac) $(document.body).removeClassName("overlay-mac");
        try {
            resumeVideo();
        } catch (e) { }

        Event.stopObserving(window, "resize", this.bound);
        Event.stopObserving(window, "scroll", this.bound);

        this.overlay.fade({ duration: 0.5 })
        this.box.fade({ duration: 0.5 })

        this.overlay.hide();
        this.box.update();
        this.box.hide();
        this.boxFrame.hide();
    },

    resize: function() {
        this.overlayOffset = (this.overlayOffset) ? this.overlayOffset : $("sectionbar");
        this.boxOffset = (this.boxOffset) ? this.boxOffset : $("subnav-wrapper");

        var overlayTopOffset = this.overlayOffset ? parseInt(this.overlayOffset.cumulativeOffset().top) : 100;
        var overlayBoxOffset = this.boxOffset ? parseInt(this.boxOffset.cumulativeOffset().top + this.boxOffset.getDimensions().height) : 100;

        var win = document.viewport.getDimensions();
        var doc = $(document.body).getDimensions();
        var box = {};
        box.width = parseInt(this.box.getStyle("width"));
        box.height = parseInt(this.box.getStyle("height"));

        var wrap = $("page");
        var wrapPos = wrap.getDimensions();
        wrapPos.offset = wrap.cumulativeOffset();

        var boxStyles = {};
        boxStyles.left = (parseInt(wrapPos.width) / 2) - (parseInt(box.width) / 2) + parseInt(wrapPos.offset.left) + "px";
        boxStyles.top = overlayBoxOffset + 35 + "px";

        this.overlay.setStyle({ height: doc.height - overlayTopOffset + "px", top: overlayTopOffset + "px" });
        this.box.setStyle(boxStyles);
        this.boxFrame.setStyle(boxStyles);

    }
});

//end added DS

/*-- for hiding open boxes --*/
var boxHideMap = {
    sendFriend: function() { closeEmailPage() },
    emailPhys: function() { plHidePhysicianEmail() },
    //directions: function() {plHideGetDirections()},
    findPhys: function() { plGNHideOptions() },
    physExitSite: function() { hidePxWebsite() },
    physDirections: function() { hideEmailPhysicianDirections() }
};

function hideOpenBoxes(sender) {
	
	var c = Object.clone(boxHideMap);
	if (c[sender]) delete c[sender];
	
	var a = Object.values(c);

	a.each(function(func, i) {
	    try {
	        func();
	    }
	    catch (e) { }

	});	
};



// movie functions
function thisMovie(movieName) {
	 if (navigator.appName.indexOf("Microsoft") != -1) {
		 return document.getElementById(movieName);//window[movieName];
	 } else {
		 return document[movieName];
	 }
}
function playVideo()
{
    thisMovie("videoSection").playVideo();
}
function pauseVideo()
{
    thisMovie("videoSection").pauseVideo();
}
function stopVideo()
{
    thisMovie("videoSection").stopVideo();
}
function seekVideo(offset)
{
    thisMovie("videoSection").seekVideo(offset);
}
function setVideoVolume(level)
{
    thisMovie("videoSection").setVideoVolume(level);
}
function fullScreenVideo(state)
{
    thisMovie("videoSection").fullScreenVideo(state);
}
function loadVideoById(id)
{
    thisMovie("videoSection").loadVideoById(id);
}
function resumeVideo()
{
    thisMovie("videoSection").resumeVideo();
}

function RequestConsultationConfirm(button) {

    var attributeclick = $(button).getAttribute('onclick');
    $(button).writeAttribute('onclick', '');
    $(button).setOpacity(0.5);
    
    runEmailPhysician(document.forms[0]);
    
    //if not valid reset button so it can be reclicked.
    //if (!runEmailPhysician(document.forms[0])) {        
        $(button).writeAttribute('onclick', attributeclick);
        $(button).setOpacity(1);
    //}
      
}


(function($, window) {
    var Video = this.PatientVideo = {
        curr: null,

        init: function() {
            // transcripts
            this.tranBtn = $("#patVideoToggle");
            this.tranCopy = $("#patVideoTranscriptSlide");

            this.tranBtn.bind("click", $.proxy(function() {
                var state = this.tranBtn.hasClass("active");
                this.tranBtn[state ? "removeClass" : "addClass"]("active");
                this.tranCopy[state ? "slideUp" : "slideDown"](1000);								
            }, this));

            // video selects
			var href = window.location.href.toLowerCase();
            this.videoSelects = $("#patVideoSelect li a");
            this.videoSelects.each($.proxy(function(index, el) {
				var elhref = $(el).attr("href").toLowerCase();
				if (href.indexOf(elhref) != -1) $(el).addClass("active");
                if ($(el).hasClass("active")) this.curr = index;
            }, this));

            // flash end
            this.bound = {};
            this.bound.replay = $.proxy(function(e) {
                e.preventDefault();
                this.replay();
            }, this);
            this.bound.next = $.proxy(function(e) {
                //e.preventDefault();
                this.next();
            }, this);

            this.screen = $("#patVideoFlashScreen");
            this.replayBtn = $("#patVideoReplay");
            this.nextBtn = $("#patVideoNext");

            this.replayBtn.bind("click", this.bound.replay);
            this.nextBtn.bind("click", this.bound.next);

            $.each([this.replayBtn, this.nextBtn], function(index, btn) {
                btn = $(btn);
                var icon = btn.find(".patVideoAction img");

                icon.css("opacity", 0.4);

                btn.bind({
                    "mouseenter": function() {
                        icon.css("opacity", 1);
                    },
                    "mouseleave": function() {
                        icon.css("opacity", 0.4);
                    }
                });
            });

            // expose for flash hook
            window.onVideoEnd = $.proxy(this.videoEnd, this);

        },

        videoEnd: function() {
            this.screen.show();
        },

        replay: function() {
            this.screen.hide();
            playVideo();
        },

        next: function() {            
            var next = this.curr,
                vids = this.videoSelects;
            if (next !== null) {
                var nextVideo = vids[(next + 1 > vids.length - 1) ? 0 : next + 1];                
                window.location.href = $(nextVideo).attr("href");
            }
        }

    };

})(window.jQuery, window);

