// this function is use to add favirite listing
function addFavoriteToData(data,type,div1,div2,div3,dataId,analyticText)
{ 
	if(data=="")
{
	var parameter="?type="+type;
}
else
{
	var parameter="?id="+data+"&type="+type;
}
    
new Ajax.Request('/listing/addToFavorite'+parameter,
{ 
 method: 'get',
  
 onSuccess: function(transport) {
 	var valu=transport.responseText;
 document.getElementById(dataId).value=valu;
 // check trackAnalytics Text for save search of srp.
 if(analyticText) {
 trackAnalytics(analyticText);
 }
 },
 onFailure: function() { 
 },       
 onLoading: function(){
 	//document.getElementById(div3).style.display='block';
 }
}
);
if(document.getElementById(div3)){
	document.getElementById(div3).style.display='block';
  document.getElementById(div3).innerHTML="Saved to My Zamanzar";
  fadetext(255, div3, 2000);
}


if(div1!="")
  {
  	toggelDivOnFavirate(div1,div2);
  }

}

// this function is use to add favirite listing
function removeFavoriteToData(data,div1,div2,div3,div4)
{
  	new Ajax.Request('/listing/RemoveFavoriteToData?id='+data, 
    { 
     method: 'get',
      
     onSuccess: function(transport) {
     document.getElementById(div3).style.display='none';   
     },
     onFailure: function() { 
     },       
     onLoading: function(){
     document.getElementById(div3).style.display='block';
     }
    }
    );
if(document.getElementById(data)!=null)
{
  document.getElementById(data).style.display='none';
  }
  else
  {
  	toggelDivOnFavirate(div1,div2);
  }
}

 // this function is use to remove saved listing and searches 
function removeFavoriteToDataFromShow(data,div1,div2,div3)  
{
  new Ajax.Request('/listing/RemoveFavoriteToData?id='+data, 
    { 
     method: 'get',
      
     onSuccess: function(transport) {         
     },
     onFailure: function() { 
     },       
     onLoading: function(){         
     }
    }
    );
    if(document.getElementById(div3)){
  document.getElementById(div3).style.display='block';
  document.getElementById(div3).innerHTML="Removed from My Zamanzar";
  fadetext(255, div3, 2000);
}    
  if(div1!="")
  {
    toggelDivOnFavirate(div2,div1);
  }    
}	

function toggelDivOnFavirate(div1,div2)
{
  document.getElementById(div1).style.display='none';
  document.getElementById(div2).style.display='block';
}
//success callback in register user
function registerSuccess(request,registerUserFeedback,resetPasswordLink)
{   
  if(request.responseText=='success')
  {
     document.getElementById('registerUserFeedback').style.display='none';
     var sURL = unescape(window.location.href);
     sURL=sURL+'?status=register';
     window.location.href = sURL;
  }
  else
  {
    document.getElementById('registerUserFeedback').style.display='block';
    document.getElementById('resetPasswordLink').style.display='block';
  }
}  

//success callback in login user in myzamanzar and home page.
function loginSuccess(request,analyticText)
{ 
  if(request.responseText=='success')
  {     
    trackAnalytics(analyticText);
    document.getElementById('loginButton').disabled=true 
  	document.getElementById('loginUserFeedback').style.display='none';
  	var sURL = unescape(window.location.href);
  	window.location.href = sURL;
  }
  else
  {  	
  	document.getElementById('loginUserFeedback').style.display='block';
  	document.getElementById('loginUserFeedback').innerHTML=request.responseText;
  }
}  
// Success call back in all login popup in srp/ldp.
function loginPopUpSuccess(request,analyticText)
{
  if(request.responseText=='success')
  {     
    analyticText = document.getElementById('analyticsEventText').value   //passed hidden attribute value to "analyticsText" Parameter, used in trackAnalytics.
    trackAnalytics(analyticText);
    document.getElementById('loginUserFeedback').style.display='none';
    var sURL = unescape(window.location.href);
    window.location.href = sURL;
  }
  else
  {   
    document.getElementById('loginUserFeedback').style.display='block';
    document.getElementById('loginUserFeedback').innerHTML=request.responseText;
  }
}

//This function will be used to call login action in srp and ldp page
function loginAction(loginEmail,loginPassword,rememberMe,loginUserFeedback,analyticsText)
{
  document.getElementById('analyticsEventText').value=analyticsText; // analytics event text passed in hidden attribute, used in logonPopUpSuccess call back.
  var parameter="?loginEmail="+loginEmail+"&loginPassword="+loginPassword+"&rememberMe="+rememberMe+"&listingId="+listingId+"&type="+listinType;   
	new Ajax.Request('/user/login'+parameter,
	{ 
	 method: 'post',
	 onLoading: Element.show('loginUserIndicator'),	 
	 
	 onSuccess: loginPopUpSuccess,
	      	 
	 oncomplete: Element.hide('loginUserIndicator')
	 }
	);
}

function removeConfirm(id)
{
  alert(document.getElementById(id));
  document.getElementById(id).style.display=block;
  
}
   