function getXmlHttpRequestObject() {
    if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    } else if(window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        alert("Your Browser is old and doesn't support the auto suggest meals!\n");
    }
}

var searchReq = getXmlHttpRequestObject();


function ShowMeasurements(field, cid)	{

    if (searchReq.readyState == 4 || searchReq.readyState == 0) {
    
    	document.getElementById('loading').style.display = 'inline';
    
        searchReq.open("GET", '/js/showchart.php?field=' + field + '&cid=' + cid, true);
        searchReq.onreadystatechange = handleChartResponse; 
        searchReq.send(null);
    }  

}

function handleChartResponse() {

    if (searchReq.readyState == 4) {
	    document.getElementById('loading').style.display = 'none';
        var ss = document.getElementById('BodyMeasure');
        var str = searchReq.responseText;
        ss.innerHTML = str; 

    }
}




function SetPublic(cid) {

    if (searchReq.readyState == 4 || searchReq.readyState == 0) {
        searchReq.open("GET", '/js/setpublic.php?private=0&cid=' + cid, true);
        searchReq.onreadystatechange = handleResponse; 
        searchReq.send(null);
    }        
}


function SetPrivate(cid) {

if(confirm('Are you sure? Setting your profile to private will mean other users cannot view your profile or send you messages.')) {  

    if (searchReq.readyState == 4 || searchReq.readyState == 0) {
        searchReq.open("GET", '/js/setpublic.php?private=1&cid=' + cid, true);
        searchReq.onreadystatechange = handleResponse; 
        searchReq.send(null);
    }    
   }
}


function handleResponse() {

    if (searchReq.readyState == 4) {
    
        var ss = document.getElementById('privateprofile')
        var str = searchReq.responseText;
        
        ss.innerHTML = str;
        
           
 
    }
}



// Check numeric input only

// calculate the ASCII code of the given character
function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}

function checkNumber(val) {
  var strPass = val.value;
  var strLength = strPass.length;
  var lchar = val.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);

  /* Check if the keyed in character is a number
     do you want alphabetic UPPERCASE only ?
     or lower case only just check their respective
     codes and replace the 48 and 57 */

  if (cCode < 48 || cCode > 57 ) {  
  if (cCode != 46) {
    var myNumber = val.value.substring(0, (strLength) - 1);
    val.value = myNumber;
	}
  }
  return false;
}

