﻿// JScript File
//--------------This function is used to get mouse pointer in Internet Explorer and Mozilla
    window.onload = function () 
    {
    //This check is to ensure this function should not get a call from compare vehicle page as same JS file is being used in multiple pages
        var pageName=location.href.toLowerCase();
        //alert(pageName.indexOf("comparevehicle",0));
        
        
    }

    function init() 
    {
        if (window.Event) 
        {
            document.captureEvents(Event.MOUSEMOVE);    
        }
        document.onmousemove = getXY;
    }
    
//---------------------------------------Function to get XY co-ordinates---------------------------------------

    function getXY(e) 
    {
        x = (window.Event) ? e.pageX : event.clientX;        
        y = (window.Event) ? e.pageY : event.clientY+document.body.scrollTop;
        Y=y-50;         
        document.getElementById("Divimage").style.position="absolute";
        if(document.all)
        {    
        }
        else
        {  
        }   
    }
//---------------------------------------------------------------------------------------------------------------
   function TotalHeightAboveGrid()
   {    
           
        var Header=document.getElementById("trHeader");
        var HeaderHeight=parseInt(Header.scrollHeight); 
        var tdBannerTopSpace1=document.getElementById("tdBannerTopSpace1");
        var tdBannerTopSpace1Height=parseInt(tdBannerTopSpace1.height);
        var tdBannerTopSpace2=document.getElementById("tdBannerTopSpace2");
        var tdBannerTopSpace2Height=parseInt(tdBannerTopSpace2.height);
        var tblBanner=document.getElementById("tblBanner");
        var tblBannerHeight=parseInt(tblBanner.scrollHeight);
        var tblPagging=document.getElementById("tblPagging");
        var tblPaggingHeight=parseInt(tblPagging.scrollHeight);
        var tblSpaceBelowPaging=document.getElementById("tblSpaceBelowPaging");
        var tblSpaceBelowPagingHeight=parseInt(tblSpaceBelowPaging.scrollHeight);
        var tblGridHeader=document.getElementById("tblGridHeader");
        var tblGridHeaderHeight=parseInt(tblGridHeader.scrollHeight);
        var TotalHeight=HeaderHeight+tdBannerTopSpace1Height+tdBannerTopSpace2Height+tblBannerHeight+tblPaggingHeight+tblSpaceBelowPagingHeight+tblGridHeaderHeight;
        return TotalHeight;
   } 
//-----------------------------------------------------------------------------------------------------------------   
   function TotalHeightBelowGrid()
   {
 
         var Footer=document.getElementById("Footer1_tblfooter");
         var FooterHeight=parseInt(Footer.scrollHeight);
         var tdAboveFooter=document.getElementById("tdAboveFooter");
         var tdAboveFooterHeight=parseInt(tdAboveFooter.height);
         var tdSpaceBelowGrid2=document.getElementById("tdSpaceBelowGrid2");
         var tdSpaceBelowGrid2Height=parseInt(tdSpaceBelowGrid2.height);
         var tdSpaceBelowGrid1=document.getElementById("tdSpaceBelowGrid1");
         var tdSpaceBelowGrid1Height=parseInt(tdSpaceBelowGrid1.height);
         var trPagingBelowGrid=document.getElementById("tdPagingBelowGrid");
         var trPagingBelowGridHeight=parseInt(trPagingBelowGrid.scrollHeight);
         var TotalHeight=FooterHeight+tdAboveFooterHeight+tdSpaceBelowGrid2Height+tdSpaceBelowGrid1Height+trPagingBelowGridHeight;
         return TotalHeight;
   }
    function TotalGridHeight()
    {   
         var tblBanner=document.getElementById("tblBanner");
         var tblBannerHeight=parseInt(tblBanner.scrollHeight);
         var tblPagging=document.getElementById("tblPagging");
         var tblPaggingHeight=parseInt(tblPagging.scrollHeight);
         
         var tblSpaceBelowPaging=document.getElementById("tblSpaceBelowPaging");
         var tblSpaceBelowPagingHeight=parseInt(tblSpaceBelowPaging.scrollHeight);
         var tableHideShow=document.getElementById("tableHideShow");
          var tdSpaceBelowGrid2=document.getElementById("tdSpaceBelowGrid2");
         var tdSpaceBelowGrid2Height=parseInt(tdSpaceBelowGrid2.height);
         var tdSpaceBelowGrid1=document.getElementById("tdSpaceBelowGrid1");
         var tdSpaceBelowGrid1Height=parseInt(tdSpaceBelowGrid1.height);
         var trPagingBelowGrid=document.getElementById("tdPagingBelowGrid");
         var trPagingBelowGridHeight=parseInt(trPagingBelowGrid.scrollHeight);
         var tableHideShowHeight=parseInt(tableHideShow.scrollHeight);
         var TotalHeight=tblBannerHeight+tblPaggingHeight+tblSpaceBelowPagingHeight+tableHideShowHeight+tdSpaceBelowGrid2Height+tdSpaceBelowGrid1Height+trPagingBelowGridHeight;
         return TotalHeight;
    }  
    function TotalRightPanelHeight()
    {   
         var tblMyAccount=document.getElementById("tblMyAccount");  
         var tblMyAccountHeight=parseInt(tblMyAccount.scrollHeight);
         var tblRightNavigation=document.getElementById("tblRightNavigation");  
         var tblRightNavigationHeight=parseInt(tblRightNavigation.scrollHeight);
         var tblSpaceBelowPaging=document.getElementById("tblSpaceBelowPaging");
        var tblSpaceBelowPagingHeight=parseInt(tblSpaceBelowPaging.scrollHeight);
         var tdSponsoredLink=document.getElementById("tdSponsoredLink");
         var tdSponsoredLinkHeight=parseInt(tdSponsoredLink.scrollHeight);
         var tdGoogleADD=document.getElementById("tdGoogleADD");
         var tdGoogleADDHeight=parseInt(tdGoogleADD.scrollHeight);
         var TotalHeight=tblMyAccountHeight+tblRightNavigationHeight+tblSpaceBelowPagingHeight+tdSponsoredLinkHeight+tdGoogleADDHeight;
         return TotalHeight;
    }
    
    function show(b,DivName,URL)
    {        
        
          var strImage;
          document.getElementById("Divimage").style.display="block";
          var thumbImage=document.getElementById("imgVehicle");                                 
          var isIE = (navigator.appName.toLowerCase() == "microsoft internet explorer")
          var isNN = (navigator.appName.toLowerCase() == "netscape")
          var _divMain=document.getElementById("divMain"+DivName);
          var objItem = document.getElementById("divMain"+DivName)
          var objParent = null
          var intX = 0
          var intY = 0
          do
          {     // Walk up our document tree until we find the body
                // and add the distance from the parent to our counter.
                intX += objItem.offsetLeft
                intY += objItem.offsetTop
                objParent = objItem.offsetParent.tagName
                objItem = objItem.offsetParent
           }
           while(objParent != 'BODY')
           var myScrollX
           var myScrollY
           var intImgLeft = intX ;//- myScrollX
           var intImgTop = intY ;//- myScrollY
           var Y = intImgTop;
           
           if (isIE)
               {
                    X=intImgLeft-125;
                    document.getElementById("Divimage").style.left=X+ "px";
               }
                document.getElementById("Divimage").style.position="absolute";
                document.getElementById("Divimage").style.top=Y+ "px";                                             
          
                //document.getElementById("Divimage").innerHTML=image;
                var thumbImage=document.getElementById("imgVehicle");
                thumbImage.Height="76px";
                thumbImage.Width="95px";
                thumbImage.src=b;
       
      
        return false;
    }
//----------------------------------------------------------------------------------------------------------------
    //This function Hide is used to Hide div tag used in SearchResult page displaying car image. The image source
    //is passed as null in this function and thus the there is no image to display.
    function SearchResultHide(b,DivName)
    {
       
         //eraseCookie('ExpandedDiv');
         //document.getElementById("Divimage"+DivName).innerHTML=b;
        
         //document.getElementById("Divimage").innerHTML=b;
         document.getElementById("imgVehicle").src="../Images/spacer.png";
         return false;
     }
//----------------------------------------Function ends here------------------------------------------------------     


//------------------This function is used to show the orange border color of row on mouseover---------------------   
    function GridBorderColorShow(DivName, tblMain)
     {
         var _ImgLeft, _ImgRight, _ImgBackground;
         
         _ImgLeft = document.getElementById("rowLeftImg"+DivName);
         _ImgBackground = document.getElementById("rowBgImg"+DivName);
         _ImgRight = document.getElementById("rowRightImg"+DivName);
         
         _ImgLeft.src = "../images/orange_left.gif";
         _ImgBackground.style.background = "url(../images/orange_middle_bg.gif)";
         _ImgRight.src = "../images/orange_right.gif";         
        
         document.getElementById(tblMain).className="inv_txt_white";            

         return false;
     }
//------------------------------------Function Ends here----------------------------------------------------------     
     
//----------------This function is used to hide the orange border color of row on mouseout----------------------

     function  GridBorderColorHide(DivName, tblMain)
     {
           var _ImgLeft, _ImgRight, _ImgBackground;
         
         _ImgLeft = document.getElementById("rowLeftImg"+DivName);
         _ImgBackground = document.getElementById("rowBgImg"+DivName);
         _ImgRight = document.getElementById("rowRightImg"+DivName);
         
         _ImgLeft.src = "../images/gray_small_bar_left.gif";
         
          _ImgBackground.style.background = "url(../images/gray_small_bar_bg.gif)";
         _ImgRight.src = "../images/gray_small_bar_right.gif";
          
          document.getElementById(tblMain).className="inv_txt_1";            
            
          return false;
     }

   
function OpenAlert(message)
{
    alert(message);
    //OpenHideAllDiv(0,0);
} 

        

//-------------------------Function to display popup for adding seller to Favourites------------------            
   function AddSeller(uid,source)
   {      
        ChkUser = CheckLoginUser(uid);

        if(ChkUser == -1)
        {
            showConfirm(source,'Login'); 
            return false;
        }
        else if(ChkUser == 1)
        {
            var bol = confirm('Are you sure you want to add yourself to your favorites?');
            if(bol)
            {
                showConfirm(source,'fav'); 
                return false;
            }
            else
                return false;
        }
        else if(ChkUser == 0)
        {
            var isShowPopup = checkBlockorNot(source);
            if(isShowPopup)
            {                   
                showConfirm(source,'fav'); 
            }
            return false;
        } 
       else if(ChkUser == -99)
        {
            window.location.href="../User/MyAccountInfo.aspx";
            return false;
        }
    }
//---------------------------------Function Ends here---------------------------------------------- 
   
//-------------------------Function to display popup for adding Comments---------------------------    
    function addComments(uid, source)
    {          
        ChkUser = CheckLoginUser(uid);    
        if(ChkUser == -1)
        {
            showConfirm(source,'Login'); 
            return false;
        }
        else if(ChkUser == 1)
        {
            alert('You can not rate yourself!');
            return false; 
        }
        else if(ChkUser == 0)
        {
            showConfirm(source,'Comments'); 
            return false;
        }
        else if(ChkUser == -99)
        {
            window.location.href="../User/MyAccountInfo.aspx";
            return false;
        }
    }
   
//---------------------------------Function Ends here---------------------------------------------- 
   
//-------------------------Function for blocking seller---------------------------------------   
   
    function BlockSeller(uid,source)
    {    
        ChkUser = CheckLoginUser(uid);
        if(ChkUser == -1)
        {
            showConfirm(source,'Login'); 
            return false;
        }
        else if(ChkUser == 1)
        {
            alert('You can not Block yourself!');
            return false;  
        }
        else if(ChkUser == 0)
        {
            var bol= confirm('You are about to Block this member. You may unblock them at anytime from your account page.')
            if(bol)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else if(ChkUser == -99)
        {
            window.location.href="../User/MyAccountInfo.aspx";
            return false;
        }
    }  
   
//---------------------------------Function Ends here---------------------------------------------- 
   
   //-------------------------Function for blocking seller---------------------------------------   
   
    function RateVehicle(source)
    {
        var isShowPopup = checkBlockorNot(source);
        if(isShowPopup)
        { 
            return true;
        }           
        else
        {
            return false;
        }
    }  
   
//---------------------------------Function Ends here---------------------------------------------- 

//-------------------------Function to display popup for sending email to seller---------------------------   
   
    function EmailSeller(uid, source)
    {
        ChkUser = CheckLoginUser(uid);
        if(ChkUser == -1)
        {
            showConfirm(source,'Login'); 
            return false;
        }
        else if(ChkUser == 1)
        {
            var bol = confirm('Are you sure you want to send mail to yourself?');
            if(bol)
            {
                showConfirm(source,'email'); 
                return false;
            }
            else
                return false;
        }
        else if(ChkUser == 0)
        {
            var isShowPopup = checkBlockorNot(source);
            if(isShowPopup)
            {                                  
                showConfirm(source,'email');
            }
            return false;
        }
        else if(ChkUser == -99)
        {
            window.location.href="../User/MyAccountInfo.aspx";
            return false;
        }
    }

//---------------------------------Function Ends here------------------------------------------------------- 
//---------------------------------Function to check whether user blocked or not---------------------------- 
function checkBlockorNot(src)
{
        //Code to create label id for lblBlockFlag
        var ctlVal = src.id;           
        var ctlValArr=ctlVal.split('_');

        var LabId="";        
        LabId = ctlValArr[0] + '_' + ctlValArr[1] + '_' + "lblBlockFlag";                        
        
        var lblBlockFlag = document.getElementById(LabId).innerHTML;        
        
        if(lblBlockFlag == "True")
        {
            alert("You are blocked by this member and may not contact them at this time.");
            return false;
        }
        else
        {
            return true;
        }
  }
//---------------------------------Function Ends here------------------------------------------------------- 

//-------------------------Function to display popup for making offer ------------------------------      
   
    function makeOffer(uid, source)
    {
        var ChkUser = CheckLoginUser(uid);
        
        if(ChkUser == -1)
        {
            showConfirm(source,'Login'); 
            return false;
        }
        else if(ChkUser == 1)
        {
            var bol = alert("This item belongs to you.");
            if(bol)
            {            
                return false;
            }
            else
                return false;
        }
        else if(ChkUser == 0)
        {
            var isShowPopup = checkBlockorNot(source);
            if(isShowPopup)
            {                   
                showConfirm(source,'MakeOffer');
            }
            return false;
        }
        else if(ChkUser == -99)
        {
            window.location.href="../User/MyAccountInfo.aspx";
            return false;
        }
    }
   
 //---------------------------------Function Ends here---------------------------------------------- 
   
   //-------------------------Function to display popup for Reporting to Concern---------------------------   
   
    function ReportToConcern(uid, source)
    {   
        var ChkUser = CheckLoginUser(uid);
        if(ChkUser == -1)
        {
            showConfirm(source,'Login'); 
            return false;
        }
        else if(ChkUser == 1)
        {
            var bol = alert("This Vehicle belongs to u.");
            if(bol)
            {
                showConfirm(source,'ReportAConcern'); 
                return false;
            }
            else
                return false;
        }
        else if(ChkUser == 0)
        {
            showConfirm(source,'ReportAConcern');
            return false;
        }
        else if(ChkUser == -99)
        {
            window.location.href="../User/MyAccountInfo.aspx";
            return false;
        }
    }

//---------------------------------Function Ends here---------------------------------------------- 
   
//-------------------------Function to Set Alert---------------------------   
   
    function SetAlerts(uid, source)
    {   
        var ChkUser = CheckLoginUser(uid);
        if(ChkUser == -1)
        {
            showConfirm(source,'Login'); 
            return false;
        }
        else if(ChkUser == 1)
        {
            var bol = alert("This item belongs to you.");
            if(bol)
            {
                return false;
            }
            else
            {
                return false;
            }
        }
        else if(ChkUser == 0)
        {
            var isShowPopup = checkBlockorNot(source);
            if(isShowPopup)
            { 
                return true;
            }
            else
            {
                return false;
            }
        }
        else if(ChkUser == -99)
        {
            window.location.href="../User/MyAccountInfo.aspx";
            return false;
        }
    }

//---------------------------------Function Ends here---------------------------------------------- 
   
// //------------------------------Function to display popup for Show Interest-----------------------
// 
//    function ShowInterest(uid, source)
//    {
//        ChkUser = CheckLoginUser(uid);
//    
//        if(ChkUser == -1)
//        {
//            showConfirm(source,'Login'); 
//            return false;
//        }
//        else if(ChkUser == 1)
//        {
//            var bol = alert("This Item belongs to you.");
//            if(bol)
//            {           
//                return false;
//            }
//            else
//                return false;
//        }
//        else if(ChkUser == 0)
//        {
//            var isShowPopup = checkBlockorNot(source);
//            if(isShowPopup)
//            {                   
//                showConfirm(source,'ShowInterest');
//            }
//            return false;
//        }
//        else if(ChkUser == -99)
//        {
//            window.location.href="../User/MyAccountInfo.aspx";
//            return false;
//        }
//    }
// 
// //----------------------------------Function ends here-------------------------------------  
 
 //------------------------------Function to Save Vehicle-----------------------
 
    function SaveVehicle(uid, source)
    {
        ChkUser = CheckLoginUser(uid);
        if(ChkUser == -1)
        {
            showConfirm(source,'Login'); 
            return false;
        }
        else if(ChkUser == 1)
        {
            var bol = alert("This item belongs to you.");
            if(bol)
            {        
                return false;
            }
            else
                return false;
        }
        else if(ChkUser == 0)
        {
            var isShowPopup = checkBlockorNot(source);
            if(isShowPopup)
            { 
                return true;
            }
            else
            {
                return false;
            }
        }
        else if(ChkUser == -99)
        {
            window.location.href="../User/MyAccountInfo.aspx";
            return false;
        }
    }

 //----------------------------------Function ends here-------------------------------------  

//------------------------------Function to forward a friend-----------------------


function forwardToFriend(uid, source)
   {
     var ChkUser = CheckLoginUser(uid);
     // alert(ChkUser);
            if(ChkUser == -1)
            {
             showConfirm(source,'Forward'); 
             return false;
            }
            else if(ChkUser == 1)
            {
                
                var bol = confirm('Are you sure you want to forward your buying interest to your friend?');
                 if(bol)
               {
                   showConfirm(source,'Forward'); 
                   return false;
               }
               else
                 return false;
                
            }
            else if(ChkUser == 0)
            {
              
              showConfirm(source,'Forward');
              return false;
            }
            else if(ChkUser == -99)
            {
                   window.location.href="../User/MyAccountInfo.aspx";
                   return false;
                
            }
  
   }


 //----------------------------------Function ends here-------------------------------------  


//function to check for login
function CheckUserLoggedIn(UserId,IsActive,source)   
{
    if(UserId=="-1")
        {
           showConfirm(source,'Login');
           return false;
        }
    else if(IsActive=="" || IsActive=="false")
        {
           window.location.href="../User/MyAccountInfo.aspx";
           return false;
        }

}



//--------------------------------------Function to display Chat window---------------------------   
   
    function Chat_OpenContact(uid,name,loggin)   
    {   
        if(loggin != "True")
        {
            alert("Seller is offline!");
            return false;
        }
        var UserId='<%= Session["Uid"]%>';
        if(UserId=="")
        {
            alert('Please Login/Register to Chat!');
            return false;
        }
        else if(uid==UserId)
        {
            alert('You can not chat with yourself!');
            return false;  
        }
        else
        {
            window.open('../MessengerWindow.aspx?init=1&target='+name+'','iBuyer.com','width=650,height=400,resizable=1,menubar=0,status=0,toolbar=0'); 
        }
    }
   
//---------------------------------Function Ends here---------------------------------------------- 
   
//----------------Function to check number of chk boxes checked for comparing vehicles-------------     
  
   function CheckCompareVehicle()
   {          
      var frm = document.forms[0];
      var count = 0;
      for(var i=0; i<frm.elements.length;i++)
      {               
            if (frm.elements[i].type == "checkbox" &&  frm.elements[i].id.indexOf('gvVehicle') != -1)
            {
               if(frm.elements[i].checked)
                 {                       
                   count++;
                 }  
            }
      }
      if(count < 2)
      {
        alert('Please check at least two boxes to perform this action!');
        return false;
      }
      else if(count > 4)
      {
         alert('You can not compare more than 4 items at a time!');
         return false;
      }
      return true;
          
   }
   
//---------------------------------Function Ends here----------------------------------------------   

function showAlert(str, str1)
{
    alert(str);
    alert(str1);
}


function CheckAll()
{

if(document.getElementById("chkAll").checked==true)
    {
        document.getElementById("chkSeller").checked=true;
        document.getElementById("chkBuyer").checked=true;
        document.getElementById("chkFriend").checked=true;
    }
else if(document.getElementById("chkAll").checked==false)
    {
        document.getElementById("chkSeller").checked=false;
        document.getElementById("chkBuyer").checked=false;
        document.getElementById("chkFriend").checked=false;
    }
}

function Redirect(lnkDetailPage)
{
    if(document.getElementById('hdCheckboxMaintain').value == "")
    {
       
        document.getElementById(lnkDetailPage).click();
    }
    else
    {
     document.getElementById("hdCheckboxMaintain").value = "";
    }
}