/* 
===========================================================
	FONT ALTERNATE
===========================================================
*/

var normalSize = "1em";
var bigSize = "1.2em";
var normalLineHeight = "17px";
var bigLineHeight = "23px";

function increaseFontSize() {

	var d = document.getElementById('page-content');

	if(d.style.fontSize == bigSize)
	{
		d.style.fontSize = normalSize;
		d.style.lineHeight = normalLineHeight;
	} 
	else 
	{
		d.style.fontSize = bigSize;
		d.style.lineHeight = bigLineHeight;
	}
}


/* 
===========================================================
	SELECT FUNCTIONS
===========================================================
*/

function redirectURL(obj)
{
	var url = obj.options[obj.selectedIndex].value;
	
	resetProductFinder();
	
	if (url != "")
	{
		redirect(url);	
	}
}

function redirect(url)
{
	document.location = url;	
}

function resetESituation(obj)
{	
	var url = obj.options[obj.selectedIndex].value;
	obj.selectedIndex = 0; 
	
	redirect(url);
}

/* 
===========================================================
	IE DROPDOWN FIX
===========================================================
*/

function fixIeDropDown(select){

	var select = (typeof select == "string") ? document.getElementById(select) : select;

	// THIS FUNCTION IS ONLY CONCERNED WITH INTERNET EXPLORER NON-MULTIPLE SELECT NODES THAT HAVE A SPECIFIC WIDTH DEFINED
	if(!select.attachEvent || navigator.userAgent.indexOf("Opera") > -1 || select.multiple || select.currentStyle.width == "auto") { return; }

	var body = document.getElementsByTagName("body").item(0);

	var si = select.selectedIndex;

	var clone = select.cloneNode(true);
	clone.style.position = "absolute";
	clone.style.visibility = "hidden";
	clone.style.width = "auto";
	body.appendChild(clone);

	clone._initialOffsetWidth = select.offsetWidth;
	clone._initialOffsetHeight = select.offsetHeight;
	clone._autoWidth = clone.offsetWidth;

	clone = body.removeChild(clone);
	clone.style.visibility = "visible";
	clone.style.width = clone._initialOffsetWidth + "px";

	var span = document.createElement("span");
	span._isIeDropDownContainer = true;
	span.style.position = "relative";
	span.style.width = clone._initialOffsetWidth + "px";
	span.style.height = clone._initialOffsetHeight + "px";
	span.style.marginBottom = "-4"; //hmm...quirky...
	span.appendChild(clone);

	if (select.parentNode._isIeDropDownContainer){
		select.parentNode.parentNode.replaceChild(span, select.parentNode);
	}else{
		select.parentNode.replaceChild(span, select);
	}

	if (clone._autoWidth > clone._initialOffsetWidth){
		var expand = function(){
			event.srcElement.parentNode.style.zIndex = 1;
			event.srcElement.style.width = "auto";
			if (event.srcElement.offsetWidth > event.srcElement._initialOffsetWidth){
				event.srcElement.style.width = "auto";
			}else{
				event.srcElement.style.width = event.srcElement._initialOffsetWidth + "px";
			}
		};
		var contract = function(){
			event.srcElement.parentNode.style.zIndex = 0;
			event.srcElement.style.width = event.srcElement._initialOffsetWidth + "px";
		};
		clone.attachEvent("onactivate", expand);
		clone.attachEvent("ondeactivate", contract);
		clone.attachEvent("onchange", contract);
	}
	clone.selectedIndex = si;
}

/* 
===========================================================
	DISCLAIMER
===========================================================
*/

function showDisclaimer (linkId) 
{
	var disclaimerDiv = document.getElementById("disclaimer");
	var disclaimerIframe = document.getElementById("disclaimer-iframe");
	var divText = document.getElementById("disclaimer-txt");
	var divContainer = document.getElementById("container");

	var disclaimerText = "This link will take you to a Web site to which this ";
	disclaimerText += "<a href='/privacy-policy.jsp' title='Privacy Policy'>Privacy Policy</a> ";
	disclaimerText += "does not apply. We encourage you to read the Privacy Policy of every Web site you visit.";

	CenterDiv(disclaimerDiv, disclaimerIframe, divContainer);

	divText.innerHTML = disclaimerText;
	document.getElementById("link").href = linkId;
}

function closeDisclaimer(){
	document.getElementById('disclaimer').style.display = 'none';
	document.getElementById('disclaimer-iframe').style.display = 'none';
}

/*
===========================================================
	BRAND DIFFERENCE VIDEOS
===========================================================
*/

function InsertVideo(videoName)
{
	var videoDiv = document.getElementById("video");
	var videoIframe = document.getElementById("video-iframe");

	CenterDiv(videoDiv, videoIframe, "");
	
	var so = new SWFObject("images/s/" + videoName + ".swf", "video", "330", "290", "8", "#FFFFFF");
	so.addParam("wmode", "transparent");
	so.write("flash-content");
	
	document.getElementById("flash-content").innerHTML += "<a href='javascript:CloseVideo();'><img src='images/b/close-video.gif' /></a>";
}

function CloseVideo()
{
	var videoDiv = document.getElementById("video");
	var videoIframe = document.getElementById("video-iframe");
	
	videoDiv.style.display = "none";
	videoIframe.style.display = "none";
}

/* 
===========================================================
	PRODUCT FINDER
===========================================================
*/

var activeArr = "";

var nullValueArr = new Array(["Product Name",document.location]);

var coversValueArr = new Array(
	["Johnson & Johnson RED CROSS® Brand Waterproof Pads","covers.jsp#waterproof-pads"],
	["Johnson & Johnson RED CROSS® Brand Instant Burn Cooling Patches","covers.jsp#instant-burn-cooling-patches"],
	["Johnson & Johnson RED CROSS® Brand Gauze Pads","covers.jsp#gauze-pads"],
	["Johnson & Johnson RED CROSS® Brand Rolled Gauze","covers.jsp#rolled-gauze"],
	["Johnson & Johnson RED CROSS® Brand Triple Layer Non-Stick Pads","covers.jsp#triple-layer-stick-pads"],
	["Johnson & Johnson RED CROSS® Brand Advanced Healing Adhesive Pads","covers.jsp#advanced-healing-adhesive-pads"],
	["Johnson & Johnson RED CROSS® Brand Adhesive Pads plus NEOSPORIN® Antibiotic","covers.jsp#adhesive-pads-plus-neosporin-antibiotic"]
);

var tapesValueArr = new Array(
	["Johnson & Johnson RED CROSS® Brand Waterproof Tape","tapes.jsp#waterproof-tape"],
	["Johnson & Johnson RED CROSS® Brand SECURE-FLEX™ Wrap","tapes.jsp#tape-secure-flex"],
	["Johnson & Johnson RED CROSS® Brand Cloth Tape ","tapes.jsp#all-purpose-cloth-tape"],
	["Johnson & Johnson RED CROSS® First Cloth Aid Tape with Dispenser","tapes.jsp#all-purpose-cloth-tape-1"],
	["Johnson & Johnson RED CROSS® Brand All-Purpose Clear Tape","tapes.jsp#all-purpose-clear-tape"],
	["Johnson & Johnson RED CROSS® Brand SECURE-COMFORT® Cloth Tape","tapes.jsp#secure-comfort-cloth-tape"],
	["Johnson & Johnson RED CROSS® Brand HURT-FREE® Wrap","tapes.jsp#hurt-free-tape"],
	["Johnson & Johnson RED CROSS® Brand Paper Tape","tapes.jsp#non-irritating-paper-tape"],
	["Johnson & Johnson RED CROSS® Brand Paper Tape with Dispenser","tapes.jsp#non-irritating-paper-tape-1"]
);

var firstAidKitsArr = new Array(
	["Johnson & Johnson RED CROSS® All-Purpose Brand Kit","first-a-kits.jsp#all-purpose-first-aid-kit"],
	["Johnson & Johnson RED CROSS® Deluxe Brand Kit","first-a-kits.jsp#deluxe-f-a-kit"],
	["Johnson & Johnson RED CROSS® Emergency Brand Kit","first-a-kits.jsp#emergency-first-aid-kit"],
	["Johnson & Johnson RED CROSS® SAFE TRAVELS® Brand Kit","first-a-kits.jsp#safe-travels-f-a-kit"],
	["Johnson & Johnson RED CROSS® Brand TO GO!® Brand Kit","first-a-kits.jsp#first-aid-t-go"]
);

var homeHealthcareArr = new Array(
	["Johnson & Johnson RED CROSS® Hospital Products for Home Care KLING® Rolls","home-healthcare.jsp#kling-rolls"],
	["Johnson & Johnson RED CROSS® Hospital Products for Home Care NU GAUZE® All-Purpose Dressings","home-healthcare.jsp#nu-gauze-all-purpose-dressings"],
	["Johnson & Johnson RED CROSS® Hospital Products for Home Care TOPPER® Dressing Sponges","home-healthcare.jsp#topper-dressing-sponges"],
	["Johnson & Johnson RED CROSS® Hospital Products for Home Care ADAPTIC® Non-Stick Dressing","home-healthcare.jsp#adaptic-non-stickdressing"],
	["Johnson & Johnson RED CROSS® Hospital Products for Home Care MIRASORB® Gauze Sponges","home-healthcare.jsp#mirasorb-gauze-sponges"],
	["Johnson & Johnson RED CROSS® Hospital Products for Home Care SURGIPAD® Surgical Dressings","home-healthcare.jsp#surgpad-surgical-dressings"],
	["Johnson & Johnson RED CROSS® Hospital Products for Home Care Non-Stick Dressings","home-healthcare.jsp#non-stick-dressings"]
);

var oneStopKitsArr = new Array(
	["Johnson & Johnson RED CROSS® Brand ONE-STOP® Post-Surgery Care Kit","onestop-kits.jsp#post-surgery-kit"],
	["Johnson & Johnson RED CROSS® Brand ONE-STOP® Sports Surgery Care Kit","onestop-kits.jsp#sports-surgery-kit"],
	["Johnson & Johnson RED CROSS® Brand ONE-STOP® Skin Surgery Care Kit","onestop-kits.jsp#skin-surgery-care-kit"],
	["Johnson & Johnson RED CROSS® Brand ONE-STOP® C-Section Care Kit","onestop-kits.jsp#c-section-care-kit"],
	["Johnson & Johnson RED CROSS® Brand ONE-STOP® Burn Care Kit","onestop-kits.jsp#burn-care-kit"]
);

var cleanTreatCareArr = new Array(
	["Johnson & Johnson RED CROSS® Brand Cream","clean-treat.jsp#cream"],
	["Johnson & Johnson RED CROSS® Brand Sterile Cotton Balls","clean-treat.jsp#sterile-cotton-balls"]
);

function resetProductFinder()
{
	var productType = document.getElementById("product-f-select");
	var productName = document.getElementById("links");
	
	productType.selectedIndex = 0;
	productName.selectedIndex = 0;
	
	selectFill(0);
}

function selectFill(linkValue){
	
	switch(linkValue){
	
	case ("1"):
		var activeArr = coversValueArr;
		break;
	case ("2"):
		var activeArr = tapesValueArr;
		break;
	case ("3"):
		var activeArr = firstAidKitsArr;
		break;
	case ("4"):
		var activeArr = homeHealthcareArr;
		break;
	case ("5"):
		var activeArr = oneStopKitsArr;
		break;
	case ("6"):
		var activeArr = cleanTreatCareArr;
		break;
	default:
		var activeArr = nullValueArr;
	}
	
	document.getElementById('links').options.length = 0;
	
	for (i=0; i<activeArr.length; i++){
		document.getElementById("links").options[i] = new Option(activeArr[i][0],activeArr[i][1]);
	}
}

/*
==================================================
	AUXILIAR FUNCTIONS
==================================================
*/



function CenterDiv(objDiv,objIframe,parentDiv)
{
	objDiv.style.display = "block";
	objIframe.style.display = "block";
	
	// if parentDiv is relative positioned
	if (parentDiv != "")
	{
		parentLeft = parentDiv.offsetLeft;
	}
	else
	{
		parentLeft = 0;		
	}
	
	scrollYPosition = getScrollYPosition();
	pageWidth = getPageWidth();
	pageHeight = getPageHeight();

	topPosition = parseInt(scrollYPosition + (pageHeight - objDiv.offsetHeight) / 2);
	leftPosition = parseInt(((pageWidth - objDiv.offsetWidth) / 2) - parentLeft);

	objDiv.style.top = topPosition + "px";
	objIframe.style.top = topPosition + "px";

	objDiv.style.left = leftPosition + "px";
	objIframe.style.left = leftPosition + "px";
	
	objIframe.style.zIndex = 100000;
	objDiv.style.zIndex = 150000;
}



function getScrollYPosition()
{
	var aux;
	var agt = new getBrowser();
	
	if (agt.browser == "Firefox")
	{ 
		aux = window.pageYOffset;
	}
	else if (agt.browser == "Explorer")
	{
		aux = document.documentElement.scrollTop;	
	}
	else
	{
		aux = document.body.scrollTop;	
	}

	return aux;
}

function getPageWidth()
{
	var aux;
	var agt = new getBrowser();
	
	if (agt.browser == "Firefox")
	{ 
		aux = self.innerWidth;
	}
	else
	{
		aux = document.body.offsetWidth;
	}

	return aux;
}


function getPageHeight()
{
	var aux;
	
	var agt = new getBrowser();
	
	if (agt.browser == "Firefox")
	{ 
		aux = self.innerHeight;
	}
	else if (agt.browser == "Explorer")
	{
		aux = document.documentElement.offsetHeight;
	}
	else
	{
		aux = self.innerHeight;
	}
	
	return aux;
}


function getBrowser()
{
	BrowserDetect.init();
	
	this.browser = BrowserDetect.browser;
	this.version = BrowserDetect.version;
	this.os = BrowserDetect.OS;
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
