var habilitaForm = true;
var smPicado = null;
var winName = "ventana";
var win = null;

$( document ).ready
(
	function()
	{
		if( navigator.appName == "Microsoft Internet Explorer" && parseFloat( navigator.appVersion.split( "MSIE" )[ 1 ] ) < 8 )
		{
			$( '#avisoIE' ).html( "<img src=\"img/error.png\" > Est&aacute; utilizando una versi&oacute;n obsoleta de Internet Explorer, de manera que algunos elementos de esta p&aacute;gina no se ver&aacute;n correctamente. Actual&iacute;cese gratu&iacute;tamente desde <a href=\"http://www.microsoft.com/spain/windows/internet-explorer/\" target=\"_blank\" style=\"color: #333\" >aqu&iacute;</a>." );
			$( '#avisoIE' ).addClass( "avisoJS" );
		}
	}
);

function AbreN( theURL, ancho, alto )
{
    var h = ( screen.width - ancho ) / 2;
    var v = ( screen.height - alto ) / 2;
    var windowprops = "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=" + ancho + ",height=" + alto + ",left=" + h + ",top=" + v;
    
    if( win )
    {
        win.close();
    }
    
    win = window.open( theURL, winName, windowprops );
}

function CmpFormPresupuesto( idioma )
{
	if( habilitaForm )
	{
		var seguir = true;
		
		if( document.getElementById( 'empresa' ).value.length < 2 )
		{
			seguir = false;
			
			switch( idioma )
			{
				case 'en':
					alert( 'Enter your company name.' );
				break;
				default:
					alert( 'Introduzca el nombre de su empresa.' );
				break;
			}
		}
		
		if( seguir && document.getElementById( 'nifCif' ).value.length < 8 )
		{
			seguir = false;
			
			switch( idioma )
			{
				case 'en':
					alert( 'Enter your NIF/CIF.' );
				break;
				default:
					alert( 'Introduzca su NIF/CIF.' );
				break;
			}
		}
		
		if( seguir && document.getElementById( 'nombre' ).value.length < 2 )
		{
			seguir = false;
			
			switch( idioma )
			{
				case 'en':
					alert( 'Enter your name.' );
				break;
				default:
					alert( 'Introduzca su nombre.' );
				break;
			}
		}
		
		if( seguir && document.getElementById( 'apellidos' ).value.length < 2 )
		{
			seguir = false;
			
			switch( idioma )
			{
				case 'en':
					alert( 'Enter your surname.' );
				break;
				default:
					alert( 'Introduzca sus apellidos.' );
				break;
			}
		}
		
		if( seguir && document.getElementById( 'cp' ).value.length < 5 )
		{
			seguir = false;
			
			switch( idioma )
			{
				case 'en':
					alert( 'Enter your post code.' );
				break;
				default:
					alert( 'Introduzca su código postal.' );
				break;
			}
		}
		
		if( seguir && document.getElementById( 'poblacion' ).value.length < 2 )
		{
			seguir = false;
			
			switch( idioma )
			{
				case 'en':
					alert( 'Enter your city.' );
				break;
				default:
					alert( 'Introduzca su población.' );
				break;
			}
		}
		
		if( seguir && document.getElementById( 'provincia' ).value.length < 2 )
		{
			seguir = false;
			
			switch( idioma )
			{
				case 'en':
					alert( 'Enter your province.' );
				break;
				default:
					alert( 'Introduzca su provincia.' );
				break;
			}
		}
		
		if( seguir && document.getElementById( 'pais' ).value.length < 2 )
		{
			seguir = false;
			
			switch( idioma )
			{
				case 'en':
					alert( 'Enter your country.' );
				break;
				default:
					alert( 'Introduzca su país.' );
				break;
			}
		}
		
		if( seguir && document.getElementById( 'email' ).value.length < 2 )
		{
			seguir = false;
			
			switch( idioma )
			{
				case 'en':
					alert( 'Enter your e-mail.' );
				break;
				default:
					alert( 'Introduzca su e-mail.' );
				break;
			}
		}
		
		if( seguir && ( document.getElementById( 'email' ).value.length <  8 || document.getElementById( 'email' ).value.indexOf('@',0)==-1 || document.getElementById( 'email' ).value.indexOf('@',0)==0 || document.getElementById( 'email' ).value.indexOf('.',0)==-1 || document.getElementById( 'email' ).value.indexOf('.',0)==0 ) )
		{
			seguir = false;
			
			switch( idioma )
			{
				case 'en':
					alert( 'Enter a valid e-mail.' );
				break;
				default:
					alert( 'Introduzca un e-mail válido.' );
				break;
			}
		}
		
		if( seguir && document.getElementById( 'telefono' ).value.length < 2 )
		{
			seguir = false;
			
			switch( idioma )
			{
				case 'en':
					alert( 'Enter your phone number.' );
				break;
				default:
					alert( 'Introduzca su teléfono.' );
				break;
			}
		}
		
		if( seguir && document.getElementById( 'dirEnvio' ).value.length < 2 )
		{
			seguir = false;
			
			switch( idioma )
			{
				case 'en':
					alert( 'Enter the address of the work or delivery.' );
				break;
				default:
					alert( 'Introduzca la dirección de la obra o de envío.' );
				break;
			}
		}
		
		if( seguir && document.getElementById( 'seguridad' ).value.length < 2 )
		{
			seguir = false;
			
			switch( idioma )
			{
				case 'en':
					alert( 'Enter security code.' );
				break;
				default:
					alert( 'Introduzca el código de seguridad.' );
				break;
			}
		}
		
		if( seguir )
		{
			document.getElementById( 'empresa' ).style.color = "#999999";
			document.getElementById( 'nifCif' ).style.color = "#999999";
			document.getElementById( 'nombre' ).style.color = "#999999";
			document.getElementById( 'apellidos' ).style.color = "#999999";
			document.getElementById( 'cp' ).style.color = "#999999";
			document.getElementById( 'poblacion' ).style.color = "#999999";
			document.getElementById( 'provincia' ).style.color = "#999999";
			document.getElementById( 'pais' ).style.color = "#999999";
			document.getElementById( 'email' ).style.color = "#999999";
			document.getElementById( 'telefono' ).style.color = "#999999";
			document.getElementById( 'dirEnvio' ).style.color = "#999999";
			document.getElementById( 'consulta' ).style.color = "#999999";
			document.getElementById( 'seguridad' ).style.color = "#999999";
			
			document.forms[ 'contacto' ].submit();
			
			habilitaForm = false;
		}
	}
}

function NoticiasSec( cual )
{
	$( "#hd" + cual ).stop().toggle( '300' );
}

function NoticiasSubSec( cual )
{
	$( "#hds" + cual ).stop().toggle( '300' );
}

function PicaSM( cual )
{
	if( smPicado != null )
	{
		$( '#sm' + smPicado ).toggle( 300 );
	}
	
	if( smPicado == cual )
	{
		smPicado = null;
	}
	else
	{
		smPicado = cual;
		
		$( '#sm' + smPicado ).toggle( 300 );
	}
}

function PonImgProducto( cual )
{
	//$( '#imgProd' ).html( '<img src="gestor/imagen.php?mod=Productos&id=' + cual + '" border="0" />' );
	$( '#imgProd > img' ).fadeOut
	(
		function()
		{
			var imagen = new Image();
			
			imagen.onload = function()
			{
				$('#imgProd > img')
				.removeAttr('src')
				.attr( 'src', 'gestor/imagen.php?mod=Productos&id=' + cual )
				.fadeIn();
			}
			
			imagen.src = 'gestor/imagen.php?mod=Productos&id=' + cual;
		}
	);
}

function PonSubMnu( cual )
{
	if( document.getElementById( 'subMnu' + cual ).style.height > "0px" )
	{
		$( '#subMnu' + cual ).stop().animate( { height: "0px" }, 200 );
	}
	else
	{
		$( '#subMnu' + cual ).stop().animate( { height: "89px" }, 200 );
	}
}

function CambiaVis( cual, tiempo )
{
	$( '#' + cual ).stop().toggle( tiempo );
}
