﻿function UploadImageStart(lblImageID)
{
    document.getElementById(lblImageID).innerHTML="Uploading image, please wait...";
}

 function NoImageDisplay(obj,VirtualPath)
 {
    obj.src=VirtualPath+"no-image.gif";
 }
 //display selected large image on property detail page 
 function DisplayLargePhoto(FullPhotoPath,lblFullPhoto,FullVirualpath)
{
    setTimeout("DisplayLargePhotoNew('"+FullPhotoPath+"','"+lblFullPhoto+"','"+FullVirualpath+"');",100); 
}
function DisplayLargePhotoNew(FullPhotoPath,lblFullPhoto,FullVirualpath)
{ 
    var lbl=document.getElementById(lblFullPhoto);       
    lbl.innerHTML="<img src=\""+FullPhotoPath+"\" OnError=\"javascript:NoImageDisplay(this,'"+FullVirualpath+"');\" alt=\"\">";
}
 //End display large photo on property detail page
//This function show the selected image selected in list box
function Photo_Delete_ShowPreview(lblImageID,VirtualPath,ListBoxID)
{
    var lst=document.getElementById(ListBoxID);        

    var SelectedImageName=lst[lst.selectedIndex].text;

    var lbl=document.getElementById(lblImageID);    
    lbl.innerHTML="<img src=\""+VirtualPath+SelectedImageName+"\" OnError=\"javascript:NoImageDisplay(this,'"+VirtualPath+"');\" alt=\"\">";
}
//this function check condition "I understand that when deleted, this image can not be recovered on Delete photo page
function EnableButton(obj,ListBoxID,btn_delete)
{
    var lst=document.getElementById(ListBoxID);
    if(lst.value!="" && lst.value>0)
    {
        if(obj.checked)
        {
            document.getElementById(btn_delete).disabled=false;
        }
        else
        {
            document.getElementById(btn_delete).disabled=true;
        }
    }
    else
    {
        obj.checked=false;
        alert("Please select Photo");
    }
}

//this function check condition "I understand that when deleted, this property can not be recovered. Photos are deleted manually.
function EnableDeleteButton(obj,DRPID,btn_delete)
{
    var lst=document.getElementById(DRPID);
    if(lst.value=="" || lst.value==0 || lst.value==null)
    {
        obj.checked=false;
        alert("Please select property for delete.");        
    }
    else
    {
        if(obj.checked)
        {
            document.getElementById(btn_delete).disabled=false;
        }
        else
        {
            document.getElementById(btn_delete).disabled=true;
        }
    }
}


//This function show the selected image selected in list box
function PropertyAdd_ShowPreview(lblPhotoID,VirtualPath,ListBoxID)
{
    setTimeout("PropertyAdd_ShowPreviewNew('"+lblPhotoID+"','"+VirtualPath+"','"+ListBoxID+"')",100)
}
function PropertyAdd_ShowPreviewNew(lblPhotoID,VirtualPath,ListBoxID)
{
    //alert(lblPhotoID+","+VirtualPath+","+ListBoxID);
    var lst=document.getElementById(ListBoxID);        

    var SelectedImageName=lst[lst.selectedIndex].text;

    var lbl=document.getElementById(lblPhotoID);    
    lbl.innerHTML="<img src=\""+VirtualPath+SelectedImageName+"\" OnError=\"javascript:NoImageDisplay(this,'"+VirtualPath+"');\" alt=\"\">";
}
function ShowPopupSelectPhoto()
{
    SelectExistingPhoto();
    var modal = $find(ModalPopupSelectPhotoID); 
    modal.show(); 
}
function SelectExistingPhoto()
{
    var txtHID=document.getElementById(txtH_AllSelectedPhotosID);
    var arrHID=txtHID.value.split(",");
    var lst=document.getElementById(lstPhotosID);
    var i=0;
    var j=0;
    for(i=0;i<lst.length;i++)
    {
        for(j=0;j<arrHID.length;j++)
        {
            if(arrHID[j]!="")
            {
                if(arrHID[j]==lst[i].value)
                {
                    lst[i].selected=true;
                    //j++;
                    //break;
                }
            }
        }
    }
}
function ClosePopupSelectPhoto()
{
    HidePopupSelectPhoto();
}
function ClosePopupDeletePhotoConfirm()
{
    HidePopupDeletePhotoConfirm();
}
function HidePopupSelectPhoto()
{
    var modal = $find(ModalPopupSelectPhotoID); 
    modal.hide(); 
    ShowSelectedPhotos();
    void(0);
}
function HidePopupDeletePhotoConfirm()
{
    var modal = $find(ModalPopupDeletePhotoConfirmID); 
    modal.hide(); 
    void(0);
}
function SaveSelectedPhoto()
{
    var lst=document.getElementById(lstPhotosID);
    var i=0;
    var txtH_SelectedPhotosID=document.getElementById(txtH_AllSelectedPhotosID);
    txtH_SelectedPhotosID.value="";
    for(i=0;i<lst.length;i++)
    {
        if(lst[i].selected)
        {
            var SelectedImageValue=lst[i].value;
            if(txtH_SelectedPhotosID.value=="") txtH_SelectedPhotosID.value=",";
            txtH_SelectedPhotosID.value=txtH_SelectedPhotosID.value+SelectedImageValue+",";
        }
    }
    setTimeout('HidePopupSelectPhoto()',0);
}
function ShowSelectedPhotos()
{
    var lblAllPhotos=document.getElementById(lblAllPhotosID);
    if(lblAllPhotos!=null)
    {
        lblAllPhotos.innerHTML="";
        var txtHID=document.getElementById(txtH_AllSelectedPhotosID);
        var arrHID=txtHID.value.split(",");
        var i=0;
        var DisplayRecordPerRow=6;
        var TotalPhotos=arrHID.length;
        var TdWidth=100/DisplayRecordPerRow;
        
        var HTML="";
        HTML+="<table cellpadding='0' cellspacing='0' border='0' width='100%' align='center'>";
        HTML+="     <tr>";
        var count=0;
        for(i=0;i<TotalPhotos;i++)
        {
            if(arrHID[i]!="")
            {
                var arr=arrHID[i].split("#");
                if(count%DisplayRecordPerRow==0)
                {
                    HTML+="     </tr>";
                    HTML+="     <tr><td width='5%' colspan=\""+DisplayRecordPerRow+"\">&nbsp;</td></tr>";
                    HTML+="     <tr>"; 
                    count=0;
                }
                HTML+="         <td valign='middle' width='"+TdWidth+"%' align='center' class=\"black8ptver\">";
                HTML+="             <table cellpadding='0' cellspacing='0' border='0' align='center'>";
                HTML+="                 <tr>"; 
                HTML+="                     <td align='center'>"; 
                HTML+="                         <img src=\""+ThumbVirtualPath+arr[1]+"\" border=\"0\" alt=\"\">";
                HTML+="                     <td>"; 
                HTML+="                 </tr>"; 
                HTML+="                 <tr><td style=\"height:3px;\"></td></tr>"; 
                HTML+="                 <tr>"; 
                HTML+="                     <td>"; 
                HTML+="                         <table cellpadding='0' cellspacing='0' border='0' align='center'>";
                HTML+="                             <tr>";
                HTML+="                                 <td class=\"black8ptver\">"+arr[1]+"</td>";
                HTML+="                                 <td style=\"width:5px;\"></td>";
                HTML+="                                 <td>"; 
                HTML+="                                     <a href=\"javascript:void(0);\" onclick=\"ShowDeleteConfirmPhotos('"+arrHID[i]+"')\"><img src=\"../images/delete.gif\" border=\"0\" alt=\"\"></a><br>";
                HTML+="                                 </td>"; 
                HTML+="                             </tr>";
                HTML+="                         </table>"; 
                HTML+="                     </td>"; 
                HTML+="                 </tr>"; 
                HTML+="             </table>";
                HTML+="         </td>";
                count++;
            }
        }
        if(count!=DisplayRecordPerRow)
        {
		    for(i=count;i<=DisplayRecordPerRow;i++)
		    {
			    HTML+="            <td valign='middle' width='"+TdWidth+"%' align='center'></td>";
		    }
        }
        HTML+="     </tr>";
        HTML+="</table>";
        lblAllPhotos.innerHTML=HTML;
    }
}
function ShowDeleteConfirmPhotos(PhotoID)
{
    DeletePhotoID=PhotoID;
    var arr=PhotoID.split("#");
    document.getElementById(divDeletePhotoConfirmID).innerHTML="Are you sure you want to delete photo<br>"+arr[1]+"?";
    var modal = $find(ModalPopupDeletePhotoConfirmID); 
    modal.show(); 
}
function DeleteSelectedPhoto()
{
    var txtHID=document.getElementById(txtH_AllSelectedPhotosID);
    txtHID.value=txtHID.value.replace(','+DeletePhotoID+',',',');
    if(txtHID.value==",") txtHID.value="";
    ShowSelectedPhotos();
    setTimeout('HidePopupDeletePhotoConfirm()',0);
}


//display properties photo for property detail page Start
function ShowPropertyPhotos(){
    
    var lblAllPhotos=document.getElementById(lblAllPhotosID);
    if(lblAllPhotos!=null)
    {
        lblAllPhotos.innerHTML="";
        var txtHID=document.getElementById(txtH_AllSelectedPhotosID);
        var arrHID=txtHID.value.split(",");
        var i=0;
        var DisplayRecordPerRow=5;
        var TotalPhotos=arrHID.length;
        var TdWidth=100/DisplayRecordPerRow;
        
        var HTML="";
        HTML+="<table cellpadding='2' cellspacing='0' border='0' width='100%' align='center'>";
        HTML+="     <tr>";
        var count=0;
        for(i=0;i<TotalPhotos;i++)
        {
            if(arrHID[i]!="")
            {
                var arr=arrHID[i].split("#");
                if(count%DisplayRecordPerRow==0)
                {
                    HTML+="     </tr>";
                    HTML+="     <tr><td width='1%' colspan=\""+DisplayRecordPerRow+"\"></td></tr>";
                    HTML+="     <tr>"; 
                    count=0;
                }
                HTML+="         <td valign='middle' width='"+TdWidth+"%' align='center' class=\"black8ptver\">";
                HTML+="             <table cellpadding='0' cellspacing='0' border='0' align='center'>";
                HTML+="                 <tr>"; 
                HTML+="                     <td align='center'>"; 
                HTML+="                         <a href=\"javascript:void(0)\" onclick=\"javascript:DisplayLargePhoto('"+FullVirtualPath+arr[2]+"','"+lblFullPhotoShow+"','"+FullVirtualPath+"');\"><img src=\""+ThumbVirtualPath+arr[1]+"\" OnError=\"javascript:NoImageDisplay(this,'"+FullVirtualPath+"');\"  border=\"0\" alt=\"\"></a>";
                HTML+="                     <td>"; 
                HTML+="                 </tr>";            
                HTML+="             </table>";
                HTML+="         </td>";
                count++;
            }
        }
        if(count!=DisplayRecordPerRow)
        {
		    for(i=count;i<=DisplayRecordPerRow;i++)
		    {
			    HTML+="            <td valign='middle' width='"+TdWidth+"%' align='center'></td>";
		    }
        }
        HTML+="     </tr>";
        HTML+="</table>";
        lblAllPhotos.innerHTML=HTML;
    }
}
//End property photo for property detail page End


