// Script getPage.js

// Function that starts the Ajax process:
function getPage(reqPage) {
	// Confirm that the object is usable:
	if (ajax) { 
		// Call the PHP script.
		// Use the GET method.
		// Pass the page in the URL.
		//alert('/' + (controller) +'/getPage/' + (reqPage));
		
		ajax.open('get', '/category/getPage/' + encodeURIComponent(reqPage));

		
		// Function that handles the response:
		ajax.onreadystatechange = handle_check;
		
		// Send the request:
		ajax.send(null);

	} else { // Can't use Ajax!
		document.getElementById('cat').innerHTML = 'AJAX is unavailable';
	}
	
} 

// Function that handles the response from the PHP script:
function handle_check() {

	// If everything's OK:
	if ( (ajax.readyState == 4) && (ajax.status == 200) ) {

		// Assign the returned value to a document element:
		document.getElementById('cat').innerHTML = ajax.responseText;
		
	}
	
} 

function getState(reqPage, selState) {
	// Confirm that the object is usable:
	if (ajax) {
		ajax.open('get', '/accounts/getStates/' + encodeURIComponent(reqPage) + '/' + encodeURIComponent(selState));
		// Function that handles the response:
		ajax.onreadystatechange = state_handle;
		// Send the request:
		ajax.send(null);
	} else { // Can't use Ajax!
		document.getElementById('state_province').innerHTML = 'AJAX is unavailable';
	}
	
} 

// Function that handles the response from the PHP script:
function state_handle() {

	// If everything's OK:
	if ( (ajax.readyState == 4) && (ajax.status == 200) ) {

		// Assign the returned value to a document element:
		document.getElementById('state_province').innerHTML = ajax.responseText;
		
	}
	
}
function getState2(reqPage, selState) {
	// Confirm that the object is usable:

	if (ajax) {
		ajax.open('get', '/apply/getStates/' + encodeURIComponent(reqPage) + '/' + encodeURIComponent(selState));
		// Function that handles the response:
		ajax.onreadystatechange = state_handle;
		// Send the request:
		ajax.send(null);
	} else { // Can't use Ajax!
		document.getElementById('state_province').innerHTML = 'AJAX is unavailable';
	}
	
} 

// Function that handles the response from the PHP script:
function state_handle2() {

	// If everything's OK:
	if ( (ajax.readyState == 4) && (ajax.status == 200) ) {

		// Assign the returned value to a document element:
		document.getElementById('state_province').innerHTML = ajax.responseText;
		
	}
	
}
/*
function getKaptcha(reqPage) {
	alert(reqPage);
	// Confirm that the object is usable:
	if (ajax) {
		ajax.open('get', '/accounts/kaptcha/' + encodeURIComponent(reqPage));
		// Function that handles the response:
		ajax.onreadystatechange = state_handle;
		// Send the request:
		ajax.send(null);
	} else { // Can't use Ajax!
		document.getElementById('kaptcha').innerHTML = 'AJAX is unavailable';
	}
	
} 

// Function that handles the response from the PHP script:
function kaptcha_handle() {

	// If everything's OK:
	if ( (ajax.readyState == 4) && (ajax.status == 200) ) {

		// Assign the returned value to a document element:
		document.getElementById('kaptcha').innerHTML = ajax.responseText;
		
	}
	
}
*/
function sb_category(item) {
	if (ajax) { 
		ajax.open('get', '/pr/sb_category/' + item);
		ajax.onreadystatechange = reference_handle;
		ajax.send(null);
	} else { // Can't use Ajax!
		document.getElementById('ref_content').innerHTML = 'AJAX is unavailable';
	}
	return;
} 

function sb_date(item) {
	if (ajax) { 
		ajax.open('get', '/pr/sb_date/' + item);
		ajax.onreadystatechange = reference_handle;
		ajax.send(null);
	} else { // Can't use Ajax!
		document.getElementById('ref_content').innerHTML = 'AJAX is unavailable';
	}
	return;
}

function sb_magazine(item) {
	if (ajax) { 
		ajax.open('get', '/pr/sb_magazine/' + item);
		ajax.onreadystatechange = reference_handle;
		ajax.send(null);
	} else { // Can't use Ajax!
		document.getElementById('ref_content').innerHTML = 'AJAX is unavailable';
	}
	return;
}


// Function that handles the response from the PHP script:
function reference_handle() {

	// If everything's OK:
	if ( (ajax.readyState == 4) && (ajax.status == 200) ) {
		document.getElementById('ref_content').innerHTML = ajax.responseText;
		
	}
	
}

function sb_reference(item) {
	// Confirm that the object is usable:
	if (ajax) { 
		ajax.open('get', '/pr/sb_reference/' + item);

		// Function that handles the response:
		ajax.onreadystatechange = information_handle;
		
		// Send the request:
		ajax.send(null);

	} else { // Can't use Ajax!
		document.getElementById('information').innerHTML = 'AJAX is unavailable';
	}
	
}
 
function information_handle() {

	// If everything's OK:
	if ( (ajax.readyState == 4) && (ajax.status == 200) ) {

		// Assign the returned value to a document element:
		//document.getElementById('ref_content').innerHTML = 'This is working';
		document.getElementById('information').innerHTML = ajax.responseText;
		
	}
	
}