/* --------------- Gallery Setup ----------------- */

$(function() { 
    $("a[rel='#overlay']").overlay({ 
 
        finish: {top: 'center'},  
        expose: { 
            color: '#000000', 
            opacity: 0.7, 
            closeSpeed: 1000 
        } 
		
    });
    
    
    $('#listaFotos .elements').click(cargarFotoGrande);
});


function cargarFotoGrande(event){
	var div = $(this);
	var value = div.find('input').val();
	var big = $('#imgBig_2');
	var img = $('<img/>');
	img.load(function (event){
		big.attr('src',value);
	});
	big.attr('src',div.find('img').attr('src'));
	img.attr('src',value);
	return false
}


/* -------- Ficha -------- */
$(function() {         
         
    // initialize scrollable  
   $("div.miniGallery").scrollable({ 
		next: 'div.next', 
		prev: 'div.prev',
		nextPage: 'div.nextPage',
		prevPage: 'div.prevPage',
		vertical:true,
		size: 3 
	});     
     
}); 

/* -------- Big -------- */

$(function() {         
         
    // initialize scrollable  
   $("div.bigGallery").scrollable({ 
		next: 'div.nextBig', 
		prev: 'div.prevBig',
		nextPage: 'div.nextPageBig',
		prevPage: 'div.prevPageBig',
		vertical:true,
		size: 5
		
	});     
     
}); 




function loadBigImg(id,imgId){
	
	document.getElementById(imgId).src = id;
	
	return false;
}

function submitImpr(art,tipo){
	if(document.imprform.val_1.checked == true){
		var val1 = 1;
	}else{
		var val1 = 0;
	}
	
	if(document.imprform.val_2.checked == true){
		var val2 = 1;
	}else{
		var val2 = 0;
	}
	
	if(document.imprform.val_3.checked == true){
		var val3 = 1;
	}else{
		var val3 = 0;
	}
	
	if(document.imprform.val_4.checked == true){
		var val4 = 1;
	}else{
		var val4 = 0;
	}
	
	ruta = document.getElementById("imgBig").src;
	
	//var ventanuca = window.open("rn_ficha_vo_print02.php?art="+art+"&val1="+val1+"&val2="+val2+"&val3="+val3+"&val4="+val4+"&ruta="+ruta,'Renault','toolbar=0,location=1,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=600,height=200') ;
	var ventanuca;
	if (tipo=="vo"){
	  ventanuca = f_open_window_max("/rn_ficha_vo_print02.php?art="+art+"&val1="+val1+"&val2="+val2+"&val3="+val3+"&val4="+val4+"&ruta="+ruta,"Renault");
	}else{
	  ventanuca = f_open_window_max("/vn/rn_ficha_vo_print02.php?art="+art+"&val1="+val1+"&val2="+val2+"&val3="+val3+"&val4="+val4+"&ruta="+ruta,"Renault");
	}
	//ventanuca.print();
	//ventanuca.close();
	//document.location.href = "rn_ficha_vo_print02.php?art="+art+"&val1="+val1+"&val2="+val2+"&val3="+val3+"&val4="+val4;
	
}







function f_open_window_max( aURL, aWinName )
{
   var wOpen;
   var sOptions;

   sOptions = 'status=yes,menubar=yes,scrollbars=yes,resizable=yes,toolbar=yes';
   sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
   sOptions = sOptions + ',height=' + (screen.availHeight - 122).toString();
   sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';

   wOpen = window.open( '', aWinName, sOptions );
   wOpen.location = aURL;
   wOpen.focus();
   wOpen.moveTo( 0, 0 );
   wOpen.resizeTo( screen.availWidth, screen.availHeight );
   return wOpen;
}




function muestraConcesion(muestra){
	if (muestra){
		document.getElementById('nombreConcesion').style.display = 'block';
	}
	else{
		document.getElementById('nombreConcesion').style.display = 'none';
	}
	return false;
}

function isNoCampoVacio (theElement){
	if (theElement.value == ''){
        document.getElementById('error_form').innerHTML="ERROR EN FORMULARIO: Por favor, rellene todos los campos obligatorios";
        theElement.focus();
        return false;        
    }
	else{
		return true;
	}
		
}

function isEmailAddress(theElement){
    var email = theElement.value;
    var filter=/^[A-Za-z][.A-Za-z0-9_]*@[A-Za-z0-9_]+.[A-Za-z0-9_.]+[A-za-z]$/;
    if (filter.test(email))
        return true;
    document.getElementById('error_form').innerHTML="ERROR EN FORMULARIO: Proporcione una dirección de eMail válida";
    theElement.focus();
    return false;
}

function isPhoneNumber(theElement){
    var filter = /[0-9]{3}[-]?[0-9]{3}[-]?[0-9]{3}/;
    if (!filter.test(theElement.value)){
   	 document.getElementById('error_form').innerHTML="ERROR EN FORMULARIO: Proporcione un teléfono válido";
   	 theElement.focus();
     return false;
    }
    return true;
}

function isAcepted(theElement){
    if (!theElement.checked){
   	 document.getElementById('error_form').innerHTML="ERROR EN FORMULARIO: Acepte la política de protección de datos";
   	 theElement.focus();
        return false;
    }
    return true;
}


function interesa(f){
	frm=document.getElementById(f);
	if (isAcepted(frm.acepto)){
		if (isEmailAddress(frm.mail)){			
			if (isNoCampoVacio(frm.nombre) && isNoCampoVacio(frm.mail)){	
				if ((frm.contactar.checked==false) || (isPhoneNumber(frm.telefono) && isPhoneNumber(frm.movil))){					
					xajax_mailInteresa(xajax.getFormValues(frm));
				}
				
			}
		}
	}
	return false;
}


function prueba(f){
	frm=document.getElementById(f);
	if (isAcepted(frm.acepto)){
		if (isEmailAddress(frm.mail)){			
			if (isNoCampoVacio(frm.nombre) && isNoCampoVacio(frm.mail)){				
				if ((frm.contactar.checked==false) || (isPhoneNumber(frm.telefono) && isPhoneNumber(frm.movil))){
					xajax_mailPrueba(xajax.getFormValues(frm));
					
				}
			}
		}
	}
	return false;
}

function llamada(f){
	frm=document.getElementById(f);
	if (isAcepted(frm.acepto)){
		if (isPhoneNumber(frm.telefono)){
			xajax_mailLlamada(xajax.getFormValues(frm));
		}
	}
	return false;
}

function contacto(f){
	frm=document.getElementById(f);
	if (isAcepted(frm.acepto)){
		if (isEmailAddress(frm.mail)){			
			if (isNoCampoVacio(frm.nombre) && isNoCampoVacio(frm.mail)){
					xajax_mailContacto(xajax.getFormValues(frm));
					//alert(frm);
			}
		}
	}
	return false;
}


function registrarse(f){

	frm=document.getElementById(f);
  if (isNoCampoVacio(frm.usuario) && isNoCampoVacio(frm.pass) && isNoCampoVacio(frm.nombre) && 
      isNoCampoVacio(frm.empresa) && isNoCampoVacio(frm.nifcif) && isNoCampoVacio(frm.telefono) && isNoCampoVacio(frm.email)){	
  
    	if (isAcepted(frm.acepto) && isEmailAddress(frm.email) && isPhoneNumber(frm.telefono)) {
    			xajax_mailsRegistro(xajax.getFormValues(frm));
    	}
  
  }
	return false;
}



function esBisiesto(year) { 
    return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) ? true : false; 
} 

function limpiaSelect(elSelect) { 
    while( elSelect.hasChildNodes() )
        elSelect.removeChild( elSelect.firstChild ); 
} 

function aniadeOpcion(elSelect, texto, valor) { 
    var laOpcion=document.createElement("OPTION"); 
    laOpcion.appendChild( document.createTextNode(texto) ); 
    laOpcion.setAttribute("value",valor); 
    elSelect.appendChild(laOpcion); 
}


function rellenar_anio(elSelect) {
    for(var a=2009;a<=2010;a++)
        aniadeOpcion(elSelect, a.toString(), a.toString() );
}

var meses=["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"];
function rellenar_mes(elSelect) {
    for(var a=0;a<meses.length;a++)
        aniadeOpcion(elSelect, meses[a], a );
}

function rellenar_dia(elSelect, anio, mes ) {
    var ultimo_dia;
    // febrero
    if(mes==1)
        ultimo_dia=esBisiesto(anio)?29:28;
    // acaban en 31
    else if( mes==0 || mes==4 || mes==6 || mes==7 || mes==9 || mes==11)
        ultimo_dia=31;
    else
        ultimo_dia=30;
    for(var a=1; a<=ultimo_dia; a++) {
        aniadeOpcion(elSelect, a, a);
    }
}





