function centrar_finestra(nHeight, nWidth) {
window.moveTo((screen.availWidth - nWidth)/2, (screen.availHeight - nHeight)/2);
}

function obre_finestra(sUrl,sParams) {
if (sParams == '') {sParams = sParams + 'status=no';} else {sParams = sParams + ', status=no';}
window.open(sUrl,'',sParams);
}

function nova_trobada() {
obre_finestra('nova_trobada.asp','height=500, width=450');
}

function nou_anunci() {
obre_finestra('nou_anunci.asp','height=400, width=450');
}

function mostrar_producte(producte) {
top.location.href = 'productes.asp?search=' + producte;
}
	
function expand_foto(sFile) {
foto = window.open('../imagen/productes/' + sFile,'','height=325, width=325');
foto.moveTo((screen.availWidth - 325)/2, (screen.availHeight - 325)/2);
}

function error(nErr) {
obre_finestra('error.asp?err=' + nErr,'height=150, width=300');
}

function msg(nMsg) {
obre_finestra('msg.asp?msg=' + nMsg,'height=150, width=300');
}

function idioma(sLang, sRemitent) {
top.location.href = sRemitent + '?idioma=' + sLang;
}

function tramitar_comanda(sQuery) {
top.location.href = 'confirmacio_comanda_bin.asp?' + sQuery;
}

function verificar_form_envio() {
var ok = true;
if (document.getElementById('user1').value == "") {ok = false;}
if (document.getElementById('user2').value == "") {ok = false;}
if (document.getElementById('user3').value == "") {ok = false;}
if (document.getElementById('user4').value == "") {ok = false;}
if (document.getElementById('user5').value == 0) {ok = false;}
if (document.getElementById('user6').value == "") {ok = false;}
if (document.getElementById('user7').value == "") {ok = false;}
if (document.getElementById('user8').value == "") {ok = false;}
//if (document.getElementById('carret').value == 0) {ok = false;}
//if (document.getElementById('gastos').value == 0) {ok = false;}

//alert(ok);

if (ok == true) {
	//generar_arrays();
	location.href='forma_pagament_frameset.asp?user1=' + document.getElementById('user1').value + '&user2=' + document.getElementById('user2').value + '&user3=' + document.getElementById('user3').value + '&user4=' + document.getElementById('user4').value + '&user5=' + document.getElementById('user5').value + '&user6=' + document.getElementById('user6').value + '&user7=' + document.getElementById('user7').value + '&user8=' + document.getElementById('user8').value;
} else {
	error(23);
	}
}

function confirmar_pedido() {
var ok = true;

if (document.getElementById('carret').value == 0) {ok = false;}
if (document.getElementById('gastos').value == 0) {ok = false;}

//alert(ok);

if (ok == true) {
	generar_arrays();
	top.location.href='confirmacio_comanda.asp?' + dades_user + '&id_gastos_envio=' + id_gastosenvio; // + '&gastos_envio=' + gastosenvio + '&total_comanda=' + document.getElementById('carret').value;
} else {
	error(23);
	}
}


function calcular_total_comanda(nGastosEnvio, nPais) {
top.verificar.location.href='forma_pagament_bin.asp?gastosenvio=' + nGastosEnvio + '&pais=' + nPais;		
}


function canvi_pais(nPais) {
location.href='dades_enviament.asp?id_pais=' + nPais;
}

function validar_form_usuari() {
var err = 0;

if (document.getElementById('user1').value == "" || checkForCharacters(document.getElementById('user1').value, '@') == -1 || checkForCharacters(document.getElementById('user1').value, '.') == -1) {err = 17;}
if (document.getElementById('user2').value == "") {err = 19;}
if (document.getElementById('user3').value == "" || document.getElementById('user3').value != document.getElementById('user2').value) {err = 18;}
if (document.getElementById('user4').value == "") {err = 19;}
if (document.getElementById('user5').value == "") {err = 19;}
if (document.getElementById('user6').value == "") {err = 19;}
if (document.getElementById('user7').value == 0) {err = 19;}
if (document.getElementById('user9').value == 0) {err = 19;}
if (document.getElementById('user10').value == 0) {err = 19;}

//alert(ok);

if (err == 0) {
	document.forms['alta'].submit();
} else {
	error(err);
	}
}

function validar_form_contacta() {
var err = 0;
var arr = document.getElementsByName('tipos');
var tipo_consulta = -1;

if (document.getElementById('user1').value == "") {err = 19;}
if (document.getElementById('user2').value == "") {err = 19;}
if (document.getElementById('user4').value == "") {err = 19;}
if (document.getElementById('user3').value == "" || checkForCharacters(document.getElementById('user3').value, '@') == -1 || checkForCharacters(document.getElementById('user3').value, '.') == -1) {err = 17;}
if (document.getElementById('user5').value == "") {err = 19;}
if (document.getElementById('user6').value == 0) {err = 19;}
if (document.getElementById('user8').value == "") {err = 19;}

for (n=0;n<arr.length;n++){
if (arr[n].checked == true) {tipo_consulta = n};
}

if (tipo_consulta == -1)  {err = 19};

if (err == 0 && tipo_consulta >= 0) {
	document.getElementById('user7').value = arr[tipo_consulta].value; 
	document.forms[1].submit();	} 
	else {
	error(err);
	}
	
}

function validar_form_trobades() {
var err = 0;

if (document.getElementById('user1').value == "") {err = 19;}
if (document.getElementById('user2').value == "" || checkForCharacters(document.getElementById('user2').value, '/') == -1) {err = 13;}
if (document.getElementById('user3').value == "") {err = 19;}
if (document.getElementById('user4').value == "") {err = 19;}
if (document.getElementById('user5').value == 0) {err = 19;}
if (document.getElementById('user6').value == "" || checkForCharacters(document.getElementById('user6').value, '@') == -1 || checkForCharacters(document.getElementById('user6').value, '.') == -1) {err = 17;}
if (document.getElementById('user7').value == "") {err = 19;}
if (document.getElementById('user8').value == "") {err = 19;}


//alert(ok);

if (err == 0) {
	document.forms[0].submit();
} else {
	error(err);
	}
}

function validar_form_anuncis() {
var err = 0;

if (document.getElementById('user1').value == "") {err = 19;}
if (document.getElementById('user2').value == "") {err = 19;}
if (document.getElementById('user3').value == "") {err = 19;}
if (document.getElementById('user4').value == "") {err = 19;}

if (err == 0) {
	document.forms[0].submit();
} else {
	error(err);
	}
}

function recordar_password(sEmail) {
if (sEmail == "")  {
error(21); 
} else {
top.verificar.location.href='verificar_usuari_bin.asp?email=' + sEmail + '&recordar=1';}
}


function alta_usuari(sRemitent) {
top.location.href='alta_usuaris.asp?remitent=' + sRemitent;
}

function buscar_productes(sText) {
location.href='productes.asp?idsubfamilia=0&search=' + sText;
}

function verificar_usuari(sEmail, sPassword) {
top.verificar.location.href='verificar_usuari_bin.asp?email=' + sEmail + '&password=' + sPassword;
}

function obrir_carret() {
location.href='carret.asp';
//oCarret = window.open('carret.asp','','width=620, height=400, scrollbars=yes');
//obre_finestra('carret.asp','width=620, height=400, scrollbars=yes');
}

function al_carret(cant, producte, preu, session) {
location.href='carret.asp?cantitat=' + cant + '&producte=' + producte + '&preu=' + preu + '&session='+ session + '&Accio=0';
//oCarret = window.open('carret.asp?cantitat=' + cant + '&producte=' + producte + '&preu=' + preu + '&session='+ session + '&Accio=0' ,'', 'width=620, height=400, scrollbars=yes');
//obre_finestra('carret.asp?cantitat=' + cant + '&producte=' + producte + '&preu=' + preu + '&session='+ session + '&Accio=0' ,'width=620, height=400, scrollbars=yes');
}

function treure_producte(producte, session) {
location.href='carret.asp?producte=' + producte + '&session='+ session + '&Accio=2';
}

function modificar_producte(producte, cant) {
location.href='carret.asp?cantitat=' + cant + '&producte=' + producte + '&Accio=1';
}

function mes(cant, element) {
document.getElementById(element).value = Number(document.getElementById(element).value) + Number(cant);
}

function menys(cant, element) {
	if(document.getElementById(element).value > 1) {
	document.getElementById(element).value = Number(document.getElementById(element).value) - Number(cant);
	}
}

function goto (subfamilia, flag) {
location.href = "productes.asp?idsubfamilia=" + subfamilia + "&see=" + flag;
}


function mostrar_comentaris(sComentari) {
ns = (document.layers)? true : false;
ie = (document.all)? true: false;	

if (ns) comenta = document.comentaris;
if (ie) comenta = comentaris.style;

if (ie) {
comenta.left = window.event.clientX - 270;
comenta.top = window.event.clientY;}

if (ns) {
comenta.left = event.pageX - 270;
comenta.top = event.pageY;}

MM_showHideLayers('comentaris','','show');
document.getElementById('coment').value = sComentari;
}

function ver(headx){
var ObjMenu=document.all[headx]
var StyMenu=ObjMenu.style
if (catflag.value!="")
	{
	var indAnt=catflag.value
	}
	
if (StyMenu.display=="none")
	{
	if (indAnt) document.all[indAnt].style.display="none";
	StyMenu.display="block"
	catflag.value=headx
	} 
	else {
	StyMenu.display="none"
	}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function checkForCharacters(inputString, checkString, startingIndex) {
  if (!startingIndex) startingIndex = 0;
	//alert(inputString.indexOf(checkString));
  return inputString.indexOf(checkString);
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}