var clockID = 0;
function UpdateClock() {
   if(clockID) {
	  clearTimeout(clockID);
	  clockID  = 0;
	}
   	var tDate = new Date();
	iMonth = tDate.getMonth();
	iMonth++;
	document.DAYONLY.theDay.value = tDate;
	cDate = document.DAYONLY.theDay.value;
	endloc = cDate.indexOf("UTC",10);
	document.DAYONLY.theDay.value  = cDate.substring(0,endloc)
   	clockID = setTimeout("UpdateClock()", 1000);
}

//------------------------------
function StartClock() {
   clockID = setTimeout("UpdateClock()", 500);
   document.DAYONLY.theDay.blur();
}

//------------------------------
function KillClock() {
   if(clockID) {
	  clearTimeout(clockID);
	  clockID  = 0;
   }
}

//------------------------------
function SelectIt(formdet){
        if (formdet.options[formdet.selectedIndex].value != "none"){ 
        location.href = 'cms.asp?i=<%=i%>&p=<%=p%>&sc='+formdet.options[formdet.selectedIndex].value}        
}

//------------------------------
function combinedate(formdet) {
	formdet.selectdate.value=formdet.dd.options[formdet.dd.selectedIndex].value + ' ' + formdet.mm.options[formdet.mm.selectedIndex].value + ' ' + formdet.yyyy.options[formdet.yyyy.selectedIndex].value;
}

//------------------------------
function DisplayImage(picURL) {
var picsize, picWidth, picHeight
picsize=new Image()
picsize.src=picURL
picWidth=picsize.width
picHeight=picsize.height
newWindow=window.open(picURL,'newWin','toolbar=no,menubar=0,scrollbar=0,status=0,titlebar=0,width='+picWidth+',height='+picHeight)
newWindow.document.write('<html><body background="'+picURL+'"><\/body><\/html>')
newWindow.resizeBy((picWidth-newWindow.document.body.clientWidth),(picHeight-newWindow.document.body.clientHeight))
newWindow.focus()
}



//------------------------------

function checkData()
{
   if (document.feedback.name.value == "") {
                        alert("Please fill in your name.")
                        document.feedback.name.focus()
                        return false}
 if (document.feedback.addr1.value == "") {
                        alert("Please fill in at least the first line of the address")
                        document.feedback.addr1.focus()
                        return false}
 if (document.feedback.pcode.value == "") {
                        alert("Please fill in your postcode.")
                        document.feedback.pcode.focus()
                        return false}
 if (document.feedback.phone.value == "") {
                        alert("Please fill in your telephone number.")
                        document.feedback.phone.focus()
                        return false}
   if (document.feedback.email.value == "") {
                        alert("Please fill in your email address. This is most important")
                        document.feedback.email.focus()
                        return false}
if ((document.feedback.email.value.indexOf('@') < 1) || 
    (document.feedback.email.value.lastIndexOf('.') <= document.feedback.email.value.indexOf('@')+1) ||  
    (document.feedback.email.value.lastIndexOf('.') == document.feedback.email.value.length - 1 ) ||  
    (document.feedback.email.value.indexOf(' ')  != -1)) 
   {  
      	alert('Please enter a valid e-mail address!')
	document.feedback.email.focus()
            return false}

 if (document.feedback.password.value == "") {
                        alert("Please fill in your password")
                        document.feedback.password.focus()
                        return false}
 if (document.feedback.password2.value == "") {
                        alert("Please confirm your password")
                        document.feedback.password2.focus()
                        return false}
 if (document.feedback.password.value != document.feedback.password2.value) {
                        alert("Your password entries are different.  Please try again")
                        document.feedback.password.focus()
                        return false}
 }


// //////////////////////////////////////////


// - this validates the form using trigger attributes

function validateForm(n)
{

		var x = document.forms[n].elements;
		for (var i=0;i<x.length;i++)
		{
// - set 'required=' and the message to display
			if (x[i].getAttribute('required') && !x[i].value)
			{ 	var msg=x[i].getAttribute('required')
				alert(msg)
				x[i].focus()
				return false;
			}

// - set 'email=true'
			if (x[i].getAttribute('email'))
			{ 	
				if ((x[i].value.indexOf('@') < 1) || 
    					(x[i].value.lastIndexOf('.') <= x[i].value.indexOf('@')+1) ||  
    					(x[i].value.lastIndexOf('.') == x[i].value.length - 1 ) ||  
    					(x[i].value.indexOf(' ')  != -1)) 
   				{  
    	  				alert('Please enter a valid e-mail address!')
					x[i].focus()
    	        			return false;
				}

			}

// - set 'confirm=' and the fieldname to match against
// - useful for confirmation passwords
// - could be adapted to compare numeric values of fields etc
			if (x[i].getAttribute('confirm'))
			{ 	var field=x[i].getAttribute('confirm')
				var ref=document.forms[n].elements[field].value
				if (ref!=x[i].value)
				{
					alert("Your password & confirmation don't match.  Please try again.")
					x[i].focus()
					return false;
				}
			}


// - set 'docupload=' and the message to display
// - checks the file extension of files being uploaded
			if (x[i].getAttribute('docupload') && x[i].value.length >0)
			{
				var fileext=Right(x[i].value,4)		

				if (fileext.toLowerCase() !=".doc" && fileext.toLowerCase() !=".pdf")
				{ 	var msg=x[i].getAttribute('docupload')
					alert(msg)
					x[i].focus()
					return false;
				}

	 		}

// - set 'reqradio' and the message to display
// - checks that at least one of a set of radio buttons is checked

			if (x[i].getAttribute('reqradio'))
			{
				var radio=x[i].name
				var msg=x[i].getAttribute('reqradio')
				var chk='n'

				for (z=0;z<document.forms[n].elements[radio].length;z++)
				{
					if (document.forms[n].elements[radio][z].checked)
					{
						chk='y';
					}

				}

				if(chk!='y')
				{
					chk='n'
					alert(msg)
					x[i].focus()
					return false;
				}	

			}



 		}
}
