
//////////////////////////////////////////////////////////////
//Copyright 2006-2007 Yoogli
//requires js_ajax.js

var g_raceid=0;

function open_grey_screen_background(number)
{

    
    dim = YGWin.getDocumentDimensions();

    styletext='display:block;width:100%;height:'+dim.height+'px;background-color:#000000;filter:alpha(opacity=50);opacity:0.5;-moz-opacity:0.5;position:absolute;top:0px;left:0px;z-index:1000';
    idtext='grey_screen_div'+number;
    obj = DOMelement("DIV");
      obj.setAttribute("id",idtext);
      obj.setAttribute("style",styletext);
    document.body.appendChild( obj.createElement() );
}

function addfriend(friend)
{
    var paramsobj = new Object();
    paramsobj.friend = friend;

    AJAX.execute(ajax_friend_setup, ajax_friend_response, paramsobj);
}

function ajax_friend_setup(paramsobj)
{
    var myObject = new Object();
    myObject.action  = 'friend_request';
    myObject.id      = g_raceid++;
    myObject.session = g_session;
    myObject.friend  = paramsobj.friend;
    myObject.from    = g_friendname;
    myObject.message = '';//add this later
    return myObject;
}
function ajax_friend_response(ajaxobj,paramsobj)
{
    var search_xml = XML.getDocumentTag(ajaxobj.responseXML);

    var reason = XML.getTextByName(search_xml,"reason");
    var result = XML.getTextByName(search_xml,"result");

    //alert(ajaxobj.responseText);

    if (result=='success')
    {
        alert( 'This user will be added to your friends as soon as they confirm your request');
    }
    else
    {
        alert( 'Error, try again later' );
    }
}

//----------------------------------------------------------------
// Invite friends
//----------------------------------------------------------------

function open_invitethisfriend(fromemail,toemail)
{
    open_invitefriends(fromemail);
    document.getElementById('dynform_toemail').innerHTML = toemail;
}

function open_invitefriends(fromemail)
{
    open_grey_screen_background();
    open_invite_div(fromemail);
}
function close_invite_div()
{
    removeElementbyName('grey_screen_div');
    removeElementbyName('invite_friends_div');
}
function open_invite_div(fromemail)
{
    var wind_width  = 600;
    var wind_height = 600;
    var c_window    = YGWin.getCenteredWindowCoords(wind_width,wind_height);
    var left_coord  = c_window.left;
    var top_coord   = c_window.top;

    idtext='invite_friends_div';
    styletext ="display:block;width:"+wind_width+"px;height:"+wind_height+"px;position:absolute;top:"+top_coord+"px;left:"+left_coord+"px;z-index:1002";
    obj = DOMelement("DIV");
    obj.setAttribute("id",idtext);
    obj.setAttribute("style",styletext);

    obj.innerHTML=get_invite_div_html(fromemail);

    document.body.appendChild( obj.createElement() );
}
function get_invite_div_html(fromemail)
{
    blu_x = page_to_src("images/yg2_dialog_x_unselected.gif");
    red_x = page_to_src("images/yg2_dialog_x_selected.gif");
    h='';
    h+=  "<div style='background:#E8EDFF; border:1px solid #096DC2; padding:8px;'>";
    //---------------------------------------------------
    h+=      "<div style='float:right;padding-right:5px; padding-top:5px;'>";
    h+=           "<a href='javascript:close_invite_div();'><img src='"+blu_x+"' onmouseover='this.src=\""+red_x+"\";' onmouseout='this.src=\""+blu_x+"\";' width=25 height=25 style='cursor:pointer;'></a>";
    h+=      "</div>";
    //---------------------------------------------------
    h+=      "<div style='background:#ffffff; padding:5px;'>";
    h+=           get_invite_form(fromemail);
    h+=      "</div>";
    h+=  "</div>";
    return h;
}
function get_invite_form(fromemail)
{
    h='';
    h+="<br>";
    h+=  "<div>";
    h+=  "<table cellpadding=4 cellspacing=0 border=0 width=90% style='color:#333333'>";
    h+=    "<tr>";
    h+=      "<td valign=top align=right>";
    h+=          "<b>From:</b>";
    h+=      "</td>";
    h+=      "<td width=60%>";
    h+=          "<div type=text name=from style='border:1px solid #ccc; width:260px; height:18px;'>"+fromemail+"</div>";
    h+=      "</td>";
    h+=    "</tr>";
    h+=    "<tr>";
    h+=      "<td valign=top align=right>";
    h+=          "";
    h+=          "<b>To:</b><br> (use commas to <br>separate emails)";
    h+=      "</td>";
    h+=      "<td>";
    h+=          "";
    h+=          "<textarea id='dynform_toemail' name='to' rows=8 cols=30 style='border:1px solid #ccc;'></textarea>";
    h+=      "</td>";
    h+=    "</tr>";
    h+=    "<tr>";
    h+=      "<td valign=top align=right>";
    h+=          "<b>Message:</b><br> (optional)";
    h+=      "</td>";
    h+=      "<td>";
    h+=          "";
    h+=          "<textarea id='dynform_invitemsg' name='invitemsg' rows=8 cols=30 style='border:1px solid #ccc;'></textarea>";
    h+=          "<br>";
    h+=          "<input type=button value='Invite' onclick='send_invitation()' class=blue>";
    h+=          "&nbsp;";
    h+=          "<input type=button value='Cancel' onclick='close_invite_div();'>";
    h+=      "</td>";
    h+=    "</tr>";
    h+=  "</table>";
    h+=  "</div>";
    return h;
}

function send_invitation()
{
    var paramsobj     = new Object();
    paramsobj.email   = document.getElementById('dynform_toemail').value;
    paramsobj.message = document.getElementById('dynform_invitemsg').value;
    AJAX.execute(ajax_invite_setup, ajax_invite_response, paramsobj);
}

function ajax_invite_setup(paramsobj)
{
    var myObject = new Object();
    myObject.action  = 'friend_invite';
    myObject.id      = g_raceid++;
    myObject.session = g_session;
    myObject.email   = paramsobj.email;
    myObject.from    = g_friendname;
    myObject.message = paramsobj.message;
    return myObject;
}
function ajax_invite_response(ajaxobj,paramsobj)
{
    var search_xml = XML.getDocumentTag(ajaxobj.responseXML);

    var reason = XML.getTextByName(search_xml,"reason");
    var result = XML.getTextByName(search_xml,"result");

    //alert(ajaxobj.responseText);

    if (result=='success')
    {
        alert( 'Your invitation has been sent!');
        close_invite_div();
    }
    else
    {
        alert( 'Error, try again later' );
    }
}
//----------------------------------------------------------------
//
//----------------------------------------------------------------

function open_whybirthday()
{
    open_grey_screen_background();
    open_whybirthday_div();
}
function close_whybirthday_div()
{
    removeElementbyName('grey_screen_div');
    removeElementbyName('why_birthday_div');
}
function open_whybirthday_div()
{
    var wind_width  = 450;
    var wind_height = 600;
    var c_window    = YGWin.getCenteredWindowCoords(wind_width,wind_height);
    var left_coord  = c_window.left;
    var top_coord   = c_window.top;

    idtext='why_birthday_div';
    styletext ="display:block;width:"+wind_width+"px;height:"+wind_height+"px;position:absolute;top:"+top_coord+"px;left:"+left_coord+"px;z-index:1002";
    obj = DOMelement("DIV");
    obj.setAttribute("id",idtext);
    obj.setAttribute("style",styletext);

    obj.innerHTML=get_whybday_html();

    document.body.appendChild( obj.createElement() );

}
function get_whybday_html()
{
    blu_x = page_to_src("images/yg2_dialog_x_unselected.gif");
    red_x = page_to_src("images/yg2_dialog_x_selected.gif");
    h='';
    h+=  "<div style='background:#E8EDFF; border:1px solid #096DC2; padding:8px;'>";
    //---------------------------------------------------
    h+=      "<div style='float:right;padding-right:5px; padding-top:5px;'>";
    h+=           "<a href='javascript:close_whybirthday_div();'><img src='"+blu_x+"' onmouseover='this.src=\""+red_x+"\";' onmouseout='this.src=\""+blu_x+"\";' width=25 height=25 style='cursor:pointer;'></a>";
    h+=      "</div>";
    //---------------------------------------------------
    h+=      "<div style='background:#ffffff; padding:5px;'>";
    h+=           "<div style='font-size:14pt;color:#5481E8;background:#E8EDFF;padding:5px;border:1px solid #5481E8;margin-right:50px;'>";
    h+=               "Why do I need to provide my birthday?";
    h+=           "</div>";
    h+=           "<br>";    
    h+=           "<div style='padding:5px;'>";
    h+=               "Yoogli Music requires all users to provide their full name and birthday"+"<br>";
    h+=               "as a means of maintaining site efficiency as well as providing a safe"+"<br>";    
    h+=               "environment.  You will be able to hide this information from your profile"+"<br>";        
    h+=               "if you choose."+"<br>";        
    h+=               "<br>";    
    h+=           "</div>";
    h+=      "</div>";
    h+=  "</div>";
    return h;
}
