// EP Editorial Estimator - developed by Ken Richardson
// *******************************************************
function test_it(entry) {
// if (entry.value!=null && entry.value.length!=0) {
//   entry.value=""+ eval(entry.value);
// }
 computeForm(entry.form);
}



function convertstring(number) {
//number="10,000";
var b=0.00;
var L=number.length;
if(L<1){number="1.00"}
var n = new Array(20);
var ts="";
var jj=0;
for (var ii=0; ii<=L; ii++){
        jj=ii+1;
        n[ii]=number.substring(ii,jj);
        if (n[ii]!=",") {
                ts=ts+n[ii]
        }
}
b=parseInt(ts);
return b

}

function computeForm(form) {
//alert("hello");
//    if (form.circulation.value==null || form.circulation.value.length==0) {
//        form.circulation.value=0;
//    }
//    if (form.adrate.value==null || form.adrate.value.length==0)  {
// form.adrate.value=0;
//   }

//var sr = new Array(30);

var temp=1;
var temp2=1;
var temp3=1;
var temp4=1;
var temp5=1;
var today= new Date();
var vyear = today.getYear();
var yd=1;
var both=1;
var area2=1;
var dimension=1;
var middle;
var duration=1;

var ia=1;
var is=1;
var ir=1;
var iw=1;

var vcs=form.circulation.value;
var vc=convertstring(vcs);
var vas=form.adrate.value;
var va=convertstring(vas);
var vrs=form.reprints.value;
var vr=convertstring(vrs);
var vds=form.duration.value;
var vd=convertstring(vds);
var vhs=form.height.value;
var vh=convertstring(vhs);
if (vh<240){vh=240}
var vws=form.width.value;
var vw=convertstring(vws);
if (vw<320){vw=320}
var ex=form.exchange.value;
//var ex=convertstring(exs);
var fe=form.foreign.value;
//var fe=convertstring(fes);
var fe2=0.4;
var fsr=form.forspacemod.value;
//var fsr=convertstring(fsrs);
var frr=form.forreprintmod.value;
//var frr=convertstring(frrs);
var fwr=form.forwebmod.value;
//var fwr=convertstring(fwrs);

if (fsr<0.001){fsr=1}
if (frr<0.001){frr=1}
if (fwr<0.001){fwr=1}

if (fe<7){
	fe2=0.4;
}
else{
	fe2= 0.4 + ((fe-6)*0.1);
}

if (ex<0.01){
	ex=1;
}

if (vyear>1950){
	yd=vyear-2000
}
	else{
yd=vyear-100
}

ia=Math.pow(1.0275,yd);
is=Math.pow(1.0278,yd);
ir=Math.pow(1.02692,yd);
iw=Math.pow(1.0272,yd);

// Calculate Assignment and Editions Rate

both=vc*va;

temp=(100*(Math.pow(both,0.096))-100)*100*ia*ex;
temp2=(Math.round(temp))/100;
form.assignment.value=(Math.round(temp))/100;
form.pennyassignment.value=temp2/vc*100;
form.percentassignment.value=temp2/va*100;

temp2=(50*(Math.pow(both,0.083))+250)*100*ia*ex;
if (temp<temp2){temp2=temp}

if (yd==2){temp2=temp*0.33+temp2*0.67}
if (yd==3){temp2=temp*0.67+temp2*0.33}
if (yd==4){temp2=temp*0.90+temp2*0.10}
if (yd>4){temp2=temp}

form.transitional.value=(Math.round(temp2))/100;

//form.assignment.value=ex;
temp2=fe2*temp;
form.exeditions.value=(Math.round(temp2))/100;

// Calculate Space Rates

temp=((2.1164)*(Math.pow(both,0.201))+115)*100*is*ex;
temp2=(Math.round(temp))/100;
form.spacequarter.value=temp2;
temp5=(temp2/vc)*1000000;
form.pennyspacequarter.value=Math.round(temp5)/10000;
temp5=(temp2/va)*1000000;
form.percentspacequarter.value=Math.round(temp5)/10000;
form.forspacequarter.value=temp2*fsr;

temp3=((8.5)*(Math.pow(both,0.127))+115)*100*is*ex;
if (temp3>temp){temp3=temp}
temp2=(Math.round(temp3))/100;
form.transspacequarter.value=temp2;


temp=((2.1164)*(Math.pow(both,0.201))+115)*100*is*ex;
temp3=temp*1.30;
temp2=(Math.round(temp3))/100;
form.spacehalf.value=temp2;
temp5=(temp2/vc)*1000000;
form.pennyspacehalf.value=Math.round(temp5)/10000;
temp5=(temp2/va)*1000000;
form.percentspacehalf.value=Math.round(temp5)/10000;
form.forspacehalf.value=temp2*fsr;

temp3=((1004)*(Math.pow(both,0.0190))-1228)*100*is*ex*0.973;
if (temp3>temp){temp3=temp}
temp3=temp3*1.30;
temp2=(Math.round(temp3))/100;
form.transspacehalf.value=temp2;


temp=((2.1164)*(Math.pow(both,0.201))+115)*100*is*ex;
temp3=temp*1.65;
temp2=(Math.round(temp3))/100;
form.space3quarter.value=temp2;
temp5=(temp2/vc)*1000000;
form.pennyspace3quarter.value=Math.round(temp5)/10000;
temp5=(temp2/va)*1000000;
form.percentspace3quarter.value=Math.round(temp5)/10000;
form.forspace3quarter.value=temp2*fsr;

temp3=((1902)*(Math.pow(both,0.0100))-2016)*100*is*ex*0.973;
if (temp3>temp){temp3=temp}
temp3=temp3*1.65;
temp2=(Math.round(temp3))/100;
form.transspace3quarter.value=temp2;


temp=((2.1164)*(Math.pow(both,0.201))+115)*100*is*ex;
temp3=temp*2.30;
temp2=(Math.round(temp3))/100;
form.spacefull.value=temp2;
temp5=(temp2/vc)*1000000;
form.pennyspacefull.value=Math.round(temp5)/10000;
temp5=(temp2/va)*1000000;
form.percentspacefull.value=Math.round(temp5)/10000;
form.forspacefull.value=temp2*fsr;

temp3=((327)*(Math.pow(both,0.0390))-474)*100*is*ex*0.973;
if (temp3>temp){temp3=temp}
temp3=temp3*2.30;
temp2=(Math.round(temp3))/100;
form.transspacefull.value=temp2;

temp=((2.1164)*(Math.pow(both,0.201))+115)*100*is*ex;
temp3=temp*3.20;
temp2=(Math.round(temp3))/100;
form.spacedouble.value=temp2;
temp5=(temp2/vc)*1000000;
form.pennyspacedouble.value=Math.round(temp5)/10000;
temp5=(temp2/va)*1000000;
form.percentspacedouble.value=Math.round(temp5)/10000;
form.forspacedouble.value=temp2*fsr;

temp3=((327)*(Math.pow(both,0.0390))-474)*100*is*ex*0.973;
if (temp3>temp){temp3=temp}
temp3=temp3*3.20;
temp2=(Math.round(temp3))/100;
form.transspacedouble.value=temp2;

temp3=temp*4.700;
temp2=(Math.round(temp3))/100;
form.spacefront.value=temp2;
form.forspacefront.value=temp2*fsr;
temp5=(temp2/vc)*1000000;
form.pennyspacefront.value=Math.round(temp5)/10000;
temp5=(temp2/va)*1000000;
form.percentspacefront.value=Math.round(temp5)/10000;
//form.forspacefront.value=vcs;

temp3=((327)*(Math.pow(both,0.0390))-474)*100*is*ex*0.973;
if (temp3>temp){temp3=temp}
temp3=temp3*4.70;
temp2=(Math.round(temp3))/100;
form.transspacefront.value=temp2;

temp=((2.1164)*(Math.pow(both,0.201))+115)*100*is*ex;
temp3=temp*3.6;
temp2=(Math.round(temp3))/100;
form.spaceback.value=temp2;
temp5=(temp2/vc)*1000000;
form.pennyspaceback.value=Math.round(temp5)/10000;
temp5=(temp2/va)*1000000;
form.percentspaceback.value=Math.round(temp5)/10000;
form.forspaceback.value=temp2*fsr;
//form.forspaceback.value=vc;

temp3=((327)*(Math.pow(both,0.0390))-474)*100*is*ex*0.973;
//if (temp3>temp){temp3=temp}
temp3=temp3*3.60;
temp2=(Math.round(temp3))/100;
form.transspaceback.value=temp2;

temp=((2.1164)*(Math.pow(both,0.201))+115)*100*is*ex;
temp3=temp*3.6;
temp2=(Math.round(temp3))/100;
form.spacegate.value=temp2;
temp5=(temp2/vc)*1000000;
form.pennyspacegate.value=Math.round(temp5)/10000;
temp5=(temp2/va)*1000000;
form.percentspacegate.value=Math.round(temp5)/10000;
form.forspacegate.value=temp2*fsr;
//form.forspacegate.value=vcs.length;

temp3=((327)*(Math.pow(both,0.0390))-474)*100*is*ex*0.973;
if (temp3>temp){temp3=temp}
temp3=temp3*3.60;
temp2=(Math.round(temp3))/100;
form.transspacegate.value=temp2;

//form.spacequarter.value=both;
//form.spacehalf.value=Math.pow(both,0.096);
//form.space3quarter.value=temp4;
//form.spacefull.value=(100*(Math.pow(both,0.096))-100)*100;

//form.spaceback.value=vyear;
//form.spacegate.value=yd;

// Calculate Reprint Rates

temp2=66.769*(Math.pow(vr,0.1944))/256;
temp=(temp2*(400)*(Math.pow(both,0.03))+0)*100*ir*ex;
temp2=(Math.round(temp))/100;
form.reprintquarter.value=temp2;
form.forreprintquarter.value=temp2*frr;
temp3=temp*1.30;
temp2=(Math.round(temp3))/100;
form.reprinthalf.value=temp2;
form.forreprinthalf.value=temp2*frr;
temp3=temp*1.65;
temp2=(Math.round(temp3))/100;
form.reprint3quarter.value=temp2;
form.forreprint3quarter.value=temp2*frr;
temp3=temp*2.30;
temp2=(Math.round(temp3))/100;
form.reprintfull.value=temp2;
form.forreprintfull.value=temp2*frr;
temp3=temp*3.20;
temp2=(Math.round(temp3))/100;
form.reprintdouble.value=temp2;
form.forreprintdouble.value=temp2*frr;
temp3=temp*4.7;
temp2=(Math.round(temp3))/100;
form.reprintfront.value=temp2;
form.forreprintfront.value=temp2*frr;
temp3=temp*3.6;
temp2=(Math.round(temp3))/100;
form.reprintback.value=temp2;
form.forreprintback.value=temp2*frr;
temp3=temp*3.6;

temp2=(Math.round(temp3))/100;
form.reprintgate.value=temp2;
form.forreprintgate.value=temp2*frr;

// Calculate Web Rates

area2=(240*240*60*60);
dimension=0.277*(Math.pow(area2,0.202));
temp3=(0.166*vc*va);
middle=Math.pow(temp3,0.122)+0;
duration=(0.3443*(Math.pow(vd,0.4301)));
temp2=(dimension*middle*duration*100)*ex;
if (temp2<12500){temp2=12500}
temp4=(Math.round(temp2)/100);
form.webbut.value=temp4;
temp4=(Math.round(temp2*1.5)/100);
form.homebut.value=temp4;
temp4=(Math.round(temp2*fwr)/100);
form.forwebbut.value=temp4;
temp4=(Math.round(temp2*1.5*fwr)/100);
form.forhomebut.value=temp4;

area2=(320*320*240*240);
dimension=0.277*(Math.pow(area2,0.202));
temp3=(0.166*vc*va);
middle=Math.pow(temp3,0.122)+0;
duration=(0.3443*(Math.pow(vd,0.4301)));
temp2=(dimension*middle*duration*100)*ex;
if (temp2<12500){temp2=12500}
temp4=(Math.round(temp2)/100);
form.webquarter.value=temp4;
temp4=(Math.round(temp2*1.5)/100);
form.homequarter.value=temp4;
temp4=(Math.round(temp2*fwr)/100);
form.forwebquarter.value=temp4;
temp4=(Math.round(temp2*1.5*fwr)/100);
form.forhomequarter.value=temp4;

area2=(640*640*240*240);
dimension=0.277*(Math.pow(area2,0.202));
temp3=(0.166*vc*va);
middle=Math.pow(temp3,0.122)+0;
duration=(0.3443*(Math.pow(vd,0.4301)));
temp2=(dimension*middle*duration*100)*ex;
if (temp2<12500){temp2=12500}
temp4=(Math.round(temp2)/100);
form.webhalf.value=temp4;
temp4=(Math.round(temp2*1.5)/100);
form.homehalf.value=temp4;
temp4=(Math.round(temp2*fwr)/100);
form.forwebhalf.value=temp4;
temp4=(Math.round(temp2*1.5*fwr)/100);
form.forhomehalf.value=temp4;

area2=(640*640*480*480);
dimension=0.277*(Math.pow(area2,0.202));
temp3=(0.166*vc*va);
middle=Math.pow(temp3,0.122)+0;
duration=(0.3443*(Math.pow(vd,0.4301)));
temp2=(dimension*middle*duration*100)*ex;
if (temp2<12500){temp2=12500}
temp4=(Math.round(temp2)/100);
form.webfull.value=temp4;
temp4=(Math.round(temp2*1.5)/100);
form.homefull.value=temp4;
temp4=(Math.round(temp2*fwr)/100);
form.forwebfull.value=temp4;
temp4=(Math.round(temp2*1.5*fwr)/100);
form.forhomefull.value=temp4;

area2=(vh*vh*vw*vw);
dimension=0.277*(Math.pow(area2,0.202));
temp3=(0.166*vc*va);
middle=Math.pow(temp3,0.122)+0;
duration=(0.3443*(Math.pow(vd,0.4301)));
temp2=(dimension*middle*duration*100)*ex;
if (temp2<12500){temp2=12500}
temp4=(Math.round(temp2)/100);
form.webcustom.value=temp4;
temp4=(Math.round(temp2*1.5)/100);
form.homecustom.value=temp4;
temp4=(Math.round(temp2*fwr)/100);
form.forwebcustom.value=temp4;
temp4=(Math.round(temp2*1.5*fwr)/100);
form.forhomecustom.value=temp4;
}

function reset_it(form) {
    form.amount.value="";
    form.converted.value="";
    i="";
    j="";
}