/*** JS ****/
function objetoAjax(){	var xmlhttp=false;	try {		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");	} catch (e) {		try {		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");		} catch (E) {			xmlhttp = false;  		}	}	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {		xmlhttp = new XMLHttpRequest();	}	return xmlhttp;}
//Novedades Home
function MostrarCategoriaNovedades(idcontenedor){
	document.getElementById(idcontenedor).style.display = 'block';
}


function OcultarCategoriaNovedades(cantidadCategorias, idbtn){
	cont = 0;
	num = cantidadCategorias + 1;
	while(cont < cantidadCategorias){
		id= "categorias_contenedor_"+String(cont+1);
		document.getElementById(id).style.display = 'none';
		cont++;
	}
	ActiveBtn(cantidadCategorias, idbtn);
}

function ActiveBtn(cantidadCategorias, idbtn){
	cont = 0;
	num = cantidadCategorias + 1;
	while(cont < cantidadCategorias){
		id= "btn_"+String(cont+1);
		document.getElementById(id).className = 'btn-categoria';
		cont++;
	}	
	document.getElementById(idbtn).className = 'btn-categoria btn-categoria-activa';
}
function ShowComunas(server){	codRegion = document.getElementById("contacto_region").value;	if(codRegion != ''){				datos = server+'controller/common/common_ajax.php?tipo=swregiones&codregion='+codRegion;		ajax = objetoAjax();		ajax.open("GET", datos);		ajax.onreadystatechange = function(){			if (ajax.readyState == 4 && ajax.status == 200) {				dato = ajax.responseText;								document.getElementById("contenedor_comunas").innerHTML = dato;				document.getElementById("contacto_comuna").disabled = false;			}		}		ajax.send(null)	}else{		document.getElementById("contacto_comuna").selectedIndex = 0;		document.getElementById("contacto_comuna").disabled = true;	}}
function LoadDatos(server){	rut = document.getElementById("txRut").value;		do {		rut = rut.replace('-','');		rut = rut.replace('.','');	} while(rut.indexOf('a') >= 0);		if(rut){				datos = server+'controller/common/common_ajax.php?tipo=load&rut='+rut;		//alert(datos);		ajax = objetoAjax();		ajax.open("GET", datos);		ajax.onreadystatechange = function(){            if(ajax.readyState==1){            	document.getElementById("img-load").style.display = 'block';        }else if (ajax.readyState == 4 && ajax.status == 200) {				dato = ajax.responseText;					dato = dato.split("#");								document.getElementById("txNombres").value = dato[0];				document.getElementById("txApPaterno").value = dato[1];				document.getElementById("txApMaterno").value = dato[2];				document.getElementById("txEmail").value = dato[5];				document.getElementById("txTelFijo").value = dato[3];				document.getElementById("txTelCelular").value = dato[4];								ObjSedes =document.getElementById("slc_sedes");				ObjRegiones =document.getElementById("contacto_region");				ObjRegiones =document.getElementById("contacto_region");				//ObjRegiones =document.getElementById("contacto_region");				//alert(ObjSedes.length);								for(var i=0;i<ObjSedes.length;i++){					if(ObjSedes.options[i].value == dato[6]){						ObjSedes.selectedIndex =i;					}					//alert(ObjSedes.options[i].value);				}								if(dato[7]){				for(var i=0;i<ObjRegiones.length;i++){					if(ObjRegiones.options[i].value == dato[7]){						ObjRegiones.selectedIndex =i;					}					//alert(ObjSedes.options[i].value);				}				}												if(dato[8]){					ShowComunasSelected(dato[8], dato[7]);				}												//document.getElementById("txareaConsulta").innerHTML = dato[9];								for(var i=10;i<17;i++){					if(dato[i] !=''){						if(document.getElementById("contacto_red_"+dato[i])){							document.getElementById("contacto_red_"+dato[i]).checked = true;						}					}														}								//document.getElementById("txNombres").value = dato[0];								document.getElementById("img-load").style.display = 'none';			}		}		ajax.send(null)	}else{		/*document.getElementById("contacto_comuna").selectedIndex = 0;		document.getElementById("contacto_comuna").disabled = true;*/	}}function LoadDatosColegios(server){	rut = document.getElementById("txRut").value;		do {		rut = rut.replace('-','');		rut = rut.replace('.','');	} while(rut.indexOf('a') >= 0);		if(rut){				datos = server+'controller/common/common_ajax.php?tipo=loadcolegios&rut='+rut;		//alert(datos);		ajax = objetoAjax();		ajax.open("GET", datos);		ajax.onreadystatechange = function(){            if(ajax.readyState==1){            	document.getElementById("img-load").style.display = 'block';        }else if (ajax.readyState == 4 && ajax.status == 200) {				dato = ajax.responseText;					dato = dato.split("#");								document.getElementById("txNombres").value = dato[0];				document.getElementById("txApPaterno").value = dato[1];				document.getElementById("txApMaterno").value = dato[2];				document.getElementById("txEmail").value = dato[5];				document.getElementById("txTelFijo").value = dato[3];				document.getElementById("txTelCelular").value = dato[4];								//ObjSedes =document.getElementById("slc_sedes");				ObjRegiones =document.getElementById("contacto_region");				ObjRegiones =document.getElementById("contacto_region");				//ObjRegiones =document.getElementById("contacto_region");				//alert(ObjSedes.length);								/*for(var i=0;i<ObjSedes.length;i++){					if(ObjSedes.options[i].value == dato[6]){						ObjSedes.selectedIndex =i;					}				}*/								if(dato[6]){				for(var i=0;i<ObjRegiones.length;i++){					if(ObjRegiones.options[i].value == dato[6]){						ObjRegiones.selectedIndex =i;					}					//alert(ObjSedes.options[i].value);				}				}												if(dato[7]){					ShowComunasSelected(dato[7], dato[6]);				}								if(dato[8]){					document.getElementById("txEstablecimiento").value = dato[8];				}												if(dato[9]){					document.getElementById("txCurso").value = dato[9];				}							//document.getElementById("txareaConsulta").innerHTML = dato[9];								/*for(var i=10;i<17;i++){					if(dato[i] !=''){						if(document.getElementById("contacto_red_"+dato[i])){							document.getElementById("contacto_red_"+dato[i]).checked = true;						}					}														}*/								//document.getElementById("txNombres").value = dato[0];								document.getElementById("img-load").style.display = 'none';			}		}		ajax.send(null)	}else{		/*document.getElementById("contacto_comuna").selectedIndex = 0;		document.getElementById("contacto_comuna").disabled = true;*/	}}

function ShowComunasSelected(codComuna, region){		datos = '../controller/common/common_ajax.php?tipo=swcomunaselect&codcomuna='+codComuna+'&codregion='+region;		ajax = objetoAjax();		ajax.open("GET", datos);		ajax.onreadystatechange = function(){			if (ajax.readyState == 4 && ajax.status == 200) {				dato = ajax.responseText;								document.getElementById("contenedor_comunas").innerHTML = dato;				document.getElementById("contacto_comuna").disabled = false;			}		}		ajax.send(null)}
function SubmitForm(){	nombres = document.getElementById("txNombres").value;	ApPaterno = document.getElementById("txApPaterno").value;	ApMaterno = document.getElementById("txApMaterno").value;	Email= document.getElementById("txEmail").value;	consulta= document.getElementById("txareaConsulta").value;	document.getElementById("msj-error").style.display = 'none';	document.getElementById("msj-error-email").style.display = 'none';	document.getElementById("msj-error-requeridos").style.display = 'none';	document.getElementById("msj-error-rut").style.display = 'none';	document.getElementById("txRut").style.border = '1px solid #bac2cf';	document.getElementById("txNombres").style.border = '1px solid #bac2cf';	document.getElementById("txApPaterno").style.border = '1px solid #bac2cf';	document.getElementById("txApMaterno").style.border = '1px solid #bac2cf';	document.getElementById("txEmail").style.border = '1px solid #bac2cf';	document.getElementById("txareaConsulta").style.border = '1px solid #bac2cf';		if(Valida_Rut(document.getElementById("txRut").value) == false || document.getElementById("txRut").value==''){		document.getElementById("msj-error").style.display = 'block';		document.getElementById("msj-error-rut").style.display = 'block';		document.getElementById("txRut").style.border = '1px solid #b90000';			}		if(nombres==''){		document.getElementById("msj-error").style.display = 'block';		document.getElementById("msj-error-requeridos").style.display = 'block';		document.getElementById("txNombres").style.border = '1px solid #b90000';			}		if(ApPaterno==''){		document.getElementById("msj-error").style.display = 'block';		document.getElementById("msj-error-requeridos").style.display = 'block';		document.getElementById("txApPaterno").style.border = '1px solid #b90000';			}		if(ApMaterno==''){		document.getElementById("msj-error").style.display = 'block';		document.getElementById("msj-error-requeridos").style.display = 'block';		document.getElementById("txApMaterno").style.border = '1px solid #b90000';			}	if(ValidarEmail(Email) == false){		document.getElementById("msj-error").style.display = 'block';		document.getElementById("msj-error-email").style.display = 'block';		document.getElementById("txEmail").style.border = '1px solid #b90000';			}		if(consulta==''){		document.getElementById("msj-error").style.display = 'block';		document.getElementById("msj-error-requeridos").style.display = 'block';		document.getElementById("txareaConsulta").style.border = '1px solid #b90000';			}	if(Valida_Rut(document.getElementById("txRut").value) == false || document.getElementById("txRut").value=='' || nombres=='' || ApPaterno=='' || ApMaterno=='' || ValidarEmail(Email) == false || consulta==''){		return false;	}		document.getElementById("id_form_contacto").submit();}function FormLimpiar(){	ShowComunasSelected(309, 7);}function ValidarEmail(valor){    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)) {        return true;    }    else {        return false;    }}function Valida_Rut(rut){	var tmpstr = "";	var intlargo = rut;	var bol;	var retorno;		if (intlargo.length> 0)	{		crut = rut		largo = crut.length;		if ( largo <2 )		{			//alert('rut inválido')			//Objeto.focus()			bol = false;			//return false;		}		for ( i=0; i <crut.length ; i++ )		if ( crut.charAt(i) != ' ' && crut.charAt(i) != '.' && crut.charAt(i) != '-' )		{			tmpstr = tmpstr + crut.charAt(i);		}		rut = tmpstr;		crut=tmpstr;		largo = crut.length;			if ( largo> 2 )			rut = crut.substring(0, largo - 1);		else			rut = crut.charAt(0);			dv = crut.charAt(largo-1);			if ( rut == null || dv == null )		return 0;			var dvr = '0';		suma = 0;		mul  = 2;			for (i= rut.length-1 ; i>= 0; i--)		{			suma = suma + rut.charAt(i) * mul;			if (mul == 7)				mul = 2;			else				mul++;		}			res = suma % 11;		if (res==1)			dvr = 'k';		else if (res==0)			dvr = '0';		else		{			dvi = 11-res;			dvr = dvi + "";		}		if(bol == false){			retorno = false;					}else if ( dvr != dv.toLowerCase() )		{			retorno = false;		}else{			retorno = true;			}		return retorno;	}}
