
//////////////////////////////////////////////////////////////////////////
//	Javascript for Page Functions 					//
//////////////////////////////////////////////////////////////////////////

function ToggleAreas(x)
	{
	var age = document.getElementById('ages').style;
	var bdy = document.getElementById('bodypart').style;
	var occ = document.getElementById('occlist').style;
	var std = document.getElementById('standards').style;
	var ogl = document.getElementById('earningloss').style;

	var lists = new Array(age, bdy, occ, std, ogl);

	for (i=0;i<lists.length;i++) {if (i!=x) {lists[i].display="none";}}

	if (x==1) {GetABody()}

	toggle = (lists[x].display=="none") ? lists[x].display="block" : lists[x].display="none";
	}

function HandS(x)
	{
	if((document.getElementById('xcomment'+x).checked==true) || (document.getElementById('comment'+x).style.display=='none'))
		{document.getElementById('comment'+x).style.display='inline';}
	else	{document.getElementById('comment'+x).style.display='none';}
	}

function changesched(x)
	{  
//	document.getElementById('body').value='';

	if (x==0) 		{document.getElementById('oldsched').checked=true; document.getElementById("std").style.display='inline'; document.getElementById("wpi").style.display='none'; document.getElementById("elossb").style.display='none'; document.getElementById("elossi").style.display='none'; document.getElementById("stnd").style.width='64px';  }
	else if (x==1)	{document.getElementById('newsched').checked=true; document.getElementById("std").style.display='none'; document.getElementById("wpi").style.display='inline'; document.getElementById("elossb").style.display='none'; document.getElementById("elossi").style.display='none'; document.getElementById("stnd").style.width='36px';   }
	else if (x==2)	{document.getElementById('ogilvie').checked=true; document.getElementById("std").style.display='none'; document.getElementById("wpi").style.display='inline'; document.getElementById("elossb").style.display='inline'; document.getElementById("elossi").style.display='inline'; document.getElementById("stnd").style.width='36px';  }
//	return false;
	}

function notify(x,y)
	{
	document.getElementById('message2').style.color=y;
	document.getElementById('message2').innerHTML=x; 
	}

function clearnotify(x)
	{
	setTimeout('document.getElementById("message2").innerHTML=""',x);
	}

function closeAll(a)
	{
	x = new Array("eamsbody","eamsdoctitle","dwcforms","dwc2eams","eamsoffices","rating","pdvalue","lifeex","lifepen","awwage","datecalc","interest","ttd","wageloss","ptdisability","dfec","xyzzxsjo2","retrobene");
	if (a=='advancedinfo' || a=='mdtarea' || a=='cvcarea') {x[0]=a;}
	for (i in x) { if (x[i]!=a) { document.getElementById(x[i]).style.display="none";} }
	}

function HandSB(x)
	{
	if (x == 'objectives' || x == 'standards' || x == 'workrearea' )
		{ }
	else { closeAll(x); }

	var disp = document.getElementById(x).style;
	if ((disp.display=='none') || (disp.display==''))
		{disp.display='block';}
	else	{disp.display='none';}
	}

//////////////////////////////////////////////////////////////////////////
//	Earnings Loss Functions 						//
//////////////////////////////////////////////////////////////////////////

function PlaceEarningsLoss(x)
	{
	piea = document.getElementById('earninglosspiea').value;
	piesse = document.getElementById('earninglosspiesse').value;
	document.getElementById('elossi').value=Math.round((1-(piea/piesse))*10000)/100;
	ToggleAreas(4);
	}

//////////////////////////////////////////////////////////////////////////
//	Body Code Functions 						//
//////////////////////////////////////////////////////////////////////////

function PlaceBodyCode(x,y,z)
	{
	document.getElementById('body').value=x;
	document.getElementById('bdytitle').value=y;
	if (x=="14.01.00.00")
		{ openGAF(); }
	else 
		{ ToggleAreas(1); }
	}

//////////////////////////////////////////////////////////////////////////
//	Occupational Code Functions 					//
//////////////////////////////////////////////////////////////////////////

function PlaceOccupationalCode(x,y)
	{
	document.getElementById('occc').value=x;
	document.getElementById('occtitle').value=y;
	ToggleAreas(2);
	}

//////////////////////////////////////////////////////////////////////////
//	Work Restrictions Functions 					//
//////////////////////////////////////////////////////////////////////////

function PlaceStandard(x,y)
	{
	if (x==0) {x='objectives';}
	if (x==1) {x='standards';}
	if (x==2) {x='workrearea';}
//	HandSB(x);
//	HandSB('standards');
	document.getElementById(x).style.display='none';
	document.getElementById('stnd').value=y;
	}

//////////////////////////////////////////////////////////////////////////
//	Standard Functions 						//
//////////////////////////////////////////////////////////////////////////

function Hstds(x)
	{
	document.getElementById('objectives').style.display='none';
	document.getElementById('subjectives').style.display='none';
	document.getElementById('workrearea').style.display='none';
	document.getElementById(x).style.display='block';
	}

//////////////////////////////////////////////////////////////////////////
//	Rating Functions 						//
//////////////////////////////////////////////////////////////////////////

function onemore()
	{
	var last = document.getElementById('linelast');
	last.value++;
	var whereto = document.getElementById('calcoutputs');
	var x='<input id=line'+last.value+' type=radio name=line value='+last.value+' checked class=cl1 onclick="linenowo('+last.value+')" /> '
		+'<input id=ratingout'+last.value+' type=text class=cl2 readonly /> '
		+'<input id=xcomment'+last.value+' type=checkbox class=cl3 onclick="HandS('+last.value+')"/> '
		+'<input id=comment'+last.value+' type=text value="Comments." class=cl4 /><br>';
	whereto.innerHTML+=x;
	for (i=0;i<last.value;i++)
		{ document.getElementById('line'+last.value).checked=false; }
	document.getElementById('line'+last.value).checked=true;
	linenowo(last.value);
	}

function linenowo(x)
	{ document.getElementById('linenow').value=x; }


function delrating()
	{
	var x = document.getElementById('linenow').value;
	document.getElementById('ratingout'+x).value="";
	document.getElementById('comment'+x).value="Comments."
	}

function elementExists(x)
	{
	if (document.getElementById(x) != null) 
		{ return true; } 
	else 
		{ return false; }
	}

	
//////////////////////////////////////////////////////////////////////////
//	Javascript for Page Functions 					//
//////////////////////////////////////////////////////////////////////////

function report(x,y)
	{
	var last = document.getElementById('linelast').value;

	url = "?";
	for (i=0;i<last*1+1;i++)
		{
		url+="&r"+i+"="+escape(document.getElementById("ratingout"+i).value);
		url+="&c"+i+"="+escape(document.getElementById("comment"+i).value);
		}
	url+="&linelast="+document.getElementById('linelast').value;
	url+="&advanced="+document.getElementById('advancedinfo').style.display;
	url+="&applicant="+escape(document.getElementById('applicant').value);
	url+="&wcab="+escape(document.getElementById('wcab').value);
	url+="&filenumber="+escape(document.getElementById('filenumber').value);
	url+="&doctor="+escape(document.getElementById('doctor').value);
	url+="&reportdate="+escape(document.getElementById('reportdate').value);
	url+="&ptpqmeame="+document.getElementById('ptpqmeame').value;	
	url+="&majorcomments="+escape(document.getElementById('majorcomments').value);
	url+="&BM="+escape(document.getElementById('aDOB').value);
	url+="&BD="+escape(document.getElementById('aDOB').value);
	url+="&BY="+escape(document.getElementById('aDOB').value);
	url+="&todo=1";
//	url+="&todo="+x;
//	url+="&towho="+escape(y);

//	var reporter = window.open("",'reporthere','height=600,width=800,toolbar=no,status=no,menubar=no,location=no,scrollbars=yes,resizable=1');

	makePOSTRequest("http://www.pdrater.com/pdrater/php/report.php", url, "", 2);
	}

function doemail()
	{
	alert();	
	}
//////////////////////////////////////////////////////////////////////////
//	Rating Functions 						//
//////////////////////////////////////////////////////////////////////////

function val(x)
	{
	var b = new Array(document.getElementById('agei'),document.getElementById('body'),document.getElementById('occc'),document.getElementById('stnd'),document.getElementById('frct'));

	var a = b[1].value.split('.');

	var c = new Array(document.getElementById('aoi'),document.getElementById('bdy'),document.getElementById('occ'),document.getElementById('std'),document.getElementById('wpi'),document.getElementById('frc'));

//	var a = b[4].value.split("/");

	for (each in c)
		{ c[each].style.color='black'; c[each].style.fontWeight='normal'; }
	var d = new Array(1.1,1.3,1.4,1.5,1.6,1.7,1.8,2.1,2.2,2.3,2.4,2.6,2.7,3.1,4.1,4.3,4.4,4.5,4.7,5.2,5.3,6.1,6.2,7.1,7.3,7.5,7.6,7.7,8.1,8.2,8.3,8.4,8.5,9.1,9.2,9.3,9.4,9.5,10.5,11.1,11.3,11.5,12.1,12.3,13.1,13.2,14.1,14.2,14.3,14.4,14.5,14.6,14.7,14.8);
	var d0 = 0;
	for (each in d)
		{if (d[each]==Math.floor(b[1].value*10)/10) {d0=1;} }

	var e = new Array(110,111,112,120,210,211,212,213,214,220,221,230,240,250,251,290,310,311,320,321,322,330,331,332,340,341,350,351,360,370,380,390,420,430,460,470,480,481,482,490,491,492,560,590);
	var e0 = 0;
	for (each in e)
		{if (e[each]==b[2].value) {e0=1;} }

	notify('','black');


	if (b[0].value>0) {b[0].value=Math.round(b[0].value);}
	if (b[3].value>0) {b[3].value=Math.round(b[3].value);}
	
	var f0=0; 
	if (b[4].value!='')
		{
		if ((b[4].value>0)&&(b[4].value<1)) 
			{ f0=b[4].value; }
		else if ((b[4].value.indexOf('%')==b[4].value.length-1) && (b[4].value.substring(0,b[4].value.length-1)<100))
			{ f0=b[4].value.substring(0,b[4].value.length-1)/100; }
		else if ((b[4].value.indexOf('/')>0)&&(a.length==2)&&(b[4].value.indexOf('/')!=b[4].value.length-1)&&(b[4].value.length>2)&&(eval(a[1])>1)&&(eval(a[0])<eval(a[1])))
			{ f0 = Math.round(10000*eval(b[4].value))/10000; }
		}

	if (!(b[0].value>0))
		{
		c[0].style.color='red'; c[0].style.fontWeight='bold';
		notify('Please enter an age in years.  Try using the "Age" button.','red');
		b[0].select();
		}
	else if ((document.getElementById('oldsched').checked) && (d0<1))
		{
		c[1].style.color='red'; c[1].style.fontWeight='bold';
		notify('Please enter a 1997 body part code.  Try using the "Body Part" button.','red');
		b[1].select();
		}
//	else if ((document.getElementById('newsched').checked==true) && (!(a.length==4) || !((a[0]>-1) || (a[1]>-1) || (a[2]>-1) || (a[3]>-1))))
	else if ((document.getElementById('newsched').checked==true) && (!(a.length==4) || !(b[1].value.length==11) || !(a[0]>-1) || !(a[1]>-1) || !(a[2]>-1) || !(a[3]>-1)))
		{
		c[1].style.color='red'; c[1].style.fontWeight='bold';
		notify('Please enter a 2005 body part code.  Try using the "Body Part" button.','red');
		b[1].select();
		}
	else if (e0<1)
		{
		c[2].style.color='red'; c[2].style.fontWeight='bold';
		notify('Please enter an occupational code.  Try using the "Occupation" button.','red');
		b[2].select();
		}

	else if (!(b[3].value>0)|| !(b[3].value<100))
		{
		if (c[4].style.display=='none')
			{
			c[3].style.color='red'; c[3].style.fontWeight='bold';
			notify('Please enter a standard disability between 0 and 100.','red');
			}
		else { notify('Please enter a whole person impairment between 0 and 100.','red'); }
		b[3].select();
		}

	else if ((f0==0)&&(b[4].value!=''))
		{
		c[5].style.color='red'; 
		notify('If applicable, please enter a fraction, decimal, or percentage.','red');
		b[4].select();
		}

	else { rater(document.getElementById('oldsched').checked,f0); }
	}

//////////////////////////////////////////////////////////////////////////
//	E-mail Functions 						//
//////////////////////////////////////////////////////////////////////////

function checkEmailBeforeSend()
	{ return true; }

function checkEmailBeforeSend1()
	{
	var emailID=document.getElementById("emailreport");
	
	if ((emailID.value==null)||(emailID.value==""))
		{
		bademail();
		return false;
		}
	if (echeck(emailID.value)==false)
		{
		bademail();
		return false;
		}
	else 	{ 
	 	report(1,emailID.value);
		notify('Your report has been e-mailed.','black');
		clearnotify(5000);
		}
	}

function getEmail()
	{
	document.getElementById('message2').style.color="black";
	var x = "E-mail Address: <input id=emailreport><input type=button value=Send onclick='checkEmailBeforeSend()'>";
	if ( document.getElementById('message2').innerHTML == x) { document.getElementById('message2').innerHTML=""; }
	else { document.getElementById('message2').innerHTML=x;  }
	}

function checkaddress()
	{
	var emailID=document.getElementById("visitormail");
	
	if (emailID.value==null || emailID.value=="" || echeck(emailID.value)==false)
		{
		bademail();
		return false;
		}
	else 	{ 
		sendUserEmail(emailID.value,document.getElementById('notes').value);
		}
	}

function sendUserEmail(x,y)
	{var poststr = "email="+escape(x)+"&message="+escape(y);
	makePOSTRequest('function/sendmail.php', poststr,'goodmail',0);
	}