function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function trim(str)
{
    if(!str || typeof str != 'string')
        return null;

    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
var che=1;
function blinkIt(countt) {
var s = document.getElementById("Amt"+countt);
if(s!=null){
if(che%2==0){
      s.style.visibility="hidden";
}
else{
      s.style.visibility="visible";
}
che=che+1;
}
setTimeout("blinkIt("+countt+")",500);
}




var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
var running = new Array();
var refreshID;
var Timer


Timer=0;
function countdown(auctionid)
{
var auctions;
var divs;

Timer=Timer+1;

if((Timer%10=="0")||(Timer=="1")){
$.get("current.php", {
id:auctionid},
function(data){
auctions=data.split("||");
for(n=0;n<=auctions.length;n++)
{
if(auctions[n] != undefined)
{
divis=auctions[n].split("##");
$('#futu'+divis[0]).html(divis[1]);
}}
});
}
var cauctionid="auctionid";
var tauctions=auctionid.split("|");
for(i=0;i<=tauctions.length;i++)
{
if(tauctions[i] != undefined)
{
var dd=$('#futu'+tauctions[i]).text();
var paus=$('#pause'+tauctions[i]).text();
var timad=$('#timadd'+tauctions[i]).text();
timad=timad*1000
var cdd=dd-1;
$('#futu'+tauctions[i]).html(cdd);

dd=dd*1000;
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)

if(dday==0&&dhour==0&&dmin==0&&dsec==0){
$('#Bid'+tauctions[i]).html("SOLD");
//return
}
if(dhour <=9)
{
dhour = "0"+dhour;
}
if(dmin <=9)
{
dmin = "0"+dmin;
}
if(dsec <=9)
{
dsec = "0"+dsec;
}

if(dd>=3000)
{
var valll=dhour+":"+dmin+":"+dsec;
}

if((dd<3000)&&(dd>1000))
{
var valll="Going...";
}

if((dd<=1000)&&(dd>=0))
{
var valll="Gone";
}

if(dd<0)
{
var valll="Closed";
}


if(dd<timad)
{
var valll="<font color=red>"+valll+"</font>";
}
if(paus=='yes')
{
var valll="Paused";
}
$('#Bid'+tauctions[i]).html(valll);
}}
refreshID=setTimeout("countdown('"+auctionid+"')",1000);
}



function GetBid(idname,userid){
var updates;
$.get("update.php", {
id:+ idname, uid:+ userid},
 function(data){
updates=data.split("##");
$('#Amt'+idname).html(updates[0]);
$('#SAmt'+idname).html(updates[1]);
$('#Sav'+idname).html(updates[2]);
$('#Usr'+idname).html(updates[3]);
$('#His'+idname).html(updates[6]);
$('#futu'+idname).html(updates[4]);
$('#totb'+idname).html(updates[5]);
});
$('#Amt'+idname).effect("highlight", {}, 1000);
}



function GetUpdate(auctionid,userid,pagetype){
var gauctions;
var gdivis;
$.get("ex_date.php", {
id:auctionid},
function(data){
gauctions=data.split("||");
for(m=0;m<=gauctions.length;m++)
{
if(gauctions[m] != undefined)
{
gdivis=gauctions[m].split("##");
gdivis[1]=parseFloat(gdivis[1]);
$('#pause'+gdivis[0]).html(gdivis[2]);
$('#expire_m'+gdivis[0]).html(gdivis[3]);
$('#pause_m'+gdivis[0]).html(gdivis[2]);
var gtotb=$('#totb'+gdivis[0]).text();
gtotb=parseFloat(gtotb);
if(gdivis[1]!=gtotb)
{
if(gdivis[4]!=11){
GetBid(gdivis[0],userid);
}
if(gdivis[4]==11){
GetBidMystery(gdivis[0],userid,pagetype);
}
}
}}
refreshIDD=setTimeout("GetUpdate('"+auctionid+"','"+userid+"','"+pagetype+"')",1000);
});
}

function GetBidNum(idname){
$.post("getbidnum.php", {
id:+ idname},
function(data){
$('#bid_num').html(data);
setTimeout("GetBidNum("+idname+")",3000);
});
}
function GetSearch(acat,totp){
$.get("easysearch2.php", {
keywords:acat, pageno:+ totp},
 function(data){
$('#Srch').html(data);
 });
}

function bidnow(idname,biduser){
$.get("bid_now.php", {
id:+ idname, user:+biduser},
function(data){
//alert(""+data);
});
}

function GetList(alist,acat,totp){
if(alist!=2){
$.get("list_main.php", {
listtype:+ alist, catsid:+ acat, pageno:+ totp},
 function(data){
$('#List').html(data);
 });
}
if(alist==2){
$.get("list_scratch.php", {
listtype:+ alist, catsid:+ acat, pageno:+ totp},
 function(data){
$('#List').html(data);
 });
}
}

function GetSearch(acat,totp){
$.get("easysearch2.php", {
keywords:acat, pageno:+ totp},
 function(data){
$('#Srch').html(data);
 });
}

function setauto(autop) 
{
var strmin = document.autobid.minbid.value;
var strmax = document.autobid.maxbid.value;
var strno = document.autobid.bidno.value;
storeauto(strmin,strmax,strno,autop);
}

function storeauto(strmin,strmax,strno,autop){
$.get("storeauto.php", {
minb:+ strmin, maxb:+strmax, nob:+ strno, pid:+autop},
function(data){
if(data!=0){
showauto(autop);
alert("Successfully Set");
}
if(data==0){
alert("Insufficient Balance");
}
});
}

function showauto(autop){
$.get("showauto.php", {
prid:+ autop},
 function(data){
$('#Auto'+autop).html(data);
 });
}

function unsetauto(autop,autoid,rfrsh){
$.get("unsetauto.php", {
aid:+ autoid},
 function(data){
$('#Auto'+autop).html(data);

if(rfrsh=="1"){
window.location.reload();
}
 });
}
function sstime(){
$.get("stime.php", {},
 function(data){
$('#stime').html(data);
 });
setTimeout("sstime()",1000);
}




function bidnowMystery(idname,biduser){
var delay;
var chbid;
$.get("bid_now_m.php", {
id:+ idname, user:+biduser},
function(data){
chbid=trim(data);
if(chbid!='y'){
alert(""+chbid);
}
if(chbid=='y'){
$('#buy_wait'+idname).animate({"height": "show"}, { duration: 1000 });
$('#But_m'+idname).animate({"height": "hide"}, { duration: 100 });
$.get("show_buy.php", {
id:+ idname, user:+biduser},
function(data){
delay=data.split("##");
$('#Amt_m'+idname).html(delay[1]);
$('#SAmt_m'+idname).html(delay[1]);
$('#Sav_m'+idname).html(delay[2]);
countdown_buy(idname,delay[0])
});
}
});
}

function countdown_buy(auctionid,Timer)
{
Timer=Timer-1;
if(Timer<=0)
{
$('#Amt_m'+auctionid).html('??????');
$('#SAmt_m'+auctionid).html('??????');
$('#Sav_m'+auctionid).html('??????');
hide_buy(auctionid);
}
if(Timer==0)
{
$('#buy_timer'+auctionid).html(0);
}
if(Timer>0)
{
$('#buy_timer'+auctionid).html(Timer);
refreshIDD=setTimeout("countdown_buy('"+auctionid+"','"+Timer+"')",1000);
}
}


function hide_buy(idname){
$.get("unlock.php", {
id:+ idname},
function(data){
//alert(""+data);
});
$('#buy_wait'+idname).animate({"height": "toggle"}, { duration: 200 });
$('#But_m'+idname).animate({"height": "toggle"}, { duration: 100 });
}

function GetBidMystery(idname,userid,pagetype){
var updates_m;
$.get("update_m.php", {
id:+ idname, uid:userid},
function(data){
updates_m=data.split("##");
$('#totb_m'+idname).html(updates_m[0]);
$('#His_m'+idname).html(updates_m[1]);
});
}