var x=0;
var ct=0;
var ct1=0;
var m$="Please answer all the questions";
var p2$="";
var p3$="";
var p4$="";

var mydate= new Date();
var theyear=mydate.getFullYear();
var themonth=mydate.getMonth()+1;
var theday=mydate.getDate();
var thehour=mydate.getHours();
var themin=mydate.getMinutes();

function begin(){
ct=0;
ct1=0;
p2$="";
p3$="";
p4$="";
m$="Please answer all the questions";

document.forms.matrix.S1.value="Describe your premonition here in as much detail as you can";
document.forms.matrix.Text1.value="  Please read the following important information";
document.forms.matrix.Text2.value="  Click Confirm to finalize your premonition data";
document.forms.matrix.USR.value="Username (Optional)";
document.forms.matrix.B1.value="Confirm";

document.forms.matrix.D1.disabled=false;
document.forms.matrix.D2.disabled=false;
document.forms.matrix.D3.disabled=false;
document.forms.matrix.D4.disabled=false;
document.forms.matrix.D5.disabled=false;
document.forms.matrix.D6.disabled=false;
document.forms.matrix.D9.disabled=false;
document.forms.matrix.D10.disabled=false;
document.forms.matrix.D11.disabled=false;
document.forms.matrix.D12.disabled=false;
document.forms.matrix.D13.disabled=false;
document.forms.matrix.D14.disabled=false;
document.forms.matrix.S1.disabled=false;

document.forms.matrix.Text1.disabled=true;
document.forms.matrix.Text2.disabled=true;
document.forms.matrix.USR.disabled=false;

document.forms.matrix.Publish[0].disabled=false;
document.forms.matrix.Publish[1].disabled=false;

document.forms.matrix.D1.selectedIndex=0;
document.forms.matrix.D2.selectedIndex=0;
document.forms.matrix.D3.selectedIndex=0;
document.forms.matrix.D4.selectedIndex=0;
document.forms.matrix.D5.selectedIndex=0;
document.forms.matrix.D6.selectedIndex=0;
document.forms.matrix.D7.selectedIndex=0;
document.forms.matrix.D9.selectedIndex=0;
document.forms.matrix.D10.selectedIndex=0;
document.forms.matrix.D11.selectedIndex=0;
document.forms.matrix.D12.selectedIndex=0;
document.forms.matrix.D13.selectedIndex=0;
document.forms.matrix.D14.selectedIndex=0;
document.forms.matrix.Publish[1].checked=true;

clr7();
}

function evch(){
document.forms.matrix.D7.selectedIndex=0;
document.forms.matrix.D7.disabled=false;

if(document.forms.matrix.D4.selectedIndex==1){
document.forms.matrix.D7.options[0].text="Event sub-type?";
document.forms.matrix.D7.options[1].text="Earthquake";
document.forms.matrix.D7.options[2].text="Tsunami";
document.forms.matrix.D7.options[3].text="Volcanic eruption";
document.forms.matrix.D7.options[4].text="Storm";
document.forms.matrix.D7.options[5].text="Tornado";
document.forms.matrix.D7.options[6].text="Blizzard";
document.forms.matrix.D7.options[7].text="Avalanche";
document.forms.matrix.D7.options[8].text="Drought";
document.forms.matrix.D7.options[9].text="Flood";
document.forms.matrix.D7.options[10].text="Wildfire";
document.forms.matrix.D7.options[11].text="Landslide";
document.forms.matrix.D7.options[12].text="Epidemic";
document.forms.matrix.D7.options[13].text="Famine";
document.forms.matrix.D7.options[14].text="Impact from space";
document.forms.matrix.D7.options[15].text="Other natural disaster";
}

if(document.forms.matrix.D4.selectedIndex==2){
document.forms.matrix.D7.options[0].text="Event sub-type?";
document.forms.matrix.D7.options[1].text="Car accident";
document.forms.matrix.D7.options[2].text="Coach / bus accident";
document.forms.matrix.D7.options[3].text="Aircraft accident";
document.forms.matrix.D7.options[4].text="Railway accident";
document.forms.matrix.D7.options[5].text="Shipping accident";
document.forms.matrix.D7.options[6].text="Oil platform accident";
document.forms.matrix.D7.options[7].text="Underwater accident";
document.forms.matrix.D7.options[8].text="Space accident";
document.forms.matrix.D7.options[9].text="Mining accident";
document.forms.matrix.D7.options[10].text="Mountaineering accident";
document.forms.matrix.D7.options[11].text="Caving accident";
document.forms.matrix.D7.options[12].text="Nuclear accident";
document.forms.matrix.D7.options[13].text="Chemical accident";
document.forms.matrix.D7.options[14].text="Workplace accident";
document.forms.matrix.D7.options[15].text="Other accident";
}

if(document.forms.matrix.D4.selectedIndex==3){
document.forms.matrix.D7.options[0].text="Event sub-type?";
document.forms.matrix.D7.options[1].text="Bombing";
document.forms.matrix.D7.options[2].text="Mass shooting";
document.forms.matrix.D7.options[3].text="Arson attack";
document.forms.matrix.D7.options[4].text="Chemical attack";
document.forms.matrix.D7.options[5].text="Biological attack";
document.forms.matrix.D7.options[6].text="Radiological attack";
document.forms.matrix.D7.options[7].text="Building hijack";
document.forms.matrix.D7.options[8].text="Coach / bus hijack";
document.forms.matrix.D7.options[9].text="Railway hijack";
document.forms.matrix.D7.options[10].text="Aircraft hijack";
document.forms.matrix.D7.options[11].text="Shipping hijack";
document.forms.matrix.D7.options[12].text="Political assassination";
document.forms.matrix.D7.options[13].text="Internet attack";
document.forms.matrix.D7.options[14].text="Financial terrorism";
document.forms.matrix.D7.options[15].text="Other terrorist act";
}

if(document.forms.matrix.D4.selectedIndex==4){
document.forms.matrix.D7.options[0].text="Event sub-type?";
document.forms.matrix.D7.options[1].text="Mass shooting";
document.forms.matrix.D7.options[2].text="Other murder";
document.forms.matrix.D7.options[3].text="Bank heist";
document.forms.matrix.D7.options[4].text="Jewellery heist";
document.forms.matrix.D7.options[5].text="Other burglary";
document.forms.matrix.D7.options[6].text="Vehicle theft";
document.forms.matrix.D7.options[7].text="Vandalism";
document.forms.matrix.D7.options[8].text="Arson";
document.forms.matrix.D7.options[9].text="Sexual assault / Rape";
document.forms.matrix.D7.options[10].text="Violent assault";
document.forms.matrix.D7.options[11].text="Kidnapping";
document.forms.matrix.D7.options[12].text="Child abuse";
document.forms.matrix.D7.options[13].text="Cruelty to animals";
document.forms.matrix.D7.options[14].text="Fraud / Financial crime";
document.forms.matrix.D7.options[15].text="Other crime";
}

if(document.forms.matrix.D4.selectedIndex==5){
document.forms.matrix.D7.options[0].text="Event sub-type?";
document.forms.matrix.D7.options[1].text="Sports result";
document.forms.matrix.D7.options[2].text="Game show result";
document.forms.matrix.D7.options[3].text="Lottery result";
document.forms.matrix.D7.options[4].text="Other game result";
document.forms.matrix.D7.options[5].text="Media awards result";
document.forms.matrix.D7.options[6].text="Literary award";
document.forms.matrix.D7.options[7].text="Other award / prize";
document.forms.matrix.D7.options[8].text="Examination result";
document.forms.matrix.D7.options[9].text="Political nomination";
document.forms.matrix.D7.options[10].text="Political election result";
document.forms.matrix.D7.options[11].text="Other election result";
document.forms.matrix.D7.options[12].text="Trial verdict";
document.forms.matrix.D7.options[13].text="Appeal outcome";
document.forms.matrix.D7.options[14].text="Financial outcome";
document.forms.matrix.D7.options[15].text="Other competition / verdict";
}

if(document.forms.matrix.D4.selectedIndex==6){
document.forms.matrix.D7.options[0].text="Event sub-type?";
document.forms.matrix.D7.options[1].text="Birth";
document.forms.matrix.D7.options[2].text="New relationship";
document.forms.matrix.D7.options[3].text="Marriage";
document.forms.matrix.D7.options[4].text="Divorce";
document.forms.matrix.D7.options[5].text="Separation";
document.forms.matrix.D7.options[6].text="Illness";
document.forms.matrix.D7.options[7].text="Injury";
document.forms.matrix.D7.options[8].text="Dismissal";
document.forms.matrix.D7.options[9].text="Arrest";
document.forms.matrix.D7.options[10].text="Retirement";
document.forms.matrix.D7.options[11].text="Change of abode";
document.forms.matrix.D7.options[12].text="Change of occupation";
document.forms.matrix.D7.options[13].text="Change of name";
document.forms.matrix.D7.options[14].text="Change of title";
document.forms.matrix.D7.options[15].text="Death";
}

if((document.forms.matrix.D4.selectedIndex==0)||(document.forms.matrix.D4.selectedIndex==7)){
clr7();
}
}

function clr7(){
document.forms.matrix.D7.options[0].text="";
document.forms.matrix.D7.options[1].text="";
document.forms.matrix.D7.options[2].text="";
document.forms.matrix.D7.options[3].text="";
document.forms.matrix.D7.options[4].text="";
document.forms.matrix.D7.options[5].text="";
document.forms.matrix.D7.options[6].text="";
document.forms.matrix.D7.options[7].text="";
document.forms.matrix.D7.options[8].text="";
document.forms.matrix.D7.options[9].text="";
document.forms.matrix.D7.options[10].text="";
document.forms.matrix.D7.options[11].text="";
document.forms.matrix.D7.options[12].text="";
document.forms.matrix.D7.options[13].text="";
document.forms.matrix.D7.options[14].text="";
document.forms.matrix.D7.options[15].text="";
document.forms.matrix.D7.disabled=true;
}

function cleartext(){
if(ct==1){return;}
ct=1;
document.forms.matrix.S1.value="";
}

function cleartext2(){
if(ct1==1){return;}
ct1=1;
document.forms.matrix.USR.value="";
}

function subprem(){
chkinp();
}

function chkinp(){

//calcref();return; // DISABLE THIS CONTROL IN PUBLISHED VERSION

if (document.forms.matrix.D1.selectedIndex==0){alert(m$);return;}
if (document.forms.matrix.D2.selectedIndex==0){alert(m$);return;}
if (document.forms.matrix.D3.selectedIndex==0){alert(m$);return;}
if (document.forms.matrix.D4.selectedIndex==0){alert(m$);return;}
if (document.forms.matrix.D5.selectedIndex==0){alert(m$);return;}
if (document.forms.matrix.D6.selectedIndex==0){alert(m$);return;}
if((document.forms.matrix.D4.selectedIndex<7)&&(document.forms.matrix.D7.selectedIndex==0)){alert(m$);return;}
if (document.forms.matrix.D9.selectedIndex==0){alert(m$);return;}
if (document.forms.matrix.D10.selectedIndex==0){alert(m$);return;}
if (document.forms.matrix.D11.selectedIndex==0){alert(m$);return;}
if (document.forms.matrix.D12.selectedIndex==0){alert(m$);return;}
if (document.forms.matrix.D13.selectedIndex==0){alert(m$);return;}
if (document.forms.matrix.D14.selectedIndex==0){alert(m$);return;}
calcref();
}

function calcref(){
if(document.forms.matrix.B1.value=="Submit"){conf();return;}
lockall();
mydate= new Date();
theyear=mydate.getFullYear();
themonth=mydate.getMonth()+1;
theday=mydate.getDate();
thehour=mydate.getHours();
themin=mydate.getMinutes();

p3$=String(theyear);
p3$=p3$.substring(2);

p4$=String(themonth);
if(themonth<10){p4$="0"+p4$;}
p3$=p3$+p4$;

p4$=String(theday);
if(theday<10){p4$="0"+p4$;}
p3$=p3$+p4$+"-";

p4$=String(thehour);
if(thehour<10){p4$="0"+p4$;}
p3$=p3$+p4$;

p4$=String(themin);
if(themin<10){p4$="0"+p4$;}
p3$=p3$+p4$+String(document.forms.matrix.D1.selectedIndex)+String(document.forms.matrix.D2.selectedIndex)+"-";

p4$=String(document.forms.matrix.D3.selectedIndex);
if(document.forms.matrix.D3.selectedIndex<100){p4$="0"+p4$;}
if(document.forms.matrix.D3.selectedIndex<10){p4$="0"+p4$;}

p3$=p3$+p4$+String(document.forms.matrix.D4.selectedIndex)+
+String(document.forms.matrix.D5.selectedIndex)+String(document.forms.matrix.D6.selectedIndex)+"-";
p4$=String(document.forms.matrix.D7.selectedIndex);
if(document.forms.matrix.D7.selectedIndex<10){p4$="0"+p4$;}
p3$=p3$+p4$+String(document.forms.matrix.D9.selectedIndex)+String(document.forms.matrix.D10.selectedIndex)
+String(document.forms.matrix.D11.selectedIndex)+String(document.forms.matrix.D12.selectedIndex)+"-";
p4$=String(document.forms.matrix.D13.selectedIndex);
if(document.forms.matrix.D13.selectedIndex<10){p4$="0"+p4$;}
p3$=p3$+p4$;
p4$=String(document.forms.matrix.D14.selectedIndex);
if(document.forms.matrix.D14.selectedIndex<100){p4$="0"+p4$;}
if(document.forms.matrix.D14.selectedIndex<10){p4$="0"+p4$;}
p3$=p3$+p4$;
if(document.forms.matrix.Publish[0].checked==true){p3$=p3$+"0";document.forms.matrix.H2.value="Yes";}
if(document.forms.matrix.Publish[1].checked==true){p3$=p3$+"1";document.forms.matrix.H2.value="No";}
p2$=document.forms.matrix.S1.value;
document.forms.matrix.Text2.value="  Write down Premonition ID or print this page, then click Submit";
document.forms.matrix.Text1.value=" Premonition ID:  "+p3$;
document.forms.matrix.H1.value=p3$;
document.forms.matrix.B1.value="Submit";
}

function conf(){
document.forms.matrix.D1.disabled=false;
document.forms.matrix.D2.disabled=false;
document.forms.matrix.D3.disabled=false;
document.forms.matrix.D4.disabled=false;
document.forms.matrix.D5.disabled=false;
document.forms.matrix.D6.disabled=false;
document.forms.matrix.D7.disabled=false;
document.forms.matrix.D9.disabled=false;
document.forms.matrix.D10.disabled=false;
document.forms.matrix.D11.disabled=false;
document.forms.matrix.D12.disabled=false;
document.forms.matrix.D13.disabled=false;
document.forms.matrix.D14.disabled=false;
document.forms.matrix.S1.disabled=false;
document.forms.matrix.USR.disabled=false;
document.forms.matrix.submit();
}

function lockall(){
document.forms.matrix.D1.disabled=true;
document.forms.matrix.D2.disabled=true;
document.forms.matrix.D3.disabled=true;
document.forms.matrix.D4.disabled=true;
document.forms.matrix.D5.disabled=true;
document.forms.matrix.D6.disabled=true;
document.forms.matrix.D7.disabled=true;
document.forms.matrix.D9.disabled=true;
document.forms.matrix.D10.disabled=true;
document.forms.matrix.D11.disabled=true;
document.forms.matrix.D12.disabled=true;
document.forms.matrix.D13.disabled=true;
document.forms.matrix.D14.disabled=true;
document.forms.matrix.S1.disabled=true;
document.forms.matrix.USR.disabled=true;
document.forms.matrix.Publish[0].disabled=true;
document.forms.matrix.Publish[1].disabled=true;
}