/////////////////////////////////////////////////////////
// ACCENT-WHADS S.L. 2001
// www.whads.com

function txt(esp,por) {
	if (ct_idi!=0) return(por); else return(esp);
}


function primerObj(obj)
{
	var i
	for (i in obj) {
		if (i!='_nom') return i
	}
}

function getHTMLcap() {
    var strHTML
    var strNiv
    var strObj
    var esObjecte = true
    var nomNiv
    var i
    
    strObj = 'niv'
    strNiv = ''
    strHTML = ''
    for(i=0; i!=dictio.Count-2; i++) 
    {
        strObj = strObj + '.' + dictio.Item(i)
        strNiv = strNiv + dictio.Item(i) + '_' 
        nomNiv = 'No definido'
        if (esObjecte)
        {
            if (eval(strObj)==null) 
            {
                logWrite(strObj + ' no esta definido')
                esObjecte = false;
            }
            else
            {
                nomNiv = eval(strObj + '.nom_sec')
            }
        }
        strHTML += '<A HREF="' + strNiv + 'pre_cont.asp">' 
		strHTML +=  nomNiv 
		strHTML += '</A> '
    }    
    return strHTML;   
}    

function getHTMLSec() {
    var strHTML
    var strNiv
    var strObj
    var esObjecte = true
    var nomNiv
    var i
    
    strObj = 'niv'
    strNiv = ''
    strHTML = ''
    for(i=0; i!=dictio.Count-1; i++) 
    {
        strObj = strObj + '.' + dictio.Item(i)
        strNiv = strNiv + dictio.Item(i) + '_' 
        nomNiv = 'No definido'
        if (esObjecte)
        {
            if (eval(strObj)==null) 
            {
                logWrite(strObj + ' no esta definido')
                esObjecte = false;
            }
            else
            {
                nomNiv = eval(strObj + '.nom_sec')
            }
        }
		strHTML =  nomNiv 
    }    
    return strHTML;   
}    

function nomfitxer(objtxt) {
	var i;
	var tr = '';
	var st = '';
	
	for (i=3;i<objtxt.length;i++)	{
		tr=objtxt.substring(i,i+1);
		if (tr == '.') tr = '_'
		st += tr
	}
	st += '.asp'
	return st
}


function estructura(obj,estilo)
{
	var st=''
	var i
	for(i in eval(obj))
	{
		if (i=='_nom')
		{
			st +='<tr><td valign="middle" class="'+estilo+'" nowrap><a href="' + nomfitxer(obj) + '" class="a12li">&nbsp;&nbsp;' + eval(obj + '._nom') + '</a><td></tr>'
			if (estilo=='menuOn') st+='<tr><td width="1%" bgcolor="#263D83"><img src="images/cp.gif" width="157" height="1" border="0"></td></tr>';
		}
		else 
		{
			st += estructura(obj + '.' + i,"menu2");
		}
	}
	
	return st;
}


function getLabel(lobj,eti) {
	var i;
	var obj = eval(lobj);
	var st = 'Pedidos'
	for (i in obj) {
		if (i==eti) {
			st = eval(lobj + '.' + i + '._nom')
			break;
		}
	}
	return st;
}

function nivells(){
	var i;
	var st=''
	var lobj = 'ps'
	var lurl = ''
	var eti = ''
	
	for (i=0;i<nOps;i++) {
		if (blocs[i]=='') break;
		if (eti!='no definit') eti = getLabel(lobj,blocs[i]);
		lobj += '.' + blocs[i];
		if (lurl!='') lurl += '_'
		lurl += blocs[i]
		/*if (blocs[i]==blocs[1])*/ st += '<a href="' + lurl + '.asp" class="a13az">' + eti + '</a><font class="a13az"> &gt; </font>'
		//else st += '<font class="a12li">' + eti + ' &gt; </font"> '
	}
	st = st.substring(0,st.length-14);
	return st;
}

function nom_nivell(){
	var i;
	var st=''
	var lobj = 'ps'
	var lurl = ''
	var eti = ''
	
	for (i=0;i<4;i++) {
		if (blocs[i]=='') break;
		if (eti!='no definit' && i!=0) eti = getLabel(lobj,blocs[i]);
		lobj += '.' + blocs[i];
		if (lurl!='') lurl += '_'
		lurl += blocs[i]
		st = eti
	}
	if (st=="no definit") st=nom_predefinit;
	return st;
}

function menuNivell() {
	var i;
	var st=''
	var lobj = 'ps'
	var lurl = ''
	var eti = ''
	
	for (i=0;i<maxArray;i++) {
		if (blocs[i]=='') break;
		if (eti!='no definit') eti = getLabel(lobj,blocs[i]);
		lobj += '.' + blocs[i];
		if (lurl!='') lurl += '_'
		lurl += blocs[i]
	}
	if (eti!='no definit') {
		for (i in eval(lobj)) {
			if (i!='_nom') st += eval(lobj + '.' + i + '._nom') + '<br>' 
		}
	}
	return st;
}

function nivellCab(){
	var st='';
	var i=0;
	st += '<table border="0" cellspacing="0" cellpadding="0" width="601" bgcolor="#f5f5f5">';
	st += '<tr>';
	st += '<td bgcolor="#666666" width="1"><img src="img/cp.gif" width="1" height="1"></td>';
	st += '<td bgcolor="#666666" width="593" colspan="4"><img src="img/cp.gif" width="1" height="1"></td>';
	st += '<td bgcolor="#666666" width="1"><img src="img/cp.gif" width="1" height="1"></td>';
	st += '</tr>';
	st += '<tr>';
	st += '<td bgcolor="#666666"><img src="img/cp.gif" width="1" height="1"></td>';
	st += '<td colspan="4" background="img/cab_'+blocs[0]+'.gif">';
	st += '<table border="0" cellspacing="0" cellpadding="2">';
	st += '<tr>';
	st += '<td width="5">&nbsp;</td>';
	st += '<td nowrap class="v14az">';
	st += '<b>'+nivells()+'</b>';
	st += '</td>';
	st += '</tr>';
	st += '</table>';
	st += '<td bgcolor="#666666"><img src="img/cp.gif" width="1" height="1"></td>';
	st += '</td>';
	st += '</tr>';
	st += '<tr>';
	st += '<td bgcolor="#666666" width="1"><img src="img/cp.gif" width="1" height="1"></td>';
	st += '<td bgcolor="#666666" width="593" colspan="4"><img src="img/cp.gif" width="1" height="1"></td>';
	st += '<td bgcolor="#666666" width="1"><img src="img/cp.gif" width="1" height="1"></td>';
	st += '</tr>';
	st += '</table>';
	return st;
}

function nivell1(){
	var st='&nbsp;';
	if (blocs[0]!='') st = eval('ps.' + blocs[0] + '._nom');
	return st;
}

function nivell2() {
	var st='';
	st += '<font class="a14az"><b>';
	if (blocs[1]!='') st += eval('ps.' + blocs[0] + '.' + blocs[1] + '._nom');
	else st += eval('ps.' + blocs[0] + '._nom');
	st += '</b></font>';
	return st;
}

function nivell3_pre(){
	var st='';
	var lobj='';
	var i;
	if (blocs[1]!='') {
		lobj='ps.' + blocs[0] + '.' + blocs[1]
		var obj = eval(lobj);
		for (i in obj) {
			if (i!='_nom') {
				if (typeof(id)!="undefined") st += '<img src="img/img_punto_02.gif" width="5" height="10">&nbsp;<a href="' + blocs[0] + '_' + blocs[1] + '_' + i +'.asp?id='+id+'" class="a12az2">' + obj[i]._nom + '</a><br>';
				else st += '<img src="img/img_punto_02.gif" width="5" height="10">&nbsp;<a href="' + blocs[0] + '_' + blocs[1] + '_' + i +'.asp" class="a12az2">' + obj[i]._nom + '</a><br>';
			}
		}
		st = st.substring(0,st.length-4); //Canviat de length-6 a length-4 per a no eliminar el tag </a>
	}
	return st;
}

function nivell3(){
	var st='';
	var lobj='';
	var i;
	if (blocs[2]!='') {
		lobj='ps.' + blocs[0] + '.' + blocs[1]
		var obj = eval(lobj);
		for (i in obj) {
			if (blocs[2]==i) {
				st += '<font class="a10ne">' + obj[i]._nom + '&nbsp;&nbsp;|&nbsp;&nbsp;</font>'; //eval('ps.' + blocs[0] + '.' + blocs[1] + '.' + blocs[2] + '._nom');
			}else{
				if (i!='_nom') {
					var suf='.asp';
					if (i=='datos') suf='.asp';
					if (typeof(id)!="undefined") st += '<a href="' + blocs[0] + '_' + blocs[1] + '_' + i + suf + '?id='+id+'" class="a10az2">' + obj[i]._nom + '</a><font class="a10az2">&nbsp;&nbsp;|&nbsp;&nbsp;</font>';

					else st += '<a href="' + blocs[0] + '_' + blocs[1] + '_' + i + suf + '" class="a10az2">' + obj[i]._nom + '</a><font class="a10az2">&nbsp;&nbsp;|&nbsp;&nbsp;</font>';
				}
			}
		}
		st = st.substring(0,st.length-20);
	}
	return st;
}

function menuBase() {
	var st='';
	var i,j;
	var stil = '';
	var cont=0;
	st += '<table border="0" cellspacing="2" cellpadding="2" width="135">';
	for (i in ps) {
		cont=0;
		if (i!='_nom' && i!='bibl') {
			st += '<tr><td>';
			if (i==blocs[0]) st += '<a href="' + i + '.asp" target="_top"><img name="' + i + '" border="0" src="img/menok_' + i + '_on.gif" width="135" height="22"></a>';
			else st += '<a href="' + i + '.asp" target="_top" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'' + i + '\',\'\',\'img/menok_'+i+'_on.gif\',1)"><img name="'+i+'" border="0" src="img/menok_'+i+'_off.gif" width="135" height="22"></a>';
			if (i==blocs[0]){
					var obj = ps[i]
					var aux='ps.'+blocs[0];
					var auxobj=eval(aux);
					for (a in auxobj){
						if(a!="_nom"){	
							cont++;
						}
					}
				if(cont!=0){
					st += '<table width="133" border="0" cellspacing="0" cellpadding="0">';
					st += '<tr>';
					st += '<td bgcolor="#666699"><img src="img/cp.gif" width="1" height="1"></td>';
					st += '<td bgcolor="#FFFFFF">';
					st += '<table width="133" cellpadding="2" cellspacing="2" border="0">';
					if (j!='_nom') {
						lobj = 'ps.' + blocs[0]
						var obj = eval(lobj);
						for (i in obj) {
							if (i!='_nom') {
								st += '<tr><td class="a12li">';
							 // ************** jordi 31/01/05
								if (i=="pedido") { theUrl = "https://www.leti.com/flomy/cas/"	}
								else { theUrl = ""	}
								if (typeof(id)!="undefined"){
									st += '<a href="'+theUrl+ blocs[0] + '_' + blocs[1] + '_' + i +'.asp?id='+id+'" class="a12li">' + obj[i]._nom + '</a>';
								}else{
									if (blocs[1]==i) {
										st += '<b>';
										st += '<a href="' +theUrl+ blocs[0] + '_' + i +'.asp" class="a12li" target="_top">' + obj[i]._nom + '</a>'; //eval('ps.' + blocs[0] + '.' + blocs[1] + '._nom');
										st += '</b>';
									}else{
										st += '<a href="' +theUrl+ blocs[0] + '_' + i +'.asp" class="a12li" target="_top">' + obj[i]._nom + '</a>';
									}
								}
								
							 // ************** jordi 31/01/05
							}

							st += '</td></tr>';
						}					
					}
					st += '</table>';
					st += '</td>';
					st += '<td bgcolor="#666699"><img src="img/cp.gif" width="1" height="1"></td>';
					st += '</tr>';
					st += '<tr>';
					st += '<td bgcolor="#666699"><img src="img/cp.gif" width="1" height="1"></td>';
					st += '<td bgcolor="#666699"><img src="img/cp.gif" width="1" height="1"></td>';
					st += '<td bgcolor="#666699"><img src="img/cp.gif" width="1" height="1"></td>';
					st += '</tr>';
					st += '</table>';
				}
			}	
		}
	}
	st += '</table>';
	return(st);
}


function menuHome(){
	var st=''
	var i;
	st += '<table border="0" cellspacing="0" cellpadding="0" width="50">'
	st += '<tr><td width="1%"><img src="img/cp.gif" width="25" height="10" border="0"></td><td><img src="img/cp.gif" width="1" height="1" border="0"></td></tr>'
	for (i in ps) {
		if (i!='_nom') {
			st += '<tr>'
			st += '<td align="right" valign="bottom">'
			st += '<img src="img/trigris.gif" width="10" height="10" border="0">';
			st += '<img src="img/cp.gif" width="4" height="15" border="0"></td>'
			st += '<td class="a12li" nowrap valign="bottom">'
			st += '<a href="html/' + i + '.asp" class="a12li">'
			if (i==blocs[0]) st += '<font color="#CC3333">' + ps[i]._nom + '</font>';
			else st += ps[i]._nom;
			st += '</a></td></tr>'
		}
	}
	st += '<tr><td width="1%"><img src="img/cp.gif" width="25" height="10" border="0"></td><td><img src="img/cp.gif" width="1" height="1" border="0"></td></tr>'	
	st += '</table>'
	return(st);
}


function menu() {
	return(menuBase());
}

var blocs = new Array()
var maxArray = 8
var nOps = 0;
var nom_indefinit='';

function getBlocs(url,blocsArray,pillaUltim) {
	var i,j;
	var doc='';
	var pu=0,su=0;

	doc = url + '';
	if (doc.indexOf('?')!=-1) doc = doc.substring(0,doc.indexOf('?'));
	for(i=0;i<maxArray;i++) blocsArray[i]='';
	pu=doc.lastIndexOf('/');
	if (pu<0) pu=doc.lastIndexOf('\\');
	nOps=0;
	su=doc.indexOf("_",pu+1);
	while (su>=0) {
		blocsArray[nOps]=doc.substring(pu+1,su);
		pu=su;
		nOps++;
		su=doc.indexOf("_",pu+1);
	}
	if (pillaUltim)	{
		su=doc.indexOf(".",pu+1)
		blocsArray[nOps++]=doc.substring(pu+1,su);
	}
	for (j=nOps;j<maxArray;j++) blocsArray[j]='';
}

getBlocs(document.location.href,blocs,true);


// De números

function formatnumber(n,d) {
  n = n - 0;
  d = d || 2;
  var f = Math.pow(10, d);
  n = Math.round(n * f) / f;
  n += Math.pow(10, - (d + 1));
  n += '';
  return d == 0 ? eval(n.substring(0, n.indexOf('.'))) : eval(n.substring(0, n.indexOf('.') + d + 1));
}



function a_miles(n,d){
 	n = n - 0;
  	var f = Math.pow(10, d);
  	n = Math.round(n * f) / f;

	n = '' + n;
	var st2 = '';
	var compt = 0;
	
	// busco el punt o el final
	var pi = n.lastIndexOf('.');
	var decs = '';
	if (d!=0) {
		decs += ','
		if (pi>0) decs += n.substring(pi+1,n.length);  
		for (var i=decs.length;i<d+1;i++) decs += '0';
	}
	if (pi==-1) pi = n.length;
	pi--;
	while (pi>=0) {
		st2 = n.substring(pi,pi+1) + st2;
		compt++;
		if (compt==3 && pi!=0) { st2 = '.' + st2; compt=0; }
		pi--;
	}
	return (st2+decs);
}			

function a_euros(n) {
	return Math.round((n/ct_moneda)*100)/100
}

function a_moneda(n) {
	return Math.round(n*ct_moneda)
}

function a_a(n) {
	return Math.round(n*100)/100
}

function taula_familia(familia) {
	var i,j;
	var st='';
	st += '<table width="100%" border="0" cellspacing="2" cellpadding="2" bgcolor="#FFFFFF">\n';
	for (var i in ti) {
		if (ti[i].familia == familia ) {
			st += '<tr><td colspan="3" class="a12ne" bgcolor="#DBC8DB"><b>' + ti[i].nom + '</B></td></tr>\n';
			st += '<tr><td bgcolor="#CCCCCC" class="a12ne">'+txt('Medidas','Medidas')+'</td>';
			st += '<td bgcolor="#CCCCCC" class="a12ne" align="right">Euros</td>';
			st += '<td bgcolor="#CCCCCC" class="a12ne" align="right">'+txt('Euros + IVA','Euros + IVA')+'</td></tr>\n';
			for (var j in pr) {
				if (pr[j].tipus == ti[i].id) {
					st += '<tr><td bgcolor="#EEEEEE" class="a12ne"> ';
					st += pr[j].mides;
					//st += ' -> ' + pr[j].preu;
					st += '</td><td bgcolor="#EEEEEE" align="right" class="a12ne">';
					st += a_miles(pr[j].preu,2); //a_a
					st += '</td><td bgcolor="#EEEEEE" align="right" class="a12ne">';
					st += a_miles(pr[j].preu*ct_iva,2); //a_a
					st += '</td></tr>\n';
				}
			}
			st += '<tr><td colspan="3" class="a12ne">&nbsp;</td></tr>\n';
		}	
	}
	st +='</table>\n';
	return st;		
}
