// declare a function to change the preexisting dropdown to include all of the addresses set in the cookie -->
// also declare a function to set the selected status -->
    var aaapi_array = {};
    var theCartId = "";
	if(!document.getElementById('del_summary'))
	{
		aaapi_array["cal"] = {};
		function aaapiLoadData(aaapiDataObj)
		{
			if(aaapiDataObj && aaapi_array)
			{
				for(aaapiDataObjIndex in aaapiDataObj)
				{
					aaapi_array["cal"][aaapiDataObjIndex] = aaapiDataObj[aaapiDataObjIndex];
				}
			}
		}

		function stripTempElements(formObj)
		{
			var inputToStrip = formObj.getElementsByTagName('input');
			for(theInputs in inputToStrip)
			{
				if(!isNaN(theInputs))
				{
					if(inputToStrip[theInputs].id.substring(0,4) == 'temp' && inputToStrip[theInputs].value == '' && inputToStrip[theInputs].disabled == false)
					{
						inputToStrip[theInputs].disabled = true;
					}
				}
			}
			return true;
		}
	}

	var default_address_id = 0;
	
	function printAddressList( formname, objname, default_address_id, show_default, country) {
		if (addressList) {
			var listString = addressList;

			if (!country) country = "GB"; 
			var list = listString.split(";");
			var index = 0;
			for(var i = 0; i<list.length; i++) {
				var keyvalpair = list[i].split(":");
				var options = document.getElementById(objname).options;
				if (!keyvalpair[5] || (keyvalpair[5] == country)) {
					index++;
					if (default_address_id && default_address_id == keyvalpair[0]) {
						// Hack for ie - for some reason, it doesn't set the selectedIndex properly
						if(!is_ie6up) {
							options[index] = new Option( keyvalpair[1], keyvalpair[0], false, true );			
						} else {
							options[index] = new Option( keyvalpair[1], keyvalpair[0], false, true );			
							options.selectedIndex = index;
						}
					}
					else {
						if (keyvalpair[0] && keyvalpair[1]) {
							options[index] = new Option( keyvalpair[1], keyvalpair[0], false, false );			
						}
					}
				}
			}
		}
	}


function setDynamicRules(selectName, arrayName, cellName, otherOption, onChange)
{
	idSuffix = document.getElementById('tempCartId').value;
	
	var cell = document.getElementById(cellName);
	var s = '';
	for(var i in arrayName)
	{
		s+='<input style="display:none;" id="result_aa_'+ i +'" name="result_aa_'+ i +'" value="'+ arrayName[i] +','+i+'"/>'; 
		//if(arrayName[i]
	}
	domSetInnerHTML(cell, s);
    arrayNameCount = 0;
	for(var i in arrayName)
	{
		if(document.getElementById('result_aa_'+i))
		{
			var strAvail = document.getElementById('result_aa_'+i).value;
			disableRule(strAvail);
            arrayNameCount++;
		}
	}
    firstColMethodsEL = document.getElementById("firstColMethods");
    secondColMethodsEL = document.getElementById("secondColMethods");
    firstColMethodsELMulti = document.getElementById("firstColMethods"+idSuffix);
    secondColMethodsELMulti = document.getElementById("secondColMethods"+idSuffix);
    displayConcernMessage = false;
    lookForInputs = [firstColMethodsEL, secondColMethodsEL, firstColMethodsELMulti, secondColMethodsELMulti];
	var theCount = 0;
    for (inputAreaEL in lookForInputs)
	{
        if(lookForInputs[inputAreaEL])
		{
            inputCollection = lookForInputs[inputAreaEL].getElementsByTagName("input");
            if (inputCollection.length > 0)
			{
                for (var x = 0; x < inputCollection.length; x++)
				{
                    if (!displayConcernMessage)
					{
						displayConcernMessage = inputCollection[x].disabled;
                        if((inputCollection[x].id == ('optionStandard'+idSuffix) || inputCollection[x].id == ('optionSameDay'+idSuffix)) && displayConcernMessage)
                        { var showMsg = true; }
                    }
                }
            }
        }
    }
    if (showMsg)
	{
		calNoEntriesEL = document.getElementById('no_entries');
		if(document.getElementById('cancel_button1'+idSuffix))
		{
			cancelButton1EL = document.getElementById('cancel_button1'+idSuffix);
		}
		else if(document.getElementById('cancel_button'+idSuffix))
		{
			cancelButtonBEL = document.getElementById('cancel_button'+idSuffix);
		}
		if (document.getElementById('cancel_button1'+idSuffix) || document.getElementById('cancel_button'+idSuffix))
		{
			if (calNoEntriesEL)
			{
				calNoEntriesEL.style.display = "block";
				if(document.getElementById('cancel_button1'+idSuffix))
				{
					document.getElementById('cancel_button1'+idSuffix).style.display = 'block';
					document.getElementById('cancel_button2'+idSuffix).style.display = 'block';
				}
				else if (document.getElementById('cancel_button'+idSuffix))
				{
					document.getElementById('cancel_button'+idSuffix).style.display = 'block';
				}
				if(document.getElementById('div_standard'+idSuffix).style.display == 'block')
				{
					document.getElementById('optionStandard'+idSuffix).checked = false;
				}
				if(document.getElementById('div_same_day'+idSuffix).style.display == 'block')
				{
					document.getElementById('optionSameDay'+idSuffix).checked = false;
				}
				hideDetails = new Array('selectedText','detailStandardText','detailSameDayText','detailSameDay','costSameDay','detailThreeHourText','detail3hrText','detailAMText','detailPMText','detailStandard','detailThreeHour','detail3hr','detailAM','detailPM','totalText','totalDelText','costStandard','costThreeHour','cost3hr','costAM','costPM', 'continue_button1', 'continue_button2');
				for (var i=0; i<hideDetails.length; i++)
				{
					if(document.getElementById(hideDetails[i]+ idSuffix)) { document.getElementById(hideDetails[i]+ idSuffix).style.display = 'none'; }
				}
			}
			else
			{
				if(document.getElementById('cancel_button1'+idSuffix))
				{
					calNoEntries = document.createElement("div");
					calNoEntries.id = "no_entries";
					calNoEntries.style.position = "absolute";
					calNoEntries.style.left = "20px";
					calNoEntries.style.width = "390px";
					calNoEntries.style.color = "red";
					calNoEntries.style.fontWeight = "bold";
					calNoEntries.style.fontSize = "0.85em";
					if(document.getElementById('the_company') && document.getElementById('the_company').value == 'interflora') {
						calNoEntries.style.top = (parseInt(cancelButton1EL.style.top)) + "px"; //calNoEntries.offsetHeight
					}
					else { calNoEntries.style.top = (parseInt(cancelButton1EL.style.top) - 20) + "px"; }
					calNoEntries.appendChild( document.createTextNode("Unfortunately, it is not possible to deliver your chosen product to that location on that date. You can choose a different date, or an alternative product. We apologise for any inconvenience.") );
					cancelButton1EL.parentNode.appendChild( calNoEntries );
				}
				else if (document.getElementById('cancel_button'+idSuffix))
				{
					calNoEntries = document.createElement("div");
					calNoEntries.id = "no_entries";
					calNoEntries.style.position = "relative";
					calNoEntries.style.color = "red";
					calNoEntries.style.width = "250px";
					calNoEntries.style.fontWeight = "bold";
					calNoEntries.style.fontSize = "0.85em";
					calNoEntries.appendChild(document.createElement("br"));
					calNoEntries.appendChild( document.createTextNode("Unfortunately, it is not possible to deliver your chosen product to that location on that date. You can choose a different date, or an alternative product. We apologise for any inconvenience.") );
					cancelButtonBEL.parentNode.appendChild( calNoEntries );
				}
			}
		}
	}
	else
	{
	/*
		-have a default radio button selected if either same_day or standard are available and three hour, pm and am are not.
		-international is equal to div_standard
	*/
		idSuffix = document.getElementById('tempCartId').value;
		if(document.getElementById('div_standard'+idSuffix) &&
			document.getElementById('div_standard'+idSuffix).style.display == 'block' &&
			document.getElementById('optionStandard'+idSuffix).disabled == false)
		{
			if((document.getElementById('div_am_delivery'+idSuffix) &&
				document.getElementById('div_am_delivery'+idSuffix).style.display == 'block' &&
				document.getElementById('optionAM'+idSuffix).disabled == true)
				||
				(document.getElementById('div_pm_delivery'+idSuffix) &&
				document.getElementById('div_pm_delivery'+idSuffix).style.display == 'block' &&
				document.getElementById('optionPM'+idSuffix).disabled == true)
				||
				(document.getElementById('div_am_delivery'+idSuffix) && document.getElementById('div_pm_delivery'+idSuffix) &&
				document.getElementById('div_am_delivery'+idSuffix).style.display == 'block' &&
				document.getElementById('div_pm_delivery'+idSuffix).style.display == 'block' &&
				document.getElementById('optionAM'+idSuffix).disabled == true && document.getElementById('optionPM'+idSuffix).disabled == true)
				||
				(document.getElementById('div_am_delivery'+idSuffix).style.display == 'none' &&
				document.getElementById('div_pm_delivery'+idSuffix).style.display == 'none'))
			{
				document.getElementById('optionStandard'+idSuffix).checked = true;
				getMethodByDiv(document.getElementById('optionStandard'+idSuffix).id, document.getElementById('optionStandard'+idSuffix).value);
			}
		}
		if(document.getElementById('div_same_day'+idSuffix) &&
			document.getElementById('div_same_day'+idSuffix).style.display == 'block' &&
			document.getElementById('optionSameDay'+idSuffix).disabled == false)
		{
			if(document.getElementById('div_three_hour'+idSuffix) &&
				document.getElementById('div_three_hour'+idSuffix).style.display == 'block')
			{
				if((document.getElementById('option3hr'+idSuffix) && document.getElementById('option3hr'+idSuffix).disabled == true) || (document.getElementById('optionThreeHour'+idSuffix) && document.getElementById('optionThreeHour'+idSuffix).disabled == true))
				{
					document.getElementById('optionSameDay'+idSuffix).checked = true;
					getMethodByDiv(document.getElementById('optionSameDay'+idSuffix).id, document.getElementById('optionSameDay'+idSuffix).value);
				}
			}
			if(document.getElementById('div_three_hour'+idSuffix).style.display == 'none')
			{
				document.getElementById('optionSameDay'+idSuffix).checked = true;
				getMethodByDiv(document.getElementById('optionSameDay'+idSuffix).id, document.getElementById('optionSameDay'+idSuffix).value);
			}
		}
	}
}

function disableRule(valueIdName) {
	var theString = valueIdName;
	var pattAvail = new RegExp(",");
	pattAvail.test(theString);
	var show = RegExp.leftContext;
	var theIdName = RegExp.rightContext;
	var pattColon = new RegExp(":");
	pattColon.test(theIdName);
	var sentID = RegExp.leftContext;
	var sentName = RegExp.rightContext;
	var theCartId = document.getElementById('tempCartId').value;
	if(show != "1"){
		if(sentName == 'standard'){
			if(document.getElementById('optionStandard'+theCartId)){
				document.getElementById('optionStandard'+theCartId).disabled=true;
				document.getElementById('labelStandard'+theCartId).style.color = '#c0c0c0';
			}
		}
		else if(sentName == 'pm_delivery'){
			if(document.getElementById('optionPM'+theCartId)){
				document.getElementById('optionPM'+theCartId).disabled=true;
				document.getElementById('labelPM'+theCartId).style.color = '#c0c0c0';
			}
		}
		else if(sentName == 'am_delivery'){
			if(document.getElementById('optionAM'+theCartId)){
				document.getElementById('optionAM'+theCartId).disabled=true;
				document.getElementById('labelAM'+theCartId).style.color = '#c0c0c0';
			}
		}
		else if(sentName == 'three_hour'){
			if(document.getElementById('optionThreeHour'+theCartId)){
				if(document.getElementById('optionThreeHour'+theCartId)){
					document.getElementById('optionThreeHour'+theCartId).disabled=true;
					document.getElementById('labelThreeHour'+theCartId).style.color = '#c0c0c0';
				}
			}
			else if(document.getElementById('option3hr'+theCartId)){
				if(document.getElementById('option3hr'+theCartId)){
					document.getElementById('option3hr'+theCartId).disabled=true;
					document.getElementById('label3hr'+theCartId).style.color = '#c0c0c0';
				}
			}
		}
		else if(sentName == 'same_day'){
			if(document.getElementById('optionSameDay'+theCartId)){
				document.getElementById('optionSameDay'+theCartId).disabled=true;
				document.getElementById('labelSameDay'+theCartId).style.color = '#c0c0c0';
			}
		}
	}
	if(document.getElementById('method_overlay'+ theCartId)){document.getElementById('method_overlay'+ theCartId).style.display = 'none';}
	else{document.getElementById('method_overlay').style.display = 'none';}
}


// check whether the site is only accessible from a link of an intranet page
	// if it is, check whether the user is from the intranet
	// if the site only accessible from an intranet link and the user is not from
	// the intranet link, then redirect to access_deny.html


	// get the cookie
	var referring_url_required = getcookie("referring_url_required");

	// if the site only accessible from an intranet link
	var current_page_name = document.URL.match(/access_deny\.html/);
	if ((referring_url_required != "") && (current_page_name != "access_deny.html") ) {
		var referring_url_ok = getcookie("referring_url_ok");
		// first time, set cookie
		if ((referring_url_ok == "") || (referring_url_ok == 0)) {
			referring_url_ok = getReferrer().indexOf(referring_url_required);
			if (referring_url_ok == -1) {
				referring_url_ok = 0;
			}
			else {
				referring_url_ok = 1;	
			}
			setcookie("referring_url_ok", referring_url_ok, "");
		}

		// redirect to access_deny.html
		if (referring_url_ok == 0) {
			document.location.href = "/access_deny.html";	
		}
	}

	//set the entry page cookie
	var entry_page = getcookie("entry_page");
	if(entry_page == ''){
		ref = String(document.location);
		host = getHost();
		setcookie('entry_page',ref,host);
	}

	// cookie used to show the current users name
	// replace + with ' ' 
	// get rid of website id from the returned cookie value 
	var user = getcookie('vr_user_fname').replace(/\+/g,' ');
	user = user.replace(/\</g, '&lt;');
	user = user.replace(/\>/g, '&gt;');
	user = user.replace(/\"/g, '&quot;');
	user = user.replace(/\'/g, '&#39;');
	user = user.replace(/\(/g, '&#40;');
	user = user.replace(/\)/g, '&#41;');
	user = user.replace(/\%/g, '&#37;');
	user = user.replace(/\+/g, '&#43;');
	user = user.replace(/\-/g, '&#45;');

	//function to remove SI tab
	function hideSI() {
		changeClass('tab_top-left-simply', 'blank');
		changeClass('tab_top-right-simply', 'blank');
		changeClass('tab_name-simply', 'blank');
		changeClass('tab_top_spacer-simply', 'blank');
		changeClass('tab_spacer-simply', 'blank');
		changeClass('parentcat_1000343', 'blank');
		}


