/* Open a new window (perfectly centered at 70-90% of screen size) */
function openWin() {
	args = openWin.arguments;

	/*--- 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;
}

function confirmDeleteMember()
{
	return confirm("This member will permanently be deleted out of the database! Are you sure you want to do this?");
}

//Javascript cookies
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);
}

/* For the pop-over links */
function checkPopOverLink() {
      var args = checkPopOverLink.arguments;
      var hn = stripDomain();
      
      /* [0] URL of link, [1] Cookie name, [2] Cookie value, [3] Colorbox pop-over ID */
	if (readCookie(args[1]) == args[2]) {
		document.location.href = stripDomain();
	} else {
		$.fn.colorbox.settings.opacity = 0.5;
		$.fn.colorbox({width: "600px", inline: true, href: args[3]});
		$("#colorbox").appendTo('form#aspnetForm');
		/*
		$(".open_form").colorbox({width: "600px", inline: true, href: "#international_form"});
		$("#colorbox").appendTo('form#aspnetForm');
		*/
	}
	
}

/* Stripping domain name from URL */
function stripDomain()
{
	var url = window.location.hostname;
	
	//For domains without a subdomain
	//if (url.split(".").length == 2) {
	//	return url;
	//}
	if (url.split(".").length == 3) {
		var index = url.indexOf(".");
		var subdomain = url.substring(0, index);
		url = url.replace(subdomain, "");
	}
	else if (url.split('.').Length > 3)
	{
		var lastIndex = url.lastIndexOf(".");
		var index = url.lastIndexOf(".", lastIndex - 1);
		var subdomain = url.substring(0, index);
		url = url.replace(subdomain, "");
	}
	if (url.substring(0,1) == ".") {
		url = url.slice(1);
	}
	return "http://intl." + url;
}
