﻿// JScript File
var $j = jQuery.noConflict();
var str="";
var crt="";

var budj="";
var protype="";
var catId="";
var transaction="";
var bed="";

$j(document).ready(function()
{  
    if(document.getElementById('hdnop'))
    {
        fillBudgetCombo();
        fillCityCombo();
        var v=document.getElementById('hdnop').value.split('##');
        if(v[0]=="cr")
        {
           fillBudgetComboCondition();
           document.getElementById('cmbBedroom').selectedIndex=document.getElementById('hdnBedroom').value;
            //FindAllProperty(0,'','','','');
            //FindProperty(0,'','','','','',v[1]);
        }
        else
        {
            document.getElementById('cmbTransaction').value=document.getElementById('hdnop').value;
             var catId=" and CategoryId =" + document.getElementById('hdnop').value + " ";
            // crt=catId + budj+protype;
             crt=" and CategoryId =" + document.getElementById('hdnop').value + " ";
             
             FindProperty(0,"","","","","",crt);
        }
    } 
});
function fillCityCombo()
{
       $j.ajax({
        type: "POST", 
        url: "SearchProperty.aspx?call=fillCityCombo", 
        data: "", 
        success: function(htmlSearchProperty)
        { 
            var v=htmlSearchProperty.split('|#|');
            //alert(htmlSearchProperty);
            if(v[0]!="-1")
            {
                    var anOption="";
                    var i =0;
                    var objCmb ="";
                    document.getElementById("cmbCity").length=0;          
                    objCmb = document.getElementById("cmbCity");
                    anOption ="";
                    anOption = document.createElement("OPTION");      
                    anOption.text="Select";
                    anOption.value=0;
                    objCmb.options.add(anOption);
                    for(i=0;i<v.length; i++)
                    {
                        anOption ="";
                        anOption = document.createElement("OPTION");
                        var cmbVals =v[i].split('@');
                        anOption.text = cmbVals[1];
                        anOption.value =cmbVals[0]; 
                       // alert(document.getElementById('hdnCity').value);
                      //  alert('Node Value = '+document.getElementById("cmbCity").nodeValue);
//                        if(i+1==document.getElementById('hdnCity').value)
//                        {
//                            objCmb.options.add(anOption);
//                            anOption.defaultSelected = true;
//                          //  anOption.Selected;
//                        }
//                        else
//                        {
                            objCmb.options.add(anOption);          
                        //}
                     }
                  //   alert(document.getElementById("hdnCity").value);
                     objCmb.selectedIndex=document.getElementById("hdnCity").value;
                    // document.getElementById("cmbCity").selectedIndex=document.getElementById("cmbCity").value;
                 //    alert(objCmb.selectedIndex);
            }
        }
   });
}
function fillBudgetCombo()
{    
    if(document.getElementById('hdnop').value=="1" || document.getElementById('hdnop').value=="2" )
    {
            var budget=new Array ("Below 10 Lacs","10 to 15 Lacs","15 to 20 Lacs","20 to 30 Lacs","30 to 40 Lacs","40 to 50 Lacs","50 to 60 Lacs","60 to 75 Lacs","75 lacs to 1 Cr.","1 to 2 Cr." ,"2 to 3 Cr." ,"3 to 5 Cr.","5 to 10 Cr.","More than 10 Cr.");
            var budget1= ('1','2','3','4','5','6','7','8','9','10','11','12','13','14');
           
            var anOption="";
            var i =0;
            var objCmb ="";
            document.getElementById("cmbBudget").length=0;          
            objCmb = document.getElementById("cmbBudget");
            anOption ="";
            anOption = document.createElement("OPTION");      
            anOption.text="Select";
            anOption.value=0;
            objCmb.options.add(anOption);
            for(i=0;i<budget.length; i++)
            {
                anOption ="";
                anOption = document.createElement("OPTION");
                var cmbVals ="";
                anOption.text = budget[i];
                anOption.value = budget[i];   
                objCmb.options.add(anOption);          
             }
    }
    else if(document.getElementById('hdnop').value=="3" || document.getElementById('hdnop').value=="4")
    {
            var budget=new Array ("Below 5000", "5000 to 10000", "10000 to 15000", "15000 to 20000", "20000 to 25000" ,"25000 to 40000" ,"40000 to 70000", "70000 to 1 lacs", "1 to 1.5 Lacs","1.5 to 2 Lacs", "2 to 5 Lacs", "5 to 10 Lacs","More than 10 Lacs");
            var budget1=('1','2','3','4','5','6','7','8','9','10','11','12','13');
            
            var anOption="";
            var i =0;
            var objCmb ="";
            document.getElementById("cmbBudget").length=0;          
            objCmb = document.getElementById("cmbBudget");
            anOption = document.createElement("OPTION");      
            anOption.text="Select";
            anOption.value=0;
            objCmb.options.add(anOption);      
            for(i=0;i<budget.length; i++)
            {
                anOption ="";
                anOption = document.createElement("OPTION");
                var cmbVals ="";             
                anOption.text = budget[i];
                anOption.value = budget[i];
                 objCmb.options.add(anOption);
             }
    }
    
}
function SearchProperty(Id)
{
  //  alert(Id);
           $j.ajax({
        type: "POST", 
        url: "SearchProperty.aspx?call=SearchProperty&Id=" + Id, 
        data: "", 
        success: function(htmlSearchProperty)
        { 
            alert(htmlSearchProperty);
        }
   });
}
function FindProperty(Pageno,orderNm,feildNm,serFld,serTxt,operation,criterea)
{
//alert('FindProperty'+criterea);
        var strBudget="";
        if(document.getElementById('cmbBudget').value!="0")
        {
            strBudget=" and P.Budget_Id='" + document.getElementById('cmbBudget').value+"' ";
        }
        
        $j.ajax({
        type: "POST", 
        url: "SearchProperty.aspx?call=FindProperty&pgno="+Pageno+"&orderNm="+orderNm+"&feildNm="+feildNm+"&serFld="+serFld+"&serTxt="+serTxt+"&op=" +operation + "&criterea=" + criterea +"&Budget="+strBudget, 
        data: "", 
        success: function(htmlFindProperty)
        { 
            document.getElementById('divGrid').innerHTML=htmlFindProperty;
        }
      });
}
var GlobalId=0;
function SendEMail(Id)
{
    GlobalId =Id;
    g_xModalDialog.show('div_dlgForgotPassword');
    document.getElementById('txtName').focus();
}
function HideDialog()
{
    g_xModalDialog.hide('div_dlgForgotPassword');
}

function OpenDialog()
{
    g_xModalDialog.show('div_dlgForgotPassword');
    document.getElementById('txtName').focus();
}
function gotoPhone(e)
{
     if(e.keyCode == 13 || e.keyCode==9)
        {
            document.getElementById('txtPhone').focus();
        }
}
function gotoEmail(e)
{
    if(e.keyCode == 13 || e.keyCode==9)
        {
            document.getElementById('txtEmail').focus();
        }
}
function gotoQuery(e)
{
     if(e.keyCode == 13 || e.keyCode==9)
        {
            document.getElementById('txtQuery').focus();
        }
}
function gotoSend(e)
{
        if(e.keyCode==9)
        {
            document.getElementById('btnSend').focus();
        }
}
var Namefilter  = /^([a-zA-Z\s])+$/;
var Emailfilter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var Mobilefilter=/^([0-9]{10})+$/;
var Numericfilter=/^([0-9])+$/;

function MailSend()
{
   if(ValidateControl())
   {
    $j.ajax({
        type: "POST", 
        url: "MailSend.aspx?call=MailSend&Id="+ GlobalId + "&name=" + document.getElementById('txtName').value+ "&Email="+document.getElementById('txtEmail').value + "&Phone=" + document.getElementById('txtPhone').value + "&Query=" + document.getElementById('txtQuery').value, 
        data: "", 
        success: function(htmlFindProperty)
        { 
            //document.getElementById('divGrid').innerHTML=htmlFindProperty;
            alert(htmlFindProperty);
            HideDialog();
        }
      });
   }
}

function MailSend2Authority()
{
   if(ValidateControl())
   {
    $j.ajax({
        type: "POST", 
        url: "SearchProperty.aspxMailSend.aspx?call=MailSend2Authority&name=" + document.getElementById('txtName').value+ "&Email="+document.getElementById('txtEmail').value + "&Phone=" + document.getElementById('txtPhone').value + "&Query=" + document.getElementById('txtQuery').value, 
        data: "", 
        success: function(htmlMailSend2Authority)
        { 
            //document.getElementById('divGrid').innerHTML=htmlFindProperty;
            alert(htmlMailSend2Authority);
            HideDialog();
        }
      });        
   }
}

function ValidateControl()
{
 if(document.getElementById('txtName').value=="")
    {
        alert('Please enter Your name!');
        document.getElementById('txtName').focus();
        return false;
    }
    if(!Namefilter.test( document.getElementById('txtName').value))
    {
        alert('Invalid Name!');
        document.getElementById('txtName').focus();
        return false;
    }
    if(document.getElementById('txtPhone').value=="")
    {
        alert('Please enter your Contact No!');
        document.getElementById('txtPhone').focus();
        return false;
    }
    if(!Numericfilter.test(document.getElementById('txtPhone').value))
    {
        alert('Invalid Contact No!');
        document.getElementById('txtPhone').focus();
        return false;
    }
    if(document.getElementById('txtEmail').value=="")
    {
        alert('Please enter your Email Id!');
        document.getElementById('txtEmail').focus();
        return false;
    }
    if(!Emailfilter.test(document.getElementById('txtEmail').value))
    {
        alert('Invalid emailId!');
        document.getElementById('txtEmail').focus();
        return false;
    }
    return true;
}

function searchPropertyByType()
{
    if(document.getElementById('cmbPropertyType').value!="0")
    {
        protype=" and PropertyType =" + document.getElementById('cmbPropertyType').value + " ";
        crt=catId + budj+protype;
        FindProperty(0,'','','PropertyType',document.getElementById('cmbPropertyType').value,document.getElementById('hdnop').value,crt);
    }
    else
        FindProperty(0,'','','','',document.getElementById('hdnop').value,crt);
}

function OpenImage(imageName)
{
   document.getElementById("divProductImage").innerHTML= "<img src=\"PropertyImage/" + imageName + "\" alt=\"\" onError=\"this.src='PropertyImage/noimage.jpg';\" />";
     g_xModalDialog.show('div_ProductImage');
     $j("#div_ProductImage").draggable();

}

function HideImage()
{
   g_xModalDialog.hide("div_ProductImage");
}


function FindAllProperty(Pageno,orderNm,feildNm,serFld,serTxt)
{
  //  alert('FindAll');
    var v=document.getElementById('hdnop').value.split('##');
   // alert(v[0]);
 //   alert('v[1] = ' + v[1]);
     $j.ajax({
        type: "POST", 
        url: "SearchProperty.aspx?call=FindAllProperty&pgno="+Pageno+"&orderNm="+orderNm+"&feildNm="+feildNm+"&serFld="+serFld+"&serTxt="+serTxt+"&data="+v[1], 
        data: "", 
        success: function(htmlFindAllProperty)
        { 
            document.getElementById('divGrid').innerHTML=htmlFindAllProperty;
        }
      });
}

function FindAll()
{
    
    str=" CategoryId =" + document.getElementById('cmbTranjcetion').value + " and  PropertyType=" + document.getElementById('cmbproperty_type').value;
    
    if(document.getElementById('cmbCity').value!="-1" )
    {
        str+= " and CityId=" + document.getElementById('cmbCity').value;    
    }
    if(!document.getElementById('cmbBedroom').disabled)
    {
        str+= " and MinimumBed=" + document.getElementById('cmbBedroom').value; 
    } 
    if(document.getElementById('cmbBudget').value!="-1" )
    {
        str+= " and Budget_Id=" + document.getElementById('cmbBudget').value;    
    }
  
 //   window.open("SearchProperty.aspx?newcall");
  /*   $j.ajax({
        type: "POST", 
        url: "index.aspx?call=redirectme", 
        data: "", 
        success: function(htmlFindProperty)
        { 
            alert(htmlFindProperty);
        }
      });       */
      alert('B4');
      alert(str);
    //  $j("#btnSearch1").load("SearchProperty.aspx");
    window.location("SearchProperty.aspx?call=FindAllProperty&op=cr");
      alert('After');
   // FindProperty(0,'','','','','',str);    
}

$j(document).keyup(function(event){
    if (event.keyCode == 27) {
      //  alert('escaped!');
    }
});

function selectBudget()
{
    if(document.getElementById('cmbBudget').value!=0)
    {
        //alert('Befor = ' + crt);
        budj=" and Budget_Id='" + document.getElementById('cmbBudget').value + "' ";
        crt=catId + budj+protype;
        //alert('After = ' + crt);
        FindProperty(0,'','','','','',crt);        
    }
}

function SearchCriterea()
{
    crt =" and P.CategoryId=" + document.getElementById('cmbTransaction').value + " ";       
    crt +=" and P.PropertyType=" + document.getElementById('cmbPropertyType').value + " ";
    crt +=" and P.MinimumBed>=" + document.getElementById('cmbBedroom').value+" ";
    if(document.getElementById('cmbCity').value!="0")
        crt+=" and P.CityId=" + document.getElementById('cmbCity').value+" ";
    
    FindProperty(0,'','','','','',crt);
}

function fillBudgetComboCondition()
{
    var objCmb ="";
    objCmb = document.getElementById("cmbBudget");
    if(document.getElementById('cmbTransaction').value=="1"|| document.getElementById('cmbTransaction').value=="2" )
    {
            var budget=new Array ("Below 10 Lacs","10 to 15 Lacs","15 to 20 Lacs","20 to 30 Lacs","30 to 40 Lacs","40 to 50 Lacs","50 to 60 Lacs","60 to 75 Lacs","75 lacs to 1 Cr.","1 to 2 Cr." ,"2 to 3 Cr." ,"3 to 5 Cr.","5 to 10 Cr.","More than 10 Cr.");
            var budget1= ('1','2','3','4','5','6','7','8','9','10','11','12','13','14');
          
            var anOption="";
            var i =0;
            
            document.getElementById("cmbBudget").length=0;          
           // objCmb = document.getElementById("cmbBudget");
            anOption ="";
            anOption = document.createElement("OPTION");      
            anOption.text="Select";
            anOption.value=0;
            objCmb.options.add(anOption);
            for(i=0;i<budget.length; i++)
            {
                anOption ="";
                anOption = document.createElement("OPTION");
                var cmbVals ="";
                anOption.text = budget[i];
                anOption.value = budget[i];
                objCmb.options.add(anOption);
             }
    }
    else if(document.getElementById('cmbTransaction').value=="3")
    {
            var budget=new Array ( "5000 to 10000", "10000 to 20000", "20000 to 30000", "30000 to 40000" ,"40000 to 50000" ,"50000 to 70000", "70000 to 1 lacs", "1 to 1.5 Lacs","1.5 to 2 Lacs", "2 to 5 Lacs", "5 to 10 Lacs","More than 10 Lacs");
            var budget1=('1','2','3','4','5','6','7','8','9','10','11','12','13');
            
            var anOption="";
            var i =0;
            document.getElementById("cmbBudget").length=0;          
            anOption = document.createElement("OPTION");      
            anOption.text="Select";
            anOption.value=0;
            objCmb.options.add(anOption);      
            for(i=0;i<budget.length; i++)
            {
                anOption ="";
                anOption = document.createElement("OPTION");
                var cmbVals ="";             
                anOption.text = budget[i];
                anOption.value = budget[i];
                 objCmb.options.add(anOption);
             }
    }
    else if( document.getElementById('cmbTransaction').value=="4")
    {
            var budget=new Array ("Below 5000", "5000 to 10000", "10000 to 15000", "15000 to 20000", "20000 to 25000" ,"25000 to 40000" ,"40000 to 70000", "70000 to 1 lacs", "1 to 1.5 Lacs","1.5 to 2 Lacs", "2 to 5 Lacs", "5 to 10 Lacs","More than 10 Lacs");
            var budget1=('1','2','3','4','5','6','7','8','9','10','11','12','13');
            
            var anOption="";
            var i =0;
            document.getElementById("cmbBudget").length=0;          
            anOption = document.createElement("OPTION");      
            anOption.text="Select";
            anOption.value=0;
            objCmb.options.add(anOption);      
            for(i=0;i<budget.length; i++)
            {
                anOption ="";
                anOption = document.createElement("OPTION");
                var cmbVals ="";             
                anOption.text = budget[i];
                anOption.value = budget[i];
                 objCmb.options.add(anOption);
             }
    }
    objCmb.selectedIndex=document.getElementById("hdnBudget").value;
}

function showHide()
{
//    if(document.getElementById('cmbPropertyType').value!=2 && document.getElementById('cmbPropertyType').value<10)
//        document.getElementById('cmbBedroom').disabled=false;
//    else
//        document.getElementById('cmbBedroom').disabled=true;
}

function FillBudget()
{

    if(document.getElementById('myUc1_cmbTranjcetion').value=="1" || document.getElementById('myUc1_cmbTranjcetion').value=="2")
    {
        var budget=new Array ("<--Select-->","Below 10 Lacs","10 to 15 Lacs","15 to 20 Lacs","20 to 30 Lacs","30 to 40 Lacs","40 to 50 Lacs","50 to 60 Lacs","60 to 75 Lacs","75 lacs to 1 Cr.","1 to 2 Cr." ,"2 to 3 Cr." ,"3 to 5 Cr.","5 to 10 Cr.","More than 10 Cr.");
        var budget1=new Array ("-1","Below 10 Lacs","10 to 15 Lacs","15 to 20 Lacs","20 to 30 Lacs","30 to 40 Lacs","40 to 50 Lacs","50 to 60 Lacs","60 to 75 Lacs","75 lacs to 1 Cr.","1 to 2 Cr." ,"2 to 3 Cr." ,"3 to 5 Cr.","5 to 10 Cr.","More than 10 Cr.");
            
           var anOption="";
            var i =0;
            var objCmb ="";
            document.getElementById("myUc1_cmbBudget").length=0;          
                  
            for(i=0;i<budget.length; i++)
            {
                anOption ="";
                anOption = document.createElement("OPTION");
                var cmbVals ="";
                objCmb = document.getElementById("myUc1_cmbBudget");
                
                objCmb.options.add(anOption);
                anOption.text = budget[i];
                anOption.value = budget1[i];
             }
             
    }
    else
    {
//    "<5000", "5000 to 10000", "10000 to 15000", "15000 to 20000", "20000 to 25000" ,"25000 to 40000" ,"40000 to 70000", "70000 to 1 lacs", "1 to 1.5 Lacs","1.5 to 2 Lacs", "2 to 5 Lacs", "5 to 10 Lacs",">10 Lacs"
            var budget=new Array ("<--Select-->", "5000 to 10000", "10000 to 20000", "20000 to 30000", "40000 to 50000" ,"50000 to 60000" ,"60000 to 70000", "70000 to 1 lacs", "1 to 1.5 Lacs","1.5 to 2 Lacs", "2 to 5 Lacs", "5 to 10 Lacs",">10 Lacs");
            var budget1=new Array ("-1", "5000 to 10000", "10000 to 20000", "20000 to 30000", "40000 to 50000" ,"50000 to 60000" ,"60000 to 70000", "70000 to 1 lacs", "1 to 1.5 Lacs","1.5 to 2 Lacs", "2 to 5 Lacs", "5 to 10 Lacs",">10 Lacs");
            
           var anOption="";
            var i =0;
            var objCmb ="";
            document.getElementById("myUc1_cmbBudget").length=0;          
                  
            for(i=0;i<budget.length; i++)
            {
                anOption ="";
                anOption = document.createElement("OPTION");
                var cmbVals ="";
                objCmb = document.getElementById("myUc1_cmbBudget");
                
                anOption.text = budget[i];
                anOption.value = budget1[i];
                objCmb.options.add(anOption);
             }
            
    }
    if(document.getElementById('myUc1_hdnBudget').value!="")
    {
        document.getElementById('myUc1_cmbBudget').value=document.getElementById('myUc1_hdnBudget').value;
    }
}
function SetBudgetValue()
{
    document.getElementById('myUc1_hdnBudget').value=document.getElementById('myUc1_cmbBudget').value;
}
