var xmlHttp;

function selectdictionary()
{ 
    if(chknull())
    {  
    	var	item=document.frm1.searchitem.value;
    	
    	 if((item.indexOf('?')) >= 0)
			{
			  document.frm1.searchtype.options[2].selected=true;
			  
			  document.frm1.searchtype.disabled=true;
			}
			else if((item.indexOf('*')) >= 0)
			{
			  document.frm1.searchtype.options[2].selected=true;
			  
			  document.frm1.searchtype.disabled=true;
			}
			else
			{
				document.frm1.searchtype.disabled=false;
			}
         var type=document.frm1.searchtype.value;
         if(item.indexOf('?') == 0)
        { 
        item=item.replace('?','_');
        }
        if(item.indexOf('*') == 0)
        { 
        item=item.replace('*','$'); 
        }
         var phkey=document.frm1.ph.checked;
         window.location.href = "index.php?action=dictionary&sitem="+item+"&type="+type+"&key="+phkey+"&page=0";
    }
   else
   {
   	alert("Please Enter Character or Word to Search.");
   	return false;
   }
}

function chknull()
{
	if(trim(document.frm1.searchitem.value) == '')
	{
	return false;
	}
    else 
	{
	 return true;	
	}
}


function trim(s){
	while (s.substring(0,1) == ' '){
		s = s.substring(1,s.length);
	}
	while (s.substring(s.length-1,s.length) == ' '){
		s = s.substring(0,s.length-1);
	}
	return s;
}

function check_submit(keyCode)
{	
	if(keyCode == 13)	
    { 
    	selectdictionary();
    	return false;
    }
    else
    {
    	return true;
    }
}


/*Get Meaning on clicking of Word*/
function getMeaning(pk,headword,pron)
{
	
wordHighLight(pk);
xmlHttp=GetXmlHttpObject();
//set variable
if (xmlHttp==null)
{
alert ("Your browser doesn’t support HTTP Request. please use Firefox, Internet Explorer, or Safari");
// if browser doesn’t support xmlHttp, show error message
}
//Comment by sumi var url="get_employee.php"
var url="index.php";
var sitem=document.frm1.searchitem.value;
url=url+"?action=getmean&pkword="+pk+"&headword="+headword+"&pron="+pron;
//send variable command to execute the script
url=url+"&sid="+Math.random()
//send random id
xmlHttp.onreadystatechange=displayMeaning
//if the state of xmlHttp change, go to displayMeaning function
xmlHttp.open("GET",url,true)
//use get method
xmlHttp.send(null)
	
}

function displayMeaning()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
//if AJAX state is complete (4)
{
document.getElementById("search_resultR").innerHTML=xmlHttp.responseText
//alert("TEST ");
//get element where the id is “Result", in this case it goes to the <div> tag
}
if (xmlHttp.readyState==1 || xmlHttp.readyState=="loading")
//if AJAX state is loading (loading)
{
document.getElementById("search_resultR").innerHTML="<img src=\"images/ajax-loader.gif\"/> શોધી રહ્યા છે..."
////alert("TEST 3");
//get element where the id is “Result", in this case it goes to the <div> tag
//send the loading image (loading.gif) that show us the data is being prepared
}
}
/*Get Meaning on clicking of Word*/

/*Onclicking the Other details type Other details Display*/
function getOtherDetails(fkword,fkmeaning)
{
 //alert(fkword+"--"+fkmeaning);
xmlHttp=GetXmlHttpObject();
//set variable
if (xmlHttp==null)
{
alert ("Your browser doesn’t support HTTP Request. please use Firefox, Internet Explorer, or Safari");
// if browser doesn’t support xmlHttp, show error message
}
var url="index.php";
var sitem=document.frm1.searchitem.value;
url=url+"?action=getotherdetails&fkword="+fkword+"&fkmeaning="+fkmeaning;
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=function() {
	  									 displayOtherDetails(fkmeaning);
              						  };

//if the state of xmlHttp change, go to FetchComplete function
xmlHttp.open("GET",url,true);
//use get method
xmlHttp.send(null);
}


function displayOtherDetails(fkm)
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
//if AJAX state is complete (4)
{
document.getElementById("OtherDet_"+fkm).innerHTML=xmlHttp.responseText
//get element where the id is “Result", in this case it goes to the <div> tag
}
if (xmlHttp.readyState==1 || xmlHttp.readyState=="loading")
//if AJAX state is loading (loading)
{
document.getElementById("OtherDet_"+fkm).innerHTML="<img src=\"images/ajax-loader.gif\"/> શોધી રહ્યા છે..."
//get element where the id is “Result", in this case it goes to the <div> tag
//send the loading image (loading.gif) that show us the data is being prepared
}	
}

/*Onclicking the Other details type Other details Display*/

function hideOtherDetail(fkm)
{ 
  document.getElementById("OtherDet_"+fkm).innerHTML='';
}

function getrecords(selObj)
{
	//alert(selObj);
	var val = selObj.options[selObj.selectedIndex].text;
	var sitem=document.frm1.sitem.value;
	 if(sitem.indexOf('?') == 0)
        { 
        sitem=sitem.replace('?','_');
        }
        if(sitem.indexOf('*') == 0)
        { 
        sitem=sitem.replace('*','$'); 
        }
	var type=document.frm1.type.value;
	var totpage=document.frm1.totpage.value;
	window.location.href = "index.php?action=dictionary&page="+val+"&sitem="+sitem+"&type="+type+"&totpage="+totpage;
	
}


function showgetWord(item)
{
	//var item=document.frm1.showmean.value;
	var type=document.frm1.searchtype.value;
//	alert(item +"------------"+type);
	getWord(item,type);
}


function ClickonDetails(pw,pm)
{
det=document.getElementById(pm).innerHTML;
	if(det=='વધુ +')
	{
		document.getElementById(pm).innerHTML='વધુ -';
		getOtherDetails(pw,pm);
		
	}
	else
	{  
		document.getElementById(pm).innerHTML='વધુ +';
		hideOtherDetail(pm);
	}
}


/*This function is for AJAX Call*/
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// check browser firefox, opera 8.0+, safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// browser Internet Explorer
try
{
// IE 6.0+
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
// IE 5.0
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
//return the value
}

/*This function is for AJAX Call*/
function GetXmlHttpObject1()
{
var xmlHttpNEW=null;
try
{
// check browser firefox, opera 8.0+, safari
xmlHttpNEW=new XMLHttpRequest();
}
catch (e)
{
// browser Internet Explorer
try
{
// IE 6.0+
xmlHttpNEW=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
// IE 5.0
xmlHttpNEW=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
//return the value
}


/*To show keyboard on clicking of Checkbox also hide it on clicking*/

function showhideKeyboard(obj)
 {
   if(obj.checked)
   { 
   	 document.getElementById('gk').style.display='';
   	 document.getElementById('ph').disabled=true;
   	 //removeElement();
	 //addElement(); 
	}
	else
	{
	 document.getElementById('gk').style.display='none';
	 document.getElementById('ph').disabled=false;
   	// removeElement1();
	// addElement1();
	}
 }
	

 
 
/*To enable and disable the Phonetic Keyboarde*/
	 function phkey(obj1)
	  {
	 var txtsearch=trim(document.frm1.searchitem.value);
	   if(obj1.checked)
	   {
	   	removeElement1();
	   	addElement1(txtsearch);
	   }
	   else
	   {
	   	removeElement();
	   	addElement(txtsearch);
	   }
	   
	  }
	  
function addElement(ts)
{
var par=document.getElementById('d1');
var newtxt = document.createElement('div');
var txtName = 'dd1';
newtxt.setAttribute('id',txtName);
newtxt.innerHTML = '<input type="text" id="TypePad" maxlength="150" name="searchitem" id="searchitem" value="'+ts+'" size="11" style="height: 20px; width: 200px" onkeypress="return check_submit(event.keyCode);"/>';
//alert(newtxt.innerHTML);
par.appendChild(newtxt);

}

function removeElement()
{
 var par=document.getElementById('d1');
 var chl=document.getElementById('dd1');
 par.removeChild(chl);	
}	

function addElement1(ts)
{
var par=document.getElementById('d1');
var newtxt = document.createElement('div');
var txtName = 'dd1';
newtxt.setAttribute('id',txtName);
newtxt.innerHTML = '<input id="TypePad" type="text" onkeydown="positionChange(event);" onkeyup="changeCursor(this);" onclick="changeCursor(this);" onfocus="changeCursor(this);call();" onkeypress="return change(this,event);" class="inputform" value="'+ts+'" name="searchitem" id="searchitem" maxlength="150" style="height: 20px; width: 200px"/>';
//alert(newtxt.innerHTML);
par.appendChild(newtxt);

}

function removeElement1()
{
 var par=document.getElementById('d1');
 var chl=document.getElementById('dd1');
 par.removeChild(chl);	
}

function wordHighLight(pk)
{

var wordList=new Array();
wordList=document.getElementsByClassName('selected_word');

for (var i = 0; i < wordList.length; i++)
{
  thisDiv = wordList[i].id; 
  document.getElementById(thisDiv).className='word_list';   
}
//Hilight the Selected Word
var wlid="wl_"+pk;
document.getElementById(wlid).className='selected_word';
}


function SaveAs(file)
{
	window.location.href = "index.php?action=SaveAs&file="+file;
}


function PrintWord()
{
	alert("PrintWord");
}