var context = '/dream';
// ------------------ Variables de definició de Window Open ------------------
var woWEB = 'resizable=yes, scrollbars=yes, toolbar=yes, status=yes';
var woWEB_1024 = 'resizable=yes, width=1024, height=768, scrollbars=yes, toolbar=yes, status=yes';
var woWEB_FULL = 'fullscreen=yes, resizable=yes, scrollbars=yes, toolbar=yes, status=yes';

var woInternacional         = 'width=600, height=240, scrollbars=no, toolbar=no, status=yes';
var woInternacionalTextArea = 'width=750, height=550, scrollbars=yes, toolbar=no, status=yes';

//var woPDF   = 'width=800, height=600, resizable=yes, scrollbars=yes, toolbar=no, status=yes';
var woPDF   = '';
var woNull           = 'width=100, height=100, scrollbars=no, toolbar=no, status=no';
var woMasterDetall   = 'width=740, height=250, scrollbars=yes, toolbar=no, status=yes';
var woMasterDetall1  = 'width=740, height=300, scrollbars=yes, toolbar=no, status=yes';
var woMasterDetall11 = 'width=840, height=300, scrollbars=yes, toolbar=no, status=yes';
var woMasterDetall2  = 'width=740, height=350, scrollbars=yes, toolbar=no, status=yes';
var woMasterDetall22 = 'width=840, height=350, scrollbars=yes, toolbar=no, status=yes';
var woMasterDetall3  = 'width=740, height=400, scrollbars=yes, toolbar=no, status=yes';
var woMasterDetall4  = 'width=740, height=450, scrollbars=yes, toolbar=no, status=yes';
var woMasterDetall5  = 'width=740, height=500, scrollbars=yes, toolbar=no, status=yes';
var woMasterDetall6  = 'width=740, height=550, scrollbars=yes, toolbar=no, status=yes';
var woMasterDetall7  = 'width=740, height=600, scrollbars=yes, toolbar=no, status=yes';
var woMasterDetall8  = 'width=740, height=650, scrollbars=yes, toolbar=no, status=yes';

var woFotoAG = 'width=400, height=290, scrollbars=no, toolbar=no, status=no';

var uploadFeatures = 'width=450, height=110, scrollbars=no, resizable=yes';

var woHidden        = 'width=1, height=1, scrollbars=no, toolbar=no, status=no';

var timeOutMN = 500;
var finestra  = null;

// ------------------- Funcions estandard i tipiques de JS --------------------

function SubmitForm()
{
  setTimeout('document.forms[0].submit()', timeOutMN);
}

function fNavegador()
{
 var vNavigator = navigator.appName;
 var vVersion = parseInt(navigator.appVersion);
 var vRet;

 if (vNavigator == "Netscape") vRet = "N"
 else vRet = "IE";

 if (vVersion >= 5)
 {
  if (vNavigator == "Netscape") vRet += "6";
  else vRet += "5";
 }
 else vRet += "4";

 return (vRet);
}


// Retornem l'apuntador al formulari de nom pForm
function fGetForm (pForm, pLayer)
{
 var nNavegador = fNavegador();

 if (nNavegador.substr(1,1) >= 6) return (document.getElementById(pForm));
 else
 {
  if (nNavegador.substr(0,1) == "N")
  {
   if (pLayer == null) return (document.forms[pForm]);
   else return (document.layers[pLayer].document.forms[pForm]);
  }
 }

 return (document.all[pForm]);
}


function fOpenWindow (pUrl, pTarget, pAtributos)
{
  finestra = window.open(pUrl, pTarget, pAtributos);
}

function SwapImg(codi)
{
  var imgNova = 'imgS'+codi;

  if (imgSel.name != '')
  {
    if (imgSel.name != imgNova)
    {
      imgSel.src = imgNoSelSrc;
      imgSel     = eval("document."+imgNova);
      imgSel.src = imgSelSrc;
    }
    else //És la mateixa
    {
      imgSel.src  = imgNoSelSrc;
      imgSel = new Image();
      imgSel.name = '';
    }
  }
  else //No n'hi ha cap de seleccionada
  {
    imgSel     = eval("document."+imgNova);
    imgSel.src = imgSelSrc;
  }

  fAssignarCamp('pCodi',codi);
}


// Passa el nom del fitxer que es fa UpLoad
function passarFitxer(pCamp, pFitxer)
{
 f.elements[pCamp].value = pFitxer;
}


function canviPestanya(url)
{
  var f = document.forms[0];
  var w = document;
 
  if (f)
  {
    var fAction = f.action;
    var fOp     = f.op.value;
    
    if ((fAction.indexOf('set.do')==-1) || (fOp!='GU'))
    {
      w.location = url;
    }
    else
    {
      alert('standard.js Tens un element bloquejat, Cancela l\'acció primer.');
    }
  }
  else 
  {
    w.location = url;
  }
}

//control -> Nom del control multibox a marcar tots
//marker  -> Referencia al checkbox que marca l'estat del multibox

function fMarcarMultibox(control,marker)
{
    f=document.forms[0];
    var che=eval("f.elements['"+control+"']");
    var max= che.length;
    for (var idx = 0; idx < max; idx++) {
     eval("f.elements['"+control+"']["+idx+"].checked=marker.checked");
   }
}

function resetDia(t)
{
   var f = document.forms[0];
   f.elements[t].value = "";
}

function resetFK(t, h)
{
   var f = document.forms[0];
   f.elements[t].value = "";
   f.elements[h].value = 0;   
}

function resetFK(t)
{
   var f = document.forms[0];
   f.elements[t].selectedIndex = -1;
}

function open_upload (campRetorn, conf) 
{
  var camp = document.forms[0].elements[campRetorn];
  
  if (camp.value=='')
  {
    theURL = context+"/upload/document.do?fitxerInfo.nomCampRetorn=" + campRetorn + "&fitxerInfo.conf=" + conf;
    winName = "uploadwindow";
    window.open(theURL, winName, uploadFeatures);
  }
  else alert('Primer tens que eliminar la imatge existent.');
}

function open_upload (campRetorn, campMime, campSubMime, conf) 
{
  var camp = document.forms[0].elements[campRetorn];
  
  if (camp.value=='')
  {
    theURL = context+"/upload/document.do?fitxerInfo.nomCampRetorn=" + campRetorn + "&fitxerInfo.nomMime=" + campMime + "&fitxerInfo.nomSubMime=" + campSubMime + "&fitxerInfo.conf=" + conf;
    winName = "uploadwindow";
    window.open(theURL, winName, uploadFeatures);
  }
  else alert('Primer tens que eliminar la imatge existent.');
}

function open_upload_generic (campRetorn, campMime, campSubMime, conf) 
{
  var camp = document.forms[0].elements[campRetorn];
  
  if (camp.value=='')
  {
    theURL = context+"/uploadgeneric/document.do?fitxerInfo.nomCampRetorn=" + campRetorn + "&fitxerInfo.nomMime=" + campMime + "&fitxerInfo.nomSubMime=" + campSubMime + "&fitxerInfo.conf=" + conf;
    winName = "uploadwindow";
    window.open(theURL, winName, uploadFeatures);
  }
  else alert('Primer tens que eliminar la imatge existent.');
}

function open_delete (campRetorn, servei) 
{
  var camp = document.forms[0].elements[campRetorn];
  camp.value = ""; //******************************
  if (camp.value!='')
  {
    theURL = context+"/upload/deleteFile.do?deleteFile.campRetorn="+campRetorn+"&deleteFile.nomFitxer="+camp.value+"&deleteFile.servei="+servei;
    winName = "deletewindow";
    window.open(theURL, winName, uploadFeatures);
  }
}

function open_delete_generic (campRetorn, servei) 
{
  var camp = document.forms[0].elements[campRetorn];
  camp.value = ""; //******************************
  if (camp.value!='')
  {
    theURL = context+"/uploadgeneric/deleteFile.do?deleteFile.campRetorn="+campRetorn+"&deleteFile.nomFitxer="+camp.value+"&deleteFile.servei="+servei;
    winName = "deletewindow";
    window.open(theURL, winName, uploadFeatures);
  }
}

/** Funcion llamada despues de finalizar la subida de un fichero */
function onUpload()
{
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}



/*************
 * Funcions associades a la tecnologia Ajax
 ************/
function include(url)
{
  var e = document.createElement("script");
  e.src = url;
  e.type = "text/javascript";
  document.getElementsByTagName("head")[0].appendChild(e);
}

function ajaxResultatNull(resposta, obj)
{
  var dBody = document.getElementById(obj);
  dBody.innerHTML = resposta;
}

function ajaxResultat(resposta, obj)
{
//alert(resposta);
  var dBody = document.getElementById(obj);
  dBody.innerHTML = resposta;
  var res = resposta;

  for (var r=0; r<res.length; r++)
  {
    var si = res.indexOf("<script");
    if (si >= 0)
    {
      var sf = res.indexOf("</script");
      var scripts = res.substring(si,sf);
      if (scripts.indexOf("src=")>=0)
      {
        var source = scripts.substring(scripts.indexOf("src=")+5, scripts.indexOf('\"', scripts.indexOf("src=")+5));
//        alert(source);
        include(source);
        res = res.substr(sf+9);
      }
    }
    else
    {
      res = "";
    }
  }
}

