﻿// JScript File

function jsAddMyListPre(PropertyId){
    if(document.getElementById('addListLimg'+PropertyId)){
        document.getElementById('addListLimg'+PropertyId).style.visibility = 'visible';
    }
}

function jsAddMyListAfter(PropertyId,rightR){
    if(document.getElementById('addListLimg'+PropertyId)){
        document.getElementById('addListLimg'+PropertyId).style.display = 'none';
    }
    if(rightR){
        if(document.getElementById('addListLmsg'+PropertyId) && document.getElementById('NoaddListLmsg'+PropertyId)){
            document.getElementById('addListLmsg'+PropertyId).style.display = 'inline';
            document.getElementById('NoaddListLmsg'+PropertyId).style.display = 'none';
        }
    }else{
        if(document.getElementById('addListLmsg'+PropertyId) && document.getElementById('NoaddListLmsg'+PropertyId)){
            document.getElementById('addListLmsg'+PropertyId).style.display = 'none';
            document.getElementById('NoaddListLmsg'+PropertyId).style.display = 'inline';
        }        
    }
    if(document.getElementById('lnkAddMyListProp')){        
        document.getElementById('lnkAddMyListProp').className = 'btn1G';
        document.getElementById('lnkAddMyListProp').onclick = '';         
    }    
}

function jsAddMyListMod(NumProp,NewListUrl){
    if(document.getElementById('MyList')){
        document.getElementById('MyList').innerHTML = '&nbsp;('+ NumProp +')';
    }
    if(document.getElementById('ctl00_myHeader_lnkMyList')){
        document.getElementById('ctl00_myHeader_lnkMyList').href = NewListUrl;
    }
    
}

function addToMyList(PropertyId,RegionId){ 
    //alert(sign);
    if(!onProcess){
		var url="MyList_jx.aspx?CrsiID="+ Math.floor(Math.random()*1000) +"&RegionId="+ RegionId +"&Action=add&PropertyId="+PropertyId;
		jsAddMyListPre(PropertyId);

		http.open("GET",url,true);
		
		http.onreadystatechange=handleHttpResponse;
		onProcess=true;
		http.send(null);
	}else{
		alert("Process still active, please wait.");
	}
}


function handleHttpResponse(){
	if(http.readyState==4){
		if(http.status==200){
			if(http.responseText.indexOf('null')==-1){
			    //document.getElementById('vpos').innerHTML= results
				var results=http.responseText.split("#");				
				if(results.length>3){
				    if(results[0]=='0'){	
				        jsAddMyListAfter(results[1],true);
					    jsAddMyListMod(results[2],results[3]);
					}else{
					    jsAddMyListAfter(results[1],false);					    
					}
				}
			}
			onProcess=false;
		}
	}
}
