// JavaScript Document

// JScript File

/*function about_faq_click(id)
{
    document.getElementById(id + '_img').src = '../DiabetesControlForLife/images/About_Us/FAQ/faq_topic_arrow_selected.jpg'
    document.getElementById(id + '_txt').className = 'aboutus_faq_topic_sel'
}*/

var min = 0.7;
var max = 1.4;
var header_max = 1.8;
var header_min = 0.9;
function setFontSize()
{
   var currentHeaderSize = ReadHeaderFontCookie();
   var currentParagraphSize = ReadParagraphFontCookie();
   var p = document.getElementsByTagName('p');
   var s = 0;
   for(i=0;i<p.length;i++)
   {
        if(p[i].className.indexOf("header") != -1 ||
        p[i].className.indexOf("h") != -1 ||
        p[i].className.indexOf("H") != -1)
        {
            if(currentHeaderSize != null)
                s = currentHeaderSize;
            else
                s = 0;
        }
        else
        {
            if(currentParagraphSize != null)
                s = currentParagraphSize;
            else
                s = 0;
        }
      if(s > 0)  
        p[i].style.fontSize = s + "em"
   }
}
function redirect()
{
    var url = ""+window.location.href;
    if(url == null)
    {
        var urlparts = url.split('/');
        if(urlparts[2].match('localhost'))
            url = urlparts[0]+ '//' + urlparts[2] + '/' + urlparts[3] + '/index.aspx';
        else
            url = urlparts[0]+ '//' + urlparts[2] + '/index.aspx';
    }
    window.location.href = url;
        
}
function redirect_noquery()
{
    var url = ""+window.location.href;
    var urlparts = url.split('/');
    var page;
    if(urlparts[2].match('localhost'))
    {
        page = urlparts[4];
        var index = page.indexOf('?');
        if(index > 0)
            page = page.substring(0,index);
        url = urlparts[0]+ '//' + urlparts[2] + '/' + urlparts[3] + '/' + page;
    }    
    else
    {
        page = urlparts[3];
        var index = page.indexOf('?');
        if(index > 0)
            page = page.substring(0,index);
        url = urlparts[0]+ '//' + urlparts[2] + '/' + page;
    }    
    window.location.href = url;
        
}
function increaseFont() 
{
   var p = document.getElementsByTagName('p');
   var s;
   for(i=0;i<p.length;i++)
   {
        if(p[i].className.indexOf("header") != -1 ||
        p[i].className.indexOf("h") != -1 ||
        p[i].className.indexOf("H") != -1)
        {
            if(p[i].style.fontSize) 
            {
             s = parseFloat(p[i].style.fontSize.replace("em",""));
            }
            else
            {
             s = 1.4;
            }
            if(s < header_max)
            {
             s += 0.1;
            }
            SetHeaderFontCookie(s);
        }
        else
        {
            if(p[i].style.fontSize) 
            {
             s = parseFloat(p[i].style.fontSize.replace("em",""));
            }
            else
            {
             s = 1.0;
            }
            if(s < max)
            {
             s += 0.1;
            }
            SetParagraphFontCookie(s);
        }
      p[i].style.fontSize = s + "em"
   }
}
function decreaseFont() 
{
   var p = document.getElementsByTagName('p');
   var s;
   for(i=0;i<p.length;i++) 
   {
        if(p[i].className.indexOf("header") != -1 ||
        p[i].className.indexOf("h") != -1 ||
        p[i].className.indexOf("H") != -1)
        {
            if(p[i].style.fontSize) 
            {
             s = parseFloat(p[i].style.fontSize.replace("em",""));
            }
            else
            {
             s = 1.4;
            }
            if(s > header_min)
            {
             s -= 0.1;
            }
            SetHeaderFontCookie(s);
        }
        else
        {
            if(p[i].style.fontSize) 
            {
             s = parseFloat(p[i].style.fontSize.replace("em",""));
            }
            else
            {
             s = 0.8;
            }
            if(s > min)
            {
             s -= 0.1;
            }
            SetParagraphFontCookie(s);
        }
        p[i].style.fontSize = s +"em"
    }   
}
function SetHeaderFontCookie(value) 
{
	createCookie('HeaderFontCookie',value,0.1);
}

function ReadHeaderFontCookie()
{
	return readCookie('HeaderFontCookie');
}
function SetParagraphFontCookie(value) 
{
	createCookie('ParagraphFontCookie',value,0.1);
}
function ReadParagraphFontCookie()
{
	return readCookie('ParagraphFontCookie');
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function openTerms()
{
    openWindow('Terms.aspx','Terms_and_Conditions','true');
}

function openCDETerms()
{
    openWindow('CDETerms.aspx','Terms_and_Conditions','true');
}

function openPrivacy()
{
    openWindow('http://www.abbott.com/global/url/content/en_US/0:0/general_content/General_Content_00029.htm','Privacy_Policy','false');
}

function openWindow(filename,title,relative)
{
    var urlfinal = "";
    if(relative == 'true')
    {
        var url = ""+window.location;
        var urlparts = url.split('/');
        if(urlparts[2].match('localhost'))
            urlfinal = urlparts[0]+ '//' + urlparts[2] + '/' + urlparts[3] + '/' + filename;
        else
            urlfinal = urlparts[0]+ '//' + urlparts[2] + '/' + filename;
    }
    else
    {
        urlfinal = filename;
    }
    window.open( urlfinal , title, 'width=970,height=800,scrollbars=1,resizable=yes');
}
function checkUsername(control, valid)
{
    var txt = control.controltovalidate;
    if(document.getElementById(txt).value.length > 5)
    {
        control.style.visibility = 'hidden';
        valid.IsValid = true;
    }
    else
    {
        control.style.visibility = 'visible';
        valid.IsValid = false;
    }
}
function checkPassword(control, valid)
{
    var txt = control.controltovalidate;
    if(document.getElementById(txt).value.length > 3)
    {
        control.style.visibility = 'hidden';
        valid.IsValid = true;
    }
    else
    {
        control.style.visibility = 'visible';
        valid.IsValid = false;
    }
}
function showVideo()
{
    var player = document.getElementById('rightads_player');
    if(player != null)
        player.style.visibility = 'visible';
}
function hideVideo()
{
    var player = document.getElementById('rightads_player');
    if(player != null)
        player.style.visibility = 'hidden';
}
function ddlpopup(value)
{
    var x = value;
    alert('value');
}
function popupReplyModal()
{
    var modalPopupBehavior = null;
    modalPopupBehavior = $find('ctl00_ImageCallout1_mpe_Reply');
    if(modalPopupBehavior != null)
    {
        modalPopupBehavior.show();
    }
}
function SuggestNewTopic()
{
    var modalPopupBehavior = null;
    modalPopupBehavior = $find('ctl00_ImageCallout1_mpe_SuggestTopic');
    if(modalPopupBehavior != null)
    {
        modalPopupBehavior.show();
    }
}
function popupLoginModalControl(continueTo)
{
    var modalPopupBehavior = null;
    modalPopupBehavior = $find('ctl00_ImageCallout1_mpe_Login');
    if(modalPopupBehavior != null)
    {
        if(continueTo != null)
            PageMethod("http://localhost/controls/global/ImageCallout.ascx","SetPageAfterLogin",['"url":"' + continueTo + '"'],success,failure);
        modalPopupBehavior.show();
    }
}
function PageMethod(pagePath, fn, paramArray, successFn, errorFn)
{
 var pagePath = window.location.pathname;
 var paramList = '';
 if (paramArray.length > 0)
 {
 for (var i=0; i<paramArray.length; i++)
 {
   if (paramList.length > 0) paramList += ',';
   paramList += paramArray[i];
   }
 }
 paramList = '{' + paramList + '}';
 //Call the page method
 $.ajax({
   type: "POST",
   url: pagePath + "/" + fn,
   contentType: "application/json; charset=utf-8",
   data: paramList,
   dataType: "json",
   success: successFn,
   error: errorFn
 })
;}
function success(returned)
{
    alert('Success:' + returned);
}
function failure(returned)
{
    alert('Failed:' + returned);
}
function popupEmailModalControl()
{
    var modalPopupBehavior = null;
    modalPopupBehavior = $find('ctl00_ImageCallout1_mpe_Email');
    if(modalPopupBehavior != null)
    {
        modalPopupBehavior.show();
    }
}
function popupEmailModal(value)
{
    var modalPopupBehavior = null;
    if(value == 'default')
    {
        modalPopupBehavior = $find('ctl00_mpe_Email');
    }
    else
    {
        modalPopupBehavior = $find('ctl00_ContentPlaceholderMain_Toolbar1_mpe_Email');
        var img = document.getElementById('ctl00_ContentPlaceholderMain_article_title_img');
        var imgEmail = document.getElementById('ctl00_ContentPlaceholderMain_Toolbar1_imgEmail');
        if(img != null && imgEmail != null)
            imgEmail.src = img.src;
    }
    if(modalPopupBehavior != null)
    {
        var player = document.getElementById('rightads_player');
        if(player != null)
            player.style.visibility = 'hidden';
        modalPopupBehavior.show();
    }
}

function popupPatientModalControl()
{
    var modalPopupBehavior = null;
    modalPopupBehavior = $find('ctl00_ImageCallout1_mpe_InvitePatient');
    if(modalPopupBehavior != null)
    {
        modalPopupBehavior.show();
    }
}



function popupNutrition()
{
    var modalPopupBehavior = $find('ctl00_ContentPlaceholderMain_mpe_NutritionInfo');
    if(modalPopupBehavior != null)
        modalPopupBehavior.show();
}

//function to show and hide the divs
function showHideDiv(thediv)
{
    if (document.getElementById(thediv).style.display=='')
    {
        document.getElementById(thediv).style.display = 'none';
    }
    if (document.getElementById(thediv).style.display=='none')
    {
        document.getElementById(thediv).style.display = 'block';
    }
    else
    {
        document.getElementById(thediv).style.display = 'none';
    }
}
function showHideDiv2(thediv)
{
    if (document.getElementById(thediv).style.display=='')
    {
        document.getElementById(thediv).style.display = 'none';
    }
    if (document.getElementById(thediv).style.display=='none')
    {
        document.getElementById(thediv).style.display = 'block';
    }
    else
    {
        document.getElementById(thediv).style.display = 'none';
    }
}
function Message(value)
{
    alert(value);
}

function advanceField(current, next)
{
    if(current.value.length == current.maxLength)
    {
        next.focus();        
    }
}
function setFocus(control)
{
    var c = null;
    var the_inputs=document.getElementsByTagName("input");
    for(var n=0;n<the_inputs.length;n++)
    {
        if(the_inputs[n].id.indexOf(control) > 0)
        {
            c = document.getElementById(the_inputs[n].id);
            break;
        }
    }
    if(c != null)
        c.focus();
}
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) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); 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];}
}

function warn_on_leave(site){
    var msg = "\nThis link will take you out of the Abbott Nutrition Division of\n"+
        "Abbott Laboratories worldwide web site.  Links which take you out\n"+                                                                  
        "of Abbott Laboratories worldwide web site are not under the control of\n"+                                                             
        "Abbott Laboratories, and Abbott Laboratories is not responsible for the\n"+                                                            
        "contents of any such site or any further links from such site.  Abbott\n"+
        "Laboratories is providing these links to you only as a convenience, and\n"+
        "the inclusion of any link does not imply endorsement of the linked site\n"+
        "by Abbott Laboratories.\n\n"+ 
        "Do you wish to leave this site?";

    var newwin = null;
    if(confirm(msg))
    {    
        window.open(site,"popup","");
	      if(newwin != null)
	        newwin.focus();
    }
    else
        return false;
}
