// Title: Ajax Script

function getXMLHTTP() { //fuction to return the xml http object
		var xmlhttp=false;	
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				req = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		 	
		return xmlhttp;
 }
	
function getState(trade) {		
		var strURL="findTrader.php?trade="+trade;
		var req = getXMLHTTP();
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {			
						document.getElementById('statediv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	
}

function getTraderDetails(traderId)
{
  if(traderId == ""){
	  document.getElementById('traderdetailsdiv').innerHTML="";
	  document.getElementById('traderdetailsdiv').style.display = "none";
  }else{
	  document.getElementById('traderdetailsdiv').style.display = "block";
  	var strURL="getTraderDetails.php?trader="+traderId;
  	var req = getXMLHTTP();
  	if (req)
  	{
  	  req.onreadystatechange = function()
  	  {
  	    if (req.readyState == 4) // only if “OK”
  	    {
  	      if (req.status == 200)
   	     {
   	       document.getElementById('traderdetailsdiv').innerHTML=req.responseText;
    	    } else {
        	  alert("There was a problem while using XMLHTTP:\n" + req.statusText);
    	    }
    	  }
    	}
    	req.open("GET", strURL, true);
    	req.send(null);
  	}
  }
}


//Added for removing images
function removeLogo(agentID) {		
	
		var strURL="removeLogo.php?agent="+agentID;
		var req = getXMLHTTP();
		
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {			
						document.getElementById('logodiv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	
}

//Added for removing main image
function removeMainImg(listingID) {		
		var strURL="removeMainImg.php?listing="+listingID;
		var req = getXMLHTTP();
		
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {			
						document.getElementById('maindiv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	
}

//Added for removing second image
function removeSecondImg(listingID) {		
	
		var strURL="removeSecImg.php?listing="+listingID;
		var req = getXMLHTTP();
		
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {			
						document.getElementById('seconddiv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	
}

function getPropertyDetails(propertyID)
{
  if(propertyID == ""){
	  document.getElementById('propertyDetails').innerHTML="";
	  document.getElementById('propertyDetails').style.display = "none";
  }else{
	  document.getElementById('propertyDetails').style.display = "block";
  	var strURL="getPropertyDetails.php?id="+propertyID;
  	var req = getXMLHTTP();
  	if (req)
  	{
  	  req.onreadystatechange = function()
  	  {
  	    if (req.readyState == 4) // only if “OK”
  	    {
  	      if (req.status == 200)
   	     {
   	       document.getElementById('propertyDetails').innerHTML=req.responseText;
    	    } else {
        	  alert("There was a problem while using XMLHTTP:\n" + req.statusText);
    	    }
    	  }
    	}
    	req.open("GET", strURL, true);
    	req.send(null);
  	}
  }
}

//Added for agents main image
function removeAgentImg(agentID) {	
		var isIE = (document.all && !window.opera)? true:false;
		if (isIE) {
			var req = new ActiveXObject("Microsoft.XMLHTTP"); 
		}else{
			var req = new XMLHttpRequest(); 
		}
		var strURL="removeLogo.php?agent="+agentID;
		
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {		
						document.getElementById('maindiv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			
			req.open("GET", strURL, true);
			if (isIE) {
				req.send(); 
			}else{
				req.send(null);
			}
		}		
	
}