﻿function openBMICalc()
{
   openChromelessWindow('../interactive/interactivehost.aspx?module=bmi',600,475); 
}

function openSurvey()
{
   openChromelessWindow('../interactive/interactivehost.aspx?module=survey',600,400); 
}

function openExerciseGuide()
{
   openChromelessWindow('../interactive/interactivehost.aspx?module=exercise',600,400); 
}

function openCharactersPro()
{
   openChromelessWindow('../interactive/interactivehost.aspx?module=charpro',600,400); 
}

function openCharacters()
{
   openChromelessWindow('../interactive/interactivehost.aspx?module=char',600,400); 
}

function openMealPlanner()
{
   openChromelessWindow('../interactive/interactivehost.aspx?module=mealplanner',600,400); 
}

function openCatwalk()
{
   openChromelessWindow('../interactive/interactivehost.aspx?module=catwalk',600,377); 
}

function openChiltonVideo()
{
   openChromelessWindow('../interactive/interactivehost.aspx?module=chilton',640,520); 
}

function openDeFronzoVideo()
{
   openChromelessWindow('../interactive/interactivehost.aspx?module=defronzo',640,520); 
}

function openHowItWorksBranded()
{
   openChromelessWindow('../interactive/interactivehost.aspx?module=moab',720,405); 
}

function openHowItWorks()
{
   openChromelessWindow('../interactive/interactivehost.aspx?module=moa',720,405); 
}

function openSPPARMVideo()
{
   openChromelessWindow('../interactive/interactivehost.aspx?module=spparm',640,404); 
}

function openGlucoseLog()
{
    var rando = Math.ceil(Math.random() * 3)
    openPopupWindow('../downloads/bloodGlucose'+ rando +'.pdf',800,600); 
}

function openExternalLink(link, fromSite)
{
    //openFullFeatureWindow('../popups/externallinkhost.aspx?link='+ link +'&from='+ fromSite,800,600); 
    var newWindow = window.open('../popups/externallinkhost.aspx?link='+ link +'&from='+ fromSite, '_blank'); 
    newWindow.focus(); 
}


function openOfferWindow(which)
{
    var url;
    switch(which)
   {
        case 'ACTOS':
            url = '../popups/actosspecialoffer.htm';
            break;  
       case 'ACTOplusMet':
            url = '../popups/actoplusmetspecialoffer.htm';
            break;
       case 'Duetact':
            url = '../popups/duetactspecialoffer.htm';
            break;  
   } 
   openPopupWindow(url,740,600); 
}

function openChromelessWindow(url, width, height)
{	
	if(width == null)
		width = 800;
	if(height == null)
		height = 600;
		
	var x = screen.availWidth / 2 - (width / 2);
	var y = screen.availHeight / 2 - (height / 2);		
		
	if(typeof(winHost) == "object")
		if(!winHost.closed)
			winHost.close();
			    
	var strFeatures = "directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,height=" + height + ",width=" + width + ",top="+y+",left="+x;
	winHost = window.open(url, "winHost", strFeatures, true);
}

function openPopupWindow(url, width, height)
{	
	if(width == null)
		width = 800;
	if(height == null)
		height = 600;
		
	var x = screen.availWidth / 2 - (width / 2);
	var y = screen.availHeight / 2 - (height / 2);		
		
	if(typeof(winHost) == "object")
		if(!winHost.closed)
			winHost.close();
			
	var strFeatures = "directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,height=" + height + ",width=" + width + ",top="+y+",left="+x;
	winHost = window.open(url, "winHost", strFeatures, true);
}

function openFullFeatureWindow(url, width, height)
{	
	if(width == null)
		width = 800;
	if(height == null)
		height = 600;
		
	var x = screen.availWidth / 2 - (width / 2);
	var y = screen.availHeight / 2 - (height / 2);		
		
	if(typeof(winHost) == "object")
		if(!winHost.closed)
			winHost.close();
			
	var strFeatures = "directories=yes,location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes,height=" + height + ",width=" + width + ",top="+y+",left="+x;
	winHost = window.open(url, "winHost", strFeatures, true);
}

// AJAX helper functions...
function createRequestObject() {
    var tmpXmlHttpObject;
    
    //depending on what the browser supports, use the right way to create the XMLHttpRequest object
    if (window.XMLHttpRequest) { 
        // Mozilla, Safari would use this method ...
        tmpXmlHttpObject = new XMLHttpRequest();
	
    } else if (window.ActiveXObject) { 
        // IE would use this method ...
        tmpXmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    return tmpXmlHttpObject;
}

var http;
function GetImageProperties(url) {
    http = createRequestObject();
    http.open('get', url);
    http.onreadystatechange = processResponse;
    http.send(null);
}

var processCount = 0;
function processResponse() {
    if(http.readyState == 4){	
        var response = http.responseText;
        if(response == 'NOIMAGE')
        {
            if (processCount == 2)
            {
                alert('The image you have requested is not available.');
                processCount = 0;
            }
            else
            {
                processCount = processCount + 1;
                imageSource = '../contentgraphics/fullsize/';
                GetImageProperties('imagehelper.ashx?fileName='+ imageToEnlarge); //return response; //alert('The image you have requested is not available.');
            }
        }
        else
        {   
            var props=response.split('|');
            //alert(props[0] +' x '+ props[1]); 
            openEnlargeImageWindow(props[0], props[1]);        
        } 
    }
}

function openEnlargeImageWindow(width, height)
{	
	var x = screen.availWidth / 2 - (width / 2);
	var y = screen.availHeight / 2 - (height / 2);		
	var scroll = 'no';
	if(typeof(winHost) == "object")
		if(!winHost.closed)
			winHost.close();
			
    if(width > screen.availWidth || height > screen.availHeight)
        scroll='yes';			
	var html = '<html><title>Enlarged Image</title><body style="margin:0px"><img src="' + imageSource + imageToEnlarge + '" /></body></html>';
	var strFeatures = "directories=no,location=no,menubar=no,resizable=no,scrollbars=" + scroll + ",status=no,toolbar=no,height=" + height + ",width=" + width + ",top="+y+",left="+x;
	winHost = window.open("", "winHost", strFeatures, true);
	
	var doc = winHost.document;
	doc.open();
	doc.write(html);
	doc.close();
}

var imageToEnlarge;
var imageSource;
function enlargeImage(fileName)
{
    processCount = processCount + 1;
    imageToEnlarge = fileName;
    imageSource = 'SiteImageHandler.ashx?path=';
    GetImageProperties('SiteImageHandler.ashx?getSize='+ fileName);
}