﻿// JScript File

    var _source;
    // keep track of the popup div
    var _popup;
    
    function showConfirm(source,popupName)
    {       
       //clear message from login window
       if(popupName == "Login")
       {
           if(document.getElementById('MainHeader_LoginPopUp_lblMessage'))
              document.getElementById('MainHeader_LoginPopUp_lblMessage').innerHTML = "";
           else if(document.getElementById('MainHeader_LoginPopUp_lblMessage'))
              document.getElementById('MainHeader_LoginPopUp_lblMessage').innerHTML = "";
       }
       if(document.getElementById('HomeFlash') != null)
       {
           document.getElementById('HomeFlash').style.display = 'none';

       }
       
       //  find the browser type
       //var browserName=navigator.appName; 
      
       document.body.style.overflow = 'hidden';
       this._source = source;
       //  find the confirm ModalPopup and show it  
       this._popup = $find(popupName);
                   
       // Show the popup
       this._popup.show();
       
       if(document.getElementById("Player") != null)
	   {		
	    	document.getElementById("Player").style.display="none";       
	   }
       
    }
    

       function okClick()
       {
            //debugger;
            if(_source == "lnkbtnAddToFavorites")
            {                   
               this._popup.hide();
               __doPostBack(this._source,'');               
               
                document.body.style.overflow = 'auto';
               //  clear the event source
               this._source = null;
               this._popup = null;
            }
            else
            {
                //  find the confirm ModalPopup and hide it    
                this._popup.hide();
                //  use the cached button as the postback source
                         
                if(this._source.id.indexOf('$') == -1)
                //if(this._source.indexOf('$') == -1)
                {            
                    __doPostBack(this._source.id.replace(/_/g,'$'), '');
                }
                else
                {
                    __doPostBack(this._source,'');               
                }
               
                document.body.style.overflow = 'auto';
               //  clear the event source
               this._source = null;
               this._popup = null;
            }
       }
       
       function onClickOfferMeVehicleSend()
       {     
            var flag="0";      
            if(document.getElementById('ddMyVehicles').value == 0)  
            {
                alert('You must choose a vehicle from your inventory.'); 
                flag="1";
                document.body.style.overflow = 'auto';                     
           	    // Hide the popup
           	    this._popup.hide();           
            	if(document.getElementById('HomeFlash') != null)
           	    {
               		document.getElementById('HomeFlash').style.display = 'block';

           	    }           
		        // calling a method for open the popup again
		        showConfirm(_source,'OfferVehicle');                     
            }   
            else if(document.getElementById('txtamount').value == '')   
            {
                alert('You must enter an amount.'); 
                flag="1";
		        document.body.style.overflow = 'auto';             
           	    // Hide the popup
           	    this._popup.hide();           
           	    if(document.getElementById('HomeFlash') != null)
           	    {
               		document.getElementById('HomeFlash').style.display = 'block';

           	    }
           	
                // calling a method for open the popup again
		        showConfirm(_source,'OfferVehicle');                                              
            }
             else
            {
                if(document.getElementById('hdPriceFrom').value!=null)
                {
                    var PriceFrom=parseInt(document.getElementById('hdPriceFrom').value);
                    var PriceTo=parseInt(document.getElementById('hdPriceTo').value);
                    var txtboxAmount=parseInt(document.getElementById('txtamount').value);
                    if(txtboxAmount<PriceFrom || txtboxAmount>PriceTo)
                    {
                        alert('Enter amount within price range.'); 
                        flag="1";
		                document.body.style.overflow = 'auto';             
           	            // Hide the popup
           	            this._popup.hide();           
           	            if(document.getElementById('HomeFlash') != null)
           	            {
               		        document.getElementById('HomeFlash').style.display = 'block';

           	            }
                   	
                        // calling a method for open the popup again
		                showConfirm(_source,'OfferVehicle');       
                     }
                }
            }
            if(flag=="0")
            {               
               this._popup.hide(); //  find the confirm ModalPopup and hide it 
               if(document.getElementById('HomeFlash') != null)
               {
                   document.getElementById('HomeFlash').style.display = 'block';

               }            
                if(this._source.indexOf('$') == -1)
                {            
                    __doPostBack(this._source.replace(/_/g,'$'), '');                
                }          
                else
                {                
                    __doPostBack(this._source,'');               
                }
               
               document.body.style.overflow = 'auto';
               if(document.getElementById('HomeFlash') != null)
               {
                   document.getElementById('HomeFlash').style.display = 'block';

               }
               //  clear the event source
               this._source = null;
               this._popup = null;
           }
       }
       
       function okClickForOfferPages()
       {             
            if(this._source.indexOf('$') == -1)
            {            
                __doPostBack(this._source.replace(/_/g,'$'), '');
            }
          
            else
            {
                __doPostBack(this._source,'');               
            }
           
            document.body.style.overflow = 'auto';
           if(document.getElementById('HomeFlash') != null)
           {
               document.getElementById('HomeFlash').style.display = 'block';

           }
           //  clear the event source
           this._source = null;
           this._popup = null;
       }//okClickForOfferPages    

       function cancelClick()
       {          
           document.body.style.overflow = 'auto';         
            
           // Hide the popup
           this._popup.hide();
           
           if(document.getElementById('HomeFlash') != null)
           {
               document.getElementById('HomeFlash').style.display = 'block';

           }
           //  clear the event source
           this._source = null;
           this._popup = null;  
	   
	   if(document.getElementById("Player") != null)
	   {		
           	document.getElementById("Player").style.display="block";       
	   }
       }

// method for checking the offer amount from view profile page for offer me a vehicle when click send.       
function CheckOfferPriceAmount(txtboxid)
{        
   if(document.getElementById(txtboxid).value == "")
   {
        alert('Enter Amount');
        document.getElementById(txtboxid).focus();
        return false;
   } 
   else
   {        
        var source = this._source;        
        var idPart = source.split('_');  
              
        var lblPriceFromId = idPart[0] + '_' + idPart[1] + '_' + 'hdPriceFrom';
        var lblPriceToId = idPart[0] + '_' + idPart[1] + '_' + 'hdPriceTo'; 

        var PriceFromValue = document.getElementById(lblPriceFromId).value;
        var PriceToValue = document.getElementById(lblPriceToId).value;
        
        if(PriceFromValue != '0.0000')  
        {            
            PriceFromValue = PriceFromValue.split('.');
            PriceToValue = PriceToValue.split('.');  
            
            var PriceFromAmount = parseInt(PriceFromValue[0]);
            var PriceToAmount = parseInt(PriceToValue[0]);                               
            
            var PriceAmount =  parseInt(document.getElementById(txtboxid).value);            
                        
            if(PriceAmount >= PriceFromAmount && PriceAmount <= PriceToAmount)
            {
                return true;
            }
            else
            {
                alert('You must enter an amount within the specified price range!');
                document.getElementById(txtboxid).focus();
                return false;
            }
        }      
   }  
}


//function for Email Member Modal Pop up for view profile and search seller
function okClickForSellerEmail()
       {
       
       if(document.getElementById('txtMessage').value == '')  
            {
                alert("Please enter a message.");
                this._popup.hide();           
           	    // calling a method for open the popup again
		        showConfirm(_source,'email');           
            }
            else
            {
                if(_source=="lnkSendMessage")
                    __doPostBack(this._source,''); 
                else
                    __doPostBack(this._source.id.replace(/_/g,'$'), '');
                    
               document.body.style.overflow = 'auto';       
               //  clear the event source
               this._source = null;
               this._popup = null;
           }
       }
 
 function CheckValidEmailForModalPop(id)
{   
    
			var ErrorMsg="Please Enter a Valid Email";
			EmailPattern = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+$/;
			if(!EmailPattern.test(document.getElementById(id.id).value))
			{
				alert(ErrorMsg);
				
				return false;
			}
			
}      
       
//function for forward to friend Modal Pop up for view profile and search seller
function okClickForForwardToFriend()
       {
            var bool=false;
            if(document.getElementById("txtFirstName").value=="")
            {   
                alert("Enter Your name");

                bool=false;
            }
            else
            {
                bool=true;
            }
            if (bool)
            {
                if(document.getElementById("txtYourEmailId").value=="")
                {   
                    alert("Enter Your Email");
                    
                    bool=false;
                }
                else if(document.getElementById("txtYourEmailId").value!="")
                {
                    var tEmail=CheckValidEmailForModalPop(document.getElementById("txtYourEmailId"));
                    if(tEmail==false)
                    bool=false;
                    else
                    bool=true;
                }
            }  
            if (bool)
            {
                if(document.getElementById("txtFriendName").value=="")
                {   
                    alert("Enter your friend name");
                   
                    bool=false;
                }
                 else
                {
                    bool=true;
                }
            }
            if (bool)
            {
                if(document.getElementById("txtFriendEmail").value=="")
                {   
                    alert("Enter Your Friend's Email");
                   
                    bool=false;
                }
                else if(document.getElementById("txtFriendEmail").value!="")
                {
                    var tEmail=CheckValidEmailForModalPop(document.getElementById("txtFriendEmail"));
                    if(tEmail==false)
                    bool=false;
                    else
                    bool=true;
                }  
            }
            if (bool)
            {
                if(document.getElementById("txtCaptcha").value=="")
                {   
                    alert("Enter Text in Image");
                   
                    bool=false;
                }
                else if(document.getElementById("txtCaptcha").value!="")
                {
                    var SessionValue=document.getElementById("hdCaptcha").value
                    if(document.getElementById("txtCaptcha").value.toLowerCase()==SessionValue.toLowerCase())
                        bool=true;
                    else
                    {
                        alert("Please Enter Correct Image Text");
                        bool=false;
                    }
                }  
            }
            if(!bool)
            {
                this._popup.hide();           
           	    // calling a method for open the popup again
		        showConfirm(_source,'Forward');           
            }
            else
            {
                if(_source=="lnkSendMessage")
                    __doPostBack(this._source,''); 
                else
                    __doPostBack(this._source.id.replace(/_/g,'$'), '');
                    
               document.body.style.overflow = 'auto';       
               //  clear the event source
               this._source = null;
               this._popup = null;
           }
       }     
       
       
       
//function for Email Member Modal Pop up for view profile and search seller
function okClickForReportConcernEmail()
       {
       
       if(document.getElementById('txtReportAConcernMessage').value == '')  
            {
                alert("Please enter a message.");
                this._popup.hide();           
           	    // calling a method for open the popup again
		        showConfirm(_source,'ReportAConcern');           
            }
            else
            {
                if(_source=="lnkReportConcern")
                    __doPostBack(this._source,''); 
                else
                    __doPostBack(this._source.id.replace(/_/g,'$'), '');
                    
               document.body.style.overflow = 'auto';       
               //  clear the event source
               this._source = null;
               this._popup = null;
           }
       }
    
    
    //function for Email Member Modal Pop up for view profile and search seller
    function okClickForMakeAnOffer()
       {
       
       if(document.getElementById('txtamount').value == '')  
            {
                 alert('Enter Amount');
                this._popup.hide();           
           	    // calling a method for open the popup again
		        showConfirm(_source,'MakeOffer');           
            }
            else
            {
                if(_source=="lnkMakeOffer")
                    __doPostBack(this._source,''); 
                else
                    __doPostBack(this._source.id.replace(/_/g,'$'), '');
                    
               document.body.style.overflow = 'auto';       
               //  clear the event source
               this._source = null;
               this._popup = null;
           }
       }

 function onClickShowInterestOfferMeVehicleSend()
{     
    var flag="0";      
    if(document.getElementById('ddMyVehiclesForShowInterest').value == 0)  
    {
        alert('You must choose a vehicle from your inventory.'); 
        flag="1";
        document.body.style.overflow = 'auto';                     
   	    // Hide the popup
   	    $find("ShowInterestOfferVehicle").hide();           
    	if(document.getElementById('HomeFlash') != null)
   	    {
       		document.getElementById('HomeFlash').style.display = 'block';

   	    }           
        // calling a method for open the popup again
        $find("ShowInterestOfferVehicle").show();                      
    }   
    else if(document.getElementById('txtamountForShowInterest').value == '')   
    {
        alert('You must enter an amount.'); 
        flag="1";
        document.body.style.overflow = 'auto';             
   	    // Hide the popup
   	    $find("ShowInterestOfferVehicle").hide();        
   	    if(document.getElementById('HomeFlash') != null)
   	    {
       		document.getElementById('HomeFlash').style.display = 'block';

   	    }
   	
        // calling a method for open the popup again
        $find("ShowInterestOfferVehicle").show();                                             
    }
     else
    {
        if(document.getElementById('hdPriceFrom').value!=null)
        {
            var PriceFrom=parseInt(document.getElementById('hdPriceFrom').value);
            var PriceTo=parseInt(document.getElementById('hdPriceTo').value);
            var txtboxAmount=parseInt(document.getElementById('txtamountForShowInterest').value);
            if(txtboxAmount<PriceFrom || txtboxAmount>PriceTo)
            {
                alert('Enter amount within price range.'); 
                flag="1";
                document.body.style.overflow = 'auto';             
   	            // Hide the popup
   	            $find("ShowInterestOfferVehicle").hide();           
   	            if(document.getElementById('HomeFlash') != null)
   	            {
       		        document.getElementById('HomeFlash').style.display = 'block';

   	            }
           	
                // calling a method for open the popup again
                $find("ShowInterestOfferVehicle").show();        
             }
        }
    }
    if(flag=="0")
    {               
       $find("ShowInterestOfferVehicle").hide();  //  find the confirm ModalPopup and hide it 
       if(document.getElementById('HomeFlash') != null)
       {
           document.getElementById('HomeFlash').style.display = 'block';

       }            
          
            __doPostBack('ShowInterestOffer','');               
               
       document.body.style.overflow = 'auto';
       if(document.getElementById('HomeFlash') != null)
       {
           document.getElementById('HomeFlash').style.display = 'block';

       }
       //  clear the event source
       this._source = null;
       
   }
}
 function ShowInterestcancelClick()
{          
    document.body.style.overflow = 'auto';         

    // Hide the popup
    this.$find("ShowInterestOfferVehicle").hide();

    if(document.getElementById('HomeFlash') != null)
    {
        document.getElementById('HomeFlash').style.display = 'block';

    }
    //  clear the event source
    this._source = null;
    if(document.getElementById("Player") != null)
    {		
        document.getElementById("Player").style.display="block";       
    }
}
