﻿function RObj(ea){var LS="";var QS=new Object();var un="undefined";var x=null;var f="function";var n="number";var r="string";var e1="ERROR:Index out of range in\r\nRequest.QueryString";var e2="ERROR:Wrong number of arguments or invalid property assignment\r\nRequest.QueryString";var e3="ERROR:Object doesn't support this property or method\r\nRequest.QueryString.Key";var dU=window.decodeURIComponent?1:0;function Err(arg){if(ea){alert("Request Object:\r\n"+arg)}};function URID(t){var d="";if(t){for(var i=0;i<t.length;++i){var c=t.charAt(i);d+=(c=="+"?" ":c)}}return(dU?decodeURIComponent(d):unescape(d))};function OL(o){var l=0;for(var i in o){if(typeof o[i]!=f){l++}};return l};function AK(key){var auk=true;for(var u in QS){if(typeof QS[u]!=f&&u.toString().toLowerCase()==key.toLowerCase()){auk=false;return u}}if(auk){QS[key]=new Object();QS[key].toString=function(){return TS(QS[key])};QS[key].Count=function(){return OL(QS[key])};QS[key].Count.toString=function(){return OL(QS[key]).toString()};QS[key].Item=function(e){if(typeof e==un){return QS[key]}else {if(typeof e==n){var a=QS[key][Math.ceil(e)];if(typeof a==un){Err(e1+"(\""+key+"\").Item("+e+")")};return a}else {Err("ERROR:Expecting numeric input in\r\nRequest.QueryString(\""+key+"\").Item(\""+e+"\")")}}};QS[key].Item.toString=function(e){if(typeof e==un){return QS[key].toString()}else {var a=QS[key][e];if(typeof a==un){Err(e1+"(\""+key+"\").Item("+e+")")};return a.toString()}};QS[key].Key=function(e){var t=typeof e;if(t==r){var a=QS[key][e];return(typeof a!=un&&a&&a.toString()?e:"")}else {Err(e3+"("+(e?e:"")+")")}};QS[key].Key.toString=function(){return x}};return key};function AVTK(key,val){if(key!=""){var key=AK(key);var l=OL(QS[key]);QS[key][l+1]=val}};function TS(o){var s="";for(var i in o){var ty=typeof o[i];if(ty=="object"){s+=TS(o[i])}else if(ty!=f){s+=o[i]+", "}};var l=s.length;if(l>1){return(s.substring(0,l-2))}return(s==""?x:s)};function KM(k,o){var k=k.toLowerCase();for(var u in o){if(typeof o[u]!=f&&u.toString().toLowerCase()==k){return u}}}if(window.location&&window.location.search){LS=window.location.search;var l=LS.length;if(l>0){LS=LS.substring(1,l);var preAmpAt=0;var ampAt=-1;var eqAt=-1;var k=0;var skip=false;for(var i=0;i<l;++i){var c=LS.charAt(i);if(LS.charAt(preAmpAt)=="="||(preAmpAt==0&&i==0&&c=="=")){skip=true}if(c=="="&&eqAt==-1&&!skip){eqAt=i}if(c=="&"&&ampAt==-1){if(eqAt!=-1){ampAt=i}if(skip){preAmpAt=i+1};skip=false}if(ampAt>eqAt){AVTK(URID(LS.substring(preAmpAt,eqAt)),URID(LS.substring(eqAt+1,ampAt)));preAmpAt=ampAt+1;eqAt=ampAt=-1;++k}}if(LS.charAt(preAmpAt)!="="&&(preAmpAt!=0||i!=0||c!="=")){if(preAmpAt!=l){if(eqAt!=-1){AVTK(URID(LS.substring(preAmpAt,eqAt)),URID(LS.substring(eqAt+1,l)))}else if(preAmpAt!=l-1){AVTK(URID(LS.substring(preAmpAt,l)),"")}}if(l==1){AVTK(LS.substring(0,1),"")}}}};var TC=OL(QS);if(!TC){TC=0};QS.toString=function(){return LS.toString()};QS.Count=function(){return(TC?TC:0)};QS.Count.toString=function(){return(TC?TC.toString():"0")};QS.Item=function(e){if(typeof e==un){return LS}else {if(typeof e==n){var e=Math.ceil(e);var c=0;for(var i in QS){if(typeof QS[i]!=f&&++c==e){return QS[i]}};Err(e1+"().Item("+e+")")}else {return QS[KM(e,QS)]}};return x};QS.Item.toString=function(){return LS.toString()};QS.Key=function(e){var t=typeof e;if(t==n){var e=Math.ceil(e);var c=0;for(var i in QS){if(typeof QS[i]!=f&&++c==e){return i}}}else if(t==r){var e=KM(e,QS);var a=QS[e];return(typeof a!=un&&a&&a.toString()?e:"")}else {Err(e2+"().Key("+(e?e:"")+")")};Err(e1+"().Item("+e+")")};QS.Key.toString=function(){Err(e2+"().Key")};this.QueryString=function(k){if(typeof k==un){return QS}else {if(typeof k==n){return QS.Item(k)};var k=KM(k,QS);if(typeof QS[k]==un){t=new Object();t.Count=function(){return 0};t.Count.toString=function(){return "0"};t.toString=function(){return x};t.Item=function(e){return x};t.Item.toString=function(){return x};t.Key=function(e){Err(e3+"("+(e?e:"")+")")};t.Key.toString=function(){return x};return t}else {return QS[k]}}};this.QueryString.toString=function(){return LS.toString()};this.QueryString.Count=function(){return(TC?TC:0)};this.QueryString.Count.toString=function(){return(TC?TC.toString():"0")};this.QueryString.Item=function(e){if(typeof e==un){return LS.toString()}else {if(typeof e==n){var e=Math.ceil(e);var c=0;for(var i in QS){if(typeof QS[i]!=f&&++c==e){return QS[i]}};Err(e1+".Item("+e+")")}else {return QS[KM(e,QS)]}}if(typeof e==n){Err(e1+".Item("+e+")")};return x};this.QueryString.Item.toString=function(){return LS.toString()};this.QueryString.Key=function(e){var t=typeof e;if(t==n){var e=Math.ceil(e);var c=0;for(var i in QS){if(typeof QS[i]=="object"&&(++c==e)){return i}}}else if(t==r){var e=KM(e,QS);var a=QS[e];return(typeof a!=un&&a&&a.toString()?e:"")}else {Err(e2+".Key("+(e?e:"")+")")};Err(e1+".Item("+e+")")};this.QueryString.Key.toString=function(){Err(e2+".Key")};this.Version=1.4;this.Author="Andrew Urquhart (http://andrewu.co.uk)"};var Request=new RObj(false);

var province, ProvinceCombo,SessionTypeCombo, page,city,Gender,type,keyword,Citycombo,Gendercombo;

function getDropDownLabel(obj)
{
   var element=obj[obj.selectedIndex].firstChild.nodeValue;
   return element;
}

function InitPage()
{
       ProvinceCombo=document.getElementById("cbxProvince");
       SessionTypeCombo=document.getElementById("cbxSessionType");
       Citycombo=document.getElementById("cbxCity");
       Gendercombo=document.getElementById("cbxGender");
       
       if(Request.QueryString("keyword").Count>0)
       {
            city=0;
            Gender=0;
            type=89;
          LoadSessionType("SessionType", 0);
          document.getElementById("divcity").style.display='none';
          Citycombo.style.display='none';
          keyword=Request.QueryString("keyword");
          LoadProvince("Province", 1);
          province=0;
           
       }
       else if(Request.QueryString("province").Count>0)
       {
           province= Request.QueryString("province");
           city=Request.QueryString("city");
           Gender=Request.QueryString("Gender");
           type=Request.QueryString("type");
           LoadSessionType("SessionType", type);
           keyword='';
           Gendercombo.value=Gender;
           LoadProvince("province",province);
           
       }
       else
       {
            city=0;
            Gender=0;
            type=89;
            keyword='';
            LoadSessionType("SessionType", 0);
           LoadProvince("Province", 1);
           province=1;
       }
       
}
//function LoadSessionsByQueryString(part,province,city,Gender,type)
//{
//    ShowLoading();
//    var ajax = new AJAX();
//    var args = {part : part, province : province , city : city , Gender : Gender , type : type };
//    ajax.request("Ajaxify.aspx", args, LoadSessionByQueryStringCallBack);
//}
//function LoadSessionByQueryStringCallBack(response)
//{

//    if (response == null || /Fatal error/.test(response)) 
//    {
//        ShowError();
//        return;
//    }
//    var content=document.getElementById("content");
//    content.innerHTML=response;
//    HideLoading();

//    }

 function LoadSessionType(part, num)
{
    var ajax = new AJAX();
    var args = {part : part, num : num};
    ajax.request("Ajaxify.aspx", args, LoadSessionTypeCallBack);
}

function LoadSessionTypeCallBack(response)
{

    if (response == null || /Fatal error/.test(response)) 
    {
        ShowError();
        return;
    }
        var sp = response.split("|");
        var spID;
        var len = sp.length -1;
        var j;
        AddItem("تمامي جلسات",0);
        for(j=1; j<=len; j++){spID=sp[j].split(";");AddItem(spID[0],spID[1]);}
        function AddItem(Text,Value)
           {
                var opt = document.createElement("option");
                SessionTypeCombo.options.add(opt);
                opt.text = Text;
                opt.value = Value;
           }
        SessionTypeCombo.value = type;
    }
 
function LoadProvince(part, num)
{
    var ajax = new AJAX();
    var args = {part : part, num : num};
    ajax.request("Ajaxify.aspx", args, LoadProvinceCallBack);
}

function LoadProvinceCallBack(response)
{

    if (response == null || /Fatal error/.test(response)) 
    {
        ShowError();
        return;
    }
    var sp = response.split("|");
    var spID;
    var len = sp.length -1;
    var j;
    AddItem("تمامي استانها",0);
    for(j=1; j<=len; j++){spID=sp[j].split(";");AddItem(spID[0],spID[1]);}
    function AddItem(Text,Value)
            {
                var opt = document.createElement("option");
                ProvinceCombo.options.add(opt);
                opt.text = Text;
                opt.value = Value;
            }
        ProvinceCombo.value=province;
        ProvinceSelect();
    }
function ProvinceSelect()
{
    ShowLoading();
    LoadCity("City",ProvinceCombo.value);
 }
 function OnProvinceSelect()
{
    ShowLoading();
    if(ProvinceCombo.value==0)
    {
        document.getElementById("cbxCity").style.display='none';
        document.getElementById("divcity").style.display='none';
    }
    else
    {
        document.getElementById("cbxCity").style.display='block';
        document.getElementById("cbxCity").style.valign='middle';
        document.getElementById("divcity").style.display='block';
    }
    keyword='';
    LoadCity("City",ProvinceCombo.value);
 }

function LoadCity(part, num)
{
    ShowLoading();
    var ajax = new AJAX();
    var args = {part : part, num : num};
    ajax.request("Ajaxify.aspx", args, LoadCityCallBack);
}

function LoadCityCallBack(response)
{
    
    if (response == null || /Fatal error/.test(response)) 
    {
        ShowError();
        return;
    }
    
    var sp = response.split("|");
    var spID;
    var len = sp.length -1;
    var j;
    var Citycombo=document.getElementById("cbxCity")
    function AddItem(Text,Value)
            {
                var opt = document.createElement("option");
                Citycombo.options.add(opt);
                opt.text = Text;
                opt.value = Value;
            }
     var optionLen = Citycombo.options.length;
     for(i=optionLen-1; i>=0; i--)
      {
        Citycombo.remove(i);
      }
      AddItem("تمامي شهرستانها",0);
    for(j=1; j<=len; j++){spID=sp[j].split(";");AddItem(spID[0],spID[1]);}
    Citycombo.value = city;
    
    
//    var keyword=document.getElementById("txtAdvSearch");
//    keyword=keyword.value;
//    var hiddenfield = document.getElementById("Hidden1");
//hiddenfield=hiddenfield.value;
//    alert(keyword + hiddenfield);
//    if(hiddenfield==1)
//    {
       DoSearch(1,keyword); 
//    }
//    else
//    {
//        DoSearch(page,''); 
//    }
    
    
    HideLoading();
}
function teachersearch()
{   
//    var hiddenfield = document.getElementById("Hidden1");
//    hiddenfield.value=1;
    var keyword=document.getElementById("txtAdvSearch");
    keyword=keyword.value;
    DoSearch(1,keyword);
}
function DoSearch(page,keyword)
{
//    var hiddenfield = document.getElementById("Hidden1");
//    hiddenfield.value=0;

    var Citycombo=document.getElementById("cbxCity");
    var Gendercombo=document.getElementById("cbxGender");
    var SessionTypecombo=document.getElementById("cbxSessionType");
    //LoadSessionList("SessionList",page,ProvinceCombo.value,ProvinceCombo.options[ProvinceCombo.selectedIndex].text,Citycombo.value,Citycombo.options[Citycombo.selectedIndex].text,Gendercombo.value,Gendercombo.options[Gendercombo.selectedIndex].text,SessionTypeCombo.value,SessionTypecombo.options[SessionTypecombo.selectedIndex].text,keyword);
	LoadSessionList("SessionList", page, ProvinceCombo.value, ProvinceCombo.options[ProvinceCombo.selectedIndex].text, ProvinceCombo.value == 0 ? 0 : Citycombo.value, ProvinceCombo.value == 0 ? 'تمامي شهرستانها' : Citycombo.options[Citycombo.selectedIndex].text, Gendercombo.value, Gendercombo.options[Gendercombo.selectedIndex].text, SessionTypeCombo.value, SessionTypecombo.options[SessionTypecombo.selectedIndex].text, keyword);
}
function LoadSessionList(part,page, num,provincename,city,cityname,Gender,Gendername,type,typename,keyword)
{
    var ajax = new AJAX();
    var args = {part : part, page : page , num : num , provincename : provincename, city : city , cityname : cityname , Gender : Gender , Gendername : Gendername, type : type, typename : typename , keyword : keyword};
    ajax.request("Ajaxify.aspx", args, LoadSessionListCallBack);
}

function LoadSessionListCallBack(response)
{
    if (response == null || /Fatal error/.test(response)) 
    {
        ShowError();
        return;
    }
    var content=document.getElementById("content");
    content.innerHTML=response;
    HideLoading();

}
function ShowLoading()
{
    var w = 150;
    var h = 30;

    var d = getWinDims();
    var elm = document.getElementById('divLoading');

    elm.style.left   = (d.width - 320)/2  + "px";
    elm.style.top    = "250px";//(d.height - 100)/2 + "px";
    elm.style.height = h + "px";
    elm.style.width  = w + "px";
    elm.style.display = "block";
}
function HideLoading()
{
    //return;
    var elm = document.getElementById('divLoading');
    elm.style.display = "none";
}

function DoChangePage(page,keyword)
{
//    var keyword=document.getElementById("txtAdvSearch");
//    keyword=keyword.value;
//    var hiddenfield = document.getElementById("Hidden1");
//hiddenfield=hiddenfield.value;
//    alert(keyword + hiddenfield);
//    if(hiddenfield==1)
//    {
       DoSearch(page,keyword); 
//    }
//    else
//    {
//        DoSearch(page,''); 
//    }
    
}
