// JavaScript Document
	/*
	# eLuminous Technologies - Copyright (C)  http://eluminoustechnologies.com 
	# This code is written by eLuminous Technologies, Its a sole property of 
	# eLuminous Technologies and cant be used / modified without license.  
	# Any changes/ alterations, illegal uses, unlawful distribution, copying is strictly
	# prohibhited 
	# Name: ajax_request_handler.js
	# Usage: included the file to handle ajax request. ( WRITE USAGE DETAILS ) 
	# Created : Rupal Pinge & Sham Shriwastav (30-05-2007)
	# Update  : 30-05-2007 Sham Shriwastav 
	# Status  : open
	# Purpose : make javascript code seprate from other coding
	*/
	
var http; //golbal http object
var target_element_id; //if there is any target element then assing its id to this function
var processing_image_tag; //this will be the processing image path
var show_processing_image; //this will decide whether to show processing image or not

target_element_id="";
var processing_image_path="http://sham/vipdesk_new/images/ajax-loader.gif";
//processing_image_path="http://eluminoustechnologies.net/sham/vipdesk_new/images/ajax-loader.gif";
show_processing_image=1;

var aVersions = [ "MSXML2.XMLHttp.5.0",
        "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
        "MSXML2.XMLHttp","Microsoft.XMLHttp"];

/* The following function creates an XMLHttpRequest object... */
function createRequestObject()
{	
	
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer")
	{		
		for (var i = 0; i < aVersions.length; i++)
		{
			try
			{
				request_o = new ActiveXObject(aVersions[i]); //Create the object using MSIE's method 
			}
			catch(err)
			{
				
			}
		}
		
	}
	else
	{			
		try
		{
			request_o = new XMLHttpRequest();//Create the object using other browser's method 
		}
		catch(err)
		{
			
		}
	}
	return request_o; //return the object
	
	
}

/* The variable http will hold our new XMLHttpRequest object. */
function getData(method,target_file,parameters,target_element_id_param,show_processing_image_param)
{
	try
	{
		http = createRequestObject();
	}
	catch(err)
	{
		txt="Unable create request object!\n\n";
		txt+="Error description: " + err.description + "\n\n";
	//	alert(txt);
	}
	target_element_id=target_element_id_param; //get the return element id
	show_processing_image=show_processing_image_param; //decided whether to show the processing image or not
	if(method=="POST")//if the method is post
	{
		try
		{
			http.open("POST",target_file, true);  
		}
		catch(err)
		{
			txt="Unable to open the connection!\n\n";
			txt+="Error description: " + err.description + "\n\n";
			//alert(txt);
		}
		http.onreadystatechange = handle_response; //use this callback function when the ready state changes
		try
		{
			http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");   
			http.setRequestHeader("Content-length", parameters.length);   
			http.setRequestHeader("Connection", "close");	
		}
		catch(err)
		{
			txt="Unable to set the request header!\n\n";
			txt+="Error description: " + err.description + "\n\n";
		//	alert(txt);
		}
		try
		{
			http.send(parameters); /* Send the data. We use something other than null when we are sending using the POST
		method. */	
		}
		catch(err)
		{
			txt="Unable to set the send the request\n\n";
			txt+="Error description: " + err.description + "\n\n";
			alert(txt);
		}
	}
		
	if(method=="GET")
	{
		target_url=target_file+"?"+parameters;		
		try
		{
			http.open('get',target_url);	
		}
		catch(err)
		{
			txt="Unable to open the connection!\n\n";
			txt+="Error description: " + err.description + "\n\n";
			//alert(txt);
		}
		http.onreadystatechange = handle_response;
		try
		{
			http.send(null); /* Send the data. Use null to send data using get */
		}
		catch(err)
		{
			txt="Unable to set the send the request\n\n";
			txt+="Error description: " + err.description + "\n\n";
			//alert(txt);
		}
	}
}


// This function handles the response
// Make sure that the transaction has finished. 
// The XMLHttpRequest object has a property called readyState with several states:
// 0: Uninitialized
// 1: Loading
// 2: Loaded
// 3: Interactive
// 4: Finished
function handle_response()
{
	try
	{
		var readystate=http.readyState;
	}
	catch(err)
	{
		txt="Unable to get the ready state !\n\n";
		txt+="Error description: " + err.description + "\n\n";
		//alert(txt);
	}
	if(readystate<4)
	{
		if(processing_image_path!="" && show_processing_image==1)
		{
			var response = "<img src='"+processing_image_path+"' />";
			show_response(response);
		}
	}
	if(readystate == 4)
	{
		req_status=http.status;
		switch(req_status)
		{
			case 200:
				var response = http.responseText;	
				show_response(response);
				break;
			case 400:
				alert("Bad Request");
				break;
			case 401:
				alert("Unauthorised Request");
				break;
			case 403:
				alert("Forbidden Request");
				break;
			case 404:
				alert("File Not Found");
				break;
			case 500:
				alert("Internal Server Error");
				break;
			default:
				alert("No valid response received !");
				break;
		}
	}
}

// This functions shows the response at the proper place
function show_response(response)
{
	//alert(response);
	/*
	if(document.getElementById(target_element_id))	
	{
		document.getElementById(target_element_id).innerHTML = response;
	}*/
}

function BrowserInfo()
{
  this.name = navigator.appName;

  this.codename = navigator.appCodeName;

  this.version = navigator.appVersion.substring(0,4);

  this.platform = navigator.platform;

  this.javaEnabled = navigator.javaEnabled();

  this.screenWidth = screen.width;

  this.screenHeight = screen.height;
}

function browserDetection()
{
		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: "OmniWeb",
				versionSearch: "OmniWeb/",
				identity: "OmniWeb"
			},
			{
				string: navigator.vendor,
				subString: "Apple",
				identity: "Safari"
			},
			{
				prop: window.opera,
				identity: "Opera"
			},
			{
				string: navigator.vendor,
				subString: "iCab",
				identity: "iCab"
			},
			{
				string: navigator.vendor,
				subString: "KDE",
				identity: "Konqueror"
			},
			{
				string: navigator.userAgent,
				subString: "Firefox",
				identity: "Firefox"
			},
			{
				string: navigator.vendor,
				subString: "Camino",
				identity: "Camino"
			},
			{		// for newer Netscapes (6+)
				string: navigator.userAgent,
				subString: "Netscape",
				identity: "Netscape"
			},
			{
				string: navigator.userAgent,
				subString: "MSIE",
				identity: "Explorer",
				versionSearch: "MSIE"
			},
			{
				string: navigator.userAgent,
				subString: "Gecko",
				identity: "Mozilla",
				versionSearch: "rv"
			},
			{ 		// for older Netscapes (4-)
				string: navigator.userAgent,
				subString: "Mozilla",
				identity: "Netscape",
				versionSearch: "Mozilla"
			}
		],
		dataOS : [
			{
				string: navigator.platform,
				subString: "Win",
				identity: "Windows"
			},
			{
				string: navigator.platform,
				subString: "Mac",
				identity: "Mac"
			},
			{
				string: navigator.platform,
				subString: "Linux",
				identity: "Linux"
			}
		]
	
	};
	BrowserDetect.init();
	//alert(BrowserDetect.browser + ' ' + BrowserDetect.version + '  ' + BrowserDetect.OS);
	return BrowserDetect.browser+ BrowserDetect.version;
}