var pageLoaded = 0 ;
function hideWaitDialog()
{
    if (document.getElementById("WaitDialog") != null)
    {
        var dialog = document.getElementById("WaitDialog");
        dialog.style.display = 'none';  
        scrollTo(0,0);
    }
}

function hideProcessingDiv(divName)
{
    document.getElementById(divName).style.display="none";
//    var X = document.documentElement.scrollLeft + ( (screen.availWidth/2) - (88/2) ) ;
//    var Y = getBrowserTop() ;
//    scrollTo(X,Y);
//    document.documentElement.scrollTop = 300 ;//getBrowserTop();
}

function showProcessingDiv(divName , width , height)
{
    var X = document.documentElement.scrollLeft + ( (screen.availWidth/2) - (width/2) ) ;
    var Y = getBrowserTop() ;
    setSize(divName,width,height);
    moveXY(divName,X,Y);
    setPosition(divName,'fixed');
    setVisibility(divName , "show");
}

function move_box() 
{
     var offset = 0; // set offset (likely equal to your css top)  
     var element = document.getElementById('LoadingDiv');
     if (element.style.display == 'block')
     {
        element.style.top = getBrowserTop();//(document.documentElement.scrollTop + offset) + 'px';
     }
}
function setHeaderMenu()
{
    var X = document.documentElement.scrollLeft + ( (screen.availWidth/2) - (getElementWidth(lblHeaderHTMLClientID)/2) ) ;
    var Y = getBrowserTop() ;
    moveXY(lblHeaderHTMLClientID,X,Y);
}

function setMasterHeight()
{
     //setHeight("tdMasterCenter",(getElementHeight("tdMasterLeft")));
     if ( getElementHeight("tdMasterLeft") > getElementHeight(tdMasterRight))
        {
            setHeight(tdMasterCenter,(getElementHeight("tdMasterLeft")));
        }
        else
        {
            setHeight(tdMasterCenter,(getElementHeight(tdMasterRight)));
        }

//    if (typeof(tdMasterRight) != "undefined")
//    {
//        if ( getElementHeight("tdMasterLeft") > getElementHeight(tdMasterRight) )
//        {
//            setHeight("tdMasterCenter",(getElementHeight("tdMasterLeft")));
//        }
//        else
//        {
//            //alert('else');
//            setHeight("tdMasterCenter",(getElementHeight(tdMasterRight)));
//        }
//    }
//    else
//        {
//            setHeight("tdMasterCenter",(getElementHeight("tdMasterLeft")));
//        }

//    alert(getElementHeight("tdMasterLeft"));
//    alert(getElementHeight(tdMasterRight));
}

//********************************************BUY.ASPX********************************************//
function performClick(devID,totListing)
{
    document.getElementById(hdnLoadListingClientID).value = "1" ;
    document.getElementById(hdnDevelopmentIDClientID).value = devID ;
    document.getElementById(hdnTotListingClientID).value = totListing ;
    document.getElementById(btnLoadListingClientID).click();
}


function openListingDiv()
{
    
    //tdMasterCenter
    //moveXY("ListingContainer",(getElementLeft("tr_SearchContainer") + 7),(getElementTop("tr_SearchContainer") - 2));
    moveXY("ListingContainer",(getElementLeft(tdMasterCenter)-1 ),(getElementTop(tdMasterCenter) - 18 ));
    moveXY("ListingContainerFrame",(getElementLeft(tdMasterCenter)-1 ),(getElementTop(tdMasterCenter) - 18 ));

    //ListingContainerFrame
    setVisibility("ListingContainer" , "show");
    setVisibility("ListingContainerFrame" , "show");
    
    //setHeight("ListingContainer",(getElementHeight("tbl_frame") - 0));
    setHeight("ListingContainer",(getElementHeight(tdMasterCenter) + 18));
    setHeight("ListingContainerFrame",(getElementHeight(tdMasterCenter) + 18));

    //setHeight("divPH_Stocks",(getElementHeight("tbl_frame") - 72));
    setHeight("divPH_Stocks",(getElementHeight(tdMasterCenter) - 72 ));
    setHeight("divStocksTabular",(getElementHeight(tdMasterCenter)- 19));
    //divStocksTabular
    //alert(getElementHeight("tdMasterCenter"));
    //moveXY("divStockPaging",(( getElementWidth("ListingContainer") / 2 ) - 325),(getElementHeight("tbl_frame") - 40));

    var _ListingContainerWidth = getElementWidth("ListingContainer") / 2;
    var _divStockPagingWidth = getElementWidth("divStockPaging") / 2 ;
    var _staringX = _ListingContainerWidth - _divStockPagingWidth ;
    //moveXY("divStockPaging",(( getElementWidth("ListingContainer") / 2 ) - (getElementWidth("divStockPaging")/2)),(getElementHeight("tdMasterCenter") - 35));
    moveXY("divStockPaging", _staringX ,(getElementHeight(tdMasterCenter) - 35));
}

function loadBuy()
{
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandlerBuy);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandlerBuy);
}


function loadDevelopmentSearch()
{
    //alert("loadDevelopmentSearch")
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandlerDevelopmentSearch);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndReqHandlerDevelopSearch);
}

function keyPressHandler(e , DivID) 
{
//      var kC  = (window.event) ?    // MSIE or Firefox?
//                 event.keyCode : e.keyCode;
//      var Esc = (window.event) ?   
//                27 : e.DOM_VK_ESCAPE ;// MSIE : Firefox
//                

    //e= (window.event)? window.event: e;
     e = e || window.event;
    var keyCode = e.which || e.keyCode; 

    if(keyCode==27)
    { 
        var div = document.getElementById(DivID);  
        if (div)
        {
                setVisibility(DivID , "hide");
        }
    }
//      if(kC==Esc)
//      {
//        var div = document.getElementById(DivID);  
//        if (div){
//                //hideProcessingDiv(DivID)
//                setVisibility(DivID , "hide");
//        }
//       //alert("Esc pressed")
//       
//       //document.getElementById("ListingContainer").style.display="none";
//      }   
}
//********************************************BUY.ASPX********************************************//


//********************************************ProjProfile.ASPX********************************************//
function loadProjProfile()
{
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandlerProjProfile);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandlerProjProfile);
}

//********************************************ProjProfile.ASPX********************************************//

function loadPropEnquiry()
{
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandlerPropEnquiry);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandlerPropEnquiry);
}


//********************************************BUY_TAB.ASPX********************************************//

function initEvents()
{
    if (typeof(hdnUnitTypeValClientID) != "undefined")
    {
        if (document.getElementById(hdnUnitTypeValClientID).value == "APT:R" || 
            document.getElementById(hdnUnitTypeValClientID).value == "THS:R" || 
            document.getElementById(hdnUnitTypeValClientID).value == "VLA:R")
        {
            document.getElementById(ddl_BedroomsClientID).disabled = false;
        }
        else
        {
            document.getElementById(ddl_BedroomsClientID).selectedIndex = 0;
            document.getElementById(ddl_BedroomsClientID).disabled = true;
        }
        setSelectedIndex('ddl_unitType',document.getElementById(hdnUnitTypeValClientID).value);
    }

    if (typeof(hdnunitTypeMortClientID) != "undefined")
    {
        if (document.getElementById(hdnunitTypeMortClientID) != null)
        {
            if (document.getElementById(hdnunitTypeMortClientID).value == "APT:R" || 
                document.getElementById(hdnunitTypeMortClientID).value == "THS:R" || 
                document.getElementById(hdnunitTypeMortClientID).value == "VLA:R")
            {
                document.getElementById(ddl_bedroomMortClientID).disabled = false;
            }
            else
            {
                document.getElementById(ddl_bedroomMortClientID).selectedIndex = 0;
                document.getElementById(ddl_bedroomMortClientID).disabled = true;
            }
            setSelectedIndex('ddl_unitTypeMort',document.getElementById(hdnunitTypeMortClientID).value);
        }
    }
    
    if(typeof(ddl_psfClientID) != "undefined")
    {
       togglePricing();
    }
    if (typeof(hdnEnqTypeClientID) != "undefined")
    {
        manageEnquiry();
    }
    
    if (typeof(ddlPropIdentifiedClientID) != "undefined")
    {
        togglePropLoc();
    }

    if (typeof(hdnModeClientID) != "undefined")
    {
        //setMode();
        if(document.getElementById(hdnModeClientID).value=='sell')
        {
            showOccDate();
        }
    }
}

//function setMode()
//{
//    if(document.getElementById(hdnModeClientID).value=='rent')
//    {
//        setVisibility("trAvailability" , "show");
//        setVisibility("trStatus" , "hide");
//    }
//    else
//    {
//        setVisibility("trAvailability" , "hide");
//        setVisibility("trStatus" , "show");
//        showOccDate();
//    }
//}

function setReviewMode()
{
    if ( document.getElementById(hdnModeClientID).value == 'rent' )
    {
        setVisibilityTable("trAvailabilityFromReview" , "show");
        setVisibilityTable("trAvailabilityToReview" , "show");
        setVisibilityTable("trStatusReview" , "hide");
    }
    else
    {
        setVisibilityTable("trStatusReview" , "show");
        setVisibilityTable("trAvailabilityFromReview" , "hide");
        setVisibilityTable("trAvailabilityToReview" , "hide");
    }
}

var timeoutID;timeoutID='';
var listingAction;
function manageEnquiry()
{
    var enquiryType = document.getElementById(hdnEnqTypeClientID) ;

    if (enquiryType.value == '1|WMOT' )
    {
        clearTimeOut();
        setVisibilityTable("trOtherheader" , "hide");
        setVisibilityTable("trOtherDetails" , "hide");
        setVisibilityTable("trOtherSubmit" , "hide");
        setVisibilityTable("trMortgage" , "show");
    }
    else if (enquiryType.value == '0|SELL' )
    {
        listingAction = 'sell'
        clearTimeOut();
        setTimeOut();
    }
    else if (enquiryType.value == '0|RNT')
    {
        listingAction = 'rent'
        clearTimeOut();
        setTimeOut();
    }
    else 
    {
        clearTimeOut();
        setVisibilityTable("trOtherheader" , "show");
        setVisibilityTable("trOtherDetails" , "show");
        setVisibilityTable("trOtherSubmit" , "show");
        setVisibilityTable("trMortgage" , "hide");
    }
    setVisibility(divErrorMsgClientID , "hide");

    var isReadonly = document.getElementById(hdnFlagReadOnlyClientID) ;
    if ( isReadonly.value == '1' )
    {
        setSelectedIndex('ddl_enqType',enquiryType.value);
        document.getElementById('ddl_enqType').disabled  = true;
    }
    else
    {
        document.getElementById('ddl_enqType').disabled  = false;
    }
}

function setSelectedIndex(objName,value)
{
    var objDDL;
    objDDL = document.getElementById(objName);
    var i=0;
    while ( (objDDL.options[i].value != value) && (i < objDDL.options.length-1))
    {
        i++;
    }

    if (i < objDDL.options.length)
    {
        objDDL.selectedIndex = i;
    }
}

function setTimeOut()
{
        setVisibility("divShowRedirection" , "show");
        timeoutID = window.setTimeout(showRedirection, 2000);
}

function clearTimeOut()
{
    if (timeoutID != '')
        {
            window.clearTimeout(timeoutID);
            setVisibility("divShowRedirection" , "hide");
        }
}

function showRedirection()
{
    window.open('Listing.aspx?mode=' + listingAction ,'_self');
}

function CancelRedirect()
{
    clearTimeOut();
    document.getElementById('ddl_enqType').selectedIndex = 0;
    if (typeof(hdnEnqTypeClientID) != "undefined")
    {
        document.getElementById(hdnEnqTypeClientID).value = '';
        manageEnquiry();
    }
}

function togglePricing()
{
    if (typeof(ddl_psfClientID) != "undefined" && document.getElementById(ddl_psfClientID)!= null )
    {
        var ddlPriceType = document.getElementById(ddl_psfClientID) ;
       
        if (ddlPriceType.options[ddlPriceType.selectedIndex].value == 'PSF')
        {
            document.getElementById(ddl_budgetPSFClientID).style.display = 'block';
            document.getElementById(ddl_budgetWholeClientID).style.display = 'none';
        }
        else if (ddlPriceType.options[ddlPriceType.selectedIndex].value == 'Unit')
        {
            document.getElementById(ddl_budgetPSFClientID).style.display = 'none';
            document.getElementById(ddl_budgetWholeClientID).style.display = 'block';
        }
        else //if (ddlPriceType.options[ddlPriceType.selectedIndex].value == 2)
        {
            document.getElementById(ddl_budgetPSFClientID).style.display = 'none';
            document.getElementById(ddl_budgetWholeClientID).style.display = 'none';
        }
    }
}

function togglePropLoc()
{
    var ddlPropIdentify = document.getElementById(ddlPropIdentifiedClientID) ;
    if (ddlPropIdentify.options[ddlPropIdentify.selectedIndex].value == 'Y')
    {
        setVisibilityTable("trStateMort" , "show");
        setVisibilityTable("trLocationMort" , "show");
        setVisibilityTable("trDevelopmentMort" , "show");
        setVisibilityTable("trUnitMort" , "show");
    }
    else 
    {
        setVisibilityTable("trStateMort" , "hide");
        setVisibilityTable("trLocationMort" , "hide");
        setVisibilityTable("trDevelopmentMort" , "hide");
        setVisibilityTable("trUnitMort" , "hide");
    }
}


function setValues(srcObj) 
{
    document.getElementById(hdnUnitTypeValClientID).value = srcObj.options[srcObj.selectedIndex].value;
    if (typeof(hdnUnitTypeTextClientID) != "undefined")
    {
        document.getElementById(hdnUnitTypeTextClientID).value = srcObj.options[srcObj.selectedIndex].text;
    }
    disableBedrooms(srcObj.options[srcObj.selectedIndex].value);
}

function setUnitTypeMort(srcObj) 
{
    document.getElementById(hdnunitTypeMortClientID).value = srcObj.options[srcObj.selectedIndex].value;
    disableBedroomsMort(srcObj.options[srcObj.selectedIndex].value);
}

function setFinanceType(srcObj) 
{
    document.getElementById(hdnFinTypeClientID).value = srcObj.options[srcObj.selectedIndex].value;
}

function showHideBudget(srcObj)
{
    if (srcObj.options[srcObj.selectedIndex].value == 'ORNT')
    {
        setVisibilityTable(trBudgetClientID , "hide");
        setVisibilityTable(trFinanceClientID , "hide");
    }
    else
    {
        setVisibilityTable(trBudgetClientID , "show");
        setVisibilityTable(trFinanceClientID , "show");    
    }
}

function setEnquiryType(srcObj) 
{
    document.getElementById(hdnEnqTypeClientID).value = srcObj.options[srcObj.selectedIndex].value;
    manageEnquiry();
}

function disableBedroomsMort(propType)
{
    if (propType == "APT:R" || 
        propType == "THS:R" || 
        propType == "VLA:R" )
    {
        document.getElementById(ddl_bedroomMortClientID).disabled = false;
    }
    else
    {
        document.getElementById(ddl_bedroomMortClientID).selectedIndex = 0;
        document.getElementById(ddl_bedroomMortClientID).disabled = true;
    }
}

function disableBedrooms(propType)
{
    if (typeof(ddl_BedroomsClientID) != "undefined" && document.getElementById(ddl_BedroomsClientID) != null)
    {
        if (propType == "APT:R" || 
            propType == "THS:R" || 
            propType == "VLA:R" )
        {
            document.getElementById(ddl_BedroomsClientID).disabled = false;
        }
        else
        {
            document.getElementById(ddl_BedroomsClientID).selectedIndex = 0;
            document.getElementById(ddl_BedroomsClientID).disabled = true;
        }
    }
}

function showOccDate()
{
    if (typeof(ddlStatusClientID) != "undefined" && document.getElementById(ddlStatusClientID) != null)
    {
        if (document.getElementById(ddlStatusClientID).value=='V')
        {
            setVisibilityTable("tdOccDate" , "hide");
        }
        else
        {
            setVisibilityTable("tdOccDate" , "show");
        }
    }
}

function loadStockSearch() 
{
   Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandlerStockSearch);
   Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandlerStockSearch);
}

function loadPostEnquiry()
{
   Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandlerStockSearch);
   Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandlerStockSearch);
}



function loadSell()
{
   Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandlerSell);
   Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandlerSell);
   disableDateBoxesListing(); 
}

function disableDateBoxesListing()
{
if(document.getElementById(txtOccDateClientID) != null)
   {
       document.getElementById(txtOccDateClientID).disabled="disabled";   
   }
   if(document.getElementById(txtFromDtClientID) != null)
   {
        document.getElementById(txtFromDtClientID).disabled="disabled";   
   }
   if(document.getElementById(txtToDtClientID) != null)
   {
        document.getElementById(txtToDtClientID).disabled="disabled";   
   }
}

function loadLogin()
{
   Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandlerLogin);
   Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandlerLogin);
}

function loadRegister()
{
   Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandlerRegister);
   Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandlerRegister);
}

function loadEditProfile()
{
   Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandlerEditProfile);
   Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandlerEditProfile);
   document.getElementById(txtDOBClientID).disabled="disabled";
}

function loadResetPassword()
{
   Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandlerResetPassword);
   Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandlerResetPassword);
}

function loadChpwd()
{
   Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandlerChpwd);
   Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandlerChpwd);
}

function loadWishlist()
{
   Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandlerWishlist);
   Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandlerWishlist);
}

function loadViewListing()
{
   Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandlerViewListing);
   Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandlerViewListing);
}

//********************************************  BUY_TAB  ********************************************//

function loadTabularListing(){
    document.getElementById(btnLoadTabularViewClientID).click();
    hideStockPaging();
}

function loadGridListing(){
    document.getElementById(btnLoadGridViewClientID).click();
    showStockPaging();
}

function showStockPaging()
{
    setVisibility("divStockPaging" , "show");
}

function hideStockPaging()
{
    setVisibility("divStockPaging" , "hide");
}


function toggleRegistration(tab)
{
/*    if (tab=='0')
    {
        setVisibility("tblExistingUser" , "show");
        setVisibility("tblNewUser" , "hide");
    }
    else if (tab=='1')
    {
        setVisibility("tblExistingUser" , "hide");
        setVisibility("tblNewUser" , "show");
    }
    setVisibility(divErrorMsgClientID , "hide");*/

if (document.getElementById(rbtnExisting).checked == 1)
  {
    setVisibility("tblExistingUser" , "show");
    setVisibility("tblNewUser" , "hide");
  }
else
  {
    setVisibility("tblExistingUser" , "hide");
    setVisibility("tblNewUser" , "show");
  }
setVisibility(divErrorMsgClientID , "hide");
}



function toggleSubmit()
{
    if (document.getElementById(chkTermsClientID).checked == true )
    {
        setVisibility(btnRegisterClientID , "show");
        setVisibility(btnRegisterDClientID , "hide");
    }
    else
    {
        setVisibility(btnRegisterClientID , "hide");
        setVisibility(btnRegisterDClientID , "show");
    }
}

function toggleSorting()
{
    if (typeof(ddlSortingClientID) != "undefined" && document.getElementById(ddlSortingClientID)!= null )
    {
        var ddlSorting = document.getElementById(ddlSortingClientID) ;
        if (ddlSorting.options[ddlSorting.selectedIndex].value == 'T')
        {
            setVisibilityTable("trUnitType" , "show");
        }
        else 
        {
            setVisibilityTable("trUnitType" , "hide");
        }
        //totalWishListFlag=false;
    }
}

var totalWishListProperties;
var totalWishListCounter;
var selectedWishlistProperty = new Array();
var propertySpacing = new Array();
var chekboxList = new Array();

function SetAllCheckBoxes(CheckValue)
{
	totalWishListProperties = parseInt(document.getElementById(lblCountClientID).innerHTML);
	var objCheckBoxes = document.getElementsByName("chkboxGroup");
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;

	if(!countCheckBoxes)
	{
		objCheckBoxes.checked = CheckValue;	
		return false;
	}
    else
	{
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
		{
		    if (CheckValue== false)
		    {
		        objCheckBoxes[i].checked = CheckValue;
		    }
			else if (CheckValue== true)
		    {
		        //alert((totalWishListProperties - totalWishListCounter));
		        if ( totalWishListProperties > 0 )
		        {
		            if (objCheckBoxes[i].id != chekboxList[i])
		            {
		                objCheckBoxes[i].checked = CheckValue;
		            }
		        }
		        else
		        {
		            alert('Your wish list is Empty.');
		            return false;
		            break;
		        }
		    }
		}
	}
}

function removeSelectedProperties()
{
    totalWishListProperties = parseInt(document.getElementById(lblCountClientID).innerHTML);
    var objCheckBoxes = document.getElementsByName("chkboxGroup");
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;

    if(!countCheckBoxes)
    {
        alert('Your wishlist is empty.');return false;
    }
	else
	{
	    var flag;
	    flag = false;
	    document.getElementById(hdnStockIDClientID).value = '';
	    document.getElementById(hdnModeClientID).value = '';
	    for(var i = 0; i < countCheckBoxes; i++)
	    {
	        if ( objCheckBoxes[i].checked == true)
	        {
	            flag = true ;
	            document.getElementById(hdnStockIDClientID).value = document.getElementById(hdnStockIDClientID).value + document.getElementById("Ref"+i).value + "|" ;
	            document.getElementById(hdnModeClientID).value = document.getElementById(hdnModeClientID).value + document.getElementById("mode"+i).value + "|" ;
	        }
	    }
	    
	    if(flag == false)
	    {
	        if ( totalWishListProperties < 1 )
	        {
	             alert('Your wish list is Empty.');
	             return false;
	        }
	        else
	        {
	            alert('Please select properties to remove from Wishlist.');
	            return false;
	        }
	    }
	    else
	    {
	        //return confirm('Are you sure you want to remove selected properties from Wishlist?');
	        if (confirm('Are you sure you want to remove selected properties from Wishlist?'))
	        {
//	            for(var i = 0; i < countCheckBoxes; i++)
//	            {
//	                if ( objCheckBoxes[i].checked == true)
//	                {
//	                    selectedWishlistProperty[i] = "tblProperty"+i;
//	                    propertySpacing[i]="brProperty"+i;
//	                    chekboxList[i] = "PROPERTYID"+i ;
//	                    document.getElementById("PROPERTYID"+i).checked=false;
//	                }
//	            }
	            return true;
	        }
	        else {
	            return false;
	        }
	    }
	}
}

//function hideRemovedProperties()
//{
//    var counter;
//    for (counter in selectedWishlistProperty)
//      {
//        document.getElementById(selectedWishlistProperty[counter]).style.display='none';
//        document.getElementById(propertySpacing[counter]).style.display='none';
//      }
//      document.getElementById(hdnFlagClientID).value = "" ;
//      SetAllCheckBoxes(false);
//      //document.getElementById(lblCountClientID).innerHTML  = totalWishListProperties - totalWishListCounter;
//}


var previous , ctrlCounter;
previous='';
ctrlCounter='';

function SingleSelect(regex,current,counter)
{
    document.getElementById(hdnSortFlagClientID).value="0";
    re = new RegExp(regex);
    for(i = 0; i < document.forms[0].elements.length; i++) 
    {
        elm = document.forms[0].elements[i];
        if (elm.type == 'checkbox') 
        {
                if (re.test(elm.name)) 
                {
                    elm.checked = false;
                }
        }
    }
    current.checked = true;
    if (previous == current.id)
    {
        current.checked = false;
        previous = '' ;
        ctrlCounter='';
    }
    else{
        previous = current.id;
        ctrlCounter = counter; }
}

function performRMV()
{
    //document.getElementById(hdnSortFlagClientID).value="0";
    if ( ctrlCounter != '' )
    {
        var arrRemoveAllow = document.getElementById('isRemoveAllow' + ctrlCounter).value.split("|");
        if (arrRemoveAllow[0] == '1')
        {
            document.getElementById(hdnStockIDClientID).value = document.getElementById('Ref' + ctrlCounter).value;
            return true;
        }
        else
        {
            alert(arrRemoveAllow[1]);
            return false;
        }
    }
    else 
    {
        alert('Please select property to perform this action.');
        return false;
        }
}

function performHDN()
{
   // document.getElementById(hdnSortFlagClientID).value="0";
    if ( ctrlCounter != '' )
    {
        var arrHiddenAllow = document.getElementById('isHiddenAllow' + ctrlCounter).value.split("|");
        if (arrHiddenAllow[0] == '1')
        {
            document.getElementById(hdnStockIDClientID).value = document.getElementById('Ref' + ctrlCounter).value;
            return true;
        }
        else
        {
            alert(arrHiddenAllow[1]);
            return false;
        }
    }
    else 
        alert('Please select property to perform this action.');
        return false;
}

function performAVL()
{
    //document.getElementById(hdnSortFlagClientID).value="0";
    if ( ctrlCounter != '' )
    {
        var arrAvailAllow = document.getElementById('isAvailAllow' + ctrlCounter).value.split("|");
        if (arrAvailAllow[0] == '1')
        {
            document.getElementById(hdnStockIDClientID).value = document.getElementById('Ref' + ctrlCounter).value;
            return true;
        }
        else
        {
            alert(arrAvailAllow[1]);
            return false;
        }
    }
    else 
        alert('Please select property to perform this action.');
        return false;
}
//********************************************ENQUIRYREPLY.ASCX********************************************//

function loadEnquiryBlog()
{
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandlerEnquiryBlog);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandlerEnquiryBlog);
}


function initEnquiryBlog()
{
 setVisibility(imgResetClientID,'hide'); 
}

function setPostEffect()
{
     //alert(document.getElementById(htftxtBoxReplyClientID).value)
     if (document.getElementById(htftxtBoxReplyClientID).value != '' )
      {
         setDisabled(htfimgSaveClientID, 'enabled');
      }
     else
     {
        setDisabled(htfimgSaveClientID, 'disabled');
     }
}

function setEnquiryBlogValue(ID,EnquiryID, EnquiryType, INDENT, METHOD, RefID, SENDTO)
    {
        document.getElementById(htfIDClientID).value  = ID;
        document.getElementById(htfEnquiryIDClientID).value = EnquiryID;
        document.getElementById(htfEnquiryTypeClientID).value = EnquiryType;
        document.getElementById(htfINDENTClientID).value = INDENT;
        document.getElementById(htfMETHODClientID).value  = METHOD;
        document.getElementById(htfRefIDClientID).value =   RefID;
        document.getElementById(htfSENDTOClientID).value = SENDTO;
        initEnquiryBlog();
    }

function callEnquiryReply(UserID, imgRestClientID)
{
    var ID, EnquiryID, EnquiryType, Indent, Method, EnquiryDescription,RefID, Sendto;

    
    ID = document.getElementById(htfIDClientID).value;
    EnquiryID  =  document.getElementById(htfEnquiryIDClientID).value ;
    
    EnquiryType =  document.getElementById(htfEnquiryTypeClientID).value ;
    Indent = document.getElementById(htfINDENTClientID).value ;
    Method = document.getElementById(htfMETHODClientID).value ;
    EnquiryDescription  = document.getElementById(htftxtBoxReplyClientID).value ;
    RefID  = document.getElementById(htfRefIDClientID).value ;
    Sendto = document.getElementById(htfSENDTOClientID).value ;
    document.getElementById(htfUserIDClientID).value =  UserID;
    document.getElementById(htftxtBoxReplyClientID).value = '' ;
    EnquiryReply(ID, EnquiryID, EnquiryType, Indent, Method, EnquiryDescription,RefID, UserID, Sendto , imgRestClientID );
    initEnquiryBlog();
    return false;
}

function Navigation(varURL)
{
    window.location=varURL;
//loadurl(varURL);
}

function autoExpandTextArea(event)
{
    if(event.keyCode == "13" || event.keyCode == "8"){
        var therows=0;
        var thetext = document.getElementById(htftxtBoxReplyClientID).value;
        var newtext = thetext.split("\n");
        therows+=newtext.length;
        var i;

        setVisibility(imgSubmitClientID,'show'); 

        if ( therows < 10 && therows > 4   ){
             document.getElementById(htftxtBoxReplyClientID).rows = therows;
             return false;
        }
        else if ( therows < 5)
        {
           document.getElementById(htftxtBoxReplyClientID).rows = 5;
           return false;
        }
    }
}

function SetCommentBox(isActive)
{
    if ( isActive == 1 && document.getElementById(htftxtBoxReplyClientID).value == 'Write a Comment...')
       {    
            setVisibility(imgSubmitClientID,'show'); 
            document.getElementById(htftxtBoxReplyClientID).value = '';
            document.getElementById(htftxtBoxReplyClientID).rows = 5;
       }
    else if ( document.getElementById(htftxtBoxReplyClientID).value == '')
        {
            document.getElementById(htftxtBoxReplyClientID).value = 'Write a Comment...';
            document.getElementById(htftxtBoxReplyClientID).rows = 1;
            setVisibility(imgSubmitClientID,'hide'); 
        }        
}


//********************************************ENQUIRYREPLY.ASCX********************************************//




function ShowPropertyProfile(stockID, viewIndex, mode)
{
    var url;
    url ='propProfile.aspx?propertyID='+ stockID + '&viewIndex=' + viewIndex + '&mode=' + mode;
    winRef = window.open(url,'PropertyProfile', '_blank');
    winRef.focus();
    return false;
}

function ShowEnquiry(stockID, mode)
{
    var url;
    url ='propEnquiry.aspx?propertyID='+ stockID +  '&enqType=' + mode  ;
    if (navigator.userAgent.indexOf('Chrome/') > 0) 
    {
        if (window.winRef) {
            window.winRef.close();
            window.winRef = null;
        }
    }

 window.winRef = window.open(url,'SendEnquiry', '_blank');
 window.winRef.focus();
 return false;
}

//********************************************ENQUIRYREPLY.ASCX********************************************//

//********************************************WINDOW LOAD********************************************//
function loadOfAll()
{
    //hideWaitDialog();
    setMasterHeight();
    //alert(pageLoaded);
//    if ( pageLoaded == 0 )
//         {
//            //alert('pageLoad is 0')
//            ret = zoneHandler.getZoneHtml("3",OnCompletesaleHandler, OnTimeOutsaleHandler, OnErrorsaleHandler);
//            ret = zoneHandler.getZoneHtml("2",OnCompleteRentHandler, OnTimeOutRentHandler, OnErrorRentHandler);
//         }
}

//********************************************WINDOW LOAD********************************************//

function toggleSearch()
{
    if(document.getElementById(ddl_StateClientID).selectedIndex==0)
    {
        if (typeof(btnSearchDisableClientID) != "undefined")
        {
            setVisibility(btnSearchDisableClientID , "show");
        }
        if (typeof(btnSearchClientID) != "undefined")
        {
            setVisibility(btnSearchClientID , "hide");
        }
    }
    else
    {
        if (typeof(btnSearchDisableClientID) != "undefined")
        {
            setVisibility(btnSearchDisableClientID , "hide");
        }
        if (typeof(btnSearchClientID) != "undefined")
        {
            setVisibility(btnSearchClientID , "show");
        }
    }
}



//********************************************INIT LOAD********************************************//

function applicationInitHandler()
{
    ret = zoneHandler.getZoneHtml("3",btnEnqURL,pEqnURL,pProfURL,OnCompletesaleHandler, OnTimeOutsaleHandler, OnErrorsaleHandler);
    ret = zoneHandler.getZoneHtml("2",btnEnqURL,pEqnURL,pProfURL,OnCompleteRentHandler, OnTimeOutRentHandler, OnErrorRentHandler);
    ret = zoneHandler.getZoneHtml("5",btnEnqURL,pEqnURL,pProfURL,OnCompleteFurnishedRentHandler, OnTimeOutFurnishedRentHandler, OnErrorFurnishedRentHandler);
    if (typeof(lblHotDealsClientID) != 'undefined')
    {
        ret = zoneHandler.getHotDealZoneHtml("1",fldrImagesURL,pEqnURL,pProfURL,OnCompleteHotDealsHandler, OnTimeOutHotDealsHandler, OnErrorHotDealsHandler);
    }
    if (typeof(lblHotResProjectsClientID) != 'undefined')
    {
        ret = zoneHandler.bindResCommStocks('1',projProfURL,OnCompleteHotResProjectsHandler, OnTimeOutHotResProjectsHandler, OnErrorHotResProjectsHandler);
    }
    if (typeof(lblHotComProjectsClientID) != 'undefined')
    {
        ret = zoneHandler.bindResCommStocks('0',projProfURL,OnCompleteHotComProjectsHandler, OnTimeOutHotComProjectsHandler, OnErrorHotComProjectsHandler);
    }
}

//********************************************INIT LOAD********************************************//
