var flipflop=1;
var storedata;
var pauseopenflag;
var counterobj = new Array();
var counterobj1 = new Array();
var expressauctioncredit = expressauctioncredit;
//var newcountdownsec = expressauctionduration;
//var newcountdownmillsec = expressauctionmicroduration;

function OnloadPage()
{
	if($.browser.msie){
        //Configuring ajax
        $.ajaxSetup({
            cache: false
        });
    }
    var auctionUpdateTime = 2;
	var counterUpdateTime = 1000;

    auctionUpdateTime = auctionUpdateTime * 1000;

    var auctions = '';
	var prices = '';
	var auctions1 = '';

    $('.auction-item').each(function(){
        var auctionId    = $(this).attr('id');
        var auctionTitle = $(this).attr('title');
		auctions = auctions + auctionId + '=' + auctionTitle + '&';
    });
	var firstimage_bold;

	var GlobalVar = 0;
    setInterval(function(){
        if(auctions){
                getStatusUrl = 'update_info.php';
            $.ajax({
                url: getStatusUrl,
                dataType: 'json',
                type: 'POST',
                timeout: 2000,
                data: auctions,
				global: false,
                success: function(data){
					storedata = data;
					$.each(data, function(i, item){
						auction_id = item.auction.id;
						auctionstatus = item.auction.status;
						if(auctionstatus==3)
						{
							if(document.getElementById('image_main_now_'+auction_id))
							{
								if(document.getElementById("bannershowprice_"+auction_id)!=null)
								{	
									document.getElementById('image_main_now_'+auction_id).src = allimagepath + "bigsold3.png";
								}
								else if(document.getElementById("proddetshowprice_"+auction_id)!=null)
								{
									document.getElementById('image_main_now_'+auction_id).src = allimagepath + "bigsold4.png";
								}
								else if(document.getElementById("proddetshowprice1_"+auction_id)!=null)
								{
									document.getElementById('image_main_now_'+auction_id).src = allimagepath + "pro1_bigsold.png";
								}
								else if(document.getElementById("proddetshowprice2_"+auction_id)!=null)
								{
									document.getElementById('image_main_now_'+auction_id).src = allimagepath + "pro2_bigsold.png";
								}
								else
								{
									document.getElementById('image_main_now_'+auction_id).src = allimagepath + "bigsold.png";
								}
								document.getElementById('image_main_now_' + auction_id).onclick="";
								document.getElementById('image_main_now_' + auction_id).onmouseover="";
								document.getElementById('image_main_now_' + auction_id).name="";							
								document.getElementById('image_main_now_' + auction_id).onmouseout="";
								document.getElementById('auction_sold_' + auction_id).style.display = "block";
							}
						}
					});
					GlobalVar = 1;
				  },
				error: function(XMLHttpRequest,textStatus, errorThrown){
				}
			});
		}
	}, auctionUpdateTime);

	$('.bid-button-Express').click(function(){
		newurl = $(this).attr('name');
		$.ajax({
            url: newurl,
            dataType: 'json',
            success: function(data){
				$.each(data, function(i, item){
				result = item.result.split("|");
				if(result[0]=="loginnotavailable")
				{
					if(confirm(sessiontimedoutmsg))
					{
						window.location.href = 'login.php';
					}
					else
					{
						return false;
					}
				}
				if(result[0]=="auctionnotavailable")
				{
					alert(cancelledbyadmin);
					return false;
				}
				if(result[0]=="unsuccess")
				{
					if(confirm(plsrechargebid))
					{
						window.location.href='buybids.php';
					}
				}
				if(result[0]=="auclimitreach")
				{
					alert(newmembersauc);
					return false;
				}
				if(result[0]=="onlyononebegi")
				{
					alert(bidonlyonenewmember);
					return false;
				}
				if(result[0]=="success")
				{
					obj = document.getElementById('bids_count');
					bidpoint = expressauctioncredit;
					objvalue = document.getElementById('bids_count').innerHTML;
					if(obj.innerHTML!='0')
					{
						obj.innerHTML = Number(objvalue) - Number(bidpoint);
					}
					
					
					document.getElementById("price_index_page_"+result[3]).innerHTML = result[1];
					document.getElementById("image_main_now_"+result[3]).style.display = "none";
					document.getElementById("image_main_buynow_"+result[3]).style.display = "block";
					document.getElementById("price_left_"+result[3]).style.backgroundImage = "none";
					document.getElementById("price_right_"+result[3]).style.backgroundImage = "none";
					document.getElementById("price_index_page_"+result[3]).style.backgroundImage = "none";
					document.getElementById("price_index_page_"+result[3]).style.color ="#3b3b3b";
					document.getElementById('express_counter_bg_'+result[3]).style.display = 'block';
					document.getElementById('express_counter_'+result[3]).style.display = 'block';
					//document.getElementById('express_counter_dot_'+result[3]).style.display = 'block';
					//document.getElementById('express_counter_micro_'+result[3]).style.display = 'block';
					//document.getElementById('countertest_'+result[3]).style.display = 'block';
					var definecounterarray = counterobj.length+1;
					//var definecounterarray1 = counterobj1.length+1;
					ChangeBiddingTimer = setTimeout("ChangePriceLabel('"+result[3]+"','"+definecounterarray+"')",(10*1000));
					SetTimerIntervalforAuction(result[3],definecounterarray);
					//ChangeBiddingTimer = 
					//counterobj1[definecounterarray] = setTimeout("SetTimerIntervalforAuctionmicro('"+result[3]+"','"+definecounterarray+"')",1);
					//SetTimerIntervalforAuctionsec(result[3],definecounterarray);
					//SetTimerIntervalforAuctionmic(result[3],definecounterarray1);
					//SetTimerIntervalforAuctionmicro(result[3],definecounterarray);
					//display(result[3],definecounterarray);
					//runcountdowntimer(result[3],definecounterarray1);
				}
			});
            },
			error: function(XMLHttpRequest,textStatus, errorThrown){
			}
        });

        return false;
    });	
}

function GetConfirmation(auctionid)
{
	window.location.href = "confirmation.php?aid="+auctionid;	
}

function ChangePriceLabel(auctionid,defarrayele)
{
	document.getElementById('express_counter_bg_'+auctionid).style.display = 'none';		
	document.getElementById('express_counter_'+auctionid).style.display = 'none';
	document.getElementById('express_counter_'+auctionid).style.color = "#FFFFFF";
	//document.getElementById('express_counter_micro_'+auctionid).style.display = 'none';
	clearInterval(counterobj[defarrayele]);
	//clearInterval(counterobj1[defarrayele]);
	document.getElementById("price_index_page_"+auctionid).innerHTML = "???";
	document.getElementById("image_main_now_"+auctionid).style.display = "block";
	document.getElementById("image_main_buynow_"+auctionid).style.display = "none";
	if(document.getElementById("bannershowprice_"+auctionid)!=null)
	{
		document.getElementById("price_left_"+auctionid).style.backgroundImage = "url('images/bigprice01_banner.png')";
		document.getElementById("price_right_"+auctionid).style.backgroundImage = "url('images/bigprice02_banner.png')";
		document.getElementById("price_index_page_"+auctionid).style.color = "#FFFFFF";
		document.getElementById("price_index_page_"+auctionid).style.backgroundImage = "url('images/bigpricegred_banner.png')";
	}
	else if(document.getElementById("proddetshowprice_"+auctionid)!=null)
	{
		document.getElementById("price_left_"+auctionid).style.backgroundImage = "url('images/bigprice01_banner2.png')";
		document.getElementById("price_right_"+auctionid).style.backgroundImage = "url('images/bigprice02_banner2.png')";
		document.getElementById("price_index_page_"+auctionid).style.color = "#FFFFFF";
		document.getElementById("price_index_page_"+auctionid).style.backgroundImage = "url('images/bigpricegred_banner.png')";
	}
	else if(document.getElementById("proddetshowprice1_"+auctionid)!=null)
	{
		document.getElementById("price_left_"+auctionid).style.backgroundImage = "url('images/pro1_priceleft.png')";
		document.getElementById("price_right_"+auctionid).style.backgroundImage = "url('images/pro1_priceright.png')";
		document.getElementById("price_index_page_"+auctionid).style.color = "#FFFFFF";
		document.getElementById("price_index_page_"+auctionid).style.backgroundImage = "url('images/bigpricegred_banner.png')";
	}
	else if(document.getElementById("proddetshowprice2_"+auctionid)!=null)
	{
		document.getElementById("price_left_"+auctionid).style.backgroundImage = "url('images/pro2_priceleft.png')";
		document.getElementById("price_right_"+auctionid).style.backgroundImage = "url('images/pro2_priceright.png')";
		document.getElementById("price_index_page_"+auctionid).style.color = "#FFFFFF";
		document.getElementById("price_index_page_"+auctionid).style.backgroundImage = "url('images/bigpricegred_banner.png')";
	}
	else
	{
		document.getElementById("price_left_"+auctionid).style.backgroundImage = "url('images/new_bigprice01.png')";
		document.getElementById("price_right_"+auctionid).style.backgroundImage = "url('images/new_bigprice02.png')";
		document.getElementById("price_index_page_"+auctionid).style.color = "#FFFFFF";
		document.getElementById("price_index_page_"+auctionid).style.backgroundImage = "url('images/new_bigpricegred.png')";
	}
	
	$.ajax({
		url: "updatestatus.php?aid="+auctionid,
		dataType: 'json',
		success: function(data){
			$.each(data, function(i, item){
					result = item.result;
				});
			}
		});
	document.getElementById('express_counter_'+auctionid).innerHTML = 10;
	//document.getElementById('express_counter_micro_'+auctionid).innerHTML = 9;
	//document.getElementById('express_counter_temp_'+auctionid).innerHTML = 29;
	//document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML = 9;
	//document.getElementById('countertest_'+auctionid).value = "09 99";
	//newcountdownsec = 9;
	//newcountdownmillsec = 99;
}

function SetTimerIntervalforAuction(auctionid,definearrayele)
{
	counterobj[definearrayele] = setInterval(function()
	{
		if(Number(document.getElementById('express_counter_'+auctionid).innerHTML)<=10)
		{
			if(Number(document.getElementById('express_counter_'+auctionid).innerHTML)<=6)
			{
				document.getElementById('express_counter_'+auctionid).style.color = "#FF0000";
			}
				document.getElementById('express_counter_'+auctionid).innerHTML = "0"+(Number(document.getElementById('express_counter_'+auctionid).innerHTML) - 1);
		}
		else
		{
			document.getElementById('express_counter_'+auctionid).innerHTML = (Number(document.getElementById('express_counter_'+auctionid).innerHTML) - 1);
		}
	},1000);
}
function SetTimerIntervalforAuctionmicro(auctionid,definearrayele)
{
	counterobj1[definearrayele] = setInterval(function()
	{	
		if(Number(document.getElementById('express_counter_micro_'+auctionid).innerHTML)=="01")
		{
			if(Number(document.getElementById('express_counter_'+auctionid).innerHTML)<=0)
			{
				ChangePriceLabel(auctionid,definearrayele);
			}
			else
			{
				if(Number(document.getElementById('express_counter_'+auctionid).innerHTML)<=10)
				{
					document.getElementById('express_counter_'+auctionid).innerHTML = "0"+(Number(document.getElementById('express_counter_'+auctionid).innerHTML) - 1);
				}
				else
				{
					document.getElementById('express_counter_'+auctionid).innerHTML = "0"+(Number(document.getElementById('express_counter_'+auctionid).innerHTML) - 1);
				}
				document.getElementById('express_counter_micro_'+auctionid).innerHTML = 99;
				clearInterval(counterobj1[definearrayele]);
				SetTimerIntervalforAuctionmicro(auctionid,definearrayele);
				//counterobj1[definearrayele] = setTimeout("SetTimerIntervalforAuctionmicro('"+auctionid+"','"+definearrayele+"')",1);
			}
			
		}
		else
		{
			if(Number(document.getElementById('express_counter_'+auctionid).innerHTML)<=10)
			{
				document.getElementById('express_counter_'+auctionid).innerHTML = "0"+(Number(document.getElementById('express_counter_'+auctionid).innerHTML));	
			}
		}
		if(Number(document.getElementById('express_counter_micro_'+auctionid).innerHTML)<=10)
		{
			document.getElementById('express_counter_micro_'+auctionid).innerHTML = "0"+(Number(document.getElementById('express_counter_micro_'+auctionid).innerHTML) - 1);
		}
		else
		{
			document.getElementById('express_counter_micro_'+auctionid).innerHTML = (Number(document.getElementById('express_counter_micro_'+auctionid).innerHTML) - 1);
		}
	},1);	
		//setTimeout("SetTimerIntervalforAuctionmicro('"+auctionid+"','"+definearrayele+"')",1);
}
function SetTimerIntervalforAuctionsec(auctionid,definearrayele)
{
	counterobj[definearrayele] = setInterval(function()
	{
	    document.getElementById('express_counter_temp_'+auctionid).innerHTML=Number(document.getElementById('express_counter_temp_'+auctionid).innerHTML)-1;
	    if (Number(document.getElementById('express_counter_temp_'+auctionid).innerHTML) <= 0)
	    {
		 	//ChangePriceLabel(auctionid,definearrayele);
		 	//return;
	    }
		if(Number(document.getElementById('express_counter_temp_'+auctionid).innerHTML)<10)
		{
			document.getElementById('express_counter_'+auctionid).innerHTML="0"+Number(document.getElementById('express_counter_temp_'+auctionid).innerHTML);
		}
	},1000);
	
	/*counterobj1[definearrayele] = setInterval(function()
	{	
		if(Number(document.getElementById('express_counter_micro_'+auctionid).innerHTML)=="01")
		{
			if(Number(document.getElementById('express_counter_'+auctionid).innerHTML)<=0)
			{
				ChangePriceLabel(auctionid,definearrayele);
			}
			else
			{
				if(Number(document.getElementById('express_counter_'+auctionid).innerHTML)<=10)
				{
					document.getElementById('express_counter_'+auctionid).innerHTML = "0"+(Number(document.getElementById('express_counter_'+auctionid).innerHTML) - 1);
				}
				else
				{
					document.getElementById('express_counter_'+auctionid).innerHTML = "0"+(Number(document.getElementById('express_counter_'+auctionid).innerHTML) - 1);
				}
				document.getElementById('express_counter_micro_'+auctionid).innerHTML = 99;
				clearInterval(counterobj1[definearrayele]);
				SetTimerIntervalforAuctionmicro(auctionid,definearrayele);
				//counterobj1[definearrayele] = setTimeout("SetTimerIntervalforAuctionmicro('"+auctionid+"','"+definearrayele+"')",1);
			}
			
		}
		else
		{
			if(Number(document.getElementById('express_counter_'+auctionid).innerHTML)<=10)
			{
				document.getElementById('express_counter_'+auctionid).innerHTML = "0"+(Number(document.getElementById('express_counter_'+auctionid).innerHTML));	
			}
		}
		if(Number(document.getElementById('express_counter_micro_'+auctionid).innerHTML)<=10)
		{
			document.getElementById('express_counter_micro_'+auctionid).innerHTML = "0"+(Number(document.getElementById('express_counter_micro_'+auctionid).innerHTML) - 1);
		}
		else
		{
			document.getElementById('express_counter_micro_'+auctionid).innerHTML = (Number(document.getElementById('express_counter_micro_'+auctionid).innerHTML) - 1);
		}
	},1);*/	
		//setTimeout("SetTimerIntervalforAuctionmicro('"+auctionid+"','"+definearrayele+"')",1);
}
function SetTimerIntervalforAuctionmic(auctionid,definearrayele)
{
	counterobj1[definearrayele] = setInterval(function()
	{
	    document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML=Number(document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML)-1;
	    if (Number(document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML) <= 0)
	    {
			if(Number(document.getElementById('express_counter_temp_'+auctionid).innerHTML)==0)
			{
				if(Number(document.getElementById('express_counter_temp_'+auctionid).innerHTML)==0 && Number(document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML)==0)
				{																													
					ChangePriceLabel(auctionid,definearrayele);
					return;
				}
				else
				{
					document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML = 9;
					document.getElementById('express_counter_micro_'+auctionid).innerHTML = 9;
				}
			}
			else
			{
				document.getElementById('express_counter_temp_'+auctionid).innerHTML=Number(document.getElementById('express_counter_temp_'+auctionid).innerHTML)-1;
				if(Number(document.getElementById('express_counter_temp_'+auctionid).innerHTML)<10)
				{
					document.getElementById('express_counter_'+auctionid).innerHTML="0"+Number(document.getElementById('express_counter_temp_'+auctionid).innerHTML);
				}
				else
				{
					document.getElementById('express_counter_'+auctionid).innerHTML=Number(document.getElementById('express_counter_temp_'+auctionid).innerHTML);	
				}
				document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML = 9;
				document.getElementById('express_counter_micro_'+auctionid).innerHTML = 9;
			}
	    }
		if(Number(document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML)<10)
		{
			document.getElementById('express_counter_micro_'+auctionid).innerHTML="0"+Number(document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML);
		}
		else
		{
			document.getElementById('express_counter_micro_'+auctionid).innerHTML=Number(document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML);
		}
	},100);	
	/*counterobj1[definearrayele] = setInterval(function()
	{	
		if(Number(document.getElementById('express_counter_micro_'+auctionid).innerHTML)=="01")
		{
			if(Number(document.getElementById('express_counter_'+auctionid).innerHTML)<=0)
			{
				ChangePriceLabel(auctionid,definearrayele);
			}
			else
			{
				if(Number(document.getElementById('express_counter_'+auctionid).innerHTML)<=10)
				{
					document.getElementById('express_counter_'+auctionid).innerHTML = "0"+(Number(document.getElementById('express_counter_'+auctionid).innerHTML) - 1);
				}
				else
				{
					document.getElementById('express_counter_'+auctionid).innerHTML = "0"+(Number(document.getElementById('express_counter_'+auctionid).innerHTML) - 1);
				}
				document.getElementById('express_counter_micro_'+auctionid).innerHTML = 99;
				clearInterval(counterobj1[definearrayele]);
				SetTimerIntervalforAuctionmicro(auctionid,definearrayele);
				//counterobj1[definearrayele] = setTimeout("SetTimerIntervalforAuctionmicro('"+auctionid+"','"+definearrayele+"')",1);
			}
			
		}
		else
		{
			if(Number(document.getElementById('express_counter_'+auctionid).innerHTML)<=10)
			{
				document.getElementById('express_counter_'+auctionid).innerHTML = "0"+(Number(document.getElementById('express_counter_'+auctionid).innerHTML));	
			}
		}
		if(Number(document.getElementById('express_counter_micro_'+auctionid).innerHTML)<=10)
		{
			document.getElementById('express_counter_micro_'+auctionid).innerHTML = "0"+(Number(document.getElementById('express_counter_micro_'+auctionid).innerHTML) - 1);
		}
		else
		{
			document.getElementById('express_counter_micro_'+auctionid).innerHTML = (Number(document.getElementById('express_counter_micro_'+auctionid).innerHTML) - 1);
		}
	},1);	*/
		//setTimeout("SetTimerIntervalforAuctionmicro('"+auctionid+"','"+definearrayele+"')",1);
}
/*function display(auctionid,defarrayele){ 
 if (newcountdownmillsec<=0){ 
    newcountdownmillsec=expressauctionmicroduration; 
    newcountdownsec-=1 
 } 
 if (newcountdownsec<=-1){ 
    newcountdownmillsec=0 
    newcountdownsec+=1 
 } 
 else 
    newcountdownmillsec-=1 
    //document.counter.d2.value=seconds+"."+milisec
	if(newcountdownmillsec<10)
	{
		document.getElementById('countertest_'+auctionid).value = "0"+newcountdownsec+" 0"+newcountdownmillsec;
	}
	else
	{
		document.getElementById('countertest_'+auctionid).value = "0"+newcountdownsec+" "+newcountdownmillsec;
	}
	//document.getElementById('express_counter_micro_'+auctionid).innerHTML =  newcountdownmillsec;
	if(newcountdownsec==0 && newcountdownmillsec==1)
	{
		ChangePriceLabel(auctionid,defarrayele);
	}
    setTimeout("display('"+ auctionid +"','"+defarrayele+"')",1) 
}*/

function runcountdowntimer(auctionid,definearrayele)
{
	counterobj1[definearrayele] = setInterval(function()
	{
		//var startmicrosec = new Date().getMilliseconds();
	    document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML=Number(document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML)-1;
	    if (Number(document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML) <= 1)
	    {
			ChangePriceLabel(auctionid,definearrayele);
			return;
	    }
		if(Number(document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML)<10)
		{
			document.getElementById('express_counter_micro_'+auctionid).innerHTML="000"+Number(document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML);
		}
		else if(Number(document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML)<100)
		{
			document.getElementById('express_counter_micro_'+auctionid).innerHTML="00"+Number(document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML);	
		}
		else
		{
			document.getElementById('express_counter_micro_'+auctionid).innerHTML="0"+Number(document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML);
		}
		//var endedmicrosec = new Date().getMilliseconds();
		//var newmillisec = (Number(endedmicrosec) - Number(startmicrosec) * 1)
	},1);	
}
/*function runcountdowntimer(auctionid,definearrayele)
{
	counterobj1[definearrayele] = setInterval(function()
	{
		//var startmicrosec = new Date().getMilliseconds();
	    document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML=Number(document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML)-1;
	    if (Number(document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML) <= 1)
	    {
			if(Number(document.getElementById('express_counter_temp_'+auctionid).innerHTML)==0)
			{
				ChangePriceLabel(auctionid,definearrayele);
				return;
			}
	    }
		if(Number(document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML)<10)
		{
			document.getElementById('express_counter_micro_'+auctionid).innerHTML="000"+Number(document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML);
		}
		else if(Number(document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML)<100)
		{
			document.getElementById('express_counter_micro_'+auctionid).innerHTML="00"+Number(document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML);	
		}
		else
		{
			document.getElementById('express_counter_micro_'+auctionid).innerHTML="0"+Number(document.getElementById('express_counter_micro_temp_'+auctionid).innerHTML);
		}
		//var endedmicrosec = new Date().getMilliseconds();
		//var newmillisec = (Number(endedmicrosec) - Number(startmicrosec) * 1)
	},1);	
}*/