﻿	
	//functions.js
	
	//Create a boolean variable to check for a valid MS instance.
	var xmlhttp = false;
	
	//Check if we are using IE.
	try {
		//If the javascript version is greater than 5.
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		//If not, then use the older active x object.
		try {
			//If we are using IE.
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			//Else we must be using a non-IE browser.
			xmlhttp = false;
		}
	}
	
	//If we are using a non-IE browser, create a javascript instance of the object.
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	
	
	
	function findPosX(obj){
		var curleft = 0;
		if (obj.offsetParent){
			while (obj.offsetParent){
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		} else if (obj.x){
			curleft += obj.x;
		}
		return curleft;
	}
	
	function findPosY(obj){
		var curtop = 0;
		if (obj.offsetParent){
			while (obj.offsetParent){
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		} else if (obj.y){
			curtop += obj.y;
		}
		return curtop;
	}
	
	function autocomplete (thevalue, e){
		
		theObject = document.getElementById("autocompletediv");
		
		theObject.style.visibility = "visible";
		theObject.style.width = "208px";
		
		var posx = 0;
		var posy = 0;
		
		posx = (findPosX (document.getElementById("txtSearch")) + 0);
		posy = (findPosY (document.getElementById("txtSearch")) + 22);
		
		theObject.style.left = posx + "px";
		theObject.style.top = posy + "px";
		
		var theextrachar = e.which;
		
		if (theextrachar == undefined){
			theextrachar = e.keyCode;
		}
		
		//The location we are loading the page into.
		var objID = "autocompletediv";
		
		//Take into account the backspace.
		var kof = /%DA%A9/gi;
		var yeh = /DB%8C/gi;
		var query = encodeURIComponent(thevalue);
		
		query = query.replace(kof, "%D9%83" );
		query = query.replace(yeh, "%D9%8A" );
		
		var serverPage = "autocompleteHandler.php" + "?sstring=" + query ;
		//alert(serverPage);
		
		//alert(serverPage);
		
		var obj = document.getElementById(objID);
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				obj.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.setRequestHeader("Content-Type","charset=utf-8");
		xmlhttp.send(null);
		
	}
	
	function setvalue (thevalue){
		acObject = document.getElementById("autocompletediv");
		
		acObject.style.visibility = "hidden";
		acObject.style.height = "0px";
		acObject.style.width = "0px";
		
		document.getElementById("txtSearch").value = thevalue;
	}
	
	function OpenItem(id)
	{
		strURL="searchResult.php?id=" + id;
		window.open(strURL,'','left=240, top=100, width=512, height=512, resizable=0, status=0, Scrollbars=0, toolbar=0, menubar=0');
		return;
	}

	
	function openPic(Address)
	{
		window.open(Address, '','left=10, top=10, width=850,height=650, resizable=1, status=1, Scrollbars=1, toolbar=0, menubar=0');
	}

	function OpenNews(id)
	{
		strURL="Newshome.php?id=" + id;
		window.open(strURL,'','left=0, top=0, width=800, height=600, resizable=0, status=0, Scrollbars=1, toolbar=0, menubar=0');
		return;
	}
	function OpenArticles(id)
	{
		strURL="articles.php?id=" + id;
		window.open(strURL,'','left=0, top=0, width=800, height=600, resizable=0, status=0, Scrollbars=1, toolbar=0, menubar=0');
		return;
	}
	
	function encodeFarsi(string){
	}
	
	function ImgCloseOver(ImgID)
{
	ImgID.src="images/BtnClose2.gif";
	ImgID.style.cursor="hand";
}

function ImgCloseOut(ImgID)
{
	ImgID.src="images/BtnClose.gif";
}
