﻿function init(){
	google.load('maps', '2');
    var map = undefined;
}	
function get_ajax(url){
	$('box_download').style.display = 'none';
	var req = new Request.HTML({
	method :'get',
	url:url,
	onRequest: function(){
		$('box_response').innerHTML = '<div class="limpiar" style="height:40px;"></div><img src="img/_loader.gif" style="display:block; margin:auto; width:32px; height:32px;" />';
	},
	onSuccess: function(html,xml,txt) {
		$('box_response').empty();				
		$('box_response').innerHTML = txt;
	},
	onFailure: function() {
		$('box_response').empty();
		$('box_response').innerHTML = 'Fallo la peticion ...';	
	}
							});
	return req;
}
function get_ajax_ubication(url,valor){
	$('box_download').style.display = 'none';
	var req = new Request.HTML({
	method :'get',
	url:url,
	onRequest: function(){
		$('box_response').innerHTML = '<div class="limpiar" style="height:40px;"></div><img src="img/_loader.gif" style="display:block; margin:auto; width:32px; height:32px;" />';
	},
	onSuccess: function(html,xml,txt) {
		$('box_response').empty();				
		$('box_response').innerHTML = txt;			
		init_map(valor);
	},
	onFailure: function() {
		$('box_response').empty();
		$('box_response').innerHTML = 'Fallo la peticion ...';	
	}
							});
	return req;
}
function get_ajax_gallery(url){
	$('box_download').style.display = 'none';
	var req = new Request.HTML({
	method :'get',
	url:url,
	onRequest: function(){
		$('box_response').innerHTML = '<div class="limpiar" style="height:40px;"></div><img src="img/_loader.gif" style="display:block; margin:auto; width:32px; height:32px;" />';
	},
	onSuccess: function(html,xml,txt) {
		$('box_response').empty();				
		$('box_response').innerHTML = txt;			
		init_gallery('box_gallery');
	},
	onFailure: function() {
		$('box_response').empty();
		$('box_response').innerHTML = 'Fallo la peticion ...';	
	}
							});
	return req;
}
function init_map(valor){
	if (!GBrowserIsCompatible())
		return;
	map = new GMap2($('box_map'));
	var customUI = map.getDefaultUI();
	customUI.maptypes.hybrid = false;
    customUI.maptypes.physical = false;			 
    map.setUI(customUI);
	put_marker(valor);
}
function put_marker(valor){
	var marker1 = new GMarker(new GLatLng(19.399872,-99.169014));
	var _html1 = '<p class="map_text"><b>Van-Tec México</b><br />San Francisco No. 2 Desp.203, Col Del Valle Del Benito Ju&aacute;rez<br />CP 03100, M&eacute;xico, D.F.<br />';
	_html1 += 'Tel&eacute;fonos: <b>5543-5651, 5523-9138, 5523-9031</b><br />Fax: <b>5523-8163</b><br />';
	_html1 += 'Informaci&oacute;n: <a href="javascript:mail_to(\'Información\',\'ldiaz@van-tec.com.mx\')">ldiaz@van-tec.com.mx</a>,<a href="javascript:mail_to(\'Información\',\'jdiaz@van-tec.com.mx\')">jdiaz@van-tec.com.mx</a><br />';
	_html1 += 'Soporte: <a href="javascript:mail_to(\'Soporte México\',\'support@van-tec.com.mx\')">support@van-tec.com.mx</a><br />';
	_html1 += 'Ventas: <a href="javascript:mail_to(\'Ventas México\',\'ventas@van-tec.com.mx\')">ventas@van-tec.com.mx</a><br />';
    map.addOverlay(marker1);
    GEvent.addListener(marker1, "click", function(){
    	marker1.openInfoWindow(_html1);
    });
	if(valor == 1){
		map.setCenter(new GLatLng(19.399872,-99.169014), 14);
    	marker1.openInfoWindow(_html1);
	}
	var marker2 = new GMarker(new GLatLng(19.050894,-98.216135));
	var _html2 = '<p class="map_text"><b>Van-Tec Puebla</b><br />23 Sur  No.506-208, Col La Paz <br />CP 72160, Puebla, Puebla<br />';
	_html2 += 'Tel&eacute;fonos: <b>01 222 2314060,01 222 2495196</b><br />';
	_html2 += 'Contacto: <a href="javascript:mail_to(\'Contacto Puebla\',\'puebla@van-tec.com.mx\')">puebla@van-tec.com.mx</a><br />';
    map.addOverlay(marker2);
    GEvent.addListener(marker2, "click", function(){
    	marker2.openInfoWindow(_html2);
    });
	if(valor == 2){
		map.setCenter(new GLatLng(19.050894,-98.216135), 14);
    	marker2.openInfoWindow(_html2);
	}
	var marker3 = new GMarker(new GLatLng(20.674166,-103.368875));
	var _html3 = '<p class="map_text"><b>Van-Tec Guadalajara</b><br />Av. Chapultepec Sur No. 140-107, Col Americana<br />CP 44160, Guadalajara, Jalisco<br />';
	_html3 += 'Tel&eacute;fonos: <b>01 333 6153090, 01 333 36152006</b><br />';
	_html3 += 'Contacto: <a href="javascript:mail_to(\'Contacto Guadalajara\',\'jalisco@van-tec.com.mx\')">jalisco@van-tec.com.mx</a><br />';
    map.addOverlay(marker3);
    GEvent.addListener(marker3, "click", function(){
    	marker3.openInfoWindow(_html3);
    });
	if(valor == 3){
		map.setCenter(new GLatLng(20.674166,-103.368875), 14);
    	marker3.openInfoWindow(_html3);
	}
	var marker4 = new GMarker(new GLatLng(19.190176,-96.129642));
	var _html4 = '<p class="map_text"><b>Van-Tec Veracruz</b><br />Av. 1° de Mayo  No. 866, Col Flores Magón<br />CP 91900, Veracruz, Veracruz<br />';
	_html4 += 'Tel&eacute;fono: <b>01 229 9321905</b><br />';
	_html4 += 'Contacto: <a href="javascript:mail_to(\'Contacto Veracruz\',\'veracruz@van-tec.com.mx\')">veracruz@van-tec.com.mx</a><br />';
    map.addOverlay(marker4);
    GEvent.addListener(marker4, "click", function(){
    	marker4.openInfoWindow(_html4);
    });
	if(valor == 4){
		map.setCenter(new GLatLng(19.190176,-96.129642), 14);
    	marker4.openInfoWindow(_html4);
	}
}
function get_center_map(valor){
	$('box_download').style.display = 'none';
	if(map == undefined){
		put_menu('mnu_4');
		var _url = 'pag/contacto.html';
		get_ajax_ubication(_url,valor).send();
	}
	else{
		map.clearOverlays();
		if(valor == 1){
			map.setCenter(new GLatLng(19.399872,-99.169014), 14);
		}
		else if(valor == 2){
			map.setCenter(new GLatLng(19.050894,-98.216135), 14);
		}
		else if(valor == 3){
			map.setCenter(new GLatLng(20.674166,-103.368875), 14);
		}
		else if(valor == 4){
			map.setCenter(new GLatLng(19.190176,-96.129642), 14);
		}
		put_marker(valor);		
	}
}
function init_vidio(){
	Mediabox.scanPage();
}
function init_gallery(id_cnt){
		var mf = new MooFlow($(id_cnt), {
			useSlider: false,
			useCaption: true,
			useAutoPlay: false,
			useResize: false,
    		useWindowResize: true,			
			useMouseWheel: true,
			useKeyInput: true,
			useViewer: true,
 
			onClickView: function(obj){				
				var img = new Element('img',{src:obj.src, title:obj.title, alt:obj.alt, styles:obj.coords}).setStyles({'position':'absolute','border':'none'});
				var link = new Element('a',{'class':'remooz-element','href':obj.href,'title':obj.title, styles:{'border':'none'}});
				$(document.body).adopt(link.adopt(img));
				var remooz = new ReMooz(link, {
		            centered: false,
					resizeFactor: 0.8,
		            origin: link.getElement('img'),
					onCloseEnd: function(){link.destroy()}
		        });
				remooz.open();				
			}
		});
}
function put_ajax(url){
	var req = new Request.HTML({
	method :'post',
	url:url,
	onRequest: function(){
		$('vt_f_msj').innerHTML = '<div class="limpiar" style="height:5px;"></div><img src="img/_loader.gif" style="display:block; margin:auto; width:32px; height:32px;" />';
	},
	onSuccess: function(html,xml,txt) {
		$('vt_f_msj').empty();
		var val_txt = txt.split('$');
		$('vt_f_msj').innerHTML = val_txt[1];
	},
	onFailure: function() {
		$('vt_f_msj').empty();
		$('vt_f_msj').innerHTML = "<p class='status_envio mal_envio'>Error de envío.</p>";	
	}
							});
	return req;
}
function mail_to(titulo,valor){
	$('box_download').style.display = 'none';
	map = undefined;
	$('box_response').empty();
	get_normal_mnu();
	var _title = titulo + ' &lt; ' + valor + ' &gt;';
	var _html = '';
	_html += '<h1>Envíanos un e-mail</h1><p class="txt" style="text-align:right;font-style:italic;"><b>' + _title + '</b></p>';
	_html += '<div class="limpiar" style="height:20px;"></div><div class="entrada_box"><div class="limpiar" style="height:10px;"></div>	<div class="box_dato"><label class="label" >Nombre:</label><input id="fm_name" value="" class="textbox textbox_user" /></div><div class="limpiar"></div><div class="box_dato"><label class="label" >E-mail:</label><input id="fm_email" value="" class="textbox textbox_email" /></div><div class="limpiar"></div><div class="box_dato"><label class="label" >Asunto:</label><input id="fm_asunto" value="" class="textbox textbox_asunto" /></div><div class="limpiar"></div><div class="box_dato"><label class="label" >Mensaje:</label><textarea id="fm_msj" class="textbox textbox_text" style="height:100px; font-size:14px;" ></textarea> <input type="hidden" id="f_to" value="' + valor + '" /> </div><div class="limpiar"></div><div id="box_fm_loading" class="btn_cuadrado"></div><div id="btn_send" class="btn_cuadrado btn_cuadrado_send" onclick="put_fm_send()"><p>Enviar</p></div><div id="vt_f_msj" class="btn_cuadrado" style="width:350px;"></div><div class="limpiar" style="height:10px;"></div></div>';
	$('box_response').innerHTML = _html;
}
function get_validacion(){
	var _return = true;
	var fm1 = $('fm_name').value;
	var fm2 = $('fm_email').value;
	var fm3 = $('fm_asunto').value;
	var fm4 = $('fm_msj').value;
	$('fm_name').removeClass('error');
	$('fm_email').removeClass('error');
	$('fm_asunto').removeClass('error');
	$('fm_msj').removeClass('error');
	if(fm1 == ''){
		$('fm_name').addClass('error');
		_return = false;
	}
	if(fm2 == ''){
		$('fm_email').addClass('error');
		_return = false;
	}
	else{
		var aux = fm2.split('@');
		if(aux.length != 2){
			$('fm_email').addClass('error');
			_return = false;
		}
	}
	if(fm3 == ''){
		$('fm_asunto').addClass('error');
		_return = false;
	}
	if(fm4 == ''){
		$('fm_msj').addClass('error');
		_return = false;
	}
	return _return;
}
function put_fm_send(){
	if(get_validacion()){
		var _fm_name = $('fm_name').value;
		var _fm_email = $('fm_email').value;
		var _fm_asunto = $('fm_asunto').value;
		var _fm_msj = $('fm_msj').value;
		var _f_to = $('f_to').value;
		var _url = 'pag/send.php?name='+_fm_name+'&email='+_fm_email+'&asunto='+_fm_asunto+'&msj='+_fm_msj+'&to='+_f_to;
		put_ajax(_url).send();
	}
}
function get_parametro(variable){
	var direccion = location.href;
	var posicion = direccion.indexOf("?");
	posicion = direccion.indexOf(variable,posicion) + variable.length;
	if (direccion.charAt(posicion) == "="){
		var final = direccion.indexOf("&",posicion);
		if (final == -1){
			final=direccion.length;
		}
		return direccion.substring(posicion + 1,final);
	}
}
function decode_url(txt){
	var str = txt.replace('%*','%');
	str = unescape(str);
	return str;
}
/*---------------------------------------------------------------------------------*/
function init_d(){
	google.load('maps', '2');
    var map = undefined;
	m__ = get_parametro('m');
	p__ = get_parametro('p');
	v__ = get_parametro('v');
	put_menu('mnu_'+m__.toString());
	get_ajax_gallery_opc('pag/productos/producto'+p__.toString()+'.html').send();

}
function get_ajax_gallery_opc(url){
	$('box_download').style.display = 'none';
	var req = new Request.HTML({
	method :'get',
	url:url,
	onRequest: function(){
		$('box_response').innerHTML = '<div class="limpiar" style="height:40px;"></div><img src="img/_loader.gif" style="display:block; margin:auto; width:32px; height:32px;" />';
	},
	onSuccess: function(html,xml,txt) {
		$('box_response').empty();				
		$('box_response').innerHTML = txt;			
		init_gallery('box_gallery');
	},
	onFailure: function() {
		$('box_response').empty();
		$('box_response').innerHTML = 'Fallo la peticion ...';	
	}
							});
	return req;
}