// <![CDATA[
var d = new Date();
var year = d.getFullYear();

//sfHover = function() {
//    var navigation = document.getElementById("navigation");
//    if (navigation != null)
//    {
//        var sfEls = navigation.getElementsByTagName("li");
//
//        for (var i=0; i<sfEls.length; i++) {
//	        sfEls[i].onmouseover=function() {
//		        this.className+=" sfhover";
//	        }
//	        sfEls[i].onmouseout=function() {
//		        this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
//	        }
//        }
//    }
//}
//if (window.attachEvent) window.attachEvent("onload", sfHover);

function doPopups()
{
if (!document.getElementsByTagName) return false;
	var anchors = document.getElementsByTagName('a');
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];
		var relAttribute = String(anchor.getAttribute('rel'));
		var classAttribute = String(anchor.getAttribute('class'));
		if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('popup'))){
			if (anchor.id == "downloadnow" || anchor.id == "downloadtext" || anchor.id == "downloadlogo") {
				anchor.setAttribute("target", "_blank");
			} else {
				anchor.onclick = function () {window.open(this.href); return false;}
			}
		}
	}
}

function clearOnFocus(type)
{
  if (!document.getElementsByTagName) return false;
  var fields = document.getElementsByTagName(type);
  for (var i=0; i < fields.length; i++) {
    if (fields[i].className.match("clearonfocus")) {
      fields[i].onfocus = function() {
        if (this.value == this.defaultValue) {
          this.value = "";
          return false;
		}
      }
	  fields[i].onblur = function() {
        if (this.value == "") {
          this.value = this.defaultValue;
          return false;
		}
      }
    }
  }
}

function doButtonImages() 
{
	if (!document.getElementsByTagName)
		return false;
	
	var inputs = document.getElementsByTagName("input");
	
	for (var i=0; i < inputs.length; i++) 
	{
		if (inputs[i].type=="submit" || inputs[i].type=="button")
		{
			inputs[i].onmouseover = function()
			{
				this.className += "hover";
			}
			
			inputs[i].onmouseout = function()
			{
				this.className = this.className.replace(/hover/g, "");
			}
		}
	}
}

//// Unobtrusive scroller object
//var fdScroller = {
//        scrollLoop:false,
//        scrollInterval:null,
//        currentBlock:null,
//        lastY:0,
//        requestedY:0,
//        init: function() {
//                var lnks = document.getElementsByTagName('a');
//                var removeLoc = window.location + ' ';
//
//                // strip any #target, force a String cast
//                if(removeLoc.indexOf('#') != -1) {
//                        removeLoc = removeLoc.substr(0, removeLoc.indexOf('#'));
//                } else {
//                        removeLoc = removeLoc.substr(0, removeLoc.length - 1);
//                }
//
//                for(var i = 0, lnk; lnk = lnks[i]; i++) {
//                        tmploc = lnk.href.replace(removeLoc,'');
//                        if(tmploc.charAt(0) == '#' && !lnk.onclick) lnk.onclick = fdScroller.initScroll;
//                }
//        },
//        getWindowHeight: function(){
//                var myHeight = 0;
//                if( typeof( window.innerWidth ) == 'number' ) {
//                        //Non-IE
//                        myHeight = window.innerHeight;
//                } else if( document.documentElement &&
//                                ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//                        //IE 6+ in 'standards compliant mode'
//                        myHeight = document.documentElement.clientHeight;
//                } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//                        //IE 4 compatible
//                        myHeight = document.body.clientHeight;
//                }
//                return myHeight;
//        },
//        getScrollLeft: function(){
//                if(document.all) return (document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
//                else return window.pageXOffset;
//        },
//        getScrollTop: function(){
//                if(document.all) return (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
//                else return window.pageYOffset;
//        },
//        getElementYpos: function(el){
//                var y = 0;
//                while(el.offsetParent){
//                        y += el.offsetTop
//                        el = el.offsetParent;
//                }
//                return y;
//        },
//        initScroll: function(e){
//                var targ;
//
//                if (!e) var e = window.event;
//                if (e.target) targ = e.target;
//                else if (e.srcElement) targ = e.srcElement;
//                if (targ.nodeType == 3) targ = targ.parentNode;
//
//                if(targ.href && targ.href.indexOf('#') != -1) {
//                        var where = targ.href.substr(targ.href.indexOf('#')+1,targ.href.length);
//                        fdScroller.currentBlock = document.getElementById(where);
//                        if(!fdScroller.currentBlock) return;
//
//                        var documentHeight = document.getElementsByTagName('body').offsetHeight;
//                        var windowHeight = fdScroller.getWindowHeight();
//                        var ypos = fdScroller.getElementYpos(fdScroller.currentBlock);
//                        if(ypos > documentHeight - windowHeight) ypos = documentHeight - windowHeight;
//                        fdScroller.requestedY = ypos;
//                        fdScroller.scroll();
//                }
//
//                return false;
//        },
//        scroll: function(){
//                var left = fdScroller.getScrollLeft();
//                var top  = fdScroller.getScrollTop();
//
//                if(Math.abs(top-fdScroller.requestedY) <= 1){
//                        window.scrollTo(0,fdScroller.requestedY);
//                        fdScroller.lastY = -1;
//                } else {
//                        fdScroller.lastY = top;
//                        window.scrollTo(0, Math.round(top+((fdScroller.requestedY-top)/2)));
//                        setTimeout(fdScroller.scroll,50);
//                }
//        }
//}

//Email subscription form validation
var rxEmailAddress	= /^(\w+|[.]|[-]+)+[@](\w+|[-]+)+[.](\w+|[.]|[-]+)+$/;
var rxTelephone		= /^[\(\)\+ 0-9]*$/;

function submitEmailNewsletters()
{
	var txtName				= document.getElementById('fname');
	var txtEmail			= document.getElementById('email');
	var frmSubscribeForm	= document.getElementById('frmSubscribeForm');
	
	var errors			= '';

	if (txtName.value.length < 3 || txtName.value.length > 40 || txtName.value == "Full Name")
	{
		errors = errors + '- enter a name between 3 and 40 characters in length\r\n';
	}
	
	if (txtEmail.value.length < 6 || txtEmail.value.length > 255 || !rxEmailAddress.test(txtEmail.value))
	{
		errors = errors + '- enter a valid email address between 6 and 255 characters in length\r\n';
	}

	if (errors.length > 0)
	{
		window.alert('Sorry, please correct the following before submitting the Email Newsletter Subscription form:\r\n\r\n' + errors);
		return false;
	}
	else
	{
		return true;
	}
}

function submitOfferEmail()
{
	var txtEmail			= document.getElementById('txtEmail');
	
	var errors			= '';

	if (txtEmail.value.length < 6 || txtEmail.value.length > 255 || !rxEmailAddress.test(txtEmail.value))
	{
		errors = errors + '- enter a valid email address between 6 and 255 characters in length\r\n';
	}

	if (errors.length > 0)
	{
		window.alert('Sorry, please correct the following before submitting the Offers Email form:\r\n\r\n' + errors);
		return false;
	}
	else
	{
		return true;
	}
}

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

function twoCols(src, type)
  {
  var origList = src;

  var leftList = document.createElement(type);
  var rightList = document.createElement(type);
  var container = document.createElement('div');

  var items = origList.getElementsByTagName('LI');

  var itemsLength = items.length/2;
  for (i = 0; i < itemsLength; i++)
    {
    leftList.appendChild(items[0]);
    }

  itemsLength = items.length;
  for (i = 0; i < itemsLength; i++)
    {
    rightList.appendChild(items[0]);
    }
  container.appendChild(leftList);
  container.appendChild(rightList);

  leftList.setAttribute('class', 'left');
  rightList.setAttribute('class', 'right');
  container.setAttribute('class','twocol');
  if (document.all)
    {
    leftList.setAttribute('className', 'left');
    rightList.setAttribute('className', 'right');
    container.setAttribute('className','twocol');
    }
  if (type == 'ol')
    {
    rightList.setAttribute('start', leftList.getElementsByTagName('LI').length + 1 );
    }
  origList.parentNode.replaceChild(container, origList);
  }

function allTwoCols (whichclass, type)
{
	var uls = document.getElementsByTagName(type);
	for (var i=0; i< uls.length; i++)
	{
	if (uls[i].getAttribute('class') == whichclass || 
		uls[i].getAttribute('className') == whichclass)
	  {
	  twoCols(uls[i], type.toLowerCase());
	  }
	}
}
  
function addClass(element,name) {
  if (!element.className) {
    element.className = name;
  } else {
    element.className+= " "+name;
  }
}

function stripeTables() {
  var tables = document.getElementsByTagName("table");
  for (var i=0; i<tables.length; i++) {
    var rows = tables[i].getElementsByTagName("tr");
    for (var j=0; j<rows.length; j=j+2) {
      addClass(rows[j],"odd");
    }
  }
}

var nlf = new Array(3.93,5.9,6.95,8.91,14.81,16.78,17.7);
var nls = new Array(5,8.5,18.5,24.4,26.62,27.54,38.42);
var flf = new Array(1.96,3.01,3.93,7.86,10.88,11.8,15.75,16.78,19.62,19.62);
var fls = new Array(3.01,9.83,10.88,18.23,20.52,21.63,27.54,31.47,46.29,46.29);
function calcRakeback(){
	var table = document.getElementById('selGame').value;
	var type = table.substring(0,3);
	var limit = table.substring(4);
	var rake = nlf[limit];
	if (type == "nls")
		rake = nls[limit];
	else if (type == "flf")
		rake = flf[limit];
	else if (type == "fls")
		rake = fls[limit];
	var tables = document.getElementById('selTables').value;
	var hours = document.getElementById('selHours').value;
	var rakeback = document.getElementById('selRakeback').value;
	//alert(type + " " + limit + " " + rake + " " + tables + " " + hours + " " + rakeback);
	document.getElementById('daily').innerHTML = "$" + (hours*tables*rakeback*rake).toFixed(0);
	document.getElementById('weekly').innerHTML = "$" + (hours*tables*rakeback*rake*7).toFixed(0);
	document.getElementById('monthly').innerHTML = "$" + (hours*tables*rakeback*rake*31).toFixed(0);
	document.getElementById('results').style.display = "block";
}


window.onload = function ()
{
	doPopups();
	clearOnFocus('input');
	clearOnFocus('textarea');
	doButtonImages();
	//fdScroller.init();
	stripeTables();
	allTwoCols('two', 'UL');
	allTwoCols('two', 'OL');

	var exists = false;
	
	try
	{
		if (customOnLoad)
			exists = true;
	}
	catch(e){}

	if (exists)
		customOnLoad();
	
}

function InsertAtCursor(field, value)
{
    // IE Support
    if (document.selection)
    {
        field.focus();
        var sel = document.selection.createRange();
        sel.text = value;
    }
    
    // Mozilla\NetScape Support
    else if (field.selectionStart || field.selectionStart == '0')
    {
        var startPos = field.selectionStart;
        var endPos = field.selectionEnd;
        field.value = field.value.substring(0, startPos) + value + field.value.substring(endPos, field.value.length);
    }
    else
    {
        field.value += value;
    }
}

function GetParameter(name)
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )
		return "";
	else
		return results[1];
}

function CookiesEnabled()
{
    var cookieEnabled = (navigator.cookieEnabled) ? true : false;
    
    // If not IE4+ or NS6+
    if (typeof(navigator.cookieEnabled) == "undefined" && !cookieEnabled)
    {
        document.cookie = "testcookie";
        cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false;
    }
    
    return cookieEnabled;
}
// ]]>