window.onload=function(){
	
	if(document.getElementById('divnavegacionind')!=null){
		/*
		if(document.getElementById('topbar')!=null){
			document.getElementById("topbar").style.display = '';
		}
		*/
		Start();
		load_true = true;
	}
	/* iniciar el mapa */
	if(document.getElementById('map')!=null){
		load();
	}
}


function guardar_keywords(id_keywords,nocache){
	cargaDIVXML('div_keywords','','cargando...','','');
	cargaXML(BASEURL+'consultas/admin-accion.php?keywords='+id_keywords+'&guardar=true&texto='+document.getElementById('imput_keywords').value+'&nocache='+nocache);
}

function bt_imagen(btid){
	document.getElementById(btid).src = BASEURL+"imagenes/botones/"+btid+"-up.jpg";
}

function bt_imagen_out(btid,btselesct){
	document.getElementById(btid).src = BASEURL+"imagenes/botones/"+btid+btselesct+".jpg";
}

function barra_SWFObject(url,swf_pagina){
		var soAN = new SWFObject(url, "swf_barraprincipal", "810", "35", "7", "#6D80A8");
		soAN.addParam("wmode", "transparent");
		soAN.addVariable("pagina", swf_pagina);
		soAN.write('swf_barraprincipal');
}

function cerrar_sesion(username){
	if(username==' '){
		username = '';
	}
	ht = document.getElementsByTagName("html");
	ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
	if(confirm("CM Electónica\n¿"+username+"Confirmas cerrar la sesión?")!=true){
		ht[0].style.filter = "";
	return;
	}else{
		window.location = BASEURL+"index.php?accion=salir";
	}
}


function img_mostrar(accion,oblid){
	if(accion == 'mostrar'){
		document.getElementById("img_articulo_"+oblid).style.display = '';
	}else{
		document.getElementById("img_articulo_"+oblid).style.display = 'none';
	}
	if(document.getElementById("img_articulo_"+oblid).style.left==0){
		ref = document.getElementById("div_articulo_"+oblid).offsetLeft;
		ref_top = (document.getElementById("img_articulo_"+oblid).height /2);
		document.getElementById("img_articulo_"+oblid).style.left = ref - ref - document.getElementById("img_articulo_"+oblid).width;
		document.getElementById("img_articulo_"+oblid).style.top = 20 - document.getElementById("img_articulo_"+oblid).height/2
	}
}


var detener;
/************** validacion de formularios **********************/
function frm_iniciar(values){
	str = values.split(","); // a ver que tenemos
	cont = 0;
	while(str[cont]!=null){
		if(str[cont]!=""){
				if(document.getElementById(str[cont]).value!=""){ // si esta vacio
					document.getElementById(str[cont]).style.backgroundColor="#e8fde3";
					document.getElementById("indic_"+str[cont]).className = "font_verde";
				}
		}
	cont = cont+1;
	}
}

function frm_passsumbit(frmname,values){ // formulario,campos

	str = values.split(","); // a ver que tenemos
	cont = 0;
	while(str[cont]!=null){
		if(str[cont]!=""){
				if(document.getElementById(str[cont]).value=="otro"){ // si esta vacio
					if(document.getElementById('frm_artefacto_2').value==""){ // si esta vacio
					alert("CM Electronica:\nCampo "+document.getElementById(str[cont]).value+" no valido");
					return;
					}
				}
				if(document.getElementById(str[cont]).value==""){ // si esta vacio
					if(detener!=true){
					alert("CM Electronica:\nPor favor complete los campos requeridos");
					document.getElementById(str[cont]).style.backgroundColor="#ff9595";
					document.getElementById(str[cont]).focus();
					detener = true;
						if(document.getElementById("indic_"+str[cont])!=null){
							document.getElementById("indic_"+str[cont]).className = "font_rojo";
						}
					}
				}else{
					document.getElementById(str[cont]).style.backgroundColor="#e8fde3";
					if(document.getElementById("indic_"+str[cont])!=null){
						document.getElementById("indic_"+str[cont]).className = "font_verde";
					}
				}
		}
	cont = cont+1;
	}
	if(detener==true){
		detener=false;
		return;
	}

	/* si se esta enviando una consulta o respuesta */
	if(document.getElementById('edit')!=null){ // si esta!
		if(document.getElementById('edit').contentWindow.document.body.innerHTML==""){
			alert("CM Electronica:\nPor favor complete los campos requeridos");
			document.getElementById('tb_editor').style.backgroundColor="#ff9595";
		return;
		}
		
		if(document.getElementById('edit').contentWindow.document.body.innerHTML.length <= 7){
			alert('CM Electronica:\nEl mensaje ingresado es muy corto!');
			document.getElementById('tb_editor').style.backgroundColor="#fbfda8";
		return;
		}else{
		frm_pasar_data(); // esto es para pasar el campo edit al textarea
		}
	}

	if(document.getElementById('edit')!=null){
		if(document.getElementById('edit').style.display == 'none'){
			if(confirm("CM electronica:\nEl editor esta abierto! ¿guardar edición?")!=true){
				return false;
			}else{
				pegar_codigo();
				return true;
			}
		}
	}

	if(document.getElementById('frm_provincia')!=null){
		document.getElementById('frm_provincia').disabled = false;
	}
	if(document.getElementById('frm_pais')!=null){
		document.getElementById('frm_pais').disabled = false;
	}
	/**********************************************/
	// todo OK, enviar
	document.getElementById('enviar').disabled="disabled";
	document.getElementById(frmname).submit();
}
/****************************************************************/

var extra;
function buscar_articulo(tipo,buscar,frm_id){
/*
		if(document.getElementById('frm_buscar_artefacto').value != null){
			
		}
*/
		extra = document.getElementById(frm_id).value;
		window.location = BASEURL+"articulos/index.php/"+tipo+buscar+".html"
		/*
		if(buscar == ""){
			alert('CM Electronica:\nPor favor ingrese una búsqueda');
			return;
		}else{
			
		}
		*/
}

/**************************/
function buscar_casilla(id,accion){
	extra_add = "";
	if(accion=='mostrar'){
		extra_add = "&accion=mostrar";
	}
		document.getElementById('div_casilla').style.display = '';
		cargaDIVXML('div_casilla','','','','');
		cargaXML(BASEURL+"articulos/busqueda-casillas.php?palabra="+document.getElementById(id).value+"&elementoid="+id+extra_add);
}




function display_buscar_casilla(display){
	if(display=='ocultar'){
		document.getElementById('div_casilla').style.display = 'none';
	}else{
		document.getElementById('div_casilla').style.display = '';
	} 
}

function esperar_display_buscar_casilla(display){
	string="display_buscar_casilla('"+display+"');";
	setTimeout(string,400);
}

/**************************/
function change_titulo_artefacto(accion_artefacto,id){
	if(accion_artefacto=='mostrar'){
		document.getElementById('frm_edit_titulo_'+id).style.display = '';
		document.getElementById('div_edit_titulo_'+id).style.display = 'none';
	}
	
	if(accion_artefacto=='guardar'){
		//alert(id);
		cargaDIVXML('div_edit_titulo_'+id,'','','','');
		cargaXML(BASEURL+"articulos/admin-articulos.php?edit-modelo="+id+"&modelo="+document.getElementById('frm_edit_titulo_'+id).value);
		document.getElementById('frm_edit_titulo_'+id).style.display = 'none';
		document.getElementById('div_edit_titulo_'+id).style.display = '';
	}
}


/* cargando */
var load_true=false;
function cargando(){
	if(load_true==false){
		onj_c = document.getElementById('msj_cargando');
		if(onj_c.name=='1'){
			onj_c.name = '0';
			$(document.getElementById('msj_cargando')).fadeOut(500)
			onj_c.innerHTML = '<strong>cargando...</strong>';
		}else{
			onj_c.name = '1';
			//onj_c.innerHTML = '<strong>cargando..</strong>';
			
		}
		esperar_display_buscar_casilla();
	}else{
		onj_c.style.display = '';
		onj_c.style.backgroundColor = '#72bc45';
		onj_c.innerHTML = '<strong>Listo</strong>';
		onj_c.style.width = '34px';
		$(document.getElementById('msj_cargando')).fadeOut(2500)
	}
}

function esperar_display_buscar_casilla(){
	string="cargando();";
	setTimeout(string,300);
}
/* ******** */
