//-------------------------------------------------------------------------------------------------------------------------------------------------------------
   var http_request = false;
   function makePOSTRequest(url, parameters) {

      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }
   
   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
			result = http_request.responseText;
            document.getElementById(span).innerHTML = result;            
         } else {			 	
            alert('There was a problem with the request.');
         }
      }
   } 
   
   function ajaxDisplay(id,val){
	   switch(id){
		   case "total": url = 'total.php?proposalID='+val; break;
		   case "validateName": url = 'validation.php?action=checkName&TYPE=patient&name='+val; break;
		   case "validateInvoice": url = 'validation.php?action=checkName&TYPE=invoice&name='+val; break;
		   case "checkCard": url = 'Proposal_pastcard.php?action=checkCard&editID='+val; break;
	   }
	   return new Ajax.Updater(id,url,{asynchronous:true}); 
   } 
   
   function ajax(span1,page,poststr){
	   span = span1;
	   var poststr = poststr;
	   makePOSTRequest(page, poststr);
   }      
   
   function preload(id){
		document.getElementById(id).innerHTML = "<br><center>Loading...<center><br>";
   }
   
   function confirmSubmit(value){
		var agree=confirm(value);
		if (agree)
			return true ;
		else
			return false ;
   }	
	
   function checkedAll(id, checked) {	   
		var el = document.getElementById(id);
		for (var i = 0; i < el.elements.length; i++) {
		  el.elements[i].checked = checked;
		}
   }
   
   function checkBox(id,chk){
	   var checkbox = document.getElementById('checkboxes');
	   
	   if(chk == 1){
		   document.getElementById('checkboxes').innerHTML = "<input type=\"checkbox\" name=\"all\" value=\"0\" onclick=\"checkBox('"+id+"','2')\"/>";
		   checkedAll(id,true);
	   }else{
		   document.getElementById('checkboxes').innerHTML = "<input type=\"checkbox\" name=\"all\" value=\"1\" onclick=\"checkBox('"+id+"','1')\"/>";
		   checkedAll(id,false);
	   }	    
   }
	
   function CountLeft(field, count, max) { 
		if (field.value.length > max)// if the length of the string in the input field is greater than the max value, trim it 
 			field.value = field.value.substring(0, max);
 		else// calculate the remaining characters   
 			count.value = max - field.value.length;
   }
   
   function hide2(id){
	   	document.getElementById(id).innerHTML = "";
   }
	
   function show(id){
		document.getElementById(id).style.display = 'block';
   }
   
   function hide(id){		
		document.getElementById(id).style.display = 'none';
   }
   
   function MM_openBrWindow(theURL,winName,features) { //v2.0
   		window.open(theURL,winName,features);
   } 
   
   function formSubmit(value,fieldId){	   	
	  	if(value == 2){
			document.getElementById(fieldId).disabled = true;
			document.getElementById(fieldId).style.background = '#d4d4d4';
		}else{
			document.getElementById(fieldId).disabled = false;
			document.getElementById(fieldId).style.background = '';
		}
   }     
	
	
   function phonetrapping(e,formID,fieldID){
   		var unicode=e.charCode? e.charCode : e.keyCode;
		var phone_a = document.getElementById(fieldID+'1');
		var phone_b = document.getElementById(fieldID+'2');
		var phone_c = document.getElementById(fieldID+'3');
		
		if((unicode!= 8) && (unicode != 9)){ 
			if((unicode > 47) && (unicode < 58)){
				if((phone_a.value.length == 2 && phone_b.value.length != 2)){
					setTimeout("document.forms."+formID+"."+fieldID+"2.focus()", 1);
				}else if((phone_b.value.length == 2 && phone_c.value.length != 4)){
					setTimeout("document.forms."+formID+"."+fieldID+"3.focus()", 1);
				}
				return true;
			} else {
				return false;
			}
		}
   }	
