function gId(id){return document.getElementById(id);}

function activarMenu(nombreMenu, acceso, idioma)	{			
	
	if (nombreMenu != "mapa" && nombreMenu != "avisoLegal" && nombreMenu != "resultadosBusqueda" && nombreMenu != "perfilContratante") {
		menu = gId("menu" + nombreMenu + ucwords(acceso));		
		menu.className = "menuActivado";	
	}
	cambiarPestanyasAcceso(acceso, idioma);
}

function cambiarPestanyasAcceso(acceso, idioma)	{
	gId("pestanyasAcceso").style.backgroundImage = "url('img/pestanyasAcceso" + acceso + idioma + ".jpg')";	
}

function openPopupArtesano(link) {
	window.open(c,
	'window',
	'width=550,height=345,scrollbars=no,status=yes');	
	return false;
}

function loadResultados(idform, acceso, menu, idioma) {
	sendForm(gId(idform), 'divTableResultados'); 
	//cambiarPestanyasAcceso(acceso);
	activarMenu(menu, acceso, idioma);
}

function ucwords(strObj){
	return(strObj.charAt(0).toUpperCase()+strObj.substr(1));
}

function printDiv(divId)
{
  var divToPrint = gId(divId);  
  newWin = window.open("");
  newWin.document.write("<link rel='stylesheet' type='text/css' href='css/principalPrint.css'>");
  newWin.document.write("<link rel='stylesheet' type='text/css' href='css/textosPrint.css'>");
  
   newWin.document.write("<script type='text/javascript'>window.onload=function{ window.print()} ;</script>");
   newWin.document.write("<body>");
  newWin.document.write(divToPrint.innerHTML);
 newWin.document.write("</body>");
  
	  
	//if (newWin.print) {
		newWin.print() ;  
	/*} else {
	    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
		document.body.insertAdjacentHTML('beforeEnd', newWin);
	    newWin.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
	}*/
  
  //newWin.close();
}

function validarFormBusqueda(formBusqueda) {
	
	busquedaValue = formBusqueda.cajaBusqueda.value;
	
	if (busquedaValue == "") {
		alert("Debe rellenar el campo de busqueda");
		return false;
	} else {
		return true;
	}
}

/* ------------------------------------ */
/*                                      */
/*        	Funciones para 	        	*/
/*          Rutas Artesanas             */
/*                                      */
/* ------------------------------------ */


function changeCheckBoxes (c, start, stop, formName) {
	
	frm=eval("document." + formName);

	if (c.checked)
	value=true;
	else
	value=false;

	for (i = 0; frm.elements[i]; i++) {
		if (frm.elements[i].name.substr(0,4) == "cbx_")
		frm.elements[i].checked=value;
	}
}  

function info(a) {
	var b = document.getElementById(a).href;location.href=(b)
}	

function envia(URL) {
	c=document.getElementsByTagName('input'); 
	nv=new Array();
	j=0; 
	for(var i=0;i<c.length;i++){ 
		
	    if((c[i].type=='checkbox')&&(c[i].checked)){ 
	    nv[j]=[c[i].value]; 
	    j++; 
	    } 
	} 
	if (nv.length==0) { 
		alert('No se ha seleccionado ningun artesano.'); 
	}
   else {
		sended='';
		for(var i=0;i<nv.length;i++){ 
		 if (nv[i] != 'on') {	
			if (sended == '') { sended = nv[i]; }
			else { sended = sended+','+nv[i]; }
		  }
		} 
		tipo = getIndex();
		if (tipo == 0) {
		alert('No se ha seleccionado el formato.'); 	 
	  }
	  else {
		location.href=URL+'?id='+sended+'&tipo='+tipo; 
		}
	}
}

function getIndex()   {
  var x=document.getElementById("formato");
  //alert (x.selectedIndex);
  return x.selectedIndex;
  //alert(this.options[this.selectedIndex].value)
  }