/*
#############################################################################
# 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 lesson_detail.php
   -- Contains javascript functions for various functionalities.
  } 
# Update: created on 26-Monday-2008 by Seema Abraham
# Status: production
# Purpose: Lists all the internet markters for free products. User can also signup on these markters websites by this page.
 
#############################################################################
ALSO STRICTLY MAINTAINING THE LOGS OF CHANGES AND PERSON NAME 
#############################################################################
*/
/**
* 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);
	}
	
	function jumpLanguage(selObj)
	{
		languageid = selObj.options[[selObj.selectedIndex]].value;
		
		window.location.href = 'index.php?languageid='+languageid;
	}
	
	/**
	* ###############################################
	* AJAX
	* ###############################################
	*/
	
	var ajaxRequest;
	var xmlaction = "";
	var targetDiv = "";
	var post_parameters = "";
	
	function load_ajax_request(url,trgtDiv,actionName,parameters)
	{	
		/*alert(url);
		alert(trgtDiv);
			alert(actionName);
				alert(parameters);*/
				
		
		xmlaction = actionName;
		
		ajaxRequest = false;
				
		post_parameters = parameters;
		
		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() 
	{
		
		if (ajaxRequest.readyState == 4) 
		{
			if (ajaxRequest.status == 200)
			 {
				// ======= decide which request has been executed ======= //
				//alert(ajaxRequest.status+" "+ajaxRequest.readyState);
				switch(xmlaction)
				{				
			
					    case "post_rating" :
						
						var result = ajaxRequest.responseText; 
						
					
						var msg_rate = "";
						
						if(result != '')
						{
							ajax_request_completed = 1;
							
							var msg_status = result.substr(0,1);
							
							if(msg_status == "1")//success
							{
								 var curr_user_rating =  parseInt(result.substr(2,1));
							
								 var arr_result = result.split("@@#$%^&*SEEMAABRAHAMCOMMENTDETAILS*&^%$#@@");
								
								 var confirm_msg = arr_result[0].substr(3);
								 
								 var div_star_content = arr_result[1];
								 
								 var div_star_Obj = browserObject("div_stars");
								 
								 if(div_star_Obj)
								 {
								 	div_star_Obj.innerHTML = div_star_content;	
								 }
								 
								 var rateMsgDivObj = browserObject("ratingMessage");
								 
								 if(rateMsgDivObj)
								 {
								 	rateMsgDivObj.innerHTML = "Thanks for rating!";
								 	
								 	setSkipMessageUpdate(true);
								 	
								 }
								 
							 	var ratingCountDivObj = browserObject("div_ratingcount");
							 	if(ratingCountDivObj)
							 	{
									
									if(ratingCountDivObj.innerHTML!='')
									{
										
										var curr_rating = parseInt(ratingCountDivObj.innerHTML);
									}
									else
									{
										
										curr_rating = 0;
									}
								 	//ratingCountDivObj.innerHTML = (curr_rating + curr_user_rating) + " ratings";
									
									ratingCountDivObj.innerHTML = (curr_rating + 1) + " ratings";
								}
								
								msg_rate = confirm_msg;
							}
							else
							{
								msg_rate = result.substr(2);
								
								alert(msg_rate);
							}
						 }
						break;
						
					
				}
			}
		}
	}
	
	function get_from_post_parameters($fieldName)
	{
		var parameters = post_parameters;
		var arr_params = parameters.split("&");
		
	}
	
	var irsContents = "";
	
	function startIRSTimer()
	{
		if (document.frmaskquestion.txtdesc.value != irsContents && document.frmaskquestion.txtdesc.value != "")
		{
			var pr_url = "knowledgebase_search.html";
			
			var targDiv = "div_knowledgebase_search";
			
			var actionName = "knowledgebase_search";
			
			var params = "txtdesc=" + encodeURI(document.frmaskquestion.txtdesc.value);
			
			load_ajax_request(pr_url,targDiv,actionName,params);
			
			irsContents = document.frmaskquestion.txtdesc.value;
		}
	
		setTimeout('startIRSTimer();', 2000);
	}

