// JavaScript Document
// Copyright NISA Internet and Computer Solutions Limited 2009 all rights reserved

<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



 function GetDay(intDay){
    var DayArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday", 
                         "Thursday", "Friday", "Saturday")
    return DayArray[intDay]
    }

  function GetMonth(intMonth){
    var MonthArray = new Array("January", "February", "March",
                               "April", "May", "June",
                               "July", "August", "September",
                               "October", "November", "December") 
    return MonthArray[intMonth] 	  	 
    }
  function getDateStrWithDOW(){
    var today = new Date()
    var year = today.getYear()
    if(year<1000) year+=1900
    var todayStr = GetDay(today.getDay()) + ", "
    todayStr += GetMonth(today.getMonth()) + " " + today.getDate()
    todayStr += ", " + year
    return todayStr
    }
	
	

  //----------------------------------------------------------------------------
  // Name: field()
  // Role: Locate the document with the specified id
  //----------------------------------------------------------------------------
  function field( id ) {
    var ele = document.getElementById( id );
    if ( !ele ) {
      alert( 'Specified document element not found.  id="' + id + '"' );
    }
    return ele;
  }

  //----------------------------------------------------------------------------
  // Name: padout()
  // Role: prepend a leading '0' to values < 10 (e.g., 0..9)
  //----------------------------------------------------------------------------
  function padout( number ) {
    return ( number < 10 ) ? '0' + number : number;
  }
  //----------------------------------------------------------------------------
  // Name: showAllDates()
  // Role: Populate all listed combos
  //----------------------------------------------------------------------------
  // Inline in each page
  //function showAllDates( ) {
  //showDates('dateselector');
  //showDates('dateselector2');
  //showDates('dateselector3');
  //showDates('dateselector4');
  //showDates('dateselector5');
  //showDates('dateselector6');
  //showDates('dateselector7');
  //showDates('dateselector8');
  //showDates('dateselector9');
  //showDates('dateselector10');

  //}


  //----------------------------------------------------------------------------
  // Name: showDates()
  // Role: Generate all the dates in the specified range
  //----------------------------------------------------------------------------
  function showDates( id ) {
    var result = '';
    var combo	= field( id );
	var startDate = new Date();
	var endDate = new Date();
	//
	var today = new Date();
	//
	var shownfirst = false;
	var d = new Date();
	var weekday=new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");

    if (d.getHours() < 12)
    {
    	startDate= new Date();
		//
        startDate.setDate( d.getDate() + 1 );
		//
    }
    else
    {
    	startDate= new Date();
        //startDate.setDate( d.getDate() + 1 );
        startDate.setDate( d.getDate() + 2 );
    }

	endDate.setDate( d.getDate() + 14 );
    while ( startDate < endDate ) {
		if ((startDate.getDay() >0) && (startDate.getDay() <6)) { // If it's not Saturday or Sunday
        	if (shownfirst == false ) {
				
				// If today is Friday after 12pm (actually this won't kick in until 1pm) or today is Saturday or Sunday make the first available delivery day Tuesday not Monday
				if ((startDate.getDay() == 1) && ((weekday[today.getDay()] == 'Fri') && (d.getHours() > 11) || (weekday[today.getDay()] == 'Sat') || (weekday[today.getDay()] == 'Sun'))) {
        			startDate.setDate( startDate.getDate() + 1 );
				}
        	}
			
        	var opt = document.createElement("option");
        	opt.text = weekday[startDate.getDay()] + " "+ padout( startDate.getDate()) + '-' + padout( startDate.getMonth() + 1 ) + '-' + startDate.getFullYear();
        	opt.value = weekday[startDate.getDay()] + " "+ padout( startDate.getDate()) + '-' + padout( startDate.getMonth() + 1 ) + '-'+ startDate.getFullYear();

      		combo.options.add ( opt );
      		shownfirst=true;
		
		}

      startDate.setDate( startDate.getDate() + 1 );

    }


	//----
	// Add '2-3 Working Days' to the last date dropdown option, this will be position [9] ** see below where it check the chosen delivery option
	var opt = document.createElement("option");
	opt.text = "2-3 Working Days";
	opt.text = "2-3 Working Days";
	combo.options.add ( opt );
	//----
	

    return result.substring( 1 );
  }
  
  
  
// Comfy Gift Boxes Promotion Voucher Discount


var vouchval = "(blanket)"; // What user entered - not used

// Array details

// All Comfy Gift Boxes plus mixed new baby ones, (4 extra 11 - 14)


var discount_array = new Array("0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"); // Starts at 0 (first position 0 not used as forms start at form1)

	
function ChkVouch (form_number) {

// Pick up the code from the relevant form details

if (form_number == 1) {
vouchval = document.form1.vouchcode.value; // Voucher code entered on website
}
if (form_number == 2) {
vouchval = document.form2.vouchcode.value; // Voucher code entered on website
}
if (form_number == 3) {
vouchval = document.form3.vouchcode.value; // Voucher code entered on website
}
if (form_number == 4) {
vouchval = document.form4.vouchcode.value; // Voucher code entered on website
}
if (form_number == 5) {
vouchval = document.form5.vouchcode.value; // Voucher code entered on website
}
if (form_number == 6) {
vouchval = document.form6.vouchcode.value; // Voucher code entered on website
}
if (form_number == 7) {
vouchval = document.form7.vouchcode.value; // Voucher code entered on website
}
if (form_number == 8) {
vouchval = document.form8.vouchcode.value; // Voucher code entered on website
}
if (form_number == 9) {
vouchval = document.form9.vouchcode.value; // Voucher code entered on website
}
if (form_number == 10) {
vouchval = document.form10.vouchcode.value; // Voucher code entered on website
}
if (form_number == 11) {
vouchval = document.form11.vouchcode.value; // Voucher code entered on website
}
if (form_number == 12) {
vouchval = document.form12.vouchcode.value; // Voucher code entered on website
}
if (form_number == 13) {
vouchval = document.form13.vouchcode.value; // Voucher code entered on website
}
if (form_number == 14) {
vouchval = document.form14.vouchcode.value; // Voucher code entered on website
}
if (form_number == 15) {
vouchval = document.form15.vouchcode.value; // Voucher code entered on website
}
if (form_number == 16) {
vouchval = document.form16.vouchcode.value; // Voucher code entered on website
}
if (form_number == 17) {
vouchval = document.form17.vouchcode.value; // Voucher code entered on website
}
if (form_number == 18) {
vouchval = document.form18.vouchcode.value; // Voucher code entered on website
}
if (form_number == 19) {
vouchval = document.form19.vouchcode.value; // Voucher code entered on website
}


promocode = "CGB8931" ; // Actual promotion code
voucher_discount = 1; // £1.00

    if (vouchval == promocode) {
      discount_array[form_number] = voucher_discount;  // remember the discount amt
      alert ("Valid promotion voucher code for a Comfy Gift Box, your discount is now in effect. \n\n" + "Please select your delivery options and click on the Buy Now button.");
      return;
    }
  alert ("'" + vouchval + "'  is not a valid Comfy Gift Boxes promotion code.");
}



// Apply discount to the correct form and Buy Now button

function ReadForm (form_details) {
	
// Check a message has been entered
if (form_details.os0.value == "" && form_details.os1.value == "") {
	
	alert ("Please enter a message we can include on a gift card to go with your present.");
	form_details.os0.focus();
	form_details.os0.style.borderColor = "#cc0000";
	return false;
	
}

//


var amt,des;

// Get form number from the form name - format: form1, form2, form3 etc

form_no = form_details.name.match(/\d+$/)[0]; // Extract the number from the form name, e.f for form3 we want '3'

amt = form_details.baseamt.value*1.0; // Base amount from form
des = form_details.basedes.value; // Base description from form


// Apply the discount if discount is active in array relating to the form, i.e they entered a valid code in the same form as the Buy Now button they are pressing

  if (discount_array[form_no] > 0) { 
    amt = Pound (amt - discount_array[form_no]);
	des = des + " - with £1.00 " + vouchval + " promotion discount";
  }
  
  form_details.amount.value = Pound (amt);
  form_details.item_name.value = des;



  
}

function Pound (val) { // Force to valid pound amount
var str,pos,rnd=0;
  if (val < .995) rnd = 1; // For old Netscape browsers
  str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape
  pos = str.indexOf (".");
  if (pos > 0) str = str.substring (rnd, pos + 3);
  return str;
}


//----






//-->
