function init(ids, pageval, main_auc_ids, hr_delay)
{	
	setAuctionsvalues(ids, pageval, main_auc_ids, hr_delay);		
	setInterval("setAuctionsvalues('"+ids+"','"+pageval+"','"+main_auc_ids+"','"+hr_delay+"')",1000);
}
function setAuctionsvalues(index_auctions, page_name, main_auc_ids, hr_delay)
	  {		
	  	var auctions = '';
	  	 $('.timer_info').each(function(){
        		auctionId = $(this).attr('id');
        		start_time = $(this).attr('title');
				end_time = $('#'+auctionId).html();
				
				//auctions = auctions + auctionId + '#' + auctionTitle + '|';
				auctions = auctions + auctionId + '#' + start_time + '#' + end_time + '|';
			});
			
			if(page_name=="detail") { main_auc_id=auctionId; main_auction_amount = $('#item_price_'+auctionId).html(); }
			else { main_auc_id=0; main_auction_amount="0.00"; }
			
			//var auctions=index_auctions;
		  $.post("function/ajax_auction_data.php", { all_auctions: auctions , mainAucId: main_auc_id, mainAucPrice: main_auction_amount, pg_name: page_name, hr_delay: hr_delay} , function(data)
	      {
		  	//alert(data);
			if(data!=undefined) {
			//splitting the values
			 auctions=data.split('|');			 
			 for(i=0;i<=auctions.length;i++)
			 { 
				 if(auctions[i] != undefined)
				 {
					//alert(auctions[i]);
				  	auc_det=auctions[i].split("@@");
					
					if(auc_det[0]=="no_update")
					{
						var n=1;
						//alert(auc_det[2]);
						if($.trim($('#item_price_'+$.trim(auc_det[1])).html())!= $.trim(auc_det[2]))
						{ 
						  if((auc_det[1]==main_auc_ids) || (page_name=="detail"))
						  	var bgcolor="#F7F7F7";
						  else
						  	var bgcolor="#FFFFFF";
															
						  $('#item_price_'+$.trim(auc_det[1])).animate({backgroundColor:"#CC0000"},200).animate({backgroundColor: bgcolor},200);						 
						}
						$('#item_price_'+$.trim(auc_det[1])).html(auc_det[2]);	
						$('#current_aucprice').html(auc_det[2]);	
						$('#bidder_name_'+$.trim(auc_det[1])).html(auc_det[3]);
						$('#item_timer_'+$.trim(auc_det[1])).html(auc_det[4]);
						
						
						if(auc_det[5])
						{							
							$('#'+$.trim(auc_det[1])).html(auc_det[5]);
						}
												
						if(auc_det[4]=="Paused" && page_name=="detail")
						{							
							$('#auction_bidnow_bttn').html('<img src="images/paused.jpg" width="86" height="33" />');
						}
						else if(auc_det[4]=="Ended" && main_auc_ids!="" && $.trim(auc_det[1])==main_auc_ids)
						{							
							$('#mbidnow_button').html('<img src="images/complete.jpg" width="109" height="32" />');
						}
						else if(auc_det[4]=="Ended")
						{
							$('#auction_bidnow'+$.trim(auc_det[1])).html('<img src="images/complete.jpg" width="109" height="32" />');
						}
					
						if(($.trim(auc_det[6])=="yes") && auc_det[4]!="Paused")
						{							
							$('#auction_bidnow'+auc_det[1]).hide();
							$('#auction_paused'+auc_det[1]).hide();
							$('#auction_remind'+auc_det[1]).show();										
						}
						else if(auc_det[4]=="Paused")
						{							
							$('#auction_bidnow'+auc_det[1]).hide();
							$('#auction_remind'+auc_det[1]).hide();	
							$('#auction_paused'+auc_det[1]).show();					
						}
						else
						{						
							$('#auction_remind'+auc_det[1]).hide();	
							$('#auction_paused'+auc_det[1]).hide();
							$('#auction_bidnow'+auc_det[1]).show();				
						}
						
						 
					}
					else
					{
						var n=0;
						
						if(auc_det[11]=="Ended" && page_name=="detail")
						{							
							//document.location.reload();
							//document.location.href='close-auction-details.php?pid='+auc_det[0];
						}
						//alert(auc_det[3]);
					   $('#item_timer_'+$.trim(auc_det[0])).html(auc_det[3]);
					   //animate item price
					   if($.trim($('#item_price_'+$.trim(auc_det[0])).html())!= $.trim(auc_det[1]))
					   {						  
						   if((auc_det[0]==main_auc_ids) || (page_name=="detail"))
						  	var bgcolor="#F7F7F7";
						   else
						  	var bgcolor="#FFFFFF";
						  $('#item_price_'+$.trim(auc_det[0])).animate({backgroundColor:"#CC0000"},200).animate({backgroundColor: bgcolor},200);
					   }					  
					  
						$('#item_price_'+$.trim(auc_det[0])).html(auc_det[1]);
						$('#current_aucprice').html(auc_det[1]);	
						$('#bidder_name_'+$.trim(auc_det[0])).html(auc_det[2]);
						
						if(auc_det[3]=="Ended")
						{$('#bid_now_bttn_'+$.trim(auc_det[0])).html("SOLD");}
						
						if($.trim(auc_det[0])==main_auc_ids)
						{
							//alert(auc_det[0]);  
							var rrp=$('#rrp').html();
							$('#item_price2_'+$.trim(auc_det[0])).html(auc_det[1]);
							var item_price=auc_det[1];
							var total_saving=parseFloat(rrp)-parseFloat(item_price);
							$('#saving').html(total_saving.toFixed(2));	
						}
						$('#bid_history').html(auc_det[4]);
						//$('#user_bids_balance').html(auc_det[5]);
					}// end else for data not update
					
					if(page_name=="detail")
					{
						var bid_amount=$('#item_price_'+$.trim(auc_det[n])).html();	
						var vat_amount=$('#vat_amount').html();
						var ship_cost=$('#shipping').html();
						var rrp=$('#arrp').html();
						//alert("Amt: "+bid_amount+" Vat: "+vat_amount+" Shipping: "+ship_cost);
						var total_amount=eval(bid_amount)+eval(vat_amount)+eval(ship_cost);
						var total_amount_2b_paid=total_amount.toFixed(2);
						$('#total_amt_2b_paid').html(total_amount_2b_paid);
						var total_saving=eval(rrp)-total_amount_2b_paid;
						$('#saving').html(total_saving.toFixed(2));	
						//$('#user_bids_balance').html(auc_det[7]);
					}
				
				 }
			 } 
			}
          });
	  }	 

<!--             help page  -->
function hidedisplay_helpheaders(div_id) {
  for (var i = 0; i < 15; i++) {
    el = document.getElementById('help_header_' + i);	
    if (el) {
      el.style.display = 'none';
    }
  }
  $('#'+div_id).show();
} 
function display_help(hqaid)
{
	
	
	$('#help_disp').html('<div style="padding-left:40px; padding-top:20px; padding-bottom:20px; width:500px;" align="center"><img src="images/ajax-loader.gif" /><div>');
	$.post("function/ajax_help_data.php", {question_id: hqaid} , function(data)
		{			
			   if (data != '' || data != undefined || data != null) 
			   {				   
				  $('#help_disp').html(data);	
			   }
          });		
}
function checkUserName(un)
{
	$('#un').html('<img src="images/ajax_loader_small.gif" />');
	$.post("function/ajax_check_username.php", {user_name: un} , function(data)
		{			
			   //alert(data);
			   if (data != '' || data != undefined || data != null) 
			   {				   
				  $('#un').html(data);	
			   }
          });
}
function hideDive5Sec(divid)
{
	$('#'+divid).hide(); 	
	//alert(divid);
}
function place_bid(auc_id, user_id, bid_type, page_name)
{
	//alert("a:"+auc_id+",u:"+user_id+",bt:"+bid_type+",p:"+page_name);
	//document.getElementById(bid_error_"+auc_id+").innerHTML = "<img src='../images/loading.gif' style='padding: 5px 0px 0px 5px;'/>"
	if(user_id == undefined || user_id == null || user_id == '')
	{document.location.href='index.php?function=login';}
	else
	{ 
			$.post("function/ajax_bidding_process.php", {aid: auc_id, bidType: bid_type, uid:user_id, page:page_name} , function(data)
	      	{ 
				if($.trim(data)=="recharge")
				{
					$('#bid_error_'+auc_id).show();
					$('#bid_error_'+auc_id).html("Oops, You do not have enough credits!");
					setTimeout("hideDive5Sec('bid_error_"+auc_id+"')", 3000);
				}
				else if($.trim(data)=="already_winner")
				{
					$('#bid_error_'+auc_id).show();
					$('#bid_error_'+auc_id).html("You are already the highest bidder!");
					setTimeout("hideDive5Sec('bid_error_"+auc_id+"')", 3000);
				}
				else if($.trim(data)=="for_first_winner")
				{						
					$('#bid_error_'+auc_id).show();
					$('#bid_error_'+auc_id).html("Sorry, First time winners only!");
					setTimeout("hideDive5Sec('bid_error_"+auc_id+"')", 3000);
				}
				else
				{
					//alert(data);
					if(data=="Ended")
					{
						$('#item_timer_'+$.trim(auc_id)).html("Ended");
						//$('#bid_now_bttn_'+$.trim(auc_id)).html("SOLD");
					}
					else
					{						
						auctions=data.split('@@');
						if($.trim($('#item_price_'+$.trim(auctions[0])).html())!= $.trim(auctions[1]))
						{							
						 $('#item_price_'+$.trim(auctions[0])).animate({backgroundColor:"#CC0000"},200).animate({backgroundColor:"#FFFFFF"},200);
						}
						
						 $('#item_price_'+$.trim(auctions[0])).html(auctions[1]);
						 $('#bidder_name_'+$.trim(auctions[0])).html(auctions[2]);
						 $('#user_bids_balance').html(auctions[3]);
						 //$('#bid_history').html(auc_det[4]);
						 //alert(auc_det[4]);
						 // if(auctions[4]){$('#no_bid_placed_'+$.trim(auctions[0])).html(auctions[4]);}
						 // if(auctions[5]){$('#bid_placed_amt_'+$.trim(auctions[0])).html(auctions[5]);}
					}
				}
				 
			 });
	}
}

function  get_category_page(cat_id,jobs_id,limit)
{		
	
	$.post("function/ajax_auction_category_data.php", { category_id: cat_id, job_id: jobs_id, lt: limit} , function(data)
	      	{
				//alert(data);
             if(data != undefined && data!="")
				 {  										
					var data_parts=data.split("<--second_part-->");
					$('#cat_auction_'+cat_id+'_'+jobs_id).html(data_parts[0]);
					if(data_parts[1] != undefined && data_parts[1]!="")
					{
						//alert(data_parts[1]);
						init(data_parts[1],"all_category_page","");
					}
				 }				
          });
}
function browse_category_page(cat_id,jobs_id,limit,page_no)
{
	
	$.post("function/ajax_auction_category_data.php", {category_id: cat_id, job_id: jobs_id, page: page_no, lt: limit} , function(data)
	      	{						
             if(data != undefined && data!="")
				 {   
					
					var data_parts=data.split("<--second_part-->");
					$('#cat_auction_'+cat_id+'_'+jobs_id).html(data_parts[0]);
					init(data_parts[1],"all_category_page","");
					
				 }				
          });
}
function book_bidbutler(form)
{
	
	var uid=form.uid.value;
	var aid=form.aid.value;
	var no_bid=form.no_bids.value;
	var job=form.job.value;
	var bidButler_id=form.bidbuttler_id.value;	

	//alert('uid='+uid+'aid='+aid+'no_bid='+no_bid+'job='+job+'bidButler_id='+bidButler_id);
	//alert('uid'+uid+'aid'+aid+'b_from'+b_from+'b_to'+b_to+"no_bid"+no_bid+"job"+job+"bidButler_id"+bidButler_id);
	
	 if (uid == '' || uid == undefined || uid == null) 
	 {return false;} 
	 else if(aid == '' || aid == undefined || aid == null)
	 {return false;}
	
	
	$.post("function/book_bidbutlerd.php", {user_id: uid, auc_id: aid, no_bids: no_bid, action:job,bidButtlerId:bidButler_id } , function(data)
	      {
			 //alert(data);
			  butler_msg=data.split('#');	
			  			  
				if($.trim(butler_msg[0])=="error" || $.trim(butler_msg[0])=="success")
				{
					// alert(data);
					$('#bidbutller_msg').html(butler_msg[1]);
					$('#bid_butler_erro').show();
				}
				
				setTimeout("hideDive5Sec('bid_butler_erro')", 3000);	
				/*if($.trim(butler_msg[0])=="edit_success")
				{
					$('#bidbutller_msg').html(butler_msg[1]);
					$('#bid_butler_erro').show();
					bidbutlerHistory(aid,uid);
				}*/
          });
				
		form.no_bids.value="";
		
	return false;	
}
function bidbutlerHistory(aid,uid)
{	
	if(aid=="" || uid=="")
	{
		return false;	
	}
	
	$.post("function/ajax_bidbutler_overview.php", {user_id: uid, auc_id: aid} , function(data)
	{
	   if (data != '' || data != undefined || data != null) 
	   {
		  $('#autobid_overview').html(data); 	
	   }
	});							
	
}
function deleteBidButller(bidButtlerId)
{
	
		if(confirm("Are you sure you want to delete this Autobid?"))
		{
			   
		$.post("function/ajax_bidbutler_overview.php", {buttlerId: bidButtlerId, job:'delete'} , function(data)
		{			
			   if (data != '' || data != undefined || data != null) 
			   {
				  $('#bidbutlerov').html(data); 	
			   }
          });
	}
	else{return false}
	
}
function editBidButller(bidButtlerId)
{
	 
		$.post("function/ajax_bidbutler_overview.php", {buttlerId: bidButtlerId, job:'edit'} , function(data)
		{			
			   if (data != '' || data != undefined || data != null) 
			   {
				  $('#bidbutlerov').html(data); 	
			   }
          });
	
}
function my_offers(frm_o)
{	
	
	var code=frm_o.code.value;
	$.post("function/ajax_promotion_offer_process.php", {offer: code} , function(data)
		{			
			   if (data != '' || data != undefined || data != null) 
			   {
				  $('#offer_code').html(data);	
			   }
          });	
	return false;
}
function refer_friend(frm_o)
{	
	
	var uemail=frm_o.email.value;
	$('#refer_pop_msg').show();
	$('#refer_pop_msg').html('<img src="images/ajax-loader.gif" />');
	
	$.post("function/ajax_refer_friend_process.php", {user_email: uemail} , function(data)
		{			
			   if (data != '' || data != undefined || data != null) 
			   {
				  $('#refer_pop_msg').show();
				  $('#refer_pop_msg').html(data);
				  	frm_o.email.value='';
				  setTimeout("hideDive5Sec('refer_pop_msg')", 3000);	
			   }
          });	
	return false;
}

