function calculate(formname){
var aaa="";
var bbb="";
var pricebaht="";
var exch="";
for (var i=0; i < document.forms[formname].JointPrivate.length; i++){
exch=document.forms[formname].Exchange_Rate.value;
if (exch == 0) {
exch = 1;
}

if (exch.toString().indexOf(',')!= -1){
var z=exch.toString().split(',');
exch=z[0]+'.'+z[1];
}

if (document.forms[formname].JointPrivate[i].checked){
var radio_value = document.forms[formname].JointPrivate[i].value;
}}

if(radio_value == "Joint"){
var pricebaht = document.forms[formname].joint.value;
document.forms[formname].nradultc.value = document.forms[formname].nradult.value;
document.forms[formname].nrchildc.value = document.forms[formname].nrchild.value;
}
else{
if (document.forms[formname].nradult.value/1 + document.forms[formname].nrchild.value/1 < 3){
document.forms[formname].nradultc.value = "2";
document.forms[formname].nrchildc.value = "";
}
else{
aaa=document.forms[formname].nradult.value/1;
bbb=Math.floor(document.forms[formname].nrchild.value/2);
document.forms[formname].nradultc.value = aaa + bbb;
document.forms[formname].nrchildc.value = document.forms[formname].nrchild.value - bbb*2;
}

switch (document.forms[formname].elements["nradultc"].value/1) {
case 2:
pricebaht = document.forms[formname].elements["adult2"].value;
break;
case 3:
pricebaht = document.forms[formname].elements["adult3"].value;
break;
case 4:
pricebaht = document.forms[formname].elements["adult4"].value;
break;
case 5:
pricebaht = document.forms[formname].elements["adult5"].value;
break;
case 6:
pricebaht = document.forms[formname].elements["adult6"].value;
break;
case 7:
pricebaht = document.forms[formname].elements["adult7"].value;

break;

default:
pricebaht = document.forms[formname].elements["joint"].value;
break;
}



}



var pricejoint=document.forms[formname].joint.value;
var priceprivat2=document.forms[formname].adult2.value;
var priceprivat3=document.forms[formname].adult3.value;
var priceprivat4=document.forms[formname].adult4.value;
var priceprivat5=document.forms[formname].adult5.value;
var priceprivat6=document.forms[formname].adult6.value;
var priceprivat7=document.forms[formname].adult7.value;
var pricejointfr=money(pricejoint/exch);
var priceprivat2fr=money(priceprivat2/exch);
var priceprivat3fr=money(priceprivat3/exch);
var priceprivat4fr=money(priceprivat4/exch);
var priceprivat5fr=money(priceprivat5/exch);
var priceprivat6fr=money(priceprivat6/exch);
var priceprivat7fr=money(priceprivat7/exch);
var allroundpricebaht = money(pricebaht * document.forms[formname].nradultc.value +  pricebaht / 5*3 * document.forms[formname].nrchildc.value);
var allroundpricefr = money(allroundpricebaht/exch);
var pricefr = money(pricebaht/exch);

document.forms[formname].jointfr.size=pricejointfr.length;
document.forms[formname].jointfr.value=pricejointfr;
document.forms[formname].foreign2.size=priceprivat2fr.length;
document.forms[formname].foreign2.value=priceprivat2fr;
document.forms[formname].foreign3.size=priceprivat3fr.length;
document.forms[formname].foreign3.value=priceprivat3fr;
document.forms[formname].foreign4.size=priceprivat4fr.length;
document.forms[formname].foreign4.value=priceprivat4fr;
document.forms[formname].foreign5.size=priceprivat5fr.length;
document.forms[formname].foreign5.value=priceprivat5fr;
document.forms[formname].foreign6.size=priceprivat6fr.length;
document.forms[formname].foreign6.value=priceprivat6fr;
document.forms[formname].foreign7.size=priceprivat7fr.length;
document.forms[formname].foreign7.value=priceprivat7fr;
document.forms[formname].allroundbaht.size=allroundpricebaht.length;
document.forms[formname].allroundbaht.value=allroundpricebaht;
document.forms[formname].allroundfr.size=allroundpricefr.length;
document.forms[formname].allroundfr.value=allroundpricefr;
document.forms[formname].perpersonbaht.size=pricebaht.length;
document.forms[formname].perpersonbaht.value=pricebaht;
document.forms[formname].perpersonfr.size=pricefr.length;
document.forms[formname].perpersonfr.value=pricefr;
}
function money(num){
if (num.toString().indexOf('.')!= -1){
var a=num.toString().split('.');
var b=a[1].substr(0,2);
if (b.length<2){b=b+"0"}
var c=a[0]+"."+b}
else{var c=num.toString()}
return c;
}
function Ersetze(was){
was = was.replace(/%20/g, " ");
was = was.replace(/%0A/g, "<br>");
was = was.replace(/%22/g, "\"");
return was
}
function e_mailer(formname){
var ClearButton = "<p><input type='button' class='BUTTON' value='L&ouml;schen' onclick='document.getElementById\(\"EmailtextTrek\"\).innerHTML =\"\"'><\/p>";
var subject = "";
for (var i=0; i < document.forms[formname].JointPrivate.length; i++){
if (document.forms[formname].JointPrivate[i].checked){
var radio_value = document.forms[formname].JointPrivate[i].value;
}}
if (formname == "trek1day"){
subject = "Reservation%20for%201%20day%20trek";
}
if (formname == "trek2days"){
subject = "Reservation%20for%202%20days%201%20night%20trek";
}
if (formname == "trek3days"){
subject = "Reservation%20for%203%20days%202%20nights%20trek";
}
var body1 = "Price%20per%20person:%20" + document.forms[formname].perpersonbaht.value + "%20Baht%0AAll%20round%20price:%20" + document.forms[formname].allroundbaht.value + "%20Baht%0ANo.%20of%20Adults:%20" + document.forms[formname].nradult.value + "%0ANo.%20of%20Children:%20" + document.forms[formname].nrchild.value + "%0AJoint%20or%20private:%20" + radio_value;
var body2 = "%0AYour%20Name:%0AStart%20date%20of%20the%20trek:%0AHotel%20or%20Guest-house + Phone No.:%0ADate%20and%20time%20for%20collection%20of%20payment:";
var EmailId = "buddytours@chiangmai1.com";
var divemail = '<h3 class="blue">Falls das Email Programm nicht &ouml;ffnet!<\/h3><p>Kopieren Sie bitte den folgenden Text, f&uuml;gen ihn in Ihr Email Programm ein und senden ihn an:<br>'+EmailId+'<p>'+Ersetze(subject)+"<br><br>"+Ersetze(body1)+Ersetze(body2)+ClearButton;
if(navigator.appName.indexOf("Internet Explorer") != -1) {
document.getElementById("EmailtextTrek").innerHTML = divemail;
}
try{
window.location="mailto:"+EmailId+"?subject="+subject+"&body="+body1+body2;
}
catch (e){
document.getElementById("EmailtextTrek").innerHTML = divemail;
}}