var xmlHttp; 
var xmlHttp2; 

var DivAjax ; 
var DivAjax2 ; 
	var agt = navigator.userAgent.toLowerCase();
	var is_major = parseInt(navigator.appVersion);
	var is_nav = ((agt.indexOf('mozilla') != -1) && (agt.indexOf('spoofer') == -1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera') == -1) && (agt.indexOf('webtv') == -1));
	var is_nav4up = (is_nav && (is_major >= 4));
	var is_ie = (agt.indexOf("msie") != -1);
	var is_ie3  = (is_ie && (is_major < 4));
	var is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5") == -1) && (agt.indexOf("msie 6") == -1));
	var is_ie4up = (is_ie && (is_major >= 4));
	var is_ie5up  = (is_ie  && !is_ie3 && !is_ie4);
	var is_mac = (agt.indexOf("mac") != -1);
	var is_gecko = (agt.indexOf("gecko") != -1);
var g_calendarObject; 
var submenutimer = 0; 
var submenuitem = 0; 
var vsubmenuClose = ""; 

//imatges 
Rollimage = new Array()
//Rollimage[0]= new Image(30,31)
//Rollimage[0]= new Image(10,10)
//Rollimage[0].src = "fesfotos/estrellano2.jpg"
//Rollimage[1] = new Image(30,31)
//Rollimage[1] = new Image(10,10)
//Rollimage[1].src = "fesfotos/estrellasi2.jpg"



function changeclass(row,vClass){
	if (row.className) row.className = vClass;
}
function activateRow(row){
	if (row.className) row.className = "selectrowactive";
}
function deactivateRow(row){
	if (row.className) row.className = "selectrow";
}

var newwindow;
function popbox(url,name){
	newwindow=window.open(url,'name','scrollbars=yes,resizable=yes,width=620,height=440,location=no');
	if (window.focus) {newwindow.focus()}
}
function popnormal(url,name){
	newwindow=window.open(url,name,'scrollbars=yes,resizable=yes,width=620,height=440,location=no');
	if (window.focus) {newwindow.focus()}
}
function popmini(url,name){
	newwindow=window.open(url,name,'scrollbars=no,resizable=no,width=320,height=240,location=no');
	if (window.focus && newwindow) {newwindow.focus()}
}
function textlenght(pfield, plenght){
  // textarea:onblur
	if (pfield.value.length > plenght){
		alert('El máximo de carácteres admitido és '+plenght);
		pfield.value = pfield.value.substr(0,plenght)
	}
}
function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } 
}
function imposemaxlength(pfield, plenght) {
  // textarea:onkeypress
  return (pfield.value.length <= plenght);
}
function vv_validateForm() { //v4.0
	// form:onsubmit
	var i,p,q,nm,test,num,min,max,errors='',args=vv_validateForm.arguments;
	for (i=1; i<(args.length-2); i+=3) {
		test=args[i+2];
		val=eval('document.forms.'+args[0].name+'.'+args[i])
		nm=args[i+1];
		if(test.charAt(0) == 'R' && val.value == ''){
			errors += '- '+nm+' és requerido.\n';
		}
		if (test.indexOf('isEmail')!=-1) {
			p=val.value.indexOf('@');
			if (p<1 || p==(val.value.length-1)) {
				errors+='- '+nm+' débe conener una dirección de correo electrónico.\n';
			}
		}
		if (test.indexOf('isInt')!=-1) {
			p=parseInt(val.value);
			if (isNaN(p)){
				errors+='- '+nm+' débe conener valor numérico.\n';
			}
		}

		if (test.indexOf('eqPwd')!=-1) {
			val2=eval('document.forms.'+args[0].name+'.'+args[i]+'_');
			if (val.value != val2.value) errors+='- '+nm+' no coinciden los valores entrados.\n';
		}
	}
	if (errors!=''){
		alert('No se puede procesar la petición, revise los siguientes errores:\n'+errors);
		return false;
	} else {
		val=eval('document.forms.'+args[0].name+'.submitform');
		//val.disabled='true';
		return true;
	}
}

function app_elmntMouseUp(elmnt)
{
elmnt.style.border="solid black 1px"
elmnt.style.background="#FFEEC9"
}

function app_elmntMouseOver(elmnt)
{
elmnt.style.border="solid black 1px"
elmnt.style.background="#FFEEC9"
}

function app_elmntMouseOut(elmnt)
{
elmnt.style.border="solid #FFFFFF 1px"
elmnt.style.background=""
}

function app_elmntMouseDown(elmnt)
{
elmnt.style.background="#FFC828"
}

function replaceimg(elmnt,item)
{
elmnt.src=item
}

  function SwapOut(elmnt,punts){
	var i ; 
	
	for ( i=1; i<11; i++){  
	if (punts>i-1){
	document.getElementById("ImgVote"+i).src="fesfotos/estrellasi2.jpg"  //Rollimage[1].src;
	}else{
	document.getElementById("ImgVote"+i).src="fesfotos/estrellano2.jpg" //Rollimage[0].src;
	}
	}
	//elmnt.src = Rollimage[1].src;
    return true;
  }

  function SwapBack(elmnt,punts){
     
	for ( i=punts; i>0; i--){     
	document.getElementById("ImgVote"+i).src=Rollimage[0].src;
	}
	elmnt.src = Rollimage[0].src;

    return true;
  }

// ********************************************************************************
// AJAX FUNCTIONS 
// ********************************************************************************

// Show record 
function showRecord(posajax,vweb,vsql,vvalor1,vvalor2,vvalor3,vvalor4)
{
//alert (posajax );
DivAjax= posajax; 
if (posajax.length==0)
  { 
  document.getElementById("txtajax").innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  
var url="ajax.asp";
url=url+"?fn=showrecord";
url=url+"&idweb="+vweb;
url=url+"&sql="+vsql;
url=url+"&valor1="+vvalor1;
url=url+"&valor2="+vvalor2;
url=url+"&valor3="+vvalor3;
url=url+"&valor4="+vvalor4;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 


// update record 
function updaterecord(idweb,str,valor1,valor2,valor3)
{
//alert ("babaX!");
DivAjax= "ContingutAjax";
if (str.length==0)
  { 
  document.getElementById("txtajax").innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 

var url="ajax.asp";
url=url+"?fn=updaterecord";
url=url+"&sql="+str;
url=url+"&valor1="+valor1;
url=url+"&valor2="+valor2;
url=url+"&valor3="+valor3;
url=url+"&idweb="+idweb;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 

function updatetable(idweb,numsql,valor1,valor2,valor3)
{
//alert ("babaX!");
DivAjax= "ContingutAjax";

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
// preparar dades 
x=document.getElementById("formDatos")
// MONTAR XML AMB ELS CAMPS INPUT 
y=x.getElementsByTagName("input")
//var datos = "&ltdatos&gt"; 
var datos = "<datos>"; 
for (i=0;i<y.length;i++)
	{
	//datos=datos+"&ltvalor name='"+y[i].name+"' value='"+y[i].value+"'&#47&gt";
	if (y[i].type=="checkbox") {
		//alert (y[i].checked); 
		if (y[i].checked) {
		datos=datos+"<valor name='"+y[i].name+"' value='1'>1</valor>";
		}else{
		datos=datos+"<valor name='"+y[i].name+"' value='0'>0</valor>";
		}
	}else {
	datos=datos+"<valor name='"+y[i].name+"'>"+make_xml(y[i].value)+"</valor>";
	}
	}
//datos=datos+"&lt&#47datos&gt";

// MONTAR XML AMB ELS CAMPS TEXTAREA
yy=x.getElementsByTagName("textarea")
for (ii=0;ii<yy.length;ii++){
	//alert (yy[ii].value);
	datos=datos+"<valor name='"+yy[ii].name+"'/>"+make_xml(yy[ii].value)+"</valor>";
	}



datos=datos+"</datos>";
//datos = make_xml(datos); 
//alert (datos) ;
datos = encodeURIComponent(datos); 
//var url="http://www.doom-informatica.com/webs2/ajax.asp";
var url="ajax.asp";
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("POST","ajax.asp",true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
url="datos="+datos;
url=url+"&fn=updatetable";
url=url+"&idweb="+idweb;
url=url+"&sql="+numsql;
xmlHttp.send(url);
} 


// DO AJAX 
function doajax(posajax,vdo,vweb,vsql,vvalor1,vvalor2,vvalor3,vvalor4,vvalor5,vvalor6)
{
//alert ("posAjax:"+posajax+" fn:"+vdo+" idweb:"+vweb+" sql:"+vsql+" valor1:"+vvalor1+" valor2:"+vvalor2+" valor3:"+vvalor3  );
DivAjax=posajax; 
if (posajax.length==0)
  { 
  alert ("Falta el contenedor Html en la llamada"); 
  document.getElementById("txtajax").innerHTML="";
  return;
  }else 
    {
  //alert ("img"); 
  //var image1 = new Image();
  //image1.src = "/Img/loading.gif";
  // document.getElementById(DivAjax).innerHTML = "<img src='/Img/loading.gif'></img>"; 
  }

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  
var url="";
url="fn="+vdo;
url=url+"&idweb="+vweb;
url=url+"&sql="+vsql;
url=url+"&valor1="+vvalor1;
url=url+"&valor2="+vvalor2;
url=url+"&valor3="+vvalor3;
url=url+"&valor4="+vvalor4;
url=url+"&valor5="+vvalor5;
url=url+"&valor6="+vvalor6;
url=url+"&datos="+documentdatos(); 
// alert (documentdatos()) ; 
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("POST","ajax.asp",true);
//xmlHttp.open("GET","ajax.asp",true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
//request.setRequestHeader("Content-Type","text/plain");


//xmlHttp.open("GET",url,true);
//xmlHttp.send(null);
xmlHttp.send(url);
} 


function doajaxw(posajax,vdo,vweb,vsql,vvalor1,vvalor2,vvalor3,vvalor4,vvalor5,vvalor6)
{
//alert ("posAjax:"+posajax+" fn:"+vdo+" idweb:"+vweb+" sql:"+vsql+" valor1:"+vvalor1+" valor2:"+vvalor2+" valor3:"+vvalor3  );
DivAjax=posajax; 
if (posajax.length==0)
  { 
  alert ("Falta el contenedor Html en la llamada"); 
  document.getElementById("txtajax").innerHTML="";
  return;
  }else 
    {
  //alert ("img"); 
  }

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  
var url="";
url="fn="+vdo;
url=url+"&idweb="+vweb;
url=url+"&sql="+vsql;
url=url+"&valor1="+vvalor1;
url=url+"&valor2="+vvalor2;
url=url+"&valor3="+vvalor3;
url=url+"&valor4="+vvalor4;
url=url+"&valor5="+vvalor5;
url=url+"&valor6="+vvalor6;
url=url+"&datos="+documentdatos(); 
//alert (documentdatos()) ; 

//MOSTRAR IMAGEN 
var image1 = new Image();
image1.src = "Img/loading.gif";
document.getElementById(DivAjax).innerHTML = "<img src='Img/loading.gif'></img>"; 


xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("POST","ajax.asp",true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

//xmlHttp.open("GET",url,true);
//xmlHttp.send(null);
xmlHttp.send(url);
} 

function doajaxNoDatos(posajax,vdo,vweb,vsql,vvalor1,vvalor2,vvalor3,vvalor4,vvalor5,vvalor6)
{
//alert ("posAjax:"+posajax+" fn:"+vdo+" idweb:"+vweb+" sql:"+vsql+" valor1:"+vvalor1+" valor2:"+vvalor2+" valor3:"+vvalor3  );
DivAjax=posajax; 
if (posajax.length==0)
  { 
  document.getElementById("txtajax").innerHTML="";
  return;
  }else
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  
var url="ajax.asp";
url=url+"?fn="+vdo;
url=url+"&idweb="+vweb;
url=url+"&sql="+vsql;
url=url+"&valor1="+vvalor1;
url=url+"&valor2="+vvalor2;
url=url+"&valor3="+vvalor3;
url=url+"&valor4="+vvalor4;
url=url+"&valor5="+vvalor5;
url=url+"&valor6="+vvalor6;
//url=url+"&datos="+documentdatos(); 
//alert (documentdatos()) ; 
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 


// DO AJAX 
function doajax2(posajax,vdo,vweb,vsql,vvalor1,vvalor2,vvalor3,vvalor4,vvalor5,vvalor6)
{
//alert ("posAjax:"+posajax+" fn:"+vdo+" idweb:"+vweb+" sql:"+vsql+" valor1:"+vvalor1+" valor2:"+vvalor2+" valor3:"+vvalor3  );
DivAjax2=posajax; 
if (posajax.length==0)
  { 
  alert ("Falta el contenedor Html en la llamada"); 
  document.getElementById("txtajax").innerHTML="";
  return;
  }else 
    {
  //alert ("img"); 
  //var image1 = new Image();
  //image1.src = "/Img/loading.gif";
  // document.getElementById(DivAjax).innerHTML = "<img src='/Img/loading.gif'></img>"; 
  }

xmlHttp2=GetXmlHttpObject()
if (xmlHttp2==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  
var url="";
url="fn="+vdo;
url=url+"&idweb="+vweb;
url=url+"&sql="+vsql;
url=url+"&valor1="+vvalor1;
url=url+"&valor2="+vvalor2;
url=url+"&valor3="+vvalor3;
url=url+"&valor4="+vvalor4;
url=url+"&valor5="+vvalor5;
url=url+"&valor6="+vvalor6;
url=url+"&datos="+documentdatos(); 
//alert (documentdatos()) ; 
xmlHttp2.onreadystatechange=stateChanged2;
xmlHttp2.open("POST","ajax.asp",true);
xmlHttp2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

//xmlHttp.open("GET",url,true);
//xmlHttp.send(null);
xmlHttp2.send(url);
} 




function stateChanged(){ 
if (xmlHttp.readyState==4)
{ 
con = unescape(xmlHttp.responseText); 
//con = xmlHttp.responseText; 
//con = encodeURIComponent(xmlHttp.responseText); 
// con = escape(xmlHttp.responseText); 
// con = encodeURI(xmlHttp.responseText); 
// con = decodeURIComponent(xmlHttp.responseText);

//con = htmlencode(con); 
//con2=con.replace(/\+/gi," ");

//document.getElementById(DivAjax).innerHTML=parseScript(con);
document.getElementById(DivAjax).innerHTML=con;
if (con.indexOf("<script") > -1) {
	parseScript(con);
} //indexof 
}
}

function stateChanged2(){ 
if (xmlHttp2.readyState==4)
{ 
con = unescape(xmlHttp2.responseText)   ; 
//con2=con.replace(/\+/gi," ");

//document.getElementById(DivAjax).innerHTML=parseScript(con);
document.getElementById(DivAjax2).innerHTML=con;
if (con.indexOf("<script") > -1) {
	parseScript(con);
} //indexof 
}
}

   
function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}
function htmlencode(mytext) {
	var text = mytext; 
	text = replace(text,'"',unescape('%22'));
    //text = replace(text,'&',unescape('%26'));
    //text = replace(text,'<',unescape('%3C'));
    //text = replace(text,'>',unescape('%3E'));
    text = replace(text,' ',unescape('%A0'));
    text = replace(text,'¡',unescape('%A1'));
    text = replace(text,'¢',unescape('%A2'));
    text = replace(text,'£',unescape('%A3'));
    text = replace(text,'¥',unescape('%A5'));
    text = replace(text,'¦',unescape('%A6'));
    text = replace(text,'§',unescape('%A7'));
    text = replace(text,'¨',unescape('%A8'));
    text = replace(text,'©',unescape('%A9'));
    text = replace(text,'ª',unescape('%AA'));
    text = replace(text,'«',unescape('%AB'));
    text = replace(text,'¬',unescape('%AC'));
    text = replace(text,'­',unescape('%AD'));
    text = replace(text,'®',unescape('%AE'));
    text = replace(text,'¯',unescape('%AF'));
    text = replace(text,'°',unescape('%B0'));
    text = replace(text,'±',unescape('%B1'));
    text = replace(text,'²',unescape('%B2'));
    text = replace(text,'³',unescape('%B3'));
    text = replace(text,'´',unescape('%B4'));
    text = replace(text,'µ',unescape('%B5'));
    text = replace(text,'¶',unescape('%B6'));
    text = replace(text,'·',unescape('%B7'));
    text = replace(text,'¸',unescape('%B8'));
    text = replace(text,'¹',unescape('%B9'));
    text = replace(text,'º',unescape('%BA'));
    text = replace(text,'»',unescape('%BB'));
    text = replace(text,'¼',unescape('%BC'));
    text = replace(text,'½',unescape('%BD'));
    text = replace(text,'¾',unescape('%BE'));
    text = replace(text,'¿',unescape('%BF'));
    text = replace(text,'À',unescape('%C0'));
    text = replace(text,'Á',unescape('%C1'));
    text = replace(text,'Â',unescape('%C2'));
    text = replace(text,'Ã',unescape('%C3'));
    text = replace(text,'Ä',unescape('%C4'));
    text = replace(text,'Å',unescape('%C5'));
    text = replace(text,'Æ',unescape('%C6'));
    text = replace(text,'Ç',unescape('%C7'));
    text = replace(text,'È',unescape('%C8'));
    text = replace(text,'É',unescape('%C9'));
    text = replace(text,'Ê',unescape('%CA'));
    text = replace(text,'Ë',unescape('%CB'));
    text = replace(text,'Ì',unescape('%CC'));
    text = replace(text,'Í',unescape('%CD'));
    text = replace(text,'Î',unescape('%CE'));
    text = replace(text,'Ï',unescape('%CF'));
    text = replace(text,'Ð',unescape('%D0'));
    text = replace(text,'Ñ',unescape('%D1'));
    text = replace(text,'Ò',unescape('%D2'));
    text = replace(text,'Ó',unescape('%D3'));
    text = replace(text,'Ô',unescape('%D4'));
    text = replace(text,'Õ',unescape('%D5'));
    text = replace(text,'Ö',unescape('%D6'));
    text = replace(text,'×',unescape('%D7'));
    text = replace(text,'Ø',unescape('%D8'));
    text = replace(text,'Ù',unescape('%D9'));
    text = replace(text,'Ú',unescape('%DA'));
    text = replace(text,'Û',unescape('%DB'));
    text = replace(text,'Ü',unescape('%DC'));
    text = replace(text,'Ý',unescape('%DD'));
    text = replace(text,'Þ',unescape('%DE'));
    text = replace(text,'ß',unescape('%DF'));
    text = replace(text,'à',unescape('%E0'));
    text = replace(text,'á',unescape('%E1'));
    text = replace(text,'â',unescape('%E2'));
    text = replace(text,'ã',unescape('%E3'));
    text = replace(text,'ä',unescape('%E4'));
    text = replace(text,'å',unescape('%E5'));
    text = replace(text,'æ',unescape('%E6'));
    text = replace(text,'ç',unescape('%E7'));
    text = replace(text,'è',unescape('%E8'));
    text = replace(text,'é',unescape('%E9'));
    text = replace(text,'ê',unescape('%EA'));
    text = replace(text,'ë',unescape('%EB'));
    text = replace(text,'ì',unescape('%EC'));
    text = replace(text,'í',unescape('%ED'));
    text = replace(text,'î',unescape('%EE'));
    text = replace(text,'ï',unescape('%EF'));
    text = replace(text,'ð',unescape('%F0'));
    text = replace(text,'ñ',unescape('%F1'));
    text = replace(text,'ò',unescape('%F2'));
    text = replace(text,'ó',unescape('%F3'));
    text = replace(text,'ô',unescape('%F4'));
    text = replace(text,'õ',unescape('%F5'));
    text = replace(text,'ö',unescape('%F6'));
    text = replace(text,'÷',unescape('%F7'));
    text = replace(text,'ø',unescape('%F8'));
    text = replace(text,'ù',unescape('%F9'));
    text = replace(text,'ú',unescape('%FA'));
    text = replace(text,'û',unescape('%FB'));
    text = replace(text,'ü',unescape('%FC'));
    text = replace(text,'ý',unescape('%FD'));
    text = replace(text,'þ',unescape('%FE'));
    text = replace(text,'ÿ',unescape('%FF'));
	return text; 
}

function parseScript(_source) {
		var source = _source;
		var scripts = new Array();
		
		// Strip out tags
		while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
			var s = source.indexOf("<script");
			var s_e = source.indexOf(">", s);
			var e = source.indexOf("</script", s);
			var e_e = source.indexOf(">", e);
			
			// Add to scripts array
			scripts.push(source.substring(s_e+1, e));
			// Strip from source
			source = source.substring(0, s) + source.substring(e_e+1);
		}
		
		// Loop through every script collected and eval it
		//alert(scripts.length); 
		for(var i=0; i<scripts.length; i++) {
			try {
				eval(scripts[i]);
			}
			catch(ex) {
				// do what you want here when a script fails
			}
		}
		
		// Return the cleaned source
		return source;
	}

	
function GetXmlHttpObject(){
	var xmlHttp = function() {
  try { return new ActiveXObject("Msxml2.XMLHTTP.6.0") } catch(e) {}
  try { return new ActiveXObject("Msxml2.XMLHTTP.3.0") } catch(e) {}
  try { return new ActiveXObject("Msxml2.XMLHTTP") } catch(e) {}
  try { return new ActiveXObject("Microsoft.XMLHTTP") } catch(e) {}
  throw new Error( "This browser does not support XMLHttpRequest." )
};
return xmlHttp;
}

	
function GetXmlHttpObject(){
var xmlHttp=null;
try {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP.6.0") ;
    }
  catch (e){
	try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e){
    try
	{
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }catch (e)
	{
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP.3.0") ;
  }   }}
  }
return xmlHttp;
}



	
function GetXmlHttpObjectOLD(){


var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function make_xml(txt)
{
var tlen,n,i,addtxt,j,newtxt=""
var symbol=new Array()
var entity=new Array()
tlen=30
symbol[0]="<"
entity[0]="&#60;"
symbol[1]=">"
entity[1]="&#62;"
symbol[2]="&"
entity[2]="&#38;"
symbol[3]="/"
entity[3]="&#47;"
symbol[3]="ñ"
entity[3]="&#241;"
symbol[4]="á"
entity[4]="&#225;"
symbol[5]="à"
entity[5]="&#224;"
symbol[6]="é"
entity[6]="&#233;"
symbol[7]="è"
entity[7]="&#232;"
symbol[8]="í"
entity[8]="&#237;"
symbol[9]="ì"
entity[9]="&#236;"
symbol[10]="ó"
entity[10]="&#243;"
symbol[11]="ò"
entity[11]="&#242;"
symbol[12]="ú"
entity[12]="&#250;"
symbol[13]="ù"
entity[13]="&#249;"
symbol[14]="ï"
entity[14]="&#239;"
symbol[15]="ü"
entity[15]="&#252;"
symbol[16]="@"
entity[16]="&#64;"
symbol[17]="%"
entity[17]="&#37;"
symbol[18]="("
entity[18]="&#40;"
symbol[19]=")"
entity[19]="&#41;"
symbol[20]="="
entity[20]="&#61;"
symbol[21]="#"
entity[21]="&#35;"
symbol[22]="$"
entity[22]="&#36;"
symbol[23]="'"
entity[23]="&#39;"
symbol[24]="*"
entity[24]="&#42;"
symbol[25]="+"
entity[25]="&#43;"
symbol[26]=","
entity[26]="&#44;"
symbol[27]="-"
entity[27]="&#45;"
symbol[28]="."
entity[28]="&#46;"
symbol[28]="ç"
entity[28]="&#231;"
symbol[29]="€"
entity[29]="&#8364;"
symbol[30]="Ó"
entity[30]="&Oacute;"
symbol[31]="À"
entity[31]="&Agrave;"
symbol[32]="Á"
entity[32]="&Aacute;"
symbol[33]="É"
entity[33]="&Eacute;"
symbol[34]="È"
entity[34]="&Egrave;"


if (txt)
	{
	n=app_Rtrim(txt).length
	}
else
	{
	return ""
	}
for (i=0;i<n;i++)
	{
	addtxt=txt.substr(i,1)
	for (j=0;j<=tlen;j++)
		{
		if (addtxt==symbol[j])
			{
			addtxt=entity[j]
			}
		}
		
	newtxt=newtxt + addtxt;
	}

return newtxt

}
function app_Rtrim(txt)
{
while (txt.charAt((txt.length -1))==" ")
	{
	txt=txt.substring(0,txt.length-1)
	}
return txt
}

// --------------------------------------------------- DOCUMENT DATOS 
// retorna una cadema Xml de dades amb tots els camps de datos que hi hagi dins del document actual 
function documentdatos()
{

// MONTAR XML AMB ELS CAMPS INPUT 
y=document.getElementsByTagName("input")

//var datos = "&ltdatos&gt"; 
//var datos = "<?xml version='1.0' encoding='iso-8859-1'?><datos>"; 
var datos = "<datos>"; 
var numS = 0;
for (i=0;i<y.length;i++)
	{
	//datos=datos+"&ltvalor name='"+y[i].name+"' value='"+y[i].value+"'&#47&gt";
	if (y[i].type=="checkbox") {
		//alert (y[i].checked); 
		if (y[i].checked) {
		datos=datos+"<valor name='"+y[i].name+"' value='1'>1</valor>";
		}else{
		datos=datos+"<valor name='"+y[i].name+"' value='0'>0</valor>";
		}
	}else {
	datos=datos+"<valor name='"+y[i].name+"'>"+escape(make_xml(y[i].value))+"</valor>";
	}
	numS=numS+1;
	}
//datos=datos+"&lt&#47datos&gt";

// MONTAR XML AMB ELS CAMPS TEXTAREA
yy=document.getElementsByTagName("textarea")
for (ii=0;ii<yy.length;ii++){
	//alert (yy[ii].value);
	datos=datos+"<valor name='"+yy[ii].name+"'>"+escape(make_xml(yy[ii].value))+"</valor>";
	// alert(make_xml(yy[ii].value)); 
	numS=numS+1;
	}

// MONTAR XML AMB ELS CAMPS SELECT 
yy=document.getElementsByTagName("select")
for (ii=0;ii<yy.length;ii++){
	//alert ("name: "+yy[ii].name+"="+yy[ii].value);
	datos=datos+"<valor name='"+yy[ii].name+"'>"+make_xml(yy[ii].value)+"</valor>";
	numS=numS+1;
}


datos=datos+"</datos>";
if (numS==0){
datos=""; 
}
//datos = make_xml(datos); 

datos = encodeURIComponent(datos); 
//var datosUTF = utf8_encode(datos); 
//var datosUTF; 
//alert (datosUTF) ;
return datos; 
//return datosUTF; 
//return  datosUTF; 
} 
function utf8_encode (argString) {
    // Encodes an ISO-8859-1 string to UTF-8  
    // 
    // version: 1109.2015
    // discuss at: http://phpjs.org/functions/utf8_encode
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: sowberry
    // +    tweaked by: Jack
    // +   bugfixed by: Onno Marsman
    // +   improved by: Yves Sucaet
    // +   bugfixed by: Onno Marsman
    // +   bugfixed by: Ulrich
    // +   bugfixed by: Rafal Kukawski
    // *     example 1: utf8_encode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'
    if (argString === null || typeof argString === "undefined") {
        return "";
    }
 
    var string = (argString + ''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n");
    var utftext = "",
        start, end, stringl = 0;
 
    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;
 
        if (c1 < 128) {
            end++;
        } else if (c1 > 127 && c1 < 2048) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc !== null) {
            if (end > start) {
                utftext += string.slice(start, end);
            }
            utftext += enc;
            start = end = n + 1;
        }
    }
 
    if (end > start) {
        utftext += string.slice(start, stringl);
    }
 
    return utftext;
}

function utf8_decode ( str_data ) {  
    // Converts a UTF-8 encoded string to ISO-8859-1    
    //   
    // version: 810.1317  
    // discuss at: http://phpjs.org/functions/utf8_decode  
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)  
    // +      input by: Aman Gupta  
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)  
    // +   improved by: Norman "zEh" Fuchs  
    // +   bugfixed by: hitwork  
    // +   bugfixed by: Onno Marsman  
    // *     example 1: utf8_decode('Kevin van Zonneveld');  
    // *     returns 1: 'Kevin van Zonneveld'  
    var tmp_arr = [], i = ac = c1 = c2 = c3 = 0;  
  
    str_data += '';  
  
    while ( i < str_data.length ) {  
        c1 = str_data.charCodeAt(i);  
        if (c1 < 128) {  
            tmp_arr[ac++] = String.fromCharCode(c1);  
            i++;  
        } else if ((c1 > 191) && (c1 < 224)) {  
            c2 = str_data.charCodeAt(i+1);  
            tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));  
            i += 2;  
        } else {  
            c2 = str_data.charCodeAt(i+1);  
            c3 = str_data.charCodeAt(i+2);  
            tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));  
            i += 3;  
        }  
    }  
  
    return tmp_arr.join('');  
}  


function pedirvalor(ob) 
{
inputBox.getFloat("Introduzca la medida en centimetros");
ob.value = "99.99" 
}



	function grabObject ( id ) {
		if ( is_ie4 ) {
			var view = eval(id);
		}
		if ( is_ie5up || is_gecko ) {
			var view = document.getElementById(id);
		}
		return view;
	}
	function show_hide (id) {
		if( is_ie4up || is_gecko ) {
			var hdn_div = grabObject(id);
			if( hdn_div.style.display == 'block' ) {
				hdn_div.style.display = 'none';
			} else {
				hdn_div.style.display = 'block';
			}
		}
	}

	
function intercept(event,obj) {
    var key = event.keyCode; 
    if (key == 9) {
	// alert (key); 
      mostrarTab(obj); 
      return false;
    } else {
      return key;
    }
}
function mostrarTab(obj) {
    rolling=obj.scrollTop;
    if(typeof obj.selectionStart == 'number') {
        // Resto de navegadores
        var start = obj.selectionStart;
        var end = obj.selectionEnd;
		var str = obj.value; 
		//alert(start  )  ; 
		//alert(str.substring(start, str.length) ) ; 
        obj.value = obj.value.substring(0, start)+"\t";
        obj.value+= str.substring(start, str.length);
        obj.focus();
        obj.selectionStart =  obj.selectionEnd= end + 1;
    } 
    else if(document.selection) {
        // Internet Explorer
        obj.focus();
        var range = document.selection.createRange();
        if(range.parentElement() != obj) return false;
        if (range.text != "") {
            if(typeof range.text == 'string'){
                document.selection.createRange().text ="\t"+range.text;
            }
            else obj.value += "\t";
        }
        else
            obj.value += "\t";
    }
    obj.scrollTop=rolling;
}


// COMPRUEVA LAS FECHAS DE UN CALENDARIO 
function fieldcalendar(obj){
	var str = obj.value;
	var l = str.length; 
	if (l==2) { 
		obj.value = str+"/"; 
	}
	if (l==5) { 
		obj.value = str+"/"; 
	}
}
function completecalendar(obj){
	var str = obj.value;
	var l = str.length; 
	var currentTime = new Date()
	var month = currentTime.getMonth() + 1
	var day = currentTime.getDate()
	var year = currentTime.getFullYear()

	if (l==3) { 
		obj.value = str+month+"/"+year;
	}
	if (l==6) { 
		obj.value = str+year; 
	}
}
function calendarshow(mydiv,myfield){

	g_calendarObject = new JsDatePick({
        useMode:1,
        target:mydiv
    });
    g_calendarObject.setOnSelectedDelegate(function(){
        var obj = g_calendarObject.getSelectedDay();
		var mydate; 
		var mycontent; 
		//alert(document.getElementById(myfield).innerHTML);
		//alert(document.getElementById(myfield).value);
		//document.getElementById(myfield).innerHTML=obj.day + "/" + obj.month + "/" + obj.year;
		mydate = obj.day + "/" + obj.month + "/" + obj.year;
		mycontent = document.getElementById(myfield);
		//alert(mycontent.value);
		mycontent.value = mydate;
		g_calendarObject.JsDatePickBox.style.display = "none"; 
        
		});
		
		// alert('aa');
}



// IMAGE POPUP 
// ------------------------------
var titulopordefecto = "Imagenes"; 
var ventana;
var cont=0;

// ********************** CAMBIAR ELS NOMS DE LES CLASES ****************** 
function menuclass(vid,element,estilnormal,estilactivat){
	//alert(vid+"  "+element+"  "+estilnormal+"  "+estilactivat); 
	//alert("aqui"); 
	var elementli=document.getElementById(vid);
	var i=elementli.childNodes.length; 
	var numelem; 
	//alert(i); 
	for ( var x = 0;x<i;x++){
			// alert(elementli.childNodes[x].tagName+"  "+elementli.childNodes[x].id+"  "+elementli.childNodes[x].name+"  "+elementli.childNodes[x].text);
			numelem=elementli.childNodes[x].id; 
			// nomes treballa amb els elements tipus a 
			if (elementli.childNodes[x].tagName=='A') { 
			if (numelem == element) {
			elementli.childNodes[x].className=estilactivat;
			}else{
			//alert(elementli.childNodes[x].id+"  "+elementli.childNodes[x].text);
			elementli.childNodes[x].className=estilnormal;
			}
			}
			//alert(elementli.childNodes[x].className); 
	}
}

document.getElementsByClassName = function(cl, sTagName) {
    var retnode = [];
    var myclass = new RegExp('\\b'+cl+'\\b');
    var elem = this.getElementsByTagName((sTagName===""||sTagName===null)?"*":sTagName);
    for (var i = 0; i < elem.length; i++) {
        var classes = elem[i].className;
        if (myclass.test(classes)) retnode.push(elem[i]);
    }
    return retnode;
};

function ChangeClassElemets(sTagName, oldClass, newClass){
	var items = []; 
	var i; 
	items = document.getElementsByClassName(oldClass,sTagName)
	for (var i = 0; i < items.length; i++) {
		//alert (items[i].className);
		items[i].className = newClass; 	
	}

}



// ********************** CREATE DIV ****************** 
function creatediv(id, html, left, top, width, height) {
var newdiv = document.createElement('div'); 
newdiv.setAttribute('id', id); 
if (width) { newdiv.style.width = width; } 
if (height) { newdiv.style.height = height; } 
if ((left || top) || (left && top)) { newdiv.style.position = "absolute"; if (left) { newdiv.style.left = left; } if (top) { newdiv.style.top = top; } } 
newdiv.style.background = "#fff"; newdiv.style.border = "1px solid #cacaca"; 
if (html) { newdiv.innerHTML = html; } else { newdiv.innerHTML = "nothing"; } 
//if (document.body.firstChild){
//	alert('yes');
//      document.body.insertBefore(newdiv,document.body.firstChild);
//}else{
//	alert('no');
//	  for i in document.body.childs
//	  
//	  next
document.body.appendChild(newdiv);

return newdiv; 
}


// **********************ABOSLUTE POSITION  ****************** 
// FUNCION PER EL SUBMENUS 
function absolutepositionY( oElement )
{
var iReturnValue = 0;
while( oElement != null ) {
iReturnValue += oElement.offsetTop;
oElement = oElement.offsetParent;
}
return iReturnValue;
}

function absolutepositionX( oElement )
{
var iReturnValue = 0;
while( oElement != null ) {
iReturnValue += oElement.offsetLeft;
//alert(oElement.id+' '+oElement.offsetLeft+' '+oElement.style.left);

oElement = oElement.offsetParent;
}
return iReturnValue;
} 

function submenuclose( vId)  {
	var vtime = 500; 
	vsubmenuClose = vId; 
	submenutimer = setTimeout("mcloses()",vtime);
	
}
function mcloses(){
	document.getElementById(vsubmenuClose).style.visibility='hidden';
}
function submenucancel()  {
	clearTimeout(submenutimer);
}



// ********************** INSERT PARAM  ****************** 
function insertParam(key, value) {
        key = escape(key); value = escape(value);

        var kvp = document.location.hash.split('&');
		//alert(document.location.hash+'  key:'+key+'  value:'+value);
        if (kvp == "") {
            document.location.hash = key + "=" + value;
        }
        else {

            var i = kvp.length; var x; 
			
			while (i--) {
                x = kvp[i].split('=');
				//alert(kvp[i]);
                if ((x[0] == key) || (x[0] == '#'+key)){
                    x[1] = value;
					//alert('set:'+x.join('='));
                    kvp[i] = x.join('=');
                    break;
                }
            }

            if (i < 0) { 
			kvp[kvp.length] = [key, value].join('='); 
			
			}

            //this will reload the page, it's likely better to store this until finished
            document.location.hash = kvp.join('&');
        }
    }



// ********************** COOKIES.  ****************** 	
function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
 
function eraseCookie(name) {
    createCookie(name,"",-1);
}


// ********************** setstyle of a element .  ****************** 	
function setElementStyle(element, declaration) {
alert(declaration); 
   if (declaration.charAt(declaration.length-1)==';')
     declaration = declaration.slice(0, -1);
   var k, v;
   var splitted = declaration.split(';');
   for (var i=0, len=splitted.length; i<len; i++) {
      k = rzCC(splitted[i].split(':')[0]);
      v = splitted[i].split(':')[1];
      eval("element.style."+k+"='"+v+"'");

   }
 }
