function createCookie(name,value,days) {
  
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
      
  document.cookie = name+"="+value+expires+"; path=/";
}

function getCookieValue(cookie_name) {
   var nameEQ = cookie_name + "=";
   var ca = document.cookie.split(';');
   for(var i=0;i < ca.length;i++) {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
   }
   return null;
}

window.addEvent('domready', function() {
	
	var tfCookie = getCookieValue("25percent");
	if (tfCookie == null) {
		createCookie('25percent', 'active', 7);
	}

	var matrix = $('content').getElement('.matrix');
	if (matrix) {	
	    var link = new Element('a', { 'href': '/promo/25-percent' });
		//var banner = new Element('img', { 'src' : '/promo/25-percent/images/banner-full-468x60_clean-layers.jpg' });
		var banner = new Element('img', { 
		    'src' : '/promo/25-percent/images/Hosting+landing+pg+WC+v3.png',
			'styles' : {
				'padding' : '0 0 0 10px',
				'backgroundColor' : '#001046'
			} 
		});		
		
		var asterix = new Element('span', { 'html' : '*', 'styles' : { 'padding' : '0px, 4px', 'color' : 'red' }});
		var condition = new Element('p', { 'html' : 'Offer only available to new hosting customers', 'styles' : { 'text-align' : 'right', 'padding' : '0 0 8px', 'margin-bottom' : '-4px' }});
		asterix.inject(condition, 'top');
		condition.inject(matrix, 'top');
		//banner.inject(link, 'top');
		//link.inject(matrix, 'top');
		banner.inject(matrix, 'top');
    }
  
    var page = getURLParam('p');
    var ecoPrice = $$('tr');
    var baseUrl = getBaseUrl();
    var price = new Array();
    var plan = new Array();
    
    // mapping of page names for price index (used below).  
    plan['easystart']    = { 'pos' : '0', 'name' : 'Easy Start' };
    plan['economy']      = { 'pos' : '1', 'name' : 'Economy' };
    plan['business']     = { 'pos' : '2', 'name' : 'Business' };
    plan['professional'] = { 'pos' : '3', 'name' : 'Professional' };
    plan['premier']      = { 'pos' : '4', 'name' : 'Premier' };
    plan['premiera']     = { 'pos' : '5', 'name' : 'Premier Advantage' };
    
    // pricing array indexed by number for use with overview page
	price[0] = { 'oldAnnual' : '240',  'newAnnual' : '180',     'oldMonth' : '21.95',  'newMonth' : '16.45',  'monthId' : '97826', 'yearId' : '97827' };
	price[1] = { 'oldAnnual' : '420',  'newAnnual' : '315',     'oldMonth' : '39.95',  'newMonth' : '29.95',  'monthId' : '97828', 'yearId' : '97829' };
	price[2] = { 'oldAnnual' : '599',  'newAnnual' : '449',     'oldMonth' : '65.95',  'newMonth' : '49.45',  'monthId' : '97830', 'yearId' : '97831' };
	price[3] = { 'oldAnnual' : '845',  'newAnnual' : '633',     'oldMonth' : '89.95',  'newMonth' : '67.45',  'monthId' : '97832', 'yearId' : '97833' };
	price[4] = { 'oldAnnual' : '2999', 'newAnnual' : '2249',    'oldMonth' : '329.95', 'newMonth' : '247.45', 'monthId' : '97836', 'yearId' : '97837' };
	price[5] = { 'oldAnnual' : '6999', 'newAnnual' : '5248.75', 'oldMonth' : '699',    'newMonth' : '524.25', 'monthId' : '97838', 'yearId' : '97839' };
    
    if(ecoPrice.length == 23) {
		var saving = '';
	    var annualCells = ecoPrice[16].getElements('td');	    
		var monthlyCells = ecoPrice[17].getElements('td');
		var orderCells = ecoPrice[19].getElements('td');		
		var annualPrices = $$('strong[class=annualPrice]');
		var monthlyPrices = $$('strong[class=monthlyPrice]');
		
		if(annualCells && monthlyCells && orderCells) {
		    for (var num = 0; num < 6; num++) {		    	
		    	saving = ((price[num]['newMonth'] * 12) - price[num]['newAnnual']).toFixed(2);		    	
		    	annualCells[num].innerHTML = "<strike>$"+ addCommas(price[num]['oldAnnual']) +"/yr</strike><br /><strong>$"+ addCommas(price[num]['newAnnual']) +"/yr</strong><br /><small>Best Value!<br/>Save $"+ addCommas(saving) +"</small>";
		    	monthlyCells[num].innerHTML = "<strike>$"+ addCommas(price[num]['oldMonth']) + "/mth</strike><br /><strong>$"+ addCommas(price[num]['newMonth']) +"/mth</strong>";
			    orderCells[num].innerHTML = "<a href=\"https://"+baseUrl+"/order-online.php?productid="+ price[num]['monthId'] +"\">Order Now</a>";
		    }
	    }	
    } else if(ecoPrice.length == 18) {
    	var monthlyCell = ecoPrice[1].getElement('td');
    	var annualRow = ecoPrice[2];    	
	    var annualCell = ecoPrice[2].getElement('td');	    	    
        var orderCell = $('signup');
        if(annualCell && monthlyCell && orderCell) {        	
    	    if((page != '') && page != 'us') {
    	    	var num = plan[page]['pos'];
    	    	var name = plan[page]['name'];
		    	annualEquate = (price[num]['newAnnual'] / 12).toFixed(2);		    	
		    	annualRow.style.background = "#E7151A";
    	    	monthlyCell.innerHTML = "<strike><strong>$"+ price[num]['oldMonth'] +"</strong></strike><br /><strong>$"+ price[num]['newMonth'] +"</strong>";    	    	
	    	    annualCell.innerHTML = "<strike><strong>$"+ addCommas(price[num]['oldAnnual']) +"</strong></strike><br /><strong>$"+ addCommas(price[num]['newAnnual']) +"</strong><br />(equates to $"+ annualEquate +"/mth)";	    	    
	    	    orderCell.innerHTML = "<a title=\"Sign up to "+ name +" Web Hosting\" href=\"https://"+baseUrl+"/order-online.php?productid="+ price[num]['monthId'] +"\"><img alt=\"Sign up to Business Web Hosting\" title=\"Sign up to "+ name +" Web Hosting\" src=\"/library/images/sme/icons/signup2.gif\"/></a>";
    	    }
        }
    }   
});