﻿
if (typeof(xTracker)=="undefined") xTracker={};
if (typeof(xTracker.requiresPost)=="undefined") xTracker.requiresPost=false;
xTracker.load = function(url) {
    if (typeof(url) == "undefined") {
        url=root+'/tracker/default.aspx';
    }
    var oTracker = xFunctions.el('trackeriframe');        
    if ( typeof(oTracker)!="undefined" && oTracker != null ) {
        oTracker.style.minHeight="375px";
        xFunctions.rpc(oTracker,url,'trackeriframe');
    }
}

xTracker.getSearchName=function(searchType,objid,updateSpan) {
    var obj=xFunctions.el("propertytracker_searchname");
    obj.style.display="block";    
    var o = {};
    o.searchType=searchType;
    o.objId=objid;
    o.updateSpan=updateSpan;
    xTracker.newSearch=o;    
}

xTracker.addSearchByName =  function() {       
    var obj=xFunctions.el("pt_searchname");
    if ( obj.value != "" ) {
        xTracker.addSearch(obj.value,xTracker.newSearch.searchType,xTracker.newSearch.objId,xTracker.newSearch.updateSpan);
        var obj=xFunctions.el("propertytracker_searchname");
        obj.style.display="none"; 
    }
}

xTracker.doReload = function() {
   //if (xTracker.requiresPost) {   
        parent.location.reload();
   //}
}

xTracker.getUrl = function(url) {    
    var oTracker = xFunctions.el('trackeriframe');
    xFunctions.rpc(oTracker,url,'trackeriframe');
}

xTracker.addListing = function(listingid,objid,updatespan) {
    if (typeof(updatespan)=="undefined") updatespan=false;
    eval("var rpcaddlisting"+listingid+";");
    xFunctions.rpc(eval("rpcaddlisting"+listingid),root+"/common/controls/tracker/scripts/addlisting.aspx?listingid="+listingid,"rpcaddlisting"+listingid);    
    if ( updatespan ) { xTracker.createRemoveListing(listingid,objid); }    
}

xTracker.removeListing = function(listingid,objid,updatespan) {
    if (typeof(updatespan)=="undefined") updatespan=false;
    eval("var rpcremovelisting"+listingid+";");
    xFunctions.rpc(eval("rpcremovelisting"+listingid),root+"/common/controls/tracker/scripts/removelisting.aspx?listingid="+listingid,"rpcremovelisting"+listingid);    
    if (updatespan) {xTracker.createAddListing(listingid,objid);}    
}

xTracker.createAddListing = function(listingid,objid) {
    obj=xFunctions.el(objid);
    if ( typeof(obj)!="undefined") obj.innerHTML='<a href="javascript:xTracker.addListing('+listingid+',\''+objid+'\',true);"><img src="'+root+'/assets/icons/propertytracker_add.gif" border="0" align="absmiddle"></a>';
}

xTracker.createRemoveListing = function(listingid,objid) {
    obj=xFunctions.el(objid);
    if ( typeof(obj)!="undefined") obj.innerHTML='<a href="javascript:xTracker.removeListing('+listingid+',\''+objid+'\',true);"><img src="'+root+'/assets/icons/propertytracker_remove.gif" border="0" align="absmiddle"></a>';
}

xTracker.createAddSearch = function(searchType,objid,updatespan) {
    if (typeof(updatespan)=="undefined") updatespan="true";
    obj=xFunctions.el(objid);
    if ( typeof(obj)!="undefined") obj.innerHTML='<a href="javascript:xTracker.getSearchName(\''+searchType+'\',\''+objid+'\','+updatespan+');">+ Add Search to Favorites</a>';
    //<img src="'+root+'/assets/icons/propertytracker_addsearch.gif" border="0" align="absmiddle">
}

xTracker.createRemoveSearch = function(searchType,objid,updatespan) {
    if (typeof(updatespan)=="undefined") updatespan="true";
    obj=xFunctions.el(objid);
    if ( typeof(obj)!="undefined") obj.innerHTML='<a href="javascript:xTracker.removeSearch(\''+searchType+'\',\''+objid+'\','+updatespan+');">Remove Search from Favorites</a>';
    //<img src="'+root+'/assets/icons/propertytracker_remsearch.gif" border="0" align="absmiddle">
}

xTracker.addSearch = function(searchName,searchType,objid,updatespan) {    
    if (typeof(updatespan)=="undefined") updatespan=false;
    var url=scriptname.replace(root,'')+xFunctions.getPageUrl("document",true).toString();
    var posturl=root+"/common/controls/tracker/scripts/addsearch.aspx?searchName="+escape(searchName)+"&searchType="+escape(searchType);
    posturl+="&linkurl="+escape(url);
    var addsearchiframe;        
    xFunctions.rpc(addsearchiframe,posturl,'addsearchiframe');        
    if (updatespan) {xTracker.createRemoveSearch(searchType,objid);}    
}

xTracker.removeSearch = function(searchType,objid,updatespan) {
    if (typeof(updatespan)=="undefined") updatespan=false;
    var url=scriptname.replace(root,'')+xFunctions.getPageUrl("document",true).toString();
    var posturl=root+"/common/controls/tracker/scripts/removesearch.aspx?searchType="+escape(searchType);
    posturl+="&linkurl="+escape(url);
    var removesearchiframe;            
    xFunctions.rpc(removesearchiframe,posturl,'removesearchiframe');    
    if (updatespan) {xTracker.createAddSearch(searchType,objid);}    
}

