var d = window.document; function getE( v ) { e = false; if ( d.getElementById ) { e = d.getElementById( v ); } else if ( d.all ) { e = d.all[ v ]; } return e; } function countdown(instance,target) { var Today = new Date(); var Todays_Date = new Date(Today.toGMTString()); var Target_Date = new Date(target); //Find their difference, and convert that into seconds. var Time_Left = Math.round((Target_Date - Todays_Date) / 1000); if(Time_Left < 0) Time_Left = 0; var thisCountDown = getE('countdown' + instance); thisCountDown.innerHTML = Math.floor(Time_Left / 60) + ":" + (Time_Left % 60).toFixed().pad(2, "0"); //Recursive call, keeps the clock ticking. if(Time_Left > 0) setTimeout('countdown('+instance+',\''+target+'\');',1000); else checkOnProduct(instance); //call AJAX } function individualCountdown(target) { Today = new Date(); Todays_Date = new Date(Today.toGMTString()); Target_Date = target; //Find their difference, and convert that into seconds. var Time_Left = Math.round((Target_Date - Todays_Date) / 1000); if(Time_Left < 0) Time_Left = 0; var thisCountDown = getE('countdown'); thisCountDown.innerHTML = Math.floor(Time_Left / 60) + ":" + (Time_Left % 60).toFixed().pad(2, "0") ; //Recursive call, keeps the clock ticking. if(Time_Left > 0) setTimeout('individualCountdown(Target_Date);',1000); else window.location='/timeout.php'; } function getHTTPObject() { //http://www.webpasties.com/xmlHttpRequest/xmlHttpRequest_tutorial_1.html var xmlhttp; /*@cc_on @if (@_jscript_version >= 5) try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } @else xmlhttp = false; @end @*/ if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp = false; } } return xmlhttp; } function handleHttpResponse() { if (http.readyState == 4) { var incoming_json = http.responseText; //http://www.json.org/js.html var productData = eval('('+incoming_json+')'); right_this_instant = new Date(); var money_time = getE('countdown'+productData.series_number); var a_link = getE('a'+productData.series_number); var li_class = getE('li_class'+productData.series_number); if(productData.hold_end > productData.now) { right_now = new Date(); counted_ahead = parseInt(right_now.getTime()) + parseInt(productData.hold_end) - parseInt(productData.now); soon = new Date(); soon.setTime(counted_ahead); countdown(productData.series_number,soon); } else if(productData.purchase_complete == "1") { money_time.innerHTML = 'SOLD!'; li_class.className = 'sold_button'; } else { money_time.innerHTML = '$' + productData.series_number; a_link.addEventListener("click",eval('enableProduct'+productData.series_number),true); li_class.className = 'purchase_button'; } isWorking = false; } } var http = getHTTPObject(); // We create the HTTP Object var isWorking = false; function checkOnProduct(instance) { if(!isWorking) { isWorking = true; var url="_svc/product_status.php?product_id=" + product_id + "&series_number=" + instance; http.open("GET", url , true); http.onreadystatechange = handleHttpResponse; http.send(null); var detailsDiv=document.getElementById('detailsDiv'); } else { setTimeout("checkOnProduct()",500); } } String.prototype.pad = function(l, s) { return (l -= this.length) > 0 ? (s = new Array(Math.ceil(l / s.length) + 1).join(s)).substr(0, s.length) + this + s.substr(0, l - s.length) : this; };