// JavaScript Document
function checkUserName(un)
{
	jQuery('#un').html('<img src="images/ajax_loader_small.gif" />');
	jQuery.post("app/ajax/ajax_check_username.php", {user_name: un} , function(data)
		{			
			   //alert(data);
			   if (data != '' || data != undefined || data != null) 
			   {				   
				  jQuery('#un').html(data);	
				  jQuery('#un').attr("style",'color:#CC0000;');
			   }
          });
}

function showprice(aid,uid, lang, baseURL)
{ 
	if(uid == undefined || uid == null || uid == '')
	{document.location.href= baseURL+lang +"/login.php";return false;}
	jQuery.post(baseURL+"app/ajax/ajax_showprice.php", {usid: uid, aucid: aid,ln:lang} , function(data)
		{		
			   if (data != '' || data != undefined || data != null) 
			   {				   
				  if(data=="Closed")
				  {
					  jQuery("#msg"+jQuery.trim(aid)).show();					  
					  jQuery("#msg"+jQuery.trim(aid)).html("The auction has been sold.");
					  //jQuery('#showpeep'+jQuery.trim(aid)).html('<img src="images/sold.gif" />');
					  jQuery('#bidnow_btn'+jQuery.trim(aid)).html('<img src="images/sold.gif" />');					  
					  setTimeout("hide_div('msg"+aid+"')", 3000);
				  }
				  else if(data == "PriceRevealed")
				  {					  
					  jQuery("#pricerevealed"+jQuery.trim(aid)).show();
					  secTimer("timecountdown"+jQuery.trim(aid),"pricerevealed"+jQuery.trim(aid),'');
				  }
				  else if(data == "buyNowProcessing")
				  {					  
					  jQuery(".buyNowProcessing"+jQuery.trim(aid)).show();
					  setTimeout("hide_div_class('buyNowProcessing"+aid+"')", 300000);
				  }
				  else if(data=="recharge")
				  {
					  	jQuery("#msg"+jQuery.trim(aid)).show();					  
					  	jQuery("#msg"+jQuery.trim(aid)).html("Please recharge your account.");					  	
					  	setTimeout("hide_div('msg"+aid+"')", 3000);
						document.location="account.php?job=purcahse-credit";
				  }
				  else if(data=="error")
				  {
					  jQuery("#msg"+jQuery.trim(aid)).show();					  
					  	jQuery("#msg"+jQuery.trim(aid)).html("System Error. Please try latter.");					  	
					  	setTimeout("hide_div('msg"+aid+"')", 3000);					
				  }
				  else
				  { 
				  	
					  	var auc_data=data.split("@@");
						//alert(jQuery.trim(auc_data[0]));
						if(jQuery.trim(auc_data[0])=="buynow")
						{
							var auc_price=jQuery.trim(auc_data[1]);
							var realc=jQuery.trim(auc_data[2]);
					 		var pbonus=jQuery.trim(auc_data[3]);
							var credit_from=jQuery.trim(auc_data[4]);
							
							jQuery("#cprice"+jQuery.trim(aid)).html(auc_price);
							
							jQuery("#rcredit").html(realc);
							jQuery("#pcredit").html(pbonus);
							jQuery("#bid_meter").html(auc_data[5]);
 							
							jQuery("#credit_from"+jQuery.trim(aid)).html(credit_from);							
							jQuery("#showpeep"+jQuery.trim(aid)).hide();
							jQuery("#bidnow_btn"+jQuery.trim(aid)).hide();
							
							jQuery("#buynow"+jQuery.trim(aid)).show();
							
							jQuery("#buynowtime"+jQuery.trim(aid)).show();
							
					  		secTimer("buynowTimer"+jQuery.trim(aid),"buynowtime"+jQuery.trim(aid),jQuery.trim(aid));
							
							if(jQuery("#hotauc"+jQuery.trim(aid)).html() == "Yes")
							{
								jQuery(".hotbannerShow"+jQuery.trim(aid)).hide();
								jQuery(".hotbannerHide"+jQuery.trim(aid)).show();
							}
			
						}
				  }
			   }
          });
}


function power_showprice(aid,uid, lang, baseURL)
{ 
	if(uid == undefined || uid == null || uid == '')
	{document.location.href= baseURL+lang +"/login.php";return false;}
	jQuery.post(baseURL+"app/ajax/ajax_power_showprice.php", {usid: uid, aucid: aid,ln:lang} , function(data)
		{		
			   if (data != '' || data != undefined || data != null) 
			   {				   
				  if(data=="Closed")
				  {
					  jQuery("#msg"+jQuery.trim(aid)).show();					  
					  jQuery("#msg"+jQuery.trim(aid)).html("The auction has been sold.");
					  //jQuery('#showpeep'+jQuery.trim(aid)).html('<img src="images/sold.gif" />');
					  jQuery('#bidnow_btn'+jQuery.trim(aid)).html('<img src="images/sold.gif" />');					  
					  setTimeout("hide_div('msg"+aid+"')", 3000);
				  }
				  else if(data == "PriceRevealed")
				  {					  
					  jQuery("#pricerevealed"+jQuery.trim(aid)).show();
					  secTimer("timecountdown"+jQuery.trim(aid),"pricerevealed"+jQuery.trim(aid),'');
				  }
				  else if(data == "buyNowProcessing")
				  {					  
					  jQuery(".buyNowProcessing"+jQuery.trim(aid)).show();
					  setTimeout("hide_div_class('buyNowProcessing"+aid+"')", 300000);
				  }
				  else if(data=="recharge")
				  {
					  	jQuery("#msg"+jQuery.trim(aid)).show();					  
					  	jQuery("#msg"+jQuery.trim(aid)).html("Not enough Power Credit.");					  	
					  	setTimeout("hide_div('msg"+aid+"')", 3000);
						document.location="power_bid.php";
				  }
				  else if(data=="error")
				  {
					  jQuery("#msg"+jQuery.trim(aid)).show();					  
					  	jQuery("#msg"+jQuery.trim(aid)).html("System Error. Please try latter.");					  	
					  	setTimeout("hide_div('msg"+aid+"')", 3000);					
				  }
				  else
				  { 
					  	var auc_data=data.split("@@");
						if(jQuery.trim(auc_data[0])=="buynow")
						{
							var auc_price=jQuery.trim(auc_data[1]);
							var realc=jQuery.trim(auc_data[2]);
					 		var pbonus=jQuery.trim(auc_data[3]);
							var credit_from=jQuery.trim(auc_data[4]);
							
							jQuery("#cprice"+jQuery.trim(aid)).html(auc_price);
							
							jQuery("#rcredit").html(realc);
							jQuery("#pcredit").html(pbonus);
							
							jQuery("#credit_from"+jQuery.trim(aid)).html(credit_from);							
							jQuery("#showpeep"+jQuery.trim(aid)).hide();
							jQuery("#bidnow_btn"+jQuery.trim(aid)).hide();
							
							jQuery("#buynow"+jQuery.trim(aid)).show();
							
							jQuery("#buynowtime"+jQuery.trim(aid)).show();
							
					  		secTimer("buynowTimer"+jQuery.trim(aid),"buynowtime"+jQuery.trim(aid),jQuery.trim(aid));
							
							if(jQuery("#hotauc"+jQuery.trim(aid)).html() == "Yes")
							{
								jQuery(".hotbannerShow"+jQuery.trim(aid)).hide();
								jQuery(".hotbannerHide"+jQuery.trim(aid)).show();
							}
				
						}
				  }
			   }
          });
}


function buynow(aid,uid, lang, baseURL)
{
	
	if(uid == undefined || uid == null || uid == '')
	{document.location.href=baseURL+lang +"/login.php";return false;}
	
	if(jQuery("#credit_from"+jQuery.trim(aid)).html() == "real")
	{
		document.location.href=baseURL+'account.php?job=checkout&id='+aid+'&ln='+lang;
	}
	else
	{
		 var result =window.confirm("You must use credits to buy this product, Click Here to proceed!");
		 
		 if(result==true)
		{
			jQuery.post(baseURL+"app/ajax/ajax_buynow.php", {usid: uid, aucid: aid} , function(data)
			{			
				   if (data != '' || data != undefined || data != null) 
				   {
					   if(data=="recharge")
					  {
							jQuery("#msg"+jQuery.trim(aid)).show();					  
							jQuery("#msg"+jQuery.trim(aid)).html("Please recharge your account.");					  	
							setTimeout("hide_div('msg"+aid+"')", 3000);
							document.location="account.php?job=purcahse-credit";
					  }
					  else if(data == "buynow")
					  {
						  document.location.href='account.php?job=checkout&id='+aid+'&ln='+lang;
					  }
				   }
				   
			  });	
		}
		 
	}
	
}


function hide_div(divid)
{jQuery('#'+divid).hide();}

function hide_div_class(divid)
{jQuery('.'+divid).hide();}


function place_bid(bid_type,lang, baseURL,uid,aid)
{	
var single_bid_value=jQuery('#bidval_single'+aid).val();
var from_bid_value=jQuery('#from_bidval'+aid).val();
var to_bid_value=jQuery('#to_bidval'+aid).val();

if(uid == undefined || uid == null || uid == '')
	{  
		document.location.href=baseURL+lang +"/login.php";return false;    
    }
	else
	{
      jQuery.post("app/ajax/ajax_bidding_process.php", {auction_id: aid, sbid_val: single_bid_value, fbidval: from_bid_value, tbid_val:to_bid_value, bidt: bid_type,ln:lang} , function(data)
	      	{				
				
                //splitting the values
				auctions=data.split('@@');							
				 if(data != undefined && data != null && data != '')
				 {	
				  
				 	if(jQuery.trim(auctions[0]) == "Not allowed. Auction was Closed.")
					{
						jQuery('#place_bid').html('<img src="images/sold.gif" />');
					}
					else
					{

						if(jQuery('#page').html() == "Live Auction" )
						{
                            jQuery('#bid_error'+aid).html(auctions[0]);
							jQuery('#bid_error'+aid).show();
						}
                                                
                        else
						{								
							jQuery('#bid_error').html(auctions[0]);	
							jQuery('#bid_error').show();
							if(auctions[0] != undefined || auctions[0] != null || auctions[0] != '')
							{dis_bid(aid,uid,'',20, baseURL,lang);}					
							jQuery("#rcredit").html(auctions[1]);
							jQuery("#rcreditSL").html(auctions[1]);
							jQuery("#pcredit").html(auctions[2]);
							jQuery("#bid_meter").html(auctions[3]);
						}
                                                
					}
				 }				
          });
	}
		
	return false;	
}


function place_power_bid(bid_type,lang, baseURL,uid,aid)
{	
	var single_bid_value=jQuery('#bidval_single'+aid).val();

	if(uid == undefined || uid == null || uid == '')
	{  
		document.location.href=baseURL+lang +"/login.php";return false;    
    }
	else
	{
      jQuery.post("app/ajax/ajax_power_bidding_process.php", {auction_id: aid, sbid_val: single_bid_value, bidt: bid_type,ln:lang} , function(data)
	      	{				
                //splitting the values
				auctions=data.split('@@');							
				 if(data != undefined && data != null && data != '')
				 {	
				 	if(jQuery.trim(auctions[0]) == "Not allowed. Auction was Closed.")
					{
						jQuery('#place_bid').html('<img src="images/sold.gif" />');
					}
					else
					{
						if(jQuery('#page').html() == "Live Auction" )
						{
                            jQuery('#bid_error'+aid).html(auctions[0]);
							jQuery('#bid_error'+aid).show();
						}
                        else
						{								
							jQuery('#bid_error').html(auctions[0]);	
							jQuery('#bid_error').show();
							if(auctions[0] != undefined || auctions[0] != null || auctions[0] != '')
							{dis_bid(aid,uid,'',20, baseURL,lang);}					
							jQuery("#rcredit").html(auctions[1]);
							jQuery("#rcreditSL").html(auctions[1]);
							jQuery("#pcredit").html(auctions[2]);
							jQuery('#view_btn'+aid).show();
						}
                                                
					}
				 }				
          });
	}
		
	return false;	
}

function dis_bid_auto_refresh(aid,uid,pg_no,lmt, baseURL,lang)
{	
	dis_bid(aid,uid,pg_no,lmt, baseURL,lang);
	setInterval("dis_bid('"+aid+"','"+uid+"','"+pg_no+"','"+lmt+"','"+baseURL+"','"+lang+"')",60*1000);
}

function dis_bid(aid,uid,pg_no,lmt, baseURL,lang)
{
	jQuery('#bid_status').html('<div style="padding:40px;" align="center"><img src="images/ajax-loader.gif" /><div>');
	jQuery.post(baseURL+"app/ajax/ajax_dis_current_bid.php", {auc_id: aid, user_id: uid, page: pg_no, lt: lmt,ln:lang} , function(data)
	      	{
				if(data != undefined && data != null && data != '')
				{jQuery('#bid_status').html(data);}				
          });
}


var seconds=11;
function secTimer(id,hideDiVid,aucid)
{	
		var time = 10;
		jQuery("#"+id).html(10);
		var tim = setInterval(function(){			
			jQuery("#"+id).html(--time);
			if(time <= 0){
				clearInterval(tim);			
				jQuery('#'+hideDiVid).hide();		
				if(aucid)
				{
					jQuery("#buynow"+jQuery.trim(aucid)).hide();
					jQuery("#showpeep"+jQuery.trim(aucid)).show();
					jQuery("#bidnow_btn"+jQuery.trim(aucid)).show();										
					if(jQuery("#easy").html() == "view")
					jQuery("#cprice"+jQuery.trim(aucid)).html('????');
					else
					jQuery("#cprice"+jQuery.trim(aucid)).html('<span class="current_price_for_auction">Current Price:</span> <span class="current_pricered">??? </span>');					
					if(jQuery("#hotauc"+jQuery.trim(aucid)).html() == "Yes")
					{
						jQuery(".hotbannerHide"+jQuery.trim(aucid)).hide();
						jQuery(".hotbannerShow"+jQuery.trim(aucid)).show();												
					}					
				}
			}
		}, 1000);
}
