var profile = null;

function openPhoto(args)
{
  h=500;
  w=550;
  s='height='+h+', width='+w+', top='+(screen.height-h-30)/2+', left='+(screen.width-w)/2+', status=yes, scrollbars=yes, resizable=yes';
  win=window.open("/cornice.jsp?id="+args+"&p="+(Math.random()+"R").substring(2), "photo", s);
  win.window.focus();
}

function openPhotoFromAlbum(args)
{
  h=500;
  w=550;
  s='height='+h+', width='+w+', top='+(screen.height-h-30)/2+', left='+(screen.width-w)/2+', status=yes, scrollbars=yes, resizable=yes';
  win=window.open("/cornice.jsp?id="+args+"&t=2&p="+(Math.random()+"R").substring(2), "photo", s);
  win.window.focus();
}

function openProfile(args)
{
  h=400;
  w=250;
  s='height='+h+', width='+w+', top='+(screen.height-h-30)/2+', left='+(screen.width-w)/2+', status=no, scrollbars=no, resizable=no';
  profile=window.open("/profile.jsp?id="+args+"&p="+(Math.random()+"R").substring(2), "profile", s);
  profile.window.focus();
}

function openProfileByNick(args)
{
  h=400;
  w=250;
  s='height='+h+', width='+w+', top='+(screen.height-h-30)/2+', left='+(screen.width-w)/2+', status=no, scrollbars=no, resizable=no';
  profile=window.open("/profile.jsp?nick="+args+"&p="+(Math.random()+"R").substring(2), "profile", s);
  profile.window.focus();
}

function closeProfile()
{
  profile.window.close();
}

function findPassword()
{
  h=500;
  w=700;
  s='height='+h+', width='+w+', top='+(screen.height-h-30)/2+', left='+(screen.width-w)/2+', status=yes, scrollbars=no, resizable=no';
  win=window.open("password.jsp", "pssword", s);
  win.window.focus();
}

function openAnagrafica(args)
{
  h=500;
  w=700;
  s='height='+h+', width='+w+', top='+(screen.height-h-30)/2+', left='+(screen.width-w)/2+', status=yes, scrollbars=no, resizable=no';
  win=window.open("/anagrafica.jsp?&p="+(Math.random()+"R").substring(2), "anagrafica", s);
  win.window.focus();
}

function openMessages(arg1, arg2)
{
  h=500;
  w=700;
  s='height='+h+', width='+w+', top='+(screen.height-h-30)/2+', left='+(screen.width-w)/2+', status=yes, scrollbars=no, resizable=no';
  if (arg2!="") arg2="&id=" + arg2;
  win=window.open("my2dp/index.jsp?page="+arg1+arg2+"&p="+(Math.random()+"R").substring(2), "my2dp", s);
  win.window.focus();
}

function sendMessage(args)
{
  openMessages ("1", args);
}

function sendSMS(args)
{
  h=200;
  w=300;
  s='height='+h+', width='+w+', top='+(screen.height-h-30)/2+', left='+(screen.width-w)/2+', status=no, scrollbars=no, resizable=no';
  win=window.open("/sms.jsp", "sms", s);
  win.window.focus();
}

function openContacts()
{
  openMessages ("4", "");
}

function openBuy(args)
{
  sendSMS (args);
  //alert ("Ancora niente SMS! Riprova tra qualche giorno...");
}

function addToContacts(args)
{
  openMessages ("4", args);
}

function requestCensure(args)
{
  h=200;
  w=300;
  s='height='+h+', width='+w+', top='+(screen.height-h-30)/2+', left='+(screen.width-w)/2+', status=no, scrollbars=no, resizable=no';
  win=window.open("/censure.jsp?id="+args+"&p="+(Math.random()+"R").substring(2), "censure", s);
  win.window.focus();
}

function openScocciatori(args)
{
  h=200;
  w=350;
  s='height='+h+', width='+w+', top='+(screen.height-h-30)/2+', left='+(screen.width-w)/2+', status=no, scrollbars=no, resizable=no';
  win=window.open("/scocciatori.jsp?id="+args+"&p="+(Math.random()+"R").substring(2), "censure", s);
  win.window.focus();
}

function messaggio(arg1)
{
  alert (arg1);
}

function showBanner(arg1)
{
  if (arg1=='1')
    document.getElementById ("banner").style.visibility = "visible";
  else
    document.getElementById ("banner").style.visibility = "hidden";
}

function openChat ()
{
  h=620;
  w=760;
  s='height='+h+', width='+w+', top='+(screen.height-h-30)/2+', left='+(screen.width-w)/2+', status=yes, scrollbars=no, resizable=no';
  // il percorso assoluto va specificato in modo che si possa controllare il referres dalla vc
  win=window.open("/vc/index.jsp?p="+(Math.random()+"R").substring(2), "2dpvc", s); 
  win.window.focus();
}

function openBlindDate ()
{
  win=window.open("/blinddate/index.jsp?p="+(Math.random()+"R").substring(2), "blinddate", "fullscreen"); 
  win.window.focus();
}

function openMainWindow ()
{
  try
  {
    w = screen.availWidth;
    h = screen.availHeight;
    s='height='+h+', width='+w+', top=0, left=0, screenX=0, screenY=0, status=no, scrollbars=' + (w<950?'yes':'no') + ', resizable=1, maximize=1';
    win=window.open("duedipicche.jsp?w="+w+"&h="+h+"&p="+(Math.random()+"R").substring(2), "DueDiPicche", s); //window.open("page.htm", "WindowName", "fullscreen");
    win.window.focus();

    win.window.moveTo(0,0);

    if (document.all)
      win.window.resizeTo(screen.availWidth, screen.availHeight);
    else if (document.layers||document.getElementById)
    {
      if (win.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth)
      {
        win.window.outerHeight = screen.availHeight;
        win.window.outerWidth = screen.availWidth;
      }
    }
  }
  catch (e)
  {
    popupBlock(true);
    return;
  }
  
  popupBlock(false);
}


function ASInteraction (command, args)
{
  if (command=="openProfile")
    openProfile(args);
  else if (command=="openProfileByNick")
    openProfileByNick(args);
  else if (command=="openAnagrafica")
    openAnagrafica(args);
  else if (command=="openMessages")
    openMessages("1", "");
  else if (command=="openContacts")
    openContacts();
  else if (command=="openBuy")
    openBuy(args);
  else if (command=="openPhoto")
    openPhoto(args);
  else if (command=="openPhotoFromAlbum")
    openPhotoFromAlbum(args);
  else if (command=="sendMessage")
    sendMessage(args);
  else if (command=="sendSMS")
    sendSMS(args);
  else if (command=="addToContacts")
    addToContacts(args);
  else if (command=="requestCensure")
    requestCensure(args);
  else if (command=="closeProfile")
    closeProfile();
  else if (command=="findPassword")
    findPassword();
  else if (command=="showBanner")
    showBanner(args);
  else if (command=="openChat")
    openChat ()
  else if (command=="openBlindDate")
    openBlindDate ()
  else if (command=="openScocciatori")
    openScocciatori ()
  else if (command=="messaggio")
    messaggio(args);
  else if (command=="blindDate" && args=="quit")
    window.close()
  else if (command=="openMainWindow")
    openMainWindow()
  else 
    alert ("error: " + command + " " + args);
 }
