﻿//Open new window
function openWin() {
	args = openWin.arguments;
	
	/*--- Choose window size (full screen minus how many pixels) ---*/
	var windowsize = 150;
	/*--------------------------------------------------------------*/
	
	var width = screen.width - windowsize;
	var height = screen.height - (windowsize * 2);
	var widthc = 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;
}




//In case you want to print windows...
jQuery(function() {
	jQuery("a.popup").click(function() {
		window.open(this.href, "popupwin", "status=0, toolbar=0, location=0, menubar=0, width=790, height=580, resizeable, scrollbars");
		return false;
	})
});

function PrintWindow() {
	window.print()
}





//Resets all the text-size images and sets the correct font
function fontsize(whichStyle) {

	//Reset all the images
	document.getElementById("smallfont").style.backgroundPosition = "";  //null;
	document.getElementById("normalfont").style.backgroundPosition = "";  //null;
	document.getElementById("largefont").style.backgroundPosition = "";  //null;
	document.getElementById("smallfont").style.cursor = "";  //null;
	document.getElementById("normalfont").style.cursor = "";  //null;
	document.getElementById("largefont").style.cursor = "";  //null;
	
	//Activate which one should be live
	if (whichStyle == "smallSize") {
		document.getElementById("smallfont").style.backgroundPosition = "bottom left";
		document.getElementById("smallfont").style.cursor = "default";
		setFontSize("");
	}
	else if (whichStyle == "normalSize") {
		document.getElementById("normalfont").style.backgroundPosition = "bottom left";
		document.getElementById("normalfont").style.cursor = "default";
		setFontSize("120%");
	}
	else if (whichStyle == "largeSize") {
		document.getElementById("largefont").style.backgroundPosition = "bottom left";
		document.getElementById("largefont").style.cursor = "default";
		setFontSize("140%");
	}

	saveFontSize(whichStyle);
	
}

function setFontSize(incomingSize) {

	var idname = "";
	if (document.getElementById("mainbodycontentsub"))
		idname = "mainbodycontentsub";
	else if (document.getElementById("mainbodycontenthome"))
		idname = "mainbodycontenthome"

	var p = document.getElementById(idname).getElementsByTagName("p");
	var h3 = document.getElementById(idname).getElementsByTagName("h3");
	var ul = document.getElementById(idname).getElementsByTagName("ul");
	for (i = 0; i < p.length; i++) {
		p[i].style.fontSize = incomingSize;
	}
	for (i = 0; i < h3.length; i++) {
		h3[i].style.fontSize = incomingSize;
	}
	for (i = 0; i < ul.length; i++) {
		ul[i].style.fontSize = incomingSize;
	}
}

function getFontSize() {
	var cookie = readCookie("AsianLiverFontSize");
	var fontsizeset = cookie ? fontsize(cookie) : fontsize("smallFont");
}
function saveFontSize(savedFontSize) {
	var cookie = createCookie("AsianLiverFontSize", savedFontSize, 1);
}

//On page load get the value of previous style sheeet or use preferred styles sheet.
window.onload = function(e) {
var cookie = readCookie("AsianLiverFontSize");
	var fontsizeset = cookie ? fontsize(cookie) : fontsize("smallFont");
}



// ================================================================ //
// ===== FUNCTIONS FOR READING AND WRITING JAVASCRIPT COOKIES ===== //
// ================================================================ //

//Create a cookie to store the preferred style sheet.
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 expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}
//Read the cookie to return the prefered style sheet.
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;
}



// ================================================================ //
// ======= SCRIPTS INHERITED FROM OLD ASIANLIVER.COM WEBSITE ====== //
// ================================================================ //


function goPage(strPageName) {
	window.location.href = strPageName;
}
function NavBackOn(objLi) {
	objLi.className = "hover";
}
function NavBackOff(objLi) {
	objLi.className = "";
}

function AgreeToDisclaimer(sender, args) {
	var sAgreed = this.getCookie("disclaimeragreed");

	if (sAgreed.length > 0) {
		args.IsValid = true;
	}
	else {
		args.IsValid = false;
		document.getElementById("popupdisclaimer").style.display = "block";
	}
}
function AcceptDisclaimer() {
	document.cookie = "disclaimeragreed=1";
}
function getCookie(c_name) {
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1) {
			c_start = c_start + c_name.length + 1;
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end == -1)
				c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start, c_end));
		}
	}
	return "";
}