
function setVal(form) {
  dz=document.form.duration.options[document.form.duration.selectedIndex].value;
  mz=document.form.accomodation.options[document.form.accomodation.selectedIndex].value;
  wh=document.form.where.options[document.form.where.selectedIndex].value;
  pv=document.form.priv.options[document.form.priv.selectedIndex].value;
//deledz=document.form.deleduration.options[document.form.deleduration.selectedIndex].value;
  s=document.form.start.options[document.form.start.selectedIndex].value;
  courss=document.form.courss.options[document.form.courss.selectedIndex].value;

deledz = 0


lang=document.form.lang.value;

var d = new Date();
secs=d.getTime();

secss=("" + secs);

stamp=secss.substr(0,10);

durmilli = dz * 86400000 * 7;

var dateArray = s.split('/');
sdate = new Date(dateArray[2],dateArray[1]-1,dateArray[0]);

sdatemilli = sdate.getTime();
endmilli = sdatemilli + durmilli;
//holms is holidaymilliseconds
//holsup is holidaysupplement
//supw is price of supplement per week
holms = 0;
holsup = 0;
ss =  sdatemilli;
se =  endmilli;


almunopeneng = "The school in Almuñécar opens on 5/7/2009. Please choose a later starting date.";
almunopenspan = "El colegio en Almuñécar abre el día 5/7/2009. Por favor, elige una fecha de comienzo después esta fecha.";
almuncloseeng = "The school in Almuñécar closes on 13/9/2009. Please choose an earlier starting date or a shorter course duration.";
almunclosespan = "El colegio en Almuñécar cierra el día 13/9/2009. Por favor, elige una fecha de comienzo anterior o una duración de curso más corta.";

if (lang == "eng")
{almunopentext = almunopeneng;
almunclosetext = almuncloseeng}

if (lang == "span")
{almunopentext = almunopenspan;
almunclosetext = almunclosespan}

//almuecar dates 
if (wh == "3" && ss < 1246053600000)
{window.alert(almunopentext)
document.form.start.options.value = 0;
document.form.start.options[document.form.start.selectedIndex].value = 0;
setVal(form)
}

//almuecar dates 
if (wh == "3" && se > 1252879200000)
{window.alert(almunclosetext)
document.form.start.options.value = 0;
document.form.start.options[document.form.start.selectedIndex].value = 0;
document.form.duration.options.value = 2;
document.form.duration.options[document.form.duration.selectedIndex].value = 2;
setVal(form)
}

price= "0";
ppn= "0";

weeks = dz; 


//STANDARD CE CURSO ESTANDARD 20 horas por semana

if (courss == 6){

if (weeks == 1)  {courseprice = 152;} //1
if (weeks == 2)  {courseprice = 305;} //2
if (weeks == 3)  {courseprice = 410;} //3
if (weeks == 4)  {courseprice = 475;} //4
if ((weeks  >= 4 ) &&  (weeks  <= 7 )) {courseprice = (weeks * 119);} // 4-7
if (weeks == 8)  {courseprice = 882 ;} //8
if ((weeks  >= 8 ) &&  (weeks  <= 11 )) {courseprice = (weeks * 110);} // 8-11
if (weeks == 12)  {courseprice = 1172 ;} //12
if (weeks > 12)  {courseprice = 1172 + ((weeks -12) * 98) ;} //12+
}

if (courss == 7){

if (weeks == 1)  {courseprice = 210;} //1
if (weeks == 2)  {courseprice = 415;} //2
if (weeks == 3)  {courseprice = 578;} //3
if (weeks == 4)  {courseprice = 683;} //4
if ((weeks  >= 4 ) &&  (weeks  <= 7 )) {courseprice = (weeks * 171);} // 4-7
if (weeks == 8)  {courseprice = 1344;} //8
if ((weeks  >= 8 ) &&  (weeks  <= 11 )) {courseprice = (weeks * 168);} // 8-11
if (weeks == 12)  {courseprice = 1172 ;} //12
if (weeks > 12)  {courseprice = 1172 + ((weeks -12) * 168) ;} //12+
}


//ACCOMM PRICES

accommprice = 0;
//GRANADA
//SHARED AP DOUBLE ROOM SELF-CATERING

if (mz == 27){

if (weeks == 1 )  {accommprice = 74;} //1
if (weeks == 2 )  {accommprice = 147;} //2
if (weeks == 3 )  {accommprice = 215;} //3
if (weeks == 4 )  {accommprice = 263;} //4
if ((weeks  >= 4 ) &&  (weeks  <= 7 )) {accommprice = (weeks * 58);} // 4-7
if (weeks  >= 8 ) {accommprice = (weeks * 55);} // 8- <<
}

//SHARED AP SINGLE ROOM SELF-CATERING

if (mz == 29){

if (weeks == 1 )  {accommprice = 90;} //1
if (weeks == 2 )  {accommprice = 180;} //2
if (weeks == 3 )  {accommprice = 252;} //3
if (weeks == 4 )  {accommprice = 315;} //4
if ((weeks  >= 4 ) &&  (weeks  <= 7 )) {accommprice = (weeks * 79);} // 4-7
if (weeks  >= 8 ) {accommprice = (weeks * 74);} // 8- <<
}

//FAMILY SHARED ROOM HALF BOARD

if (mz == 33){

if (weeks == 1 )  {accommprice = 111;} //1
if (weeks == 2 )  {accommprice = 223;} //2
if (weeks == 3 )  {accommprice = 334;} //3
if (weeks == 4 )  {accommprice = 445;} //4
if ((weeks  >= 4 ) &&  (weeks  <= 7 )) {accommprice = (weeks * 114);} // 4-7
if (weeks  >= 8 ) {accommprice = (weeks * 111);} // 8- <<
}

//FAMILY SINGLE ROOM HALF BOARD

if (mz == 31){

if (weeks == 1 )  {accommprice = 140;} //1
if (weeks == 2 )  {accommprice = 280;} //2
if (weeks == 3 )  {accommprice = 394;} //3
if (weeks == 4 )  {accommprice = 525;} //4
if ((weeks  >= 4 ) &&  (weeks  <= 7 )) {accommprice = (weeks * 131);} // 4-7
if (weeks  >= 8 ) {accommprice = (weeks * 131);} // 8- <<
}

//FAMILY SHARED ROOM FULL BOARD

if (mz == 37){

if (weeks == 1 )  {accommprice = 132;} //1
if (weeks == 2 )  {accommprice = 265;} //2
if (weeks == 3 )  {accommprice = 397;} //3
if (weeks == 4 )  {accommprice = 529;} //4
if ((weeks  >= 4 ) &&  (weeks  <= 7 )) {accommprice = (weeks * 132);} // 4-7
if (weeks  >= 8 ) {accommprice = (weeks * 132);} // 8- <<
}

//FAMILY SINGLE ROOM FULL BOARD

if (mz == 35){

if (weeks == 1 )  {accommprice = 160;} //1
if (weeks == 2 )  {accommprice = 320;} //2
if (weeks == 3 )  {accommprice = 457;} //3
if (weeks == 4 )  {accommprice = 609;} //4
if ((weeks  >= 4 ) &&  (weeks  <= 7 )) {accommprice = (weeks * 152);} // 4-7
if (weeks  >= 8 ) {accommprice = (weeks * 152);} // 8- <<
}


//NO ACCOMM 

if (mz == 5){
accommprice = 0;
}

accomm = "Weird Browser";

if (mz == "29" )
{accomm = "Shared apartment non-shared room" }

if (mz == "27" )
{accomm = "Shared apartment shared room" }

if (mz == "35" )
{accomm = "Spanish family non-shared room - full board" }

if (mz == "31" )
{accomm = "Spanish family non-shared room - half board" }

if (mz == "37" )
{accomm = "Spanish family shared room - full board" }

if (mz == "33" )
{accomm = "Spanish family shared room - half board" }

if (mz == "1" )
{accomm = "Accommodation not required";
}


//supplements

if (wh == "2")
{hs = 1143496800000;
he = 1159135200000;
supw = 20}

if (wh == "3")
{hs = 1138230000000;
he = 1167174000000;
supw = 0}

if (ss < hs && se > hs && se < he )
{holms = se - hs ;}
if (ss > hs && se > he && ss < he )
{holms = he - ss ;}
if (ss >= hs && se <= he )
{holms = durmilli ;}
if (ss <= hs && se >= he )
{holms = he - hs ;}

//holw is holidayweeks
holw = holms/604800000;
if (mz < 5)
{holsup = holw * supw;
price = price + holsup}


delesup = 0;
delesup = 90*deledz;

dz = dz*1;

priv = dz * (pv * 26);

//ADD 60% if single acom in Almuñecar
sharing = 0

if (mz == 29) {sharing = 1;} 
if (mz == 35) {sharing = 1;} 
if (mz == 31) {sharing = 1;} 

if ((sharing ==1) &&(wh ==3))
{accommprice =  accommprice + (accommprice * 0.6 )}



//ADD PRICE COMPONENTS TOGETHER
price = courseprice + accommprice + priv;



startdateeng = "Please choose a starting date. The price is affected by this date.";
startdatespan = "Por favor, elige una fecha de comienzo. El precio se cambia según la fecha.";
futuredateeng = "Please choose a date in the future.";
futuredatespan = "Por favor, elige una fecha en el futuro.";
deleeng = "You cannot choose more weeks of D.E.L.E. classes than the duration you have chosen on the Standard Course.";
delespan = "No se puede elegir más semanas de classes D.E.L.E. que la duración del curso Estándar.";

if (lang == "eng")
{startdatetext = startdateeng;
futuredatetext = futuredateeng;
deletext = deleeng}

if (lang == "span")
{startdatetext = startdatespan;
futuredatetext = futuredatespan;
deletext = delespan}

if (s == "0")
{window.alert(startdatetext);
document.form.fullprice.value = 0;
return false}

if (sdatemilli < secs)
{window.alert(futuredatetext);
document.form.start.value = 0;
setVal(form);
return false}

if (deledz > dz)
{window.alert(deletext)
document.form.deleduration.options.value = 0;
document.form.deleduration.options[document.form.deleduration.selectedIndex].value = 0;
setVal(form)}


fullprices = Math.round(price);

dollars= fullprices*1.32; 
pounds= fullprices*0.90; 
fianza=fullprices/4;
pricepn = fullprices/dz;
pricepp = pricepn/7;


 document.form.id.value=+stamp;
 document.form.fullprice.value=Math.round(+fullprices*100)/100;
 document.form.pounds.value=Math.round(+pounds*100)/100;
 document.form.dollars.value=Math.round(+dollars*100)/100;
 document.form.deposit.value=Math.round(+fianza*100)/100;
 document.form.ppn.value=Math.round(+pricepn*100)/100;
 document.form.ppp.value=Math.round(+pricepp*100)/100;
 document.form.accomm.value=accomm;
 document.form.acomprice.value=accommprice;
 document.form.courseprice.value=courseprice;
 document.form.privat.value=priv;



}
            
              
              