/******************************************************/
/*** LIBRERIA DE FUNCIONES COMUNES DEL SITIO NORDIK ***/
/******************************************************/
function Show(pagina, tab){ //v1.0
	eval("parent.location='"+pagina+".php?tab="+tab+"'");
	//eval("parent.location='"+pagina+".php'");
}

function ShowFamilia(tab, familia, imagen){ //v2.0
	eval("parent.location='listado_familia.php?tab="+tab+"&familia="+familia+"&imagen="+imagen+"'");
	//eval("parent.location='"+pagina+".php'");
}

function ShowListado(tab, familia, padre, banner){ //v1.0
	eval("parent.location='listado.php?tab="+tab+"&familia="+familia+"&padre="+padre+"&banner="+banner+"'");
	//eval("parent.location='"+pagina+".php'");
}

function ShowProducto(tab, familia, padre, hijo, banner){ //v1.0
	eval("parent.location='productos.php?tab="+tab+"&familia="+familia+"&padre="+padre+"&hijo="+hijo+"&banner="+banner+"'");
	//eval("parent.location='"+pagina+".php'");
}

function ShowTiendas(tab){ //v1.0
	eval("parent.location='listado_tiendas.php?tab="+tab+"'");
	//eval("parent.location='"+pagina+".php'");
}

function ShowTienda(tab,tienda){ //v1.0
	eval("parent.location='tienda.php?tab="+tab+"&tienda="+tienda+"'");
	//eval("parent.location='"+pagina+".php'");
}


function ShowProduct(codigo, menu){ //v1.0
	//eval("parent.location='"+pagina+".php?menu="+menu+"'");
	eval("parent.location='productos.php?id="+codigo+"&menu="+menu+"'");
}

function contactar_tienda(tienda) { 
  	// Codigo basico para impedir el spam en correos electrónicos 
  	dominio  = 'nordik.cl';
	if (tienda == 1) {     
  		direccion = 'acordova'; 
		nombre    = 'Nordik Alonso de Cordova';
	} else if (tienda == 2){
  		direccion = 'tienda.ladehesa'; 
		nombre    = 'Nordik La Dehesa';
	} else if (tienda == 3){
  		direccion = 'tienda.vespucio';
		nombre    = 'Nordik Quilicura';
	} else if (tienda == 4){
  		direccion = 'tienda.vina'; 
		nombre    = 'Nordik Vi&ntilde;a del Mar';
	} else if (tienda == 5){
  		direccion = 'tienda.velasquez'; 
		nombre    = 'Nordik General Velasquez';
	} else if (tienda == 6){
  		direccion = 'outlett.vespucio'; 
		nombre    = 'Outlett Nordik Vespusio';
	} else if (tienda == 7){
  		direccion = 'ventas.institucionales'; 
		nombre    = 'Ventas Institucionales';
	}
   
  //window.location = 'mailto:'+direccion+'@'+dominio+'?subject=Solicitud de Informacion desde web.'; 
  window.open('formulario.php?mail='+direccion+'@'+dominio+'&nombre='+nombre, 'formulario', 'width=400,height=250,Scrollbars=No,resizable=NO,Location=No,Toolbar=No,Menubar=No,Directories=No,Status=No'); 
   
}  


//************************
//
//    AJAX Y FUNCIONES
//       JAVASCRIPT
//
//  Generadas por C.Haack
//    ragamo@gmail.com
//
//************************

//************************
//    AJAX: OBJETO
//************************
function ajaxobj() {
	try {
		_ajaxobj = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			_ajaxobj = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			_ajaxobj = false;
		}
	}

	if (!_ajaxobj && typeof XMLHttpRequest!='undefined') {
		_ajaxobj = new XMLHttpRequest();
	}

	return _ajaxobj;
}

function sinc(url, id, div) {
	ajax = ajaxobj();
	ajax.open("GET", "inc/"+url+".php?id="+id, true);

	ajax.onreadystatechange = function() {
		switch(ajax.readyState) {
			case 1: 
				document.getElementById(div).innerHTML = "<table border=0><tr><td><img src=img/ajax-loader.gif></td><td>Cargando...</td></tr></table>";
				break;
				
			case 4: 
				document.getElementById(div).innerHTML = ajax.responseText;
				break;
		}
	}
	ajax.send(null);
}

function img(id, campo, div) {
	ajax = ajaxobj();
	ajax.open("GET", "inc/detalleImg.php?id="+id+"&campo="+campo, true);

	ajax.onreadystatechange = function() {
		switch(ajax.readyState) {
			case 1: 
				document.getElementById(div).innerHTML = "<table border=0><tr><td><img src=img/ajax-loader.gif></td><td>Cargando...</td></tr></table>";
				break;
				
			case 4: 
				document.getElementById(div).innerHTML = ajax.responseText;
				break;
		}
	}
	ajax.send(null);
}

//************************
//    AJAX: BUSCADOR
//************************
function buscar(palabra) {
	ajax = ajaxobj();
	ajax.open("GET", "./include/miniResults.php?q="+palabra, true);

	ajax.onreadystatechange = function() {
		switch(ajax.readyState) {
			case 1: 
				document.getElementById('results').innerHTML = "<table border=0><tr><td><img src=img/ajax-loader.gif></td><td>Cargando...</td></tr></table>";
				break;
				
			case 4: 
				document.getElementById('results').innerHTML = ajax.responseText;
				break;
		}
	}
	ajax.send(null);
}

function onSearch(e) {
	var query = document.getElementById('query');
	var result = document.getElementById('resultContainer');
		
	intKey = e.keyCode;
	if(intKey == 8) { //13 = enter
		if(query.value.length > 2) {
			result.style.display = '';
			buscar(query.value);
			
		} else {
			result.style.display = 'none';
		}
	}
	
	if(query.value.length > 2) {
		result.style.display = '';
		buscar(query.value);
	}
}

//************************
//  BUSCADOR: RESULTADOS
//************************
function cerrar() {
	document.getElementById('resultContainer').style.display = 'none';
}

function setFocus() {
	document.getElementById('query').focus();
}






function Show_Detail(id_producto){
	eval("parent.location='detalle_movie.php?id_producto="+id_producto+"'");
}

function makevisible(cur,which) {
	strength=(which==0)? 1 : 0.6
	if (cur.style.MozOpacity)
		cur.style.MozOpacity=strength
	else if (cur.filters)
		cur.filters.alpha.opacity=strength*100
}

function MostrarCategoria(tipo, titulo, categoria, caption){ //v3.0
	eval("parent.location='listar_categoria.php?tipo="+tipo+"&titulo="+titulo+"&cat="+categoria+"&caption="+caption+"'");	
}


function Usuario(pagina){ //v3.0
	eval("parent.location='"+pagina+".php'");	
}

function BuscarCriterio(tipo){ //v3.0
	criterio = busqueda.query.value;
	eval("parent.location='buscar_criterio.php?criterio="+criterio+"'");	
}

function Show_Requisitos(){
	var win = window.open('requisitos.php','_blank','height=700,width=400, resizable=no, scrollbars=no, status=no, titlebar=no');	
}

function Show_Valores(){
	var win = window.open('valores.php','_blank','height=380,width=400, resizable=no, scrollbars=no, status=no, titlebar=no');	
}

function Show_Locales(){
	var win = window.open('locales.php','_blank','height=225,width=400, resizable=no, scrollbars=no, status=no, titlebar=no');	
}

function Show_Mapa(){
	var win = window.open('area_cobertura.php','_blank','height=650,width=550, resizable=no, scrollbars=no, status=no, titlebar=no');	
}

function validar(formulario) {
	//Validar que los campos no esten en blanco
	if (formulario.username.value.length==0) {
		alert("No puede dejar el campo Username en blanco. Ingrese un valor.");
		formulario.username.focus();
		return;
	}
	if (formulario.password.value.length==0) {
		alert("No puede dejar el campo Password en blanco. Ingrese un valor.");
		formulario.password.focus();
		return;
	}
	formulario.submit();
}


