function FP_changeProp() {//v1.0
 var args=arguments,d=document,i,j,id=args[0],o=FP_getObjectByID(id),s,ao,v,x;
 d.$cpe=new Array(); if(o) for(i=2; i<args.length; i+=2) { v=args[i+1]; s="o"; 
 ao=args[i].split("."); for(j=0; j<ao.length; j++) { s+="."+ao[j]; if(null==eval(s)) { 
  s=null; break; } } x=new Object; x.o=o; x.n=new Array(); x.v=new Array();
 x.n[x.n.length]=s; eval("x.v[x.v.length]="+s); d.$cpe[d.$cpe.length]=x;
 if(s) eval(s+"=v"); }
}

function FP_getObjectByID(id,o) {//v1.0
 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
 f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
 for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
 return null;
}

function FP_changePropRestore() {//v1.0
 var d=document,x; if(d.$cpe) { for(i=0; i<d.$cpe.length; i++) { x=d.$cpe[i];
 if(x.v=="") x.v=""; eval("x."+x.n+"=x.v"); } d.$cpe=null; }
}

function checkenrollment() {

var str1=document.getElementById('name').value;
var str2=document.getElementById('surname').value;
var str3=document.getElementById('address').value;
var str4=document.getElementById('postalcode').value;
var str5=document.getElementById('city').value;
var str6=document.getElementById('country').value;
var str7=document.getElementById('email').value;
var str8=document.getElementById('telephone').value;
var str9=document.getElementById('nationality').value;
var str10=document.getElementById('dateofbirth').value;
var str11=document.getElementById('courselength').value;
var str12=document.getElementById('accommodation0');
var str13=document.getElementById('accommodationfirstnight').value;
var str14=document.getElementById('accommodationlastnight').value;
var str15=document.getElementById('termsconditions');
var str16=document.getElementById('startingdates').value;
var str17=document.getElementById('findole').value;
var resultado=false;
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i



	if (str1=="" || str2=="" || str3=="" || str4=="" || str5=="" || str6=="" || str7=="" || str9=="" || str10=="" || str11=="" || str16=="" || str17==""){
		alert("Fields marked with * must be filled out");		
	}
	else {
		if (filter.test(str7)){
				if (isNaN(str11)){
					alert('The number of weeks is not a valid number');
					field.focus();
					field.select();
				}
				else{
						if (str11<=0){
							alert('The number of weeks should be greater than 0');
							field.focus();
							field.select();
						}
						else{
						
								if (checkShortDate(str10)){
										alert("Birthday format wrong");
								}
								else{
									if (str8==""){
										alert("You must enter at least one telephone or mobile number");
									}
									else{
										if (str12.checked) {
													resultado=true;
												}
												else{
													if (str13=="" || str14=="") {
														alert("Please, complete the accommodation dates");
													}
													else{
														if (checkShortDate(str13)|| checkShortDate(str14)) {
															alert("firstnight or lastnight accommodation date wrong");
														}
														else{
															resultado=true;
								
														}
																						
													}		
												}
										}
									}
						}
					}
			
		}
		else{
			alert("Please input a valid email address!");
		}
	}
	if (resultado){
			if (str15.checked){
				document.forms[0].submit();
			}
			else{
				alert("You must accept the terms & conditions");								
		
			}
	}
	else{
												
		
	}
}

	


function checktest() {

var str1=document.getElementById('name').value;
var str2=document.getElementById('surname').value;
var str3=document.getElementById('date').value;

	if (str1=="" || str2=="" || str3==""){
		alert("Name, Surname and Date must be filled out");		
	}
	else {
		document.forms[0].submit();
					
			
		}
}

function checkrequestcode() {

var str1=document.getElementById('firstname').value;
var str2=document.getElementById('lastname').value;
var str3=document.getElementById('email').value;
var str4=document.getElementById('email2').value;
var str5=document.getElementById('year').value;
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i


	if (str1=="" || str2=="" || str3=="" || str4=="" || str5==""){
		alert("All the fields must be filled out");		
	}
	else {
				if (filter.test(str3)){
							if (str3==str4){
									document.forms[0].submit();
							}
							else{
									alert("Emails don't match")
							}	
				}
				else{
				alert("Please input a valid email address!")
				}														
		}
}





function checklanguageexchange() {
var str1=document.getElementById('name').value;
var str2=document.getElementById('country').value;
var str3=document.getElementById('idiomaquehablas').value;
var str4=document.getElementById('idiomaparapracticar').value;
var str5=document.getElementById('email').value;
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	
	if (str1=="" || str2=="" || str3=="" || str4=="" || str5==""){
		alert("Fields marked with * must be filled out");
	}
	else {
	
		if (filter.test(str5)){
			document.forms[0].submit();
		}
		else{
			alert("Please input a valid email address!")
		}	
	}
}



function check1() {
/*
alert(document.getElementById('years').value+"-"+
(document.getElementById('months').selectedIndex+1)+"-"+
	(document.getElementById('days').selectedIndex+1));
*/
	
	document.getElementById('birthDate').value = document.getElementById('years').value+"-"+
(document.getElementById('months').selectedIndex+1)+"-"+
	(document.getElementById('days').selectedIndex+1);
	if (document.getElementById('email').value != document.getElementById('remail').value) {
		alert('Email entries are diferent');
	}
	else document.forms[0].submit();	
	
}


function checkemail(){
var str=document.getElementById('email').value
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
document.getElementById('birthDate').value = document.getElementById('years').value+"/"+
(document.getElementById('months').selectedIndex+1)+"/"+
	(document.getElementById('days').selectedIndex+1);
if (filter.test(str)){
document.forms[0].submit();
}
else{
alert("Please input a valid email address!")
}
}

function checkcontactanos(){
var str=document.getElementById('email').value
var str2=document.getElementById('name').value
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i


if (str2==""){

                    alert("Please input a name!")

             }
			 else{
                      if (filter.test(str)){
                         document.forms[0].submit();
                      }
                      else{
                         alert("Please input a valid email address!")
                      }
			     }
}

function checkpayment(){
var str1=document.getElementById('email').value
var str2=document.getElementById('name').value
var str3=document.getElementById('amount').value
var str4=document.getElementById('surname').value
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i



			if (str1=="" || str2=="" || str3=="" || str4==""){

                    alert("All the fields must be filled out")

             }
             else{
             		if (isNaN(str3)) {
             			alert("Please input a valid amount (only numbers)")
        			}
					else{
							if (filter.test(str1)){
                         	document.forms[0].submit();
                      		}
                      		else{
                         		alert("Please input a valid email address!")
                      			}
					}
    		}			
	
			     
}


function checkcontactanos2(){
var str=document.getElementById('name2').value
var str1=document.getElementById('telephone').value

if (str1==""){

                     alert("Please input a valid telephone number!")

             }
			 else{
                      if (str==""){
                         
						 alert("Please input a name!")
                      }
                      else{
                         document.forms[1].submit();
                      }
			     }
}



function checkbae(){
if (document.layers||document.getElementById||document.all)
return checkemail()
else
return true
}



function FP_swapImg() {//v1.0
 var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
 n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
 elm.$src=elm.src; elm.src=args[n+1]; } }
}

function FP_preloadImgs() {//v1.0
 var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
 for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}

function checkclick(obj)
{
	
	if (obj.checked) {
		document.getElementById("accommodationfirstnight").disabled = false;
		document.getElementById("accommodationlastnight").disabled = false;
		document.getElementById("amigodoble").disabled = false;
		document.getElementById("vegetariano").disabled = false;
		document.getElementById("alergico").disabled = false;
	
	}
	else {
		document.getElementById("accommodationfirstnight").disabled = true;
		document.getElementById("accommodationlastnight").disabled = true;
		document.getElementById("amigodoble").disabled = true;
		document.getElementById("vegetariano").disabled = true;
		document.getElementById("alergico").disabled = true;
	}
}

function checkclick2(obj)
{
	
	if (obj.checked) {
		document.getElementById("accommodationfirstnight").disabled = true;
		document.getElementById("accommodationlastnight").disabled = true;
		document.getElementById("amigodoble").disabled = true;
		document.getElementById("vegetariano").disabled = true;
		document.getElementById("alergico").disabled = true;
	
	}
	else {
		document.getElementById("accommodationfirstnight").disabled = false;
		document.getElementById("accommodationlastnight").disabled = false;
		document.getElementById("amigodoble").disabled = false;
		document.getElementById("vegetariano").disabled = false;
		document.getElementById("alergico").disabled = false;
	}
}

function checksamedate(obj)
{
	alert(document.getElementById("fechas"));
	if (obj.checked) {
			document.getElementById("anweeks").disabled = true;
		document.getElementById("accStart").disabled = true;
	}
	else {
			document.getElementById("anweeks").disabled = false;
			document.getElementById("anweeks").value = document.getElementById("nweeks").value;
		document.getElementById("accStart").disabled = false;
		document.getElementById("accStart").value = document.getElementById("fechas").value;
	}
}

	
function check2()
{
	
	var field = document.getElementById('nweeks');
	var field2 = document.getElementById('anweeks');
	var field3 = document.getElementById('accomodation');
	var dt = document.getElementById('accStart');
	if (isNaN(field.value)) {
		alert('The number of weeks is not a valid number');
		field.focus();
		field.select();
		ok = false;
	}	
	if (ok) if (field.value<=0) {
		alert('The number of weeks should be greater than 0');
		field.focus();
		field.select();
		ok = false;
	}
	
	if (isNaN(field2.value)) {
		alert('The number of Accomodation weeks is not a valid number');
		field.focus();
		field.select();
		ok = false;
	}	

	if (field3.checked==true){
	      if (isDate(dt.value)==false){
	     dt.focus();
		 ok = false;
		 field3.defaultChecked = true;
		   }
	  }   
	  else  {
		field3.defaultChecked = false;
		    }
	if (ok) document.forms[0].submit();
}
function check4() {
	var ok = true;
	if (cardval(document.getElementById('creditCardNumber').value) == false) {
		alert('Credit card number is invalid');
		ok = false;
	}	
	if (ok) ok = checkShortDate();
	if (ok) document.forms[0].submit();
}
function check5() {
	document.forms[0].submit();
}


function cancel1() {
   
	document.forms[0].action = "http://localhost:8080/Ole2/jsp/index.jsp" 
	document.forms[0].submit();

}

function atras1() {
	document.forms[0].action = "http://localhost:8080/Ole2/jsp/enroll_online_select.jsp" 
	document.forms[0].submit();
}

function atras2() {
	document.forms[0].action = "http://localhost:8080/Ole2/jsp/free_price_quote_select.jsp" 
	document.forms[0].submit();
}

function cardval(s) {
	// remove non-numerics
	var v = "0123456789";
	var w = "";
	for (i=0; i < s.length; i++) {
		x = s.charAt(i);
		if (v.indexOf(x,0) != -1)
		w += x;
	}
	// validate number
	j = w.length / 2;
	if (j < 6.5 || j > 8 || j == 7) return false;
	k = Math.floor(j);
	m = Math.ceil(j) - k;
	c = 0;
	for (i=0; i<k; i++) {
		a = w.charAt(i*2+m) * 2;
		c += a > 9 ? Math.floor(a/10 + a%10) : a;
	}
	for (i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;
		return (c%10 == 0);
}
function checkShortDate(s) {
	var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/;
	//var objRegExp = /^\d{1,2}(\-|\/|\.)\d{2}$/;
	var re = new RegExp(objRegExp);
	var ok = false;
	if (re.test(s) == false) {
		ok = true;
	}
	return ok;
}

function canceltx() {}

function startclock()
{
var thetime=new Date();

var nhours=thetime.getHours();
var nmins=thetime.getMinutes();
var nsecn=thetime.getSeconds();
var nday=thetime.getDay();
var nmonth=thetime.getMonth();
var ntoday=thetime.getDate();
var nyear=thetime.getYear();
var AorP=" ";

/*
if (nhours>=12)
    AorP="P.M.";
else
    AorP="A.M.";

if (nhours>=13)
    nhours-=12;

if (nhours==0)
   nhours=12;
*/
if (nsecn<10)
 nsecn="0"+nsecn;

if (nmins<10)
 nmins="0"+nmins;

if (nday==0)
  nday="Domingo";
if (nday==1)
  nday="Lunes";
if (nday==2)
  nday="Martes";
if (nday==3)
  nday="Miércoles";
if (nday==4)
  nday="Jueves";
if (nday==5)
  nday="Viernes";
if (nday==6)
  nday="Sabado";

nmonth+=1;

if (nmonth==1) nmonth="Enero";
else if (nmonth==2) nmonth="Febrero";
else if (nmonth==3) nmonth="Marzo";
else if (nmonth==4) nmonth="Abril";
else if (nmonth==5) nmonth="Mayo";
else if (nmonth==6) nmonth="Junio";
else if (nmonth==7) nmonth="Julio";
else if (nmonth==8) nmonth="Agosto";
else if (nmonth==9) nmonth="Septiembre";
else if (nmonth==10) nmonth="Octubre";
else if (nmonth==11) nmonth="Noviembre";
else if (nmonth==12) nmonth="Diciembre";
if (nyear<=99)
  nyear= "19"+nyear;

if ((nyear>99) && (nyear<2000))
 nyear+=1900;
/*
document.getElementById('cciudad').value="Barcelona, \n"+nday;
document.getElementById('cfecha').value=ntoday+" de "+nmonth+" de "+nyear;
document.getElementById('chora').value=nhours+": "+nmins+": "+nsecn+" CET"; */
//document.getElementById('horafecha').value="Barcelona, "+nday+"\n"+ntoday+" de "+nmonth+" de "+nyear+"\n"+nhours+": "+nmins+": "+nsecn+" CET";
document.getElementById('horafecha').value="Barcelona, "+nday+"\n"+ntoday+" de "+nmonth+" de "+nyear;

setTimeout('startclock()',1000);

}

var dtCh= "/";
var minYear=2004;
var maxYear=2006;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

