	/*
	#############################################################################
	# 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: manage_ajax.js
	# Usage: included ( WRITE USAGE DETAILS ) 
	  {
	   -- It is called from header.php
	   -- Contains javascript functions for Ajax handling.
	  } 
	# Update: created on 1-Feb-2007 by swati patel
	# Status: production
	# Purpose: Ajax handling function
	 
	#############################################################################
	ALSO STRICTLY MAINTAINING THE LOGS OF CHANGES AND PERSON NAME 
	#############################################################################

	1.	function doRand()
	
	2.	function browserObject(objid)	
	
	3.	function switchDisplay(objid)
	
	4.	function displayObject(objid)
	
	5.	function hideObject(objid)
	
	6.	function htmlize(str)
	
	7.	function writeMessage(towrite) 
	
	8.	function writeToDoc(data) 
	
	9.	function clearDoc() 
	
	10.	function writeToDiv(data) 								

	11.	function writeToDivSaf(data)
	
	12.	function clearDiv() 
	
	13.	function addBookmark(title,url)
	
	14. function popupInfoWindow(url) 
	
	15.	function jumpLanguage(selObj)
	
	//ajax functions
	
	16. function load_ajax_request(url,trgtDiv,actionName,parameters)
	
	17. function processStatusChange() 		

*/

/**
* Declaration variables
*/
	var screenHeight = window.screen.availHeight;
	
	var screenWidth = window.screen.availWidth;
	
	var colorDepth = window.screen.colorDepth;
	
	var timeNow = new Date();
	
	var referrer = escape(document.referrer);
	
	var windows, mac, linux;
	
	var ie, op, moz, misc, browsercode, browsername, browserversion, operatingsys;
	
	var dom, ienew, ie4, ie5, ie6, moz_rv, moz_rv_sub, ie5mac, ie5xwin, opnu, op4, op5, op6, op7, saf, konq;
	
	var appName, appVersion, userAgent;
	
	var appname = navigator.appName;
	
	var appVersion = navigator.appVersion;
	
	var userAgent = navigator.userAgent.toLowerCase();
	
	var title = document.title;
	
	var checktoggle = 1;
	
	var DOM = "default";
	
	windows = (appVersion.indexOf('Win') != -1);
	
	mac = (appVersion.indexOf('Mac') != -1);
	
	linux = (appVersion.indexOf('Linux') != -1);

/**
* DOM Compatible?
*/
	if (!document.layers)
	{
		dom = (document.getElementById ) ? document.getElementById : false;
	}
	else
	{
		dom = false;
	}

	if (document.getElementById)
	{
		DOM = "default";
	}
	else if (document.layers) 
	{
		DOM = "NS4";
	} 
	else if (document.all)
	{
		DOM = "IE4";
	}

	misc=(appVersion.substring(0,1) < 4);
	
	op=(userAgent.indexOf('opera') != -1);
	
	moz=(userAgent.indexOf('gecko') != -1);
	
	ie=(document.all && !op);
	
	saf=((userAgent.indexOf('safari') != -1) || (navigator.vendor == "Apple Computer, Inc."));
	
	konq=(userAgent.indexOf('konqueror') != -1);

	if (op) 
	{
		op_pos = userAgent.indexOf('opera');
		
		opnu = userAgent.substr((op_pos+6),4);
		
		op5 = (opnu.substring(0,1) == 5);
		
		op6 = (opnu.substring(0,1) == 6);
		
		op7 = (opnu.substring(0,1) == 7);
	} 
	else if (moz)
	{
		rv_pos = userAgent.indexOf('rv');
		
		moz_rv = userAgent.substr((rv_pos+3),3);
		
		moz_rv_sub = userAgent.substr((rv_pos+7),1);
		
		if (moz_rv_sub == ' ' || isNaN(moz_rv_sub)) 
		{
			moz_rv_sub='';
		}
		
		moz_rv = moz_rv + moz_rv_sub;
		
	} 
	else if (ie)
	{
		ie_pos = userAgent.indexOf('msie');
		
		ienu = userAgent.substr((ie_pos+5),3);
		
		ie4 = (!dom);
		
		ie5 = (ienu.substring(0,1) == 5);
		
		ie6 = (ienu.substring(0,1) == 6);
	}

	if (konq) 
	{
		browsercode = "KO";
		
		browserversion = appVersion;
		
		browsername = "Knoqueror";
		
	} 
	else if (saf) 
	{
		browsercode = "SF";
		
		browserversion = appVersion;
		
		browsername = "Safari";
		
	} 
	else if (op) 
	{
		browsercode = "OP";
		
		if (op5) 
		{
			browserversion = "5";
			
		}
		else if (op6) 
		{
			browserversion = "6";
			
		} 
		else if (op7) 
		{
			browserversion = "7";
		}
		else 
		{
			browserversion = appVersion;
		}
		browsername = "Opera";
		
	} 
	else if (moz) 
	{
		browsercode = "MO";
		
		browserversion = appVersion;
		
		browsername = "Mozilla";
	}
	else if (ie) 
	{
		browsercode = "IE";
		
		if (ie4) 
		{
			browserversion = "4";
		} 
		else if (ie5) 
		{
			browserversion = "5";
		} 
		else if (ie6) 
		{
			browserversion = "6";
		} 
		else 
		{
			browserversion = appVersion;
		}
		browsername = "Internet Explorer";
	}
	
	if (windows) 
	{
		operatingsys = "Windows";
	} 
	else if (linux) 
	{
		operatingsys = "Linux";
	} 
	else if (mac) 
	{
		operatingsys = "Mac";
	}
	else
	{
		operatingsys = "Unkown";
	}
	
	function doRand()
	{
		var num;
		
		now=new Date();
		
		num=(now.getSeconds());
		
		num=num+1;
		
		return num;
	}
	
	function browserObject(objid)
	{
		if (DOM == "default")
		{
			return document.getElementById(objid);
		} 
		else if (DOM == "NS4")
		{
			return document.layers[objid];		
		}
		else if (DOM == "IE4") 
		{
			return document.all[objid];
		}
	}
	
	function switchDisplay(objid)
	{
		result = browserObject(objid);
		
		if (!result)
		{
			alert("Invalid Display Object: "+objid+"\nPlease make sure that all correct display objects are on the page");
			
			return;
		}
	
		if (result.style.display == "none")
		{
			result.style.display = "";
		} 
		else 
		{
			result.style.display = "none";
		}
	}
	
	function displayObject(objid)
	{
		result = browserObject(objid);
		if (!result)
		{
			alert("Invalid Display Object: "+objid+"\nPlease make sure that all correct display objects are on the page");
			
			return;
		}
	
		result.style.display = "";
	}
	
	function hideObject(objid)
	{
		result = browserObject(objid);
		
		if (!result)
		{
			alert("Invalid Display Object: "+objid+"\nPlease make sure that all correct display objects are on the page");
			
			return;
		}
	
		result.style.display = "none";
	}
	
	function htmlize(str)
	{
		str = str.replace(/\&/g,"&amp;");
		
		str = str.replace(/\</g,"&lt;");
		
		str = str.replace(/\>/g,"&gt;");
		
		str = str.replace(/\"/g,"&quot;");
		
		str = str.replace(/\n/g,"<br/>\n");
		
		return str;
	}
	
	function writeMessage(towrite) 
	{
		if (browsercode == "OP") 
		{
			window.parent.contentframe.writeToDiv(towrite);
		}
		else if (browsercode == "SF") 
		{
			writeToDivSaf(towrite);
		} 
		else 
		{
			writeToDoc(towrite);
		}
	}
	
	function writeToDoc(data) 
	{
		window.parent.contentframe.window.document.write(data);
	
		if (typeof(scrollBy) != "undefined")
		{
			window.parent.contentframe.window.scrollBy(0, 6000);
		}
		else if (typeof(scroll) != "undefined")
		{
			window.parent.contentframe.window.scrollBy(0, 6000);
		}
	}
	
	function clearDoc() 
	{
		if (browsercode == "OP") 
		{
			window.parent.contentframe.clearDiv();
		}
		else
		{
			window.parent.contentframe.window.document.close();
			
			window.parent.contentframe.window.document.open();
			
			window.parent.contentframe.window.document.clear();
			
			window.parent.contentframe.window.document.write("");
		}
	}
	
	function writeToDiv(data) 
	{
		divobj = browserObject("buffer");
		
		divobj.innerHTML = divobj.innerHTML + data;
	
		if (typeof(scrollBy) != "undefined")
		{
			window.scrollBy(0, 6000);
		}
		else if (typeof(scroll) != "undefined") 
		{
			window.scrollBy(0, 6000);
		}
	}
	
	function writeToDivSaf(data) 
	{
		divobj = parent.contentframe.document.getElementById("buffer");
		
		divobj.innerHTML = divobj.innerHTML+data;
	
		if (typeof(scrollBy) != "undefined")
		{
			window.scrollBy(0, 6000);
		} 
		else if (typeof(scroll) != "undefined") 
		{
			window.scrollBy(0, 6000);
		}
	}
	
	function clearDiv() 
	{
		divobj = browserObject("buffer");
		
		divobj.innerHTML = "";
	}
	
	function addBookmark(title,url)
	{
		if (window.sidebar) 
		{ 
			window.sidebar.addPanel(title, url,""); 
		} 
		else if( document.all ) 
		{
			window.external.AddFavorite( url, title);
		}
		else if( window.opera && window.print ) 
		{
			return true;
		}
	}
	
	function popupInfoWindow(url) 
	{
		screen_width = screen.width;
		
		screen_height = screen.height;
		
		widthm = (screen_width-400)/2;
		
		heightm = (screen_height-500)/2;
		
		window.open(url,"infowindow"+doRand(), "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=400,height=500,left="+widthm+",top="+heightm);
	}

	/**
	* ###############################################
	* AJAX
	* ###############################################
	*/
	
	var ajaxRequest;
	var xmlaction = "";
	var targetDiv = "";
	var post_parameters = "";
	var temp_id = "";
	
	function load_ajax_request(url,trgtDiv,actionName,parameters)
	{	
		xmlaction = actionName;
		
		ajaxRequest = false;
				
		//alert("hi : "+ url);

		post_parameters = parameters;
		
		//alert(window.XMLHttpRequest + " , " + window.ActiveXObject);

		if (window.XMLHttpRequest) // Mozilla, Safari,...
		{	
			try
			{
				ajaxRequest = new XMLHttpRequest();
			}
			catch(e)
			{
				alert("Unable to create instance of XMLHttpRequest!!");
			}
			
		} 
		else if (window.ActiveXObject) // IE
		{
			try 
			{
            	ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); //for IE 7.0
			}
			catch (e) 
			{
				try 
				{
				   	ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); //for IE version < 7.0
				}
				catch (e) 
				{
					alert("Unable to create instance of XMLHttp!!");
					
					return false;
				}
         	}
			
		}
		
		if(ajaxRequest)
		{
			targetDiv = trgtDiv;
			
			ajaxRequest.onreadystatechange = processStatusChange;
			
			ajaxRequest.open("POST", url, true);
			
			ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			
			ajaxRequest.setRequestHeader("Content-length", parameters.length);
			
			ajaxRequest.setRequestHeader("Connection", "close");
			
			//alert(url + parameters);
			
			ajaxRequest.send(parameters);
		}
		else
		{
			alert("Unable to load ajax request!!");
			
			return false;
		}
	}
	
	function processStatusChange() 
	{
		//alert("state:" + ajaxRequest.readyState);

		if (ajaxRequest.readyState == 4) 
		{
			if (ajaxRequest.status == 200)
			 {
				// ======= decide which request has been executed ======= //
				
				switch(xmlaction)
				{
					case "processCouponCode" : 
					
							//alert(ajaxRequest.responseText); 
							var result = ajaxRequest.responseText;
							
							if(result == 1)
							{
								window.location.href = "index.php";
							}
							else if(targetDiv)
							{
								var obj_img_div = browserObject('div_progressbar_img');
								obj_img_div.style.visibility = "hidden";
								obj_img_div.style.display 	 = "none";
								
								if(result == "")
								{
									targetDiv.innerHTML = "";
									alert("Invalid serial number. Please make sure you entered the correct serial number.");
								}
								else
								{
									targetDiv.innerHTML = result;
									targetDiv.style.visibility = "visible";
									targetDiv.style.display = "block";
								}
							}
							break;
							
					/*########################
					**end ***
					*#########################
					*/
				}
			}
		}
	}
	