function SimpleAjax() { this.xmlreq = null; if ( window.XMLHttpRequest ) { // Create XMLHttpRequest object in non-Microsoft browsers this.xmlreq = new XMLHttpRequest(); } else if ( window.ActiveXObject ) { // Create XMLHttpRequest via MS ActiveX try { // Try to create XMLHttpRequest in later versions // of Internet Explorer this.xmlreq = new ActiveXObject( "Msxml2.XMLHTTP" ); } catch ( e1 ) { // Failed to create required ActiveXObject // Try version supported by older versions // of Internet Explorer this.xmlreq = new ActiveXObject( "Microsoft.XMLHTTP" ); } } SimpleAjax.prototype.doPost = function ( url, parameters, stateChanged ) { this.doRequest( "POST", url, parameters, stateChanged ); }; SimpleAjax.prototype.doGet = function( url, parameters, stateChanged ){ this.doRequest( "GET", url, parameters, stateChanged ); }; SimpleAjax.prototype.doRequest = function( type, url, parameters, stateChanged ) { this.xmlreq.onreadystatechange = this.getReadyStateHandler( stateChanged ); this.xmlreq.open( type, url, true ); this.xmlreq.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" ); this.xmlreq.setRequestHeader( "Content-length", parameters.length ); this.xmlreq.setRequestHeader( "Connection", "close" ); this.xmlreq.send( parameters ); }; /* * Returns a function that waits for the specified XMLHttpRequest * to complete, then passes its XML response to the given handler function. * req - The XMLHttpRequest whose state is changing * responseXmlHandler - Function to pass the XML response to */ SimpleAjax.prototype.getReadyStateHandler = function( responseHandler ) { var req = this.xmlreq; // Return an anonymous function that listens to the // XMLHttpRequest instance return function () { // If the request's status is "complete" if ( req.readyState == 4 ) { // Check that a successful server response was received if ( req.status == 200 ) { // Pass the XML payload of the response to the // handler function responseHandler( req ); //responseXML or responseText } else { // An HTTP problem has occurred //alert( "HTTP error: " + req.status ); } } } }; } var roll_count = new Array(); var mainbanner = new Array(); var position4= new Array(); position4['0'] = '32'; position4['1'] = '71'; position4['2'] = '48'; position4['3'] = '81'; position4['4'] = '65'; position4['5'] = '80'; position4['6'] = '60'; position4['7'] = '77'; mainbanner['position4'] = position4; roll_count['position4'] = 0; var position5= new Array(); position5['0'] = '78'; position5['1'] = '57'; position5['2'] = '40'; position5['3'] = '41'; position5['4'] = '59'; position5['5'] = '52'; mainbanner['position5'] = position5; roll_count['position5'] = 0; var position6= new Array(); position6['0'] = '56'; position6['1'] = '58'; position6['2'] = '72'; position6['3'] = '82'; position6['4'] = '70'; mainbanner['position6'] = position6; roll_count['position6'] = 0; var current_id = '0'; function cycleAds(position){ if (mainbanner[position]){ if (++roll_count[position] >= mainbanner[position].length){ roll_count[position] = 0; } var ajax = new SimpleAjax(); query_string = "position="+position+"&id="+ mainbanner[position][roll_count[position]] +"¤t_id=" + current_id; current_id = mainbanner[position][roll_count[position]]; ajax.doPost("/index.php/ps_pagename/get_banner", query_string, newBanner); } } function newBanner(banner_details){ position = banner_details.responseXML.firstChild.getAttribute("position"); if(banner_details.responseXML.firstChild.text){ document.getElementById(position).innerHTML = banner_details.responseXML.firstChild.text; }else if(banner_details.responseXML.firstChild.textContent){ document.getElementById(position).innerHTML = banner_details.responseXML.firstChild.textContent; }else{ string1 = ""; start_index = banner_details.responseText.indexOf( string1, 0 ) + 9; end_index = banner_details.responseText.indexOf( string2, 0 ) ; document.getElementById(position).innerHTML = banner_details.responseText.substring(start_index,end_index); } setTimeout("cycleAds('" + position + "')", 30000); }