// This will set the default link message
window.defaultStatus='Comber Young Men F.C.';

/**************************************************************************************
Javascript Functions
--------------------

Author: R. J. Dean

addToBasket(code,cat) 							- Adds an item onto the end of the shopping list
removeFromBasket(index,cat) 					- Removes an item from the specified index in the shopping list
ToggleSection(sectionID,imgID,openImg,closeImg)	- Makes a section invisible/visible and changes the image if required
checkExpiryDate(form) 							- Makes sure expiry date has not passed
checkTelno(form, field) 						- Checks first digit is zero
checkNumeric(form, field) 						- Checks for numeric-only input
checkSortCode(form, field)	 					- Checks length of sort code is 6
checkCardNo(form, field) 						- Checks length of card number is 16
checkForEmpty(form, field)	 					- Checks to make sure field is not empty
checkForValue(form, field, value)	 			- Checks to make sure field contains a specific value
checkEmailAddress(form, field)					- Checks a field contains a valid email address  
validateFields(form, arrFields)					- Runs specified checks against an array of fields according to name  
toggleShowHide(form,button)						- Toggles value of selected button
useDelAddress(form)								- Disables inv boxes and enters del address info into them
ChangeRowClass(sObject, sNewClass)				- Changes colour of menu items and underline link
OpenProductWindow(URL)							- Opens a small window containing page at URL
OpenProgressWindow(URL)							- Opens a  very small window containing page at URL
convertAmptoAmp(URL)							- Converts "&" into "%26"
ToggleImage(imgID, outImg, overImg) 			- Changes the image src
HideAllTabs()									- Hides all tabs listed in tabs() array
ShowTab(sTab)									- Shows a selected tab
ShowAllTabs()									- Shows all tabs listed in tabs() array
ShowSection(sectionID)							- Shows a selected section
sendArgs(sForm,strArgs)							- Sends arugments to fields in the form and submits the form
getQS(sSearchTerm)								- Finds the value of a parm in the QueryString
setCurrency(currency,amount)					- Changes the data posted to PayPal when currency changes
submitWeddingList(sortField)            		- Get item that should be submitted and add the values to querystring
startTimer()                            		- Counts down to a date and enters result in a form element
checkForAnonymous(form, field, value)   		- Check for anonymous nickname

**************************************************************************************/

function addToBasket(code,cat)
{
// Add an item to the shopping list
	var itemsinbasket
	var qty
	itemsinbasket = document.frmProducts.itemsinbasket.value;
	qty = document.frmProducts.elements['selQty' + code].value;
	if (code != "")
	{
		if (itemsinbasket == "")
		{
			document.frmProducts.itemsinbasket.value = qty + 'x' + code;
		}
		else
		{
			if (itemsinbasket.indexOf("x" + code) != -1)
			{
				var pos
				var sCode
				pos = itemsinbasket.indexOf("x" + code);
				iCommaPos = itemsinbasket.lastIndexOf(',',pos)
				iDiff = (pos - iCommaPos)-1;
				qty = parseInt(qty) + parseInt(itemsinbasket.substring(pos-iDiff,pos));
				sCode = code.toString();
				itemsinbasket = itemsinbasket.replace(itemsinbasket.substring(pos-iDiff,pos+sCode.length+1),qty+ "x" + code)
				document.frmProducts.itemsinbasket.value = itemsinbasket;
			}
			else
			{
				document.frmProducts.itemsinbasket.value = itemsinbasket + ',' + qty + 'x' + code;
			}	
		}
	}
	document.frmProducts.category.value = cat;
	document.frmProducts.submit();
}

function removeFromBasket(index,cat)
{
// Remove an item from the basket list
	document.frmProducts.rem.value = index;
	document.frmProducts.category.value = cat;
	document.frmProducts.submit();	
}

function ToggleSection(sectionID, imgID, openImg, closeImg)
{
// Show or hide a section and change the image if required
	var oSection = document.getElementById(sectionID);
	
	if (imgID != '')
	{
		var imgSection = document.getElementById(imgID);
	}
	
	if (oSection.style.display == 'block')
	{
		oSection.style.display = 'none';
		if (imgID != '' && imgSection.src != '')
		{
			imgSection.src = closeImg;
			imgSection.alt = 'Expand';
		}
	}
	else
	{
		oSection.style.display = 'block';
		if (imgID != '' && imgSection.src != '')
		{
			imgSection.src = openImg;
			imgSection.alt = 'Collapse';
		}
	}
}

function checkExpiryDate(form)
{
//Prevent past dates being entered
	var today = new Date();
	var iMonth = today.getMonth();
	var iYear = today.getYear();

	iMonth++;
	if(iMonth.length = 1)
	{
		iMonth = '0' + iMonth;
	}
	
	if(document.forms[form].expMonth.value < iMonth && document.forms[form].expYear.value == iYear)
	{
		document.forms[form].expYear.value = iYear + 1;
	}
}

function checkDateValid(form,field)
{
//Check the date is valid and prevent past dates being entered
	var today = new Date();
	var dateDatetocheck;
	var dateArray;
	var day,month,year;
	dateArray = document.forms[form].elements[field].value.split("/")
	day = dateArray[0];
	month = dateArray[1]-1;
	year = dateArray[2];
	
	dateDatetocheck = new Date(year,month,day);

	if(!isValidDate(document.forms[form].elements[field].value) || isNaN(dateDatetocheck) || dateDatetocheck < today)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function isValidDate(d) {
	//var strDatestyle = "US"; //United States date style
	var strDatestyle = "EU";  //European date style
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intDay;
	var intMonth;
	var intYear;
	var booFound = false;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var err = 0;
	var strMonthArray = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	strDate = d;
	if (strDate.length < 1) {
		return false;
	}
	if (strDate.toLowerCase()=="today" || strDate.toLowerCase()=="now"){return true;}

	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) 
			{
				err = 1;
				return false;
			}
			else 
			{
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
		}
	}

	if (booFound == false) {
		if (strDate.length>5) {
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
		}
		else
			return false;
	}
	
	// verify year part	2 or 4 digits
	if (strYear.length != 2 && strYear.length != 4) {return false;}
	if (isNaN(strYear)){return false;}
	// US style (swap month and day)
	if (strDatestyle == "US") {
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}

	// verify 1 or 2 digit integer day
	if (strDay.length<1 || strDay.length>2) {return false;}
	if (isNaN(strDay)){return false;}
	
	// month may be digits of characters, hence following check
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) {
		for (i = 0;i<12;i++) {
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
			}
		}
		if (isNaN(intMonth)) {
			err = 3;
			return false;
		}
	}

	intDay=parseInt(strDay,10);
	intYear = parseInt(strYear, 10);
	
	if (intMonth>12 || intMonth<1) {
		err = 5;
		return false;
	}
	
	// day in month check
	if (intDay < 1 || intDay > 31){return false;}
		
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intDay > 30)) {
		return false;
	}
	
	if (intMonth == 2) {
		if (LeapYear(intYear)) {
			if (intDay > 29) {return false;}
		}
		else 
		{
			if (intDay > 28) {return false;}
		}
	}
	
	return true;
}

function LeapYear(intYear) {
	if (intYear % 100 == 0) {
		if (intYear % 400 == 0) { return true; }
	}
	else {
		if ((intYear % 4) == 0) { return true; }
	}
	return false;
}

function checkTelno(form, field)
{
// Check first digit is zero
	var sFieldText
	sFieldText = document.forms[form].elements[field].value;
	if (sFieldText.substr(0,1) != '0')
	{
		return false;
	}
	else
	{
		return true;
	}
}
function checkNumeric(form, field)
{
// Check for numeric-only input
	var i
	var IsNumber=true;
	var sFieldText
	var ValidChars = "0123456789";
	var Char;
	
	sFieldText = document.forms[form].elements[field].value;
	for (i = 0; i< sFieldText.length && IsNumber == true; i++) 
	{ 
		Char = sFieldText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			return false;
		}
	}
}

function checkSortCode(form, field)
{
// Check length of sort code
	var sortcode = document.forms[form].sortcode.value;
	if (sortcode.length != 6)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function checkCardNumber(form, field)
{
// Check length of card number
	var cardno = document.forms[form].cardno.value;
	if (cardno.length != 16)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function checkForEmpty(form, field)
{
// Check for empty fields
	var i;
	var bFormComplete;
	if (document.forms[form].elements[field])
	{
		if(document.forms[form].elements[field].value == "")
		{
			//alert('The ' + document.forms[sForm].elements[arrFields[i]].name + ' field is empty!')
			bFormComplete = 'FALSE';
		}
	}
	
	if(bFormComplete != 'FALSE')
	{
		return true;
	}
	else
	{
		return false;
	}
}

function checkForValue(form, field, value)
{
// Check for an anonymous nickname
	var bFormComplete;
	if (document.forms[form].elements[field])
	{
		if(document.forms[form].elements[field].value == value || document.forms[form].elements[field].value == '')
		{
		    return true;
		}
	    else
	    {
		    return false;
	    }
	}
}

function checkEmailAddress(form, field)
{
	var emailAddress = document.forms[form].elements[field].value;
	var posOfAtSign = emailAddress.indexOf('@');
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,3}$/;
	// If there is an @ sign continue checking
	if (posOfAtSign >= 0)
	{
		// Make sure there are not more than 1 @ sign
		if(((emailAddress.search(exclude) != -1)||
		(emailAddress.search(check))== -1)||
		(emailAddress.search(checkend) == -1))
		{
			return false;
		}
	}
	else
	{
		if(posOfAtSign != -1)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}

function compareFields(form, field1, field2)
{
	if(document.forms[form].elements[field1].value==document.forms[form].elements[field2].value)
	{
		return true;
	}
	else
	{
		return false;
	}
}

var oFileSystem;

function checkFileSize(form, field)
{
    try
    {
        oFileSystem = new ActiveXObject("Scripting.FileSystemObject");
    }
    catch(err)
    {
        var sErrorMsg = 'Unable to check the file size of the upload'
    }
	var strPath = "";
	if(document.forms[form].elements[field].value)
	{
		strPath = document.forms[form].elements[field].value;
	}
    if(strPath != "")
    {
        if (oFileSystem)
        {
	        try
	        {
	            var intFileSize = oFileSystem.GetFile(strPath).Size;
	        }
	        catch(err)
	        {
	            var sErrorMsg = 'File not found'
	        }
	        if (intFileSize > 204800)
	        {
		        return false;
	        }
	        else
	        {
		        return true;
	        }
        }
        else
        {
            return true;
        }
    }
}

function getFileCreated(form, field)
{
    try
    {
        oFileSystem = new ActiveXObject("Scripting.FileSystemObject");
    }
    catch(err)
    {
        var sErrorMsg = 'Unable to check the file size of the upload'
    }
	var strPath = document.forms[form].elements[field].value;
	if (oFileSystem)
	{
	    strDateCreated = oFileSystem.GetFile(strPath).DateCreated;
	    return strDateCreated;
	}
}

function validateFields(sForm, arrField, bSubmit)
{
// Run specified checks against an array of fields according to name
var fieldname;
var sErrorMsg = '';
var i, x, selFolder;
	var selFolder = document.getElementById("selFolder")
	for(i=0;i<arrField.length && sErrorMsg=='';i++)
	{
		if(document.forms[sForm].elements[arrField[i]])
		{
			fieldname = document.forms[sForm].elements[arrField[i]].name;
		}
		switch (fieldname)
			{
			case "File1":
				if (checkForEmpty(sForm, fieldname) == false)
				{
					sErrorMsg = 'Please select an image file to upload';
					break;
				}
				if (checkFileSize(sForm, fieldname) == false)
				{
					sErrorMsg = 'You attempted to upload a file that is larger than 200Kb, please reduce the size of the file.';
					break;
				}
				break;
			case "givenname":
				if (checkForEmpty(sForm, fieldname) == false)
				{
					sErrorMsg = 'Please enter your given name';
					break;
				}
				break;
			case "name":
				if (checkForEmpty(sForm, fieldname) == false)
				{
					sErrorMsg = 'Please enter your name';
					break;
				}
				break;
			case "customername":
				if (checkForEmpty(sForm, fieldname) == false)
				{
					sErrorMsg = 'Please enter a customer name';
					break;
				}
				break;
			case "bookingdatetime":
				if (checkForEmpty(sForm, fieldname) == false)
				{
					sErrorMsg = 'Please enter a valid date for your booking';
					break;
				}
				if (checkDateValid(sForm, fieldname) == false)
				{
					sErrorMsg = 'Please enter a valid date for your booking';
					break;
				}
				break;
			case "enquiry":
				if (checkForEmpty(sForm, fieldname) == false)
				{
					sErrorMsg = 'Please enter the details of your enquiry';
					break;
				}
				break;
			case "cardno":
				if (checkForEmpty(sForm, fieldname) == false)
				{
					sErrorMsg = 'Please enter a valid credit card number';
					break;
				}
				if (checkNumeric(sForm, fieldname) == false)
				{
					sErrorMsg = 'Card Number should only contain numbers';
					break;
				}
				if (checkCardNumber(sForm, fieldname) == false)
				{
					sErrorMsg = 'Card Number should contain 16 digits';
					break;
				}
				break;
			case "sortcode":
				if (checkForEmpty(sForm, fieldname) == false)
				{
					sErrorMsg = 'Please enter a valid sort code';
					break;
				}
				if (checkNumeric(sForm, fieldname) == false)
				{
					sErrorMsg = 'Sort Code should only contain numbers';
					break;
				}
				if (checkSortCode(sForm, fieldname) == false)
				{
					sErrorMsg = 'Sort Code should contain 6 digits';
					break;
				}
				break;
			case "telno":
				if (checkForEmpty(sForm, fieldname) == false)
				{
					sErrorMsg = 'Please enter your telephone number';
					break;
				}
				if (checkNumeric(sForm, fieldname) == false)
				{
					sErrorMsg = 'Telephone number should only contain numbers';
					break;
				}
				if (checkTelno(sForm, fieldname) == false)
				{
					sErrorMsg = 'Telephone number should begin with zero';
					break;
				}
				break;
			case "telephone":
				if (checkForEmpty(sForm, fieldname) == false)
				{
					sErrorMsg = 'Please enter your telephone number';
					break;
				}
				if (checkNumeric(sForm, fieldname) == false)
				{
					sErrorMsg = 'Telephone number should only contain numbers';
					break;
				}
				if (checkTelno(sForm, fieldname) == false)
				{
					sErrorMsg = 'Telephone number should begin with zero';
					break;
				}
				break;
			case "mobileno":
				if (checkForEmpty(sForm, fieldname) == false)
				{
					sErrorMsg = 'Please enter your mobile number';
					break;
				}
				if (checkNumeric(sForm, fieldname) == false)
				{
					sErrorMsg = 'Mobile number should only contain numbers';
					break;
				}
				if (checkTelno(sForm, fieldname) == false)
				{
					sErrorMsg = 'Mobile number should begin with zero';
					break;
				}
				break;
			case "loginname":
				if (checkForEmpty(sForm, fieldname) == false)
				{
					sErrorMsg = 'Please enter your login name';
					break;
				}
				if (checkEmailAddress(sForm, fieldname) == false)
				{
					sErrorMsg = 'The Login Name must contain a valid email address';
					break;
				}
				break;
			case "email":
				if (checkForEmpty(sForm, fieldname) == false)
				{
					sErrorMsg = 'Please enter a valid email address';
					break;
				}
				if (checkEmailAddress(sForm, fieldname) == false)
				{
					sErrorMsg = 'The Email address field must contain a valid email address';
					break;
				}
				if (compareFields(sForm, fieldname, fieldname+'_verify') == false)
				{
					sErrorMsg = 'The email addresses entered do not match';
					break;
				}
				break;
			case "txtSubject":
				if (checkForEmpty(sForm, fieldname) == false)
				{
					sErrorMsg = 'Please enter a subject';
					break;
				}
				break;
			case "billingstreetaddress":
				if (checkForEmpty(sForm, fieldname) == false)
				{
					sErrorMsg = 'Please enter a billing street address';
					break;
				}
				break;
			case "venue":
				if (checkForEmpty(sForm, fieldname) == false)
				{
					sErrorMsg = 'Please enter the name of your venue';
					break;
				}
				break;
			case "eventdescription":
				if (checkForEmpty(sForm, fieldname) == false)
				{
					sErrorMsg = 'Please enter a description of your event';
					break;
				}
				break;
			case "txtMessage":
				if (checkForEmpty(sForm, fieldname) == false)
				{
					sErrorMsg = 'Please enter your message text';
					break;
				}
				break;
			case "txtNickname":
				if (checkForEmpty(sForm, fieldname) == false)
				{
					sErrorMsg = 'Please enter a nickname';
					break;
				}
				if (checkForValue(sForm, fieldname,'Anonymous') == true)
				{
					sErrorMsg = 'Please enter a valid nickname';
					break;
				}
				break;
			case "txtFolder":
				if (document.getElementById('radiobutton2').checked == true)
				{
					if (checkForEmpty(sForm, fieldname) == false)
					{
						sErrorMsg = 'Please select an event';
						break;
					}
					else
					{
						for(x=0; x<selFolder.length; x++)
						{
							if (checkForValue(sForm, fieldname,selFolder(x).text) == true)
							{
								sErrorMsg = 'Your event already exists, please select an existing event or enter a new event';
								break;
							}
						}
					}
				}
				break;
			default:
				if (checkForEmpty(sForm, fieldname) == false)
				{
					sErrorMsg = 'The required fields are not complete';
					break;
				}
				break;
			}
	}
	
	if (sErrorMsg == '')
	{
		if (sForm == 'frmUpload')
		{
		    OpenProgressWindow('progress.asp?message=Checking and uploading file');
		}
		if(bSubmit == true)
		{
			document.forms[sForm].submit();
		}
		else
		{
			return false;
		}
	}
	else
	{
		alert(sErrorMsg);
		document.forms[sForm].elements[fieldname].focus();
	}
}

function toggleShowHide(form,button)
{
// Toggle value of selected button
	if (document.forms[form].elements[button].value == 'Show Order Info')
	{
		document.forms[form].elements[button].value = 'Hide Order Info';
	}
	else
	{
		document.forms[form].elements[button].value = 'Show Order Info';
	}
}

function useDelAddress(form)
{
	var arrFields = new Array('address1','address2','address3','town','county','postcode');
	var i;
	if (document.forms[form].elements['UseDEL'].value == 0)
	{
		document.forms[form].elements['UseDEL'].value = 1;
	}
	else
	{
		document.forms[form].elements['UseDEL'].value = 0;
	}
	//alert("Checkbox value is: " + document.forms[form].elements['UseDEL'].value);
	
	for (i=0;i<arrFields.length;i++)
	{
		if (document.forms[form].elements['INV' + arrFields[i]].disabled == false)
		{
			document.forms[form].elements['INV' + arrFields[i]].value = document.forms[form].elements['DEL' + arrFields[i]].value;
			document.forms[form].elements['INV' + arrFields[i]].disabled = true;
		}
		else
		{
			document.forms[form].elements['INV' + arrFields[i]].value = document.forms[form].elements['hiddenINV' + arrFields[i]].value;
			document.forms[form].elements['INV' + arrFields[i]].disabled = false;
		}
	}
}

function ChangeRowClass(sObject, sNewClass)
{
	sObject.className = sNewClass;
}

function OpenProductWindow(URL)
{
	var ProductWindow;
	ProductWindow = window.open(convertAmptoAmp(URL),'productPopup','width=545,height=300,scrollbars=no,location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=200,top=130')		
	ProductWindow.focus();	
}

function OpenArticleWindow(URL)
{
	var ProductWindow;
	ProductWindow = window.open(convertAmptoAmp(URL),'productPopup','width=800,height=600,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=200,top=130')		
	ProductWindow.focus();	
}

function OpenCommentWindow(URL)
{
	var ProductWindow;
	ProductWindow = window.open(convertAmptoAmp(URL),'commentPopup','width=545,height=300,scrollbars=no,location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=200,top=130')		
	ProductWindow.focus();	
}

function OpenProgressWindow(URL)
{
	var ProgressWindow;
	ProgressWindow = window.open(convertAmptoAmp(URL),'progressWindow','width=150,height=100,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=200,top=130')		
	ProgressWindow.focus();	
}

function convertAmptoAmp(URL)
{
	var permURL = URL.toString();
	var newURL;
	var ampPos = permURL.indexOf("&amp;");
	
	if(ampPos >= 0)
	{
		newURL = permURL.substr(0,permURL.indexOf("&amp;")) + '%26' + permURL.substr(ampPos + 5, permURL.length);
	}
	else
	{
		newURL = permURL;
	}
	return newURL;
}

function ToggleImage(imgID, newImg)
{
	if (imgID != '')
	{
		var img = document.getElementById(imgID);
			img.src = newImg;
	}
}

function ToggleImages(sectionID, imgID, openImg, closeImg)
{
// Show or hide a section and change the image if required
	var oSection = document.getElementById(sectionID);
	
	if (imgID != '')
	{
		var imgSection = document.getElementById(imgID);
	}
	
	if (oSection.style.display == 'block')
	{
		if (imgID != '' && imgSection.src != '')
		{
			imgSection.src = closeImg;
			imgSection.alt = 'Expand';
		}
	}
	else
	{
		if (imgID != '' && imgSection.src != '')
		{
			imgSection.src = openImg;
			imgSection.alt = 'Collapse';
		}
	}
}
tabs = new Array('neworders','approved','picking','packing','despatch','cancel','returns','invoices','credits')
function HideAllTabs()
{
	for (i=0;i<tabs.length;i++)
	{
		var oSection = document.getElementById(tabs[i]);
		if (oSection.style.display == 'block')
		{
			oSection.style.display = 'none';
		}
		//var oDiv = document.getElementById('nav_' + tabs[i]);
		//oDiv.className = 'sys-toppane-bgcolor';
	}
}

function ShowTab(sTab)
{
	HideAllTabs()
	var oDiv = document.getElementById(sTab);
	//oDiv.className = 'sys-toppane-selection';
	oDiv.style.display = 'block';
	var oSubDiv = document.getElementById('sub_' + sTab);
	oSubDiv.style.display = 'block';
	document.frmState.sectiontoshow.value = sTab;
}

function ShowAllTabs()
{
	//if (isNS6)
	{
		var tabToShow;
		for(i=0;i<tabs.length;i++)
		{
			tabToShow = document.getElementById(tabs[i]);
			tabToShow.style.display = "block";
		}
	}
}

function ShowSection(sectionID)
{
// show a section
	var oSection = document.getElementById(sectionID);
	oSection.style.display = 'block';
}

function sendArgs(sForm,strArgs)
{
	var arrArgs;
	arrArgs = strArgs.split(",");
	for(i=0;i<arrArgs.length;i++)
	{
		strValue = arrArgs[i];
		arrValue = strValue.split("=");
		sFieldName = arrValue[0];
		sValue = arrValue[1];
		document.forms[sForm].elements[sFieldName].value = sValue;
	}
	document.forms[sForm].sectiontoshow.value = document.frmState.sectiontoshow.value;
	document.forms[sForm].submit();
}

function getQS(sSearchTerms)
{
	var arrSearchTerms = sSearchTerms.split(',');
	var query = window.location.search.substring(1);
	var parms = query.split('&');
	var sSearchTerm;
	var pos;
	var val;
	for (var j=0; j<arrSearchTerms.length; j++)
	{
		sSearchTerm = arrSearchTerms[j];
		for (var i=0; i<parms.length; i++)
		{
			pos = parms[i].indexOf(sSearchTerm);
			if (pos >= 0)
			{
				val = parms[i].substring(pos+(sSearchTerm.length+1));
				document.frmCustomer.elements[sSearchTerm].value=val;
			}
		}
	}
	switch (document.frmCustomer.cc.value)
	{
		case 'GBP':
			document.getElementById('amount').innerHTML = '£' + document.frmCustomer.amt.value;
			break
		case 'USD':
			document.getElementById('amount').innerHTML = '$' + document.frmCustomer.amt.value;
			break
		case 'EUR':
			document.getElementById('amount').innerHTML = '€' + document.frmCustomer.amt.value;
			break
		default:
			document.getElementById('amount').innerHTML = '£' + document.frmCustomer.amt.value;
	}
}

function setCurrency(currency,amount)
{
		document.frmPayPal.currency_code.value = currency;
		document.frmPayPal.amount_1.value = amount;
}

function submitWeddingList(sortField)
{
    var i;
    var sFields = '';
		for (var i=1; i<100; i++)
		{
			if(document.getElementById('txtReserve'+i) && document.getElementById('txtReserve'+i).value != 'Enter your name here' && document.getElementById('txtReserve'+i).value != '')
			{
		        sFields = sFields + '&' + document.getElementById('txtReserve'+i).name + '=' + document.getElementById('txtReserve'+i).value + '&' + document.getElementById('ResQty'+i).name + '=' + document.getElementById('ResQty'+i).value;
			}
		}
		window.location = 'default.asp?id=wlist&sortby=' + sortField + sFields;
}

function startTimer(message,wedy,wedmonth,wedd,wedh,wedm) 
{
// message,year,month,day,hour,min
	var today = new Date()
	var gmtHours = today.getTimezoneOffset()/60
	var wedding = new Date(wedmonth+" "+wedd+", "+wedy+" "+(wedh-gmtHours)+":"+wedm+":00")

	var d=today.getDate()
	var mo=today.getMonth()+1
	var y=today.getFullYear()
	var h=today.getHours()
	var m=today.getMinutes()
	var s=today.getSeconds()

	var wedmo=wedding.getMonth()+1
	var weds=wedding.getSeconds()

	var drem;
	var morem;
	var yrem;
	var hrem;
	var mrem;
	var srem;
	
	if (weds<s)
		{srem=weds+60-s}
	else
		{srem=weds-s}

	if (s==0)
	{
		if (wedm<m)
			{mrem=wedm+60-m}
		else
		{
			if(m==0 && drem>0 && hrem>0)
			{
				if(s==0){mrem=(wedm-m)+60}
				else{mrem=(wedm-(m+1))+60}
			}
			else
			{
				mrem=wedm-m
			}
		}
	}
	else
	{
		if (wedm<m)
			{mrem=wedm+60-(m+1)}
		else
		{
			if(m==0){mrem=(wedm-(m+1))}
			else{mrem=wedm-(m+1)}
		}
	}
	
	drem=wedd-d
	
	var arrMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31)
	if (y==wedy)
	{
	    for(var i=today.getMonth();i<wedding.getMonth();i++)
	    {
	    drem+=arrMonth[today.getMonth()]
	    }
	}
	else
	{
	    for(var i=today.getMonth();i<12;i++)
	    {
	    drem+=arrMonth[i]
	    }
	    for(var i=0;i<wedding.getMonth();i++)
	    {
	    drem+=arrMonth[i]
	    }
	}

	if (wedh<h)
	{
		if(wedm<m)
		{
		hrem=(wedh-(h+1))+24;
		drem--;
		}
		else
		{
		hrem=wedh-h;
		}
	}
	else
	{
		if(wedh==h)
		{
			if(drem>0)
			{
				if(wedm<m)
				{
				hrem=(wedh-(h+1))+24;
				drem--;
				}
				else
				{
				hrem=wedh-h;
				}
			}
			else
			{
			hrem = 0;
			}
		}
		else{
			if(wedm<m){hrem=(wedh)-(h+1);}
			else{hrem=(wedh)-(h);}
			}
	}
	if (mrem < 0){mrem += 60;hrem --;}
	if (hrem < 0){hrem += 24;drem --;}
	
	if (mrem==60){mrem=0;hrem++;}
	if (hrem==24){hrem=0;drem++;}
    
	if(today>wedding)
		{
			var sWeddingMessage = message;
			document.getElementById('weddingtimer').innerHTML=sWeddingMessage;
		}
	else
	{
		var sTimeRemaining = "Countdown to the big day: ";
		if (1>0){sTimeRemaining = sTimeRemaining+addZero(drem)+" days "}
		if (1>0){sTimeRemaining = sTimeRemaining+addZero(hrem)+" hrs "}
		if (1>0){sTimeRemaining = sTimeRemaining+addZero(mrem)+" mins "}
		if (1>0){sTimeRemaining = sTimeRemaining+addZero(srem)+" s"}
		document.getElementById('weddingtimer').innerHTML=sTimeRemaining;
		t=setTimeout("startTimer('"+message+"',"+wedy+",'"+wedmonth+"',"+wedd+","+wedh+","+wedm+")",500)
	}
}

function addZero(x)
{
    if(x<10){x="0"+x;}
    return x;
}

function OpenPhotoViewer(URL)
{
	var photoViewer;
	photoViewer = window.open(convertAmptoAmp(URL),'smallPopup','width=670,height=375,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=200,top=50')		
	photoViewer.focus();	
}

function checkForAnonymous(form, field, value)
{
	var sErrorMsg = '';
	if (checkForValue(form, field, value) == true)
	{
		sErrorMsg = 'Please enter a valid nickname';
	}
	
	if (sErrorMsg == '')
	{
        document.forms[form].submit();
	}
	else
	{
		alert(sErrorMsg);
	}
}

function clearField(form,field,value)
{
   // Clear the field if the field contains a specific value
   if(document.forms[form].elements[field])
   {
        if(document.forms[form].elements[field].value == value)
        {
            document.forms[form].elements[field].value = '';
        }
   }
}

var g_idFlyPopup = -1;
var g_oPopup;
                    
function ShowPopup(msg)
{
    g_oPopup = window.createPopup();
    var oPopupBody = g_oPopup.document.body;
    var szFont = window.document.body.currentStyle.fontFamily;
    var szHTML = "<TABLE height=100% width=100% cellpadding=4 cellspacing=0 style=\"font-family:"+szFont+";font-size:100%;\"><TR "+
                    //"style=\"background-image:url(images/close_button.gif);background-repeat:no-repeat;background-position:99% 99%"\"+
                    "><TD align=middle >"+
                    msg+
                    "</TD></TR></TABLE>";
                    oPopupBody.innerHTML = szHTML;
                    oPopupBody.style.fontSize = '10pt';
                    //oPopupBody.style.cursor="hand";
                    oPopupBody.style.color = "#000084";
                    oPopupBody.style.borderWidth='1px';
                    oPopupBody.style.borderStyle='window-inset';
                    oPopupBody.style.borderColor="#000084";
                    //oPopupBody.style.borderColor='activeborder';
                    //oPopupBody.style.backgroundImage="url(images/tile_back.gif)";
                    //oPopupBody.style.backgroundRepeat="repeat";
                    //oPopupBody.style.backgroundPosition="center center";
                    oPopupBody.style.backgroundColor="#ffffff";
                    flyInit();
                    if (g_idFlyPopup == -1)
                        g_idFlyPopup = window.setInterval("flyMove('up')",10);
}

function flyInit()
{
    flyMove.curH = 0;
    if (window.document.dir === "rtl")
        flyMove.curX = 0;
    else
        flyMove.curX = window.screen.availWidth - flyMove.flyWidth;
        flyMove.curY = window.screen.availHeight;
}

flyMove.curH = 0;
flyMove.curY = 0;
flyMove.curX = 0;
flyMove.flyHeight = 126;
flyMove.flyWidth = 130;

function flyMove(direction)
{
    if (direction == 'up')
    {
        flyMove.curH += 2;
        flyMove.curY -= 2;

        if (flyMove.curH >= flyMove.flyHeight)
        {
            window.clearInterval(g_idFlyPopup);
            g_idFlyPopup = -1;
            window.setTimeout("closePopup()", 3000);
        }
        else
        {
            g_oPopup.show(800,flyMove.curY,200,flyMove.curH,100);
        }
    }
    else
    {
        flyMove.curH -= 5;
        flyMove.curY += 5;

        if (flyMove.curH < 0)
        {
            window.clearInterval(g_idFlyPopup);
            g_idFlyPopup = -1;
        }
        else
        {
            g_oPopup.show(800,flyMove.curY,200,flyMove.curH,100);
        }
    }
}

function closePopup()
{
    if (null != g_oPopup)
    {
        if (g_idFlyPopup == -1)
        {
            g_idFlyPopup = window.setInterval("flyMove('down')",10);
        }
    }
    g_oPopup.hide();
}

var xmlHttp

function saveVars()
{ 
	var url="saveVars.asp?sid=" + Math.random() + "&folder=" 
	if (document.getElementById('radiobutton1').checked == true)
	{
		url += document.frmUpload.elements("selFolder").value
	}
	else
	{
		url += document.frmUpload.elements("txtFolder").value
	}
	url += "&name=" + document.getElementById("txtPhotoName").value
	url += "&description=" + document.getElementById("txtDescription").value
	url += "&sendername=" + document.getElementById("txtSender").value
	url += "&datecreated=" + getFileCreated('frmUpload','File1');
	xmlHttp=GetXmlHttpObject(stateChanged)
	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)
} 

function stateChanged() 
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    { 
	    var arrFields = new Array("File1","txtFolder")
	    validateFields("frmUpload", arrFields, true)
    } 
} 

function GetXmlHttpObject(handler)
{ 
    var objXmlHttp=null

    if (navigator.userAgent.indexOf("Opera")>=0)
    {
        alert("This example doesn't work in Opera") 
        return 
    }
    if (navigator.userAgent.indexOf("MSIE")>=0)
    { 
        var strName="Msxml2.XMLHTTP"
        if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
        {
            strName="Microsoft.XMLHTTP"
        } 
        try
        { 
            objXmlHttp=new ActiveXObject(strName)
            objXmlHttp.onreadystatechange=handler 
            return objXmlHttp
        } 
        catch(e)
        { 
            alert("Error. Scripting for ActiveX might be disabled") 
            return 
        } 
    } 
    if (navigator.userAgent.indexOf("Mozilla")>=0)
    {
        objXmlHttp=new XMLHttpRequest()
        objXmlHttp.onload=handler
        objXmlHttp.onerror=handler 
        return objXmlHttp
    }
} 

function disableUploadFields()
{
	if (document.getElementById('radiobutton1').checked == true)
	{
		document.getElementById('selFolder').disabled = false;
		document.getElementById('txtFolder').disabled = true;			
	}
	else
	{
		document.getElementById('selFolder').disabled = true;
		document.getElementById('txtFolder').disabled = false;			
	}
}

function resizeWindow(sectionID)
{
	var oSection = document.getElementById(sectionID);
	if (oSection.style.display == 'block')
	{
		window.resizeTo('340','371');
	}
	else
	{
		window.resizeTo('340','301');
	}
}

function adjustFilter(imageobject, opacity)
{
	if (navigator.appName.indexOf("Netscape")!=-1 && parseInt(navigator.appVersion)>=5)
	{
		imageobject.style.MozOpacity=opacity/100;
	}
	else if (navigator.appName.indexOf("Microsoft")!=-1 && parseInt(navigator.appVersion)>=4)
	{
		imageobject.filters.alpha.opacity=opacity;
	}
}

var arrPhotoOrientation = new Array();
function resizeImages(longside, shortside, id)
{
	var intNewHeight;
	var intNewWidth;
	var objImage;
	var imgwidth;
	var imgheight;
    var index=1;

	for (i=0; i<document.images.length; i++)
	{
		objImage = document.images[i];

		if (objImage.id.substr(0,id.length)==id)
		{
			imgwidth = objImage.width;
			imgheight = objImage.height;
			
			if (imgwidth < imgheight)
			{
				//Portrait
				intNewHeight = longside;
				intNewWidth = shortside;
				document.getElementById('div'+index).style.posLeft = document.getElementById('div'+index).style.posLeft+18;
				arrPhotoOrientation[index] = "p";
			}
			else
			{
				//Landscape
				intNewHeight = shortside;
				intNewWidth = longside;
				document.getElementById('div'+index).style.posTop = document.getElementById('div'+index).style.posTop+18;
                arrPhotoOrientation[index] = "l";
            }
			
			objImage.width=intNewWidth;
			objImage.height=intNewHeight;
            adjustFilter(objImage, 60);
            index++;
		}
	}
}

function resizeMainPic(longside, shortside, index)
{
    var intNewHeight;
    var intNewWidth;
    var objImage;

    objImage = document.getElementById('mainpic');
	objMainpic = document.getElementById('mainpicDIV');

    if(index!=-1)
    {
        if (arrPhotoOrientation[index] == "p")
        {
	        //Portrait
	        objImage.height=longside;
	        objImage.width=shortside;
	        objMainpic.style.posTop = 10;
	        objMainpic.style.posLeft = 190;
        }
        else
        {
	        //Landscape
	        objImage.height=shortside;
	        objImage.width=longside;
	        objMainpic.style.posTop = 60;
	        objMainpic.style.posLeft = 140;
        }
    }
    else
    {
        objImage.height=shortside;
        objImage.width=longside;
        objMainpic.style.posTop = 60;
        objMainpic.style.posLeft = 140;    
    }
    adjustFilter(objImage, 100);
}

var photosLoaded = 0;
function showLoadingStatus()
{
	photosLoaded++;
	if(photosLoaded==document.images.length-3)
	{
		document.getElementById('status').innerHTML = '';
		window.resizeTo(680,690);
		document.getElementById('statusframe').style.display = 'none';
	}
	else
	{
		document.getElementById('status').innerHTML = 'Loading photos: ' + ((document.images.length-3)-photosLoaded) + ' remaining';
	}
}

var xmlHttp;
var wait = 0;
var targetdiv = '';
function getInfo(url,div)
{ 
window.status ='Please wait...'
targetdiv=div;
xmlHttp=GetXmlHttpObject(stateChanged)
xmlHttp.open("GET", url+"&sid=" + Math.random(), false)
xmlHttp.send(null)
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
document.getElementById(targetdiv).innerHTML=xmlHttp.responseText
window.status ='Done'
} 
} 

function GetXmlHttpObject(handler)
{ 
var objXmlHttp=null

if (navigator.userAgent.indexOf("Opera")>=0)
{
alert("This code doesn't work in Opera") 
return 
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{ 
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.XMLHTTP"
} 
try
{ 
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler 
return objXmlHttp
} 
catch(e)
{ 
alert("Error. Scripting for ActiveX might be disabled") 
return 
} 
} 
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler 
return objXmlHttp
}
} 

var objItemList,objBodyList,objTitleList,objLinkList,objStatusList,objTargetListobjNodeList,objSubTitleList,objLeaderList,objDateTimeList,objDescList;
var iMessageCount;
function loadXMLDoc(url)
{
	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest()
		xmlhttp.onreadystatechange=xmlhttpChange
		xmlhttp.open("GET",url,true)
		xmlhttp.send(null)
	}
	// code for IE
	else if (window.ActiveXObject)
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		if (xmlhttp)
		{
			xmlhttp.onreadystatechange=xmlhttpChange
			xmlhttp.open("GET",url,true)
			xmlhttp.send()
		}
	}
}

function xmlhttpChange()
{
	// if xmlhttp shows "loaded"
	if (xmlhttp.readyState==4)
	{
		// if "OK"
		if (xmlhttp.status==200)
		{
			objNodeList = xmlhttp.responseXML.getElementsByTagName("article");
			objTitleList = xmlhttp.responseXML.getElementsByTagName("title");
			//objSubTitleList = xmlhttp.responseXML.getElementsByTagName("subtitle");
			//objLeaderList = xmlhttp.responseXML.getElementsByTagName("leader");
			objBodyList = xmlhttp.responseXML.getElementsByTagName("body");
			//objDateTimeList = xmlhttp.responseXML.getElementsByTagName("datetime");
			objLinkList = xmlhttp.responseXML.getElementsByTagName("link");
			objStatusList = xmlhttp.responseXML.getElementsByTagName("status");
			objTargetList = xmlhttp.responseXML.getElementsByTagName("target");
			objAuthorList = xmlhttp.responseXML.getElementsByTagName("author");
			//objDescList = xmlhttp.responseXML.getElementsByTagName("description");
			iMessageCount = objNodeList.length;
			// start scroller
			initte();			
		}
		else
		{
			alert("Problem retrieving XML data")
		}
	}
}

var asphttp;
function writeInclude(url) 
{ 
	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
	{
		asphttp=new XMLHttpRequest()
		asphttp.onreadystatechange=getASPpage
		asphttp.open("GET",url,true)
		asphttp.send(null)
	}
	// code for IE
	else if (window.ActiveXObject)
	{
		asphttp=new ActiveXObject("Microsoft.XMLHTTP")
		if (asphttp)
		{
			asphttp.onreadystatechange=getASPpage
			asphttp.open("GET",url,true)
			asphttp.send()
		}
	}
} 

function getASPpage()
{
	// if asphttp shows "loaded"
	if (asphttp.readyState==4)
	{
		// if "OK"
		if (asphttp.status==200)
		{
		    document.getElementById("bodytext").innerHTML = asphttp.responseText;
		}
		else
		{
			alert("Problem retrieving ASP page. Error: "+asphttp.status)
		}
	}
}

function OpenCalendarWindow(control)
{
	var calWindow;
	calWindow = window.open('calendar.asp?control='+control,'CalendarPopup','width=250,height=300,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=250,top=130')		
	calWindow.focus();
}

function OpenCalendarAdmin()
{
	var calWindow;
	calWindow = window.open('calendar.asp','CalendarPopup','width=600,height=300,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=150,top=130')		
	calWindow.focus();	
}

function OpenAdminWindow(url)
{
	var adminWindow;
	adminWindow = window.open(url,'AdminPopup','width=800,height=625,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=20,left=150,top=75')		
	adminWindow.focus();	
}

function OpenLogin()
{
	var loginWindow;
	loginWindow = window.open('include/i_login.asp','LoginPopup','width=250,height=125,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=250,top=130')		
	loginWindow.focus();	
}

function OpenSplashLogin()
{
	var loginWindow;
	loginWindow = window.open('admin/splash.asp','LoginPopup','width=630,height=215,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes,screenX=20,screenY=20,left=150,top=75')		
	loginWindow.focus();	
}

function calculateQuote(basic,IDarray)
{
	var hiddenfield;
	var checkbox;
	var div;
	var itemArray;
	var total = basic;
	for(i=0;i<IDarray.length;i++)
	{
		itemArray  = IDarray[i].split("/");
		hiddenfield = document.getElementById("txt"+itemArray[0]);
		checkbox = document.getElementById("chk"+itemArray[0]);
		div = document.getElementById("div"+itemArray[0]);
		if (checkbox)
		{
			if(checkbox.checked)
			{
				if(parseInt(itemArray[1])>0)
					{div.innerHTML = '&pound;'+itemArray[1];}
				else
					{div.innerHTML = '&pound;POA'}
				total+=parseInt(itemArray[1]);
			}
			else
			{
				div.innerHTML = '';
			}
		}
	}
		
	document.getElementById("txtTotal").value = total;
	document.getElementById("divTotal").innerHTML = '&pound;' + total;
}

function selectThisDay(date, control)
{
    if(window.opener.document.getElementById(control))
    {
        window.opener.document.getElementById(control).value=date;
        window.opener.focus();
        window.close();
    }
    else
    {
        window.opener.location = 'contact.asp?action=create'+control+'=' + date;
        window.opener.focus();
        window.close();
    }
}

function toggleAdminMenu(sStyle)
{
	//window.opener.focus();
	window.opener.document.getElementById("adminpanel").style.display = sStyle;
	window.focus();
}

function confirmAction(url,msg,form)
{
    if (confirm(msg))
    {
        if(form!='')
        {
            document.forms[form].submit();
        }
        else
        {
            window.location = url;
        }
    }
}

function validateThenConfirm(url,msg,form,arrFields)
{
	if (validateFields(form,arrFields,false) == false)
	{
		confirmAction(url,msg,form)
	}
}

function ToggleDisabled(form,field,obj,bCurrStatus)
{
	var strConf
	if (bCurrStatus == 0)
	{
		document.getElementById(field).value = 1
		strConf = "Enable the user?"
	}
	else
	{
		document.getElementById(field).value = 0
		strConf = "Disable the user?"
	}
	confirmAction('',strConf,form);
}

function validateDBLogon()
{
    getInfo('dblogon.asp?user='+document.getElementById('txtUserID').value+'&password='+document.getElementById('txtPassword').value,'output');
    if(document.getElementById('output').innerHTML == 1)
    {
        document.getElementById('output').style.display = 'none';
        frmLogin.submit();
    }
    else
    {
        if(document.getElementById('txtPassword').value!='')
        {
            if(document.getElementById('txtUserID').value!='')
            {
                document.getElementById('txtPassword').select();
            }
            else
            {
                document.getElementById('txtUserID').select();
            }
        }
        else
        {
            document.getElementById('txtUserID').select();
        }
        document.getElementById('output').style.display = 'block';
    }
}


