﻿var exptime=null;
var secondCounter=0;
var lastSecondsMeasure=new Date();

function updateexpiredtime() {
	if (exptime==null) return;
	secondCounter+=((new Date())-lastSecondsMeasure)/1000;
	lastSecondsMeasure=new Date();
	var cont=document.getElementById("expiredtime");
	var dif=exptime-secondCounter;
	//dif=477938; //5 d, 12 hour, 45 min, 38 sec
	//alert(secondCounter+';'+exptime);
	var sign="";		
	var day=dif/86400;
	if (day<0) {sign="-"; day=-day;}
	var hour=(day-Math.floor(day))*24;
	var min=(hour-Math.floor(hour))*60;
	var sec=(min-Math.floor(min))*60;
	cont.innerHTML=showexpirytime(sign, day, hour, min, sec)
	self.setTimeout("updateexpiredtime()", 1000)
}

function showexpirytime(sign, day, hour, minute, sec) {
	if (sign=="-") return "-ended-";
	var tmp='';
	tmp+=sign;
	if (day>1) tmp+=getTwoDigits(Math.floor(day))+'d ';
	tmp+=getTwoDigits(Math.floor(hour))+':';
	tmp+=getTwoDigits(Math.floor(minute))+':';
	tmp+=getTwoDigits(Math.floor(sec));
	return tmp;
}

function getTwoDigits(vl) {
	return vl<10 ? '0'+vl : vl ;
}


//---------------------MACROMEDIA SCRIPTS------------------------
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 MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

//-------------------------------------------------------- Danae Service Availabilty Cofirmation Methods ----------------------------------------------------------------
var viewed=false;
//window.setInterval("GetAvailabilityResult()",60000);

function GetAvailabilityResult()
{
	var fm=document.getElementById("availabilityForm");
	var orderID=fm.orderID.value.toString()
	if (orderID != "0")
	{
		var dt=new Date();
		$.get("/ws/ws_confirmavailability.asp?dt="+escape(dt)+"&id=" + orderID, viewAvailabilityResult);
	}
}

function viewAvailabilityResult(response) 
{
	if (response != "")
	{
		$("#availability_result").html(response);
		if (!viewed) 
		{
			viewport.init(".availability_popup_div");
			viewed=true;
		}
		$(".availability_popup_div").show();
	}
}

function closeAvailabilityDiv() 
{
	$(".availability_popup_div").hide();
}

/* Center-screen the popup div */
var viewport = {
	o: function() {
			if (self.innerHeight) {
				this.pageYOffset = self.pageYOffset;
				this.pageXOffset = self.pageXOffset;
				this.innerHeight = self.innerHeight;
				this.innerWidth = self.innerWidth;
			} else if (document.documentElement && document.documentElement.clientHeight) {
				this.pageYOffset = document.documentElement.scrollTop;
				this.pageXOffset = document.documentElement.scrollLeft;
				this.innerHeight = document.documentElement.clientHeight;
				this.innerWidth = document.documentElement.clientWidth;
			} else if (document.body) {
				this.pageYOffset = document.body.scrollTop;
				this.pageXOffset = document.body.scrollLeft;
				this.innerHeight = document.body.clientHeight;
				this.innerWidth = document.body.clientWidth;
			}
			return this;
		},
		init: function(el) {
			$(el).css("left",Math.round(viewport.o().innerWidth/2) + viewport.o().pageXOffset - Math.round($(el).width()/2));
			$(el).css("top",Math.round(viewport.o().innerHeight/2) + viewport.o().pageYOffset - Math.round($(el).height()/2));
		}
}; 
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------