// JavaScript Document
function MM_swapImgRestore() { //v3.0
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
    var d=document; if(d.images){
        if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
            if (a[i].indexOf("#")!=0){
                d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
            }
    }
}

function MM_findObj(n, d) { //v4.01
    var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
    }
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
        if ((x=MM_findObj(a[i]))!=null){
            document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
        }
}

function matchInputFields( fieldA, fieldB, responseID )
{
    if( document.getElementById(fieldA).value == "" || document.getElementById(fieldB).value == "" )
        document.getElementById(responseID).innerHTML = 'No Match';
    else if(document.getElementById(fieldA).value == document.getElementById(fieldB).value)
        document.getElementById(responseID).innerHTML = 'GOOD!';
    else
        document.getElementById(responseID).innerHTML = 'No Match';
}

function filterText(elem, filterType){
    var regExp;
	
    switch(filterType){
        case 'alphaNum':
            regExp = /[^a-zA-Z0-9 ]+/;
            break;
        case 'numbers':
            regExp = /[^0-9]+/;
            break;
        case 'phone':
            regExp = /[^0-9\- ]+/;
            break;
        case 'email':
            regExp = /[^a-z0-9\-@_.]+/;
            break;
        default:
            regExp = /[^a-zA-Z0-9\-.!@#$&=+ ]+/;
            break;
    }

    elem.value = elem.value.replace(regExp,'');
}

function openLobby()
{
    var lobbyWindow;
    if( screen.width > 800 && screen.height > 600 )
        lobbyWindow = window.open("http://www.dominochamp.com/Game/DominoChampLobby.html","lobby","width=900,height=640,resizable=1,scrollbars=1");
    else
        lobbyWindow = window.open("http://www.dominochamp.com/Game/DominoChampLobby800x600.html","lobby","width=640,height=456,resizable=1,scrollbars=1");
    if(!lobbyWindow)
        alert("Close the lobby and turn off your browser's pop-up blocker!");
    else
    {
        location.href = "http://www.dominochamp.com/Game/";
        lobbyWindow.focus();
    }
}

function openFacebookLobby()
{
    var lobbyWindow;
    if( screen.width > 800 && screen.height > 600 )
        lobbyWindow = window.open("http://www.dominochamp.com/Game/FacebookLobby.html","lobby","width=900,height=640,resizable=1,scrollbars=1");
    else
        lobbyWindow = window.open("http://www.dominochamp.com/Game/FacebookLobby800x600.html","lobby","width=640,height=456,resizable=1,scrollbars=1");
    if(!lobbyWindow)
        alert("Close the lobby and turn off your browser's pop-up blocker!");
    else
    {
        location.href = "http://www.dominochamp.com/Game/";
        lobbyWindow.focus();
    }
}

function call(ajaxScript, container, params, evalScript){
    $(container).innerHTML = '<p style="text-align:center;margin-top:'+Math.round($(container).offsetHeight*0.4)+'px"><img src="../siteImages/loader.gif" width="42" height="42" /></p>';
    new Ajax.Updater(container, ajaxScript+'?__uid='+(new Date().getTime()), {
        parameters: params,
        evalScripts: evalScript
    });
    return false;
}

function clickTab(el, folderName){
    $A($('accountTable').getElementsByClassName('accountTabOn')).invoke('setAttribute', 'class', 'accountTabOff');
    Element.up(el).setAttribute('class', 'accountTabOn');
    call(folderName + '/ajax.main.php', 'accountPanel');
}

function claim(button, prizeID){
    button.value = 'Wait...';
    button.disabled = true;
    new Ajax.Updater($('_prize'+prizeID), '_ClaimPrizes/ajax.claim.php?__uid='+(new Date().getTime()), {
        parameters: {
            id: prizeID,
            action: 'claim'
        }
        });
    return false;
}

function reject(button, prizeID){
    if( confirm("Rejecting a prize cannot be undone.\n\nAre you sure you want to reject this prize?") )
    {
        button.value = 'Wait...';
        button.disabled = true;
        new Ajax.Updater($('_prize'+prizeID), '_ClaimPrizes/ajax.claim.php?__uid='+(new Date().getTime()), {
            parameters: {
                id: prizeID,
                action: 'reject'
            }
            });
    }
    return false;
}

function payoutPref(type){
    new Ajax.Request('_ClaimPrizes/ajax.payout.php?__uid='+(new Date().getTime()), {
        parameters:{
            method: type
        },
        onSuccess: function(){
            alert("Your Payout Preference has been saved.\n\nYou will now be paid via "+type+".");
        },
        onFailure: function(){
            alert("There was an error. Please try again.");
        }
    });
}

function openSubscription()
{
    var lobbyWindow;
    if( screen.width > 800 && screen.height > 600 )
        lobbyWindow = window.open("Subscribe/StepOne.php","lobby","width=900,height=640,resizable=1,scrollbars=1");
    else
        lobbyWindow = window.open("Subscribe/StepOne.php","lobby","width=640,height=456,resizable=1,scrollbars=1");
    if(!lobbyWindow)
        alert("Close the lobby and turn off your browser's pop-up blocker!");
    else
    {
        //location.href = "../Game/";
        lobbyWindow.focus();
    }
}

function saveShipping(button){
    button.value = ' . . . . Saving Changes . . . . ';
    button.disabled = true;
    new Ajax.Request('_ClaimPrizes/ajax.shipping.php?__uid='+(new Date().getTime()), {
        parameters:{
            _name: $F('_name'),
            _address: $F('_address'),
            _city: $F('_city'),
            _state: $F('_state'),
            _zip: $F('_zip'),
            _phone: $F('_phone'),
            _fax: $F('_fax'),
            _country: $F('_country')
        },
        onSuccess: function(){
            alert("Your changes have been saved.");
        },
        onFailure: function(){
            alert("There was an error. Please try again.");
        },
        onComplete: function(){
            button.value = 'Save Shipping Address Changes'; button.disabled = false;
        }
    });
}

function checkNameAvailability(){
    $('_checkPlayerNameResponse').innerHTML = 'Please wait...';
    new Ajax.Updater('_checkPlayerNameResponse', '../Register/ajax.checkPlayerName.php?__uid='+(new Date().getTime()), {
        parameters: {
            search: $F('_playerName')
        }
        });
}

function checkSubmit(){
    if(document.getElementById('_playerName').value == ""){
        alert('Please enter your DominoChamp Player Name before registering.');
        return false;
    }
    if(document.getElementById('_email').value == '' || document.getElementById('_email').value != document.getElementById('_emailVerify').value){
        alert('Your email fields do not match. Please fix those before registering.');
        return false;
    }
    if(document.getElementById('_password').value == '' || document.getElementById('_password').value != document.getElementById('_passwordVerify').value){
        alert('Your password fields do not match. Please fix those before registering.');
        return false;
    }
    if(document.getElementById('_secretAnswer').value == ""){
        alert('Please enter your security question answer before registering.');
        return false;
    }

    return true;
}
