var request6;
var request61;
var request7;
var request71;
var request8;
var request9;
var request10;
var request101;
var secondss=0;
var changeMessageTimer;




//alert(clearsec);

var request11;
var from=1;
var to=1;
var froms=1;
var browser;
var version;




function isDigit(event)
{
var charCode = (event.which) ? event.which : event.keyCode;

//alert(charCode);

if(!(charCode > 47 && charCode < 58) && (charCode!=46) && (charCode!=8) &&  (charCode!=37) && (charCode!=39) )
return false;
else
return true;
}

function initialreserve()
{
reservebuttonload();

loadimageonload();
}

function initial()
{
	
		//proderef();
   initialbuttonload();
 
  loadimageonload();
 // loadbuyimageonload();
  
// alert("hiiiiii");	  
	//	if (navigator.appName=="Netscape"&&parseFloat(navigator.appVersion)>=4.7)
//alert("You are using Netscape 4.7+")	

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 sec()
{
	 secondss++;
	 if(secondss > 7)
	 {
		  if(document.getElementById('bidassist'))
	          closepopup('bidassist');
		secondss=0;
	 }
	 else
	  window.setTimeout(sec,1000); 
}
			
function proderef()
{
    count_placed_bids(); 
	ref_this();
	bidhistory();
	
	//alert(changeMessageTimer);
   
	window.setTimeout(proderef,1000);
	//alert(changeMessageTimer);
}
function initbids()
{
 seatbidhistory();
 window.setTimeout(initbids,1000);	
 
}

function count_placed_bids()
{
	
	  request12=makeObject()
	  request12.open('get', 'placed_bid_count.php?auctionid='+document.frm.img.value);
	  request12.onreadystatechange =placed_bids;
	  request12.send('');

}


function placed_bids()
{
	
	  if(request12.readyState == 4)
       {    
		  
            answer=request12.responseText;
			
		//alert(answer);	
		if(document.frm.buynw.value != 0)
		{
		
			document.getElementById('placebids').innerHTML=answer+'.00';
		}
			var saving=document.frm.bidCost.value-Number(answer);
			//saving=Math.round(saving*10)/100;
					   
					//alert(saving);
					   var savings=saving;
			if(saving>=0)
			{		   
					   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';
						   }
					   }
					   
				}
			else
			{
					saving=0;	
			}	
					
					
					//alert(saving);
					//return(saving);
					if(document.getElementById('bidamount'))
					{
					
					document.getElementById('bidamount').innerHTML=saving;  
					}
					if(document.getElementById('amount'))
					{
					var shippingcost=document.frm.shippingcost.value;
					
					var totcostss=parseFloat(saving)+Number(shippingcost);
					document.getElementById('amount').value=totcostss;  
					}
			
			}
		   

}






function bidsubmit()
{
    	sec();
 
     document.getElementById('bidassist').style.visibility="visible";
   if(document.frm.bidsfrom.value!="")
   {
    
      request11=makeObject()
	  request11.open('get', 'checkminbids.php?auctionid='+document.frm.img.value+'&bidsfrom='+document.frm.bidsfrom.value);
	  request11.onreadystatechange = checkminbids;
	  request11.send('');
	  
   }

    else
	{
	 
	 if(browser=="mozilla")
	   document.getElementById('bidassist').innerHTML='<div style="position:absolute;left:0px height:55px; width:175;right:500px"> <div id="term1" class="popup_detail">Bid from field should not left empty  <a href=javascript:closepopup(bidassist); class="gray_Text" style="text-decoration:none"> <br> close </br> </a> </div>';
	 
	  if(browser=="ie")
	  { 
	   document.getElementById('bidassist').innerHTML='<div style="position:absolute;left:0px height:75px; width:175; right:875px"> <div id="term1" class="popup_detail">Bid from field should not left empty  <a href=javascript:closepopup(bidassist); class="gray_Text" style="text-decoration:none"> <br> close </br> </a> </div>';  
	  } 
	//  from=0;
	
	}
}
	
	
function closepopup(bidassist)
{
    document.getElementById('bidassist').style.visibility="hidden";
	document.frm.submit();
}	
	
	
	
	function checkminbids()
	{
		  var to=1;
	    if(request11.readyState == 4)
        {    
		  
           answer=request11.responseText;
		// alert(answer);
		   x="Min bids should more than current auction price"; 
		     
			 if(answer==1) 
			 {
				   
				   to=0;
				    if(browser=="mozilla")
			         document.getElementById('bidassist').innerHTML='<div style="position:absolute;left:0px height:55px; width:175;right:800px"> <div id="term1" class="popup_detail">'+x+'<a href=javascript:closepopup(bidassist); class="gray_Text" style="text-decoration:none"><br> close </br> </a> </div>';
			        
					if(browser=="ie")     
			           document.getElementById('bidassist').innerHTML='<div style="position:absolute;left:0px height:75px; width:175;right:875px"> <div id="term1" class="popup_detail">'+x+'<a href=javascript:closepopup(bidassist); class="gray_Text" style="text-decoration:none"><br> close </br> </a> </div>';
			 			  
		      
			 }
			 
			 else
			 {
				      if(document.frm.bidsto.value=="")
                      {
	                    to=0;
	    
		                if(browser=="mozilla")
	                      document.getElementById('bidassist').innerHTML='<div style="position:absolute;left:0px height:55px;                          width:175;right:800px"> <div id="term1" class="popup_detail">Bid to field should not left empty<a                  href=javascript:closepopup(bidassist); class="gray_Text" style="text-decoration:none"><br> close </br> </a> </div>';
		 
		                if(browser=="ie")  
		 document.getElementById('bidassist').innerHTML='<div style="position:absolute;left:0px height:75px; width:175; right:875px"> <div id="term1" class="popup_detail">Bid to field should not left empty<a href=javascript:closepopup(bidassist); class="gray_Text" style="text-decoration:none"><br> close </br> </a> </div>';
	                 }  
	                  else
	                 {
	   	                    						 
	                     if(parseFloat(document.frm.bidsto.value) <= parseFloat(document.frm.bidsfrom.value))
		                 { 
		                    to=0;
				            if(browser=="mozilla")
		        document.getElementById('bidassist').innerHTML='<div style="position:absolute;left:0px height:55px; width:175;right:800px"> <div id="term1" class="popup_detail">Bid to field should greater than bid from field<a href=javascript:closepopup(bidassist); class="gray_Text" style="text-decoration:none"><br> close </br> </a> </div>';
				  
				  if(browser=="ie") 
				     document.getElementById('bidassist').innerHTML='<div style="position:absolute;left:0px height:75px; width:175;right:875px"> <div id="term1" class="popup_detail">Bid to field should greater than bid from field<a href=javascript:closepopup(bidassist); class="gray_Text" style="text-decoration:none"><br> close </br> </a> </div>';
		                }		
	                }			
		          
	             } 
	  
			 
			 if(to==1)
	      {
	  
	  
	  
	  
	    
	  if(parseInt(document.frm.noofbids.value)>=2)
	 {
		
	    if(totalbids<document.frm.noofbids.value)
		{
		 if(browser=="mozilla")
		        document.getElementById('bidassist').innerHTML='<div style="position:absolute;left:0px height:55px; width:175;right:800px"> <div id="term1" class="popup_detail">Not Enough bids<a href=javascript:closepopup(bidassist); class="gray_Text" style="text-decoration:none"> <br> close </br> </a> </div>'; 
		
		if(browser=="ie") 	
				 document.getElementById('bidassist').innerHTML='<div style="position:absolute;left:0px height:75px; width:175;right:875px"> <div id="term1" class="popup_detail">Not Enough bids<a href=javascript:closepopup(bidassist); class="gray_Text" style="text-decoration:none"> <br> close </br> </a> </div>'; 
				
		}
		  else
		  {	 
		  
		  
	  request12=makeObject()
	  request12.open('get', 'checkminbids.php?auctionid='+document.frm.img.value+'&bidsfrom='+document.frm.bidsfrom.value+'&bidsto='+document.frm.bidsto.value+'&noofbids='+document.frm.noofbids.value);
	  request12.onreadystatechange = updatebidassist;
      request12.send('');
	       }
	     }
	 
	  else
	  { 
	    if(browser=="mozilla")
	       document.getElementById('bidassist').innerHTML='<div style="position:absolute;left:0px height:55px; width:175;right:750px"> <div id="term1" class="popup_detail">Min 2 bids<a href=javascript:closepopup(bidassist); class="gray_Text" style="text-decoration:none"><br> close </br> </a> </div>';
		
		if(browser=="ie")    
		    document.getElementById('bidassist').innerHTML='<div style="position:absolute;left:0px height:140px; width:175;right:825px"> <div id="term1" class="popup_detail">Min 2 bids<a href=javascript:closepopup(bidassist); class="gray_Text" style="text-decoration:none"><br> close </br> </a> </div>';
	 }		
   }
			 
			
		}
		
		 
		
	}
	
	function updatebidassist()
	{
	  if(froms!=0)
	  if(browser=="mozilla")
	    document.getElementById('bidassist').innerHTML='<div style="position:absolute;left:0px height:55px; width:175;right:800px"> <div id="term1" class="popup_detail">Bid assist submited successfully<a href=javascript:closepopup(bidassist); class="gray_Text" style="text-decoration:none" ><br> close </br> </a> </div>';
	 
	 if(browser=="ie")	
		 document.getElementById('bidassist').innerHTML='<div style="position:absolute;absolute;left:0px height:75px; width:175;right:875px"> <div id="term1" class="popup_detail">Bid assist submited successfully<a href=javascript:closepopup(bidassist); class="gray_Text" style="text-decoration:none" ><br> close </br> </a> </div>';
	}


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 loadimageonload()
{  
            var flag=1;
            
			request10=makeObject();
			
		 //alert("hiiiii");
			//alert(document.getElementById('uname').value);			
			if(document.getElementById('uname').value=="")
			{
		      if(document.getElementById('addwatchlist')){		
				document.getElementById('addwatchlist').innerHTML='<a  href=mydeal.php? style=text-decoration:none;color:#FFFFFF;font:bold>  Add auction to watchlist </a>';
			  }
			}
			   
			 else
			 {
			    request10.open('get', 'addwatchlist.php?auctionid='+document.getElementById('img').value+'&check='+flag);
			    request10.onreadystatechange=notadded;
			    request10.send('');
			 }
			
			request6=makeObject();	
 			request6.open('get', 'loadimage.php?auctionid='+document.getElementById('img').value+'&imgname=Image1');
            request6.onreadystatechange = loadimage;
           	request6.send('');
}			

function loadimage()
{
    if(request6.readyState == 4)
   {
     
     var answer=request6.responseText;
	
	 <!--document.getElementById('initialimage').innerHTML='<img src=admin/up_images/'+answer+'border=0>';-->
	  document.getElementById('initialimage').innerHTML='<img src="admin/up_images/'+answer+'" border=0>';
	
	 	
   }
 }  
 
 function loadbuyimageonload()
{  

            var flag=1;
            
			request101=makeObject();
			
		//alert(document.getElementById('uname').value);			
			
			/*if(document.getElementById('uname').value=="")
			{
				document.getElementById('addwatchlist').innerHTML='<a  href=mydeal.php? style=text-decoration:none;color:#FFFFFF;font:bold>  Add auction to watchlist </a>';
			}
			   
			 else
			 {
			    request101.open('get', 'addwatchlist.php?buyid='+document.getElementById('img').value+'&check='+flag);
			    request101.onreadystatechange=notadded;
			    request101.send('');
			 }*/
			
			request61=makeObject();	
 			request61.open('get', 'loadbuyitimage.php?buyid='+document.getElementById('img').value+'&imgname=Image1');
            request61.onreadystatechange = loadbuyitimage;
           	request61.send('');
}			

function loadbuyitimage()
{

	if(request61.readyState == 4)
   {
	  // alert("hiiiiiiiiii");
     
     var answer=request61.responseText;
	
	 <!--document.getElementById('initialimage').innerHTML='<img src=admin/up_images/'+answer+'border=0>';-->
	 if(document.getElementById('initialbuyimage'))
	 {
	 document.getElementById('initialbuyimage').innerHTML='<img src="admin/up_images/'+answer+'" border=0>';
	 }
	 	
   }
 }  
 
 function notadded()
 {
	 if(request10.readyState == 4)
     {
        var answer=request10.responseText;
	
	    if(answer==1)
		{
		   if(document.getElementById('addwatchlist'))
		   {
		   document.getElementById('addwatchlist').innerHTML='<a href=javascript:addwatchlist('+document.frm.img.value+')   style=text-decoration:none;color:#FFFFFF;font:bold> Add auction to watchlist </a>';
		   }
		}
		  else
		  {
		   if(document.getElementById('addwatchlist'))	  
		   document.getElementById('addwatchlist').innerHTML='Added to watchlist';
		  }
	  }   
 }
	 

			  
 
 function changeimage(auctionid,imgname)
 {
   	        request7=makeObject();	
			request7.open('get', 'loadimage.php?auctionid='+auctionid+'&imgname='+imgname);
            request7.onreadystatechange = loadimage1;
           	request7.send('');
 }			
	 
function loadimage1()
{
    if(request7.readyState == 4)
   {
	  
     
     var answer=request7.responseText;
	
	 document.getElementById('initialimage').innerHTML='<img src="admin/up_images/'+answer+'" border=0>';
	 
	 	 
   }
 }  
 
 function changebuyimage(buyid,imgname)
 {
	 
	 
   	        request71=makeObject();	
			request71.open('get', 'loadbuyitimage.php?buyid='+buyid+'&imgname='+imgname);
            request71.onreadystatechange = loadbuyimage1;
           	request71.send('');
 }			
	 
function loadbuyimage1()
{
    if(request71.readyState == 4)
   {
	  
     var answer=request71.responseText;
	
	 document.getElementById('initialbuyimage').innerHTML='<img src="admin/up_images/'+answer+'" border=0>';
	 
	 	 
   }
 }  
 
 function bidhistory()
 {
    
       request8=makeObject();	
	  // alert(document.getElementById('img').value);
	   request8.open('get', 'bidhistory.php?auctionid='+document.getElementById('img').value);
       request8.onreadystatechange=readbidhistory;
    // alert("hi");
	   request8.send('');
	  
 }
 
 function readbidhistory()
 {
  
     if(request8.readyState == 4)
     {
	
	    var answer=request8.responseText; 
		//alert(answer);
		if(document.getElementById('bid').innerHTML!=null)
		document.getElementById('bid').innerHTML=answer;
  
	  	  
   }
}   
function seatbidhistory()
 {
    
       request8=makeObject();	
	  // alert(document.getElementById('img').value);
	   request8.open('get', 'bidhistory_reserveseat.php?auctionid='+document.getElementById('img').value);
       request8.onreadystatechange=reservebidhistory;
    // alert("hi");
	   request8.send('');
	  
 }
 
 function reservebidhistory()
 {
  
     if(request8.readyState == 4)
     {
	
	    var answer=request8.responseText; 
		//alert(answer);
		if(document.getElementById('bid').innerHTML!=null)
		document.getElementById('bid').innerHTML=answer;
  
	  	  
   }
}   
	   
function addwatchlist(auction)
{
            document.getElementById('addwatchlist').innerHTML='Added to watchlist';
	        request9=makeObject();	
			request9.open('get', 'addwatchlist.php?auctionid='+auction);
            request9.onreadystatechange = addwatch;
           	request9.send('');
}

function addwatch()
{
	 
	
}


