/* Change Visibility of an element */
function changeVis(vID){
	oVis = document.getElementById(vID);
	if (oVis.style.visibility=="hidden"){
		oVis.style.visibility="visible";
		oVis.style.display = "";
	} else {
		oVis.style.visibility="hidden";
		oVis.style.display="none";
	}
}

function changeShow(vID){
	oVis = document.getElementById(vID);
	oVis.style.visibility="visible";
	oVis.style.display = "";
}
function changeHide(vID){
	oVis = document.getElementById(vID);
	oVis.style.visibility="hidden";
	oVis.style.display="none";
}

function checkdelitem(vUrl){
	fRet = confirm("Are you sure you wish to delete this? It is often better to hide an item or set it's date to some time in the past rather than completely delete it."); 
	if(fRet == 1){
		location.replace(vUrl);
	}	
}

/* Swap an image from it's name */
function swapImage(vImage, vFile){
	document.images[vImage].src=vFile;
}


function checkNewDrop(vDD, vOB){
	vDDVal = document.getElementById(vDD).options[document.getElementById(vDD).selectedIndex].value;
	vOBVis = document.getElementById(vOB).style.visibility;
	if( (vDDVal == 'n3w' && vOBVis == "hidden") || (vDDVal != 'n3w' && vOBVis == "visible") ){
		changeVis(vOB);
	}
}

/* Preload any images */
function preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

/* Change Background Color */
function bgChange(menuID, col){
	if(document.getElementById){
		if( document.getElementById(menuID) ){
			document.getElementById(menuID).style.backgroundColor = col;
		}
	} else if(document.all){
		if(document.all(menuID)){
			document.all(menuID).style.backgroundColor = col;
		}
	} 
}

/* Menus expand/close from ID */
var keepMenuOpen=0;
var keepSubOpen=0;

function showMenu(menuID){
	keepMenuOpen= menuID;
	keepSubOpen = (menuID.substr(-2, 2) == 's') ? menuID : 0;
	
	if(document.getElementById){
		document.getElementById(menuID).style.backgroundColor = '#B6BBBD';
		if( document.getElementById(menuID + 's') ){
			document.getElementById(menuID + 's').style.visibility="visible";
			document.getElementById(menuID + 's').style.display="block";
		}
	} else if(document.all){
		document.all(menuID).style.backgroundColor = '#B6BBBD';
		if(document.all(menuID)){
			keepSubOpen= menuID;
			document.all(menuID).style.visibility = "visible";
		}
	} 
}

function closeMenu(menuID){
	//document.getElementById(menuID).style.backgroundColor = '#E6F1E0';
	keepMenuOpen = (menuID == keepMenuOpen) ? 0 : keepMenuOpen;
	setTimeout("hideMenu('" + menuID + "');", 500);
}

function hideMenu(menuID){
  //document.menuOpen.innerHTML=keepMenuOpen;
  if ( keepMenuOpen != menuID && (keepSubOpen == 0 || menuID + 's' != keepSubOpen) ){
	  
    if(document.getElementById){
		document.getElementById(menuID).style.backgroundColor = '#898C8E';
		if( document.getElementById(menuID + 's') ){
			document.getElementById(menuID + 's').style.visibility="hidden";
		}
	}
	else if(document.all){
		document.all(menuID).style.backgroundColor = '#898C8E';
		if(document.all(menuID)){
			document.all(menuID).style.visibility = "hidden";
		}
	}
  }
}

/* Create a popup */
function fPopUp(vURL, vW, vH){
	vDay = new Date();
	vId = vDay.getTime();
	eval("page" + vId + " = window.open(vURL, '" + vId + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+vW+",height="+vH+"');");
}

/* Create a popup */
function popup(n){
	window.open( n , 'popup', 'width=934,height=680,scrollbars=yes,toolbar=no,location=no;directories=no,status=no,resizable=yes,');
	return 1;
}

/* Check action before carrying out */
function fCheckAct(vMessage, vUrl){
	vCheck = confirm(vMessage); 
	if(vCheck == 1){
		location.replace(vUrl);
	}
}
function fAddTag(vTag, vID){
	oTB = document.getElementById(vID);
	if(oTB.value.toLowerCase().indexOf(vTag.toLowerCase()) != -1){
		alert('Tag (' + vTag + ') is already included');
	}else{
		oTB.value += ';' + vTag;
	}
}

function cardTypeChanged(selectObject){
	sDisabledBGColour = "#DDDDDD";
	aElements = new Array('cardHolder', 'cardNumber', 'securityCode', 'issueNumber', 'startDate][month', 'startDate][year', 'expiryDate][month', 'expiryDate][year');
	if(selectObject.value=='PAYPAL') {
		for(i=0;i<aElements.length;i++){
			if( selectObject.form['data[payment]['+ aElements[i]+']'].type.indexOf('select') == -1){
				selectObject.form['data[payment]['+ aElements[i]+']'].value='';
				selectObject.form['data[payment]['+ aElements[i]+']'].style.background=sDisabledBGColour;
			}
			selectObject.form['data[payment]['+ aElements[i]+']'].disabled = true;			
		}
		alert('You just selected a payment method of PayPal so card details will not be required here.\n\nAfter clicking \'Submit order\' you will be securely redirected to the PayPal website to authorise your details.');
	} else {
		for(i=0;i<aElements.length;i++){
			if( selectObject.form['data[payment]['+ aElements[i]+']'].type.indexOf('select') == -1){
				selectObject.form['data[payment]['+ aElements[i]+']'].style.background='';
			}
			selectObject.form['data[payment]['+ aElements[i]+']'].disabled = false;			
		}
	}
}

function deliveryToBilling(selectObject){
	if(selectObject.checked == true){
		if(selectObject.form['data[user][mandatory][deliveryAddress1]'].value != undefined){
			selectObject.form['data[user][mandatory][billingAddress1]'].value = selectObject.form['data[user][mandatory][deliveryAddress1]'].value;
		}
		if(selectObject.form['data[user][voluntary][deliveryAddress2]'].value != undefined){
			selectObject.form['data[user][voluntary][billingAddress2]'].value = selectObject.form['data[user][voluntary][deliveryAddress2]'].value;
		}
		if(selectObject.form['data[user][mandatory][deliveryTown]'].value != undefined){
			selectObject.form['data[user][mandatory][billingTown]'].value = selectObject.form['data[user][mandatory][deliveryTown]'].value;
		}
		if(selectObject.form['data[user][mandatory][deliveryPostcode]'].value != undefined){
			selectObject.form['data[user][mandatory][billingPostcode]'].value = selectObject.form['data[user][mandatory][deliveryPostcode]'].value;
		}
		if(selectObject.form['data[user][mandatory][deliveryFullName]'].value != undefined){
			selectObject.form['data[user][mandatory][billingFullName]'].value = selectObject.form['data[user][mandatory][deliveryFullName]'].value;
		}
		if(selectObject.form['data[user][mandatory][deliveryCountry]'].options.selectedIndex != undefined){
			selectObject.form['data[user][mandatory][billingCountry]'].options.selectedIndex = selectObject.form['data[user][mandatory][deliveryCountry]'].options.selectedIndex;
		}
	}
}

function submitEBookForm(vS){
	document.bookingForm['goNextPage'].value = vS;
	document.bookingForm['next'].click();
}
