/*********************************************************************************************
  Función valida:
	función para validar formularios. Unicamente a los "id" de el fomulario hay que 
	inicializarlos cun un guion bajo "_".
  Parámetros:
	form = Nombre del "id" del formulario a validar.
*********************************************************************************************/
function valida(form){
	for(x = 0; x < document.getElementById(form).elements.length; x++){
		temp=document.getElementById(form).elements[x].id;
		temp2=temp.indexOf("_");
		if( trim(document.getElementById(form).elements[x].value) == "" && document.getElementById(form).elements[x].type != "submit" && temp2 == 0){
			nombre = document.getElementById(form).elements[x].id.replace("_","");
			alert("El campo "+nombre+" esta vacio");
			document.getElementById(form).elements[x].focus();
			return false;
		}
	}
	
	return true;
} // Termina function valida()


/*********************************************************************************************
  Función trim:
	función para quitar los espacios iniciales y finales de una cadena
  Parámetros:
	cadena = String o Cadena a validar.
*********************************************************************************************/
function trim(cadena){
	for(i=0; i<cadena.length; i++){
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(i+1, cadena.length);
		else
			break;
	}

	for(i=cadena.length-1; i>=0; i=cadena.length-1){
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(0,i);
		else
			break;
	}
	
	return cadena;
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Email invalido")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Email invalido")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Email invalido")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Email invalido")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Email invalido")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Email invalido")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Email invalido")
		    return false
		 }

 		 return true					
	}




/************************************************
	Funciones para el Home
*************************************************/
function hiddenDiv(element) {
	var myFx = new Fx.Tween(element);
	myFx.start('opacity', 0);
}

function appearDiv(element){
	var myFx = new Fx.Tween(element);
	myFx.start('opacity', 0, 1);
}

function initHome() {
	hiddenDiv("advance");
	hiddenDiv("lemans");
	hiddenDiv("homeNews");
	hiddenDiv("homeLiving");
}


/************************************************
	Funciones para el submenu de tl
*************************************************/
var interval = 0; // intervalo de tiempo

function showMenuTl(){
	clearInterval(interval);
	interval = setInterval(function(){
		var myFx = new Fx.Tween('tl_submenu');
		myFx.start('opacity', 1);
	}, 300);
	
	obj = document.getElementById('tl_submenu');
	element = document.getElementById('botonesModelos');
	obj.style.left = findPosX(element) + 480 + "px";
	obj.style.top = findPosY(element) + 55 + "px";
}

function hideMenuTl() {
	clearInterval(interval);
	interval = setInterval(function(){
		var myFx = new Fx.Tween('tl_submenu');
		myFx.start('opacity', 0);
	}, 500);
}

function deleteMenuInterval(){
	clearInterval(interval);
}

function posicionaVideo(){
	ancho = document.documentElement.innerWidth;
	alto = document.documentElement.innerHeight;
	document.getElementById('flashVideo').style.left = (ancho / 2) + "px";
	document.getElementById('flashVideo').style.top = (alto / 2) + "px";
	document.getElementById('flashVideo').style.width = ancho + "px";
	document.getElementById('flashVideo').style.height = alto + "px";
}
	


// Find positions
function findPosX(obj){
	var curleft = 0;

	if(obj.offsetParent)
		while(1){
        	curleft += obj.offsetLeft;
          
			if(!obj.offsetParent)
            	break;
          	
			obj = obj.offsetParent;
        }
    else if(obj.x)
    	curleft += obj.x;
    
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
    
	if(obj.offsetParent)
    	while(1){
        	curtop += obj.offsetTop;
          
		  	if(!obj.offsetParent)
            	break;
          	
			obj = obj.offsetParent;
        }
    else if(obj.y)
    	curtop += obj.y;
    
	return curtop;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


/**********************
	quitar el video
***********************/

function removeVideo(){
	var d = document.getElementById("flashVideo"); 
	var d_nested = document.getElementById("video"); 
	var throwawayNode = d.removeChild(d_nested);
	d.style.display = "none"; 
}