﻿var req;

function Initialize()
{
	try
	{
		req=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			req=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			req=null;
		}
	}
	if(!req && typeof XMLHttpRequest!="undefined")
	{
		req=new XMLHttpRequest();
	}
}

function SendQuery(key)
{
	Initialize();
	var url="./kev.aspx?k="+key+"&PassWord=www.dik.ir";
	
	if(key !="")
	{
            document.getElementById ('autocomplete').style.backgroundImage = 'url(dik_files/loading.gif)';
            document.getElementById ('autocomplete').style.backgroundColor='#FFFFFF';
            document.getElementById ('autocomplete').style.border='none'
            document.getElementById ('autocomplete').innerHTML = '<br/><br/>';
            ShowDiv("autocomplete");
	
		    if(req!=null)
	        {  
		    req.onreadystatechange = Process;
		    req.open("GET",encodeURI(url), true);
            req.send(null); 
	        }
	}
	else
	    {HideDiv("autocomplete");}
	    
}
function Process()
{ 
	if (req.readyState == 4) 
        {
        // only if "OK"
			if (req.status == 200) 
			{
				if(req.responseText=="" || req.responseText=="farsi" )
					HideDiv("autocomplete");
				else
				{
					ShowDiv("autocomplete");
                    Sresult=req.responseText		
                    			
					document.getElementById ('autocomplete').style.backgroundImage = 'none';
                    document.getElementById ('autocomplete').style.backgroundColor='#ffffC0';
                    document.getElementById ('autocomplete').style.border='1px solid #AAAAAA'
                    document.getElementById ('autocomplete').style.borderTop='none';
                    
                   

                    
                    if (Sresult.substring(0,5) == "farsi")
					{
					    document.getElementById ('autocomplete').style.direction='ltr';
					    document.getElementById ('autocomplete').style.textAlign='left';
                    
                            if (Sresult.substring(5,16) == "noneprondik")
					        {
					
                                Sresult=Sresult.substring(16);                        
                                
                                document.getElementById('DikPronunciation').innerHTML ="";
                                //document.getElementById('DikPronunciation').innerHTML ="<object style=\"margin: 0 0 0 3px;\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\"  codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\"   width=\"28\" height=\"18\">  <param name=\"movie\" value=\"http://dik.ir/sound.swf\">  <param name=\"menu\" value=\"false\">  <param name=\"wmode\" value=\"transparent\">  <param name=\"FlashVars\" value=\"sound_src=./A0002200.mp3\">  <embed style=\"margin: 0 0 0 3px;\" src=\"./sound.swf\" flashvars=\"sound_src=./A0002200.mp3\"  menu=\"false\" width=\"28\" height=\"18\" wmode=\"transparent\" type=\"application/x-shockwave-flash\"    pluginspage=\"http://www.macromedia.com/go/getflashplayer\"> </object>";
                            }
                            else
                            {
                                mpron=Sresult.substring(5,Sresult.indexOf(".mp3"));
                                mpron+=".mp3";

                                Sresult=Sresult.substring(Sresult.indexOf(".mp3")+4);                        
                                //document.getElementById('DikPronunciation').innerHTML =mpron;
                                document.getElementById('DikPronunciation').innerHTML ="<object style=\"margin: 0 0 0 3px;\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\"  codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\"   width=\"28\" height=\"18\">  <param name=\"movie\" value=\"http://dik.ir/sound.swf\">  <param name=\"menu\" value=\"false\">  <param name=\"wmode\" value=\"transparent\">  <param name=\"FlashVars\" value=\"sound_src="+mpron+"\">  <embed style=\"margin: 0 0 0 3px;\" src=\"http://dik.ir/sound.swf\" flashvars=\"sound_src="+mpron+"\"  menu=\"false\" width=\"28\" height=\"18\" wmode=\"transparent\" type=\"application/x-shockwave-flash\"    pluginspage=\"http://www.macromedia.com/go/getflashplayer\"> </object>";
                            }
                    
                    }
                    else 
                    {
					    document.getElementById ('autocomplete').style.direction='rtl';
					    document.getElementById ('autocomplete').style.textAlign='right';
                    }
                    document.getElementById("autocomplete").innerHTML=Sresult;
                   }
			}
			else 
			{
				document.getElementById("autocomplete").innerHTML="There was a problem retrieving data:<br>"+req.statusText;
			}
		}
		
		
		
		
//dar google chrome pas az load shodan flash haye marboot be clock haye analog namayesh dade nemishavad ,in code baraye refresh kardan safhe dar zamani ke karbar time ra neveshte bashad mibashad. google chrome 10.0.648.204
	if(document.getElementById("keyword").value=="time")
        window.location.href='#';      
      
      		
}

function Play (file) {
			document.getElementById ('ppsound').innerHTML = '<embed src="'+file+'" autostart="true" loop="false" hidden="true" height="0" width="0" />';
		}
		
function ShowDiv(divid) 
{
   if (document.layers) document.layers[divid].visibility="show";
   else document.getElementById(divid).style.visibility="visible";
}

function HideDiv(divid) 
{
    document.getElementById("autocomplete").innerHTML ="";
    document.getElementById('DikPronunciation').innerHTML ="";

   if (document.layers) document.layers[divid].visibility="hide";
   else document.getElementById(divid).style.visibility="hidden"; 
}

function BodyLoad()
{

	HideDiv("autocomplete");
	document.form1.keyword.focus();
}

