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');
}

var extUrl = '';
function warnExt(url)
{
    extUrl = url;
    Effect.Appear('pl-profile-extwarn', { duration: 0.5 });
    return false;
}

function continueExt() {    
    dcsMultiTrack('DCS.dcssip', extUrl, 'DCS.dcsuri', '', 'WT.ti', 'Outside Link', 'WT.dl', "24");        
    window.open(extUrl);
    Effect.Fade('pl-profile-extwarn', { duration: 0.5 });    
}

function cancelExt()
{
    Effect.Fade('pl-profile-extwarn', { duration: 0.5 });
}

function hcpConfirmCancel()
{
    Effect.Fade('hcp-confirm', { duration: 0.5 });
}
    
function hcpConfirmContinue(url)
{
    setCookie('isHCP', 'N');
    resolvelink(url);    
    //location.href = url;
}    

function isHCP(url)
{
    var ret = false;
//    if (getCookie('isHCP') == 'Y')
//	    ret = true;
//    else
        Effect.Appear('hcp-confirm', { duration: 0.5 });
	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});
        
    $('nav-locator-rollout-wrapper').style.zIndex = 22;
    Effect.Appear('nav-locator-rollout', {duration: plGNTransDuration});
}

function plGNHideOptions(el)
{
    Effect.Fade('nav-locator-rollout', {duration: plGNTransDuration});
    if ($('tools-wrapper-wide'))
        Effect.Appear('tools-wrapper-wide', {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;
}

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: 0.5 });
    updateEmailPhysStatus();

    $('pl-profile-physician').observe('click', updateEmailPhysStatus);    
}
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('sacom079');
    
    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()', 30000);
    
}
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() } });

        physname = $(clientid + 'pl-profile-name').innerHTML;
        $('confirm-msg').innerHTML = "Your email has been sent to Dr. " + physname;
        
    }
    return false;
}

function plShowGetDirections() {

    clearTimeout(deTimer);
	try {
		hideOpenBoxes("directions");
	} catch(e) {}

    if ($('get-directions-toggle'))
        $('get-directions-toggle').addClassName("active")

    Effect.Appear('pl-profile-directions', { duration: 0.5 });    

    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")
    Effect.Fade('pl-profile-directions', { duration: 0.5 });

    Effect.Fade('profile-directions-confirm', { duration: 0.5 });
    Effect.Appear('profile-directions-open', { duration: 0.5 });  
    
    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);
    Effect.Fade('profile-directions-open', { duration: 0.5});
    Effect.Appear('profile-directions-confirm', { duration: 0.5});
   // setTimeout('plHidePhysicianEmail()', 3000);
}

function spotlight(category) {
    var axel = Math.random() + "";
    var a = axel * 10000000000000;
    
    var mysrc = 'http://fls.doubleclick.net/activityi;src=1089869;type=scup10;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);
}

/*-- overlay class --*/
var myFlashBox;

Event.observe(window, 'load', function() {
    myFlashBox = new FlashBox();
    // determine whether to launch overlay immediately
    var querystrs = window.location.href.toQueryParams();
    if (querystrs.overlay) {
        myFlashBox.show();
    };
});
function showFlashOverlay() {
    try {
        myFlashBox.show();
    } catch (e) { }

}
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) { }

        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.75 })
        this.box.appear({ duration: 0.5 })
        this.boxFrame.show();

        this.flashEmbed();
        spotlight('watch909');
    },

    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);

    }
});
/*-- for hiding open boxes --*/
var boxHideMap = {
	sendFriend: function() {closeEmailPage()},
	emailPhys: function() {plHidePhysicianEmail()},
	directions: function() {plHideGetDirections()},
	findPhys: function() {plGNHideOptions()}	
};

function hideOpenBoxes(sender) {
	
	var c = Object.clone(boxHideMap);
	if (c[sender]) delete c[sender];
	
	var a = Object.values(c);
	
	a.each(function(func, i) {
		func();
	});	
};



// 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);
    //}
      
}

