/* ------------------------------- */
/* JAVSCRIPT HANDLING AJAX FUNC    */
/* (c)2010/11 TOOLING INTELLIGENCE */
/* ------------------------------- */


/* ---------------------------------- */
/* XMLHTTPRequest Enable - NAV */
/* ---------------------------------- */
function createObjectNav() {
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 http2 = createObjectNav();

/* gets around IE cache problem */
var nocache = 0;

/* --------------------------- */
/* TILweb, NAV RESPONSE */
/* --------------------------- */
function Nav() {
nocache = Math.random();
http2.open('get', 'resources/php/dynamics.php?action=nav&nocache='+nocache);
http2.onreadystatechange = NavReply;
http2.send(null);
}
function NavReply() {
if(http2.readyState == 4){
var response = http2.responseText;
//if(response == 0){
//document.getElementById('navbox').innerHTML = '<h4>Could not load Nav</h4>';
//} else {
document.getElementById('navigation').innerHTML = response;
//}
}
return response;
}


/* ---------------------------------- */
/* XMLHTTPRequest Enable - NEWSLETTER */
/* ---------------------------------- */
function createObjectNewsletter() {
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 = createObjectNewsletter();

/* gets around IE cache problem */
var nocache = 0;

/* --------------------------- */
/* TILweb, NEWSLETTER RESPONSE */
/* --------------------------- */
function Newsletter() {
var email = encodeURI(document.getElementById('newsemail').value);
nocache = Math.random();
http.open('get', 'resources/php/dynamics.php?action=newsletter&email='+email+'&nocache='+nocache);
http.onreadystatechange = NewsletterReply;
http.send(null);
}
function NewsletterReply() {
if(http.readyState == 4){
var response = http.responseText;
if(response == "2"){
document.getElementById('newsletter').innerHTML = '<h5>You have already registered.</h5>';
} else {
document.getElementById('newsletter').innerHTML = '<h5>You are subscribed to the newsletter. Thank you</h5>';
}
}
return response;
}

/* ---------------------------------- */
/* XMLHTTPRequest Enable - NEWSTICKER */
/* ---------------------------------- */
function createObjectTicker() {
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 = createObjectTicker();

/* gets around IE cache problem */
var nocache = 0;

/* --------------------------- */
/* TILweb, NEWSticker RESPONSE */
/* --------------------------- */
function ticker() {
nocache = Math.random();
http.open('get', 'resources/php/dynamics.php?action=newsticker&nocache='+nocache);
http.onreadystatechange = tickerReply;
http.send(null);
}
function tickerReply() {
if(http.readyState == 4){
var response = http.responseText;
if(response == 0){
document.getElementById('newsticker').innerHTML = response;
} else {
document.getElementById('newsticker').innerHTML = response;
}
}
return response;
}

/* ---------------------------------- */
/* XMLHTTPRequest Enable - QOTD */
/* ---------------------------------- */
function createObjectQotd() {
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 http5 = createObjectQotd();

/* gets around IE cache problem */
var nocache2 = 0;

/* --------------------------- */
/* TILweb, NEWSticker RESPONSE */
/* --------------------------- */
function qotd() {
nocache2 = Math.random();
http5.open('get', 'resources/php/dynamics.php?action=qotd&nocache='+nocache2);
http5.onreadystatechange = qotdReply;
http5.send(null);
}
function qotdReply() {
if(http5.readyState == 4){
var response = http5.responseText;
if(response == 0){
document.getElementById('qotd').innerHTML = '<h4>Error</h4>';
} else {
document.getElementById('qotd').innerHTML = response;
}
}
return response;
}


/* ---------------------------------- */
/* XMLHTTPRequest Enable - CUSTOMER LOGIN */
/* ---------------------------------- */
function createObjectLogin() {
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 = createObjectLogin();

/* gets around IE cache problem */
var nocache = 0;

/* --------------------------- */
/* TILweb, CUSTOMER LOGIN RESPONSE */
/* --------------------------- */
function LoginCustomer() {
var usr = encodeURI(document.getElementById('user').value);
var pas = encodeURI(document.getElementById('pass').value);
nocache = Math.random();
http.open('get', 'http://www.tisoftwareservices.co.uk/xmlrpc/webclient.php?u='+usr+'&p='+pas+'&nocache='+nocache);
http.onreadystatechange = LoginReply;
http.send(null);
}
function LoginReply() {
if(http.readyState == 4){
var response = http.responseText;
if(response == "0"){
document.getElementById('customerarea').innerHTML = 'Logged Out';
} else {
document.getElementById('customerarea').innerHTML = response;
}
}
return response;
}


