var clickmessage="Copyright Next Day Flowers 2007. Unauthorised use is prohibited"

function disableclick(e) {
	if (document.all) {
		if (event.button==2||event.button==3) {
			if (event.srcElement.tagName=="IMG"){
				//alert(clickmessage);
			return false;
			}
		}
	}
	else if (document.layers) {
		if (e.which == 3) {
			//alert(clickmessage);
		return false;
		}
	}
	else if (document.getElementById){
		if (e.which==3&&e.target.tagName=="IMG"){
			//alert(clickmessage)
		return false
		}
	}
}

function associateimages(){
for(i=0;i<document.images.length;i++)
	document.images[i].onmousedown=disableclick;
	}

if (document.all)
	document.onmousedown=disableclick
else if (document.getElementById)
	document.onmouseup=disableclick
else if (document.layers)
	associateimages()
	
	
	
function showResponse( OriginalRequest ) {
	var RequestSplit = OriginalRequest.responseText.split("::");
	if( RequestSplit[0] == "ERR" ) {
		alert( RequestSplit[1] );
		return( false );
		
	} else if( RequestSplit[0] == "OUTPUT" ) {
		$(RequestSplit[1]).innerHTML = RequestSplit[3];
		$(RequestSplit[2]).style.display = 'block';
		
		if( RequestSplit[2] == "coNoDelivery" ) {
			document.getElementById('addressChoose').style.display = 'none';
			document.getElementById('coAddressLines').style.display = "none";
		}
		
	} else if( RequestSplit[0] == "ADDRESS" ) {
		
		document.getElementById("shippingCompany").value = RequestSplit[1];
		document.getElementById("shippingAddress").value = RequestSplit[2];
		document.getElementById("shippingAddress2").value = RequestSplit[3];
		document.getElementById("shippingAddress3").value = RequestSplit[4];
		document.getElementById("shippingAddress4").value = RequestSplit[5];
		document.getElementById("shippingCity").value = RequestSplit[6];
		document.getElementById("shippingLocState2").value = RequestSplit[7];
		document.getElementById("shippingZip").value = RequestSplit[8];
	
		document.getElementById('coAddressLines').style.display = "block";
		document.getElementById('addressChoose').style.display = "none";
		document.getElementById('fullPostcode').style.display = "none";
		//document.getElementById("coNextButton").style.display = "block";
		document.getElementById("coNextButton2").style.display = "block";
		
	} else if ( RequestSplit[0] == "ALERT" ) {
		
		if( RequestSplit[1] == "Y" ) {
			document.getElementById("coNextButton2").style.display = "block";
			$(RequestSplit[2]).style.display = 'none';
		} else {
			document.getElementById("coNextButton").style.display = "none";
			document.getElementById("coNextButton2").style.display = "none";
			$(RequestSplit[1]).innerHTML = RequestSplit[3];
			$(RequestSplit[2]).style.display = 'block';
		}
		
	} else {
	}

}

function checkPostcode(postcode) {
	
	if( postcode.length == 0 ) {
		document.getElementById("coNextButton2").style.display = "none";
	} else {
		sendData('postcode2');
	}
}

function checkPostcode2(postcode) {
	
	if( postcode.length == 0 ) {
		document.getElementById("coNextButton2").style.display = "none";
	} else {
		sendData('postcode4');
	}
}

function checkPostcode3(postcode) {
	
	if( postcode.length == 0 ) {
		document.getElementById("coNextButton2").style.display = "none";
	} else {
		document.getElementById("coNextButton2").style.display = "block";
	}
}

function checkDel() {
	var dropdownIndex = document.getElementById('deliveryD').selectedIndex;
	if( dropdownIndex == 0 ) {
		alert( 'Please select a delivery date.' );
		return( false );
	} else {
		return( true );
	}
}

function ShipCosts(e,total) {
	if( e == '12' ) {
		document.getElementById("ShipCst").innerHTML = "&pound;4.99";
		document.getElementById("s").value = "12"
		total = total + 4.99;
	} else if( e == '24' ) {
		document.getElementById("ShipCst").innerHTML = "&pound;0.00";
		document.getElementById("s").value = "24"
	} else if( e == 'S' ) {
		document.getElementById("ShipCst").innerHTML = "&pound;2.99";
		document.getElementById("s").value = "S"
		total = total + 2.99;
	} else if( e == 'N' ) {
		document.getElementById("ShipCst").innerHTML = "&pound;0.00";
		document.getElementById("s").value = "B"
	}
	total = total.toFixed(2);
	document.getElementById("spanTotal").innerHTML = total;
}

function timedDelivery(e) {
	var RequestSplit = e.split("|");
	if( RequestSplit[1] != "Free" )  {
		
		if( document.getElementById("t12hr").checked == true || document.getElementById("t9am").checked == true || document.getElementById("t10am").checked == true ) {
			alert('Sorry, 8am to 6pm is only available for Saturday orders.');
		}
		document.getElementById("t12hr").disabled = true;
		document.getElementById("t9am").disabled = true;
		document.getElementById("t10am").disabled = true;
		document.getElementById("t24hr").checked = "checked";
		ShipCosts('S', vShipTotal);
	} else {
		
		//if( e != 'Saturday, 2 May 2009|Free' ) {
		if( e.substring(0,3) != 'Sat' && e.substring(21,4)!= 'Free' ) {
			document.getElementById("t12hr").disabled = false;
			document.getElementById("t9am").disabled = false;
			document.getElementById("t10am").disabled = false;
			ShipCosts('24', vShipTotal);
		} else {
			document.getElementById("t12hr").disabled = true;
			document.getElementById("t9am").disabled = true;
			document.getElementById("t10am").disabled = true;
			document.getElementById("t24hr").checked = "checked";
			ShipCosts('24', vShipTotal);
		}
	}
	document.getElementById("dd").value = RequestSplit[0];
}

function reshowPostcode() {
	document.getElementById('fullPostcode').style.display = "block";
	document.getElementById('coAddressLines').style.display = "none";
	document.getElementById('addressChoose').style.display = "none";
	document.getElementById("coNextButton").style.display = "none";
}

function getAddressData( value ) {
	if( value ) {
		var url = 'ajax.asp';
		var rand = Math.random(9999);
		var pars = 'action=address&value=' + value + '&rand=' + rand;
		var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars, onComplete: showResponse} );
	}
}

function sendData (action) {
	if( action == 'postcode3' ) { var value = document.getElementById('shippingZipTemp').value; }
	if( action == 'postcode' ) { var value = document.getElementById('shippingZipTemp').value; }
	if( action == 'postcode2' ) { var value = document.getElementById('shippingZip').value; }
	if( !value ) {
		alert( 'Please enter a postcode' );
		return( false );
	}
	document.getElementById('coNoDelivery').style.display = 'none';
	var url = 'ajax.asp';
	var rand = Math.random(9999);
	var pars = 'action=' + action + '&value=' + value + '&rand=' + rand;
	var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars, onComplete: showResponse} );
}		


var popWin = null    // use this when referring to pop-up window
var winCount = 0
var winName = "popWin"
function openPopWin(winURL, winWidth, winHeight, winFeatures, winLeft, winTop){
  var d_winLeft = 20  // default, pixels from screen left to window left
  var d_winTop = 20   // default, pixels from screen top to window top
  winName = "popWin" + winCount++ //unique name for each pop-up window
  closePopWin()           // close any previously opened pop-up window
  if (openPopWin.arguments.length >= 4)  // any additional features? 
                winFeatures = "," + winFeatures
  else 
                winFeatures = ""
  if (openPopWin.arguments.length == 6)  // location specified
                winFeatures += getLocation(winWidth, winHeight, winLeft, winTop)
  else
                winFeatures += getLocation(winWidth, winHeight, d_winLeft, d_winTop)
  popWin = window.open(winURL, winName, "width=" + winWidth 
                                   + ",height=" + winHeight + winFeatures)
  }
function closePopWin(){    // close pop-up window if it is open
  if (navigator.appName != "Microsoft Internet Explorer" 
                  || parseInt(navigator.appVersion) >=4) //do not close if early IE
                if(popWin != null) if(!popWin.closed) popWin.close()
  }
function getLocation(winWidth, winHeight, winLeft, winTop){
  return ""
  }
function getLocation(winWidth, winHeight, winLeft, winTop){
  var winLocation = ""
  if (winLeft < 0)
                winLeft = screen.width - winWidth + winLeft
  if (winTop < 0)
                winTop = screen.height - winHeight + winTop
  if (winTop == "cen")
                winTop = (screen.height - winHeight)/2 - 20
  if (winLeft == "cen")
                winLeft = (screen.width - winWidth)/2
  if (winLeft>0 & winTop>0)
                winLocation =  ",screenX=" + winLeft + ",left=" + winLeft
                                                                + ",screenY=" + winTop + ",top=" + winTop
  else
                winLocation = ""
  return winLocation
  }
