/******************************************************************************
*	Retorna la fecha pasada en formato DD/MM/AAAA en milisegundos
*******************************************************************************/

function obtener_milisegundos(fecha){
	var dia1 = parseInt(fecha.substr(0,2))
	if (dia1 == 0) dia1 = parseInt(fecha.substr(1,1))
	mes1 = parseInt(fecha.substr(3,2))-1
	if (mes1 == -1) mes1 = parseInt(fecha.substr(4,1))-1
	ano1 = parseInt(fecha.substr(6,4))
	f = new Date(ano1,mes1,dia1)
	return Date.parse(f)
}

// CSS Browser Selector   v0.2.3
// Documentation:         http://rafael.adm.br/css_browser_selector
// License:               http://creativecommons.org/licenses/by/2.5/
// Author:                Rafael Lima (http://rafael.adm.br)
// Contributors:          http://rafael.adm.br/css_browser_selector#contributors
var css_browser_selector = function() {
	var
		ua = navigator.userAgent.toLowerCase(),
		is = function(t){ return ua.indexOf(t) != -1; },
		h = document.getElementsByTagName('html')[0],
		b = (!(/opera|webtv/i.test(ua)) && /msie (\d)/.test(ua)) ? ((is('mac') ? 'ieMac ' : '') + 'ie ie' + RegExp.$1)
			: is('gecko/') ? 'gecko' : is('opera') ? 'opera' : is('konqueror') ? 'konqueror' : is('applewebkit/') ? 'webkit safari' : is('mozilla/') ? 'gecko' : '',
		os = (is('x11') || is('linux')) ? ' linux' : is('mac') ? ' mac' : is('win') ? ' win' : '';
	var c = b+os+' js';
	h.className += h.className?' '+c:c;
}();


function nuevoAjax(){
	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;
}

// function HIT
function h(page){
	var str_post= 'appName='+navigator.appName+'&appVersion='+navigator.appVersion+'&platform='+navigator.platform+'&page='+page
	var ajax=nuevoAjax();
	ajax.open("POST", "ajaxActions/hit.php",true);
	ajax.onreadystatechange=function() { }
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(str_post);
	delete ajax;
}

// limita el ingreso de solo números a las cajas de texto
function numeros(tecla){
	if(typeof(tecla) == 'undefined')
	var tecla = window.event;
	var codigo = (tecla.which ? tecla.which : tecla.keyCode ? tecla.keyCode : tecla.charCode);
	// permite números, 8=backspace, 46=del e 9=tab
	if ( (codigo >= 48 && codigo <= 57) || (codigo >= 96 && codigo <= 105) || codigo == 8 || codigo == 46 || codigo == 9 ){
		return true
	}
	else {
		return false;
	}
}

function open_image(type,id,num){
	window.open("/ajaxActions/imagenes.php?type="+type+"&id="+id+"&numero="+num+"&t=large","ver", "height=250,width=250,status=yes,toolbar=no,menubar=no,location=no,left=50,top=50,scrollbars=yes");
}

function subscribe(email){
	document.getElementById('body').style.cursor = 'wait'
	var str_post= "email="+email
	var ajax=nuevoAjax();
	ajax.open("POST", "ajaxActions/subscribe.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			document.getElementById('body').style.cursor = ''
			document.getElementById('email_news').value = ''
			alert("El email ha sido subscripto al newsletter, gracias por utilizar nuestros servicios.")
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(str_post);
	delete ajax;
}

function validaNews(){
	email = document.getElementById('email_news').value
	if (email == ''){
		document.getElementById('email_news').focus()
	}
	else {
		if (email != ""){
			var regex = /^\w(?:\w|-|\.(?!\.|\@))*\@\w(?:\w|-|\.(?!\.))*\.\w{2,3}/
			if(!regex.test(email)){
				alert("El email ingresado no posee un formato correcto.")
				document.getElementById('email_news').focus()
			}
			else
				subscribe(email)
		}
	}
}
