

var dQuotePattern = /\"/g;

var isIE = navigator.appName.indexOf("Internet Explorer") != -1;

var sl = window.setInterval("setLinks()", 100);
var sizePattern = /^\d+x\d+$/;

function setLinks() {
	for (var i = 0; i < document.links.length; i++) {
		var theLink = document.links[i];
		if (!theLink.href || (theLink.href.indexOf("javascript:") != -1) || theLink.onclick) {
			continue;
		}
		if (theLink.className.indexOf("popup_page_opener") == 0) {
			theLink.onclick = openPageFromLink;
		}
	}
}

function getCookieValue(cookieName) {
	var c = document.cookie;
	var nameStart = c.indexOf(cookieName + "=");
	if (nameStart == -1) return undefined;
	var separatorPos = c.indexOf(";", nameStart);
	if (separatorPos == -1) separatorPos = c.length;
	var cStr = c.substring(nameStart, separatorPos);
	cStr = cStr.substring(cStr.indexOf("=") + 1, cStr.length);
	cStr = cStr.replace(dQuotePattern, "");
	return cStr;
}

function openPageFromLink() {
	var parts = this.className.split("_");
	var w = 290;
	var h = 390;
	var lastPart = parts[parts.length - 1];
	if (sizePattern.test(lastPart)) {
		var wh = lastPart.split("x");
		w = wh[0];
		h = wh[1];
	}
	openPopupWin(this.href, w, h);
	return false;
}

function openPopupWin(url, width, height, windowName) {
	if (!windowName) {
		windowName = 'popup_page' + Math.round(Math.random() * 1000);
	}
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	var win = window.open(url, windowName, 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',menubar=0,location=0,resizable=0,scrollbars=1,directories=0,scroll=0,status=0,menubar=0,locationbar=0,statusbar=0,titlebar=0,toolbar=0');
}



function openPopup(popupId){
	document.getElementById(popupId).style.display = "block";
}

function closePopup(popupId){
	document.getElementById(popupId).style.display = "none";
}


function initLoginForm(sFormName) {
	try {
		var theForm = document.getElementById(sFormName);
		var userNameCookie = getCookieValue("remember_username");
		if ((userNameCookie == undefined) || (userNameCookie == "") || (userNameCookie == "null") ) {
			tempLogin = getCookieValue("temporary_login_value");
			if ((tempLogin != undefined) && (tempLogin != "") && (tempLogin != "null")) {
				theForm.elements["club_login"].value = tempLogin;
				theForm.elements["club_password"].focus();
			}
			theForm.elements["remember_username"].checked = false;
		} else {
			theForm.elements["club_login"].value = userNameCookie.substring(0,8);
			theForm.elements["club_password"].value = userNameCookie.substring(8,13);
			theForm.elements["remember_username"].checked = true;
			theForm.elements["login_btn"].focus();
		}
	} catch (e) {
		// noop
	}
}




function initPage() {
	window.clearInterval(sl);
	setLinks();

	if (document.getElementById("login_form_static")) {
		initLoginForm("login_form_static");
		if (getCookieValue("requested_url") != undefined) {
			document.getElementById("login_form_static").elements["requested_url"].value = getCookieValue("requested_url");
		}
	}
}

function switchCssClass(obj, name, turnOn) {
	var clazz = obj.className ? obj.className : "";
	if (turnOn == undefined) {
		turnOn = clazz.indexOf(name) == -1
	}
	if (turnOn === false) {
		obj.className = clazz.replace(new RegExp("\s?" + name, "g"), "");
	} else if (turnOn === true) {
		obj.className = obj.className ? (obj.className + " " + name) : name;
	}
}


//-----------------------------------------------------------------------------
//Globals
//Major version of Flash required
var requiredMajorVersion = 9;
//Minor version of Flash required
var requiredMinorVersion = 0;
//Revision of Flash required
var requiredRevision = 45;
//-----------------------------------------------------------------------------


function flash(src, alternateContent, width, height) {
	if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
		var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
		if(hasRightVersion) {  // detected an acceptable version
			// embed the flash movie
			AC_FL_RunContent(
				'codebase', 'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0',
				'width', width,
				'height', height,
				'src', src,
				'quality', 'high',
				'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
				'align', 'middle',
				'play', 'true',
				'loop', 'true',
				'scale', 'showall',
				'wmode', 'transparent',
				'devicefont', 'false',
				'id', 'home-image',
				'bgcolor', '#000',
				'name', 'home-image',
				'menu', 'false',
				'allowScriptAccess','sameDomain',
				'allowFullScreen','false',
				'movie', src,
				'salign', ''
				); //end AC code
		} else {  // flash is too old or we can't detect the plugin
			document.write(alternateContent);  // insert non-flash content
		}
	}
}

function toggleClass(classname, obj) {
	if(obj.className.indexOf(classname) >= 0) {
		switchCssClass(obj, classname, false);
	} else {
		switchCssClass(obj, classname, true);
	}

}

function toggleRow (obj) {
	toggleClass("active", obj);
	var toggleRow = obj.nextSibling;
	if(toggleRow.nodeName != "TR") toggleRow = toggleRow.nextSibling;
	toggleClass("closed", toggleRow);
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}


function changeInputType(oldObject, oType) {
	  var newObject = document.createElement('input');
	  newObject.type = oType;
	  if(oldObject.size) newObject.size = oldObject.size;
	  if(oldObject.value) newObject.value = oldObject.value;
	  if(oldObject.name) newObject.name = oldObject.name;
	  if(oldObject.id) newObject.id = oldObject.id;
	  if(oldObject.className) newObject.className = oldObject.className;
	  oldObject.parentNode.replaceChild(newObject,oldObject);
	  return newObject;
}

function placePopupContent() {
	var container = document.getElementById("popupContainer");
	var content = document.getElementById("popupContent");
	if(container && content) {
		container.innerHTML = content.innerHTML;
	}
}

function ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
	}

function imposeMaxLength(Object, MaxLen) {
	if (Object.value.length >= MaxLen) Object.value = Object.value.substring(0,MaxLen-1);
}

function hideDefaultPwd(){
	try {
		document.getElementById("passwordLabel").style.display = "none";
		document.getElementById("club_password").focus();
	} catch (e) {}
}

function showDefaultPwd(){
	var pwdInput = document.getElementById("club_password");
	if(pwdInput.value=='') {
		document.getElementById("passwordLabel").style.display = "block";
	}
}

function trimStr (str) {
	return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

var isIe = /MSIE/.test(navigator.userAgent) && navigator.platform == "Win32";

function setTopMenuCells () {
	var cells = new Array();
	var rows = document.getElementById("navcontent").rows;
	for(var i = 0; i < rows.length; i++) {
		var theCells = rows[i].cells;
		for(var k = 0; k < theCells.length; k++) {
			cells[cells.length] = theCells[k];
		}
	}
	for(var i = 0; i < cells.length; i++) {
		var cell = cells[i];
		cell.onmouseover = function() {
			switchCssClass(this,"hover",true);
		};

		cell.onmouseout = function() {
			switchCssClass(this,"hover",false);
		};
		var width = cell.clientWidth;

		var bgTable = getElementsByClass("activeLinkBg",cell,"TABLE")[0];
		if(i == 0) {
			bgTable.style.width = width + 20 + 18 + "px";
			bgTable.style.left = "-27px";
		} else {
			bgTable.style.width = width + 20 + "px";
		}
		if(cell.className.indexOf("active") >= 0) {
			bgTable.style.display = isIe ? "block" : "table";
		}
	}
}