var context = '';
// ------------------ 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 woInternacional2 = 'width=600, height=300, scrollbars=no, toolbar=no, status=yes';
var woMedia = 'scrollbars=yes, toolbar=no, status=yes, resize=yes';
var woInternacionalTextArea = 'width=700, height=510, scrollbars=yes, toolbar=no, status=yes';
var woInternacionalTextArea2 = 'width=700, height=820, scrollbars=no, toolbar=no, status=yes';
var woInternacionalTextArea3 = 'width=700, height=200, scrollbars=no, toolbar=no, status=yes';

//var woPDF   = 'width=800, height=600, resizable=yes, scrollbars=yes, toolbar=no, status=yes';
var woPDF   = '';
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 woMasterDetall9  = 'width=570, height=650, scrollbars=yes, toolbar=no, status=yes';
var woMasterDetall99 = 'width=520, height=400, scrollbars=yes, toolbar=no, status=yes';
var woMasterDetall88 = 'width=740, height=750, scrollbars=yes, toolbar=no, status=yes';
var woLogin = 'width=300, height=200, scrollbars=no, 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_club (campRetorn, campMime, campSubMime, conf, codiClub) 
{
  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+ "&fitxerInfo.codi=" + codiClub;
    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;
}


function mostrar(divId)
{
  var dBody = document.getElementById(divId);
  dBody.style.display="block";
}

function ocultar(divId)
{
  var dBody = document.getElementById(divId);
  dBody.innerHTML="";
}

function ocultarTootip()
{
  var dBody = document.getElementById('tooltip');
  dBody.style.display='none';
}


function findPosition( oElement ) 
{
  if( typeof( oElement.offsetParent ) != 'undefined' ) 
  {
    for( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent ) 
    {
      posX += oElement.offsetLeft;
      posY += oElement.offsetTop;
    }
    return [ posX, posY ];
  } 
  else 
  {
    return [ oElement.x, oElement.y ];
  }
}

function refreshUpdateText(url, formName)
{
  ajax.makeRequestForm(url, formName, 'ajaxResultatForm(content)');
}