/*
CSS Browser Selector v0.2.8
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
var css_browser_selector = function() {
var ua=navigator.userAgent.toLowerCase(),
is=function(t){return ua.indexOf(t) != -1;},
h=document.getElementsByTagName('html')[0],
b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?'gecko ff2':is('firefox/3')?'gecko ff3':is('gecko/')?'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('chrome')?'chrome webkit safari':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',
os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';
var c=b+os+' js'; h.className += h.className?' '+c:c;
}();

/*Start scripts for pop up and page switch controls */

function returnObjById( id ) 
{ 
	if (document.getElementById) 
		var returnVar = document.getElementById(id); 
	else if (document.all) 
		var returnVar = document.all[id]; 
	else if (document.layers) 
		var returnVar = document.layers[id]; 
	return returnVar; 
}

if (!String.prototype.endsWith) {
    String.prototype.endsWith = function(suffix) {
        var startPos = this.length - suffix.length;
        if (startPos < 0) {
            return false;
        }
        return (this.lastIndexOf(suffix, startPos) == startPos);
    };
}

function showPopup(disp, section, id) {
    var popup_div = returnObjById(section + 'popup');
    var overlay_div = returnObjById(section + 'overlay');
    var bodybg_div = returnObjById(id);
    var select_dl = returnObjById('ieFix_select');
    var select2_dl = returnObjById('ieFix_select2');
    
    if (disp == 'show') {
        popup_div.style.display = 'block';
        overlay_div.style.display = 'block';

        if (id.endsWith("bodybg")) {
            bodybg_div.style.backgroundImage = "url('images/bg_login_dim.jpg')";
            if (select_dl) select_dl.style.display = 'none';
            if (select2_dl) select2_dl.style.display = 'none';
        } 
        else if (id.endsWith("bodybgreg")) {
            bodybg_div.style.backgroundImage = "url('images/bg_registration_dim.jpg')";
            if (select_dl) select_dl.style.display = 'none';
        } 
        else if (id.endsWith("bodybgupc")) {
            bodybg_div.style.backgroundImage = "url('images/bg_upc_dim.jpg')";
        }
		else if (id.endsWith("bodybgupc_played")) {
            bodybg_div.style.backgroundImage = "url('images/bg_profHist_dim.jpg')";
        }

    }
    else {
        popup_div.style.display = 'none';
        overlay_div.style.display = 'none';

        if (id.endsWith("bodybg")) {
            bodybg_div.style.backgroundImage = "url('images/bg_login.jpg')";
            if (select_dl) select_dl.style.display = 'block';
            if (select2_dl) select2_dl.style.display = 'block';
        } 
        else if (id.endsWith("bodybgreg")) {
            bodybg_div.style.backgroundImage = "url('images/bg_registration.jpg')";
            if (select_dl) select_dl.style.display = 'block';
        } 
        else if (id.endsWith("bodybgupc")) {
            bodybg_div.style.backgroundImage = "url('images/bg_upc.jpg')";
        }
		else if (id.endsWith("bodybgupc_played")) {
            bodybg_div.style.backgroundImage = "url('images/bg_profHist.jpg')";
        }
        
    }
}

function validateForgotPW()
{
	var my_email_reg = /[_a-zA-Z0-9.-]+@[_a-zA-Z0-9.-]+[.][_a-zA-Z0-9.-][_a-zA-Z0-9.-]+/;
	var my_email = document.forgot_password_form.email.value;
	var res = my_email_reg.test(my_email);
	if (!res)
	{
		alert("The email address entered for Email " + my_email + " is not valid.");
		document.forgot_password_form.your_email.focus();
		return false;
	}
	submitForgotPW();
}

function submitForgotPW()
{
	var url = 'test.html';
	var post_string = 'email=' + encodeURI(document.forgot_password_form.email.value);
	var location = 'login-popupcontents';
	var xObj = false;
	xObj = getHTTPObject();
	xObj.open('POST', url,true);
	xObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xObj.onreadystatechange=function()
	{
		if (xObj.readyState==4)
		{
			document.getElementById(location).innerHTML = xObj.responseText;
		}
	}
	xObj.send(post_string);
}

function getHTTPObject()
{
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
	try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	  try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
		xmlhttp = false;
	  }
	}
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	try {
	  xmlhttp = new XMLHttpRequest();
	} catch (e) {
	  xmlhttp = false;
	}
  }
  return xmlhttp;
}

function toggleProfile(disp)
{
	var profile_div = returnObjById('profileForm');
	var gamehistory_div = returnObjById('gameHistory');
	if(disp == 'hide')
	{
		profile_div.style.display = 'none';
		gamehistory_div.style.display = 'block';
	}
	else
	{
		profile_div.style.display = 'block';
		gamehistory_div.style.display = 'none';
	}
}

/*End scripts for pop up and page switch controls */
