// JavaScript Document
function checkForm(id) {
        var error = false;
        $$('form#'+id+' .required').each(function(node){
			node.style.background = "#FFFFFF";
			node.style.color = "#000000";
            if (node.value == "") {
                error = true;
                node.style.background = "#F00";
				node.style.color = "#FFFFFF";
            }else{
				node.style.background = "#FFFFFF";
				node.style.color = "#000000";
			}
        });
		
        $$('form#'+id+' .email').each(function(node){
			node.style.background = "#FFFFFF";
			node.style.color = "#000000";
			var filtro = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
			if (filtro.test(node.value)){
				node.style.background = "#FFFFFF";
				node.style.color = "#000000";
			}else{
				error = true;
                node.style.background = "#F00";
				node.style.color = "#FFFFFF";
			}
			/*var punto = node.value.indexOf(".");
			var arroba = node.value.indexOf("@")
            if ((punto <= 0) || (arroba <= 0) || arroba > punto) {
                error = true;
                node.style.background = "#F00";
            }else{
				node.style.background = "#FFFFFF";
			}*/
        });
		
		$$('form#'+id+' .date').each(function(node){
			node.style.background = "#FFFFFF";
			node.style.color = "#000000";
			var Ano= node.value.substring(node.value.lastIndexOf("-")+1,node.value.length);
			var Mes= node.value.substring(node.value.indexOf("-")+1,node.value.lastIndexOf("-"));
			var Dia= node.value.substring(0,node.value.indexOf("-"));
			var chivato=1;	
            if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900){chivato=0;}
			if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12){chivato=0;}
			if (isNaN(Dia) || parseInt(Dia, 10)<1 || parseInt(Dia, 10)>31){chivato=0;}
			if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) { if (Mes==2 && Dia > 28 || Dia>30) { chivato=0}}
			if (chivato==0) {
                error = true;
                node.style.background = "#F00";
				node.style.color = "#FFFFFF";
            }else{
				node.style.background = "#FFFFFF";
				node.style.color = "#000000";
			}
        });


        $$('form#'+id+' .numeric').each(function(node){
			node.style.background = "#FFFFFF";
			node.style.color = "#000000";
            var strChars = "0123456789.-";
            for (i = 0; i < node.value.length; i++) {
                strChar = node.value.charAt(i);
                if (strChars.indexOf(strChar) == -1) {
                    error = true;
                    node.style.background = "#F00";
					node.style.color = "#FFFFFF";
				}else{
					node.style.background = "#FFFFFF";
					node.style.color = "#000000";
				}
            }
        });

        if (error == true) {
			return false;
        } else {
            $(id).submit();
        }

    }
	
function protoSend(file){
	var params = Form.serialize($('formcontacto'));
	new Ajax.Updater('formcontacto', file, {asynchronous:true, parameters:params});
}

function abrirSB(player,title,content){
	/*Shadowbox.open({
		content:    	content,
		player:     	player,
		//title:      	title,
		height:			440,
		width:			700
	});*/
	lightwindowInit();
	myLightWindow.activateWindow({
		href: 	content, 
		title:	title,
		height:	480,
		width:	740
	});
}

function shbox(player,title,content,height,width){
	/*Shadowbox.open({
		content:    	content,
		player:     	player,
		title:      	title,
		height:			height,
		width:			width
	});*/
	lightwindowInit();
	myLightWindow.activateWindow({
		href: 	content, 
		title:	title,
		height:	height,
		width:	width
	});
}

function show_map(lat,lon,texto){
	html = '';
	html = html + '<script type="text/javascript">'
	html = html + 'if (GBrowserIsCompatible()) {';
    html = html + 'var map = new GMap2(document.getElementById("googlemaps"));';
	html = html + 'map.addControl(new GLargeMapControl());';
	html = html + 'map.addControl(new GMapTypeControl());';
	html = html + 'map.setCenter(new GLatLng('+lat+','+lon+'), 16);';
	html = html + 'var point = new GLatLng('+lat+','+lon+');';
	html = html + 'var marker = new GMarker(point);';
	html = html + 'GEvent.addListener(marker, "click", function() {';
    html = html + '  marker.openInfoWindowHtml("'+texto+'");';
    html = html + '});';
	html = html + 'map.addOverlay(marker);';
	html = html + 'map.openInfoWindowHtml(point,"'+texto+'");';
	html = html + '}';
	html = html + '</script>';
	return html;	
}

function pluggin_test(){
	//********cambiar los siguientes datos*************
	/*flashpage = "flash.htm"
	upgradepage = "plugin-flash.htm"
	nonflashpage = "html.htm"
	cantdetectpage = "no-se-pudo-detectar-plugin.html"*/
	//**************************************************
	noautoinstall = ""
	var flash = false;
	if(navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion.indexOf("Mac") != -1 // navigator.appVersion.indexOf("3.1") != -1
	)){
		noautoinstall = "true";
	}
	if (navigator.appName == "Microsoft Internet Explorer" && noautoinstall != "true"){
		//window.location=flashpage;
		flash = true;
	}
	else if(navigator.plugins){
		if(navigator.plugins["Shockwave Flash"]){
			//window.location=flashpage;
			flash = true;
		}else if(navigator.plugins["Shockwave Flash 2.0"]){
			//window.location=upgradepage;
			flash = true;
		}else{
			//window.location=nonflashpage;
			flash = false;
		}
	}
	else {
		//window.location=cantdetectpage;
		flash = false;
	}
	return flash;
}