//
//    JavaScript include file for general use JS functions
//
function popup(url)
{
    //Description:  displays a disclaimer message, then redirects the browser to
    //              another URL (presumably an off-site page); this version should be 
    //              called by static HTML pages
    //ARGS:
    //    url           fully qualified URL for the destination
    redirectLink2(url, true, true, "", "");         

}

function redirectLink2(url, showWarning, useTracking, conditionName, trackData)
{
    //Description:  redirects the browser to another URL (presumably an off-site page),
    //              and optionally (1) displays a disclaimer message and (2) captures
    //              the referral in our logs for reporting;  this version should be 
    //              called by pages dynamically delivered through Open Market
    //ARGS:
    //    url           fully qualified URL for the destination
    //    showWarning   true/false whether to show popup warning for external links
    //    useTracking   (no longer used)
    //    conditionName the name of a condition to use in summary reporting (only useful if track=true)       
    //    trackData     the name of a tracking group to use in summary reporting (only useful if track=true)

    // always enter the simpletracker
    // get the stage if any for tracking
    var stage = getValue("Stage"); 
    var tmpMetricImg2 = new Image();
    tmpMetricImg2.src = "/images/simpletracker.gif?ConditionName="+conditionName+ "&Stage=" +stage+ "&Article=" +url+ "&View=Normal";

    // get the tracking  Always use two different images
    if ((trackData != "")&&(trackData != " ")&&(trackData != "%20")) {    
       var tmpMetricImg1 = new Image();
	 tmpMetricImg1.src = "/images/calltoaction.gif?ConditionName="+conditionName+"&Track="+ trackData;
    }
    
    if (showWarning == true)
    {
        alert('*You have just clicked on a link.  If you continue, you will leave the Medtronic Site and look at a web site run by someone else.  We do not review or monitor the content on the linked web site.  Medtronic is not responsible for any business dealings or transactions you may have with them, such as buying a product.  Your use of the linked web site is subject to the terms and conditions of that site.');
    }

    loc = unescape(url);	
    window.location.href = loc;        
}

function replaceLink2(url, showWarning, useTracking, conditionName, trackData)
{
    //Description:  redirects the browser to another URL (presumably an off-site page),
    //              and optionally (1) displays a disclaimer message and (2) captures
    //              the referral in our logs for reporting;  this version should be 
    //              called by pages dynamically delivered through Open Market
    //
    //	        Important Note:
    //		  replaceLink2 is identical to redirectLink2, however it uses location.replace() instead of location.href.
    //	        This means that it should be used to redirect a page in situations where you want to remove the last history entry.
    //              Generally, use redirectLink2 inside HREF="" on anchor tags, and use replaceLink2 when you want to redirect a page as it loads 
    //		  (Ex: Category Pages use this when only 1 assets exists in the category to preserve the use of the back button).
    //
    //ARGS:
    //    url           fully qualified URL for the destination
    //    showWarning   true/false whether to show popup warning for external links
    //    useTracking   (no longer used)
    //    conditionName the name of a condition to use in summary reporting (only useful if track=true)       
    //    trackData     the name of a tracking group to use in summary reporting (only useful if track=true)
    
    // always enter the simpletracker
    // get the stage if any for tracking
    var stage = getValue("Stage");  
    var tmpMetricImg2 = new Image();
    tmpMetricImg2.src = "/images/simpletracker.gif?ConditionName="+conditionName+ "&Stage=" +stage+ "&Article=" +url+ "&View=Normal";

    if ((trackData != "")&&(trackData != " ")&&(trackData != "%20")) {     
       var tmpMetricImg1 = new Image();
	 tmpMetricImg1.src = "/images/calltoaction.gif?ConditionName="+conditionName+"&Track="+ trackData;
    }
      
    if (showWarning == true)
    {
        alert('*You have just clicked on a link.  If you continue, you will leave the Medtronic Site and look at a web site run by someone else.  We do not review or monitor the content on the linked web site.  Medtronic is not responsible for any business dealings or transactions you may have with them, such as buying a product.  Your use of the linked web site is subject to the terms and conditions of that site.');
    }
    loc = unescape(url);
    window.location.replace(loc);        
}

function getValue(parameter) {
    //Description:      gets value of a parameter from the HTTP get string 
    //ARGS:
    //    parameter     the name of a query string parameter
    
    var HTTPGetString=window.location.href;
    var startPos = HTTPGetString.indexOf(parameter + "=")

    if (startPos > -1) {
        startPos = startPos + parameter.length + 1;
        var endPos = HTTPGetString.indexOf("&",startPos);
        var endPos2 = HTTPGetString.indexOf("#",startPos);
        if (endPos == -1) endPos = HTTPGetString.length;
        if(endPos2 != -1 && endPos2<endPos) endPos=endPos2 //remove ending # is present
        
        var parameterValue=unescape(HTTPGetString.substring(startPos,endPos));
        return( parameterValue );
     }
     return("");
}
   
function getStage(condStage) {
   //Description:       gets value of the stage from the ConditionStageName.
   //                   The form is "condition_stage"  (ie. Bradycardia_Diagnosis where
   //                   Bradycardia is the condition and Diagnosis is the stage.)
   //ARGS:
   //   condStage       the combined form of condition and stage.  The form is
   //                   "condition_stage"  (ie. Bradycardia_Diagnosis where
   //                   Bradycardia is the condition and Diagnosis is the stage.)
   
    var startPos = condStage.lastIndexOf("_")
    
    if (startPos > -1) 
        return( condStage.substring(startPos+1) );
    
    return("none");
}

function PrintFriendly(){
   //Description:       function to display the print-friendly version of the current page;
   //                   this version should be used by pages dynamically delivered through Open Market
   
   var HTTPString = window.location.href;
   var endPos = HTTPString.indexOf("#");
   if (endPos == -1){
   	var stringValue= HTTPString;
   }
   else {
   	var stringValue= HTTPString.substring(0,endPos);
   }
   
   var HTTPNewString = (stringValue + "&View=Print");
   PrintWindow = window.open(HTTPNewString,"printfriendly","width=625,height=500,resizable=yes,scrollbars=yes,menubar=yes,locationbar=yes,toolbar=yes");
   PrintWindow.focus();
}

function StageArt(strArticleName,strCondition,strStage) {
    //Description:       builds a link to a stage-level article page that is dynamically delivered through Open Market
    //ARGS:
    //   strArticleName     the asset name of an article in Open Market
    //   strCondition       the name of a Condition group in Open Market
    //   strStage           the corresponding stage - Diagnosis, Treatment, or Management
       
    if(strCondition==-1) {
        var strCondition = getValue("ConditionName");}
    if(strStage == -1) {
        var strStage = getValue("Stage"); }

    // check for anchor reference in ArticleName remove before escaping
    var anchor = '';
    var poundPos = strArticleName.indexOf('#');
    if (poundPos>=0) {
	anchor = strArticleName.substr(poundPos);
      strArticleName = strArticleName.substr(0,poundPos);
    }
        
    var strLink = ("/servlet/ContentServer?pagename=Medtronic/Website/StageArticle&ConditionName="+ escape(strCondition) +"&Stage="+ escape(strStage) +"&Article="+escape(strArticleName)+anchor );
    location.href = (strLink);
}

function ConditionArt(strArticleName,strCondition,isPatientStory) {
    //Description:       builds a link to a condition-level article page that is dynamically delivered through Open Market
    //ARGS:
    //   strArticleName     the asset name of an article in Open Market
    //   strCondition       the name of a Condition group in Open Market
    //   isPatientStory     true/false whether strArticleName refers to a patient story
        
    if(strCondition==-1) {
        var strCondition = getValue("ConditionName"); }

    // check for anchor reference in ArticleName remove before escaping
    var anchor = '';
    var poundPos = strArticleName.indexOf('#');
    if (poundPos>=0) {
	anchor = strArticleName.substr(poundPos);
      strArticleName = strArticleName.substr(0,poundPos);
    }  

    if(isPatientStory) {
        var strLink = ("/servlet/ContentServer?pagename=Medtronic/Website/Patient&ConditionName="+ escape(strCondition) +"&Article="+escape(strArticleName) + anchor); }
    else {
        var strLink = ("/servlet/ContentServer?pagename=Medtronic/Website/ConditionArticle&ConditionName="+ escape(strCondition) +"&Article="+escape(strArticleName) + anchor);}
    
    location.href = (strLink);
}

function ConditionStage(strCondition,strStage) {
    //Description:       builds a link to a condition stage page that is dynamically delivered through Open Market
    //ARGS:
    //   strCondition       the name of a Condition group in Open Market    
    //   strStage           the corresponding stage - Diagnosis, Treatment, or Management
    
    if(strCondition==-1) {
        var strCondition = getValue("ConditionName");}
    if(strStage == -1) {
        var strStage = getValue("Stage"); }
    
    var strLink = ("/servlet/ContentServer?pagename=Medtronic/Website/ConditionStage&ConditionName="+ escape(strCondition) +"&Stage="+ escape(strStage) );
    location.href = (strLink);
}

function FAQ(strFAQCategory,strCondition) {
    //Description:       builds a link to a FAQ page that is dynamically delivered through Open Market
    //ARGS:
    //   strFAQCategory     the name of an FAQCategory group in Open Market    
    //   strCondition       the name of a Condition group in Open Market    

    if(strCondition==-1) {
        var strCondition = getValue("ConditionName");}

    // check for anchor reference in strFAQCategory remove before escaping
    var anchor = '';
    var poundPos = strFAQCategory.indexOf('#');
    if (poundPos>=0) {
	anchor = strFAQCategory.substr(poundPos);
      strFAQCategory = strFAQCategory.substr(0,poundPos);
    }  

    var strLink = ("/servlet/ContentServer?pagename=Medtronic/Website/FAQ&ConditionName="+ escape(strCondition) +"&FAQ_Category="+ escape(strFAQCategory) + anchor );
    location.href = (strLink);
}

function FAQCategory(strCondition) {
    //Description:       builds a link to a FAQCategory page that is dynamically delivered through Open Market
    //ARGS: 
    //   strCondition       the name of a Condition group in Open Market

    if(strCondition==-1) {
        var strCondition = getValue("ConditionName");}

    var strLink = ("/servlet/ContentServer?pagename=Medtronic/Website/FAQCategory&ConditionName="+ escape(strCondition));
    location.href = (strLink);
}

function PatientCategory(strCondition) {
    //Description:       builds a link to a PatientCategory page that is dynamically delivered through Open Market
    //ARGS: 
    //   strCondition       the name of a Condition group in Open Market

    if(strCondition==-1) {
        var strCondition = getValue("ConditionName");}

    var strLink = ("/servlet/ContentServer?pagename=Medtronic/Website/PatientCategory&ConditionName="+ escape(strCondition) );
    location.href = (strLink);
}

function PhysicianCategory(strCondition) {
    //Description:       builds a link to a PhysicianCategory page that is dynamically delivered through Open Market
    //ARGS: 
    //   strCondition       the name of a Condition group in Open Market

    if(strCondition==-1) {
        var strCondition = getValue("ConditionName");}

    var strLink = ("/servlet/ContentServer?pagename=Medtronic/Website/PhysicianCategory&ConditionName="+ escape(strCondition) );
    location.href = (strLink);
}

function ProductCategory(strCondition) {
    //Description:       builds a link to a ProductCategory page that is dynamically delivered through Open Market
    //ARGS: 
    //   strCondition       the name of a Condition group in Open Market

    if(strCondition==-1) {
        var strCondition = getValue("ConditionName");}

    var strLink = ("/servlet/ContentServer?pagename=Medtronic/Website/ProductCategory&ConditionName="+ escape(strCondition) );
    location.href = (strLink);
}

function RelatedConditionCategory(strCondition) {
    //Description:       builds a link to a RelatedConditionCategory page that is dynamically delivered through Open Market
    //ARGS: 
    //   strCondition       the name of a Condition group in Open Market

    if(strCondition==-1) {
        var strCondition = getValue("ConditionName");}

    var strLink = ("/servlet/ContentServer?pagename=Medtronic/Website/RelatedConditionCategory&ConditionName="+ escape(strCondition) );
    location.href = (strLink);
}

function SafetyInformation(strCondition) {
    //Description:       builds a link to a SafetyInformation page that is dynamically delivered through Open Market
    //ARGS: 
    //   strCondition       the name of a Condition group in Open Market


    if(strCondition==-1) {
        var strCondition = getValue("ConditionName");}

    var strLink = ("/servlet/ContentServer?pagename=Medtronic/Website/SafetyCategory&ConditionName="+ escape(strCondition) );
    location.href = (strLink);
}

function FooterWin(newin) { //added for management template only
    footer=window.open(newin,"footer","resizable=yes,scrollbars=yes,width=760,height=425,top=100,left=100")
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
