//var basepath = "https://dev1.ebidnsave.com";
var checkbid=1;

function product_bid(pid)
{	
	url= basepath + "/ajax_p_bid.php";	
	http_product_bid(url,pid);		
}

function http_product_bid(strURL,pid) { 
	
    if(checkbid==0)	
    return false;    
    
    checkbid=0;
    
    var bid_xmlHttpReq = false;
    var bid_self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        bid_self.bid_xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        bid_self.bid_xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    bid_self.bid_xmlHttpReq.open('POST', strURL, true);
    bid_self.bid_xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    bid_self.bid_xmlHttpReq.onreadystatechange = function() {
        if (bid_self.bid_xmlHttpReq.readyState == 4) 
		{ 
		
		   checkbid=1;
		   maxbidp = "maximumbid_" + pid; 
		    if(bid_self.bid_xmlHttpReq.responseText ==1)
		   {
		   document.getElementById(maxbidp).style.display=''; 
		   document.getElementById(maxbidp).innerHTML='You are currently the highest bidder for this Auction.';
		   setTimeout("hide_max_bid(" + pid + ")",3000);
		   }
		   else if(bid_self.bid_xmlHttpReq.responseText ==2)
		   {
		   document.getElementById(maxbidp).style.display='';
		   document.getElementById(maxbidp).innerHTML='You do not have enough Credits to bid on this Auction.';
		   setTimeout("hide_max_bid(" + pid + ")",3000);
		   }
		   else if(bid_self.bid_xmlHttpReq.responseText ==3)
		   {
		   document.getElementById(maxbidp).style.display='';
		   document.getElementById(maxbidp).innerHTML='You do not have enough Credits to Register.';
		   setTimeout("hide_max_bid(" + pid + ")",3000);
		   }
		   else if(bid_self.bid_xmlHttpReq.responseText ==4)
		   {
		   document.getElementById(maxbidp).style.display='';
		   document.getElementById(maxbidp).innerHTML='You have registered already for this Auction.';
		   setTimeout("hide_max_bid(" + pid + ")",3000);
		   }
		   else if(bid_self.bid_xmlHttpReq.responseText ==5)
		   {
		   document.getElementById(maxbidp).style.display=''; 
		   document.getElementById(maxbidp).innerHTML='You have bid already in Round 1 for this Auction.';
		   setTimeout("hide_max_bid(" + pid + ")",3000);
		   }
		    else if(bid_self.bid_xmlHttpReq.responseText ==6)
		   {
		   document.getElementById(maxbidp).style.display='';
		   document.getElementById(maxbidp).innerHTML='You have not registered for this Auction.';
		   setTimeout("hide_max_bid(" + pid + ")",3000);
		   }
		   else if(bid_self.bid_xmlHttpReq.responseText ==7)
		   {
			  jQuery.get('round1_bid.php', function(data) {jQuery.facebox(data)});			 
			  setTimeout("jQuery(document).trigger('close.facebox')",5000);		  
		   }
		   else if(bid_self.bid_xmlHttpReq.responseText ==8)
		   {
			  jQuery.get('thank_register.php', function(data) {jQuery.facebox(data)});			 
			  setTimeout("jQuery(document).trigger('close.facebox')",5000);		  
		   }
		   else if(bid_self.bid_xmlHttpReq.responseText ==9)
		   {
		   document.getElementById(maxbidp).style.display=''; 
		   document.getElementById(maxbidp).innerHTML='This Auction is open for beginners only.';
		   setTimeout("hide_max_bid(" + pid + ")",3000);
		   }
		   else if(bid_self.bid_xmlHttpReq.responseText ==10)
		   {
		   popupBox('registration_bidpak',pid);
		   }
		   else if(bid_self.bid_xmlHttpReq.responseText ==11)
		   {
			 window.parent.parent_waiting_lightbx(pid);	  
		   }
		   
        }
    }
    bid_self.bid_xmlHttpReq.send(getbidstring(pid));
}

function getbidstring(pid)
{
	qstr = 'pid=' + pid + '&bid=bid' ;  // NOTE: no '?' before querystring  
	return qstr;
}


function hide_max_bid(pid)
{
	var maxbidp = "maximumbid_" + pid;
	 document.getElementById(maxbidp).style.display='none';
}

function bid_ended(pid)
{	
	url= basepath + "/ajax_bid_ended.php";	
	http_bid_ended(url,pid);	 
}


function http_bid_ended(strURL,pid) {
    var xmlHttpReq5 = false;
    var self5 = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self5.xmlHttpReq5 = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self5.xmlHttpReq5 = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self5.xmlHttpReq5.open('POST', strURL, true);
    self5.xmlHttpReq5.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self5.xmlHttpReq5.onreadystatechange = function() {
        if (self5.xmlHttpReq5.readyState == 4) 
		{ 		
		 if(self5.xmlHttpReq5.responseText ==1)
		   { 
		 	countdiv="counter_index_page_" + pid;	
			  el = document.getElementById(countdiv);
				if (el) 
				{				
				   el.innerHTML ="Ended";
				   pageRefresh();
				}
			 biddiv="button_finished_index_page_" + pid;
			 document.getElementById(biddiv).style.display='none';  			 	 
		   }
        }
    }
    self5.xmlHttpReq5.send(getbidendstring22(pid));
}
function getbidendstring22(pid)
{ 
	qstr = 'pid=' + pid + '&end=end' ;  // NOTE: no '?' before querystring  
	return qstr;	
}


function calc_counter_from_time22(diff) 
{
	
  if (diff > 0) {
    hours=Math.floor(diff / 3600)
    minutes=Math.floor((diff / 3600 - hours) * 60)
    seconds=Math.round((((diff / 3600 - hours) * 60) - minutes) * 60)
  } else {
    hours = 0;
    minutes = 0;
    seconds = 0;
  }
  if (seconds == 60) {
    seconds = 0;
  }
  if (minutes < 10) {
    if (minutes < 0) {
      minutes = 0;
    }
    minutes = '0' + minutes;
  }
  if (seconds < 10) {
    if (seconds < 0) {
      seconds = 0;
    }
    seconds = '0' + seconds;
  }
  if (hours < 10) {
    if (hours < 0) {
      hours = 0;
    }
    hours = '0' + hours;
  }
  //alert(hours + ":" + minutes + ":" + seconds);

  return hours + ":" + minutes + ":" + seconds;
}


