
function passCompareForms(aform, alist){
    //	alert(alist);
    url='getprops.cfm?all=1';
    //icon ='';
    DeleteShape(); 
    url += '&listmlnum='+alist;
    //alert(url);
    CallToGetList(url, icon);
    
}

function compfrmreturn(form, buttonName){
    // require that at least one checkbox be checked
    var checkSelected = false;
    var checkCounter = 0;
    var mlnumsellist = '';
    
    var summaryListings = Ext.get('divMapListings');
    var detailListings = Ext.get('divListLoading');
    var activeList;
    var chkBxArray;
    
    if( summaryListings.isVisible() ){
        activeList = summaryListings;
    }else if( detailListings.isVisible() ){
        activeList = detailListings;
    }
    
    if( activeList ){
        var chkBxArray = Ext.DomQuery.select('INPUT[name=listMLNUM]', activeList.dom);
        for (var i = 0, l = chkBxArray.length;  i < l;  i++){
            if (chkBxArray[i].checked){
                //alert(document.compareForm.listMLNUM[i].value);
                //checkSelected = true;
                checkCounter = checkCounter + 1;
                mlnumsellist+= chkBxArray[i].value +',';
            }
        }
    }else{
        chkBxArray = [];
    }
    
    //alert(form);
    /*
        if(buttonName =='Compare'){
            var chkBxArray = Ext.DomQuery.select('INPUT[name=listMLNUM]');
            for (var i = 0, l = chkBxArray.length;  i < l;  i++){
                if (chkBxArray[i].checked){
                    //alert(document.compareForm.listMLNUM[i].value);
                    checkSelected = true;
                    checkCounter = checkCounter + 1;
                    mlnumsellist+= chkBxArray[i].value +',';
                }
            }
        }
        
        if (form.name == 'compareForm2'){
            for (var i = 0;  i < document.compareForm2.listMLNUM.length;  i++){
                if (document.compareForm2.listMLNUM[i].checked){
                    //alert(document.compareForm.listMLNUM[i].value);
                    checkSelected = true;
                    checkCounter = checkCounter + 1;
                    mlnumsellist+= document.compareForm2.listMLNUM[i].value +',';
                    }
            }
        }
        */
    
    mlnumsellist+= '-999';
    
    if (checkCounter == 0)	{
        Ext.MessageBox.alert('Too Few Listings Selected', 'Please select at least one of the listings.');
        return false;
    }
    if (checkCounter > 5){
        Ext.MessageBox.alert('Too Many Listings Selected', 'You are only allowed to select up to 5 lisitng.\n Please uncheck one or some of your selection in order to select more.');
        return false;
    }
    
    if(buttonName =='Compare'){
        //alert(mlnumsellist+ form.name);
        //win=window.open('','myWin','width=850,height=900,scrollbars=yes,resizable=yes,left:0px, top:0px'); 
        win=window.open('http://search.har.coml/idx/dispSetMycartTransit.cfm?listMLNUM='+mlnumsellist,'myWin','width=850,height=900,scrollbars=yes,resizable=yes,left:0px, top:0px'); 
        

        
    }else if (buttonName == 'Map'){
        passCompareForms(form,mlnumsellist );
    }
    
}


function setSchoolAddresstoProx(myaddress){

	
	Ext.get('proxaddress').dom.value = myaddress;

	markInputProxAddress();
	//updatepropcount();
	//Ext.get('btnSubmit').dom.click();

	}
function markInputProxAddress(){
  // alert('mark center address');
    var centerURl = 'getGeoByAddress.cfm?';
    var centerAddress = Ext.get('proxaddress').dom.value;
    var centerAddressLen = centerAddress.length;
    
    centerURl += "addr="+centerAddress;
    /*HAR.getRoofTop(centerAddress, function(){
      console.log(arguments);
	});*/
    var http=getHTTPObject();

    //window.open(centerURl,'mywindow','width=650,height=500,toolbar=yes, location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
    
    http.open("GET", centerURl, false);
    http.send(null);
    
    var centerInfo=http.responseText;
    
    if(http.status == 200){
        //alert(centerInfo);
        mapLoadProxAddress(centerInfo,centerAddress);
		
    }
	//updatepropcount();
}


function mapLoadProxAddress(centerInfo,centerAddress){
    
    var cLat = centerInfo.split(',')[0];
    var cLong = centerInfo.split(',')[1];
   
    mapLoadPoint(cLat, cLong,centerAddress);
}


/************************************may not needed
function ClearProx(){
    clearProxAddress();
    clearProxZip();
    clearSearchResult();
}
*/

function mapLoadPoint(cLat,cLong,centerAddress){

  var center = new google.maps.LatLng(cLat, cLong);
  var propIcon = HAR.pins.greenHouse;
  var propString = "<div style='width:200px;'><span class='mdBlueBold'>"+centerAddress+"</span></div>"
  try{
	  
	  if( mlnum != '' && leadid==6)
	  {
		  HAR.map.setOptions({center: center, zoom:17/*, mapTypeId: google.maps.MapTypeId.HYBRID*/ });
	  }
	  else
		  HAR.map.setOptions({center: center, zoom:14});  

	  HAR.plotPin({
		  lat: cLat,
		  lng: cLong,
		  pinIcon: propIcon,
		  html: propString,
		  title:centerAddress 
	  });
  }
  catch(e){}   
    /*var center = new VELatLong(cLat, cLong);
    //	alert(cLat + ','+cLong+ 'in maploadpoint');
    
    
    var propIcon = "/mapsearch/graphics/greenarrow.gif";
    var propString = "<div style='width:200px;'><span class='mdBlueBold'>"+centerAddress+"</span></div>"
    
    var shape = new VEShape(VEShapeType.Pushpin, center);

    //Set the icon
    shape.SetCustomIcon(propIcon);
    
    //Set the info box
    //shape.SetTitle("<font face='Arial, Helvetica, sans-serif' size='1px' color='666666'>Proximity Address/Zip Code</font>");
    shape.SetDescription(propString);
    
    
    try{

        map.AddShape(shape);
        map.SetCenterAndZoom(center, 14);		
        
    }
    catch(e){}*/
	
	//alert('I am here to mark center');
    //updatepropcount();
    
}


function checkboxval(boxname, boxval){
    var counter = 0;
    var i;
    var proptypeid = 'Property_Class_ID';
    var proptypelease ='PROP_TYPE';
    var mydom;
    //	if(boxname =='Property_Class_ID'){
    for(i=1;i<=6;i++){

        mydom =Ext.get(proptypeid+i).dom; 
        if(mydom.checked){
            counter++;
            boxval = boxval.concat(mydom.value);
            boxval = boxval.concat(',')
        }
    }
    //}else if(boxname =='PROP_TYPE'){
    for(i=1;i<=3;i++){
        mydom =Ext.get(proptypelease+i).dom;
        if(mydom.checked){
            counter++;
            boxval = boxval.concat(mydom.value);
            boxval = boxval.concat(',')
        }
    }
    //}	
    //alert('counter'+counter);
    if(counter == 0){
        alert("You have to select at least one property type.");
        return (false);
    }
    else{
        return (boxval);
    }

}
function showdiv(divid) {
    obj = Ext.get(divid);
    if(obj.style.display == 'none') {
        obj.style.display = '';
    }
    else {
        obj.style.display = 'none';
    }
}


function checkdateback(dateback){
	var datebackdom ;
	datebackdom = Ext.get('dateback2').dom;
	datebackdom1 = Ext.get('dateback1').dom;
	datebackdom6 = Ext.get('dateback6').dom;
	
	if(dateback == 'oneyear'){
		datebackdom.checked = false;
		datebackdom6.checked = false;
		datebackdom1.checked = true;
	}else if(dateback == 'sixmon'){
		datebackdom.checked = false;
		datebackdom1.checked = false;
		datebackdom6.checked = true;	
	}else{
		datebackdom.checked = true;
		datebackdom1.checked = false;
		datebackdom6.checked = false;	
		}
}

function showBuyDiv(ival, issold){
    var i;
    var proptypeid = 'Property_Class_ID';
    var proptypelease ='PROP_TYPE';
    var mydom;
	
    Ext.get('divBuy').dom.style.display = 'block';
    Ext.get('divLease').dom.style.display = 'none';
    Ext.get('LEASE_PRICE_MIN').selectedIndex = 0;
    Ext.get('LEASE_PRICE_MAX').selectedIndex = 0;
    
	/*
   	 for(i=1;i<=3;i++){
        document.getElementById('PROP_TYPE' + i).checked =false;
    }
    if(ival==0){
        for(i=1;i<=6;i++){
            document.getElementById('Property_Class_ID' + i).checked =true;
        }
    }


        if(mydom.checked){
            counter++;
            boxval = boxval.concat(mydom.value);

	*/
	var forsalechecked = 0;
	
	for(i=1;i<=6;i++){
		mydom =Ext.get(proptypeid+i).dom; 
		if(mydom.checked ==true){
			forsalechecked += 1;
			}
	}
	if (forsalechecked ==0){
		for(i=1;i<=3;i++){
			mydom =Ext.get(proptypelease+i).dom; 
      		mydom.checked =false;
    	}
		 for(i=1;i<=6;i++){
            Ext.get(proptypeid + i).dom.checked =true;
        }
	}
	
    if (issold ==1){
        Ext.get('divsold').dom.style.display = 'block';
        Ext.get('divnosold').dom.style.display = 'none';
    }else{
        Ext.get('divsold').dom.style.display = 'none';
        Ext.get('divnosold').dom.style.display = 'block';
    }

   // updatepropcount();
}
function showLeaseDiv(ival){
    //	alert(document.getElementById("for_sale").value);
    var i;
    var proptypeid = 'Property_Class_ID';
    var proptypelease ='PROP_TYPE';
    var mydom;
	
    Ext.get('divLease').dom.style.display = '';
    Ext.get('divBuy').dom.style.display = 'none';
    Ext.get('divsold').dom.style.display = 'none';
    Ext.get('divnosold').dom.style.display = '';
    Ext.get('LISTING_PRICE_MIN').dom.selectedIndex = 0;
    Ext.get('LISTING_PRICE_MAX').dom.selectedIndex = 0;
    
    /*
   	for(i=1;i<=6;i++){
        document.getElementById('Property_Class_ID' + i).checked =false;
    }
  	
	if(ival==0){
        for(i=1;i<=3;i++){
            document.getElementById('PROP_TYPE' + i).checked =true;
        }
    }	
	*/
	var leaseChecked = 0;
	  for(i=1;i<=3;i++){
            if (Ext.get(proptypelease + i).dom.checked ==true){
				leaseChecked+=1;
				}
        }
	if 	(leaseChecked==0){
		 for(i=1;i<=6;i++){
       		 Ext.get(proptypeid + i).dom.checked =false;
    		}
		  for(i=1;i<=3;i++){
            Ext.get(proptypelease + i).dom.checked =true;
        }
	}

    //fnClearFormObjects(searchform);
    //searchform.for_sale.value = 7;
    //document.getElementById("for_sale").value = 7;
   // updatepropcount();
}

function clearProxAddress(){
    Ext.get("proxaddress").dom.value ='';
    
}
function clearProxZip(){
    Ext.get("proxzip").dom.value ='';
    
}
