/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}

var http = createObject();
var http1 = createObject();
var http2 = createObject();
var httpSH = createObject();
var httpSD = createObject();
var httpSPL = createObject();
var httpMS = createObject();
var httpPSV = createObject();
var httpSS = createObject();
var httpBB = createObject();
/* -------------------------- */
/* LOGIN */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function registration() {
// Optional: Show a waiting message in the layer with ID ajax_response
document.getElementById('registration_response').innerHTML = "Loading..."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var age = encodeURI(document.getElementById('age').value);
//alert(age);
var weight2 = encodeURI(document.getElementById('weight2').value);
//alert(weight2);
var weight_unit = encodeURI(document.getElementById('weight_unit').value);
//alert(weight_unit);
var height;
//height = encodeURI(document.getElementById('height').value);
if(document.getElementById('height_unit').value=='cms')
{
	//cent
	height=document.getElementById('cent').value;
}
else if(document.getElementById('height_unit').value=='inch')
{
	height=document.getElementById('Bmi_feet').value+","+document.getElementById('Bmi_inch').value;
}
//alert(height);
var height_unit = encodeURI(document.getElementById('height_unit').value);
//alert(height_unit);

// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'weight_cal.php?age='+age+'&weight2='+weight2+'&weight2='+weight2+'&weight_unit='+weight_unit+'&height='+height+'&height_unit='+height_unit+'&nocache = '+nocache);
http.onreadystatechange = loginReply;
http.send(null);
}



function loginReply() {
if(http.readyState == 4){
var response = http.responseText;
if(response == 0){
// if login fails
document.getElementById('registration_response').innerHTML = 'Calculation Failed! Verify again for the same';
// else if login is ok show a message: "Welcome + the user name".
} else {
document.getElementById('registration_response').innerHTML = response;
}
}
}


function registration2() {
// Optional: Show a waiting message in the layer with ID ajax_response
document.getElementById('registration_response1').innerHTML = "loading.."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var age = encodeURI(document.getElementById('age').value);
//alert(age);
var weight2 = encodeURI(document.getElementById('weight2').value);
//alert(weight2);
var weight_unit = encodeURI(document.getElementById('weight_unit').value);
//alert(weight_unit);
var height = encodeURI(document.getElementById('height').value);
//alert(height);
var height_unit = encodeURI(document.getElementById('height_unit').value);
//alert(height_unit);
var sex = encodeURI(document.getElementById('sex').value);
//alert(sex);

var health_diseases = encodeURI(document.getElementById('health_diseases').value);
//alert(health_diseases);
var reach_goal = encodeURI(document.getElementById('reach_goal').value);
//alert(reach_goal);
var eat_weekday = encodeURI(document.getElementById('eat_weekday').value);
//alert(eat_weekday);
var eat_weekend = encodeURI(document.getElementById('eat_weekend').value);
//alert(eat_weekend);
var indulged_dieting = encodeURI(document.getElementById('indulged_dieting').value);
//alert(indulged_dieting);

var indulged_difficulties = encodeURI(document.getElementById('indulged_difficulties').value);
//alert(indulged_difficulties);
var allergic = encodeURI(document.getElementById('allergic').value);
//alert(allergic);
var fluid_intake = encodeURI(document.getElementById('fluid_intake').value);
//alert(fluid_intake);
var reg_fluid = encodeURI(document.getElementById('reg_fluid').value);
//alert(reg_fluid);
var activity = encodeURI(document.getElementById('activity').value);
//alert(activity);

var fname = encodeURI(document.getElementById('fname').value);
//alert(fname);
var lname = encodeURI(document.getElementById('lname').value);
//alert(lname);
var username = encodeURI(document.getElementById('username').value);
//alert(username);
var password = encodeURI(document.getElementById('password').value);
//alert(password);
var confirm_password = encodeURI(document.getElementById('confirm_password').value);
//alert(confirm_password);
var email = encodeURI(document.getElementById('email').value);
//alert(email);
var country = encodeURI(document.getElementById('country').value);
//alert(country);
var code = encodeURI(document.getElementById('code').value);
//alert(code);
var registration_response = encodeURI(document.getElementById('registration_response').value);
//alert(registration_response);


// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http1.open('get', 'weight_cal2.php?age='+age+'&weight2='+weight2+'&weight_unit='+weight_unit+'&height1='+height+'&height_unit='+height_unit+'&gender='+sex+'&diseases='+health_diseases+'&weight_goal='+reach_goal+'&eat_weekdays='+eat_weekday+'&eat_weekends='+eat_weekend+'&indulged_dieting='+indulged_dieting+'&indulged_problem='+indulged_difficulties+'&allergic_food='+allergic+'&fluid_intake1='+fluid_intake+'&reg_fluid='+reg_fluid+'&activity_level='+activity+'&fname='+fname+'&lname='+lname+'&username='+username+'&password='+password+'&confirm_password='+confirm_password+'&email='+email+'&country='+country+'&code='+code+'&nocache = '+nocache);
http1.onreadystatechange = registraionReply;
http1.send(null);
}
function registraionReply() {
if(http1.readyState == 4){
var response1 = http1.responseText;
//var submit = <script>'window.open('thanks.html','_self')'//
//script>';

if(response1 == 0){
// if login fails
document.getElementById('registration_response1').innerHTML = 'Login failed! Verify user and password';
// else if login is ok show a message: "Welcome + the user name".
} else {
	
//document.getElementById('registration_response1').innerHTML = 'You are Register Succeessfully';
//document.frm1.action="thanks.html";
//document.frm1.submit();
 window.location.href="thanks.html";

}
}
}


function registration3() {
// Optional: Show a waiting message in the layer with ID ajax_response
document.getElementById('registration_response3').innerHTML = "loading.."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var day = encodeURI(document.getElementById('day').value);
//alert(day);
var month = encodeURI(document.getElementById('month').value);
//alert(month);
var year = encodeURI(document.getElementById('year').value);
//alert(year);
var registration_response = encodeURI(document.getElementById('registration_response3').value);
//alert(registration_response);


// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http1.open('get', 'weight_cal3.php?day='+day+'&month='+month+'&year='+year+'&nocache = '+nocache);
http1.onreadystatechange = registraionReply;
http1.send(null);
}

function registration4() {
// Optional: Show a waiting message in the layer with ID ajax_response
document.getElementById('registration_response3').innerHTML = "loading.."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var day = encodeURI(document.getElementById('day').value);
//alert(day);
var month = encodeURI(document.getElementById('month').value);
//alert(month);
var year = encodeURI(document.getElementById('year').value);
//alert(year);
var registration_response = encodeURI(document.getElementById('registration_response3').value);
//alert(registration_response);


// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http1.open('get', 'weight_cal4.php?day='+day+'&month='+month+'&year='+year+'&nocache = '+nocache);
http1.onreadystatechange = registraionReply;
http1.send(null);
}


function registration5() {
// Optional: Show a waiting message in the layer with ID ajax_response
document.getElementById('registration_response3').innerHTML = "loading.."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var day = encodeURI(document.getElementById('day').value);
//alert(day);
var month = encodeURI(document.getElementById('month').value);
//alert(month);
var year = encodeURI(document.getElementById('year').value);
//alert(year);
var registration_response = encodeURI(document.getElementById('registration_response3').value);
//alert(registration_response);


// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http1.open('get', 'weight_cal5.php?day='+day+'&month='+month+'&year='+year+'&nocache = '+nocache);
http1.onreadystatechange = registraionReply;
http1.send(null);
}

function registration6() {
// Optional: Show a waiting message in the layer with ID ajax_response
document.getElementById('registration_response3').innerHTML = "loading.."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var day = encodeURI(document.getElementById('day').value);
//alert(day);
var month = encodeURI(document.getElementById('month').value);
//alert(month);
var year = encodeURI(document.getElementById('year').value);
//alert(year);
var registration_response = encodeURI(document.getElementById('registration_response3').value);
//alert(registration_response);


// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http1.open('get', 'weight_cal6.php?day='+day+'&month='+month+'&year='+year+'&nocache = '+nocache);
http1.onreadystatechange = registraionReply;
http1.send(null);
}

function registration7() {
// Optional: Show a waiting message in the layer with ID ajax_response
document.getElementById('registration_response3').innerHTML = "loading.."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var day = encodeURI(document.getElementById('day').value);
//alert(day);
var month = encodeURI(document.getElementById('month').value);
//alert(month);
var year = encodeURI(document.getElementById('year').value);
//alert(year);
var registration_response = encodeURI(document.getElementById('registration_response3').value);
//alert(registration_response);


// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http1.open('get', 'weight_cal7.php?day='+day+'&month='+month+'&year='+year+'&nocache = '+nocache);
http1.onreadystatechange = registraionReply;
http1.send(null);
}

function registration8() {
//salert("start");	
// Optional: Show a waiting message in the layer with ID ajax_response
document.getElementById('registration_response3').innerHTML = "loading.."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var day = encodeURI(document.getElementById('day').value);

var month = encodeURI(document.getElementById('month').value);

var year = encodeURI(document.getElementById('year').value);

//alert(year);
var registration_response = encodeURI(document.getElementById('registration_response3').value);

//alert(registration_response);


// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http1.open('get', 'weight_cal8.php?day='+day+'&month='+month+'&year='+year+'&nocache = '+nocache);
http1.onreadystatechange = registraionReply;
http1.send(null);

}



function registraionReply() {
if(http1.readyState == 4){
var response1 = http1.responseText;
//alert(response1);
//var submit = <script>'window.open('thanks.html','_self')'</script>;

if(response1 == 0){
// if login fails
document.getElementById('registration_response3').innerHTML = 'Login failed! Verify user and password';
// else if login is ok show a message: "Welcome + the user name".
} else {
	
document.getElementById('registration_response3').innerHTML = ''+ response1;
//document.frm1.action="thanks.html";
//document.frm1.submit();
// window.location.href="thanks.html";

}
}
}


function Fill_From_DB(serviceID,l_query,targetElement,baseValue) 
{
	nocache = Math.random();
	var url='phpWS.php?l_query='+l_query+'&serviceID='+serviceID+'&eID='+targetElement+'&bValue='+baseValue+'&nocache = '+nocache;	
	http2.open('get',url );
	http2.onreadystatechange = responseFill;
	http2.send(null);
}
function responseFill(){
	if(http2.readyState == 4)
	{
		var response = http2.responseText;
		//alert(response);
		var out = response.split("###");
		
		if(response == 0)
		{
			document.getElementById(out[1]).innerHTML = 'Server has encountered a problem. Please try again.';
		} 
		else 
		{
			document.getElementById(out[1]).innerHTML = out[0];
		}
	}
}

