﻿// JScript File
var strTitle="";
var blnClicked = false;
var mapAgt = null;
var mapOfc = null;
var pinPoint = null;
var pinPixel = null;
var glbValue="";

var currPageName = GetCurrentPageName();

function getAgentOfficeData(intPageNum,strType) {  
    
    //if (currPageName =="RealtorSearch.aspx") showProgBarAgt('3',strType);    
    //showLoadingMessage_Home('ListView');
    //showLoadingMessage('undefined', 'ListView');
    ShowLoadingMessage_ShowPrompt('ListView');
    
    document.getElementById('PageFooter').style.display="none";
    
    var intPrevCurPage = 1;
    //if (CheckObject("txtPrevCurPage")) intPrevCurPage = $get('txtPrevCurPage').value;        
    var strFirstName="" ;
    var strLastName ="";
    var strCompanyName ="";
    var intSearchType=0;
    
    var prevCurrentPage=1;
    
    var strCity = $get('txtCity').value;    
    var strZip= $get('txtZipCode').value;
    var strSortOrder = $get('lstSortOrder').value;        
    if (CheckObject("txtPrevCurPage")) intPrevCurPage = $get('txtPrevCurPage').value;    
    
    if ($get('divAgentPane').style.visibility == 'hidden') {               
        strCompanyName = $get('txtCompany').value; 
        intSearchType = 2;
    } else {
        strFirstName = $get('txtFirstName').value;        
        strLastName = $get('txtLastName').value;        
        intSearchType = 1;
    }
                       
    RealtorSearchService.GetSearchResults(strFirstName,strLastName,strCompanyName,strCity,strZip,strSortOrder,intSearchType,intPageNum,prevCurrentPage,radAgtSuccess, radAgtFail);   
}

function SendFeedback() {
    
    var strModule = document.getElementById ("lstModule").value;    
    var strComments = escape(document.getElementById ("txtComments").value);
    var strEmailAddress = document.getElementById ("txtEmail").value;
    var strName = document.getElementById ("txtName").value;
    
    RealtorSearchService.SendFeedback(strModule, strComments, strEmailAddress, strName,FeedbackSuccess, FeedbackFail);   

}

function FeedbackSuccess(e){
    
    if (e != null) {	
    
    }
}

function FeedbackFail() {
    if (!blnAndroid) {
        alert('in feedback Fail');
    }
}

function CheckObject(Name) {
    
    if(eval($get(Name))) {
        return true;
    } else {
        return false;
    }
}

function radAgtSuccess(e) {
 
	if (e != null) {	    
	    
        document.getElementById('divListView').innerHTML = e;
        document.getElementById('PageFooter').style.display = "";

        if (e.search(/No Results found/i) > 0) {            
            document.getElementById("PageFooter").style.paddingTop = 520 + "px";
        }  else {
            //document.getElementById("PageFooter").style.paddingTop = "5px";
            var intRowCount = document.getElementById("divHdnPosition").innerHTML;
            var intPosition;

            if (intRowCount < 10) {
                intPosition = 350;
                if (varBrowser == "IE") {
                    document.getElementById("PageFooter").style.paddingTop = intPosition + "px";
                } else {                    
                    document.getElementById("PageFooter").style.paddingTop = intPosition + "px";
                }
            } else {
                //document.getElementById("PageFooter").style.paddingTop = "10px";
                if (varBrowser == "IE") {
                    document.getElementById("PageFooter").style.paddingTop = "110px";
                } else {
                    document.getElementById("PageFooter").style.paddingTop = "410px";
                }
            }
        }
        
       /*
         var glbFooterPos = FindAbsolutePosition(document.getElementById("divHdnPosition"));
	        
	    //alert(glbFooterPos );
	    var intPosition = glbFooterPos;
        if (intPosition < 650) intPosition  = 1200;
        //alert(intPosition);
        var intRowCount = document.getElementById("divHdnPosition").innerHTML ;
        if (intRowCount < 10 )intPosition = 550;
        if (varBrowser == "IE") {
            document.getElementById("PageFooter").style.top= intPosition + "px";
        } else {
            document.getElementById("PageFooter").style.marginTop= intPosition + "px";
        }*/
	}    		
	
	//Save Search Criteria into cookies
    SaveRealtorCriteriaToCookie();
   
	//if (currPageName =="RealtorSearch.aspx") HideProgBarAgt();
	//SetNormalScreen();
	SetNormalScreen_Prompt();
		
}

function SaveRealtorCriteriaToCookie(){

    var strSrchType ="1";
    
    if (document.forms[0].radSearchBy[1].checked) strSrchType = "2";
    
    createCookie("RSearchType",strSrchType,"7");           
    createCookie("RZip",$get('txtZipCode').value,"7");   
        
    switch (strSrchType){
        case "1":
            //LN,FN
            
            createCookie("RLastName",$get('txtLastName').value,"7");           
            createCookie("RFirstName",$get('txtFirstName').value,"7");                       
            createCookie("RACity",$get('txtCity').value,"7");   
                      
            break;
        
        case "2":
            //Company Name
            createCookie("Company",$get('txtCompany').value,"7"); 
            createCookie("ROCity",$get('txtCity').value,"7");   
            
            break;       
    }
}


function radAgtFail(e) {
	
	alert("Error fetching Agent/Office Search Results: " + e);
	
}

function ShowTB_Iframe(strURL){

    if (!(blnAndroid || blnIpad)) {
        ShowLoadingMessage_ShowPrompt('PropDetLB');
        
        tb_show('Office Details',strURL);
    } else {
        window.open(strURL, "", "");        
    }
}


function showTBAgt(DivId, strID, intSearchType, strTarget, strEmailSubject, strLeadCaptureSrc) {
    // alert(blnAndroid);

    if (!(blnAndroid || blnIpad)) {

        if (currPageName == "RealtorSearch.aspx") ShowLoadingMessage_ShowPrompt('PropDetLB');

        //if (currPageName =="RealtorSearch.aspx") showLoadingMessage('undefined', 'PropDetLB');

        blnView = false;

        if (intSearchType == 1) {
            strTitle = "Agent Details"      //1 - agt srch       
        } else {
            strTitle = "Office Details"     //2 - ofc srch
        }

        //if (!(blnClicked)){
        blnClicked = true;
        RealtorSearchService.GetDetails(strID, intSearchType, strTarget, "0", strEmailSubject, strLeadCaptureSrc, AgtDetailSuccess, AgtDetailFail);
        //}
    } else {
        //alert("AgentProfile.aspx?ID=" + strID + "&SrchType=" + intSearchType);
        window.open("AgentProfile.aspx?ID=" + strID + "&SrchType=" + intSearchType + "&Target=O&src=O&Print=0", "", "");
    }
} 

function showTBOfc(DivId,strID,intSearchType,strTarget,strEmailSubject,strLeadCaptureSrc)  { 
    
    if (currPageName =="RealtorSearch.aspx") showProgBarAgt('4');
        
        blnView = false;
        
        if (intSearchType == 1) {
            strTitle = "Agent Details"      //1 - agt srch       
        } else {
            strTitle = "Office Details"     //2 - ofc srch
        }
        
        //if (!(blnClicked)){
            blnClicked = true;
            RealtorSearchService.GetDetails(strID,intSearchType,strTarget,"0",strEmailSubject,strLeadCaptureSrc,OfcDetailSuccess, AgtDetailFail);                 
        //}
      
} 


function showTBAgt_1(DivId,strID,intSearchType)  { 
    
    blnView = false;
    
    /*if (intSearchType == 1) {
        strTitle = "Agent Details"      //1 - agt srch       
    } else {
        strTitle = "Office Details"     //2 - ofc srch
    }
    */
    var newURL = "#TB_inline?height=420&width=800&inlineId=popAgentContent"; 
    //WriteHighSlideScripts();
    
    //$get('popAgentContent').innerHTML = e;
    //document.write(e);
    //alert(e);
    
    //LoadMap();
    //toggleDisplayOff ('Map');  
    
//    LoadMapAgt();  
//alert(newURL);
    tb_show(strTitle, newURL); 
        
} 

function AgtDetailSuccess(e){
    
    var newURL = "#TB_inline?height=410&width=800&inlineId=popAgentContent"; 
        
    $get('popAgentContent').innerHTML = e;
        
    tb_show(strTitle, newURL); 
    
    document.getElementById("spnOfficeName").innerHTML= wordwrap(strOfficeName, 26, "<br/>\n" );        
    if (document.getElementById("divVideo") != null) {
        document.getElementById('divVideo').style.display='none';
        //document.getElementById('divMortgage').style.display='none';
    }
    
    LoadMapAgt();
    
    //if (currPageName =="RealtorSearch.aspx") HideProgBarAgt();
    if (currPageName =="RealtorSearch.aspx") SetNormalScreen_Prompt();
}

function OfcDetailSuccess(e){

    var newURL = "#TB_inline?height=430&width=800&inlineId=popOfficeContent"; 
        
    $get('popOfficeContent').innerHTML = e;
    
    tb_show(strTitle, newURL); 
    
    //document.getElementById("spnOfficeName").innerHTML= wordwrap(strOfficeName, 26, "<br/>\n" );        
    
    if (CheckObject("spnOfficeName_Det")) {
        if (document.getElementById("spnOfficeName_Det").innerHTML != "") document.getElementById("spnOfficeName_Det").innerHTML = wordwrap(strOfficeName, 26, "<br/>\n" );        
    }
    //alert('det=' + document.getElementById("spnOfficeName_Det").innerHTML );
    //alert(document.getElementById("spnOfficeName").innerHTML + "," + wordwrap(strOfficeName, 26, "<br/>\n" ));
    if (CheckObject("spnOfficeName_Ofc")) {
        //alert('in obj');
        document.getElementById("spnOfficeName_Ofc").innerHTML = wordwrap(strOfficeName, 26, "<br/>\n" );        
    }
    //alert(wordwrap(strOfficeName, 26, "<br/>\n" ));
    //alert(document.getElementById("spnOfficeName").innerHTML );
    if (document.getElementById("divVideo") != null) {
        document.getElementById('divVideo').style.display='none';
        //document.getElementById('divMortgage').style.display='none';
    }
    
    LoadMapOfc();
    
    if (currPageName =="Agentsearch.aspx") HideProgBarAgt();
}

function LoadMapAgt(){
    
    //var map = null;
    var strLatLong = document.getElementById('hidLatLong').value;
    //alert(strLatLong );
    
     var arrLatLon = strLatLong.split(",");
     
    
    var strLatVal = arrLatLon[0];
    var strLonVal = arrLatLon[1];
    
   //var LA = new VELatLong(42.479876,-82.901402);
    var LA = new VELatLong(arrLatLon[0],arrLatLon[1]);

    mapAgt = new VEMap('myMapAgt');

    mapAgt.SetDashboardSize(VEDashboardSize.Small);
    mapAgt.LoadMap(LA, 14, VEMapStyle.Road, false, VEMapMode.Mode2D, true, 1);

    AddPin1();
                  
}

function LoadMapOfc(){
    
    //var map = null;
    var strLatLong = document.getElementById('hidLatLong').value;
    //alert(strLatLong );
    
    var arrLatLon = strLatLong.split(",");
    
    
    var strLatVal = arrLatLon[0];
    var strLonVal = arrLatLon[1];
    
   //var LA = new VELatLong(42.479876,-82.901402);
    var LA = new VELatLong(arrLatLon[0],arrLatLon[1]);

    mapOfc = new VEMap('myMapOfc');

    mapOfc.SetDashboardSize(VEDashboardSize.Small);
    mapOfc.LoadMap(LA, 14, VEMapStyle.Road, false, VEMapMode.Mode2D, true, 1);

    //AddPin1();
    pinPoint = mapOfc.GetCenter();
    pinPixel = mapOfc.LatLongToPixel(pinPoint);
    mapOfc.AddPushpin(pinPoint);
//                  
}

function LoadMap1(){
    
    
   var LA = new VELatLong(42.479876,-82.901402);
   
    map = new VEMap('myMap');

    map.SetDashboardSize(VEDashboardSize.Small);
    map.LoadMap(LA, 14, VEMapStyle.Road, false, VEMapMode.Mode2D, true, 1);

    //AddPin1();
                  
}
         
function AddPin1() {

    // Add a new pushpin to the center of the map.
    pinPoint = mapAgt.GetCenter();
    pinPixel = mapAgt.LatLongToPixel(pinPoint);
    mapAgt.AddPushpin(pinPoint);
    
}


function AgtDetailFail(e) {
    //Process Request Failure
        alert("Error fetching Agent/Office Details: " + e);
}


