var context = '/fch';
// ------------------ 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=700, height=500, scrollbars=yes, 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 woMasterDetall23 = 'width=860, 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 woSendMail  = 'width=520, height=440, 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 woClau = 'width=430, height=280, scrollbars=yes, toolbar=no, status=yes';

var timeOutMN = 500;
var finestra  = null;

// ------------------- Funcions estandard i tipiques de JS --------------------
/*
 * implementacio de la funcio .trim en strings
 * exemple:
 * var a = "   aaaaa    aaaaa    aaaaa";
 * alert(a.trim());
 * 
 * valor de sortida: "aaaaa aaaaa aaaaa"
*/

String.prototype.trim = function () 
{
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

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 resetFK2(t, t2, h)
{
   var f = document.forms[0];
   f.elements[t].value = "";
   f.elements[t2].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 has d'eliminar el document 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;
}

/*************
 * 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 mostrar(divId)
{
  var dBody = document.getElementById(divId);
  dBody.style.display="block";
}

function ocultarDisplay(divId)
{
  var dBody = document.getElementById(divId);
  dBody.style.display="none";
}

function ocultar(divId)
{
  var dBody = document.getElementById(divId);
  dBody.innerHTML="";
}

function AssignarCampTipus1(campTipus)
{
  var f = document.forms[0];
  f.elements['pagina.whereCerca.camp'].value=campTipus.substring(0, campTipus.length-1);
  f.elements['pagina.whereCerca.tipus'].value=campTipus.substring(campTipus.length-1, campTipus.length);
}
function AssignarCampTipus2(campTipus)
{
  var f = document.forms[0];
  f.elements['pagina.whereCerca2.camp'].value=campTipus.substring(0, campTipus.length-1);
  f.elements['pagina.whereCerca3.tipus'].value=campTipus.substring(campTipus.length-1, campTipus.length);
}

function PassarPoblacioFKToPersonainPublic(codiPoblacio, poblacio, cp, provincia)
{
  f = document.forms[0];
  f.elements['persona.codiPoblacio'].value = codiPoblacio;
  f.elements['persona.adreca.paisCP.poblacio'].value = poblacio;
  f.elements['persona.adreca.paisCP.codiPostal'].value = cp;
  f.elements['persona.adreca.paisCP.provincia'].value = provincia;
  document.getElementById('divFK').style.display='none';
}

function PassarEntitatFKToPersonainPublic(codiEntitat, entitat)
{
  f = document.forms[0];
  f.elements['persona.codiEntitat'].value = codiEntitat;
  f.elements['persona.entitat.entitat'].value = entitat;
  document.getElementById('divFK').style.display='none';
}

function PassarCCCavallToPersonainPublic()
{
  var f = document.forms[0];
  f.elements['persona.compteCorrentc.titular'].value = f.elements['persona.compteCorrent.titular'].value;
  f.elements['persona.compteCorrentc.codiBanc'].value = f.elements['persona.compteCorrent.codiBanc'].value;
  f.elements['persona.compteCorrentc.oficinaBanc'].value = f.elements['persona.compteCorrent.oficinaBanc'].value;
  f.elements['persona.compteCorrentc.dcBanc'].value = f.elements['persona.compteCorrent.dcBanc'].value;
  f.elements['persona.compteCorrentc.ccBanc'].value = f.elements['persona.compteCorrent.ccBanc'].value;
}

function PassarCCGenetToPersonainPublic()
{
  var f = document.forms[0];
  f.elements['persona.compteCorrent.titular'].value = f.elements['persona.compteCorrentc.titular'].value;
  f.elements['persona.compteCorrent.codiBanc'].value = f.elements['persona.compteCorrentc.codiBanc'].value;
  f.elements['persona.compteCorrent.oficinaBanc'].value = f.elements['persona.compteCorrentc.oficinaBanc'].value;
  f.elements['persona.compteCorrent.dcBanc'].value = f.elements['persona.compteCorrentc.dcBanc'].value;
  f.elements['persona.compteCorrent.ccBanc'].value = f.elements['persona.compteCorrentc.ccBanc'].value;
}

function novaClau()
{
//  finestra = window.open(pUrl, pTarget, woSendMail);
  fOpenWindow ("/fch/nova-clau/get.do", "Clave", woClau)
}

function open_upload_privat (campRetorn, campMime, campSubMime, conf) 
{
  var camp = document.forms[0].elements[campRetorn];
  
  if (camp.value=='')
  {
    theURL = context+"/privat/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_delete_privat (campRetorn, servei) 
{
  var camp = document.forms[0].elements[campRetorn];
  camp.value = ""; //******************************
  if (camp.value!='')
  {
    theURL = context+"/privat/upload/deleteFile.do?deleteFile.campRetorn="+campRetorn+"&deleteFile.nomFitxer="+camp.value+"&deleteFile.servei="+servei;
    winName = "deletewindow";
    window.open(theURL, winName, uploadFeatures);
  }
}

/* No acaba de funcionar porque al recargar la pagina si tenias seleccionado que si te guarda la opcion pero
   la caja de texto se queda deshabilitada
function CanviDisabled(genetCavall)
{
  f = document.forms[0];
  
  if(genetCavall == "persona")
  {
    textbox1="persona.compteCorrent.titular";
    textbox2="persona.compteCorrent.codiBanc";
    textbox3="persona.compteCorrent.oficinaBanc";
    textbox4="persona.compteCorrent.dcBanc";
    textbox5="persona.compteCorrent.ccBanc";
  }
  else if(genetCavall == "cavall")
  {
    textbox1="persona.compteCorrentc.titular";
    textbox2="persona.compteCorrentc.codiBanc";
    textbox3="persona.compteCorrentc.oficinaBanc";
    textbox4="persona.compteCorrentc.dcBanc";
    textbox5="persona.compteCorrentc.ccBanc";
  }
  
  f.elements[textbox1].disabled=!f.elements[textbox1].disabled;
  f.elements[textbox2].disabled=!f.elements[textbox2].disabled;
  f.elements[textbox3].disabled=!f.elements[textbox3].disabled;
  f.elements[textbox4].disabled=!f.elements[textbox4].disabled;
  f.elements[textbox5].disabled=!f.elements[textbox5].disabled;
}

function enableDisable()
{
  f = document.forms[0];
  
  textbox1="persona.compteCorrent.titular";
  textbox2="persona.compteCorrent.codiBanc";
  textbox3="persona.compteCorrent.oficinaBanc";
  textbox4="persona.compteCorrent.dcBanc";
  textbox5="persona.compteCorrent.ccBanc";
  
  if(f.elements["persona.domiciliacio"].value == "S")
  {
    f.elements[textbox1].disabled=false;
    f.elements[textbox2].disabled=false;
    f.elements[textbox3].disabled=false;
    f.elements[textbox4].disabled=false;
    f.elements[textbox5].disabled=false;
  }
  else
  {
    f.elements[textbox1].disabled=true;
    f.elements[textbox2].disabled=true;
    f.elements[textbox3].disabled=true;
    f.elements[textbox4].disabled=true;
    f.elements[textbox5].disabled=true;
  }
  
  textbox1="persona.compteCorrentc.titular";
  textbox2="persona.compteCorrentc.codiBanc";
  textbox3="persona.compteCorrentc.oficinaBanc";
  textbox4="persona.compteCorrentc.dcBanc";
  textbox5="persona.compteCorrentc.ccBanc";
  
  if(f.elements["persona.domiciliacioc"].value == "S")
  {
    f.elements[textbox1].disabled=false;
    f.elements[textbox2].disabled=false;
    f.elements[textbox3].disabled=false;
    f.elements[textbox4].disabled=false;
    f.elements[textbox5].disabled=false;
  }
  else
  {
    f.elements[textbox1].disabled=true;
    f.elements[textbox2].disabled=true;
    f.elements[textbox3].disabled=true;
    f.elements[textbox4].disabled=true;
    f.elements[textbox5].disabled=true;
  }
  
}*/

function amagarMostrarDiv(nomDiv)
{
	var div = document.getElementById(nomDiv);
	if(div.style.display=="block")
		amagarDiv(nomDiv);
	else
		mostrarDiv(nomDiv);
}

function mostrarDiv(nomDiv)
{
	var div = document.getElementById(nomDiv);
	div.style.display="block";
	div.style.visibility="visible";
}

function amagarDiv(nomDiv)
{
	var div = document.getElementById(nomDiv);
	div.style.display="none";
	div.style.visibility="hidden;";
}

function llistatConAny(url, nomCamp)
{
  var camp = document.forms[0].elements[nomCamp].value;
  url = url+"&calExp.any="+camp;
  winName = "llistatConAny";
  window.open(url, winName, uploadFeatures);
}
