// JavaScript Document

function Slashes(s)

{

  var ss='';

  for (var i=0; i<s.length; i++)

    if (s.charAt(i)=="'") ss=ss+"\\"+s.charAt(i); else ss=ss+s.charAt(i);

  return ss;	

}



function time_EUR_to_US(EURtime)

{

  var h=eval(EURtime.substr(0,2));

  var m=EURtime.substr(3,2);

  var ampm;

  if (h==0) {ampm='AM'; h=12;}

  else

    if (h<12) {ampm='AM';}

    else

      {ampm='PM'; h=h-12;}

  UStime=h+':'+m+' '+ampm;

  return UStime;

}



function time_US_to_EUR(UStime)

{

}



function TodayDate()

{

  var ie = !!window.ActiveXObject;



  var TDate = new Date(); 

  var month=TDate.getMonth()+1;      

  if (month<10) month='0'+month; 

  var day=TDate.getDate();     

  if (day<10) day='0'+day; 

  var year;

  if (ie) year=TDate.getYear(); else year=TDate.getYear()+1900;

  var curr_date=year+'-'+month+'-'+day;

  return curr_date;

}



function calc_date(date,dx)

{

 var array_days_count = new Array(31,28,31,30,31,30,31,31,30,31,30,31); 



 var y=eval(date.substr(0,4));

 var m=eval(date.substr(5,2));

 var d=eval(date.substr(8,2));



 var dl;

 if (dx>0) 

  { dl=array_days_count[m-1]; 

    if ((m==2) && (y % 4 == 0)) {dl=eval(dl)+1;} 

  }

 else

  { if (m>1) {dl=array_days_count[m-2];} else {dl=31;} 

    if ((dl==28) && (y % 4 == 0)) {dl=dl+1;} 

  }

 

 var d0=d+dx;

 if ((d0>0) && (d0<=dl)) {d=d0;}



 if (d0>dl) {

  d=d0-dl;

  m=m+1; if (m>12) {m=1; y=y+1;}

            }

 if (d0<=0) {

  d=dl+d0;

  m=m-1; if (m==0) {m=12; y=y-1;}

            }

 var mm=m; if (m<10) {mm='0'+mm;}			

 var dd=d; if (d<10) {dd='0'+dd;}			

 //var cur_day=y+'-'+mm+'-'+dd;

 var cur_day=mm+'-'+dd+'-'+y;

 return cur_day;

}



function hoverEffect(g)

{

document.getElementById(g).className='over';

}



function hideHover(g)

{

document.getElementById(g).className='out';

}



function valid_field(id_field,msg,type_valid)

{

  var el=document.getElementById(id_field)

  //var v=trim(el.value);
  var v=el.value;

  var res;

  if (type_valid=='txt') res=(v=='');

  if (type_valid=='email') res=(!(v.match(/^[A-Za-z0-9\.\_]{1,32}\@[A-Za-z0-9\.\_]{1,32}\.[a-zA-Z]{2,6}$/)));

  if (type_valid=='tel') res=(!(v.match(/^[0-9\-\ \(\)\+]{1,32}$/)));

  if (res) 

  { alert (msg); el.focus(); return false; } else return v;

}



function trim(str)

{ 

  var i = 0; 

  while ((i < str.length) && (str.charAt(i) == " "))  i++;

    str = str.substr(i, str.length - i);

  i = str.length - 1;

  while ((i >= 0) && (str.charAt(i) == " "))  i--;

    str = str.substr(0,i+1);

    alert (str)

  return str;

}



//LOGIN VALIDATION

function loadXMLDoc_Login(url) {

    // branch for native XMLHttpRequest object

   //alert(url);

   if (window.XMLHttpRequest) {

        req = new XMLHttpRequest();

        req.onreadystatechange = processReqChange_Login;

//        req.open("POST", url, true);

        req.open("GET", url, true);

     // alert(url); 

	 req.send(null);

    // branch for IE/Windows ActiveX version

    } else if (window.ActiveXObject) {

        req = new ActiveXObject("Microsoft.XMLHTTP");

        if (req) {

            req.onreadystatechange = processReqChange_Login;

//            req.open("POST", url, true);

            req.open("GET", url, true);

     //alert(url);

	 req.send();

        }

    }

}



function getData_Login(url)

{

  loadXMLDoc_Login(url);

}



function processReqChange_Login() 

{

  var msg;

  var response;

  var result;

  //alert(req.readyState);

   

  if (req.readyState == 4)

  { // only if "OK"

  // alert("sta "+req.status);

   if (req.status == 200)

    { // ...processing statements go here...  

	//alert(req.responseXML.documentElement);

	  response = req.responseXML.documentElement;

      result = response.getElementsByTagName('result');

	 //alert(" ll"+result);

	  msg = result[0].firstChild.data; 

	  if (msg=='Error') document.getElementById('invalid').innerHTML='Your username or password is invalid. Please recheck your typing.';

	  else {window.location.href=msg; }

    } 

	else { alert("There was a problem retrieving the XML data:\n" + req.statusText); }

  }

}



function valid_Login()

{   

//alert(document.getElementById('userid').value);

//alert(document.getElementById('passw').value);

  var userid=document.getElementById('userid').value;

  var passw=document.getElementById('passw').value;

   

  if (userid=='') alert ('Please enter the your user ID.');

   else 

   { if (passw=='') alert ('Please enter the your password.');

       else { 	  

	  // alert(document.getElementById('userid').value);

//alert(document.getElementById('passw').value);



	   getData_Login('engine/auth/login.php?userid='+userid+'&password='+passw); }

   }

}



function login_enter(event)

{ 

  var key = event.keyCode;

  if (key==13) valid_Login();

}



function displayError()

{

if (document.getElementById('flag').innerHTML!='') 

 {

 showBox();

 document.getElementById('invalid').innerHTML = 'Your username or password is not valid. Please recheck your typing and try again.';

 

 }

}

// -------- 



function trim(value) {

	try{

		var temp = value;

		var obj = /^(\s*)([\W\w]*)(\b\s*$)/;

		if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }

		var obj = / +/g;

		temp = temp.replace(obj, "");

		if (temp == " ") { temp = ""; }

		return temp;

		

	} 

	catch ( e ) {

	}

}



function submit_regform(uid)

{
	var errorMessageBegin 	= "_____________________________________________________\n\n";	

	errorMessageBegin 	+= "The page was not submitted because of the following error(s).\n";

	errorMessageBegin	+= "Please correct these error(s) and re-submit.\n";

	errorMessageBegin	+=  "_____________________________________________________\n\n";

	errorMessageBegin	+= "-The following required field(s) are empty or incorrect:\n\n";

	errorMessageEnd 	= "\n\n-Press the OK button and make the necessary corrections."

	var error 		= "";

	var chk			= "0";

	var chk1		= "0";

	var chk2		= "0";

	var chk3		= "0";

	var chk4		= "0";

	var chk5	 	= "0";

	

	var nameRegex 		= /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;

	var phoneRegex 		= /^((\(\d{3}\) ?)|(\d{3}[- \.]))?\d{3}[- \.]\d{4}(\s(x\d+)?){0,1}$/;

	var emailRegex        	= /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;

	var lengthRegex		= /^[A-Za-z0-9]{4,12}$/;

	var trimRegex		= /^[\w0-9]+( [\w0-9]+)*$/;

	var alphaNumRegex	= /^[\w ]{0,}$/;

	

	var name		= trim(username.value);

	var pwd			= trim(passw1.value);

	var pwd1	        = trim(passw_conf.value);

	var promo		= trim(P_promo.value);

	var otherpractice	= trim(otherpractic.value);

	var promo		= trim(P_promo.value);

	var cpromo		= trim(C_promo.value);

	var cn			= trim(C_n.value);

	var sb			= trim(sb_n.value);

	

	//Crappy code, but cleaning up someone else's mess

	if(tp_1.checked) chk	="1";

	if(tp_2.checked) chk1	="1"

	if(tp_3.checked) chk2	="1"

	if(tp_4.checked) chk3	="1"

	if(tp_5.checked) chk4	="1"

	if(tp_6.checked) chk5	="1"

	

	document.getElementById('requiredFields').style.color="#8b8989"

	document.getElementById('nameastk').style.color="#8b8989";

	document.getElementById('firmnameastk').style.color="#8b8989";

	document.getElementById('addrfirmastk').style.color="#8b8989";

	document.getElementById('advphonerabastk').style.color="#8b8989";

	document.getElementById('advphonesotastk').style.color="#8b8989";

	document.getElementById('emailadvastk').style.color="#8b8989";

	document.getElementById('emailadvconfastk').style.color="#8b8989";

	document.getElementById('passw1astk').style.color="#8b8989";

	document.getElementById('passwconfastk').style.color="#8b8989";

	document.getElementById('usernameastk').style.color="#8b8989";

	document.getElementById('dradvastk').style.color="#8b8989";

	document.getElementById('sbnastk').style.color="#8b8989";

	document.getElementById('otherpracticastk').style.color="#8b8989";

	document.getElementById('clientcodeastk').style.color="#8b8989";

	document.getElementById('promocodeastk').style.color="#8b8989";

	document.getElementById('caalacodeastk').style.color="#8b8989";



	if ( (name_adv.value == "") ) {error = error + "\t- Name\n";document.getElementById('nameastk').style.color="#A50000"}

	if ( (name_firm.value == "") ) {error = error + "\t- Firm Name\n";document.getElementById('firmnameastk').style.color="#A50000";}

	if ( (addr_firm.value == "") ) {error = error + "\t- Firm Address\n";document.getElementById('addrfirmastk').style.color="#A50000";}

	if ( (adv_phone_rab.value == "") || (!adv_phone_rab.value.match(phoneRegex)) ) {error = error + "\t- Work Phone\n";document.getElementById('advphonerabastk').style.color="#A50000";}

	if ( (adv_phone_sot.value == "") || (!adv_phone_sot.value.match(phoneRegex)) ) {error = error + "\t- Cell Phone Required\n";document.getElementById('advphonesotastk').style.color="#A50000";}

	if ( (email_adv.value == "") || (!email_adv.value.match(emailRegex)) ) {error = error + "\t- Email Address\n";document.getElementById('emailadvastk').style.color="#A50000";}

	if ( (email_adv_conf.value!=email_adv.value) ) {error = error + "\t- Confirm Email Address\n";document.getElementById('emailadvconfastk').style.color="#a50000";}

	if ( (!name.match(lengthRegex)) ) {error = error + "\t- Username - 4 to 12 characters\n";document.getElementById('usernameastk').style.color="#A50000";}

	if ( (!pwd.match(lengthRegex)) ) { error = error + "\t- Password - 4 to 12 characters\n";document.getElementById('passw1astk').style.color="#A50000";} 

	if ( (pwd1 !=pwd) ) {error = error + "\t- Confirm password\n";document.getElementById('passwconfastk').style.color="#a50000";}

	if ( (dr_adv.value == "") ) {error = error + "\t- Date of Birth\n";document.getElementById('dradvastk').style.color="#A50000";}

	if ( tp_1.checked == false && tp_2.checked == false && tp_3.checked == false && tp_4.checked == false && tp_5.checked == false && tp_6.checked == false ) {error = error + "\t- Practice Type\n";document.getElementById('otherpracticastk').style.color="#A50000";}

	if ( (tp_6.checked == true) && (otherpractice == "") ) {error = error + "\t- Practice Type Other\n";document.getElementById('otherpracticastk').style.color="#A50000";}

	if ( (user_type4.checked == true) && (promo == "") ) {error = error + "\t- Client Code\n";document.getElementById('clientcodeastk').style.color="#A50000";}

	if ( (user_type2.checked == true) && (cpromo == "") ) {error = error + "\t- Promo Code\n";document.getElementById('promocode').style.color="#A50000";}

	if ( (user_type2.checked == true) && (cn == "") ) {error = error + "\t- CAALA Member #\n";document.getElementById('promocode').style.color="#A50000";}

	if ( (sb == "") ) {error = error + "\t- State Bar #\n";document.getElementById('sbnastk').style.color="#A50000";}

	

	if (error!="") {document.getElementById('requiredFields').style.color="#A50000";return alert(errorMessageBegin+error+errorMessageEnd);}

	

	else 

	{

	    	var params="name_adv="+name_adv.value

	    	+"&name_firm="+name_firm.value

	    	+"&addr_firm="+addr_firm.value

	    	+"&adv_phone_rab="+adv_phone_rab.value

	    	+"&adv_phone_sot="+adv_phone_sot.value

	    	+"&name_ass="+name_ass.value

	    	+"&phone_ass_rab="+adv_phone_rab.value

	    	+"&phone_ass_sot="+adv_phone_sot.value

	    	+"&email_adv="+email_adv.value

	    	+"&username="+name

	    	+"&pwd="+pwd

	    	+"&birthday="+dr_adv.value

	        +"&practic="+chk+chk1+chk2+chk3+chk4+chk5

	        +"&otherpractic="+otherpractice

	        +"&on_hold=1&cid="+uid

	        +"&promo4="+promo

	        +"&promo2="+cpromo

	        +"&C_n="+cn

	        +"&sb_n="+sb

	        +"&default_pay=595";	

		return loadXML_POST("engine/auth/registration.php",params,processReqChange_regform);

	}

}





function processReqChange_regform() 

{

  if (req.readyState == 4)

  { // only if "OK"

    if (req.status == 200)

    { // ...processing statements go here...

      var n = req.responseText;

// alert('---'+n+'+++');

      if (n==2) window.location = 'index.php?do=mya&sw=regafter';

      if (n==4) window.location = 'index.php?do=mya&sw=regafter';

      if (n==10) window.location = 'index.php?do=request';

	  if (n==1) window.location = 'index.php?do=mya';

	  if (n=='error1') 

	  { alert('This username is already taken. Please choose another one.'); 

	    document.getElementById('username').focus(); }

	  if (n=='error2') 

	  { alert('Promo code is not valid. Please enter another one.');

	    document.getElementById('P_promo').focus(); }

	  if (n=='error4') 

	  { alert('Client code is not valid. Please enter another one.');

	    document.getElementById('C_promo').focus(); }

    } 

  }

} 



//--------testimonial start--------



function show_requestForm()

{

  document.getElementById('name_case').value='';

  document.getElementById('date_IME').value='';

  document.getElementById('exhour').value='12';

  document.getElementById('exmin').value='00';

  document.getElementById('ampm').value='PM';

  document.getElementById('name_doctor').value='';

  document.getElementById('addr_doctor').value='';

  document.getElementById('phone_doctor').value='';

  document.getElementById('name_client').value='';

  document.getElementById('info_client').value='';



  document.getElementById('requestForm').style.display='block';

  document.getElementById('requestForm-ok').style.display='none';

}



function valid_testForm()

{

  var testimonial_txt=valid_field('testimonial_txt','Please enter the text.','txt'); 

  if (!testimonial_txt) return false; 

  document.getElementById('testimonial_txt1').innerHTML=testimonial_txt;



 

  document.getElementById('test_date1').innerHTML=TodayDate();



  document.getElementById('requestForm123').style.display='none';

  document.getElementById('requestForm-ok123').style.display='block';

}



function submit_requestForm123()

{

  var testimonial_txt=document.getElementById('testimonial_txt1').innerHTML; 

  var test_date=document.getElementById('test_date1').innerHTML;



  var cid=0;

  

  var params="testimonial_txt="+testimonial_txt+"&test_date="+test_date+'&cid='+cid;;

			   

//alert(params);

  document.getElementById('requestForm-preloader').style.display='block';

  loadXML_POST("engine/requestime_testimonial.php",params,processReqChange_testForm);

}



function processReqChange_testForm() 

{

  if (req.readyState == 4)

  { // only if "OK"

    if (req.status == 200)

    { // ...processing statements go here...

//      var n = req.responseText; 

      alert('The testimonial has been submitted.');      

	  document.getElementById('requestForm-preloader').style.display='none';

      document.getElementById('requestForm123').style.display='none';

      document.getElementById('requestForm-ok123').style.display='none';

	  document.getElementById('requestForm-alert123').style.display='block';

    } 

  }

} 





//----------testimonial ends-------------------





//

// -------- Request ---------------

//

function show_requestForm()

{

  document.getElementById('name_case').value='';

  document.getElementById('date_IME').value='';

  document.getElementById('exhour').value='12';

  document.getElementById('exmin').value='00';

  document.getElementById('ampm').value='PM';

  document.getElementById('name_doctor').value='';

  document.getElementById('addr_doctor').value='';

  document.getElementById('phone_doctor').value='';

  document.getElementById('name_client').value='';

  document.getElementById('info_client').value='';



  document.getElementById('requestForm').style.display='block';

  document.getElementById('requestForm-ok').style.display='none';

}



function valid_requestForm()

{

  var namecase=valid_field('name_case','Please enter the case name.','txt'); 

  if (!namecase) return false; 

  document.getElementById('name_case1').innerHTML=namecase;



  var imedate=valid_field('date_IME','Please enter the date.','txt'); 

  if (!imedate) return false; 

//alert(imedate);



  var curr_date=TodayDate();

  var newdate=calc_date(curr_date,7);

  //alert(newdate);

  if (imedate<newdate)  

  { alert ('IME Date is not valid. Please enter date after 7 days from now.'); document.getElementById('date_IME').focus(); return false; }

  document.getElementById('date_IME1').innerHTML=imedate;



  var hh=trim(document.getElementById('exhour').value);

  if ( (!(hh.match(/^[0-9]{1,2}$/))) || (hh>12))

  { alert ('Please enter the hour.'); document.getElementById('exhour').focus(); return false; }



  var mm=trim(document.getElementById('exmin').value);

  if ( (!(mm.match(/^[0-9]{2}$/))) || (mm>59))

  { alert ('Please enter the minutes.'); document.getElementById('exmin').focus(); return false; }



  var n=document.getElementById('ampm').selectedIndex;

  var ampm=document.getElementById('ampm').options[n].innerHTML;



  var imetime = hh+':'+mm+' '+ampm;

  document.getElementById('time_IME1').innerHTML=imetime;



  var doctorname=valid_field('name_doctor','Please enter the defense doctor name.','txt'); 

  if (!doctorname) return false; 

  document.getElementById('name_doctor1').innerHTML=doctorname;



  var addrdoctor=valid_field('addr_doctor','Please enter the defense doctor address.','txt'); 

  if (!addrdoctor) return false; 

  document.getElementById('addr_doctor1').innerHTML=addrdoctor;



  var doctorphone=valid_field('phone_doctor','Defense doctor telephone number is not valid.','tel'); 

  if (!doctorphone) return false; 

  document.getElementById('phone_doctor1').innerHTML=doctorphone;



  var clientname=valid_field('name_client','Please enter the client name.','txt'); 

  if (!clientname) return false; 

  document.getElementById('name_client1').innerHTML=clientname;



  var infoclient=valid_field('info_client','Please enter the client cell phone or contact information.','txt'); 

  if (!infoclient) return false; 

  document.getElementById('info_client1').innerHTML=infoclient;



  document.getElementById('date_case1').innerHTML=TodayDate();



  document.getElementById('requestForm').style.display='none';

  document.getElementById('requestForm-ok').style.display='block';

}



function submit_requestForm()

{

  var namecase=document.getElementById('name_case1').innerHTML; 

  var imedate=document.getElementById('date_IME1').innerHTML 

  var imetime = document.getElementById('time_IME1').innerHTML;



  var doctorname=document.getElementById('name_doctor1').innerHTML; 

  var addrdoctor=document.getElementById('addr_doctor1').innerHTML; 

  var doctorphone=document.getElementById('phone_doctor1').innerHTML; 



  var clientname=document.getElementById('name_client1').innerHTML; 

  var infoclient=document.getElementById('info_client1').innerHTML; 



  var cid=0;

  

  var params="name_case="+namecase+"&IMEDate="+imedate+"&IMETime="+imetime+

			 "&name_doctor="+doctorname+"&addr_doctor="+addrdoctor+"&phone_doctor="+doctorphone+

			 "&name_client="+clientname+"&info_client="+infoclient+'&cid='+cid;;

			   

//alert(params);

  document.getElementById('requestForm-preloader').style.display='block';

  loadXML_POST("engine/requestime.php",params,processReqChange_requestForm);

}



function processReqChange_requestForm() 

{

  if (req.readyState == 4)

  { // only if "OK"

    if (req.status == 200)

    { // ...processing statements go here...

//      var n = req.responseText; 

      alert('The request has been submitted.');      

	  document.getElementById('requestForm-preloader').style.display='none';

      document.getElementById('requestForm').style.display='none';

      document.getElementById('requestForm-ok').style.display='none';

      document.getElementById('requestForm-alert').style.display='block';

    } 

  }

} 



function status_change(cid,mode) 

{

  if ((mode==1) && (document.getElementById('retainer_st').checked==false))

  {alert('You must tick a checkbox to agreeto all\n of the terms of the Retainer agreement.'); return;}

  if ((mode==1) && (document.getElementById('retainer_st').checked))

  {

    document.getElementById('retainer_txt').style.color='cccccc';

    document.getElementById('retainer_st').disabled=true;

    document.getElementById('status1').style.display='none';

    document.getElementById('retainer_date').innerHTML='Electronically signed on '+TodayDate();

	document.getElementById('retainer_date').style.display='block';

  }

  document.getElementById('fmode'+mode).innerHTML='<img src="images/complete.jpg">';

  loadXMLDoc('engine/client/statusChange.php?rid='+cid+'&mode='+mode,processReqChange_status_change);

}



function processReqChange_status_change() 

{

  if (req.readyState == 4)

  { // only if "OK"

    if (req.status == 200)

    { // ...processing statements go here...

      var n = req.responseText; 

	  var i;

      if (n==2) { msg='Authorization Form is confirmed.'; }

      if (n==3) { msg='Pleading Form is confirmed.'; }

      if (n==1) { msg='Retainer Form is confirmed.'; }

//      alert(n);

     if (n==4)

     { msg='';

	   var elts = document.getElementById('questionnaire').getElementsByTagName('input');

	   for (i=0; i<elts.length; i++) elts[i].disabled = true;

     }



     alert(msg+' Thank you.');

     

	 document.getElementById('status'+n).style.display='none';

    } 

  }

} 



function valid_uploadPleadingForm()

{

  var url_Pleading=valid_field('url_Pleading','Please enter the File Name.','txt'); 

  if (!url_Pleading) return false; 



  return true;

}



function check() 

{

  document.getElementById('q1sub1').disabled=document.getElementById('q1no').checked;

  document.getElementById('q1sub2').disabled=document.getElementById('q1no').checked;

  var fl=document.getElementById('q1sub2').checked;

  document.getElementById('hist_1').disabled=fl;

  document.getElementById('hist_2').disabled=fl;

  document.getElementById('hist_3').disabled=fl;

  document.getElementById('hist_4').disabled=fl;

  document.getElementById('hist_5').disabled=fl;

  document.getElementById('hist_6').disabled=fl;

  

  document.getElementById('hist_7').disabled=fl;

  document.getElementById('hist_8').disabled=fl;

  document.getElementById('hist_9').disabled=fl;

  document.getElementById('hist_10').disabled=fl;

  document.getElementById('hist_11').disabled=fl;

  document.getElementById('hist_12').disabled=fl;

}



function hquest_change(cid) 

{

  var h1='_';

  var h2,h3,h4;

  if (document.getElementById('q1no').checked) h1=h1+'0'; else h1=h1+'1';

  if (document.getElementById('q1sub2').checked) h1=h1+'0000000000000'; 

  else 

  { 

    h1=h1+'1'; var k=0;

    for (var i=1; i<=12; i++)

	  if (document.getElementById('hist_'+i).checked)

	  {h1=h1+'1'; k++;} else h1=h1+'0';

	if (k==0) { alert ('Please select.'); return; }

  }

  if (document.getElementById('xraysno').checked) h2=0; else h2=1;

  if (document.getElementById('copyno').checked) h3=0; else h3=1;

  if (document.getElementById('recno').checked) h4=0; else h4=1;



  document.getElementById('fmode4').innerHTML='<img src="images/complete.jpg">';



  loadXMLDoc('engine/client/statusChange.php?rid='+cid+'&mode=4&h1='+h1+'&h2='+h2+'&h3='+h3+'&h4='+h4,processReqChange_status_change);

}

//

// ================ Search and upload reports ===========

//

function show_DocRep(sortmode,page)

{ 

  var searchterm=trim(document.getElementById('term').value);

  loadXMLDoc2('engine/search.php?searchterm='+searchterm+'&sort='+sortmode+'&page='+page,processReqChange_DocRep);

}



function processReqChange_DocRep()

{

  if (req2.readyState == 4)

  { // only if "OK"

    if (req2.status == 200)

    { // ...processing statements go here...

      var response = req2.responseXML.documentElement;

      var result = response.getElementsByTagName('result');

        var total_rec=result[0].firstChild.data;

        var page=result[1].firstChild.data;

		var kol_rec=result.length-3;



        var r=document.getElementById('regim_DocRep').innerHTML;



        sort1=' onclick="sort_options_DocRep(1)" title="Click to sort by Document Name" style="cursor: pointer;"';

        sort2=' onclick="sort_options_DocRep(2)" title="Click to sort by Doctor Name" style="cursor: pointer;"';

        sort3=' onclick="sort_options_DocRep(3)" title="Click to sort by Exam Type" style="cursor: pointer;"';

        sort4=' onclick="sort_options_DocRep(4)" title="Click to sort by Exam Date" style="cursor: pointer;"';

        sort5=' onclick="sort_options_DocRep(5)" title="Click to sort by Injury Type" style="cursor: pointer;"';

        sort6=' onclick="sort_options_DocRep(6)" title="Click to sort by Body parts involved" style="cursor: pointer;"';

        sort7=' onclick="sort_options_DocRep(7)" title="Click to sort by Upload Date" style="cursor: pointer;"';



        if (kol_rec>0)

		{

            row='<table width="100%" cellspacing="1" border="0" class="tablesorter">'+

		      '<thead><tr>';

            if (r=='adm') row=row+'  <th>&nbsp;</th>';

            row=row+  

			  '  <th><span '+sort1+'>Document Name</span></th>'+

              '  <th><span '+sort2+'>Doctor Name</span></th>'+

              '  <th><span '+sort3+'>Exam Type</span></th>'+

              '  <th><span '+sort4+'>Exam Date</span></th>'+

              '  <th><span '+sort5+'>Injury Type</span></th>'+

              '  <th><span '+sort6+'>Body parts involved</span></th>'+

              '  <th><span>Comments</span></th>'+

              '  <th><span '+sort7+'>Upload Date</span></th>'+

			  '</tr></thead><tbody>';

          for (var i=2; i<kol_rec; i=i+10)

		  {

            var docname=result[i].firstChild.data;

			var doctorname=result[i+1].firstChild.data;

			var examtype=result[i+2].firstChild.data;

			var examdate=result[i+3].firstChild.data;

			var injtype=result[i+4].firstChild.data;

			var bodyparts=result[i+5].firstChild.data;

			var comments=result[i+6].firstChild.data;

			var url_report=result[i+7].firstChild.data;

			var upd_date=result[i+8].firstChild.data;

            var id_report=result[i+9].firstChild.data;

			var docname_=Slashes(docname);

			

            row=row+

			  '<tr valign="top" align="left">';

			if (r=='adm') row=row+  

              '  <td><span onClick="del(\'Delete '+docname_+'?\', \'engine/admin/delDocRep.php?id_report='+id_report+'\',processReqChange_delDocRep);" class="control">Delete</span></td>';

            row=row+  

			  '  <td><a href="uploads/reports/'+url_report+'" target="_blank">'+docname+'</a></td>'+

              '  <td>'+doctorname+'</td>'+

              '  <td>'+examtype+'</td>'+

              '  <td>'+examdate+'</td>'+

              '  <td>'+injtype+'</td>'+

              '  <td>'+bodyparts+'</td>'+

              '  <td>'+comments+'</td>'+

              '  <td>'+upd_date+'</td>';

          } //for

          row=row+'</tbody></table>';

          row=row+'<div id="DocRep_innerNavbar" height="70" align="center">&nbsp;</div>';

          document.getElementById('reportslist').innerHTML=row;

          showNav('DocRep_innerNavbar',DocRep_setPage,page,total_rec,'DocRep_');

		}

		else { document.getElementById('reportslist').innerHTML='<h1>No results</h1>'; }

      window.status='';

    } 

  }

}



function processReqChange_delDocRep() 

{

  if (req.readyState == 4)

  { // only if "OK"

    if (req.status == 200)

    { // ...processing statements go here...

      var page=req.responseText;

	  alert('The document is removed.');

      var sortmode=document.getElementById('sort_mode_DocRep').innerHTML;

      var page=document.getElementById('page_DocRep').innerHTML;

	  loadXMLDoc2('engine/search.php?searchterm=&sort='+sortmode+'&page='+page,processReqChange_DocRep);

    } 

  }

} 



function DocRep_setPage(e)

{

  var element = e.target || e.srcElement;

  var s=element.id;

  var p=s.indexOf('_');

  var page=s.substr(p+1);

  var n=page;

  if (page=='First') n=1;

  else

  { if (page.charAt(0)=='_') n=page.substr(1); }

  document.getElementById('page_DocRep').innerHTML=n;

  var sortmode = document.getElementById('sort_mode_DocRep').innerHTML;

  var searchterm=trim(document.getElementById('term').value);

  loadXMLDoc2('engine/search.php?searchterm='+searchterm+'&sort='+sortmode+'&page='+n,processReqChange_DocRep);

}



function sort_options_DocRep(mode)

{ 

  var page=document.getElementById('page_DocRep').innerHTML;

  var sm=document.getElementById('sort_mode_DocRep').innerHTML;

  if (sm % 10 == mode) 

  { if (sm<10) sm=eval(sm)+10; else sm=sm-10; } 

  else 

  { sm=mode; }

  mode=sm;

  document.getElementById('sort_mode_DocRep').innerHTML=sm;

  var searchterm=trim(document.getElementById('term').value);

  loadXMLDoc2('engine/search.php?searchterm='+searchterm+'&sort='+mode+'&page='+page,processReqChange_DocRep);

}



function search_enter(event)

{ 

  var key = event.keyCode;

  if (key==13) show_DocRep(1,1);

}



function valid_uploadForm()

{

  var dn=valid_field('docname_','Please enter the Document Name.','txt'); 

  if (!dn) return false; 



  var doctorname=valid_field('doctorname','Please enter the Doctor Name.','txt'); 

  if (!doctorname) return false; 



  var examtype=document.getElementById('examtype').value;



  var examdate=valid_field('examdate','Exam date is not valid..','txt'); 

  if (!examdate) return false; 



  var injtype=document.getElementById('injtype').value;

  var bodyparts=document.getElementById('bodyparts').value;

  var comments=document.getElementById('comments').value;

  

  var url_report=valid_field('url_report','Please enter the File Name.','txt'); 

  if (!url_report) return false; 



  if (!document.getElementById('rep_agree').checked)

  { alert ('Please verify and check the confirmation checkbox above.'); return false;}

  return true;

}



function valid_uploadSeminarForm()

{

  var dn=valid_field('semname_s','Please enter the Seminar Name.','txt'); 

  if (!dn) return false; 



  var url_seminar=valid_field('url_seminar','Please enter the File Name.','txt'); 

  if (!url_seminar) return false; 



  return true;

}

//

// ============== Contact ================

//

function submit_contact()

{

  var fullname=trim(document.getElementById('fullname_c').value);

  if (fullname=='') 

  { alert ('Please enter the full name.'); document.getElementById('fullname_c').focus(); return; }



  var email=trim(document.getElementById('email_c').value);

  if (!(email.match(/^[A-Za-z0-9\.\_]{1,32}\@[A-Za-z0-9\.\_]{1,32}\.[a-zA-Z]{2,6}$/)))

  { alert ('Email address is not valid.'); document.getElementById('email_c').focus(); return; }



  var tel=trim(document.getElementById('tel_c').value);

//  if (!(tel.match(/^[0-9\-\ \(\)\+]{1,32}$/)))

//  { alert ('Telephone is not valid.'); document.getElementById('tel_c').focus(); return;  }



  var subj=trim(document.getElementById('subj_c').value);

  if (subj=='') 

  { alert ('Please enter the subject.'); document.getElementById('subj_c').focus(); return; }



  var comments=trim(document.getElementById('comments_c').value);

  if (comments=='') 

  { alert ('Please enter the Message.'); document.getElementById('comments_c').focus(); return; }



  var params="fname="+fullname+"&email="+email+"&tel="+tel+"&subj="+subj+"&comments="+comments_c.value;
alert(params);

  loadXML_POST("engine/contact.php",params,processReqChange_submit_comment);

}



function processReqChange_submit_comment() 

{

  if (req.readyState == 4)

  { // only if "OK"

    if (req.status == 200)

    { // ...processing statements go here...

      var n = req.responseText; 

      document.getElementById('fullname_c').value='';

      document.getElementById('email_c').value='';

      document.getElementById('tel_c').value='';

      document.getElementById('subj_c').value='';

      document.getElementById('comments_c').value='';



      document.getElementById('msgheader').innerHTML = 'We want you to know...';

	  document.getElementById('msg').innerHTML = '<p>Your opinion and comments are important to us. If your feedback requires an answers, we will get back to you as soon as possible.</p><p>Thank you.</p>';

	   document.getElementById('contactform').style.display = 'none';

	   document.getElementById('thankyou').style.display = 'block';

    } 

  }

}

//

// ============= requestForm_start ================

//

function submit_requestForm_start()

{

  var namecase=valid_field('name_case','Please enter the case name.','txt'); 

  if (!namecase) return; 



  var imedate=valid_field('date_IME','Please enter the date.','txt'); 

  if (!imedate) return; 



  var hh=trim(document.getElementById('exhour').value);

  if ( (!(hh.match(/^[0-9]{1,2}$/))) || (hh>23))

  { alert ('Please enter the hour.'); return; }



  var mm=trim(document.getElementById('exmin').value);

  if ( (!(mm.match(/^[0-9]{2}$/))) || (mm>59))

  { alert ('Please enter the minutes.'); return; }



  var n=document.getElementById('ampm').selectedIndex;

  var ampm=document.getElementById('ampm').options[n].innerHTML;



  var imetime = hh+':'+mm+' '+ampm;



  var doctorname=valid_field('name_doctor','Please enter the defense doctor name.','txt'); 

  if (!doctorname) return; 



  var addrdoctor=valid_field('addr_doctor','Please enter the defense doctor address.','txt'); 

  if (!addrdoctor) return; 



  var doctorphone=valid_field('phone_doctor','Defense doctor telephone number is not valid.','tel'); 

  if (!doctorphone) return; 



  var clientname=valid_field('name_client','Please enter the client name.','txt'); 

  if (!clientname) return; 



  var infoclient=valid_field('info_client','Please enter the client cell phone or contact information.','txt'); 

  if (!infoclient) return; 



  var cardnumber=trim(document.getElementById('cardnumber').value);

  if (!(cardnumber.match(/^[0-9]{16}$/)));

  { alert ('Credit Card Number is not valid.'); return; }



  var cardexpmonth=trim(document.getElementById('cardexpmonth').value);

  if ( (!(cardexpmonth.match(/^[0-9]{2}$/))) || (cardexpmonth>12))

  { alert ('Credit Card Expiration Month is not valid.'); return; }



  var cardexpyear=trim(document.getElementById('cardexpyear').value);

  if (!(cardexpyear.match(/^[0-9]{2}$/)))

  { alert ('Credit Card Expiration Year is not valid.'); return; }



  var params="name_case="+namecase+"&IMEDate="+imedate+"&IMETime="+imetime+

			 "&name_doctor="+doctorname+"&addr_doctor="+addrdoctor+"&phone_doctor="+doctorphone+

			 "&name_client="+clientname+"&info_client="+infoclient+

			 "&cardnumber="+cardnumber+"&cardexpmonth="+cardexpmonth+'&cardexpyear='+cardexpyear;

			   

//alert(params);

  loadXML_POST("engine/requestime_start.php",params,processReqChange_requestForm_start);

}



function processReqChange_requestForm_start() 

{

  if (req.readyState == 4)

  { // only if "OK"

    if (req.status == 200)

    { // ...processing statements go here...

      var n = req.responseText; 



      document.getElementById('requestForm').style.display='none';

      document.getElementById('requestForm-ok').style.display='block';

    } 

  }

} 



function submit_changepwd(uid)

{

  var old_passw=trim(document.getElementById('old_passw').value);

  if (!(old_passw.match(/^[A-Za-z0-9]{4,12}$/)))

  { alert ('The password should consist of 4-12 symbols.'); document.getElementById('old_passw').focus(); return; }



  var passw=trim(document.getElementById('passw1').value);

  if (!(passw.match(/^[A-Za-z0-9]{4,12}$/)))

  { alert ('The password should consist of 4-12 symbols.'); document.getElementById('passw1').focus(); return; }



  var passw_conf=trim(document.getElementById('passw_conf').value);

  if (!(passw_conf.match(/^[A-Za-z0-9]{4,12}$/)))

  { alert ('Please confirm your password.'); document.getElementById('passw_conf').focus(); return; }

   

  if (passw_conf!=passw) 

  { alert ('Password confirmation does not coinside with your new password'); 

    document.getElementById('old_passw').value=''; 

    document.getElementById('passw_conf').value=''; 

    document.getElementById('old_passw').focus(); 

	return; 

  }

  

  var params="old_passw="+old_passw+"&pwd="+passw+"&uid="+uid;

//alert(params);

  loadXML_POST("engine/auth/changepwd.php",params,processReqChange_submit_changepwd);

	

}



function processReqChange_submit_changepwd() 

{

  if (req.readyState == 4)

  { // only if "OK"

    if (req.status == 200)

    { // ...processing statements go here...

      var n = req.responseText;

// alert(n);

      if (n==0) alert('The password is successfully changed.');

      if (n==1)

	  {

	    alert('Your old password is incorrect. Please recheck your spelling.');

        document.getElementById('old_passw').focus(); 

      }

      document.getElementById('old_passw').value=''; 

      document.getElementById('passw1').value=''; 

      document.getElementById('passw_conf').value=''; 

	}

  }

} 



function submit_changepwd_adm(uid)

{

  var new_username=valid_field('new_username','Please enter the New Username.','txt'); 

  if (!new_username) return; 



  var passw=trim(document.getElementById('passw1').value);

  if (!(passw.match(/^[A-Za-z0-9]{4,12}$/)))

  { alert ('The password should consist of 4-12 symbols.'); document.getElementById('passw1').focus(); return; }



  var passw_conf=trim(document.getElementById('passw_conf').value);

  if (!(passw_conf.match(/^[A-Za-z0-9]{4,12}$/)))

  { alert ('Please confirm your password.'); document.getElementById('passw_conf').focus(); return; }

   

  if (passw_conf!=passw) 

  { alert ('Password confirmation does not coinside with your new password'); 

    document.getElementById('old_passw').value=''; 

    document.getElementById('passw_conf').value=''; 

    document.getElementById('old_passw').focus(); 

	return; 

  }

  

  var params="new_username="+new_username+"&pwd="+passw+"&uid="+uid;

//alert(params);

  loadXML_POST("engine/auth/changepwd_adm.php",params,processReqChange_submit_changepwd_adm);

}



function processReqChange_submit_changepwd_adm() 

{

  if (req.readyState == 4)

  { // only if "OK"

    if (req.status == 200)

    { // ...processing statements go here...

      var n = req.responseText;

// alert(n);

      if (n==0) 

	  {

	    alert('The username and password are successfully changed.');

	    document.getElementById('new_username').value=''; 

        document.getElementById('passw1').value=''; 

        document.getElementById('passw_conf').value=''; 

      }

      else 

	  {

	    alert('This username is already taken. Please try another one.');

        document.getElementById('new_username').focus(); 

      }

	}

  }

} 