﻿var xmlhttp
function update(email)
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        //alert ("Your browser does not support XMLHTTP!");
        return;
    }
    var url="common/calculate_common.asp";
    url=url+"?email="+email;
    url=url+"&sid="+Math.random();
    
    //window.alert("a " + url);
    
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
    
}
function copytoname(name)
{
    if (name.length > 0 )
    {
        document.getElementById('ccnameoncard').value = name;
    }
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}


function countdown_clock(month, day, hour, minute, second, zone, format)
         {
         //I chose a div as the container for the timer, but
         //it can be an input tag inside a form, or anything
         //who's displayed content can be changed through
         //client-side scripting.
         html_code = '<span id="couponCountdown"></span>';
         document.write(html_code);
         
         countdown(month, day, hour, minute, second, zone, format);                
         }
         
        function countdown(month, day, hour, minute, second, zone, format)
        {
            var toDate = new Date();
	        if (month > 0) 
	        { 
		        if (month <= toDate.getMonth())
			        toDate.setYear(toDate.getYear() + 1);
		        toDate.setMonth(month-1);
	        }
	        toDate.setDate(day);
	        toDate.setHours(hour);
	        toDate.setMinutes(minute-(zone*60));
	        toDate.setSeconds(second);
	        var fromDate = new Date();
	        fromDate.setMinutes(fromDate.getMinutes() + fromDate.getTimezoneOffset());
	        var diffDate = new Date(0);
	        diffDate.setMilliseconds(toDate - fromDate);
	        Time_Left = Math.floor(diffDate.valueOf()/1000);
	        
	        if(Time_Left < 0)
                Time_Left = 0;
         
            //More datailed.
            days = Math.floor(Time_Left / (60 * 60 * 24));
            Time_Left %= (60 * 60 * 24);
            hours = Math.floor(Time_Left / (60 * 60));
            Time_Left %= (60 * 60);
            minutes = Math.floor(Time_Left / 60);
            Time_Left %= 60;
            seconds = Time_Left;
            if (minutes < 10) 
            {
			    minutes = '0'+minutes;
			}
            if (seconds < 10) 
            {
			    seconds = '0'+seconds;
			}
			//if (Time_Left == 0)
			//{
			    //document.getElementById("couponCountdown").innerHTML = ' Sale Ended.';
			//    return;
            //}
            dps = 's'; hps = 's'; mps = 's'; sps = 's';
            //ps is short for plural suffix.
            if(days == 1) dps ='';
            if(hours == 1) hps ='';
            if(minutes == 1) mps ='';
            if(seconds == 1) sps ='';
                        
             switch(format)
             {
                   case 0:
                        //The simplest way to display the time left.
                        document.getElementById("couponCountdown").innerHTML = Time_Left + ' seconds';
                        break;
                   case 1:
                        document.getElementById("couponCountdown").innerHTML = days + ' Day' + dps + ' ' + hours + ' hour' + hps + ' ' + minutes + ' minute' + mps + ' and ' + seconds + ' second' + sps;
                        break;
                   case 2:
                        document.getElementById("couponCountdown").innerHTML = days + 'd ' + hours + 'h ' + minutes + 'm ' + seconds + 's ';
                        break;
                    case 3:
                        document.getElementById("couponCountdown").innerHTML = days + ':' + hours + ':' + minutes + ':' + seconds;
                        break;
                    case 4:
                        document.getElementById("couponCountdown").innerHTML = days + " day" + (days == 1 ? '' : 's') + ' + ' +hours+ 'h : ' +minutes+ 'm : '+seconds+'s';
                        break;   
                    case 5:
                        document.getElementById("couponCountdown").innerHTML = days + " day" + dps + ' ' +hours+ ' hour' + hps + ' and ' +minutes+ ' minute'+mps;
                        break;     
                   case 6:
                        var t = "";
                        if (days > 0) { t = days + " day" + dps + ' ';}
                        if (hours > 0) { t = t + hours+ ' hour' + hps + ' and ';}
                        document.getElementById("couponCountdown").innerHTML =  t + minutes+ ' minute'+mps;
                        break;     
                   
                   default: 
                        document.getElementById("couponCountdown").innerHTML = Time_Left + ' seconds';
                   }
               
         //Recursive call, keeps the clock ticking.
         setTimeout('countdown(' + month + ',' + day + ',' + hour + ',' + minute + ',' + second + ',' + zone + ',' + format + ');', 999);
         }
