$(document).ready(function()
{    
		
});


function init(ids, pagename, langid)
{
	setAuctionsvalues(ids, pagename, langid);	
	refreshID=setInterval("setAuctionsvalues('"+ids+"','"+pagename+"','"+langid+"')",1000);
}
function init_lowest(ids, pagename)
{
	setAuctionsvaluesLowest(ids, pagename);	
	refreshID=setInterval("setAuctionsvaluesLowest('"+ids+"','"+pagename+"')",1000);
}

  function setAuctionsvalues(index_auctions,page_name, langid)
	  {
		  var auctions=index_auctions;
		  $.post("ajax_penny_auction_data.php", { all_auctions: auctions, pagename: page_name, lang_id2: langid } , function(data)
	      {
		    //alert(data);
           //splitting the values
			 auctions=data.split('|');
			 
			 for(i=0;i<=auctions.length;i++)
			 {
				 if(auctions[i] != undefined)
				 {
				  auc_det=auctions[i].split("#");
				 
				  if(auc_det != undefined)	
				  {
				    $('#product_time_'+auc_det[0]).html(auc_det[2]);
				  }
					
					// auction price animated
					price_value=auc_det[1];
					//alert(price_value);
					if(price_value!=undefined && price_value!=null)
					{
						price_value=price_value.replace(/&pound;/,"£");
						//alert($('#product_price_'+auc_det[0]).html()+'='+price_value);
					  if( $.trim($('#product_price_'+auc_det[0]).html())!= $.trim(price_value))
					   {					   
						 var bg_color=$('#product_price_'+auc_det[0]).parents('tr').attr('bgcolor');
						 $('#product_price_'+auc_det[0]).animate({backgroundColor:"#FF9966"},200).animate({backgroundColor:bg_color},500);	 
					   }
					}
				  
				  	$('#product_price_'+auc_det[0]).html(auc_det[1]);
					$('#bidder_name_'+auc_det[0]).html(auc_det[3]);	
					$('#penny_auc_deal_time_'+auc_det[0]).html(auc_det[5]);	
					$('#user_bid_balance').html(auc_det[9]);
					
					if(auc_det[4]<=0)
						$('#penny_auction_bid_'+auc_det[0]).html("<img src='images/SOLD.gif' style='padding-top:6px;' width='125' height='32' border='0'  />");	
					
			  }
			}  
          });
	  }	
	  
	  function setAuctionsvaluesLowest(index_auctions,page_name)
	  {
		var auctions=index_auctions;
		  
		  $.post("ajax_lowest_auction_data.php", { all_auctions: auctions } , function(data)
	      { 
		    //splitting the values
			 auctions=data.split('|');
			 
			 for(i=0;i<=auctions.length;i++)
			 {
				 if(auctions[i] != undefined)
				 {
				  auc_det=auctions[i].split("#");
					 
				  if(auc_det != undefined)	
					$('#product_time_'+auc_det[0]).html(auc_det[1]);
					  
				  if(auc_det[2]<=10)
					$('#product_time_'+auc_det[0]).css({color:"#FFD701"});
					
				  if(auc_det[2]<=0)
				  	$('#lowest_bidbut_'+auc_det[0]).html("<img src='images/SOLD.gif' alt='Sold' width='124' height='32'  border='0'  />");	
					
				 }
			 }  
          });
	  }	
	  
	function init_watchlist_auction_data(ids)
	{
		setWatchlistValues(ids);	
		refreshID=setInterval("setWatchlistValues('"+ids+"')",1000);
	}

	 function setWatchlistValues(index_auctions)
	  {
		 
		  var auctions=index_auctions;
		  $.post("ajax_auction_data.php", { all_auctions: index_auctions } , function(data)
	      {
             //splitting the values
			 auctions=data.split('|');
			 
			 for(i=0;i<=auctions.length;i++)
			 {
				 if(auctions[i] != undefined)
				 {
				  auc_det=auctions[i].split("#");
				  if(auc_det != undefined)	
				  {
				    $('#product_time_watch_'+auc_det[0]).html(auc_det[2]);
				  }
					//$('#product_time_'+auc_det[0]).html(auc_det[2]);	
					if(auc_det[4]<=10)
					
					{
						$('#product_time_watch_'+auc_det[0]).css({color:"#FFD701"});
					}
					
					// auction price animated
					price_value=auc_det[1];
					price_value=price_value.replace(/&pound;/,"£");
					//alert($('#product_price_'+auc_det[0]).html()+'='+price_value);
				  if( $.trim($('#product_price_watch_'+auc_det[0]).html())!= $.trim(price_value))
				   {					   
					  var bg_color=$('#product_price_watch_'+auc_det[0]).parents('tr').attr('bgcolor');
					  $('#product_price_watch_'+auc_det[0]).animate({backgroundColor:"#FF9966"},200).animate({backgroundColor:bg_color},500);					 
				   }
				   
				   //change the price of auction from ajax
				    $('#product_price_watch_'+auc_det[0]).html(auc_det[1]);
					$('#bidder_name_watch_'+auc_det[0]).html(auc_det[3]);		
				
				 	
					if(auc_det[2]=="Ended")
					{
						//$('#buttn_'+auc_det[0]).html('<img src="images/sold.gif" border="0" title="sold" />');			
						$('#bid_watch_'+auc_det[0]).removeClass('bid_small_white');
						$('#bid_watch_'+auc_det[0]).addClass('sold_bid_smaller');
						$('#bid_watch_'+auc_det[0]).html('Sold');
					}
					
					$('#bid_error_'+auc_det[0]).hide();	
					$('#bid_butler_erro').hide();
				 }
			 }  
          });
	  }	
	  
	  
	  function find_latest_winner()
	  {
		  $.post("latest_winner_res.php", {} , function(data)
	      {
			$('#winner_result_display').html(data);			  
		  });
		  
		}

function place_bid(auc_id,user_id,auc_type)
{
	if(user_id == undefined || user_id == null || user_id == '')
	{
		document.location.href='home.php?function=loginunibid';
	}
	else
	{
		//alert(auc_id+"::"+user_id+"::"+auc_type); return false;
		$.post("ajax_penny_auc_bidding_process.php", {a_id: auc_id, u_id: user_id, a_type: auc_type} , function(data)
	      	{
				if(data == "free_bid_used")
				{
					jAlert("You have already placed bid on this auction for today.");
					return false;
				}
				//splitting the values
				 auctions=data.split('#');
				
		  	     if(auctions != undefined && auctions != 'Recharge' && auctions != 'Winner' )
				 {					 	
					
				  // auction price animated
				  price_value=auctions[1];
				  price_value=price_value.replace(/&pound;/,"£");
				 
				  if($.trim($('#product_price_'+auctions[0]).html())!= $.trim(price_value))
				   {
					  var bg_color=$('#product_price_'+auctions[0]).parents('tr').attr('bgcolor');
					  $('#product_price_'+auctions[0]).animate({backgroundColor:"#FF9966"},200).animate({backgroundColor:bg_color},500);			 
				   }
				 
				   $('#product_price_'+auctions[0]).html(auctions[1]);					
				   $('#bidder_name_'+auctions[0]).html(auctions[2]);
				   
				   $('#product_detail_price_').html(auctions[1]);					
				   $('#product_detail_bidder').html(auctions[2]);
				   
				   $('#user_bid_balance').html(auctions[3]);
					
				 }
				 if(auctions=='Recharge')
				 {
					  jAlert('You do not have enough balance to bid.');		  
				 } 
				 if(auctions=='Winner')
				 {
					  jAlert('You are leading bidder in this auction.');
				 }
			 
          });
	}			
}
function hide_fade(aid)
{
	$('#bid_error_'+aid).hide();	
}
function hide_bidbutler_error(aid)
{
	$('#bid_butler_erro').hide();	
}

function  get_category_page(cat_id,jobs_id,limit)
{		
	
	$.post("ajax_auction_category_data.php", { category_id: cat_id, job_id: jobs_id, 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 browse_category_page(cat_id,jobs_id,limit,page_no)
{
	
	$.post("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");
					
				 }				
          });
}


<!-- for product details page-->

function init_product_details(ids, type, langid)
{
	setAuctionsvalues_product_details(ids, type, langid);
	refreshID=setInterval("setAuctionsvalues_product_details('"+ids+"','"+type+"','"+langid+"')",1000);
}


	  function setAuctionsvalues_product_details(index_auctions, auc_type, langid){
		 
		 var auctions=index_auctions;	var auction_type=auc_type;	var lang_id=langid;
		
		 if(auction_type=="penny")
		  { var page_name="ajax_penny_auction_data.php"; }
		  else if(auction_type=="lowest")
		  { var page_name="ajax_lowest_auction_data.php"; }
		  else
		  { return false;  }
		  
		 $.post(page_name, { all_auctions: auctions, type: auction_type, page: "auctiondetail", lang_id2: lang_id} , function(data)
	      {
			 
		  		auc_det=data.split('#');	
				//alert(data);
			 	if(auc_det != undefined && auction_type=="penny")	
				  {
				    $('#product_detail_price').html(auc_det[1]);
				    $('#product_detail_time_'+auc_det[0]).html(auc_det[2]);
					$('#product_detail_bidder').html(auc_det[3]);
					
					if(auc_det[4]<=0 || auc_det[2]=="Ended")
					{
						$('#product_detail_bidnow').html("<img src='images/SOLD.gif' border=0 />");
					}
					
					$('#product_mybid_history').html(auc_det[8]);
					
					$('#user_bid_balance').html(auc_det[9]);
					
				  }
				 
				  if(auc_det != undefined && auction_type=="lowest")
				  {
					$('#product_detail_time_'+auc_det[0]).html(auc_det[1]);
					
					if(auc_det[1]<=0)
					{
						$('#product_detail_bidnow').html("<img src='images/SOLD.gif' border=0 />");
					}
					//$('#product_bidder_history').html(auc_det[5]);
				  }
		
		  });
	  }	 
	  
function book_bidbutler(form, langid)
{
	var uid=form.uid.value;
	var aid=form.aid.value;
	var b_to=form.bid_to.value;
	
	if (uid == '' || uid == undefined || uid == null) 
	 {return false;} 
	else if(aid == '' || aid == undefined || aid == null)
	 {return false;}
	
	$.post("unibid_bidbutler/book_bidbutlerd.php", { user_id: uid, auc_id: aid, bid_to: b_to, lang_id2: langid} , function(data)
	      {
			jAlert(data);
          });
			
		form.bid_to.value="";
	return false;	
}

function bidbutlerHistory(aid,uid)
{
		$.post("ajax_bidbutler_overview.php", {user_id: uid, auc_id: aid} , function(data)
		{			
			   if (data != '' || data != undefined || data != null) 
			   {
				  $('#bidbutlerov').html(data); 	
			   }
          });							
	
}

/*function delete_bidbutler(bidbut_id, user_id)
{
		var response=confirm("Are You Sure to Delete Saved Bidmate?");
		if(response==true)
		{
			$.post("delete_saved_bidbutler.php", {butler_id: bidbut_id, u_id: user_id}, function(data) {
				document.location.reload();
			});
		}
		
		return false;
}
function my_offers(frm_o)
{	
	$('#offer_code').html('<div style="padding-left:40px; padding-top:20px; padding-bottom:20px; width:500px;" align="center"><img src="images/wheel.gif" width="16" height="16" /><div>');
	var code=frm_o.code.value;
	$.post("ajax_promotion_offer_process.php", {offer: code} , function(data)
		{			
			   if (data != '' || data != undefined || data != null) 
			   {
				  $('#offer_code').html(data);	
			   }
          });	
	
}
*/

//FOR FLIPPING DIVS
	function flip_divs(div1, div2)
	{
		$('#'+div2).hide();
		$('#'+div1).show();
	}
	
function hideall(divid)
{
	$('#'+divid).hide();	
}
function showall(divid)
{
	$('#'+divid).show();	
}
<!--             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();
} 
$(document).ready(function(){
     
	   $("#help_body").show("slow");
    });
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/wheel.gif" width="16" height="16" /><div>');
	$.post("ajax_help_data.php", {question_id: hqaid} , function(data)
		{			
			   if (data != '' || data != undefined || data != null) 
			   {				   
				  $('#help_disp').html(data);	
			   }
			  // $("#help_body").show("slow");
          });		
}

function add_auction_to_watchlist(aid, uid)
{
	if(aid!="" && uid!="")
	{
	blockUI_message("Processing your request. Please wait...");
	 $.post("add_to_watchlist.php", { auction_id: aid,user_id: uid} , function(data)
	      {
             setTimeout(jQuery.unblockUI, 2000);	
			 if(data=="succeed")
			 	messg="Auction Successfully Added to Watchlist.";
			else
				messg="Problem While Adding Auction to Watchlist.";
				blockUI_message(messg);
				setTimeout(jQuery.unblockUI, 4000);	
          });
	}
}

function refer_ur_friend(form, userid)
{
	var email=form.email.value;
	var userid=userid;
	var emailFormat=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z]{2,4}(\.[a-zA-Z]{2,3})?(\.[a-zA-Z]{2,3})?$/;
	//CHECK FOR USER LOGIN STATUS BEFORE REFERRING
	if(userid==undefined || userid==null || userid=="")
	{
		jAlert("You Must Login to Refer Your Friend.");
		return false;
	}
	//CHECK FOR EMAIL ADDRESS
	else if(email==undefined || email==null || email=="")
	{
		jAlert("Enter Email Address to Refer.");
		return false;
	}
	else if(!email.match(emailFormat))
	{
		jAlert("Please Enter Valid Email Address.");
		return false;
	}
	else
	{
		$.post("ajax_refer_to_friend.php", {email: email, userid: userid}, function (data)
		{
			jAlert(data);
			if(data=="Success")
			{
				jAlert("Request Done Successfully.");
			}
			else
			{
				jAlert("Error While Sending Email.");
			}
			
		});
		
	return false;
	}
}

function blockUI_message(msg)
{
	jQuery.blockUI({ message: msg, css: { 
			//border: 'none', 
			padding: '15px', 
			backgroundColor: '#000', 
			'-webkit-border-radius': '10px', 
			'-moz-border-radius': '10px', 
			opacity: '.5', 
			color: '#fff' 
		} }); 			
			
}

function load_buttn(img_id,ing_name)
{
	var image_id=img_id;
	var image_name=ing_name;	
	document.getElementById(image_id).src =image_name;
}
function flip_buttn(img_id,ing_name)
{
	var image_id=img_id;
	var image_name=ing_name;	
	document.getElementById(image_id).src =image_name;
}

