// JavaScript Document
var MLSNumberArray;
var CurrentPosition = 0;
var AgentKEY;
var MLSAllow;
var AgentUserID;
var RecordType;
var Template;
var TotalListing = 0;
var TeamName;
var OfficeKEY;

	$().ready(function(){
	    AgentPrimaryMLS = $("#AgentPrimaryMLS").val();
        AgentKEY = $('#AgentKEY').val();
        MLSAllow = $('#MLSAllow').val();
        AgentUserID = $('#AgentUserID').val();	
        TeamName = $("#AgentTeam").val();
        OfficeKEY = $("#OfficeKEY").val();
        //Template = $("#Template").val();
		RecordType = "160";
		newGetAgentListing();
		
		var L_Height = $('#at2_left').height();
		var R_Height = $('#content').height();
		
		$('#at2_left').css("height", (L_Height>R_Height)?L_Height:R_Height);
		
		if (OfficeKEY=="19") $("#0270").val("1")
		else $("#0270").val(AgentPrimaryMLS);
   	})

    function newGetAgentListing()
    {
        
        var params = "HtmlInterface=TransformToJSON&RecordType=14&n_dt=0&0070=4&n_uc="+AgentKEY;
        
        var oAjaxManager = new DataFloat.Agora.AjaxManager(params);
            oAjaxManager.NewSystemRequest(DataFloat.Agora.Services.ServiceContentManagerCount, 1, function(msg){
                if ($.trim(msg)!="0")
                {
                    var PrimaryBoard = "&0270="+AgentPrimaryMLS;
                    if (OfficeKEY=="4" || OfficeKEY=="11")
                        $("#viewmylisting").attr("href","/SearchResults.aspx?5020_order=descending&0270=1&0040_order=descending&RecordType=160&a_k_14_0030_n_uc="+AgentKEY+"&a_k_14_0030_n_dt=0&a_k_14_0030_0070=4" + PrimaryBoard);
                    else $("#viewmylisting").attr("href","/SearchResults.aspx?5020_order=descending&0040_order=descending&RecordType=160&a_k_14_0030_n_uc="+AgentKEY+"&a_k_14_0030_n_dt=0&a_k_14_0030_0070=4" + PrimaryBoard);
                    $("#viewmylisting").show();
                }
        })
    }
	
	function hideShowLinks()
	{
	    var AgentEP = $("#AgentEP").val();
	    if (AgentEP) $("EPLOGO").show();
	}
	
	//Check if there is predefined agent search -- Enable the drop down
	function agentPredefinedSearchCheck()
	{
	    var AgentKEY = $('#AgentKEY').val();
	    var params = "RecordType=9&Agora__ItemPerPage=1&n_dt=0&n_uc=" + AgentKEY;
        var oAjaxManager2 = new DataFloat.Agora.AjaxManager(params);
            oAjaxManager2.NewSystemRequest(DataFloat.Agora.Services.ServiceContentManagerCount, 1, function(msg){
                if ($.trim(msg)!=0)
                    $("#MySearchLi").show();
            })
        	
	}
	
	// Generate agent Predefined Content
	function agentPredefinedSearch()
	{
	    if ($('#PredefinedSearchDiv').size())
	    {
            var AgentKEY = $('#AgentKEY').val();
            var MLSAllow = $('#MLSAllow').val();
            var AgentUserID = $('#AgentUserID').val();	
		    var RecordType = MLSAllow;
		    var PredefinedHtmlInterface = "AgentPredefinedSearchList";
			
		    var AspNet_formParams = "HtmlInterface=" + PredefinedHtmlInterface + "&RecordType=9&n_dt=0&n_uc=" + AgentKEY;

            //If there is no listing from this agent, we randomly pick one (need to change this logic)
		    var oAgentPSSearch = new DataFloat.Agora.AjaxManager(AspNet_formParams, "PredefinedSearchDiv" , "");
		    oAgentPSSearch.ItemPerPage = 1;
		    oAgentPSSearch.Call(null, null, null, null, DataFloat.Agora.Services.ServiceContentManagerMultipleHtml, "allcontent");
		}
	}
	
	function ViewAllMyProperties()
	{
		AgentUserID = $('#AgentUserID').val();
		window.location.href = "/SearchResult.aspx?get=1&4370=" + AgentUserID + "&agentkey="+AgentKEY+"&template="+Template;;
	}

	function QuickSearchSubmit(formID)
	{
		if ($('#0110').val()==$("#0110").attr("title")) $("#0110").val('');
		if ($('#1050').val()==$("#1050").attr("title")) $("#1050").val('');
		if ($('#4010').val()==$("#4010").attr("title")) $("#4010").val('');
		var params = serializeForm(formID);
	    var fragment = $.param( params );
		$("#"+formID).submit();
	}


	function gotoDetailFromOffice(k, PT)
	{
		linkTo(DOCUMENT_ROOT + '/detail.php?k=' + k + '&PT=' + PT + '&From=Office');
		$('#linkIframe').show();
		$('#columns').hide();
	}
	function submitSearch()
	{
		$('#QuickSearch').attr('target','searchIframe');
		$('#searchIframe').show();
		$('#ContentBody').hide();
	}
	function CheckAgentName()
	{
		var AgentName = $('#agentname').val();
		if (trim(AgentName)=='' || AgentName==' Agent Name')
		{
			linkTo(DOCUMENT_ROOT + '/AgentSearch.php');
			$('#linkIframe').show();
			$('#columns').hide();
			return false;
		}else
		{
			$('#linkIframe').show();
			$('#columns').hide();
			return true;
		}
	}
	function linkTo(URL)
	{
		$('#linkIframe').attr('src',URL);
		$('#linkIframe').show();
		$('#columns').hide();
	}
	
	function contactMeValidation()
	{
		if ($.trim($('#txtName').val())=='')
		{
			alert('Please fill the required field.');
			$('#txtName').focus();
			return false;
		}
		if ($.trim($('txtEmail').val())=='')
		{
			alert('Please fill the required field.');
			$('#txtEmail').focus();
			return false;
		}
		if ($.trim($('#AgentEmail').val())=='')
		{
			alert('Email cannot be sent because agent e-mail is not setup yet.');
			return false;
		}
		return true;
	}
	
	function gotoContact()
	{
		window.location.href = $('#ContactMe').attr('href');
	}

	function frameOutPage(URL)
	{
		if ($('#linkIframe').size()==0)
		{
			iframeElement = '<iframe src="'+URL+'" frameborder="0" id="linkIframe" style="width:100%; height:700px; border:none;" scrolling="no" class="autoHeight"></iframe>';
			$('#contentArea').html(iframeElement);
		}else $('#linkIframe').attr('src',URL);
	}

	function viewMyListing(ID)
	{
		var URL = $('#'+ID).attr('href');
		window.location.href = URL;
	}
