﻿// JScript File

function propertyResultsPaging(pageIndex,pageSize)
{    

    globalpageIndex = pageIndex;
    globalpageSize = pageSize;
    var id='temp';   
    for(var i = 0; id!=null || id=='temp'; i++)
    {   
        id = document.getElementById("trResults" + i);                           
        if(id!=null)
        {     
            
            if(i >= pageSize * (pageIndex - 1) && i < (pageSize * pageIndex))
            {   
                try
                {   
                    document.getElementById("trResults" + i).style.display="table-row";                                                                         
                }
                catch(ex)
                {                    
                    document.getElementById("trResults" + i).style.display="block";                                        
                }
            }
            else                
                document.getElementById("trResults" + i).style.display="none";
        }            
    } 
}

function changeImage(img)
{
    document.getElementById('imgFirst').src = img;    
}
function homesForRentResult()
{
    document.getElementById('divContentPage').innerHTML = globalHomesForRentResult;  
}
function printableVersion(phoneNo)
{   
    printWin = window.open("","PrintableVersion","left=50,top=50,scrollbars=1,height=600,width=600");    
    printWin.document.write("<TITLE>Printable Version</TITLE>");
    printWin.document.write("<link href='/style.css' rel='stylesheet' type='text/css'>");    
    printWin.document.write("<BODY>");
    printWin.document.write("<div style='width:100%; height:100%; background-color:White;' >");        
    printWin.document.write("<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;<input type=button value='Print This Page' onclick='print();'  />");        
    printWin.document.write("&nbsp;&nbsp;&nbsp;&nbsp;<input type=button value='Close This Window' onclick='window.close();'  />");                    
    
    if(phoneNo != "")
        printWin.document.write("<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;<span class=dp-content-text>Feel free to contact us directly on <strong>"+ phoneNo + "</strong></span>");                    

    var cont = document.getElementById('divContentPage').innerHTML;
    var re = new RegExp("class=grid-pager", 'i');
    cont = cont.replace(re,"class=grid-pager style='display: none;' ");
    cont = cont.replace(/Homes for Rent Result/g,"North BloomField Property Results");
    cont = cont.replace(/Property Details/,"North BloomField Property Details");
    
    printWin.document.write(cont);
    try
    {   
        printWin.document.getElementById('tdDetailsHeader').innerHTML = "";    
        printWin.document.getElementById('trPrint1').innerHTML = "";    
        printWin.document.getElementById('trPrint2').innerHTML = "";    
        printWin.document.getElementById('trPrint3').innerHTML = "";            
    }
    catch(ex){}    
  
    printWin.document.write("</div>");
    printWin.document.write("</BODY>");
    printWin.document.write("</HTML>");
    
    printWin.document.close();    
}
function redirectNewsUrl(url)
{
    window.open(url);
}
function directionMap(mapURL)
{       
    //window.open("/images/Property/"+ mapURL +"","PropertyImage","toolbar=no,scrollbars=yes,top=50,left=50")    
    window.open(mapURL);    
}
function addToFavourite(propId)
{   
    for(var i = 0; readCookie("prop" + i)!=null;i++)
    {
        //just to get the value of i
    }
    createCookie("prop" + i,propId,120);
    alert("Property has been successfully added to your favorite list.\n\n Click on My Favorite to view all your favorite properties.");    
}
function emailToFriendWin(propId)
{
    //window.location.href = "EmailToFriend.aspx?pid="+ propId +""; 
    window.open("/EmailToFriend.aspx?pid="+ propId +"");
}
function propertyDetailWin(propId)
{   
    window.open("/PropertyDetail.aspx?pid="+ propId +"");
}

function searchResults()
{   
    if(document.getElementById('ctl00_ddlCitySearch')!=null)
        var ddlCity = document.getElementById('ctl00_ddlCitySearch');
    else
        var ddlCity = document.getElementById('ddlCitySearch');
        
    var locId = ddlCity.value;            
    var cityName = ddlCity.options[ddlCity.selectedIndex].innerText;
    
    if(locId == 'Any City')
        locId = -1;        
            
    window.location.href = "/"+ cityName +"/"+ locId +"/SearchResults.aspx";
}

//----------------------------------------------------------------------------------------------
//----------------------------------    For Login    -------------------------------------------                 
//----------------------------------------------------------------------------------------------

function searchKeyPress(ev)
{
	var unicode = ev.keyCode ? ev.keyCode : ev.charCode;
	if(unicode == 13) 
	{ 
	
	   var ret = login();
	   return false;
	}
}

function login_CallBack(response)
{  
    document.getElementById('lblMessage').innerHTML = "";            
    if(response!=null && response.error==null && response.value!=null)
    {   
        if(response.value.search('aspx') != -1)
            window.location.href = "/" + response.value;
        else if(response.value == '0')
            document.getElementById('lblMessage').innerHTML = "Invalid Login.";                
        else 
            document.getElementById('lblMessage').innerHTML = "Error While Login.";                    
    } 
}

function login()
{   
    //var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if(!checkEmail('txtLoginEmail','Please Specify valid Email address','lblMessage'))return false;    
    if(!requireField('txtLoginPassword','Please Specify Password','lblMessage'))return false;
    
    var email = document.getElementById('txtLoginEmail').value;
    var pwd = document.getElementById('txtLoginPassword').value;
    //showProcessImage('lblMessage');
    AjaxMethods.Submit(email,pwd,login_CallBack);
}


//----------------------------------------------------------------------------------------------
//------------------------------    End Of Login   ---------------------------------------------                                  
//----------------------------------------------------------------------------------------------

function checkFileExtention(ctrlId,ErrMessage)
{   
    if(document.getElementById(ctrlId).value!="")
    {
        var fileName = document.getElementById(ctrlId).value;
        var extention = fileName.split('.');
        var ext = extention[extention.length - 1];
        if(ext!="jpg" && ext!="gif" && ext!="jpeg" && ext!="JPG" && ext!="GIF" && ext!="JPEG")
        {
            alert('please select only .jpg, .gif or .jpeg file. for ' + ErrMessage)
            return false;        
        }
    }
    return true;
}

function mlsListing()
{
    window.open("/MLSListing.aspx");
}
function playMovie(id)
{    
//    window.open("/PlayMovie.aspx?movie=" + id,"Playing","toolbar=no,scrollbars=yes,height=525,width=745")    
        window.open("/PlayMovie.aspx?movie=" + id,"Playing","toolbar=no,scrollbars=yes,height=335,width=435")    
}
