/* Archivo JavaScript base
*
* Copyright 2011, AES Software
* Fechado: martes 16 de agosto del 2011.- 
*/

function estCorreo(){ 
	var usuario="ventas" 
	var dominio="videomonitoreo.com.ar" 
	var conector="@" 
	var dest = usuario + conector + dominio;	
	return dest;	
} 

function esEmail(valor) {
	if ((valor == "" || valor.indexOf('@', 0) == -1) || valor.indexOf('.') == -1) {
		return false;
	}
	else {
		return true;
	}
}

function obtfecha(modo){
var dfecha = new Date();
var monthNames = ["Enero","Febrero", "Marzo", "Abril", "Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"];
var daysNames = ["Domingo","Lunes","Martes","Miercoles","Jueves","Viernes","Sábado"];	
	switch (modo){
		case 'a':
			return dfecha.getFullYear();		
		break;
		case 'c':
			sdia = dfecha.getDate().toString();
			if (sdia.length == 1){sdia = "0" + sdia;}
			nmes = dfecha.getMonth()+1;
			smes = nmes.toString();
			if (smes.length == 1){smes = "0" + smes;}
			return sdia + '/' + smes + '/' + dfecha.getFullYear();		
		break;
		case 'l':
			sdia = dfecha.getDate().toString();
			if (sdia.length == 1){sdia = "0" + sdia;}
			return  daysNames[dfecha.getDay()] + ", " + sdia + "  de " + monthNames[dfecha.getMonth()] + " del " + dfecha.getFullYear();		
		break;
		case 'm':
			sdia = dfecha.getDate().toString();
			if (sdia.length == 1){sdia = "0" + sdia;}
			return sdia + "  de " + monthNames[dfecha.getMonth()] + " del " + dfecha.getFullYear();
		break;						
	}
}

function apliContenido(id){
	$('li.current').attr('class','');
	$('#liapl'+id).attr('class','current');
	$('#apflder').empty().html('<img src="img/aplica_0'+id+'.jpg" width="674" height="299" alt="Geovision" />' );	
	$('#apflder').removeAttr( "style" ).hide().fadeIn();
}

function cargaVideo(val){
	//$('#videocont').empty().html('<div style="height:120px;">&nbsp;</div><center><img src="img/ui/espera.gif" width="64" height="64" /></center>' );		
	switch (val){		
		case 1:
			$('#videocont').empty().html('<iframe width="572" height="349" src="http://www.youtube.com/embed/tRXffEHsMyk" frameborder="0" allowfullscreen style="background:#2d2d2d"></iframe>' );	
		break;
		case 2:
			$('#videocont').empty().html('<iframe width="572" height="349" src="http://www.youtube.com/embed/-7krWHywJ44" frameborder="0" allowfullscreen style="background:#2d2d2d"></iframe>' );			
		break;
		case 3:
			$('#videocont').empty().html('<iframe width="572" height="349" src="http://www.youtube.com/embed/A_XRjC152Vk?rel=0" frameborder="0" allowfullscreen style="background:#2d2d2d"></iframe>' );			
		break;
	}
	$('#videocont').removeAttr( "style" ).hide().slideDown(500);	
}

function iniciarSlide(){
	$('#slider').nivoSlider({
		  effect:'fade,fold,fade', // Specify sets like: 'fold,fade,sliceDown'
		  slices:15, // For slice animations
		  boxCols: 8, // For box animations
		  boxRows: 4, // For box animations
		  animSpeed:500, // Slide transition speed
		  pauseTime:8000, // How long each slide will show
		  startSlide:0, // Set starting Slide (0 index)
		  directionNav:true, // Next & Prev navigation
		  directionNavHide:true, // Only show on hover
		  controlNav:true, // 1,2,3... navigation
		  controlNavThumbs:false, // Use thumbnails for Control Nav
		  controlNavThumbsFromRel:false, // Use image rel for thumbs
		  controlNavThumbsSearch: '.jpg', // Replace this with...
		  controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
		  keyboardNav:true, // Use left & right arrows
		  pauseOnHover:true, // Stop animation while hovering
		  manualAdvance:false, // Force manual transitions
		  captionOpacity:0.8, // Universal caption opacity
		  prevText: 'Anterior', // Prev directionNav text
		  nextText: 'Siguiente', // Next directionNav text
		  beforeChange: function(){}, // Triggers before a slide transition
		  afterChange: function(){}, // Triggers after a slide transition
		  slideshowEnd: function(){}, // Triggers after all slides have been shown
		  lastSlide: function(){}, // Triggers when last slide is shown
		  afterLoad: function(){} // Triggers when slider has loaded
	});
	$('#apflder').empty().html('<img src="img/aplica_01.jpg" width="674" height="299" alt="Geovision" />' );	
	iniContacto();
};

function iniClient(){
	$('#slider').nivoSlider({
		  effect:'fade,fold,fade', // Specify sets like: 'fold,fade,sliceDown'
		  slices:15, // For slice animations
		  boxCols: 8, // For box animations
		  boxRows: 4, // For box animations
		  animSpeed:500, // Slide transition speed
		  pauseTime:5000, // How long each slide will show
		  startSlide:0, // Set starting Slide (0 index)
		  directionNav:true, // Next & Prev navigation
		  directionNavHide:true, // Only show on hover
		  controlNav:true, // 1,2,3... navigation
		  controlNavThumbs:false, // Use thumbnails for Control Nav
		  controlNavThumbsFromRel:false, // Use image rel for thumbs
		  controlNavThumbsSearch: '.jpg', // Replace this with...
		  controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
		  keyboardNav:true, // Use left & right arrows
		  pauseOnHover:true, // Stop animation while hovering
		  manualAdvance:false, // Force manual transitions
		  captionOpacity:0.8, // Universal caption opacity
		  prevText: 'Anterior', // Prev directionNav text
		  nextText: 'Siguiente', // Next directionNav text
		  beforeChange: function(){}, // Triggers before a slide transition
		  afterChange: function(){}, // Triggers after a slide transition
		  slideshowEnd: function(){}, // Triggers after all slides have been shown
		  lastSlide: function(){}, // Triggers when last slide is shown
		  afterLoad: function(){} // Triggers when slider has loaded
	});
	iniContacto();	
}

function iniProd(){
	iniContacto();
}


function envPedidoPass(){
	$('#accdes #recipient').attr('value',estCorreo());	
	$('#dialog').dialog('open');
	return false;
}

function envContacto(tipo){
	var titulo = '';
	var alto = 610;
	$('#errnombre').remove();
	$('#errpersona').remove();
	$('#erremail').remove();		
	$('#errtelefono').remove();	
	$('#errcomentario').remove();		
	switch(tipo){
		case 0:		
			titulo = 'Formulario de contacto';
			$('#lbltelefono').hide();
			$('#telefono').hide();						
			$('#lblhorario').hide();
			$('#horario').hide();									
			$('#lblcalle').hide();
			$('#calle').hide();						
			$('#lblaltura').hide();
			$('#altura').hide();			
			$('#lbllocalidad').hide();
			$('#localidad').hide();
			$('#lblprovincia').hide();			
			$('#provincia').hide();
			$('#lblcomentario').show();			
			$('#comentario').show();			
			alto = 410;			
		break;
		case 1:
			titulo = 'Formulario para solicitar asesor en seguridad';
			$('#lbltelefono').show();
			$('#telefono').show();						
			$('#lblhorario').show();
			$('#horario').show();									
			$('#lblcalle').show();
			$('#calle').show();						
			$('#lblaltura').show();
			$('#altura').show();			
			$('#lbllocalidad').show();
			$('#localidad').show();
			$('#lblprovincia').show();			
			$('#provincia').show();
			$('#lblcomentario').show();			
			$('#comentario').show();						
			alto = 610;			
		break;
		case 2:
			titulo = 'Formulario para solicitar presupuesto';
			$('#lbltelefono').show();
			$('#telefono').show();						
			$('#lblhorario').hide();
			$('#horario').hide();									
			$('#lblcalle').hide();
			$('#calle').hide();						
			$('#lblaltura').hide();
			$('#altura').hide();			
			$('#lbllocalidad').hide();
			$('#localidad').hide();
			$('#lblprovincia').hide();			
			$('#provincia').hide();
			$('#lblcomentario').hide();			
			$('#comentario').hide();						
			alto = 350;			
		break;				
	}	
	$('#contacto #recipient').attr('value',estCorreo());
	$('#contacto #subject').attr('value',titulo)	;
	$('#subject').attr('value',titulo);
	$('#contacto').dialog({height:alto, title: titulo});	
	$('#contacto').dialog('open');	
}

function iniPedidoPass(){
	$('#dialog').dialog({
		autoOpen: false,
		height: 280,
		width: 500,
		modal: true,
		title: 'Solicitud acceso a descargas',
		buttons: {
			"Enviar": function() {
			 //document.forms["accdes"].submit();
			 	if (validaForm()== true){
					$( this ).dialog( "close" );
				}
			},
			"Cancelar": function() {
				$( this ).dialog( "close" );
			}
		}
	});
	iniContacto();
}

function iniContacto(){
	$('#contacto').dialog({
		autoOpen: false,
		height: 610,
		width: 550,
		modal: true,
		title: 'Formulario de Contacto',
		buttons: {
			"Enviar": function() {
			 //document.forms["contacto"].submit();
				if (validaContacto() == true){
					$( this ).dialog( "close" );
				}
			},
			"Cancelar": function() {
				$( this ).dialog( "close" );
			}
		}
	});	
}

function validaForm(){	
	var resultado = true;
	$('#errnombredes').remove();
	$('#erremaildes').remove();	
	if ($('#accdes #nombredes').attr('value').length < 5){
		$('#accdes #nombredes').before('<span id="errnombredes" style="color:#f00">ERROR debe completar el campo</span>');
		resultado = false;
	}
	if (esEmail($('#accdes #emaildes').attr('value')) == false ){
		$('#accdes #emaildes').before('<span id="erremaildes" style="color:#f00">ERROR ingrese una direccion valida</span>');
		resultado = false;
	}		
	return resultado;
}

function validaContacto(){
	var resultado = true;
	$('#errnombre').remove();
	$('#errpersona').remove();
	$('#erremail').remove();
	$('#errtelefono').remove();
	$('#errhorario').remove();
	$('#errcalle').remove();
	$('#erraltura').remove();
	$('#errlocalidad').remove();	
	$('#errcomentario').remove();	
	if ($('#contacto #nombre').attr('value').length < 5){
		$('#contacto #nombre').before('<span id="errnombre" style="color:#f00">ERROR debe completar el campo</span>');
		resultado = false;
	}	
	if ($('#contacto #persona').attr('value').length < 5){
		$('#contacto #persona').before('<span id="errpersona" style="color:#f00">ERROR debe completar el campo</span>');
		resultado = false;
	}		
	if (esEmail($('#contacto #email').attr('value')) == false ){
		$('#contacto #email').before('<span id="erremail" style="color:#f00">ERROR ingrese una direccion valida</span>');
		resultado = false;
	}			
	switch ($('#contacto #subject').attr('value')){
		case 'Formulario de contacto':
			if ($('#contacto #comentario').attr('value').length < 10){
				$('#contacto #comentario').before('<span id="errcomentario" style="color:#f00">ERROR debe completar el campo</span>');
				resultado = false;
			}								
		break;
		case 'Formulario para solicitar asesor en seguridad':
			if ($('#contacto #telefono').attr('value').length < 5){
				$('#contacto #telefono').before('<span id="errtelefono" style="color:#f00">ERROR debe completar el campo</span>');
				resultado = false;
			}						
			if ($('#contacto #horario').attr('value').length < 5){
				$('#contacto #horario').before('<span id="errhorario" style="color:#f00">ERROR debe completar el campo</span>');
				resultado = false;
			}									
			if ($('#contacto #calle').attr('value').length < 5){
				$('#contacto #calle').before('<span id="errcalle" style="color:#f00">ERROR debe completar el campo</span>');
				resultado = false;
			}									
			if ($('#contacto #altura').attr('value').length < 1){
				$('#contacto #altura').before('<span id="erraltura" style="color:#f00">ERROR</span>');
				resultado = false;
			}
			if ($('#contacto #localidad').attr('value').length < 5){
				$('#contacto #localidad').before('<span id="errlocalidad" style="color:#f00">ERROR debe completar el campo</span>');
				resultado = false;
			}			
		break;
		case 'Formulario para solicitar presupuesto':
			if ($('#contacto #telefono').attr('value').length < 5){
				$('#contacto #telefono').before('<span id="errtelefono" style="color:#f00">ERROR debe completar el campo</span>');
				resultado = false;
			}				
		break;
	}
	return resultado;
}
