/*************** open help window */
var helpWin;
function openHelp(x){
/* check value of x */
var helpURI;
if (x == null){
helpURI = ("");
} else {
helpURI = (x);
}

/* execute open popup window */
	if (helpWin == null || helpWin.closed){
		helpWin = window.open("/help/"+helpURI,"","toolbar=no,personal=no,menubar=no,status=yes,resizable=yes,width=650,height=800,location=no,scrollbars=yes");
		}
	else{
		helpWin.focus();
		helpWin.location.replace("/help/"+helpURI);
	}
}


/*************** open cms help window */
var helpWin;
function openCmsHelp(x){
/* check value of x */
var helpURI;
if (x == null){
helpURI = ("");
} else {
helpURI = (x);
}

/* execute open popup window */
	if (helpWin == null || helpWin.closed){
		helpWin = window.open(helpURI,"","toolbar=no,personal=no,menubar=no,status=yes,resizable=yes,width=650,height=800,location=no,scrollbars=yes");
		}
	else{
		helpWin.focus();
		helpWin.location.replace(helpURI);
	}
}


/*************** open help2 window */
var helpWin;
function openHelp2(x){
/* check value of x */
var helpURI;
if (x == null){
helpURI = ("");
} else {
helpURI = (x);
}

/* execute open popup window */
	if (helpWin == null || helpWin.closed){
		helpWin = window.open("/help2/"+helpURI,"","toolbar=no,personal=no,menubar=no,status=yes,resizable=yes,width=600,height=320,location=no,scrollbars=yes");
		}
	else{
		helpWin.focus();
		helpWin.location.replace("/help2/"+helpURI);
	}
}


/*************** open poker window */
var pokerWin;
function openPoker(x){
/* check value of x */
var pokerURI;
if (x == null){
pokerURI = ("");
} else {
pokerURI = (x);
}

/* execute open popup window */
	if (pokerWin == null || pokerWin.closed){
		pokerWin = window.open("/poker/"+pokerURI,"","toolbar=no,personal=no,menubar=no,status=yes,resizable=yes,width=600,height=320,location=no,scrollbars=yes");
		}
	else{
		pokerWin.focus();
		pokerWin.location.replace("/poker/"+pokerURI);
	}
}
//************** open quicktour popup ********************/
function openQuickTour(){
    var quickTourWin = window.open("/quick-tour/","QuickTour","toolbar=no,personal=no,menubar=no,status=no,resizable=no,width=760,height=420,location=no,scrollbars=no");
    quickTourWin.moveTo(screen.availWidth/2-(760/2),screen.availHeight/2-(420/2));
    if (quickTourWin.focus) {quickTourWin.focus()}

}

//************** open rules and regulations popup ********************/
//this function not only opens a window but checks to see whether or not a window of that name is already open.
//If so then it will call focus on it so that it is returned to the foreground.
function openRules(theLink, title, width, height) {
	if (typeof(popupWin) != "object"){
	popupWin = window.open(theLink,title,"toolbar=no,personal=no,menubar=no,status=yes,resizable=yes,width=" + width + ",height=" + height + ",location=no,scrollbars=yes");
	} else {
		if (!popupWin.closed){
		popupWin.location.href = theLink;
	} else {
	popupWin = window.open(theLink,title,"toolbar=no,personal=no,menubar=no,status=yes,resizable=yes,width=" + width + ",height=" + height + ",location=no,scrollbars=yes");
	}
}
popupWin.focus();
}

/************** openLink used for external links that include the Bodog header bar */

function openLink(theLink) {
	window.open("/template/popup/openLink.jsp?url="+arguments[0]);
}

/*************** used for external event preview **********************/
var loc = document.location;
	var lastpos = loc.toString().lastIndexOf(".com/") + 4;
	var firstpos = loc.toString().lastIndexOf("://");
	function LinkPop(links, title){
		LinkWin = window.open("http" + loc.toString().substring(firstpos, lastpos) + "/template/popup/openLink.jsp?url=" + links);
	}

// used by links in the help popup to trigger page change on the main window
function openParent(location) {
window.opener.location.href = arguments[0];
}

//************** generic popup ********************/
function openWin(theLink, title){
    var newWin = window.open(theLink,title,"toolbar=no,personal=no,menubar=no,status=yes,resizable=yes,width=600,height=400,location=no,scrollbars=yes");
}

function openImage( urlImageSrc, intWidth, intHeight, strImageTitle ){
    var url = "/template/popupImage.jsp?imageSrc=" + urlImageSrc + "&w=" + intWidth + "&h=" + intHeight;
    var w = intWidth + 12;
    var h = intHeight + 32;
    var imageWin = window.open(url, strImageTitle, "width=" + w + ",height=" + h + ",toolbar=no,personal=no,menubar=no,status=yes,resizable=yes,location=no,scrollbars=no");
}

function openSizedWin(theLink, title, width, height){
    var newWin = window.open(theLink,title,"toolbar=no,personal=no,menubar=no,status=yes,resizable=yes,width=" + width + ",height=" + height + ",location=no,scrollbars=yes");
}



//************ email validator *******************/

function notEmail(e) {
		if (e.length == 0) {return true}
			var pattern = /^[\w\._\-\#\&0-9]+\@[0-9a-zA-Z\.\-]+\.[a-zA-Z]{2,3}$/
			var result = e.search(pattern)
			if (result == "-1") {     
			return true;
		}
	}
//******** used by enterContent.jsp **************/

	function validateContestEmail(that) {
		if (notEmail(that.contestEmailEntry.value)) {
			alert("Please enter a valid email address...");
			that.contestEmailEntry.focus();
			return false;
		}
	}

//******** used by subscribe.jsp **************/

	function validateSubscribeEmail(that) {
		if (notEmail(that.emailAddress.value)) {
			alert("Please enter a valid email address...");
			that.emailAddress.focus();
			return false;
		}
	}

//******** used by sendReferralEmail.jsp **************/

	function validateReferralEmail() {
		if (notEmail(document.getElementById('email1').value)) {
			alert("Please enter a valid email address...");
			document.getElementById('email1').select();
			return false;
		}
		var emails = new Array("email2","email3","email4"); 
		for (var loop = 0; loop <emails.length; loop++){
			if (document.getElementById(emails[loop]).value != ""){
				if (notEmail(document.getElementById(emails[loop]).value)) {
				alert("Please enter a valid email address...");
				document.getElementById(emails[loop]).select();
				return false;
				}
			}
		}
	}

//************* print function *****************//
//****** currently inline on the Frontines Template ********//

function printThis() {
	var source = top.document.getElementById('mainContentArea').innerHTML;
	//alert(source);
	top.contentFrame.toPrint.innerHTML = source;
	var ftp = document.contentFrame;
	ftp.focus();
	ftp.print();
	}

// form button functions
function bdClassNew(obj, new_style) { 
  obj.className=new_style;
}

function bdClassNew2(obj, new_style) { 
  obj.parentNode.className=new_style;
  bdClassNew(obj, new_style)
}

// Used for the poker schedule - do not remove
var schedule;

// Used for poker lobby
var _alreadyLoggedIn = false;


function printPageArea(areaId) {
	
	if (document.getElementById != null)
	{
		var html = '<HTML>\n<HEAD>\n';
		
		var cssLinks = document.getElementsByTagName('link');
		for (var n=0; n<cssLinks.length; n++) {
			html += '<link rel="STYLESHEET" type="text/css" href="' + cssLinks[n].href + '">';
		}		
		html += '\n</HE' + 'AD>\n<BODY bgcolor="white">\n';
		html += '<div id="master-content-block" style="width:700px !important;">';
		
		var printReadyElem = document.getElementById(areaId);
		
		if (printReadyElem != null)
		{
				html += printReadyElem.innerHTML;
		}
					
		html += '</div>\n</BO' + 'DY>\n</HT' + 'ML>';
		
		var printWin = window.open('','PrinterFriendlyPage','width=730,height=400');
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
		printWin.print();
	}

}

  	function getElementsByTagNames(list,obj)
	{
		if (!obj) var obj = document;
		var tagNames = list.split(',');
		var resultArray = new Array();
		for (var i=0;i<tagNames.length;i++)
		{
			var tags = obj.getElementsByTagName(tagNames[i]);
			for (var j=0;j<tags.length;j++)
			{
				resultArray.push(tags[j]);
			}
		}
		var testNode = resultArray[0];
		if (testNode.sourceIndex)
		{
			resultArray.sort(function (a,b) {
					return a.sourceIndex - b.sourceIndex;
			});
		}
		else if (testNode.compareDocumentPosition)
		{
			resultArray.sort(function (a,b) {
					return 3 - (a.compareDocumentPosition(b) & 6);
			});
		}
		
		return resultArray;
	}

	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;
	}	
	
	