﻿/* Open a new window (perfectly centered at 70-90% of screen size) */
function openWin() {
	args = openWin.arguments;

	//If there are javascript alert notifications, identify them here
	if (args[1]) {
		if (args[1] == "1") {
			if (!outsideLinkAlert(args[0]))
				return false;
		} else if (args[1] == "2") {
			if (!AsianLiverLinkAlert(args[0]))
				return false;
		}
	}

	/*--- Choose window size (full screen minus how many pixels) ---*/
	var windowsize = 150;
	var maxwindowwidth = 1024;
	var maxwindowheight = 768;
	/*--------------------------------------------------------------*/

	if (screen.width > maxwindowwidth) {
		var width = maxwindowwidth;
		var widthc = (screen.width - maxwindowwidth) / 2;
	}
	else {
		var width = screen.width - windowsize;
		var widthc = windowsize / 2;
	}

	if (screen.height > maxwindowheight) {
		var height = maxwindowheight;
		var heightc = ((screen.height - maxwindowheight) / 2) - 50;
	}
	else {
		var height = screen.height - (windowsize * 2);
		var heightc = windowsize / 2;
	}

	window.open(args[0], 'openWin', 'width=' + width + ',height=' + height + ',top=' + heightc + ',left=' + widthc + ',scrollbars=1,status=1,toolbar=1,menubar=1,resizable=1');
	return false;
}

/* Cookie Functions */
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 eraseCookie(name) {
	createCookie(name, "", -1);
}


/* Doc Finder combinations */
function showDocFinder() {

	//Check for IE6 and below
	if (typeof document.body.style.maxHeight === "undefined") {
		animatedcollapse.toggle('topnav_docfinder_ie6_outer');
		return false;
	}

	if (readCookie("VireadDocFinder") != null) {
		if (readCookie("VireadDocFinder") == "Accepted") {
			animatedcollapse.toggle('topnav_docfinder_outer');
			animatedcollapse.hide('topnav_docfinder_results_outer');
			animatedcollapse.show('mainimage_outer');
		}
		else {
			animatedcollapse.toggle('topnav_docfinder_disclaimer_outer');
		}
	} else {
		animatedcollapse.toggle('topnav_docfinder_disclaimer_outer');
	}
}

function acceptDisclaimer() {
	createCookie("VireadDocFinder", "Accepted", 30);
	animatedcollapse.hide('topnav_docfinder_disclaimer_outer');
	animatedcollapse.show('topnav_docfinder_outer');
}
function declineDisclaimer() {
	createCookie("VireadDocFinder", null, -1);
	animatedcollapse.hide('topnav_docfinder_disclaimer_outer');
}

/* Other functions */
function highlightDocChoice(e) {

	/* Scroll to the proper place */
	var $paneTarget = $('#docfinder_list_results');
	var browserOffset = 0;
	if (navigator.appName != 'Microsoft Internet Explorer') browserOffset = 394;

	/* Highlight the proper doctor */
	var items = $('#doclist_results > li');
	for (var i = 0; i < items.length; ++i) {
		if (items[i].id == e.id) {
			items[i].className = "selected";

			if (items[i].offsetTop) {
				var moveTo = items[i].offsetTop - browserOffset;
				if (moveTo < 0) moveTo = 0;
			 $paneTarget.stop().scrollTo(moveTo, '-10');
			 }
			target = undefined;
		}
		else items[i].className = "";
	}
};



/* Verify Doc Credential */
function checkDoc() {
	if (readCookie("VireadDocVerify") == null) {
		$.colorbox({ width: "620px", inline: true, href: "#verifyDoc" });
	} else if (readCookie("VireadDocVerify") == "No") {
		$.colorbox({ width: "620px", inline: true, href: "#verifyDoc" });
	}
	//Reset the message if you need to
	//createCookie("VireadDocVerify", "No", 1);
}

/* Sign in to view the VIREAD Detail Aid */
function verifySignIn() {
	if (readCookie("VireadDocAccess") == null) {
		$.colorbox({ width: "620px", inline: true, href: "#verifyAccess" });
		$("#colorbox").appendTo('form');
		return false;
	} else if (readCookie("VireadDocAccess") == "") {
		$.colorbox({ width: "620px", inline: true, href: "#verifyAccess" });
		$("#colorbox").appendTo('form');
		return false;
	} else {
		return true;
	}
	//Reset the message if you need to
	//createCookie("VireadDocAccess", "", 1);
}

/* If certain control is selected, activate the checkbox that goes with it */
function RadioButtonEnableTextbox(rbl, on_value, txtbox) {
	var radio = document.getElementsByName(rbl);
	var selectedValue = "";
	var textbox = document.getElementById(txtbox);
	for (var i = 0; i < radio.length; i++) { if (radio[i].checked) { var selectedValue = radio[i].value; } }

	if (selectedValue == on_value) { document.getElementById(txtbox).disabled = false; document.getElementById(txtbox).focus(); }
	else {document.getElementById(txtbox).value = ""; document.getElementById(txtbox).disabled = true; }
}

//Verify for each languages
function verifyEnglish() {
	return confirm("The information contained on this site is intended for audiences in the United States only. The content on this site may not apply to non-U.S. audiences as regulatory control, legal requirements, and/or medical practices may vary in other countries.");
}
function verifyChineseT() {
	return confirm("本網站所含資訊僅適用於美國讀者。本網站內容在監管控制、法律規定及/或醫療實踐等方面可能與其他國家有所不同，因此或許不適合非美國讀者。");
}
function verifyChineseS() {
	return confirm("本网站上所包含的信息仅提供给美国的受众参阅。由于其他国家的法规控制、法律要求及（或）医疗实践可能不同，本网站上的内容可能并不适用于非美国受众。");
}
function verifyKorean() {
	return confirm("이 사이트에 나와 있는 정보는 미국인만을 위한 것입니다. 규제 관리와 법적 요구조건 및/또는 의료 시술이 국가에 따라 다를 수 있으므로, 이 사이트의 내용도 미국 외의 거주자에게는 적용되지 않을 수 있습니다.");
}
function verifyViet() {
	return confirm("Thông tin trong trang mạng này chỉ dành cho độc giả tại Hoa Kỳ mà thôi. Nội dung trang mạng này có thể không áp dụng cho độc giả ngoài Hoa Kỳ vì sự kiểm tra điều hành, các yêu cầu pháp lý và/hoặc thực hành y khoa có thể thay đổi ở các quốc gia khác.");
}
