var bPageIsLoaded = false;
/***********************************************************************
*
* setCookie -	Generic Set Cookie routine
*
* Input: sName	 -	Name of cookie to create
*	 sValue	 -	Value to assign to the cookie
*	 sExpire -	Cookie expiry date/time (optional)
*
* Returns: null
*
************************************************************************/

function setCookie(sName, sValue, sExpire) 
    {
    var sCookie = sName + "=" + escape(sValue) +"; path=/";	// construct the cookie
    if (sExpire)
    	{
    	sCookie += "; expires=" + sExpire.toGMTString();	// add expiry date if present
    	}
    document.cookie = sCookie;					// store the cookie
    return null;
    }

/***********************************************************************
*
* getCookie	-	Generic Get Cookie routine
*
* Input: sName	-	Name of cookie to retrieve
*
* Returns:		Requested cookie or null if not found
*
************************************************************************/

function getCookie(sName) 
    {
    var sCookiecrumbs = document.cookie.split("; "); 	// break cookie into crumbs array
    var sNextcrumb
    for (var i=0; i < sCookiecrumbs.length; i++) 
	{
	sNextcrumb = sCookiecrumbs[i].split("=");	// break into name and value
	if (sNextcrumb[0] == sName)			// if name matches
	    {
	     return unescape(sNextcrumb[1]); 		// return value
	    }
	}
	return null;
    }

/***********************************************************************
*
* saveReferrer -	Saves the referrer to a Cookie
*
* Input: 		nothing
*
* Returns:		null
*
************************************************************************/

function saveReferrer() 
    {
    var bSetCookie = false;
    if (parent.frames.length == 0)					// No FrameSet
		{
		bSetCookie = true;
		}
    else														// FrameSet in use
		{
		var bCatalogFrameSet = false;
		for (var nFrameId = parent.frames.length; nFrameId > 0; nFrameId--)
			{
			if (parent.frames[nFrameId - 1].name == 'CatalogBody')	// Catalog FrameSet used
				{
				bCatalogFrameSet = true;
				break;
				}
			}
		if (bCatalogFrameSet)							// Catalog FrameSet
			{
			if (window.name=='CatalogBody')			// and this is the CatalogBody frame
				{
				bSetCookie = true;
				}
			}
		else													// Not Catalog FrameSet
			{
			bSetCookie = true;
			}
		}
    if (bSetCookie)
		{
		var sUrl = document.URL;
		var nHashPos = sUrl.lastIndexOf("#");		// Look for URL anchor
		if (nHashPos > 0)									// if it exists
		    {
		    sUrl = sUrl.substring(0,nHashPos);		// then remove it
		    }
		setCookie("ACTINIC_REFERRER", sUrl);		// Emulates HTTP_REFERER
		}
	    return null;
	    }

/***********************************************************************
*
* CreateArray	creates an array with n elements
*
* Input: n	-	number of elements
*
* Returns:		the created array
*
************************************************************************/

function CreateArray(n)
	{
	this.length = n;
	for (var i=1; i <= n; i++)							// for all ns
		{
		this[i] = new Section();						// create a section structure
		}
	return this;											// return the created array
	}

/***********************************************************************
*
* Section	-	creates the section structure for raw section lists
*
* Input: 				nothing
*
* Returns:				nothing
************************************************************************/

function Section()
	{
	this.sURL = null;
	this.sName = null;
	this.sImage = null;
	this.nImageWidth = null;
	this.nImageHeight= null;
	this.nSectionId	= null;
	this.pChild = null;
	}
	
/***********************************************************************
*
* SwapImage			-	swaps an image to the alternative
*
* Input:	sName		-	name of the image
*
*			sAltImage	-	filename of the alternative image
*
************************************************************************/

function SwapImage(sName, sAltImage)
	{
	var nCount = 0;
	document.aSource = new Array;						// array for images
	if (document[sName] != null)						// if image name exists
		{
		document.aSource[nCount++] = document[sName];	// store image
		if(null == document[sName].sOldSrc)
			{
			document[sName].sOldSrc = document[sName].src;	// store image source
			}
		document[sName].src = sAltImage;				// change image source to alternative
		}
	}

/***********************************************************************
*
* RestoreImage		-	restores an image to the original
*
* Input: 				nothing
*
* Returns:				nothing
************************************************************************/

function RestoreImage()
	{
	var nCount, aSource = document.aSource;
	if (aSource != null)									// if array of images exists
		{
		for(nCount=0; nCount < aSource.length; nCount++)	// restore all images
			{
			if ((aSource[nCount] != null) &&
				(aSource[nCount].sOldSrc != null))	// if we stored something for this image
				{
				aSource[nCount].src = aSource[nCount].sOldSrc;	// restore the original image
				}
			}
		}
	}

/***********************************************************************
*
* PreloadImages		-	restores an image to the original
*
* Input: 				nothing
*
* Returns:				nothing
*
************************************************************************/

function PreloadImages()
	{
	bPageIsLoaded = true;
	if(document.images)
		{
		if(!document.Preloaded)							// preload array defined?
			{
			document.Preloaded = new Array();		// no, define it
			}
		var nCounter , nLen = document.Preloaded.length, saArguments = PreloadImages.arguments;
		for(nCounter = 0; nCounter < saArguments.length; nCounter++)	// iterate through arguments
			{
			document.Preloaded[nLen] = new Image;
			document.Preloaded[nLen++].src = saArguments[nCounter];
			}
   	}
	}
	
/***********************************************************************
*
* ShowPopUp		-	creates pop up window
*
* Input: sUrl		-	URL o page to display
*			nWidth	-	Width of window
*			nHeight	-	Height of window
*
* Returns:				nothing
*
************************************************************************/

function ShowPopUp(sUrl, nWidth, nHeight)
  	{  
	window.open(sUrl, 'ActPopup', 'width=' + nWidth + ',height=' + nHeight + ',scrollbars, resizable');
	if (!bPageIsLoaded)
		{
		window.location.reload(true);
		}
	}

/***********************************************************************
*
* DecodeMail		-	decodes the obfuscated mail address in 'contactus' link
*
* Input: 				nothing
*
* Returns:				nothing
*
************************************************************************/

function DecodeMail()
	{
	var nIdx = 0;
	for( ; nIdx < document.links.length; nIdx++ )
		if ( document.links[ nIdx ].name == "contactus" )
		{
		var sOldRef = document.links[ nIdx ].href;

		while( sOldRef.indexOf( " [dot] " ) != -1 )
			sOldRef = sOldRef.replace( " [dot] ", "." );
			
		while( sOldRef.indexOf( " [at] " ) != -1 )
			sOldRef = sOldRef.replace( " [at] ", "@" );
			
		document.links[ nIdx ].href = sOldRef;
		}
	}

/***********************************************************************
*
* HtmlInclude		-	Parses the page for <a href> tags and if any found 
*							with rel="fragment" attribute then create an XMLHTTP
*							request to download the referenced file and insert the
*							file content in place of the referring tag.
*							In case of error just leave it as is.
*
*	NOTE: this function is automatically attached to the onload event handler
*	therefore this processing is done on all pages where this js file is included.
*
* Returns:				nothing
*
* Author:				Zoltan Magyar
*
************************************************************************/

function HtmlInclude() 
	{ 
	var req;
	//
	// Check browser type
	//
	if (typeof(XMLHttpRequest) == "undefined") 	// IE
		{ 
		try 
			{ 
			req = new ActiveXObject("Msxml2.XMLHTTP"); 
			} 
		catch(e) 
			{ 
			try 
				{ 
				req = new ActiveXObject("Microsoft.XMLHTTP"); 
				} 
			catch(e) 										// no luck?
				{ 
				return; 										// nothing to do then
				} 
			} 
		} 
	else 														// Mozzila
		{  
		req = new XMLHttpRequest(); 
		} 
	//
	// Get <a href> tags and iterate on them
	//
	var tags = document.getElementsByTagName("A"); 
	var i; 
	for (i = 0; i < tags.length; i++) 
		{ 
		//
		// Check if we got "fragment" as rel attribute
		//
		if (tags[i].getAttribute("rel") == "fragment") 
			{
			try
				{
				//
				// Try to pull the referenced file from the server
				//
				req.open('GET', tags[i].getAttribute("href"), false); 
				if (document.characterSet) 
					{
					req.overrideMimeType("text/html; charset=" + document.characterSet);
					}
				req.send(null); 
				if (req.status == 200) 					// got the content?
					{ 
					//
					// Replace the reference with the pulled in content
					//
					var span = document.createElement("SPAN"); 
					span.innerHTML = req.responseText; 
					tags[i].parentNode.replaceChild(span, tags[i]);
					} 
				}
			catch(e)											// couldn't pull it from the server (maybe preview)
				{
				return;										// don't do anything then
				}
			} 
		} 
	} 

//
// The following lines will automatically parse all the pages 
// where this script is included by attaching the HtmlInclude
// function to the onload event.
//
if (window.attachEvent) 								// IE 
	{ 
	window.attachEvent("onload", HtmlInclude); 
	} 
else 															// DOM
	{  
	window.addEventListener("load", HtmlInclude, false); 
	}


// START Multiple other info prompt support - V2.50
var formno;
var fieldno;
var docform;

function locatefield(fname){
  formno = '';
  fieldno = '';
  //  (V11) look through all forms 'till one containing field "fname"
  var tf = -1;
  var te = 0;
  var df = document.forms;
  var i = df.length - 1;
  for ( var j = 0; j <= i; j++ )
    {
    var k = df[j].length - 1; 
    for ( var l = 0; l <= k; l++ )
      {
// alert(df[j].elements[l].name);
     if ( df[j].elements[l].name == (fname) ) 
        {
        tf = j;
        te = l;
        }
      }
    }
  if ( tf < 0 )
    {
    alert('Cannot find product form ' + fname);
    return false;
    }
  else
    {
    formno = tf;
    fieldno = te;
    docform = df[tf];
    return true;
    }
}

function stripspecial( prodref ){
// find the form with the order field.
  if (locatefield(prodref))
    {
    docform.elements[fieldno].value = docform.elements[fieldno].value.replace(/[¬\¦]/g, " ");
    } 
} 

function concat( prodref ){
// variables m_country and m_uk will have been set already by 'setotherinfo1' function
// find the form with the order field.
  if (locatefield('O_' + prodref))
   {
    var items = docform.elements[fieldno].value.split(' ¦ ');                     // fetch names
    docform.elements[fieldno].value = '';
    for (var i = 0; i < items.length; i++)   // add in all sub fields
      {
      var names = items[i].split('¬');
      if ( i > 0) docform.elements[fieldno].value += ' ¦ ';
// have to allow for postcode anywhere in the docform
// also allow for where the postcode anywhere buttons are not displayed for any reason

	docform.elements[fieldno].value += names[0] + '¬';

	if (i==0) {
		m_sub =i;
	} else {
		if (docform.elements[fieldno + 2].value == "Click here to get address") {
			if (i<=7) {
				m_sub = i+2;
			} else {
				if (docform.elements[fieldno + 11].value == "Click here to get address (UK only)") {
					m_sub = i+4;
				} else {
					m_sub = i+2;
				}
			}
		} else {
			if (i<=7) {
				m_sub = i;
			} else {
				if (docform.elements[fieldno + 11].value == "Click here to get address (UK only)") {
					m_sub = i+2;
				} else {
					m_sub = i;
				}
			}
		}
	}
	docform.elements[fieldno].value += docform.elements[fieldno + m_sub + 1].value.replace(/[¬\¦]/g, " ");
      }
   } else {
	alert ("We appologise but an error has occurred and we are not able to process this order. Please close down your browser and try again");
	alert ("Contact us on 0845 519 0185, Mon - Fri 9am - 5pm, if you need help");
	return false;
   }
   return true;
}

//function concat( prodref ){
// variables m_country and m_uk will have been set already by 'setotherinfo1' function
// find the form with the order field.
//  if (locatefield('O_' + prodref))
//    {
//    var items = docform.elements[fieldno].value.split(' ¦ ');                     // fetch names
//    docform.elements[fieldno].value = '';
//
//    for (var i = 0; i < items.length; i++)   // add in all sub fields
//      {
//      var names = items[i].split('¬');
//      if ( i > 0) docform.elements[fieldno].value += ' ¦ ';
// have to allow for postcode anywhere in the docform
//	docform.elements[fieldno].value += names[0] + '¬';
//	if (i==0) {m_sub =i;}

// also allow for where the postcode anywhere buttons are not displayed for any reason
//	if (docform.elements[fieldno + 2].value == "Click here to get address") {
//		if (i>0 && i<=7) {m_sub = i+2}
//		if (i>7) {m_sub = i+4}
//	} else {
//		m_sub = i;
//	}

//	docform.elements[fieldno].value += docform.elements[fieldno + m_sub + 1].value.replace(/[¬\¦]/g, " ");
//      }
//    }
//}

// ******************************************************************************************************
//
// Setotherinfo1 sets the order form up to the first post code anywhere button
//
// ******************************************************************************************************

function setotherinfo1(pre, name, size, max, prodname) {
  pre = pre.replace(/&#124;/g, '|');		// fix |
  pre = pre.replace(/&#46;/g, '.');		// fix .		
  pre = pre.replace(/&#123;/g, '{');		// fix {		
  pre = pre.replace(/&#125;/g, '}');		// fix }		
  pre = pre.replace(/&#58;/g, ':');		// fix :		

  var prodref = name.substr(8);			// the product reference part start
  var prodref = prodref.slice(0, -1);		// lose the > char
  var p1 = prodref.indexOf('"');		// end of the text
  var prodvalue = prodref.substr(p1 + 1);	// any additional value text
  prodref = prodref.substring(0, p1);		// the actual prodref 


// Get the destination country from the product name
  m_product = prodname;
  m_product = m_product.replace(/&#38;/g,"&")
  m_product = m_product.replace(/&#40;/g,"(")
  m_product = m_product.replace(/&#41;/g,")")
  m_product = m_product.replace(/&#44;/g,",")
  m_product = m_product.replace(/&#45;/g,"-")

  m_dhl =  0;
  m_dhlair = 0;
  m_parcelforce = 0;
  m_fedex = 0;
  m_hdnl = 0;
  m_bfpo = 0;
  if (m_product.indexOf("(")> -1) {
	if (m_product.indexOf("DHL") > -1) {
		m_dhl = 1;
		m_country = m_product.substring(4,m_product.indexOf("(")-1).replace(/^\s+|\s+$/g,"");
		if (m_product.toUpperCase().indexOf("AIR SERVICE") > -1) {
			m_dhlair = 1;
		}
	}
	else {
		if (m_product.indexOf("PARCELFORCE") >-1) {
			m_parcelforce = 1;
			m_country = m_product.substring(12,m_product.indexOf("(")-1).replace(/^\s+|\s+$/g,"");
		}
		else {
			if (m_product.indexOf("FedEx") >-1) {
				m_fedex = 1;
				m_country = m_product.substring(6,m_product.indexOf("(")-1).replace(/^\s+|\s+$/g,"");
			}
			else {
				if (m_product.indexOf("HOME DELIVERY NETWORK") > -1) {
					m_hdnl = 1;
					m_country = m_product.substring(22,m_product.indexOf("(")-1).replace(/^\s+|\s+$/g,"");
					if (m_product.indexOf("BFPO") > -1) {
						m_bfpo = 1;
					}
				}
				else {
					m_country = m_product.substring(0,m_product.indexOf("(")-1).replace(/^\s+|\s+$/g,"");
				}
			}
		}
	}
  } 
  else {
	if (m_product.indexOf("DHL") > -1) {
		m_dhl = 1;
		m_country = m_product.substring(4,m_product.indexOf("-")-1).replace(/^\s+|\s+$/g,"");
//		alert(m_product.toUpperCase());
		if (m_product.toUpperCase().indexOf("Air Service") > -1) {
			m_dhlair = 1;
		}
	}
	else {
		if (m_product.indexOf("PARCELFORCE") >-1) {
			m_parcelforce = 1;
			m_country = m_product.substring(12,m_product.indexOf("-")-1).replace(/^\s+|\s+$/g,"");
		}
		else {
			if (m_product.indexOf("FedEx") >-1) {
				m_fedex = 1;
				m_country = m_product.substring(6,m_product.indexOf("-")-1).replace(/^\s+|\s+$/g,"");
			}
			else {
				if (m_product.indexOf("HOME DELIVERY NETWORK") >-1) {
					m_hdnl = 1;
					m_country = m_product.substring(22,m_product.indexOf("-")-1).replace(/^\s+|\s+$/g,"");
					if (m_product.indexOf("BFPO") > -1) {
						m_bfpo = 1;
					}
				}
				else {
					m_country = m_product.substring(0,m_product.indexOf("-")-1).replace(/^\s+|\s+$/g,"");
				}
			}
		}
        }
  }
  m_country=m_country.toUpperCase()
//  if (m_country.indexOf("CHANNEL ISLANDS") > -1) {
//	m_country = "UNITED KINGDOM";
//  }

  if (m_country.indexOf("HIGHLANDS") > -1) {
	m_country = "UNITED KINGDOM";
  }

  if (m_country == "UNITED KINGDOM") {
	m_uk = 1;
  } else {
	m_uk = 0;
  }

// see if a cookie has been created for the collection address and if so populate the collection details with the values in the cookie
  cookiepc = "";
  cookiename = "";
  cookiea1 = "";
  cookiea2 = "";
  cookiect = "";
  cookieph = "";
  cookieem = "";

  var x=readCookie('p2scollection');
  if (x) 
   { 
// parse the cookie into the individual fields
	  var mySplitResult = x.split("#");
// 0 = post code, 1 = name, 2 = address line 1, 3 = address line 2, 4=city/town,5=country,6=phone number
	  cookiepc = mySplitResult[0];
	  cookiename = mySplitResult[1];
	  cookiea1 = mySplitResult[2];
	  cookiea2 = mySplitResult[3];
	  cookiect = mySplitResult[4];
	  cookieco = mySplitResult[5];
	  cookieph = mySplitResult[6];
   }
 // see if simple form
 if (pre.indexOf('|') == -1 ) 
  {
  // alert('Simple ' + name + ' Prodref-' + prodref + '-Value-' + prodvalue + '-');
  document.write(pre + '<INPUT TYPE=text NAME="O_' + prodref + '" ' + prodvalue + ' SIZE="' + size + '" MAXLENGTH="' + max 
                     + '" onchange="stripspecial(\'O_' + prodref + '\')">');
  }
 else
  {        // now have a complex selection
  //  alert('Complex-' + name + '- Prodref-' + prodref + '- Value-' + prodvalue + '-');
  if ( prodvalue == '')			  // we're not bouncing back with an error
    {
    var items = pre.split('|');	  // create default list from prompt text
    var S = ' value="'
    for (var I = 0; I < items.length - 1; I++) S += items[I] + '¬ ¦ '; 
    S += items[items.length - 1] + '¬';
    }
  else
    {
    p1 = prodvalue.indexOf(' VALUE="');    // we've had an error bounce
    var S = prodvalue.slice((p1 + 8), -1); // so extract the old data
    var items = S.split(' ¦ ');            // the items and their data
    S = prodvalue.slice(p1, -1);           // the value="..." substring
    }
 
  document.write('<INPUT TYPE=hidden NAME="O_' + prodref + '"' + S + '" MAXLENGTH="1000">');  // the standard prompt but hidden

// make a table for a nice layout
    document.write('<table border="1" width="580" cellspacing="2" cellpadding="3" class="checkout" cols="3">')
// now see how many sub fields there are
  for (var I = 0; I < items.length; I++)
    {
    if ( prodvalue == '')
      {				//  simple empty list
      var itemname = items[I];
      var itemvalue = '';

      // test for additional style code
      var itemstyle = '';
      var itemtest = itemname.match(/(.*)\{(.*)\}(.*)/);   // see if there's a {...}
      if ( itemtest != null )
        {
        itemname = itemtest[1] + itemtest[3];
        itemstyle = 'style="' + itemtest[2] + '" ';
        }
      }
    else
      { 
      var itembits = items[I].split('¬');                  // returned list with values
      itemname = itembits[0];
      itemvalue = ' value="' + itembits[1] + '"';

      // test for additional style code
      var itemstyle = '';
      var itemtest = itemname.match(/(.*)\{(.*)\}(.*)/);   // see if there's a {...}
      if ( itemtest != null )
        {
        itemname = itemtest[1] + itemtest[3];
        itemstyle = itemtest[2];
        }

      if ( (itemname.indexOf(':') == -1) && (itembits[1] == '') ) 
        {
        if ( itemstyle != '' ) itemstyle += ';';
        itemstyle += 'background-color: #ff0000';
        }      
      if ( itemstyle != '' ) itemstyle = 'style="' + itemstyle + '" ';
      }

    var fieldsize = size;
    var maxlength = '';
      var sizelook = itemname.match(/^(\d+)\.?(\d*)/);      // look for prefix nn or nn.nn
      if ( sizelook != null)
        {
        itemname = itemname.replace(/^\d+\.?\d*/, '');       // strip out any size / max prefix
        fieldsize = sizelook[1];
        if ( sizelook[2] != '' ) maxlength = ' maxlength="' + sizelook[2] + '"'; 
        }

// translate the short unique codes entered into field names that can be displayed to the user

// *********************** Collection details
      if (itemname.search(/CPC/) > -1)
	{ m_prompt = "Post Code:*";
	  if (m_dhl==1 || m_hdnl==1) {
	    document.write('<tr><td colspan="3"><b>Where is parcel to be collected from?</b></td></tr>');
	  } else {
		if (m_parcelforce==1) {
			document.write('<tr><td colspan="3"><b>Where is parcel to be collected from? (Enter your home address if self drop option selected)</b></td></tr>');
		} else {
			document.write('<tr><td colspan="3"><b>Where is the envelope to be collected from?</b></td></tr>');
		}
	  }
	  document.write ('<tr><td><SPAN CLASS="actrequiredcolor">' + m_prompt + '</td><td><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + ' VALUE="' + cookiepc + '"' + ' SIZE="' + fieldsize + '"' + maxlength + '</td>');
      	}

    }
  }
}

function setotherinfo2(pre, name, size, max, prodname) {
  pre = pre.replace(/&#124;/g, '|');		// fix |
  pre = pre.replace(/&#46;/g, '.');		// fix .		
  pre = pre.replace(/&#123;/g, '{');		// fix {		
  pre = pre.replace(/&#125;/g, '}');		// fix }		
  pre = pre.replace(/&#58;/g, ':');		// fix :		

  var prodref = name.substr(8);			// the product reference part start
  var prodref = prodref.slice(0, -1);		// lose the > char
  var p1 = prodref.indexOf('"');		// end of the text
  var prodvalue = prodref.substr(p1 + 1);	// any additional value text
  prodref = prodref.substring(0, p1);		// the actual prodref 

 // see if simple form
 if (pre.indexOf('|') == -1 ) 
  {
  // alert('Simple ' + name + ' Prodref-' + prodref + '-Value-' + prodvalue + '-');
  document.write(pre + '<INPUT TYPE=text NAME="O_' + prodref + '" ' + prodvalue + ' SIZE="' + size + '" MAXLENGTH="' + max 
                     + '" onchange="stripspecial(\'O_' + prodref + '\')">');
  }
 else
  {        // now have a complex selection
  //  alert('Complex-' + name + '- Prodref-' + prodref + '- Value-' + prodvalue + '-');
  if ( prodvalue == '')			  // we're not bouncing back with an error
    {
    var items = pre.split('|');	  // create default list from prompt text
    var S = ' value="'
    for (var I = 0; I < items.length - 1; I++) S += items[I] + '¬ ¦ '; 
    S += items[items.length - 1] + '¬';
    }
  else
    {
    p1 = prodvalue.indexOf(' VALUE="');    // we've had an error bounce
    var S = prodvalue.slice((p1 + 8), -1); // so extract the old data
    var items = S.split(' ¦ ');            // the items and their data
    S = prodvalue.slice(p1, -1);           // the value="..." substring
    }
 
// now see how many sub fields there are
  for (var I = 0; I < items.length; I++)
    {
    if ( prodvalue == '')
      {				//  simple empty list
      var itemname = items[I];
      var itemvalue = '';

      // test for additional style code
      var itemstyle = '';
      var itemtest = itemname.match(/(.*)\{(.*)\}(.*)/);   // see if there's a {...}
      if ( itemtest != null )
        {
        itemname = itemtest[1] + itemtest[3];
        itemstyle = 'style="' + itemtest[2] + '" ';
        }
      }
    else
      { 
      var itembits = items[I].split('¬');                  // returned list with values
      itemname = itembits[0];
      itemvalue = ' value="' + itembits[1] + '"';

      // test for additional style code
      var itemstyle = '';
      var itemtest = itemname.match(/(.*)\{(.*)\}(.*)/);   // see if there's a {...}
      if ( itemtest != null )
        {
        itemname = itemtest[1] + itemtest[3];
        itemstyle = itemtest[2];
        }

      if ( (itemname.indexOf(':') == -1) && (itembits[1] == '') ) 
        {
        if ( itemstyle != '' ) itemstyle += ';';
        itemstyle += 'background-color: #ff0000';
        }      
      if ( itemstyle != '' ) itemstyle = 'style="' + itemstyle + '" ';
      }

    var fieldsize = size;
    var maxlength = '';
      var sizelook = itemname.match(/^(\d+)\.?(\d*)/);      // look for prefix nn or nn.nn
      if ( sizelook != null)
        {
        itemname = itemname.replace(/^\d+\.?\d*/, '');       // strip out any size / max prefix
        fieldsize = sizelook[1];
        if ( sizelook[2] != '' ) maxlength = ' maxlength="' + sizelook[2] + '"'; 
        }

// translate the short unique codes entered into field names that can be displayed to the user

// *********************** Collection details
	if (itemname.search(/CNA/) > -1)  {
	  m_prompt = "Contact Name:*";
	  document.write ('<tr><td><SPAN CLASS="actrequiredcolor">' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + ' VALUE="' + cookiename + '"' + ' SIZE="' + fieldsize + '"' + maxlength + '</td></tr>');
	  }

      	if (itemname.search(/CA1/) > -1)  {
	  m_prompt = "Address Line 1:*";
	  document.write ('<tr><td><SPAN CLASS="actrequiredcolor">' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + ' VALUE="' + cookiea1 + '"' + ' SIZE="' + fieldsize + '"' + maxlength + '</td></tr>');
	}

      	if (itemname.search(/CA2/) > -1)  {
	  m_prompt = "Address Line 2:";
	  document.write ('<tr><td><SPAN CLASS="actrequiredcolor">' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + ' VALUE="' + cookiea2 + '"' + ' SIZE="' + fieldsize + '"' + maxlength + '</td></tr>');
	}

      	if (itemname.search(/CAT/) > -1)  {
	  m_prompt = "City/Town:*";
	  document.write ('<tr><td><SPAN CLASS="actrequiredcolor">' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + ' VALUE="' + cookiect + '"' + ' SIZE="' + fieldsize + '"' + maxlength + '</td></tr>');
	}

      	if (itemname.search(/CAC/) > -1)  {
	  m_prompt = "Country:";
	  document.write ('<tr><td>' + m_prompt + '</td><td colspan="2"><INPUT readonly ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + ' VALUE="UNITED KINGDOM"' + ' SIZE="' + fieldsize + '"' + maxlength + '</td></tr>');
	}

    	if (itemname.search(/CPH/) > -1)  {
	  		m_prompt = "Phone Number:*";
			if (m_hdnl == 1) {
				document.write ('<tr><td><SPAN CLASS="actrequiredcolor">' + m_prompt + '</td><td><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + ' VALUE="' + cookieph + '"' + ' SIZE="' + fieldsize + '"' + maxlength + '</td><td> Home Delivery network will endeavour to send you a text message with the expected collection time if you enter a mobile phone number here</td></tr>');
				} else {
				document.write ('<tr><td><SPAN CLASS="actrequiredcolor">' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + ' VALUE="' + cookieph + '"' + ' SIZE="' + fieldsize + '"' + maxlength + '</td></tr>');
			}
	}

// *************** Delivery details
      if (itemname.search(/DPC/) > -1)
	{ m_prompt = "Post Code:*";
		if (m_fedex==1) {
			document.write('<tr><td colspan="3"><b>Where is the envelope to be delivered to?</b></td></tr>');
		} else {
			document.write('<tr><td colspan="3"><b>Where is the parcel to be delivered to?</b></td></tr>');
		}
	    document.write ('<tr><td><SPAN CLASS="actrequiredcolor">' + m_prompt + '</td><td><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + itemvalue + ' SIZE="' + fieldsize + '"' + maxlength + '</td>');
    	}

    }
  }
}



function setotherinfo3(pre, name, size, max, prodname) {
  pre = pre.replace(/&#124;/g, '|');		// fix |
  pre = pre.replace(/&#46;/g, '.');		// fix .		
  pre = pre.replace(/&#123;/g, '{');		// fix {		
  pre = pre.replace(/&#125;/g, '}');		// fix }		
  pre = pre.replace(/&#58;/g, ':');		// fix :		

  var prodref = name.substr(8);			// the product reference part start
  var prodref = prodref.slice(0, -1);		// lose the > char
  var p1 = prodref.indexOf('"');		// end of the text
  var prodvalue = prodref.substr(p1 + 1);	// any additional value text
  prodref = prodref.substring(0, p1);		// the actual prodref 

 // see if simple form
 if (pre.indexOf('|') == -1 ) 
  {
  // alert('Simple ' + name + ' Prodref-' + prodref + '-Value-' + prodvalue + '-');
  document.write(pre + '<INPUT TYPE=text NAME="O_' + prodref + '" ' + prodvalue + ' SIZE="' + size + '" MAXLENGTH="' + max 
                     + '" onchange="stripspecial(\'O_' + prodref + '\')">');
  }
 else
  {        // now have a complex selection
  //  alert('Complex-' + name + '- Prodref-' + prodref + '- Value-' + prodvalue + '-');
  if ( prodvalue == '')			  // we're not bouncing back with an error
    {
    var items = pre.split('|');	  // create default list from prompt text
    var S = ' value="'
    for (var I = 0; I < items.length - 1; I++) S += items[I] + '¬ ¦ '; 
    S += items[items.length - 1] + '¬';
    }
  else
    {
    p1 = prodvalue.indexOf(' VALUE="');    // we've had an error bounce
    var S = prodvalue.slice((p1 + 8), -1); // so extract the old data
    var items = S.split(' ¦ ');            // the items and their data
    S = prodvalue.slice(p1, -1);           // the value="..." substring
    }
 
// now see how many sub fields there are
  for (var I = 0; I < items.length; I++)
    {
    if ( prodvalue == '')
      {				//  simple empty list
      var itemname = items[I];
      var itemvalue = '';

      // test for additional style code
      var itemstyle = '';
      var itemtest = itemname.match(/(.*)\{(.*)\}(.*)/);   // see if there's a {...}
      if ( itemtest != null )
        {
        itemname = itemtest[1] + itemtest[3];
        itemstyle = 'style="' + itemtest[2] + '" ';
        }
      }
    else
      { 
      var itembits = items[I].split('¬');                  // returned list with values
      itemname = itembits[0];
      itemvalue = ' value="' + itembits[1] + '"';

      // test for additional style code
      var itemstyle = '';
      var itemtest = itemname.match(/(.*)\{(.*)\}(.*)/);   // see if there's a {...}
      if ( itemtest != null )
        {
        itemname = itemtest[1] + itemtest[3];
        itemstyle = itemtest[2];
        }

      if ( (itemname.indexOf(':') == -1) && (itembits[1] == '') ) 
        {
        if ( itemstyle != '' ) itemstyle += ';';
        itemstyle += 'background-color: #ff0000';
        }      
      if ( itemstyle != '' ) itemstyle = 'style="' + itemstyle + '" ';
      }

    var fieldsize = size;
    var maxlength = '';
      var sizelook = itemname.match(/^(\d+)\.?(\d*)/);      // look for prefix nn or nn.nn
      if ( sizelook != null)
        {
        itemname = itemname.replace(/^\d+\.?\d*/, '');       // strip out any size / max prefix
        fieldsize = sizelook[1];
        if ( sizelook[2] != '' ) maxlength = ' maxlength="' + sizelook[2] + '"'; 
        }

// translate the short unique codes entered into field names that can be displayed to the user


// *************** Delivery details
	if (itemname.search(/DNA/) >-1)  {
	  if (m_bfpo == 1) {
		m_prompt = "Service Number, Rank, Name:*";
	  } else {
		m_prompt = "Contact Name:*";
	  }
	  document.write ('<tr><td><SPAN CLASS="actrequiredcolor">' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + itemvalue + ' SIZE="' + fieldsize + '"' + maxlength + '></td></tr>')
	}

    	if (itemname.search(/DA1/) >-1)	 {
	  if (m_bfpo == 1) {
		m_prompt = "Unit/Dept/Company/Job:*";
	  } else {
	  	m_prompt = "Address Line 1:*";
	  }
	  document.write ('<tr><td><SPAN CLASS="actrequiredcolor">' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + itemvalue + ' SIZE="' + fieldsize + '"' + maxlength + '></td></tr>')
	}

      	if (itemname.search(/DA2/) >-1)  {
	  if (m_bfpo == 1) {
		m_prompt = " ";
	  } else {
		  m_prompt = "Address Line 2:";
	  }
    	  document.write ('<tr><td><SPAN CLASS="actrequiredcolor">' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + itemvalue + ' SIZE="' + fieldsize + '"' + maxlength + '></td></tr>')
	}

      	if (itemname.search(/DAT/) >-1)  {
	  if (m_bfpo == 1) {
		m_prompt = "Unit/Operation Name";
	  } else {
	  	m_prompt = "City/Town:*";
	  }
	  document.write ('<tr><td><SPAN CLASS="actrequiredcolor">' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + itemvalue + ' SIZE="' + fieldsize + '"' + maxlength + '></td></tr>')
	}

      	if (itemname.search(/DAC/) > -1)  {
	  m_prompt = "Country:";
	  document.write ('<tr><td>' + m_prompt + '</td><td colspan="2"><INPUT readonly ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + ' VALUE="' + m_country + '"' + ' SIZE="' + fieldsize + '"' + maxlength + '</td></tr>');
	}

     	if (itemname.search(/DPH/) > -1)  {
	  if (m_fedex==1) {
	  	m_prompt = "Phone Number:*";
	  } else {
	  	m_prompt = "Phone Number:";
	  }
	  document.write ('<tr><td><SPAN CLASS="actrequiredcolor">' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + itemvalue + ' SIZE="' + fieldsize + '"' + maxlength + '></td></tr>')
	}

        if (itemname.search(/PWE/) > -1) {
		if (m_fedex==1) {
			m_prompt = "Maximum permitted weight of the envelope:";
			itemvalue='0.4';
			document.write('<tr><td colspan="3"><b>Envelope Details</b></td></tr>');
		    	document.write ('<tr><td>' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + ' VALUE="' + itemvalue + '"' + ' READONLY SIZE="' + fieldsize + '"' + maxlength + '> Kg</td></tr>')
		} else {
			m_prompt = "What is the ACTUAL weight of the parcel when packed? *";
			document.write('<tr><td colspan="3"><b>Parcel Details</b></td></tr>');
		    	document.write ('<tr><td><SPAN CLASS="actrequiredcolor">' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + itemvalue + ' SIZE="' + fieldsize + '"' + maxlength + '> Kg</td></tr>')
		}
        }

        if (itemname.search(/PLE/) > -1) {
		if (m_fedex==1) {
			m_prompt = "Maximum permitted length of the envelope:";
			itemvalue='30';
	  		document.write ('<tr><td>' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + ' VALUE="' + itemvalue + '"' + ' READONLY SIZE="' + fieldsize + '"' + maxlength + '> Centimetres</td></tr>');
		} else {
			m_prompt = "What is the LENGTH of the parcel when packed? *";
			document.write ('<tr><td><SPAN CLASS="actrequiredcolor">' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + itemvalue + ' SIZE="' + fieldsize + '"' + maxlength + '> Centimetres</td></tr>');
		}
	}

        if (itemname.search(/PWI/) > -1) {
		if (m_fedex==1) {
			m_prompt = "Maximum permitted width of the envelope:";
			itemvalue='21';
	  		document.write ('<tr><td>' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + ' VALUE="' + itemvalue + '"' + ' READONLY SIZE="' + fieldsize + '"' + maxlength + '> Centimetres</td></tr>');
		} else {
			m_prompt = "What is the WIDTH of the parcel when packed? *";
			document.write ('<tr><td><SPAN CLASS="actrequiredcolor">' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + itemvalue + ' SIZE="' + fieldsize + '"' + maxlength + '> Centimetres</td></tr>')
      		}
	}

     	if (itemname.search(/PHE/) > -1) {
		if (m_fedex==1) {
			m_prompt = "Maximum permitted depth of the envelope:";
			itemvalue='1';
	  		document.write ('<tr><td>' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + ' VALUE="' + itemvalue + '"' + ' READONLY SIZE="' + fieldsize + '"' + maxlength + '> Centimetres</td></tr>');
		} else {
			m_prompt = "What is the HEIGHT of the parcel when packed? *";
	  		document.write ('<tr><td><SPAN CLASS="actrequiredcolor">' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + itemvalue + ' SIZE="' + fieldsize + '"' + maxlength + '> Centimetres</td></tr>')
      		}
	 }

     	if (itemname.search(/PDE/) > -1)  {
		if (m_fedex==1) {
			m_prompt = "Type of documents being sent: *";
		} else {
			m_prompt = "Description of items being delivered: *";
		}
	  	document.write ('<tr><td><SPAN CLASS="actrequiredcolor">' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + itemvalue + ' SIZE="' + fieldsize + '"' + maxlength + '></td></tr>')
	} 

     	if (itemname.search(/PVA/) > -1) {
		if (m_fedex==1) {
			m_prompt = "Nominal value of documents:";
			itemvalue='1';
	  		document.write ('<tr><td>' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + ' VALUE="' + itemvalue + '"' + ' READONLY SIZE="' + fieldsize + '"' + maxlength + '> Pounds</td></tr>');
		} else {
			m_prompt = "Value of Items: *";
	  		document.write ('<tr><td><SPAN CLASS="actrequiredcolor">' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + itemvalue + ' SIZE="' + fieldsize + '"' + maxlength + '> Pounds</td></tr>')
		}
    	}

    	if (itemname.search(/PRE/) > -1 && m_uk==0)  {
	  	m_prompt = "Reason for export:*";
	  	document.write ('<tr><td><SPAN CLASS="actrequiredcolor">' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + itemvalue + ' SIZE="' + fieldsize + '"' + maxlength + '></td></tr>')
	}

    	if (itemname.search(/PRE/) > -1 && m_uk==1) {
	  	m_prompt = "Reason for Export:";
	  	document.write ('<tr><td><SPAN CLASS="actrequiredcolor">' + m_prompt + '</td><td colspan="2"><INPUT readonly ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + ' VALUE="Not required for UK delivery"' + ' SIZE="' + fieldsize + '"' + maxlength + '></td></tr>');
	}

    	if (itemname.search(/PSP/) > -1)  {
	  	m_prompt = "Any special instructions?";
	  	document.write ('<tr><td><SPAN CLASS="actrequiredcolor">' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + itemvalue + ' SIZE="' + fieldsize + '"' + maxlength + '></td></tr>')
	}

    	if (itemname.search(/PCO/) > -1) {
		if (m_fedex==1 || m_dhl==1 || m_hdnl==1) {
			m_prompt = "Preferred collection day: * (Note: suggested date is the earliest date available)";
		} else {
			m_prompt = "Preferred collection/drop off day * (Note: suggested date is the earliest date available)";
		}
		m_earliestcollect = setcollectdate();
		document.write ('<tr><td><SPAN CLASS="actrequiredcolor">' + m_prompt + '</td><td colspan="2"><INPUT ' + 'TYPE=text NAME="O_' + (I + 1) + '"' + ' VALUE="' + m_earliestcollect + '"' + ' SIZE="' + fieldsize + '"' + maxlength + '></td></tr>')
     	}

    }
    document.write('</table>');
  }

  if (m_dhl == 1 && m_dhlair==0) {
	if (m_country=="AUSTRIA" || m_country=="CANARY ISLANDS" || m_country=="CZECH REPUBLIC" || m_country=="DENMARK" || 
		m_country=="FINLAND" || m_country=="FRANCE" || m_country == "GERMANY" || m_country == "GREECE" ||
		m_country=="HUNGARY" || m_country == "IRELAND, REPUBLIC OF" || m_country == "ITALY" || m_country == "POLAND" ||
		m_country=="SLOVAKIA" || m_country == "SLOVENIA" || m_country == "SPAIN" || m_country == "SWEDEN") {


		switch (m_country) {
			case "CZECH REPUBLIC": 
				var URL = "Czechrepublic_validationfile.html";
				break;
			case "IRELAND, REPUBLIC OF":
				var URL = "Ireland_validationfile.html";
				break;
			case "CANARY ISLANDS":
				var URL = "Canaryislands_validationfile.html";
				break;
			default:
				var URL = m_country+"_validationfile.html"
		}    
		document.write ('<iframe id="RSIFrame" name="RSIFrame" style="width:0px; height:0px; border: 0px" src="' + URL + '"></iframe>')
	}
  }
}

// Function to set the collection date

function setcollectdate() {
var bankhols = new Array(24); 
bankhols[0]=new Date("12/22/2009");
bankhols[1]=new Date("12/23/2009");
bankhols[2]=new Date("12/24/2009");
bankhols[3]=new Date("12/25/2009");	
bankhols[4]=new Date("12/28/2009");	
bankhols[5]=new Date("12/29/2009");	
bankhols[6]=new Date("12/30/2009");
bankhols[7]=new Date("12/31/2009");	
bankhols[8]=new Date("01/07/2010");
bankhols[9]=new Date("04/02/2010");
bankhols[10]=new Date("04/05/2010");
bankhols[11]=new Date("05/03/2010");	
bankhols[12]=new Date("05/31/2010");	
bankhols[13]=new Date("08/30/2010");	
bankhols[14]=new Date("12/21/2010");	
bankhols[15]=new Date("12/22/2010");
bankhols[16]=new Date("12/23/2010");
bankhols[17]=new Date("12/24/2010");	
bankhols[18]=new Date("12/27/2010");	
bankhols[19]=new Date("12/28/2010");
bankhols[20]=new Date("12/29/2010");	
bankhols[21]=new Date("12/30/2010");	
bankhols[22]=new Date("12/31/2010");
bankhols[23]=new Date("01/03/2011");


// First find the first day that the order can be processed by us and then set the 
// earliest collection day accordingly

var m_earliestprocess = new Date();
var todaytime = m_earliestprocess.getHours()
if (todaytime > 16) {
	m_earliestprocess.setDate(m_earliestprocess.getDate()+1)
}

var m_earliestcollect = m_earliestprocess; 

// now find the earliest collection day based on normal working days
var processday = m_earliestprocess.getDay();  

if (processday==1 || processday==2 || processday==3 || processday==4) {	// Monday, Tues, Wed, Thurs
	m_earliestcollect.setDate(m_earliestcollect.getDate()+1)	
}

if (processday==5) {		// Fri
	m_earliestcollect.setDate(m_earliestcollect.getDate()+3)	
}

// 30/7/08 - add in Saturday and Sunday to processing date. Collection date = Sat + 2 and Sunday +1
if (processday==6) {		// Sat
	m_earliestcollect.setDate(m_earliestcollect.getDate()+2)	
}
if (processday==7) {		// Sun
	m_earliestcollect.setDate(m_earliestcollect.getDate()+1)	
}

 
// now check that the earliest collection day isn't a bank holiday. If so increment the days
for (j=0;j<50;j++) {
	sw_found=false
	if (m_earliestcollect.getDay()==6 || m_earliestcollect.getDay()==0) {
		sw_found=true
	}

	m_tempdate = m_earliestcollect.getDate();
	m_tempmonth = m_earliestcollect.getMonth();
	m_tempfullyear = m_earliestcollect.getFullYear();
	for (i=0; i<=23; i++) {
		if (m_tempdate==bankhols[i].getDate() && m_tempmonth==bankhols[i].getMonth() && m_tempfullyear==bankhols[i].getFullYear()) {
			sw_found=true;
			break;  
		}
	}

	if (sw_found==true) {
		m_earliestcollect.setDate(m_earliestcollect.getDate()+1)
	} else {
		break;
	} 
} 

m_earliestcollect  = m_earliestcollect.getDate()+"/"+(m_earliestcollect.getMonth()+1)+"/"+m_earliestcollect.getFullYear()
return m_earliestcollect
}



// **************************************************************************
// Function to validate entered data against a product
// **************************************************************************

function deliveryCheck(p_prodname, p_prodref) {
	var bankhols = new Array(24); 
	bankhols[0]=new Date("12/22/2009");
	bankhols[1]=new Date("12/23/2009");
	bankhols[2]=new Date("12/24/2009");
	bankhols[3]=new Date("12/25/2009");	
	bankhols[4]=new Date("12/28/2009");	
	bankhols[5]=new Date("12/29/2009");	
	bankhols[6]=new Date("12/30/2009");
	bankhols[7]=new Date("12/31/2009");	
	bankhols[8]=new Date("01/07/2010");
	bankhols[9]=new Date("04/02/2010");
	bankhols[10]=new Date("04/05/2010");
	bankhols[11]=new Date("05/03/2010");	
	bankhols[12]=new Date("05/31/2010");	
	bankhols[13]=new Date("08/30/2010");	
	bankhols[14]=new Date("12/21/2010");	
	bankhols[15]=new Date("12/22/2010");
	bankhols[16]=new Date("12/23/2010");
	bankhols[17]=new Date("12/24/2010");	
	bankhols[18]=new Date("12/27/2010");	
	bankhols[19]=new Date("12/28/2010");
	bankhols[20]=new Date("12/29/2010");	
	bankhols[21]=new Date("12/30/2010");	
	bankhols[22]=new Date("12/31/2010");
	bankhols[23]=new Date("01/03/2011");

//	concat (p_prodref)
	if (concat (p_prodref)) {
	} else {
		return false
	};

// check if this is a DHL delivery
	if (p_prodname.indexOf("DHL") > -1)
	{
		m_dhl = 1;
		if (p_prodname.toUpperCase().indexOf("AIR SERVICE") > -1) {
			m_dhlair = 1;
		} else {
			m_dhlair = 0;
		}
	} else {
		m_dhl = 0;
	}

// check if this is a Fed Ex delivery
	if (p_prodname.toUpperCase().indexOf("FEDEX") > -1)
	{
		m_fedex = 1;
	} else {
		m_fedex = 0;
	}

// check if this is a Parcelforce Ex delivery
	if (p_prodname.toUpperCase().indexOf("PARCELFORCE") > -1)
	{
		m_parcelforce = 1;
	} else {
		m_parcelforce = 0;
	}

// check if this is a Home Delivery Network delivery
	if (p_prodname.toUpperCase().indexOf("HOME DELIVERY NETWORK") > -1)
	{
		m_hdnl = 1;
		if (p_prodname.toUpperCase().indexOf("OVERSIZE") > 1)
		{
			m_hdnloversize = 1;
		} else {
			m_hdnloversize = 0;
		}
		if (p_prodname.toUpperCase().indexOf("BFPO") >1)
		{
			m_bfpo = 1;
		} else {
			m_bfpo = 0;
		}
	} else {
		m_hdnl = 0;
		m_hdnloversize = 0;
		m_bfpo = 0;
	}

// see if the guaranteed collection option has been chosen
// if we wish to suspend guaranteed collections then add test that checks m_guaranteed and puts up error
// alert
	m_guaranteed=0;
	var temp=document.getElementsByName("v_"+p_prodref+"_2");
	if (temp[1]) {
		if(temp[1].checked) 
		{
			m_guaranteed = 1;
		}
	}

// If this is a Parcelforce delivery, see if the self drop option has been chosen
	m_selfdrop=0;
	if (m_parcelforce==1) 
	{
		var temp=document.getElementsByName("v_"+p_prodref+"_2");
		if (temp[2]) {
			if(temp[2].checked) 
			{
				m_selfdrop = 1;
			}
		}
	}

// See if enhanced comp option has been chosen. Only available on Parcelforce & HDNL services
	m_enhanced=0;
	if (m_parcelforce==1 || m_hdnl==1) 
	{
		var temp=document.getElementsByName("v_"+p_prodref+"_1");
		if (temp[0]) {
			if(temp[0].selectedIndex > 0) 
			{
				m_enhanced = 1;
			}	
		}
	}


// Post code
	var pccollection=document.getElementsByName("O_1");
	test=pccollection[0].value;
	test = test.toUpperCase(); //Change to uppercase
// save for later testing against delivery post code
	m_collectpc = test;

	if (!(validateukpostcodeformat(pccollection[0]))) {return false;}

// check that a standard DHL/Fed Ex or HDNL delivery is not being picked up from an extended area
	var m_outbound = m_collectpc.substring(0,2);
	var m_zone = m_collectpc.substring(2,4);

	if (m_hdnl==1) {
		if (m_outbound=="IV" || m_outbound=="HS" || m_outbound=="KW" || m_outbound=="ZE" || m_outbound=="BT" || m_outbound=="IM") {
			alert ("Home Delivery Network cannot collect from this postcode. Please use a Parcelforce service.");
			pccollection[0].focus();
			return false;
		}

		if (m_outbound=="KA" && (Number(m_zone) >=27 && Number(m_zone)<=28)) {
			alert ("Home Delivery Network cannot collect from this postcode. Please use a Parcelforce service.");
			pccollection[0].focus();
			return false;
		}

		if (m_outbound=="PA" && (Number(m_zone) >=20 && Number(m_zone)<=50)) {
			alert ("Home Delivery Network cannot collect from this postcode. Please use a Parcelforce service.");
			pccollection[0].focus();
			return false;
		}				

		if (m_outbound=="PA" && (Number(m_zone) >=60 && Number(m_zone)<=78)) {
			alert ("Home Delivery Network cannot collect from this postcode. Please use a Parcelforce service.");
			pccollection[0].focus();
			return false;
		}			

		if (m_outbound=="PH" && (Number(m_zone) >=19 && Number(m_zone)<=44)) {
			alert ("Home Delivery Network cannot collect from this postcode. Please use a Parcelforce service.");
			pccollection[0].focus();
			return false;
		}			

		if (m_outbound=="PH" && (Number(m_zone) >=49 && Number(m_zone)<=50)) {
			alert ("Home Delivery Network cannot collect from this postcode. Please use a Parcelforce service.");
			pccollection[0].focus();
			return false;
		}			

			
		if (m_outbound=="TR" && (Number(m_zone) >=21 && Number(m_zone)<=25)) {
			alert ("Home Delivery Network cannot collect from this postcode. Please use a Parcelforce service.");
			pccollection[0].focus();
			return false;
		}

		if (m_outbound=="AB") {
			alert ("Home Delivery Network cannot collect from this postcode. Please use a Parcelforce service.");
			pccollection[0].focus();
			return false;
		}

		if (m_outbound=="DD" && (Number(m_zone) >=8 && Number(m_zone)<=11)) {
			alert ("Home Delivery Network cannot collect from this postcode. Please use a Parcelforce service.");
			pccollection[0].focus();
			return false;
		}

		if (m_outbound=="BF") {
			alert ("Sorry. We cannot pickup from this postcode.");
			pccollection[0].focus();
			return false;
		}
	}

	if (m_dhl==1 || m_fedex==1) {
		if (m_outbound=="IV" || m_outbound=="HS" || m_outbound=="KW" || m_outbound=="ZE" || m_outbound=="BT" || m_outbound=="IM") {
			alert ("DHL and FedEx cannot collect from this postcode. Please use a Parcelforce service.");
			pccollection[0].focus();
			return false;
		}

		if (m_outbound=="KA" && (Number(m_zone) >=27 && Number(m_zone)<=28)) {
			alert ("DHL and FedEx cannot collect from this postcode. Please use a Parcelforce service.");
			pccollection[0].focus();
			return false;
		}

		if (m_outbound=="PA" && (Number(m_zone) >=20 && Number(m_zone)<=49)) {
			alert ("DHL and FedEx cannot collect from this postcode. Please use a Parcelforce service.");
			pccollection[0].focus();
			return false;
		}				

		if (m_outbound=="PA" && (Number(m_zone) >=60 && Number(m_zone)<=78)) {
			alert ("DHL and FedEx cannot collect from this postcode. Please use a Parcelforce service.");
			pccollection[0].focus();
			return false;
		}			

		if (m_outbound=="PH" && (Number(m_zone) >=17 && Number(m_zone)<=44)) {
			alert ("DHL and FedEx cannot collect from this postcode. Please use a Parcelforce service.");
			pccollection[0].focus();
			return false;
		}			

		if (m_outbound=="PH" && (Number(m_zone) >=49 && Number(m_zone)<=50)) {
			alert ("DHL and FedEx cannot collect from this postcode. Please use a Parcelforce service.");
			pccollection[0].focus();
			return false;
		}			

		if (m_outbound=="PO" && (Number(m_zone) >=30 && Number(m_zone)<=41)) {
			alert ("DHL and FedEx cannot collect from this postcode. Please use a Parcelforce service.");
			pccollection[0].focus();
			return false;
		}			
			
		if (m_outbound=="TR" && (Number(m_zone) >=21 && Number(m_zone)<=25)) {
			alert ("DHL and FedEx cannot collect from this postcode. Please use a Parcelforce service.");
			pccollection[0].focus();
			return false;
		}

		if (m_outbound=="AB" && Number(m_zone) == 31) {
			alert ("DHL and FedEx cannot collect from this postcode. Please use a Parcelforce service.");
			pccollection[0].focus();
			return false;
		}

		if (m_outbound=="AB" && (Number(m_zone) >=33 && Number(m_zone)<=38)) {
			if (m_collectpc=="AB37 9EX") {
			} 
			else 
			{alert ("DHL and FedEx cannot collect from this postcode. Please use a Parcelforce service.");
				pccollection[0].focus();
				return false;
			}
			
		}

		if (m_outbound=="AB" && (Number(m_zone) >=44 && Number(m_zone)<=45)) {
			alert ("DHL and FedEx cannot collect from this postcode. Please use a Parcelforce service.");
			pccollection[0].focus();
			return false;
		}

		if (m_outbound=="AB" && (Number(m_zone) >=53 && Number(m_zone)<=56)) {
			alert ("DHL and FedEx cannot collect from this postcode. Please use a Parcelforce service.");
			pccollection[0].focus();
			return false;
		}	
	}
	
// Stop guaranteed collections from extended areas. 
	if (m_guaranteed==1) {
		if (m_outbound=="IV" || m_outbound=="HS" || m_outbound=="KW" || m_outbound=="ZE" || m_outbound=="BT" || m_outbound=="IM") {
			alert ("Sorry, we cannot offer a guaranteed collection from this post code.");
			pccollection[0].focus();
			return false;
		}

		if (m_outbound=="KA" && (Number(m_zone) >=27 && Number(m_zone)<=28)) {
			alert ("Sorry, we cannot offer a guaranteed collection from this post code.");
			pccollection[0].focus();
			return false;
		}

		if (m_outbound=="PA" && (Number(m_zone) >=20 && Number(m_zone)<=49)) {
			alert ("Sorry, we cannot offer a guaranteed collection from this post code.");
			pccollection[0].focus();
			return false;
		}				

		if (m_outbound=="PA" && (Number(m_zone) >=60 && Number(m_zone)<=78)) {
			alert ("Sorry, we cannot offer a guaranteed collection from this post code.");
			pccollection[0].focus();
			return false;
		}			

		if (m_outbound=="PH" && (Number(m_zone) >=17 && Number(m_zone)<=44)) {
			alert ("Sorry, we cannot offer a guaranteed collection from this post code.");
			pccollection[0].focus();
			return false;
		}			

		if (m_outbound=="PH" && (Number(m_zone) >=49 && Number(m_zone)<=50)) {
			alert ("Sorry, we cannot offer a guaranteed collection from this post code.");
			pccollection[0].focus();
			return false;
		}			

		if (m_outbound=="PO" && (Number(m_zone) >=30 && Number(m_zone)<=41)) {
			alert ("Sorry, we cannot offer a guaranteed collection from this post code.");
			pccollection[0].focus();
			return false;
		}			
			
		if (m_outbound=="TR" && (Number(m_zone) >=21 && Number(m_zone)<=25)) {
			alert ("Sorry, we cannot offer a guaranteed collection from this post code.");
			pccollection[0].focus();
			return false;
		}			
	}

// Check for Jersey/Guernsey pickup
	if (m_outbound=="JE") {
		alert ("Sorry - we are not able to collect from an address in Jersey");
		pccollection[0].focus();
		return false;
	}			

	if (m_outbound=="GY") {
		alert ("Sorry - we are not able to collect from an address in Guernsey");
		pccollection[0].focus();
		return false;
	}			

// Collection contact name.
	var pccollection=document.getElementsByName("O_2");
	if (!(validatename(pccollection[0]))) { return false; }

// Collection address 1.
	var pccollection=document.getElementsByName("O_3");
	if (!(validateaddrline(pccollection[0],1))) { return false; }

// Collection address 2.
	var pccollection=document.getElementsByName("O_4");
	if (!(validateaddrline(pccollection[0],2))) { return false; }

// Collection city/town.
	var pccollection=document.getElementsByName("O_5");
	if (!(validateaddrline(pccollection[0],3))) { return false; }

// Collection Phone number.
	var pccollection=document.getElementsByName("O_7");
	if (!(validatephone(pccollection[0],"M"))) { return false; }

// ************************************ Now delivery details ****************************************************
	var pccollection=document.getElementsByName("O_8");
	test=pccollection[0].value
	m_deliverypc = test.toUpperCase(); //Change to uppercase
	size=m_deliverypc.length;
	while (m_deliverypc.slice(0,1) == " ")
		{m_deliverypc = m_deliverypc.substr(1,size-1);size = m_deliverypc.length}
	while(m_deliverypc.slice(size-1,size)== " ") //Strip trailing spaces
		{m_deliverypc = m_deliverypc.substr(0,size-1);size = m_deliverypc.length}
	pccollection[0].value = m_deliverypc; //write back to form field

	if (size == 0) { // post code must be entered
		if (m_country == "UNITED KINGDOM") {
			alert("Post code must be entered");
			pccollection[0].focus();
			return false;
		} else {
			if (m_country == "IRELAND, REPUBLIC OF") {
				alert("Post code must be entered, even for Ireland. Just enter a Zero if you are sending to an area in Ireland that doesn't use postcodes");
				pccollection[0].focus();
				return false;				

			} else {
				alert("Post code must be entered, even for non UK deliveries");
				pccollection[0].focus();
				return false;
			}
		}
	}

	if (m_bfpo == 1) {
		if (!(validateBFPOpostcodeformat(pccollection[0]))) {return false;}
	} else {
		if (m_country=="UNITED KINGDOM" || 
			m_country =="JERSEY" ||
			m_country =="GUERNSEY") {

			if (!(validateukpostcodeformat(pccollection[0]))) {return false;}

			var m_outbound = m_deliverypc.substring(0,2);
			var m_zone = m_deliverypc.substring(2,4);		
		} else {
			if(!(validateforeignpostcode(m_country, pccollection[0]))) { return false; }
		}
	}

	if (m_country == "UNITED KINGDOM") {
		if (p_prodname.indexOf("ISLANDS") == -1) {
			if (m_hdnl == 1) {		
				if (m_outbound=="IV" || m_outbound=="HS" || m_outbound=="KW" || m_outbound=="ZE" || m_outbound=="BT" || m_outbound=="IM") {
					alert ("Home Delivery Network cannot deliver to this postcode under this service. Please use the Parcelforce Islands, Highlands & Northern Ireland product " +
					"\rfor delivery to this post code.");
					pccollection[0].focus();
					return false;
				}

				if (m_outbound=="KA" && (Number(m_zone) >=27 && Number(m_zone)<=28)) {
					alert ("Home Delivery Network cannot deliver to this postcode under this service. Please use the Parcelforce Islands, Highlands & Northern Ireland product " +
					"\rfor delivery to this post code.");
					pccollection[0].focus();
					return false;
				}

				if (m_outbound=="PA" && (Number(m_zone) >=20 && Number(m_zone)<=50)) {
					alert ("Home Delivery Network cannot deliver to this postcode under this service. Please use the Parcelforce Islands, Highlands & Northern Ireland product " +
					"\rfor delivery to this post code.");
					pccollection[0].focus();
					return false;
				}				

				if (m_outbound=="PA" && (Number(m_zone) >=60 && Number(m_zone)<=78)) {
					alert ("Home Delivery Network cannot deliver to this postcode under this service. Please use the Parcelforce Islands, Highlands & Northern Ireland product " +
					"\rfor delivery to this post code.");
					pccollection[0].focus();
					return false;
				}			

				if (m_outbound=="PH" && (Number(m_zone) >=19 && Number(m_zone)<=44)) {
					alert ("Home Delivery Network cannot deliver to this postcode under this service. Please use the Parcelforce Islands, Highlands & Northern Ireland product " +
					"\rfor delivery to this post code.");
					pccollection[0].focus();
					return false;
				}			

				if (m_outbound=="PH" && (Number(m_zone) >=49 && Number(m_zone)<=50)) {
					alert ("Home Delivery Network cannot deliver to this postcode under this service. Please use the Parcelforce Islands, Highlands & Northern Ireland product " +
					"\rfor delivery to this post code.");
					pccollection[0].focus();
					return false;
				}			

				if (m_outbound=="PO" && (Number(m_zone) >=30 && Number(m_zone)<=41)) {
					alert ("Home Delivery Network cannot deliver to this postcode under this service. Please use the Parcelforce Islands, Highlands & Northern Ireland product " +
					"\rfor delivery to this post code.");
					pccollection[0].focus();
					return false;
				}			
		
				if (m_outbound=="TR" && (Number(m_zone) >=21 && Number(m_zone)<=25)) {
					alert ("Home Delivery Network cannot deliver to this postcode under this service. Please use the Parcelforce Islands, Highlands & Northern Ireland product " +
					"\rfor delivery to this post code.");
					pccollection[0].focus();
					return false;
				}			

				if (m_outbound=="AB") {
					alert ("Home Delivery Network cannot deliver to this postcode. Please use a Parcelforce service.");
					pccollection[0].focus();
					return false;
				}

				if (m_outbound=="DD" && (Number(m_zone) >=8 && Number(m_zone)<=11)) {
					alert ("Home Delivery Network cannot deliver to this postcode. Please use a Parcelforce service.");
					pccollection[0].focus();
					return false;
				}

				if (m_outbound=="BF") {
					alert ("Home Delivery Network cannot deliver to this postcode. Please use a Parcelforce service.");
					pccollection[0].focus();
					return false;
				}
			}

			if (m_parcelforce == 1 || m_dhl==1 || m_fedex==1) {		
				if (m_outbound=="IV" || m_outbound=="HS" || m_outbound=="KW" || m_outbound=="ZE" || m_outbound=="BT" || m_outbound=="IM") {
					alert ("Please use the Parcelforce Islands, Highlands & Northern Ireland product " +
					"\rfor delivery to this post code.");
					pccollection[0].focus();
					return false;
				}

				if (m_outbound=="KA" && (Number(m_zone) >=27 && Number(m_zone)<=28)) {
					alert ("Please use the Parcelforce Islands, Highlands & Northern Ireland product " +
					"\rfor delivery to this post code.");
					pccollection[0].focus();
					return false;
				}

				if (m_outbound=="PA" && (Number(m_zone) >=20 && Number(m_zone)<=49)) {
					alert ("Please use the Parcelforce Islands, Highlands & Northern Ireland product " +
					"\rfor delivery to this post code.");
					pccollection[0].focus();
					return false;
				}				

				if (m_outbound=="PA" && (Number(m_zone) >=60 && Number(m_zone)<=78)) {
					alert ("Please use the Parcelforce Islands, Highlands & Northern Ireland product " +
					"\rfor delivery to this post code.");
					pccollection[0].focus();
					return false;
				}			

				if (m_outbound=="PH" && (Number(m_zone) >=17 && Number(m_zone)<=44)) {
					alert ("Please use the Parcelforce Islands, Highlands & Northern Ireland product " +
					"\rfor delivery to this post code.");
					pccollection[0].focus();
					return false;
				}			

				if (m_outbound=="PH" && (Number(m_zone) >=49 && Number(m_zone)<=50)) {
					alert ("Please use the Parcelforce Islands, Highlands & Northern Ireland product " +
					"\rfor delivery to this post code.");
					pccollection[0].focus();
					return false;
				}			

				if (m_outbound=="PO" && (Number(m_zone) >=30 && Number(m_zone)<=41)) {
					alert ("Please use the Parcelforce Islands, Highlands & Northern Ireland product " +
					"\rfor delivery to this post code.");
					pccollection[0].focus();
					return false;
				}			
		
				if (m_outbound=="TR" && (Number(m_zone) >=21 && Number(m_zone)<=25)) {
					alert ("Please use the Parcelforce Islands, Highlands & Northern Ireland product " +
					"\rfor delivery to this post code.");
					pccollection[0].focus();
					return false;
				}			
			}	

			if (m_dhl==1 || m_fedex==1) {
				if (m_outbound=="AB" && Number(m_zone) == 31) {
					alert ("DHL and FedEx cannot deliver to this postcode. Please use the Parcelforce Islands, Highlands & Northern Ireland product ");
					pccollection[0].focus();
					return false;
				}
	
				if (m_outbound=="AB" && (Number(m_zone) >=33 && Number(m_zone)<=38)) {
					alert ("DHL and FedEx cannot deliver to this postcode. Please use the Parcelforce Islands, Highlands & Northern Ireland product ");
					pccollection[0].focus();
					return false;
				}

				if (m_outbound=="AB" && (Number(m_zone) >=44 && Number(m_zone)<=45)) {
					alert ("DHL and FedEx cannot deliver to this postcode. Please use the Parcelforce Islands, Highlands & Northern Ireland product ");
					pccollection[0].focus();
					return false;
				}

				if (m_outbound=="AB" && (Number(m_zone) >=53 && Number(m_zone)<=56)) {
					alert ("DHL and FedEx cannot deliver to this postcode. Please use the Parcelforce Islands, Highlands & Northern Ireland product ");
					pccollection[0].focus();
					return false;
				}
			}
		}

		if (m_outbound=="JE") {
			alert ("Please use the Europe/Channel Islands/Jersey product " +
			"\rfor delivery to this post code.");
			pccollection[0].focus();
			return false;
		}			

		if (m_outbound=="GY") {
			alert ("Please use the Europe/Channel Islands/Guernsey product " +
			"\rfor delivery to this post code.");
			pccollection[0].focus();
			return false;
		}			
	}

	
	if (m_country.substring(0,6)=="JERSEY") {
		if (m_outbound!="JE") {
			alert ("Only JE postcodes are valid for Jersey");
			pccollection[0].focus();
			return false;
		}			
	}
	
	if (m_country.substring(0,8)=="GUERNSEY") {
		if (m_outbound!="GY") {
			alert ("Only GY postcodes are valid for Guernsey");
			pccollection[0].focus();
			return false;
		}				
	}



// Delivery contact name.
	var pccollection=document.getElementsByName("O_9");
	if (!(validatename(pccollection[0]))) { return false; }

// Delivery address 1.
	var pccollection=document.getElementsByName("O_10");
	if (!(validateaddrline(pccollection[0],1))) { return false; }

// Delivery address 2. 
	var pccollection=document.getElementsByName("O_11");
// m_delivaddr2 used in handle response later to check outliers
	m_delivaddr2 = pccollection[0].value
	size = m_delivaddr2.length
	while (m_delivaddr2.slice(0,1) == " ") {
		m_delivaddr2 = m_delivaddr2.substr(1,size-1);size = m_delivaddr2.length
	}
	while(m_delivaddr2.slice(size-1,size)== " ") { //Strip trailing spaces
		m_delivaddr2 = m_delivaddr2.substr(0,size-1);size = m_delivaddr2.length
	}
	m_delivaddr2 = m_delivaddr2.toUpperCase();

	if (!(validateaddrline(pccollection[0],2))) { return false; }

// Delivery city/town.
	var pccollection=document.getElementsByName("O_12");
// m_delivtown used in handle response later to check outliers
	m_delivtown = pccollection[0].value
	size = m_delivtown.length
	while (m_delivtown.slice(0,1) == " ") {
		m_delivtown = m_delivtown.substr(1,size-1);size = m_delivtown.length
	}
	while(m_delivtown.slice(size-1,size)== " ") { //Strip trailing spaces
		m_delivtown = m_delivtown.substr(0,size-1);size = m_delivtown.length
	}
	m_delivtown = m_delivtown.toUpperCase();

	if (!(validateaddrline(pccollection[0],3))) { return false; }

// Check for DHL remote areas, see previous comment re why portugal is excluded
	if (m_dhl == 1 && m_dhlair==0) {
		if (m_country=="AUSTRIA" || m_country=="CANARY ISLANDS" || m_country=="CZECH REPUBLIC" || m_country=="DENMARK" || 
			m_country=="FINLAND" || m_country=="FRANCE" || m_country == "GERMANY" || m_country == "GREECE" ||
			m_country=="HUNGARY" || m_country == "IRELAND, REPUBLIC OF" || m_country == "ITALY" || m_country == "POLAND" ||
			m_country=="SLOVAKIA" || m_country == "SLOVENIA" || m_country == "SPAIN" || m_country == "SWEDEN") {

			// get the iFrame to pick up the remote area details
			var oIframe = document.getElementById("RSIFrame");
			var oDoc = oIframe.contentWindow || oIframe.contentDocument;
			if (oDoc.document) {
			       	oDoc = oDoc.document;
			}
			var dataEl = oDoc.getElementById("ZIPS")
			var zipsColl = dataEl.childNodes
			var numZips = zipsColl.length

			// iterate through the collection of zip Names and see if we have the one we are after
			var remotefound = 0;
			if (m_country=="IRELAND, REPUBLIC OF") {

  // get the delivery address line 2 and the town to compare against the village returned from the validation file
  				for (var q=0; q<numZips; q++) {
					if (zipsColl[q].nodeType!=1) continue; // it's not an element node, let's skedaddle
					if (m_delivtown.indexOf(zipsColl[q].id) > -1 || m_delivaddr2.indexOf(zipsColl[q].id) > -1) {
						m_temp = m_delivtown.indexOf(zipsColl[q].id);
						if (m_temp > -1) {
							if (m_temp==0) {	// start of string
								if (m_delivtown.length == zipsColl[q].id.length) {
									remotefound = 1;
								} else {
                                    					if (m_delivtown.charAt(zipsColl[q].id.length) == " " || m_delivtown.charAt(zipsColl[q].id.length) == ",") {
                                      						remotefound = 1;
									}
								}
							} else {		// match found but not start of string
								if (m_temp + zipsColl[q].id.length >= m_delivtown.length) {	// end of string
                                    					if (m_delivtown.charAt(m_temp-1) == " " || m_delivtown.charAt(m_temp - 1) == ",") {
                                        					remotefound = 1;
                                    					}
								} else { 	// middle of string
									if ((m_delivtown.charAt(m_temp-1) == " " || m_delivtown.charAt(m_temp-1) == ",") && (m_delivtown.charAt(zipsColl[q].id.length+m_temp) == " " || m_delivtown.charAt(zipsColl[q].id.length+m_temp)==",")) {
                                        					remotefound = 1;
                                    					}
								}
							}
						}

						m_temp = m_delivaddr2.indexOf(zipsColl[q].id);
						if (m_temp > -1) {
							if (m_temp==0) {	// start of string
								if (m_delivaddr2.length == zipsColl[q].id.length) {
									remotefound = 1;
								} else {	// match not at start of address line
									if (zipsColl[q].id.toUpperCase() == "STREET" && m_delivaddr2.toUpperCase() != "STREET") {
									} else {
			                                  			if (m_delivaddr2.charAt(zipsColl[q].id.length) == " " || m_delivaddr2.charAt(zipsColl[q].id.length) == ",") {
			                                      				remotefound = 1;
										}
									}
								}
							} else { 	// match found but not at start of string
								if (zipsColl[q].id.toUpperCase() == "STREET" && m_delivaddr2.toUpperCase() != "STREET") {
								} else {
									if (m_temp + zipsColl[q].id.length >= m_delivaddr2.length) {
			                                  			if (m_delivaddr2.charAt(m_temp-1) == " " || m_delivaddr2.charAt(m_temp-1) == ",") {
											remotefound = 1;
			                                    			}
									} else { // middle of string
										if ((m_delivaddr2.charAt(m_temp-1) == " " || m_delivaddr2.charAt(m_temp-1) == ",") && (m_delivaddr2.charAt(zipsColl[q].id.length+m_temp) == " " || m_delivtown.charAt(zipsColl[q].id.length+m_temp)==",")) {
				                                      			remotefound = 1;
			                                   			}
									}
								}
							}
						}
					}
				}
			  } else {
			  	for (var q=0; q<numZips; q++) {
					if (zipsColl[q].nodeType!=1) continue; // it's not an element node, let's skedaddle
					if (zipsColl[q].id == m_deliverypc) {
						remotefound = 1;
					}
			  	}
			  }

			if (remotefound==1) {
				alert ("I'm afraid that the destination address that you have specified appears to be in a DHL remote area and cannot be delivered under this DHL ROAD service.\n\nYou WILL be able to ship to this address using a Parcelforce or a DHL Air express service if one exists to this country so please choose one of those services.");
				var pccollection=document.getElementsByName("O_8");
				pccollection[0].focus();
				return false;
			}	
		}	
	}

// Delivery Phone number. 
	var pccollection=document.getElementsByName("O_14");
	if (m_fedex == 1) {
		if (!(validatephone(pccollection[0],"M"))) { return false; }
	} else {
		if (!(validatephone(pccollection[0],"O"))) { return false; }
	}

// ******************************************************************* Now parcel details
// product weight
	if (m_dhl==1 || m_parcelforce==1 || m_hdnl==1) {
		pccollection=document.getElementsByName("O_15");
		if (isNaN(pccollection[0].value)) {
			alert ("The parcel weight that you have quoted is invalid")
			pccollection[0].focus();
			return false;
		}

		m_parcelweight=pccollection[0].value;
		size=m_parcelweight.length;
		while (m_parcelweight.slice(0,1) == "0" || m_parcelweight.slice(0,1) == " ") // strip leading zeroes & spaces
			{m_parcelweight = m_parcelweight.substr(1,size-1);size = m_parcelweight.length}	
		while (m_parcelweight.slice(size-1,size)== " ") //Strip trailing spaces
			{m_parcelweight = m_parcelweight.substr(0,size-1);size = m_parcelweight.length}	
		m_parcelweight = Number(m_parcelweight);	
		if (m_parcelweight <= 0) { 
			alert ("Weight of parcel must be entered.");
			pccollection[0].focus();
			return false;
		}
// Get the product weight from the product name unless it is a Fed Ex document delivery service in which case the maximum weight is 400 grams
// and cannot be changed by the user so no need to validate
		m_lastpos = m_product.toUpperCase().indexOf("KG")
		m_startpos = m_lastpos
		while(m_product.charAt(m_startpos)!= " ") {
		    m_startpos = m_startpos-1
		}
		var m_productweight = m_product.substring(m_startpos+1, m_lastpos);
// now compare entered weight against maximum for this delivery
		if (m_parcelweight > Number(m_productweight)) { 
			alert ("Weight of parcel is above the maximum of " + m_productweight + "KG for this delivery.");
			pccollection[0].focus();
			return false;
		}
	}

// calculate the maximum dimensions for the parcel. set the default max dimensions
	if (m_dhl==1 || m_parcelforce==1 || m_hdnl==1) {
		if (m_dhl==1) {
			m_max_len = 120;
			m_max_width = 60;
			m_max_volume = 0.17;
		} else {
			if (m_parcelforce==1) {
				m_max_len = 150;	
				m_max_girth = 300; 
				if (m_country=="ARGENTINA" || m_country=="AUSTRALIA" || m_country=="BRAZIL" || 
					m_country=="CHINA" || m_country=="MALAYSIA" || m_country=="NEW ZEALAND" ||
					m_country=="ROMANIA" || m_country=="LATVIA" || m_country=="RUSSIA" ||
					m_country=="UKRAINE" || m_country == "UNITED STATES OF AMERICA" || 
					m_country=="PHILIPPINES" || m_country=="SAUDI ARABIA") {
					m_max_len = 105;
					m_max_girth = 200; 
				}
			} else {
				if (m_hdnloversize==1) {
					m_max_len=225;
				} else {
					m_max_len = 100;	
				}
				m_max_width = 60; 
				m_max_volume = 0.45;
			}
		}

// Validate parcel length
		pccollection=document.getElementsByName("O_16");
		if (isNaN(pccollection[0].value)) {
			alert ("The parcel length that you have quoted is invalid");
			pccollection[0].focus();
			return false;
		}

		m_parcellength=pccollection[0].value;
		size=m_parcellength.length;
		while (m_parcellength.slice(0,1) == "0" || m_parcellength.slice(0,1) == " ") // strip leading zeroes & spaces
			{m_parcellength = m_parcellength.substr(1,size-1);size = m_parcellength.length}	
		while (m_parcellength.slice(size-1,size)== " ") //Strip trailing spaces
			{m_parcellength = m_parcellength.substr(0,size-1);size = m_parcellength.length}	
		m_parcellength = Number(m_parcellength);	
	
		if (m_parcellength <1) {
			alert ("The parcel length must be at least 1cm.");
			pccollection[0].focus();
			return false;
		}

		if (m_parcellength > m_max_len) {
			alert ("The parcel length that you have entered is more than the " + m_max_len + "CM permitted.");
			pccollection[0].focus();
			return false;
		}

// validate parcel width
		pccollection=document.getElementsByName("O_17");
		if (isNaN(pccollection[0].value)) {
			alert ("The parcel width that you have quoted is invalid");
			pccollection[0].focus();
			return false;
		}

		m_parcelwidth=pccollection[0].value;
		size=m_parcelwidth.length;
		while (m_parcelwidth.slice(0,1) == "0" || m_parcelwidth.slice(0,1) == " ") // strip leading zeroes & spaces
			{m_parcelwidth = m_parcelwidth.substr(1,size-1);size = m_parcelwidth.length}	
		while (m_parcelwidth.slice(size-1,size)== " ") //Strip trailing spaces
			{m_parcelwidth = m_parcelwidth.substr(0,size-1);size = m_parcelwidth.length}	
		m_parcelwidth = Number(m_parcelwidth);	

		if (m_parcelwidth <1) {
			alert ("The parcel width must be at least 1cm.");
			pccollection[0].focus();
			return false;
		}

		if (m_dhl==1 || m_hdnl==1) {
			if (m_parcelwidth > m_max_width) {
				alert ("The parcel width that you have entered is more than the " + m_max_width + "CM permitted.");
				pccollection[0].focus();
				return false;
			}
		} else {
			if (m_parcelwidth > m_max_len) {
				alert ("The parcel width that you have entered is more than the " + m_max_len + "CM permitted.");
				pccollection[0].focus();
				return false;
			}
		}

// Validate parcel height
		pccollection=document.getElementsByName("O_18");
		if (isNaN(pccollection[0].value)) {
			alert ("The parcel height that you have quoted is invalid");
			pccollection[0].focus();
			return false;
		}

		m_parcelheight=pccollection[0].value;
		size=m_parcelheight.length;
		while (m_parcelheight.slice(0,1) == "0" || m_parcelheight.slice(0,1) == " ") // strip leading zeroes & spaces
			{m_parcelheight = m_parcelheight.substr(1,size-1);size = m_parcelheight.length}	
		while (m_parcelheight.slice(size-1,size)== " ") //Strip trailing spaces
			{m_parcelheight = m_parcelheight.substr(0,size-1);size = m_parcelheight.length}	
		m_parcelheight = Number(m_parcelheight);

		if (m_parcelheight <1) {
			alert ("The parcel height must be at least 1cm.");
			pccollection[0].focus();
			return false;
		}

		if (m_dhl==1 || m_hdnl==1) {
			if (m_parcelheight > m_max_width) {
				alert ("The parcel height that you have entered is more than the " + m_max_width + "CM permitted.");
				pccollection[0].focus();
				return false;
			}
		} else {
			if (m_parcelheight > m_max_len) {
				alert ("The parcel height that you have entered is more than the " + m_max_len + "CM permitted.");
				pccollection[0].focus();
				return false;
			}
		}

// Validate girth if this is a Parcelforce delivery
		if (m_parcelforce == 1) {
			var longside = m_parcellength;
			var girth = (m_parcelwidth * 2) + (m_parcelheight * 2)
			if (m_parcelwidth > longside) {longside = m_parcelwidth; girth=(m_parcellength*2)+(m_parcelheight*2)}
			if (m_parcelheight > longside) {longside = m_parcelheight; girth=(m_parcellength*2)+(m_parcelwidth*2)}
			girth = girth + longside
			if (girth>m_max_girth) {
				alert("The girth + the longest side of parcel is " + girth + " centimetres which is greater than the maximum permitted for this delivery of " + m_max_girth + ". See the Frequently Asked Questions for a description of Girth.");
				pccollection=document.getElementsByName("O_16");
				pccollection[0].focus();
				return false;
			}
		}

// Validate dimensional weight for parcelforce and non UK DHL deliveries
		if (m_parcelforce == 1 || (m_dhl == 1 && m_country != "UNITED KINGDOM")) {
			if (m_dhl == 1) {
				if (m_dhlair == 1) {
					var dimweight = (m_parcellength * m_parcelwidth * m_parcelheight)/5000;
				} else {
					var dimweight = (m_parcellength * m_parcelwidth * m_parcelheight)/4000;
				}
			} else {
//				var dimweight = (m_parcellength * m_parcelwidth * m_parcelheight)/6000;
				var dimweight = (m_parcellength * m_parcelwidth * m_parcelheight)/5000;
			}

			var highweight = m_parcelweight;
			if (dimweight>highweight) {highweight = dimweight}
			if (highweight > m_productweight) {
				alert ("Dimensional weight of parcel has been calculated as " + highweight + " KG which is greater than the maximum of " + m_productweight +
				"KG permitted for this delivery. See the Frequently Asked Questions for a description of Dimensional Weight.");
				pccollection=document.getElementsByName("O_16");
				pccollection[0].focus();
				return false;
			}
		}

// validate volume for HDNL UK oversize delivery
		if (m_hdnloversize == 1) {
			var volume = ((m_parcellength/100) * (m_parcelwidth/100) * (m_parcelheight/100));
			if (volume > m_max_volume) {
				alert ("The volume of the parcel has been calculated as " + volume + " Metres cubed which is greater than the maximum of " + m_max_volume +
				" Metres cubed permitted for this delivery.");
				pccollection=document.getElementsByName("O_16");
				pccollection[0].focus();
				return false;
			}
		}
	
// validate parcel volume if it is a UK DHL item
		if (m_dhl == 1 && m_country == "UNITED KINGDOM") {
			var volume = ((m_parcellength/100) * (m_parcelwidth/100) * (m_parcelheight/100));
			if (volume > m_max_volume) {
				alert ("The volume of the parcel has been calculated as " + volume + " Metres cubed which is greater than the maximum of " + m_max_volume +
				" Metres cubed permitted for this delivery.");
				pccollection=document.getElementsByName("O_16");
				pccollection[0].focus();
				return false;
			}
		}
	}
	
// Validate item description
	tempcollection=document.getElementsByName("O_19");
	if(!(validatedescription(tempcollection[0]))) {return false;}

// Validate item value
	if (m_dhl==1 || m_parcelforce==1 || m_hdnl==1) {
		tempcollection=document.getElementsByName("O_20");
		m_itemvalue = tempcollection[0].value;
		size=m_itemvalue.length;
		while (m_itemvalue.slice(0,1) == "0" || m_itemvalue.slice(0,1) == " ") // strip leading spaces and zeroes
			{m_itemvalue = m_itemvalue.substr(1,size-1);size = m_itemvalue.length}	
		while (m_itemvalue.slice(size-1,size)== " ") //Strip trailing spaces
			{m_itemvalue = m_itemvalue.substr(0,size-1);size = m_itemvalue.length}
		if (m_itemvalue.length<1) {
			alert ("Item value must be supplied");
			tempcollection[0].focus();
			return false;
		}

		if (isNaN(m_itemvalue)) {
			alert ("Item value must be in pounds");
			tempcollection[0].focus();
			return false;
		}

		if (m_itemvalue < 1) {
			alert ("Item value must be at least £1");
			tempcollection[0].focus();
			return false;
		}
	}

// Validate reason for export
	tempcollection=document.getElementsByName("O_21");
	if (!(validatereasonforexport(tempcollection[0], m_country))) {return false;}

// Validate special instructions
	tempcollection=document.getElementsByName("O_22");
	if (!(validatespecialinstructions(tempcollection[0]))) {return false;}

// Validate collect date
	tempcollection=document.getElementsByName("O_23");
	m_collectdate=tempcollection[0].value
	if (isDate(m_collectdate)==false){
		tempcollection[0].focus();
		return false;
	}

// m_earliestcollect is the calculated date carried over from screen setup in setotherinfo
// m_collectdate is the collection date entered by the user 
// m_latestcollectdate (defined later) is the calculated latest collection date
	
// now extract out of the dates the dd,mm,yy and compare	
	var pos1=m_collectdate.indexOf("/")
	var pos2=m_collectdate.indexOf("/",pos1+1)
	var m_collectdd=m_collectdate.substring(0,pos1)
	var m_collectmm=m_collectdate.substring(pos1+1,pos2)
	var m_collectyy=m_collectdate.substring(pos2+1)
	var pos1=m_earliestcollect.indexOf("/")
	var pos2=m_earliestcollect.indexOf("/",pos1+1)	
	var m_earliestdd=m_earliestcollect.substring(0,pos1)
	var m_earliestmm=m_earliestcollect.substring(pos1+1,pos2)
	var m_earliestyy=m_earliestcollect.substring(pos2+1)

	if (Number(m_collectyy)<Number(m_earliestyy) ||
		(Number(m_collectyy)==Number(m_earliestyy) && Number(m_collectmm)<Number(m_earliestmm)) ||
		(Number(m_collectyy)==Number(m_earliestyy) && Number(m_collectmm)==Number(m_earliestmm) && Number(m_collectdd)<Number(m_earliestdd))) {
		alert ("The collection date you have requested is earlier than the earliest possible collection date of " + m_earliestcollect);
		tempcollection[0].focus();
		return false;
	}

// The entered collection date must be a day that we will collect and be 
// within 5 working days of the earliest collect date. Take the earliest collect date, 
// add 5 working days to it and then check that this date is later than the entered date
	
	var m_latestcollectdate = new Date()
	m_latestcollectdate.setFullYear(m_earliestyy, m_earliestmm-1, m_earliestdd)

	var m_collectdatedateformat = new Date()
	m_collectdatedateformat.setFullYear(m_collectyy, m_collectmm-1, m_collectdd)

// Check that the collection date isn't a Saturday or a Sunday
	if (m_collectdatedateformat.getDay()==6 || m_collectdatedateformat.getDay()==0) { // Saturday or Sunday??
		alert ("Sorry but we are not able to arrange a collection for a Saturday or Sunday, please select an alternative date")
		tempcollection[0].focus();
		return false;			
	}	
	
// check whether the collection date is one of our bank holidays
	m_tempdate = m_collectdatedateformat.getDate();
	m_tempmonth = m_collectdatedateformat.getMonth();
	m_tempfullyear = m_collectdatedateformat.getFullYear();
	sw_found = false
	for (i=0; i<=23; i++) {
		if (m_tempdate==bankhols[i].getDate() && m_tempmonth==bankhols[i].getMonth() && m_tempfullyear==bankhols[i].getFullYear()) {
			sw_found=true;
			break;  
		}
	}
	if (sw_found==true) {
		alert ("Sorry the collection date selected is not available, please select an alternative date");
		tempcollection[0].focus();
		return false;			
	}	

// now check that the requested collection date is within 5 working days of the earliest collection date
	for (k=1; k<6; k++) {
		m_latestcollectdate.setDate(m_latestcollectdate.getDate()+1); // increment date
		for (j=0;j<50;j++) { 	// 50 is just arbitary number to make sure that we go around the loop enough times
			sw_found=false;
			if (m_latestcollectdate.getDay()==6 || m_latestcollectdate.getDay()==0) { // Saturday or Sunday??
				sw_found=true
			}

			m_tempdate = m_latestcollectdate.getDate();
			m_tempmonth = m_latestcollectdate.getMonth();
			m_tempfullyear = m_latestcollectdate.getFullYear();
			for (i=0; i<=23; i++) {
				if (m_tempdate==bankhols[i].getDate() && m_tempmonth==bankhols[i].getMonth() && m_tempfullyear==bankhols[i].getFullYear()) {
					sw_found=true;
					break;  
				}
			}

			if (sw_found==true) {
				m_latestcollectdate.setDate(m_latestcollectdate.getDate()+1)
			} else {
				break;
			}   
		}
	}

	var m_latestdd=m_latestcollectdate.getDate()
	var m_latestmm=m_latestcollectdate.getMonth()+1
	var m_latestyy=m_latestcollectdate.getFullYear()

	if (Number(m_collectyy)>Number(m_latestyy) ||
		(Number(m_collectyy)==Number(m_latestyy) && Number(m_collectmm)>Number(m_latestmm)) ||
		(Number(m_collectyy)==Number(m_latestyy) && Number(m_collectmm)==Number(m_latestmm) && Number(m_collectdd)>Number(m_latestdd))) {
		alert ("The collection date you have requested is later than the latest possible collection date of " + m_latestdd+"/"+m_latestmm+"/"+m_latestyy);
		tempcollection[0].focus();
		return false;
	}


// see if the delivery post code is the same as the collection post code and error if so
	if (m_collectpc == m_deliverypc) {
		alert ("Collection and Delivery post codes cannot be the same");
		return false;
	}

// Validate quantity against enhanced comp
	tempcollection=document.getElementsByName("Q_" + p_prodref);
	m_quantity=tempcollection[0].value;

	if (m_enhanced == 1 && m_quantity > 1) {
		alert("Sorry, you cannot choose enhanced compensation with more than 1 parcel in the consignment. To opt for enhanced compensation please " + 
			"set the number of parcels in the consignment to 1 and then place orders separately for the additional parcels");
		tempcollection[0].focus();
		return false;
	}

	if (m_hdnl==1 && m_quantity > 20) {
		alert("The maximum number of parcels in a consignment with Home Delivery Network is 20. You will need to place multiple orders if you " + 
			"have more than 20 parcels to deliver");
		tempcollection[0].focus();
		return false;
	}


// all ok - so now create cookie for collection details
	tempcollection=document.getElementsByName("O_1");
	temp=tempcollection[0].value + "#";
	tempcollection=document.getElementsByName("O_2");
	temp= temp + tempcollection[0].value + "#";
	tempcollection=document.getElementsByName("O_3");
	temp= temp + tempcollection[0].value + "#";
	tempcollection=document.getElementsByName("O_4");
	temp= temp + tempcollection[0].value + "#";
	tempcollection=document.getElementsByName("O_5");
	temp= temp + tempcollection[0].value + "#";
	tempcollection=document.getElementsByName("O_6");
	temp= temp + tempcollection[0].value + "#";
	tempcollection=document.getElementsByName("O_7");
	temp= temp + tempcollection[0].value;
	createCookie("p2scollection",temp,90);

	return true;
}

// **************************************************************************
// Function to validate checkout page 1
// **************************************************************************
function invoicecheck() {
	var pccollection=document.getElementsByName("INVOICEPOSTALCODE");
	if (!(validateukpostcodeformat(pccollection[0]))) {return false;}

	pccollection=document.getElementsByName("INVOICENAME");
	if (!(validatename(pccollection[0]))) { return false; }

	pccollection=document.getElementsByName("INVOICEADDRESS1");
	if (!(validateaddrline(pccollection[0],1))) { return false; }

	pccollection=document.getElementsByName("INVOICEADDRESS2");
	if (!(validateaddrline(pccollection[0],2))) { return false; }

	pccollection=document.getElementsByName("INVOICEADDRESS3");
	if (!(validateaddrline(pccollection[0],3))) { return false; }

	pccollection=document.getElementsByName("INVOICEPHONE");
	if (!(validatephone(pccollection[0],"M"))) { return false; }

	var pccollection=document.getElementsByName("INVOICEEMAIL");
	if (!(validateemail(pccollection[0],"M"))) { return false; }
	m_em1=pccollection[0].value.toUpperCase();

	var pccollection=document.getElementsByName("INVOICEEMAILCONFIRM");
	if (!(validateemail(pccollection[0], "M"))) { return false; }
	m_em2=pccollection[0].value.toUpperCase();

// check that the e-mail adress has been entered twice correctly
	if (m_em1 != m_em2) {
	  var pccollection=document.getElementsByName("INVOICEEMAIL");
	  alert("Email addresses must be identical");
	  pccollection[0].focus();
	  return false;
	}

	var countrycollection=document.getElementsByName("SEPARATESHIP");
	countrycollection[0].checked = false;

// all ok - so now create cookie for collection details
	tempcollection=document.getElementsByName("INVOICEPOSTALCODE");
	temp=tempcollection[0].value + "#";
	tempcollection=document.getElementsByName("INVOICENAME");
	temp= temp + tempcollection[0].value + "#";
	tempcollection=document.getElementsByName("INVOICEADDRESS1");
	temp= temp + tempcollection[0].value + "#";
	tempcollection=document.getElementsByName("INVOICEADDRESS2");
	temp= temp + tempcollection[0].value + "#";
	tempcollection=document.getElementsByName("INVOICEADDRESS3");
	temp= temp + tempcollection[0].value + "#";
	tempcollection=document.getElementsByName("INVOICECOUNTRY");
	temp= temp + tempcollection[0].value + "#";
	tempcollection=document.getElementsByName("INVOICEPHONE");
	temp= temp + tempcollection[0].value + "#";
	tempcollection=document.getElementsByName("INVOICEEMAIL");
	temp= temp + tempcollection[0].value;
	createCookie("p2sinvoice",temp,90);
	return true;
}

// *********************************************************************************************************************
function isDate(dtStr){
// Declaring valid date character, minimum year and maximum year
	var d = new Date();
	var minYear=d.getFullYear();
	var maxYear=minYear+1;
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf("/")
	var pos2=dtStr.indexOf("/",pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("Collection Date must be in the format: dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("The month specified in the Collection date is invalid, must be 01-12")
	return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("The day specified in the collection day is invalid")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf("/",pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, "/"))==false){
		alert("Please enter a valid date")
		return false
	}
	return true
}

function isInteger(s){
	var i;
	for (i = 0; i < s.length; i++){   
// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
// All characters are numbers.
	return true;
}

function stripCharsInBag(s, bag){
	var i;
	var returnString = "";
// Search through string's characters one by one.
// If character is not in bag, append to returnString.
	for (i = 0; i < s.length; i++){   
	var c = s.charAt(i);
	if (bag.indexOf(c) == -1) returnString += c;
}
	return returnString;
}

function daysInFebruary (year){
// February has 29 days in any year evenly divisible by four,
// EXCEPT for centurial years which are not also divisible by 400.
	return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
	} 
	return this
}

function createAffiliateCookie(p_href) {
	if (p_href.indexOf("?affiliatenetwork=por")>-1) {
		createCookie("p2saffiliate","por",90);
	}
	
	if (p_href.indexOf("?affiliatenetwork=AF")>-1) {
		createCookie("p2saffiliate","AF",90);
	}
	
	if (p_href.indexOf("?affiliatenetwork=clix")>-1) {
		createCookie("p2saffiliate","clix",90);
	}
	return null
}

// ***************************************************
// *
// * Pick up a cookie of a given name if it exists
// *
// ***************************************************
function readCookie(name) {
	var nameEQ = 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;
}

// ***************************************************
// *
// * Create a cookie of a given name
// *
// ***************************************************
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 emailCheck (emailStr) {
/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/i;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */
var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/
var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */
var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";
// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);
if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
return false;
   }
}

// See if "user" is valid 
if (user.match(userPat)==null) {

// user is not valid
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
return false;
}

// Make sure there's a host name preceding the domain.
if (len<2) {
return false;
}

// If we've gotten this far, everything's valid!
return true;
}

// ***************************************************
// *
// * validate customer name
// *
// ***************************************************

function validatename(p_object) {
	test = p_object.value.replace(/'/g,' ');
	size = test.length;
	while (test.slice(0,1) == " ") {
		test = test.substr(1,size-1);size = test.length
	}
	while(test.slice(size-1,size)== " ") { //Strip trailing spaces
		test = test.substr(0,size-1);size = test.length
	}
	p_object.value = test; //write back to form field
	if (test.length==0 || test.length > 30) {
		alert("Name must be entered and be a maximum of 30 characters");
		p_object.focus();
		return false;
	}

	bolValid = true; 
	for (var iLoop=0; iLoop < size; iLoop++)
	{ 
		strCurrentChar = test.substring(iLoop,iLoop+1); 
		if ((strCurrentChar >= 'A' && strCurrentChar <= 'Z') || (strCurrentChar >= 'a' && strCurrentChar <= 'z') || 
			(strCurrentChar >= '0' && strCurrentChar <= '9') || strCurrentChar == '-' ||
			 strCurrentChar == ' ' || strCurrentChar == '.' || strCurrentChar == '&' || strCurrentChar == ',' ||
			 strCurrentChar == '/' || strCurrentChar == '%'	) {
		}
		else {
			bolValid = false; 
		}
	} 

	if(!bolValid) {
		alert("Name contains invalid character");
		p_object.focus();
		return false;
	}

	return true
}

// ***************************************************
// *
// * validate address line
// *
// ***************************************************
function validateaddrline(p_object,p_line) {
	test=p_object.value.replace(/["',]/g,' ');
	size = test.length
	while (test.slice(0,1) == " ") {
		test = test.substr(1,size-1);size = test.length
	}
	while(test.slice(size-1,size)== " ") { //Strip trailing spaces
		test = test.substr(0,size-1);size = test.length
	}
	p_object.value = test; //write back to form field
	if (p_line == 2) {
		if (test.length > 35) {
			alert("Address line must be a maximum of 35 characters");
			p_object.focus();
			return false;
		}
	} else {
		if (test.length == 0 || test.length > 35) {
			alert("Address line must be entered and be a maximum of 35 characters");
			p_object.focus();
			return false;
		}
	}

	bolValid = true; 
	for (var iLoop=0; iLoop < size; iLoop++)
	{ 
		strCurrentChar = test.substring(iLoop,iLoop+1); 
		if ((strCurrentChar >= 'A' && strCurrentChar <= 'Z') || (strCurrentChar >= 'a' && strCurrentChar <= 'z') || 
			(strCurrentChar >= '0' && strCurrentChar <= '9') || strCurrentChar == '-' ||
			 strCurrentChar == ' ' || strCurrentChar == '.' || strCurrentChar == '&' || 
			 strCurrentChar == '/' || strCurrentChar == '%'	) {
		}
		else {
			bolValid = false; 
		}
	} 

	if(!bolValid) {
		alert("Address line contains invalid character");
		p_object.focus();
		return false;
	}

	return true;
}

// ***************************************************
// *
// * validate item description
// *
// ***************************************************
function validatedescription(p_object) {
	test=p_object.value
	size = test.length
	while (test.slice(0,1) == " ") {
		test = test.substr(1,size-1);size = test.length
	}
	while(test.slice(size-1,size)== " ") { //Strip trailing spaces
		test = test.substr(0,size-1);size = test.length
	}
	p_object.value = test; //write back to form field
	if (test.length == 0 || test.length > 50) {
		alert("Item description must be entered and be a maximum of 50 characters");
		p_object.focus();
		return false;
	}

	bolValid = true; 
	for (var iLoop=0; iLoop < size; iLoop++)
	{ 
		strCurrentChar = test.substring(iLoop,iLoop+1); 
		if ((strCurrentChar >= 'A' && strCurrentChar <= 'Z') || (strCurrentChar >= 'a' && strCurrentChar <= 'z') || 
			(strCurrentChar >= '0' && strCurrentChar <= '9') || strCurrentChar == '-' ||
			 strCurrentChar == ' ' || strCurrentChar == '.' || strCurrentChar == '&' || strCurrentChar == ',' ||
			 strCurrentChar == '/' || strCurrentChar == '%'	) {
		}
		else {
			bolValid = false; 
		}
	} 

	if(!bolValid) {
		alert("item description contains invalid character");
		p_object.focus();
		return false;
	}

	return true;
}

// ***************************************************
// *
// * validate format of UK post code
// *
// ***************************************************
function validateukpostcodeformat(p_object) {
	test=p_object.value
	test = test.toUpperCase(); //Change to uppercase
	size=test.length;
	while (test.slice(0,1) == " ")
		  {test = test.substr(1,size-1);size = test.length
	}
	while(test.slice(size-1,size)== " ") //Strip trailing spaces
	      {test = test.substr(0,size-1);size = test.length
	}
	p_object.value = test; //write back to form field

	if (size < 6 || size > 8){ //Code length rule
	   alert("Postcode is not valid - wrong length");
	   p_object.focus();
	   return false;
	}

	if (!(isNaN(test.charAt(0)))){ //leftmost character must be alpha character rule
	   alert("Postcode is not valid - cannot start with a number");
	   p_object.focus();
	   return false;
	}

	if (isNaN(test.charAt(size-3))){ //first character of inward code must be numeric rule
	   alert("Postcode is not valid - alpha character in wrong position");
	   p_object.focus();
	   return false;
	}

	if (!(isNaN(test.charAt(size-2)))){ //second character of inward code must be alpha rule
	   alert("Postcode is not valid - number in wrong position");
	   p_object.focus();
	   return false;
	}

	if (!(isNaN(test.charAt(size-1)))){ //third character of inward code must be alpha rule
	   alert("Postcode is not valid - number in wrong position");
	   p_object.focus();
	   return false;
	}

	if (!(test.charAt(size-4) == " ")){//space in position length-3 rule
	   alert("Postcode is not valid - no space or space in wrong position");
	   p_object.focus();
	   return false;
	}

	count1 = test.indexOf(" ");count2 = test.lastIndexOf(" ");
	if (count1 != count2){//only one space rule
		alert("Postcode is not valid - only one space allowed");
		p_object.focus();
		return false;
	}

	bolValid = true; 
	for (var iLoop=0; iLoop < size; iLoop++)
	{ 
		strCurrentChar = test.substring(iLoop,iLoop+1); 
		if ((strCurrentChar >= 'A' && strCurrentChar <= 'Z') || (strCurrentChar >= 'a' && strCurrentChar <= 'z') || 
			(strCurrentChar >= '0' && strCurrentChar <= '9') || strCurrentChar == ' ') {
		}
		else {
			bolValid = false; 
		}
	} 

	if(!bolValid) {
		alert("Post code contains invalid character");
		p_object.focus();
		return false;
	}

	return true;
}

// ***************************************************
// *
// * validate format of BFPO post code
// *
// ***************************************************
function validateBFPOpostcodeformat(p_object) {
	test=p_object.value
	test = test.toUpperCase(); //Change to uppercase
	size=test.length;
	while (test.slice(0,1) == " ")
		  {test = test.substr(1,size-1);size = test.length
	}
	while(test.slice(size-1,size)== " ") //Strip trailing spaces
	      {test = test.substr(0,size-1);size = test.length
	}
	p_object.value = test; //write back to form field

	if (p_object.value.match(/^(BFPO) \d{2,4}$/)) {
	} else {
		alert ("Post code must be of the format BFPO #### where # equals any numeric digit (0-9)");
		p_object.focus();
		return false;			
	}


	return true;
}
// ***************************************************
// *
// * validate email address
// *
// ***************************************************
function validateemail (p_email, p_mode) {
m_email=p_email.value
size = m_email.length;
while (m_email.slice(0,1) == " ")
	  {m_email = m_email.substr(1,size-1);size = m_email.length
}
while(m_email.slice(size-1,size)== " ") //Strip trailing spaces
	  {m_email = m_email.substr(0,size-1);size = m_email.length
}
p_email.value = m_email; //write back to form field

if (p_mode == "O") {
	if (m_email.length > 50) {
		alert("Email address must be a maximum of 50 characters");
		p_email.focus();
		return false;
	}

	if (m_email.length >0) {
		if (!(emailCheck(m_email))) {  
			alert("Email address format is invalid");
			p_email.focus();
			return false
		}
	}
} else {
	if (m_email.length==0 || m_email.length > 50) {
		alert("Email address must be entered and must be a maximum of 50 characters");
		p_email.focus();
		return false;
	}

	if (!(emailCheck(m_email))) {  
		alert("Email address format is invalid");
		p_email.focus();
		return false
	}
}

if (m_email.indexOf('"') >= 0 || m_email.indexOf(' ') >= 0) {
	alert("Invalid character in email address");
	p_email.focus();
	return false;
}

// If we've gotten this far, everything's valid!
return true;
}


// ***************************************************
// *
// * validate phone number
// *
// ***************************************************
function validatephone (p_object, p_mode) {
test=p_object.value
size = test.length;
while (test.slice(0,1) == " ") {
	test = test.substr(1,size-1);size = test.length
}
while(test.slice(size-1,size)== " ") { //Strip trailing spaces
	test = test.substr(0,size-1);size = test.length
}
p_object.value = test; //write back to form field

if (p_mode == "O") {
	if (test.length > 15) {
	   alert("Phone number must be a maximum of 15 characters");
	   p_object.focus();
	   return false;
	}
} else {
	if (test.length == 0 || test.length > 15) {
	   alert("Phone number must be entered and be a maximum of 15 characters");
	   p_object.focus();
	   return false;
	}
}

bolValid = true; 
for (var iLoop=0; iLoop < size; iLoop++)
{ 
	strCurrentChar = test.substring(iLoop,iLoop+1); 
	if ((strCurrentChar >= '0' && strCurrentChar <= '9') || strCurrentChar == ' ' || strCurrentChar == '(' ||
		strCurrentChar == ')' || strCurrentChar == '+') {
	}
	else {
		bolValid = false; 
	}
} 

if(!bolValid) {
	alert("Phone number contains invalid character");
	p_object.focus();
	return false;
}

return true;
}


// ***************************************************
// *
// * validate reason for export
// *
// ***************************************************
function validatereasonforexport(p_object, p_country) {
test=p_object.value
size = test.length
while (test.slice(0,1) == " ") {
	test = test.substr(1,size-1);size = test.length
}
while(test.slice(size-1,size)== " ") { //Strip trailing spaces
	test = test.substr(0,size-1);size = test.length
}
p_object.value = test; //write back to form field
if (p_country=="UNITED KINGDOM") {
	if (!(test=="Not required for UK delivery" || test.length==0)) {
	   alert ("Reason for export should not be supplied for a UK delivery");
	   p_object.focus();
	   return false;
	}
} else {
	if (test.length<1) {
	   alert ("Reason for export required");
	   p_object.focus();
	   return false;
	}	
	if (test.length>50) {
	   alert ("Reason for export too long, maximum 50 characters allowed");
	   p_object.focus();
	   return false;
	}	   
}

bolValid = true; 
for (var iLoop=0; iLoop < size; iLoop++)
{ 
	strCurrentChar = test.substring(iLoop,iLoop+1); 
	if ((strCurrentChar >= 'A' && strCurrentChar <= 'Z') || (strCurrentChar >= 'a' && strCurrentChar <= 'z') || 
		(strCurrentChar >= '0' && strCurrentChar <= '9') || strCurrentChar == '-' ||
		 strCurrentChar == ' ' || strCurrentChar == '.' || strCurrentChar == '&' || strCurrentChar == ',' ||
		 strCurrentChar == '/' || strCurrentChar == '%'	) {
	}
	else {
		bolValid = false; 
	}
} 

if(!bolValid) {
	alert("Reason for export contains invalid character");
	p_object.focus();
	return false;
}

return true;

}

// ***************************************************
// *
// * validate special instructions
// *
// ***************************************************
function validatespecialinstructions(p_object) {
	test=p_object.value
	size = test.length
	while (test.slice(0,1) == " ") {
		test = test.substr(1,size-1);size = test.length
	}
	while(test.slice(size-1,size)== " ") { //Strip trailing spaces
		test = test.substr(0,size-1);size = test.length
	}
	p_object.value = test; //write back to form field

	if (test.length > 50) {
		alert("Special instructions must be a maximum of 50 characters");
		p_object.focus();
		return false;
	}

	bolValid = true; 
	for (var iLoop=0; iLoop < size; iLoop++)
	{ 
		strCurrentChar = test.substring(iLoop,iLoop+1); 
		if ((strCurrentChar >= 'A' && strCurrentChar <= 'Z') || (strCurrentChar >= 'a' && strCurrentChar <= 'z') || 
			(strCurrentChar >= '0' && strCurrentChar <= '9') || strCurrentChar == '-' ||
			 strCurrentChar == ' ' || strCurrentChar == '.' || strCurrentChar == '&' || strCurrentChar == ',' ||
			 strCurrentChar == '/' || strCurrentChar == '%'	) {
		}
		else {
			bolValid = false; 
		}
	} 
	
	if(!bolValid) {
		alert("Special instructions contains invalid character");
		p_object.focus();
		return false;
	}

	return true;

}

// ***************************************************
// *
// * validate foreign post code
//*
// ***************************************************
function validateforeignpostcode(p_country, p_object) {

	if (p_country=="BELGIUM" || p_country=="LUXEMBOURG" || p_country=="AUSTRIA" || 
		p_country=="HUNGARY" || p_country=="SLOVENIA" || p_country=="BULGARIA" || p_country=="CYPRUS" ||
		p_country=="DENMARK" || p_country=="LATVIA" || p_country=="NORWAY" || p_country=="SWITZERLAND" ||
		p_country=="AUSTRALIA" || p_country=="NEW ZEALAND" || p_country=="PHILIPPINES" || p_country=="SOUTH AFRICA") {
		if (p_object.value.match(/^\d{4}$/)) {
		} else {
			alert ("Post code must be of the format #### where # equals any numeric digit (0-9)");
			p_object.focus();
			return false;			
		}
	}
	
	if (p_country=="FRANCE" || p_country=="GERMANY" || p_country=="TURKEY" ||
		p_country=="SPAIN" || p_country=="ITALY" || p_country=="SWEDEN" ||
		p_country=="GREECE" || p_country=="FINLAND" || p_country=="CZECH REPUBLIC" ||
		p_country=="SLOVAKIA" || p_country=="ESTONIA" || p_country=="MONACO" ||
		p_country=="UKRAINE" || p_country=="UNITED STATES OF AMERICA" || p_country=="MALAYSIA" ||
		p_country=="ISRAEL" || p_country=="MEXICO" || p_country=="MOROCCO" || p_country=="PAKISTAN" ||
		p_country=="SAUDI ARABIA") {
		if (p_object.value.match(/^\d{5}$/)) {
		} else {
			alert ("Post code must be of the format ##### where # equals any numeric digit (0-9)");
			p_object.focus();
			return false;			
		}
	}

	if (p_country=="BELARUS" || p_country=="ROMANIA" || p_country=="RUSSIA" ||
		p_country=="CHINA" || p_country=="SINGAPORE" || p_country=="INDIA") {
		if (p_object.value.match(/^\d{6}$/)) {
		} else {
			alert ("Post code must be of the format ###### where # equals any numeric digit (0-9)");
			p_object.focus();
			return false;			
		}
	}

	if (p_country=="IRELAND, REPUBLIC OF") {
		if (p_object.value.match(/^BT/i)) {
			alert ("BT postcodes are in Northern Ireland. Please use a UK delivery rather than a Republic of Ireland delivery");
			p_object.focus();
			return false;
		}
	}

	if (p_country=="CROATIA") {
		if (p_object.value.match(/^HR-\d{5}$/)) {
		} else {
			alert ("Post code must be of the format HR-##### where # equals any numeric digit (0-9)");
			p_object.focus();
			return false;			
		}
	}
	
	if (p_country=="POLAND") {
		if (p_object.value.match(/^\d{5}$/)) {
		} else {
			alert ("Post code must be of the format ##### where # equals any numeric digit (0-9)");
			p_object.focus();
			return false;		
		}
	}
	
	if (p_country=="PORTUGAL") {
		if (p_object.value.match(/^\d{4}-\d{3}$/)) {
		} else {
			alert ("Post code must be of the format ####-### where # equals any numeric digit (0-9)");
			p_object.focus();
			return false;		
		}
	}	

	if (p_country=="JAPAN") {
		if (p_object.value.match(/^\d{3}-\d{4}$/)) {
		} else {
			alert ("Post code must be of the format ###-#### where # equals any numeric digit (0-9)");
			p_object.focus();
			return false;		
		}
	}	

	if (p_country=="KOREA") {
		if (p_object.value.match(/^\d{3}-\d{3}$/)) {
		} else {
			alert ("Post code must be of the format ###-### where # equals any numeric digit (0-9)");
			p_object.focus();
			return false;		
		}
	}

	if (p_country=="NETHERLANDS") {
		if (p_object.value.match(/^\d{4} [A-Z]{2}$/i) && m_deliverypc.length==7) {
		} else {
			alert ("Post code must be of the format ####^@@ where # equals any numeric digit (0-9), ^ equals space and @ equals any alpha character (a-z)");
			p_object.focus();
			return false;	
		}
	}

	if (p_country=="CANADA") {
		if (p_object.value.match(/^[A-Z]\d[A-Z] \d[A-Z]\d$/i)) {
		} else {
			alert ("Post code must be of the format @#@^#@# where # equals any numeric digit (0-9), ^ equals space and @ equals any alpha character (a-z)");
			p_object.focus();
			return false;	
		}
	}

	if (p_country=="ARGENTINA") {
		if (p_object.value.match(/^[A-Z]\d{4}[A-Z]{3}$/i)) {
		} else {
			alert ("Post code must be of the format @####@@@ where # equals any numeric digit (0-9), ^ equals space and @ equals any alpha character (a-z)");
			p_object.focus();
			return false;	
		}
	}

	if (p_country=="MALTA") {
		if (p_object.value.match(/^[A-Z]{3} \d{4}$/i)) {
		} else {
			alert ("Post code must be of the format @@@^#### where # equals any numeric digit (0-9), ^ equals space and @ equals any alpha character (a-z)");
			p_object.focus();
			return false;	
		}
	}

	return true;
}

// ***************************************************
// *
// * validate fields entered in the product chooser
// *
// ***************************************************

function productchoosercheck() {

	pccollection=document.getElementsByName("MODE");
	m_mode=pccollection[0].value;
	if (m_mode=="Document envelope") { return true;}

	pccollection=document.getElementsByName("COUNTRY");
	m_country=pccollection[0].value

/* calculate the maximum dimensions for the parcel for Parcelforce. Assume that all countries have a Parcelforce service*/  
	if (m_country=="UNITED KINGDOM") {
		m_max_len = 225;	
		m_max_girth = 300; 
	} else {
		m_max_len = 150;	
		m_max_girth = 300; 
	}

	if (m_country=="ARGENTINA" || m_country=="AUSTRALIA" || m_country=="BRAZIL" || 
		m_country=="CHINA" || m_country=="MALAYSIA" || m_country=="NEW ZEALAND" ||
		m_country=="ROMANIA" || m_country=="LATVIA" || m_country=="RUSSIA" ||
		m_country=="UKRAINE" || m_country == "UNITED STATES OF AMERICA" || 
		m_country=="PHILIPPINES" || m_country=="SAUDI ARABIA") {
		m_max_len = 105;
		m_max_girth = 200; 
	}

	pccollection=document.getElementsByName("PARCELLENGTH");
	if (isNaN(pccollection[0].value)) {
		alert ("The parcel length that you have quoted is invalid");
   		pccollection[0].focus();
		return false;
	}

	m_parcellength=pccollection[0].value;
	size=m_parcellength.length;
	while (m_parcellength.slice(0,1) == "0" || m_parcellength.slice(0,1) == " ") // strip leading zeroes & spaces
		{m_parcellength = m_parcellength.substr(1,size-1);size = m_parcellength.length}	
	while (m_parcellength.slice(size-1,size)== " ") //Strip trailing spaces
		{m_parcellength = m_parcellength.substr(0,size-1);size = m_parcellength.length}	
	m_parcellength = Number(m_parcellength);	

	if (m_parcellength <1) {
   		alert ("The parcel length must be at least 1cm.");
		pccollection[0].focus();
		return false;
	}
	if (m_parcellength > m_max_len) {
		alert ("The parcel length that you have entered is more than the " + m_max_len + "CM permitted for the selected destination.");
		pccollection[0].focus();
		return false;
	}

	pccollection=document.getElementsByName("PARCELWIDTH");
	if (isNaN(pccollection[0].value)) {
		alert ("The parcel width that you have quoted is invalid");
		pccollection[0].focus();
		return false;
	}
	m_parcelwidth=pccollection[0].value;
	size=m_parcelwidth.length;
	while (m_parcelwidth.slice(0,1) == "0" || m_parcelwidth.slice(0,1) == " ") // strip leading zeroes & spaces
		{m_parcelwidth = m_parcelwidth.substr(1,size-1);size = m_parcelwidth.length}	
	while (m_parcelwidth.slice(size-1,size)== " ") //Strip trailing spaces
		{m_parcelwidth = m_parcelwidth.substr(0,size-1);size = m_parcelwidth.length}	
	m_parcelwidth = Number(m_parcelwidth);	
	if (m_parcelwidth <1) {
		alert ("The parcel width must be at least 1cm.");
		pccollection[0].focus();
		return false;
	}

	if (m_parcelwidth > m_max_len) {
		alert ("The parcel width that you have entered is more than the " + m_max_len + "CM permitted for the selected destination");
		pccollection[0].focus();
		return false;
	}

	pccollection=document.getElementsByName("PARCELHEIGHT");
	if (isNaN(pccollection[0].value)) {
		alert ("The parcel height that you have quoted is invalid");
		pccollection[0].focus();
		return false;
	}
	m_parcelheight=pccollection[0].value;
	size=m_parcelheight.length;
	while (m_parcelheight.slice(0,1) == "0" || m_parcelheight.slice(0,1) == " ") // strip leading zeroes & spaces
		{m_parcelheight = m_parcelheight.substr(1,size-1);size = m_parcelheight.length}	
	while (m_parcelheight.slice(size-1,size)== " ") //Strip trailing spaces
		{m_parcelheight = m_parcelheight.substr(0,size-1);size = m_parcelheight.length}	
	m_parcelheight = Number(m_parcelheight);
	if (m_parcelheight <1) {
		alert ("The parcel height must be at least 1cm.");
		pccollection[0].focus();
		return false;
	}
	if (m_parcelheight > m_max_len) {
		alert ("The parcel height that you have entered is more than the " + m_max_len + "CM permitted for the selected delivery.");
		pccollection[0].focus();
		return false;
	}
}

// ***************************************************
// *
// * Change the mode of the product chooser
// *
// ***************************************************
function modechange() {
	pccollection=document.getElementsByName("MODE");
	if (pccollection[0].value == "Document envelope") {
		pccollection=document.getElementsByName("WEIGHT");
		pccollection[0].disabled=true;
		pccollection[0].style.background="#C0C0C0";
		pccollection=document.getElementsByName("PARCELLENGTH");
		pccollection[0].disabled=true;
		pccollection[0].style.background="#C0C0C0";	
		pccollection=document.getElementsByName("PARCELWIDTH");
		pccollection[0].disabled=true;
		pccollection[0].style.background="#C0C0C0";	
		pccollection=document.getElementsByName("PARCELHEIGHT");
		pccollection[0].disabled=true;
		pccollection[0].style.background="#C0C0C0";	
	} else {
		pccollection=document.getElementsByName("WEIGHT");
		pccollection[0].disabled=false;
		pccollection[0].style.background="#ffffff";
		pccollection=document.getElementsByName("PARCELLENGTH");
		pccollection[0].disabled=false;
		pccollection[0].style.background="#ffffff";
		pccollection=document.getElementsByName("PARCELWIDTH");
		pccollection[0].disabled=false;
		pccollection[0].style.background="#ffffff";	
		pccollection=document.getElementsByName("PARCELHEIGHT");
		pccollection[0].disabled=false;
		pccollection[0].style.background="#ffffff";	
	}
}

// ***************************************************
// *
// * send the user to the selected form
// *
// ***************************************************
function goform() {
	var formoption=document.getElementsByName("formoption");
	if (formoption[0].value == "None") {
		alert ("No action selected");
		formoption[0].focus();
	}

	if (formoption[0].value == "COLLECTION") {
		window.location = "http://www.parcel2ship.co.uk/noncollection.html";
	}
	if (formoption[0].value == "DELIVERY") {
		window.location = "http://www.parcel2ship.co.uk/nondelivery.html";
	}
	if (formoption[0].value == "DAMAGE") {
		window.location = "http://www.parcel2ship.co.uk/damageclaim.html";
	}
	if (formoption[0].value == "LOSS") {
		window.location = "http://www.parcel2ship.co.uk/lossclaim.html";
	}
	return this;
}