
var request = makeObject();
var request1;
var request2;
var request3;
var request4;
var request5;
var request50;
var request6;
var totalbids;
var seconds=0;
var timer;
var biddersname;
var soldbuttonseconds=0;
var browser;
var version;
var bidcolor;
var tim="";


function makeObject()
{
	var x;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer")
	{
		x = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		x = new XMLHttpRequest();
	}
	return x;
}

function initialbuttonload()
{
	       
          	request4=makeObject();		
			request4.open('get', 'loadbuttons.php?');
            request4.onreadystatechange = loadbutton;
           	request4.send('');
			
			if(navigator.userAgent.indexOf("Firefox")!=-1)
{
    var versionindex=navigator.userAgent.indexOf("Firefox")+8
    if (parseInt(navigator.userAgent.charAt(versionindex))>=1)
	{
     
	   browser="mozilla";
	}   
}

if (navigator.appVersion.indexOf("MSIE")!=-1)
{
   temp=navigator.appVersion.split("MSIE")
   version=parseFloat(temp[1])
}

  if (version>=5.5) //NON IE browser will return 0
  {          
	browser="ie";
  }	


  if(navigator.userAgent.indexOf("Opera")!=-1)
  {
     var versionindex=navigator.userAgent.indexOf("Opera")+6
     if (parseInt(navigator.userAgent.charAt(versionindex))>=8)
	 {
       
		browser="opera";
     }		
  }	
	

			
}				
function loadbutton()
{
 
  var field="";
   if(request4.readyState == 4)
   {
      
     var answer=request4.responseText;
	 //alert(answer);
	  for(i=0;i<answer.length;i++)
	  {
	    if(answer.charAt(i)!="," && answer.charAt(i)!="*")
		  field=field+answer.charAt(i);
		else
		{
		  if(answer.charAt(i)!="*")
	      {
		     var auctionid=Number(field);
			 //alert(document.frm.uname.value);
			 //var nation=document.frm.country.value;			
			 if(auctionid!=0)
			 {
			 if(document.frm.uname.value!="")
			 {  
				if(document.getElementById('bidbutton'+auctionid))
			document.getElementById('bidbutton'+auctionid).innerHTML='<a href=javascript:bidthis("'+document.frm.uname.value+'",'+auctionid+')> <img src=admin/images/green_bid.gif  border=0 /></a>';
			 }
			 else
			 {
				 if(document.getElementById('bidbutton'+auctionid))					   
		    document.getElementById('bidbutton'+auctionid).innerHTML='<a href=mydeal.php> <img src=images/podbij.jpg width=88 height=35 border=0 /></a>';
			 } 
			}
		  }
		   field="";
		}  	 
	  }
	}
}	  


function ref_this(filename)		
{
	
	        //alert("hi");
	        request5=makeObject();		
	         request5.open('get', 'winner.php?file='+filename+'&auctionid='+document.getElementById('img').value);
	         request5.onreadystatechange = winner;
             request5.send('');
		
				
			    request2=makeObject();		
				request2.open('get', 'readbids4seconds.php?file='+filename+'&auctionid='+document.getElementById('img').value);
	            request2.onreadystatechange = readbids4seconds;
            	request2.send('');
						
				
			
			  
			 /* 	request3=makeObject();
				request3.open('get', 'writeseconds.php?');
				request3.onreadystatechange = writeseconds;
				request3.send('');   */
}



function winner()
{
 	
  if(request5.readyState == 4)
  {
	    var answer=request5.responseText; 
		//alert(answer);
		//alert(trim(answer));
		if(answer!=-1 && answer!=0 && answer!="")
		{
		    
			var ans=trim(answer); 
			
			document.header.action="windetail.php?auctionid="+ans;
			document.header.submit();
		}
			
			 
			 		
			 
		  
  }
}
 function trim(s)
 {
    return (s.replace(/^\s+|\s+$/g, ""));
 } 
function readbids4seconds()
{
  seconds=seconds+1;
   
  if(seconds>10)
  {
    initialbuttonload();
    //loadbutton();
	 seconds=0;
  }	 
  var k=0;
  var auctionid;
   if(request2.readyState == 4)
   {
      var field="";
	  var field1="";
	  var allow=1;
	
	  var j=-1;
	  var bids;
	  //var nation=document.frm.country.value;
	  //var price=document.frm.rate.value;
	  var answer=request2.responseText; 
	  
	    //alert(answer);	
	   for(i=0;i<answer.length;i++)
	   {
	   
	    //alert(answer.length);
	      if(answer.charAt(i)!="," && answer.charAt(i)!="*" )
		 {
		 field=field+answer.charAt(i);
		 //alert(field);
		 }
		 else
		  {
		      //alert(field);
		     if(answer.charAt(i)!="*")
			 {
		       j++;
			   //alert(answer.charAt(i));
			    if(j==0)
				{
				 		 		   
				   if(!(field.length>15))
				   {
				       totalbids=Number(field);
					   //alert(totalbids);
					  if(totalbids==-1)
					     document.getElementById('bids').innerHTML='Bids 0';
					   else	 
					     document.getElementById('bids').innerHTML='Bids '+totalbids;
				   }	   
				    	 
			    }
			    if(j==1)
				{
				   
				  if(document.frm.detail.value==1)
				  {
				  var n;
				   var increment="";
				   for(n=answer.length-2;n<answer.length;n++)
				     {
					  increment=increment+answer.charAt(n);
					 //alert(increment);
					}
				   if(increment==10)
				     	document.getElementById('clockimage').innerHTML='<img src=images/clk10.png border=0 />';
				   else if(increment==15)	 
				   		document.getElementById('clockimage').innerHTML='<img src=images/clk15.png border=0 />';
				   else		
				        document.getElementById('clockimage').innerHTML='<img src=images/clk20.png border=0 />';
						
				  //displaytargetamt(increment);		
						
				  }
				   auctionid=Number(field);
				  
				}
				  
							   			    
			    if(j==2)
				{
				      var timer="";
					   //alert(field.length);
					     /*for(i=0;i<field.length;i++)
	                     {
	                      if(i==field.length-1)
						 {
						 var endtime=field.charAt(i);
						 break;
						 alert(endtime);
						 }
						 }*/
					    //alert(field);
					      timer=field.charAt(field.length-1);
						  //alert(field);
					       field=field.replace("+","");
                           field=field.replace("$","");
						   //field=field.replace("-","");
						   //alert(field);
						//alert(field);
						if(document.getElementById('timecounter'+auctionid))
						{
						document.getElementById('timecounter'+auctionid).style.color='#7DCC00';
						document.getElementById('timecounter'+auctionid).style.backgroundColor='white';
				    	document.getElementById('timecounter'+auctionid).innerHTML=field; 
						}
						
						//alert(timer);
						tim=field;
						
				}		  
			  	  
			    
				if(j==3)
				{
				   //alert(field);
				   if(document.getElementById('saving'))
				   {
					   var saving="";
					   //var saving=Math.round(document.frm.savings.value-Number(field));
					   saving=document.frm.savings.value-Number(field);
					  //alert(saving);
					   var savings=saving;
					   saving+="";
					   //alert(saving.length+"      "+saving);
					   var savingint=saving.split('.');
					   if(savingint.length==1)
					     saving=saving+'.00';
					   else
					   {
						  if(savingint[1].length>2)
						  { 
						     //alert(savingint[1].length);
							  var tmp=""; 
							  for(z=0;z<2;z++)
							   tmp+=savingint[1].charAt(z);
							   
							   saving=savingint[0]+"."+tmp;
						  }
						   
						   else
						   {
						     if(savingint[1].length==1)
				             saving=saving+'0';
						   }
					   }
					   //style="position:absolute;left:750px;"
					   if(savings<0)
					   {
					     saving=0;
	                   document.getElementById('saving').innerHTML='&pound;'+saving;
					   }
					    else
						{
	 				     
						  document.getElementById('saving').innerHTML='&pound;'+saving;
						 
						 
						}
						   
				   }
				   
				   //alert(timer);
				   
				   if(tim=="00:00:00" || timer=="$")
				   {
 				     
					 //alert(tim);
					 if(document.getElementById('bidcost'+auctionid))
					 document.getElementById('bidcost'+auctionid).innerHTML="Ended";
				   }
				     else
					 {
					
				   //document.getElementById('bidcost'+auctionid).style.backgroundColor='white';
                    //var buffer;
				    
					//var conversion=(field*currency)+fxrate;
				     var bidcostint=field.split('.');
					 //var symbol;
					/* if(nation=="usa" || nation=="germany")
					    {
						
						field=field*currency;
					    //var buffer=field-fxrate;
						//alert(field);
						//symbol="$";
						}*/
					      //symbol="&pound;";
					
					bidcolor=field;
					//alert(bidcostint);
					if(bidcostint.length==1)
					    field=field+'.00';
					  else
					  {
				        if(bidcostint[1].length==1)
				          field=field+'0';
					  }
					  
				   
				  //alert(field);
				     
				   /*if(nation=="usa") 
					 {
					  document.getElementById('bidcost'+auctionid).innerHTML='<font style="background:#FFFFFF">$'+field+'</font>';                     }
					else if(nation=="germany")
				        {
						 document.getElementById('bidcost'+auctionid).innerHTML='<font style="background:#FFFFFF">&euro;'+field+'</font>';               }
					else*/
					//alert(field);
					if(document.getElementById('bidcost'+auctionid))
					document.getElementById('bidcost'+auctionid).innerHTML='&pound;'+field; 
					 if(document.frm.setflag.value==1)
					 {
						 if(document.getElementById('currentprice'+auctionid))
					 document.getElementById('currentprice'+auctionid).innerHTML='<font style="background:#FFFFFF">&pound;'+field+'</font>';             }
					}
				 }
  
				  
			    if(j==4)
				{
			      
				 //alert(field);
				 if(document.getElementById('biddername'+auctionid))
				 document.getElementById('biddername'+auctionid).innerHTML=field;  
				  
				}
			  	//alert(document.frm.timercount.value);
				if(j==5)
				{
				  var num="";
				
				
				       if(field!="flash")
						{
						  var x=field.split("sold");	
						
						  if(x.length==2)
						  {
					         num=Number(x[0]);
							if(document.getElementById('bidbutton'+num)) 
						   document.getElementById('bidbutton'+num).innerHTML='<img src=admin/images/green_sold.gif border=0 />';
				         						  
						  }
						  else
						      num=Number(field);
							  if(document.getElementById('timecounter'+num))
						      document.getElementById('timecounter'+num).style.color='red';
						}  

                   				  
						 
				                   
	            }
				   
				   if(j==6)
				   {
				      
				    var num=field;
					//alert(currency);
					//var fxrate=0.07;
					//var dsdsd=(bidcolor*currency)-fxrate;
					//alert(currency);
					if(document.getElementById('bidcost'+num))
					document.getElementById('bidcost'+num).innerHTML='<font style="background:#FF0000">&pound;'+bidcolor+'</font>'; 
					 
				   } 	 
						 
				   
			 
			   field="";
			  }
			  else
			  {
			     j=-1;
			     k++; 
			  }	
		    
		 }	 
			   	 
		}		 
	  
	 /* if(answer.length<16)
		{
			   totalbids=Number(answer);
			   document.getElementById('bids').innerHTML='Bids '+answer;
				   
				  
		}*/
	  
   }
}   

function readtargetamt()		
{
	
	         //alert("hi");
	         request50=makeObject();		
	         request50.open('get', 'readbids4seconds.php');
	         request50.onreadystatechange = displaytargetamt;
             request50.send('');
}

function displaytargetamt()
{
	//alert(val2);
if(request50.readyState == 4)
  {
	 
	 var answer=request50.responseText;
	  //alert(answer);
	  var no;
				   var increment1="";
				   for(no=answer.length-2;no<answer.length;no++)
				     {
					  increment1=increment1+answer.charAt(no);
					 //alert(increment1);
					}
			if(increment1==20)				 
				{
					if(document.getElementById('timecounter'+document.frm.auctionid.value))
					document.getElementById('timecounter'+document.frm.auctionid.value).innerHTML='<font style="font-size:11px;"><b>15 seconds countdown start at &pound;'+document.frm.targetamt2.value+'</b></font>';
				}
				else if(increment1==15)
				{
					if(document.getElementById('timecounter'+document.frm.auctionid.value))	
					document.getElementById('timecounter'+document.frm.auctionid.value).innerHTML='<font style="font-size:11px;"><b>10 seconds countdown start at &pound;'+document.frm.targetamt1.value+'</b></font>';

 				}
				else
				{
						//document.getElementById('clock').innerHTML='';
				}
}

}
function writeseconds()
{
 
	if(request3.readyState == 4)
    {
	    
	}
}	

function bidthis(user,bid)
{
	request4=makeObject();
	
 if(totalbids==0)
 {
	 if(browser=="mozilla")
	 if(document.getElementById('bidbutton'+bid)) 
	  document.getElementById('bidbutton'+bid).innerHTML='<div style="position:absolute; "> <div id="term1" class="popup_mozilla"> Not Enough Bids <a href=javascript:closepopup('+bid+'); class="gray_Text" style="text-decoration:none">close </a> </div>';
	  
	  if(browser=="ie")
	    if(document.getElementById('bidbutton'+bid)) 
	       document.getElementById('bidbutton'+bid).innerHTML='<div style="position:absolute;"> <div id="term1" class="popup"> Not Enough Bids <a href=javascript:closepopup('+bid+'); class="gray_Text" style="text-decoration:none">close </a> </div>';
 }
	
	
	request4.open('get', 'bidthis.php?user='+user+'&bid='+bid);
    request4.onreadystatechange = bidding;
	request4.send('');

 }



function bidding()
{
	if(request4.readyState == 4)
    {
		   var answer=request4.responseText; 
		   //alert(answer);
		   
	    
	}
	  
}	
function closepopup(auctionid)
{
   
   if(document.frm.uname.value!="")
			 {
			if(document.getElementById('bidbutton'+auctionid)) 	 
			document.getElementById('bidbutton'+auctionid).innerHTML='<a href=javascript:bidthis("'+document.frm.uname.value+'",'+auctionid+')> <img src=admin/images/bid_btn.gif width=86 height=29 border=0 /></a>';
			 }
			 else
			 {
			   if(document.getElementById('bidbutton'+auctionid)) 		   
		      document.getElementById('bidbutton'+auctionid).innerHTML='<a href=login.php> <img src=admin/images/green_login.png border=0 /></a>';
			 }
   
			
}   