function openSwf(archivo, ancho, alto){
    var quality="high";
    document.write('<object>\n');
	document.write('<param name="wmode" value="transparent" />\n');
    document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
    document.write('<param name="movie" value="'+archivo+'.swf" />\n');
    document.write('<param name="quality" value="'+quality+'" />\n');
    document.write('<embed wmode="transparent" src="images/'+archivo+'.swf" quality="'+quality+'" width="'+ancho+'" height="'+alto+'" name="'+archivo+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" />\n');
    document.write('</object>\n');
}

function showHide(id1,id2){
	id1.style.display = 'block';
	id2.style.display = 'none'; 
}

/* ================================ */
/* code para calcular el dia fertil */
/* ================================ */

function Calcular(snpsForm){
	var retorno;
	retorno = FechaMasDias(snpsForm)
	if(retorno==false){
		alert("Introduzca fecha valida");
		return false;
	}
}


function FechaMasDias(snpsForm){
	var dia = snpsForm.day.options[snpsForm.day.selectedIndex].value;
	var mes = snpsForm.month.options[snpsForm.month.selectedIndex].value;
	var anno = snpsForm.year.value;
	var x = snpsForm.x.options[snpsForm.x.selectedIndex].value;
	var maxdia;

	dia  = 	eval(dia);
	mes  = 	eval(mes);
	anno = 	eval(anno);
	x =	eval(x);

	if (mes == 2){
		if ((anno%4)==0){
			maxdia = 29;
		}else{
			maxdia = 28;
		}
	}

	if (mes==1||mes==3||mes==5||mes==7||mes==8||mes==10||mes==12)
		maxdia = 31;
	if (mes==4||mes==6||mes==9||mes==11)
		maxdia = 30;
	if (dia>maxdia) {
		return false;
	}
	
		var diamf = dia + x - 14;
		var intinf = dia + x - 17;
		var intsup = dia + x - 11;

		fecha1 = Calc(maxdia,mes,anno,diamf);
		fecha2 = Calc(maxdia,mes,anno,intinf);
		fecha3 = Calc(maxdia,mes,anno,intsup);

		document.snpsForm.fecha1.value=fecha1;
		document.snpsForm.fecha2.value=fecha2;	
		document.snpsForm.fecha3.value=fecha3;
}	


function Calc(maxdia,mes,anno,date){
	if (date > maxdia){
		date = date - maxdia;
		if (mes == 12){
			anno = anno + 1;
			mes = 1;
		}else{
			mes = mes + 1;
		}
	}

	if (date < 10) date = "0" + date;
	if (mes < 10) mes = "0"+ mes;
	fecha= date + "/" + mes + "/" + anno;
	return fecha;
}	

	



function CalcCycle(theForm) {

//Form verifying:

alert();

	var year1 = theForm.year1.options[theForm.year1.selectedIndex].value;

	var year2 = theForm.year2.options[theForm.year2.selectedIndex].value;



	/*if (year1  == "")  {

	           alert ("El año esta en blanco");

	        return;

	}



	if (year1 < 1000){

	           alert ("Intentelo de nuevo\n\nIntroduzca los cuatro digitos del año");

	        return;

	}

	if (year2 == "")  {

	           alert ("Intentalo de nuevo\n\nEl año no ha sido introducido!");

	        return;

	}

	if (("" + parseInt(year2)) != year2)  {
	           alert ("Intentalo de nuevo\n\nDebe escribir el año en numeros");

	        return;

	}

	if (year2 < 1000){

	           alert ("Intentalo de nuevo\n\nEscribe los 4 numeros del año");

	        return;

	}*/





//Grab, format and calculate



	if (!(ValidateCycleDate(theForm.month1.options[theForm.month1.selectedIndex].value,year1,theForm.date1.options[theForm.date1.selectedIndex].value))) {

		alert("La fecha para el primer periodo no es valida!");

		return;

	}



	if (!(ValidateCycleDate(theForm.month2.options[theForm.month2.selectedIndex].value,year2,theForm.date2.options[theForm.date2.selectedIndex].value))) {

		alert("La fecha para el segundo periodo no es valida!");

		return;

	}

	Period1 =  Date.UTC(year1, theForm.month1.options[theForm.month1.selectedIndex].value, theForm.date1.options[theForm.date1.selectedIndex].value);



	Period2 =  Date.UTC(year2, theForm.month2.options[theForm.month2.selectedIndex].value, theForm.date2.options[theForm.date2.selectedIndex].value);



	CycleMS = (Period1 - Period2);



	if (Period1 > Period2){

			DayFormattedCycle = CycleMS / 86400000



				if ( DayFormattedCycle < 21 || DayFormattedCycle > 35 ) {

		   	   	   alert ("El resultado es" + DayFormattedCycle + " dias. Esta fuera del rango de dias esperado (21-35).");

				}



			theForm.cycle.value = DayFormattedCycle

			}



			else {

			//updated to reflect correct dates

	      alert ("La primera fecha debe ser mas reciente que la segunda.");

	      return;

		}



	}

function ValidateCycleDate(month,year,day) {

	var lmonth,lyear,lday;

	lmonth = parseInt(" " + month);

	lyear = parseInt(" " + year);

	lday = parseInt(" " + day);

	ldays = DaysInMonth(lmonth,lyear)



	if (lday > ldays) {

		return false;

	} else {

		return true;

	}

}





function DaysInMonth(month,year) {

	var days;



	switch (month) {



		case 1:

			days=31;

			break;



		case 3:

			days=31;

			break;



		case 5:

			days=31;

			break;



		case 7:

			days=31;

			break;



		case 8:

			days=31;

			break;



		case 10:

			days=31;

			break;



		case 12:

			days=31;

			break;



		case 4:

			days=30;

			break;

		case 6:

			days=30;

			break;

		case 9:

			days=30;

			break;

		case 11:

			days=30;

			break;

		case 2:



			if (IsLeapYear(year)) {

				days=29;

			}else{

				days=28;

			}

	}







	return days;





}



function IsLeapYear(lyear)  {



	if ( (lyear%4 == 0 && lyear%100 != 0) || (lyear%400 == 0) ) {

		return true;

	} else {

		return false;

	}

}

