var xmlHttp;
var catid;
var catid1;
function showadd1(s,t,i)
{
//;alert(make_id);
var tocity = document.getElementById('to_city').value;
//alert(s);
//alert(tocity);
var url="city_details.php?tocity="+t+"&fromcity="+s+"&rid="+i;
xmlHttp=GetXmlHttpObject(mystateshowadd1);
xmlHttp.open("GET", url , true);
xmlHttp.send(null);
//remmenu2();
}

function mystateshowadd1()
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
resp=xmlHttp.responseText;
//alert(resp);
document.getElementById("div1").innerHTML=resp;
}
}
function transpotcity1(s)
{
//;alert(make_id);
var tocity = document.getElementById('to_city').value;
//alert(s);
//alert(tocity);
var url="city_details.php?tocity="+tocity+"&fromcity="+s;
xmlHttp=GetXmlHttpObject(mystatetranspotcity1);
xmlHttp.open("GET", url , true);
xmlHttp.send(null);
//remmenu2();
}

function mystatetranspotcity1()
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
resp=xmlHttp.responseText;
//alert(resp);
document.getElementById("div1").innerHTML=resp;
}
}

function submit_city1()
{
//;alert(make_id);
var city_id = document.getElementById('city_id').value;
var url="estimate.php?city_id="+city_id;
xmlHttp=GetXmlHttpObject(mystateChangedcity2);
xmlHttp.open("GET", url , true);
xmlHttp.send(null);
//remmenu2();
}

function mystateChangedcity2()
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
resp=xmlHttp.responseText;
//alert(resp);
document.getElementById("div_total").innerHTML=resp;
}
}
function get_city1()
{
//;alert(make_id);
var country_id = document.getElementById('country_id').value;
var url="get_city1.php?country_id="+country_id;
xmlHttp=GetXmlHttpObject(mystateChangedcity1);
xmlHttp.open("GET", url , true);
xmlHttp.send(null);
//remmenu2();
}

function mystateChangedcity1()
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
resp=xmlHttp.responseText;
//alert(resp);
document.getElementById("div_city").innerHTML=resp;
}
}


function get_city()
{
//alert("aaa");
var country_id = document.getElementById('country_id').value;
var url="get_city.php?country_id="+country_id;
xmlHttp=GetXmlHttpObject(mystateChangedcity);
xmlHttp.open("GET", url , true);
xmlHttp.send(null);
//remmenu2();
}

function mystateChangedcity()
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
resp=xmlHttp.responseText;
//alert(resp);
document.getElementById("div_city").innerHTML=resp;
document.getElementById("div_destiny").innerHTML='';
document.getElementById("div_destiny1").innerHTML='';
}
}
function getdestiny()
{
//alert("here");
var city_id = document.getElementById('city_id').value;
var url="get_destination.php?city_id="+city_id;
xmlHttp=GetXmlHttpObject(mystateChangeddestiny);
xmlHttp.open("GET", url , true);
xmlHttp.send(null);
//remmenu2();
}
function mystateChangeddestiny()
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
resp=xmlHttp.responseText;
//alert(resp);
///document.getElementById("div_destiny11").innerHTML=resp;
document.getElementById("div_destiny").innerHTML=resp;
}
}
function make_blank()
{
//return transport_city();
}
function transport_city()
{
//alert("here");
var fromcity = document.getElementById('fromcity').value;
var tocity = document.getElementById('to_city').value;
var url="transportcity.php?fromcity="+fromcity+"&tocity="+tocity;
xmlHttp=GetXmlHttpObject(mystateChangedtransport);
xmlHttp.open("GET", url , true);
xmlHttp.send(null);
//remmenu2();
}
function mystateChangedtransport()
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
resp=xmlHttp.responseText;
//alert(resp);
///document.getElementById("div_destiny11").innerHTML=resp;
document.getElementById("div_destiny1").innerHTML=resp;
}
}
function sectioncheck1(sec_id)
{
// alert(game_id+"----"+title_id);
var url="get_subsection.php?section_id="+sec_id;
xmlHttp=GetXmlHttpObject(mystateChanged);
xmlHttp.open("GET", url , true);
xmlHttp.send(null);
//remmenu2();
}

function mystateChanged()
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
resp=xmlHttp.responseText;
//alert(resp);

myarr1=resp.split("##")
myarr1len=myarr1.length;
//alert(myarr1len);
divstr="<select name='sub_section' class='textbox'><option value=''>Sub Section</option>";
    for (x=0;x<(myarr1len-1);x++)
    {
       str1=myarr1[x];
       myarr2=str1.split("#");
       //alert(myarr2[0]+"--"+myarr2[1]);
       divstr=divstr+"<option value='"+myarr2[0]+"'>"+myarr2[1]+"</option>";

    }
    divstr=divstr+"</select>";
  //  alert(divstr);
    document.getElementById("div_sub_section").innerHTML=divstr;

}
}




function mygamev(game_id,title_id,tid,otid)
{
// alert(game_id+"----"+title_id);
var url="testgamev.php?game_id="+game_id+"&title_id="+title_id+"&tid="+tid+"&otid="+otid;
xmlHttp=GetXmlHttpObject(mystateChangedv);
xmlHttp.open("GET", url , true);
xmlHttp.send(null);
//remmenu2();
}

function mystateChangedv()
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
resp=xmlHttp.responseText;
//alert(resp);
resparr=resp.split("*");

if (resparr[0]==0)
{
 notify_text="Wrong";
}
if (resparr[0]==1)
{
 notify_text="Correct";
}


if (resparr[1]!='&nbsp;')
document.getElementById("listen").innerHTML="<a href='iv_translated_file/"+resparr[1]+"' class=cat_anc>Listen Translation</a>";
else
document.getElementById("listen").innerHTML="<span class=mytd>Game End</span>";
document.getElementById("answer").innerHTML="<a href='iv_translated_file/"+resparr[2]+"' class=cat_anc>Listen Answer of previous Attempt</a><br><span class='mytd'><font color='red'>"+notify_text+"</font> Answer: "+resparr[6]+"</span>";
document.getElementById("score").innerHTML="<span class=mytd>Score : "+resparr[3]+"</span>";
document.getElementById("cscore").innerHTML="<span class=mytd>Cumulative Score : "+resparr[5]+"</span>";
is_end=resparr[4];
c_score=resparr[5];
//alert(is_end+"--"+resparr[1]);
imgstr=resparr[7];
myarr1=imgstr.split("##")
    for (x=0;x<2;x++)
    {
       str1=myarr1[x];
       myarr2=str1.split("#");
         for (y=0;y<6;y++)
         {
         // myid="d";
          //alert(myarr2[y]);

         }
         myid="d"+myarr2[1];

         thisstr="<object id=\"MediaPlayer1\" width=180 height=200 classid=\"CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701\" standby=\"Loading Microsoft® Windows® Media Player components...\" type=\"application/x-oleobject\" align=\"middle\"><param name=\"FileName\" value=\"iv_request/"+myarr2[0]+"\"><param name=\"ShowStatusBar\" value=\"True\"><param name=\"DefaultFrame\" value=\"mainFrame\"><embed type=\"application/x-mplayer2\" pluginspage = \"http://www.microsoft.com/Windows/MediaPlayer/\" src=\"iv_request/"+myarr2[0]+"\" align=\"middle\" width=176 height=144 defaultframe=\"rightFrame\" showstatusbar=true></embed></object>";

        // document.getElementById(myid).innerHTML="<img src='iv_request/"+myarr2[0]+"'><br><input type='radio' name='is_match' id="+myarr2[1]+" value="+myarr2[1]+" onclick='mygame("+myarr2[4]+","+myarr2[1]+","myarr2[2]","myarr2[3]")'>";
         if (is_end==0)
         document.getElementById(myid).innerHTML=thisstr+"<br><input type='radio' name='is_match' id="+myarr2[1]+" value="+myarr2[1]+" onclick=\"mygamev('"+myarr2[4]+"','"+myarr2[1]+"','"+myarr2[2]+"','"+myarr2[3]+"');\">";
         else
         document.getElementById(myid).innerHTML=thisstr+"<br>"+myarr2[5];
         //alert(document.getElementById(myid).innerHTML);

    }


  //if (is_end==1)
}
}





function catval(str,ind)
{
var url="getcategory.php?sid=" + Math.random() + "&q=" + str;
xmlHttp=GetXmlHttpObject(stateChanged);
xmlHttp.open("GET", url , true);
xmlHttp.send(null);
showmenu(str,ind);
}

function getprod(prod,mypos)
{ //alert (prod);
catid1=prod;
var url="getcategory1.php?sid=" + Math.random() + "&cat_id=" + prod;
xmlHttp=GetXmlHttpObject(stateChanged1);
xmlHttp.open("GET", url , true);
xmlHttp.send(null);
showprod();

}

function stateChanged1()
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ ccc="catdiva"+catid1;
document.getElementById(ccc).innerHTML=xmlHttp.responseText;
} 
}

function catval1()
{ 
 //alert ("out");
//document.getElementById("cataj").innerHTML="";
document.getElementById("cataj").style.visibility="hidden";
} 
function catval2(ddd)
{
 ddd1="catdiva"+ddd;
document.getElementById(ddd1).innerHTML="";
document.getElementById(ddd1).style.visibility="hidden";
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("cataj").innerHTML=xmlHttp.responseText;
} 
} 


function createorder(subcat,subprod,prod,prodprice)
{catid=subprod;
 cqty="qty"+catid;
 myqty=document.getElementById(cqty).value;
 //alert(myqty);
var url="getcategory2.php?sid=" + Math.random() + "&action=add_product&products_id=" + subprod + "&prodid=" + prod +"&cart_quantity="+myqty +"&p_sprice=" + prodprice;
xmlHttp=GetXmlHttpObject(stateChanged2);
xmlHttp.open("GET", url , true);
xmlHttp.send(null);
//remmenu2();
}

function stateChanged2()
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ cdiv="div"+catid;
  ctxt="qty"+catid;

resp=xmlHttp.responseText;
//alert(resp);

resparr=resp.split("^");
//alert (resp);
document.getElementById(cdiv).innerHTML="<table align=right cellspacing=0 cellpadding =0 class=odbox5><tr><td align=right><font color=navy ><b>"+resparr[2] +"</td></tr></table>";
document.getElementById(cdiv).style.textalign="right";
document.getElementById(ctxt).value=resparr[1];
document.getElementById("carttot").innerHTML="<font color=white><b>"+resparr[0]+"</b>";

//document.getElementById(cdiv).style.visibility="visible";
} 
}
function delprod(subcat,subprod,prod)
{catid=subprod;

var url="getcategory2.php?sid=" + Math.random() + "&action=del_product&products_id=" + subprod + "&prodid=" + prod ;
xmlHttp=GetXmlHttpObject(stateChanged3);
xmlHttp.open("GET", url , true);
xmlHttp.send(null);
//remmenu2();
}

function stateChanged3()
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ cdiv="div"+catid;
ctxt="qty"+catid;
resp=xmlHttp.responseText;

resparr=resp.split("^");
if(resparr[2]==0)
document.getElementById(cdiv).innerHTML="";
else
document.getElementById(cdiv).innerHTML="<font color=navy ><b>"+resparr[2];
document.getElementById(cdiv).style.textalign="right";
if(resparr[1]==0)
document.getElementById(ctxt).value="";
else
document.getElementById(ctxt).value=resparr[1];
document.getElementById("carttot").innerHTML="<font color=white><b>"+resparr[0]+"</b>";
} 
}

function GetXmlHttpObject(handler)
{ 
var objXmlHttp=null;

if (navigator.userAgent.indexOf("Opera")>=0)
{
alert("This example doesn't work in Opera");
return 
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{ 
var strName="Msxml2.XMLHTTP";
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.XMLHTTP";
} 
try
{ 
objXmlHttp=new ActiveXObject(strName);
objXmlHttp.onreadystatechange=handler;
return objXmlHttp;
} 
catch(e)
{ 
alert("Error. Scripting for ActiveX might be disabled");
return 
} 
} 
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
objXmlHttp=new XMLHttpRequest();
objXmlHttp.onload=handler;
objXmlHttp.onerror=handler;
return objXmlHttp;
}
} 

function getbrowsertype()
{
    var AgntUsr=navigator.userAgent.toLowerCase();
    var AppVer=navigator.appVersion.toLowerCase();
    var DomYes=document.getElementById?1:0;
    var NavYes=AgntUsr.indexOf('mozilla')!=-1&&AgntUsr.indexOf('compatible')==-1?1:0;
    var ExpYes=AgntUsr.indexOf('msie')!=-1?1:0;
    if (NavYes==1)
    return 1;
    if (ExpYes==1)
    return 0;
    
    
    //alert(NavYes);
    //alert(ExpYes);
}


function showmenu(myid,myind)
{var x;
x=0;
//alert (myid);
var thisid;
 thisid=document.getElementById("cataj");


    thisid.style.visibility="visible";
    z=document.body.offsetWidth; 

    var btype;
    btype=getbrowsertype();
    if (btype==1)
    x=z-800+18;
    else
    x=z-800;
    x=x/2;
    x=x+70;
    //alert (x);
    thisid.style.left=x;
    mytop=94;
    topinc=myind*36.5;
    mytop=mytop+topinc;
    thisid.style.top=mytop;

    //thisid.style.visibility="hidden";


 }

function showprod()
{var x;
x=0;

var thisid;
thisid1="catdiva"+catid1;
 thisid=document.getElementById(thisid1);

 //alert (thisid1);
    thisid.style.visibility="visible";


    //thisid.style.visibility="hidden";


 }

function remmenu()
{
var thisid;
 thisid=document.getElementById("cataj");
      // alert();
   thisid.style.visibility="hidden";
}
function showmenu1()
{
var thisid;
 thisid=document.getElementById("cataj");
      // alert();
   thisid.style.visibility="visible";
}
function remmenu2()
{
var thisid;
thisid1="catdiva"+catid;
 thisid=document.getElementById(thisid1);
      // alert();
   thisid.style.visibility="hidden";
   thisid.innerHTML="";
}