﻿
/* register */
function register(firstName, lastName, email, phone, password, bTAC, bFB, bTwitter, clue)
{
    //notifications = true as a default
    var bNotifications = true;
    User.Register(firstName, lastName, phone, email, password, bTAC, bFB, bTwitter, bNotifications, clue, cbRegister);
}
function cbRegister(r)
{
    if (typeof r == 'object')
    {
        /*if (r.error != "")
        {
            alert(r.error);
        }
        else
        {
            alert(r.PK + ' ' + r.FirstName + ' ' + r.LastName + ' ' + r.SocialNetwork + ' ' + r.Clue);
        }*/
        getElem('flashcontent').jsCallback(r, 'register');
    }
}

/* sign in */
function signIn(email, password)
{
    User.SignIn(email, password, cbSignIn);
}
function cbSignIn(r)
{
    if (typeof r == 'object')
    {
        /*if (r.error != "")
        {
            alert(r.error);
        }
        else
        {
            alert(r.PK + ' ' + r.FirstName + ' ' + r.LastName + ' ' + r.SocialNetwork + ' ' + r.Clue);
        }*/

        getElem('flashcontent').jsCallback(r, 'signIn');
    }
}

/* reset notifications */
function setNotifications(pk, bSet)
{
    User.SetNotifications(parseInt(pk), bSet, cbSetNotifications);
}
function cbSetNotifications(r)
{
    if (typeof r == 'object')
    {
        /*if (r.error != "")
        {
            alert(r.error);
        }
        else
        {
            alert('success');
        }*/
        getElem('flashcontent').jsCallback(r, 'setNotifications');
    }
}

/* set clue */
function setClue(pk, clue)
{
    User.SetClue(parseInt(pk), parseInt(clue), cbSetClue);
}
function cbSetClue(r)
{
    if (typeof r == 'object')
    {
        /*if (r.error != "")
        {
            alert(r.error);
        }
        else
        {
            alert(r.Clue);
        }*/
        getElem('flashcontent').jsCallback(r, 'setClue');
    }
}

/***************************/
/********* CLUE 2 **********/
/***************************/
function saveSound(sequence)
{
    User.SaveSound(sequence, cbSaveSound);
}
function cbSaveSound(r)
{
    if (typeof r == 'object')
    {
        getElem('flashcontent').jsCallback(r, 'saveSound');
    }
}

function retrieveSound(pk)
{
    User.RetrieveSound(parseInt(pk), cbRetrieveSound);
}
function cbRetrieveSound(r)
{
    if (typeof r == 'object')
    {
        getElem('flashcontent').jsCallback(r, 'retrieveSound');
    }
}





/*******************************/
/******** FB / TWITTER *********/
/*******************************/
/* FB POST */
function postToFB(title, desc, imgPath, url)
{
    pName = 'Shock Value 2';
    //set global vars in fbConnect.js
    pTitle = title;
    pDesc = desc;
    pLink = url;
    pImage = imgPath;
    fbPublish();
    
}

/* TWITTER POST */
function postToTwitter(title, desc, url)
{
    var width = 800;
    var height = 600;
    var toppos = (window.screen.height/2) - (height + 50)/2;//toolbars 50px;
    var leftpos = (window.screen.width / 2) - (width + 10)/2;//border 2x5px;
    var features = 'width=' + width + ',height=' + height + ',top=' + toppos + ',left=' + leftpos + ',menubar=no,resizable=yes,scrollbars=no,status=no,titlebar=no';

    var w = window.open('twitterConnect/Default.aspx?title=' + title + '&desc=' + desc + '&link=' + url, 'Twitter', features);
    if (!w)
    {
        getElem('flashcontent').jsCallback('We have detected that you are using a popup blocker. Please disable it for the best experience on this site. Thank you.', 'popup');
        w.close();
    }
    
}


function popup()
{

    var features = 'width=1,height=1,top=0,left=0,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no';
    var w = window.open('popup.aspx','',features);
    if (!w)
    {
        var r = { error: 'We have detected that you are using a popup blocker. Please disable it for the best experience on this site. Thank you.' };
        getElem('flashcontent').jsCallback(r, 'popup');
    }
    else
    {
        var r = { error: '' };
        getElem('flashcontent').jsCallback(r, 'popup');
    }
    w.close();
}

/* email */
function email(url, sender, recipientList)
{
    User.Email(url, sender, recipientList, cbEmail);
}
function cbEmail(r)
{
    getElem('flashcontent').jsCallback(r, 'email');
}

/* shorten url */
function shortenUrl(url)
{
    User.ShortenUrl(url, cbShortenUrl);
}
function cbShortenUrl(r)
{
    getElem('flashcontent').jsCallback(r, 'shortenUrl');
}
