//<!--
function Validate(oForm,verbose){
index=0;
var message='';
var loop=1;
var Style;
var validForm=true;
var validField=false;
var oTest;
var nElements=oForm.elements.length;
var formfeedback=oForm.getAttribute("feedback");
while(index<nElements){
oTest=oForm.elements[index];
type=oTest.type;
customScript=oTest.getAttribute("customScript");
name=oTest.getAttribute("name");
field=oTest.value;
fieldfeedback=oTest.getAttribute("feedback");
max=oTest.getAttribute("max");
min=oTest.getAttribute("min");
vtype=oTest.getAttribute("vtype");
vname=oTest.getAttribute("vname");
dField=oTest.getAttribute("dfield");
dValue=oTest.getAttribute("dvalue");
mandatory=oTest.getAttribute("mandatory");
warning=oTest.getAttribute("warning");
validCustom=true;
validFormat=true;
validRange=true;
validChars=true;
validMandatory=true;
validSelect=true;
validRadio=true;
if(customScript!=null){
validCustom=(eval(customScript))}
else{
validCustom='true';
if(dField!=null){
var dVal=eval("document.getElementById('"+dField+"')")
if(dVal.type=='radio'||dVal.type=='select-one'||dVal.type=='checkbox'){
var dStatus =(dValue=='true') 
if(dVal.status==dStatus)
mandatory='true'
else
mandatory='false'}		
else{
if(!isEmpty(dVal.value))
mandatory='true'
else
mandatory='false'}}
switch(type){
case'password':
case'text':
case'textarea':
if(!isEmpty(field))	{
validChars=true;
switch(vtype){
case'text':
field=field.replace(/"/g,"`");
validFormat=true;
break;
case'numeric':
validFormat=(field.search(/^[-|+]*\d*.{1}\d*$/)!=-1);
break;
case'email':
validFormat=(field.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)!=-1);
break;
case'url':
validFormat=(field.search(/^((\w+):\/\/)([\w.]+)(\/)?(\S*)$/)!=-1);
break;
case'Date'://uk format
validFormat=(field.search(/^((mon|tue|wed|thur|fri|sat|sun){1}\w{0,3}(day)?)(\\|\/|\s|.|-)?(1|2|3|)[0-9]((st|nd|rd|th)?){1}(\\|\/|\s|.|-){1}(((jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)(r|((t)?e)|o|y)?(uary|ch|((m)?ber)|il|aust)?)|((1|2)?[0-9])){1}(\\|\/|\s|.|-){1}((19|20)?\d{2})$/)!=-1);
break;
case'Time':
validFormat=(field.search(/^[0-2]{0,1}\d[:|.]*\d\d\s*([a|p].*m.*)*$/)!=-1);
break;
case'Date/Time':
validFormat=(field.search(/^[0-2]{0,1}\d[:|.]*\d\d\s*([a|p].*m.*)*((mon|tue|wed|thur|fri|sat|sun){1}\w{0,3}(day)?)?(\\|\/|\s|.|-)?(1|2|3|)[0-9]((st|nd|rd|th)?){1}(\\|\/|\s|.|-){1}(((jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)(r|((t)?e)|o|y)?(uary|ch|((m)?ber)|il|aust)?)|((1|2)?[0-9])){1}(\\|\/|\s|.|-){1}((19|20)?\d{2})$/)!=-1);
break;
case'filename':
validFormat=(field.search(/^((\\\\[\w]+)|([A-Za-z]:\\))?([(\w|\s)+]+\\)?[\w]+[.{1}](jpg|bmp|gif|jpeg|pdf|doc|xls|mdb|ppt|txt|rtf)$/)!=-1);
break;
case'phone':
validFormat=(field.search(/^\d{4}\s*\d\s*\d{2}\s*\d\s*\d\s*\d{2}$/)!=-1);	
break;	
case'CC':
validFormat=(field.search(/^\d{4}\s*\d{4}\s*\d{4}\s*\d{4}\s*$/)!=-1);
break;	
case'Postcode':
//validFormat=(field.search(/^[A-Za-z]{1,2}[1-9]{1,2}\s?[1-9][A-Za-z]{2}$/)!=-1);
break;	
case'password':
//validFormat=(field.search(\w)!=-1);
break;}			
switch(vtype){
case'numeric'	:
if(min!=null){
if(field<min){
validRange=false;
msgRange="\nIt is smaller then the minimum allowed value of "+min+"."}}
if(max!=null){
if(field>max){
validRange=false;
msgRange="\nIt is larger then the maximum allowed value of "+max+"."}}	
default:
if(min!=null){
if(field.length<min){
validRange=false;
msgRange="\nIt is smaller then the minimum allowed size of "+min+"."}}
if(max!=null){
if(field.length>max){
validRange=false;
msgRange="\nIt is larger then the maximum allowed size of "+max+"." }}}}		
else{
if(mandatory=='true')
validMandatory=false;}	
break;	
case'checkbox':
case'radio':
validRadio=false;
while(index<nElements){
oTest=oForm.elements[index];
if(oTest.name!=name){
index--
break;}
if(mandatory=='true')
validRadio=(validRadio||oTest.status);
else{
validRadio=true
validMandatory=true}
index++}
break;
case'hidden':		
case'button':		
break;
case'select-one':
if((oTest.selectedIndex==-1)||(oTest.value==''))
{
if(mandatory=='true')
validMandatory=false;
else
validMandatory=true;
}
else
validMandatory=true;
break;
default:
break;}}
validField=((validCustom=='true')&&validFormat&&validRange&&validChars&&validMandatory&&validRadio)
if(!validField){
if(formfeedback!='none'||fieldfeedback!=null){
message+='\nYou have not correctly filled in the '+vname+' field.'
if(!validChars)
//message+="\nIt contains invalid characters."
if(!validFormat)
message+="\n'+vname+' is not in the correct format."
if(!validRange)
//message+=msgRange
if(!validRadio)
//message+="\nDoes not have a value selected."
if(!validMandatory)
//message+="\n'+vname+' is a required field and does not appear to contain a value."
if(validCustom!='true')
message+=validCustom}}
if(!validField)
Style='#ff6600';
else
Style='';
switch(type){
case'select-one':
if(oTest.parentElement.tagName!='SPAN'){
var oMySelect=oTest;
var oNewSpan=document.createElement("SPAN");
oMySelect.parentElement.insertBefore(oNewSpan,oMySelect);
var oClone=oMySelect.cloneNode(true);
oNewSpan.insertAdjacentElement("afterbegin",oClone);
oMySelect.removeNode(true);
oClone.selectedIndex =oMySelect.selectedIndex;}
else
oNewSpan=oTest.parentElement
if(!validField)
oNewSpan.style.border="2px solid "+Style;
else
oNewSpan.style.border="none"
break;
default:
oForm.elements[index].style.borderColor=Style;
break;}
validForm=(validForm&&(validField||(warning=='true')))
if((formfeedback=='incremental'||fieldfeedback=='incremental')&&!validField)
break;
index++}
if(!verbose)
return true;
if(validForm)
return validForm;
else{
if(formfeedback!='none'||fieldfeedback=='incremental'){
message+='\nPlease correct the appropriate entries and resubmit.'
alert(message)}
return validForm;}}
function isEmpty(str){
if(str.length==0){
return true;}
if(str.search(/\S/)==-1){
return true;}
return false;}

function checkForm(oForm){
var index=0;
var oElements=oForm.elements.length;
var formUsed=false;
while(index<oElements){
var oTest=oForm.elements[index];
var type=oTest.type;
switch(type){
case'text':
case'textarea':	
formUsed=(formUsed || !isEmpty(oTest.value));
break;
case'checkbox':
formUsed=(formUsed || oTest.status);
break;
case 'select-one':
formUsed=(formUsed || (oTest.selectedIndex==-1)||(oTest.value==''));
break;
default:
//ignore everything else}
break;}
if(formUsed) break;
index++}
if(formUsed)
return true;
else
return false;}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_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];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function hideColumn(whichTable,whichCol){
	var oneToDo = document.getElementById(whichTable).rows[0].cells[whichCol].childNodes[0];  

	if(oneToDo.style.display==""){
		//document.getElementById(whichTable).rows[0].cells[whichCol].children[1].innerHTML = 'A';

		for (var i = 0; i < document.getElementById(whichTable).rows.length; i++){
			oneToDo = document.getElementById(whichTable).rows[i].cells[whichCol].childNodes[0];
			oneToDo.style.display="none";
		}
	}else{
		//document.getElementById(whichTable).rows[0].cells[whichCol].children[1].innerHTML = 'A';
		for (var i = 0; i < document.getElementById(whichTable).rows.length; i++){
			oneToDo = document.getElementById(whichTable).rows[i].cells[whichCol].childNodes[0];
			oneToDo.style.display="";
		}
	}
}


function changepage(table,page)
{
oneToDo = document.getElementById(table)
var RowsPerPage = Math.floor(oneToDo.getAttribute('rowsperpage'));
var CurrentPage = Math.floor(oneToDo.getAttribute('page'));
var MaxPage = Math.floor(oneToDo.getAttribute('maxpages'));
var notvalid = false;
var changed = false;

if (page =='next')
	{
	//hide currently diplayed rows
	page = CurrentPage + 1
	document.getElementById(table+'pagelink'+CurrentPage).innerHTML = '<a href="javascript:changepage(\''+ table +'\',\''+CurrentPage+'\');">'+CurrentPage+'</a>'
	document.getElementById(table+'pagelink'+page).innerHTML = page
	for ( i = (((CurrentPage - 1) *RowsPerPage )+1); i<=(CurrentPage *RowsPerPage);i++)
	{
	if (oneToDo.rows[i])
		oneToDo.rows[i].style.display = 'none'
	}
	//show the last page
	for ( i = (((CurrentPage) *RowsPerPage )+1); i<=((CurrentPage+1) *RowsPerPage);i++)
		{
		if (oneToDo.rows[i])
			oneToDo.rows[i].style.display = ''
		}
		CurrentPage ++;
		changed = true;
	}
if (page =='last')
		{
		//hide currently diplayed rows
		page= CurrentPage - 1
		document.getElementById(table+'pagelink'+CurrentPage).innerHTML = '<a href="javascript:changepage(\''+ table +'\',\''+CurrentPage+'\');">'+CurrentPage+'</a>'
		document.getElementById(table+'pagelink'+page).innerHTML = page
		for ( i = (((CurrentPage - 1) *RowsPerPage )+1); i<=(CurrentPage *RowsPerPage);i++)
		{
		if (oneToDo.rows[i])
		oneToDo.rows[i].style.display = 'none'
		}
		//show the next page
		for ( i = (((CurrentPage-2) *RowsPerPage )+1); i<=((CurrentPage-1) *RowsPerPage);i++)
			{
			if (oneToDo.rows[i])
				oneToDo.rows[i].style.display = ''
			}
			CurrentPage --;
			changed = true;
		}

if (changed ==false)
	//user must want to go to a specific page
	//so we need to validate the input first
	{
	//page = Math.floor(document.getElementById(table+'page').value)
	if ((page < 1) || (page > MaxPage))
		{
		alert("That page is not Valid")
		notvalid=true
		}
	if (notvalid == false) 
		{
		//hide currently diplayed rows
		document.getElementById(table+'pagelink'+CurrentPage).innerHTML = '<a href="javascript:changepage(\''+ table +'\',\''+CurrentPage+'\');">'+CurrentPage+'</a>'
		document.getElementById(table+'pagelink'+page).innerHTML = page
		for ( i = (((CurrentPage - 1) *RowsPerPage )+1); i<=(CurrentPage *RowsPerPage);i++)
		{
		if (oneToDo.rows[i])
		oneToDo.rows[i].style.display = 'none'
		}
		for ( i = (((page-1) *RowsPerPage )+1); i<=((page) *RowsPerPage);i++)
			{
			if (oneToDo.rows[i])
			oneToDo.rows[i].style.display = ''
			}
		CurrentPage = page
		}	
	}
oneToDo.setAttribute('page',CurrentPage);//update the table with the current page
document.getElementById(table+'page').value = CurrentPage;//Update the Textbox with the current page
if (CurrentPage =='1')
	{
	Nav = document.getElementById(table+'left')
	Nav.style.display='none'
	}
else
	{
	Nav = document.getElementById(table+'left')
	Nav.style.display=''
	}

if (CurrentPage == MaxPage)
	{
	Nav = document.getElementById(table+'right')
	Nav.style.display='none'
	}
else
	{
	Nav = document.getElementById(table+'right')
	Nav.style.display=''
	}
}

function toggleView(oElementID)
{
if (document.getElementById(oElementID).style.display=="")
	{
	document.getElementById(oElementID).style.display="none";
	}
else
	{
	document.getElementById(oElementID).style.display="";
	}
}
function changeSelect(oElementID,iIndex)
{
	
	document.getElementById(oElementID).selectedIndex = iIndex;
}

function isEmail(field)
{
return !(field.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)!=-1);

}

function isNumeric(field)
{
return (field.search(/^[-|+]*\d*.{1}\d*$/)!=-1);
}

function getTotal()
{
var runningTotal;
runningTotal = 0;
	try 
	{
		if (isNumeric(document.getElementById('Part1Quote').value))
		{
		runningTotal = runningTotal + Number(document.getElementById('Part1Quote').value)
		document.getElementById('Part1Quote').value = Decimalise(document.getElementById('Part1Quote').value)
		}
	}
	catch(err)
	{
	}	
	try
	{
	if (isNumeric(document.getElementById('Part2Quote').value))
		{			
		runningTotal = runningTotal + Number(document.getElementById('Part2Quote').value)
		document.getElementById('Part2Quote').value = Decimalise(document.getElementById('Part2Quote').value)
		}
	}
	catch(err)
	{
	}	
	try
	{
	if (isNumeric(document.getElementById('Part3Quote').value))		
		{			
		runningTotal = runningTotal + Number(document.getElementById('Part3Quote').value)
		document.getElementById('Part3Quote').value = Decimalise(document.getElementById('Part3Quote').value)			
		}
	}
	catch(err)
	{
	}	
	try
	{
		if ((document.getElementById('CollectOnly').checked))
			{
			document.getElementById('Delivery').value = Decimalise(0);
			}
	if (isNumeric(document.getElementById('Delivery').value))		
		{			
		runningTotal = runningTotal + Number(document.getElementById('Delivery').value)			
		document.getElementById('Delivery').value = Decimalise(document.getElementById('Delivery').value)			
		}
	}
	catch(err)
	{
	}
	try 
	{
			if (!(document.getElementById('addvat').checked))
			{
			document.getElementById('vat').value = Decimalise(0);
			}
	
		if (document.getElementById('addvat').checked)
		{
		Vat = Decimalise(runningTotal * .15);
		document.getElementById('vat').value = Vat
		runningTotal = Number(runningTotal) + Number(Vat)
		}
	}
	catch(err)
	{
	}	
document.getElementById('Total').value = Decimalise(runningTotal);
}


function checkQuote()
{
if ((document.getElementById('Total').value == 0)||!(isNumeric(document.getElementById('Total').value))) 
{
alert("Your figures are invalid!") 
return false	
}
else
{
return true
}
}

function toggleStatus(oElementName)
{
if(document.getElementById(oElementName).disabled == false)
{
	document.getElementById(oElementName).disabled = true
}
else
{
	document.getElementById(oElementName).disabled = false
} 
}




  function repopulate(strElementName,strElementValue) {
      var oElement = document.getElementById(strElementName);
  //   alert(strElementName);
  var oSelect = oElement;
  var strOptions = document.getElementById(strElementValue).value;
  //alert(('v' + strElementValue).toLowerCase());
  var strvOptions = document.getElementById(('v' + strElementValue).toLowerCase()).value;

  var aOptions = strOptions.split(';');
  var vOptions = strvOptions.split(';');

   /*   for (i = (oSelect.options.length - 1); i > 0; i--) //this removes all the options that are there currently
      {
          //oSelect.options[i].removeNode(true);
          oSelect.options.remove(i);

  }*/

  while (oSelect.firstChild) {
      oSelect.removeChild(oSelect.firstChild);
  }

  for (strOption in aOptions)
  	{
  	var newOption = document.createElement("OPTION");
  	//oSelect.options.add(newOption);
  	//newOption.innerText = aOptions[strOption];
  	//newOption.value = vOptions[strOption];

  	oSelect.options[oSelect.options.length] = new Option(aOptions[strOption], vOptions[strOption]);
  	}
  if(oSelect.options[0].value == "")
  	{
  	    oSelect.disabled = true;
  	}
  	else
  	{
  	    oSelect.disabled = false;
  	}
  oSelect.options[0].selected = true;
  try { oElement.fireEvent('Onchange'); }
  catch (Error) { 
  //oElement.OnChange();
   }
  }

  function Decimalise(n) 
{
    var s = "" + Math.round(n * 100) / 100;
    var i = s.indexOf('.');
    if (i < 0) return s + ".00";
  var t = s.substring(0, i + 1) + 
     s.substring(i + 1, i + 3)
  if (i + 2 == s.length) t += "0"
  return t
}


function clear404(pagename)
{
var name = confirm("Are you sure you want to delete "+pagename+" from the database?")
if (name == true)
	{
	var page = "clear404.asp?pagename=" + pagename;
	winpops=window.open(page,"","width=850,height=500,toolbar=no,location=no,directories=no,status=no,scrollbars=no,menub=ar,resizable=no,");
	history.go(0)
	}

}

function specificday(pagename,specday)
{
var page = "specificday.asp?pagename="+pagename+"&specday="+specday;
var uscreenhe = screen.height
winpops=window.open(page,"","width=850,height=700,toolbar=no,location=no,directories=no,status=no,scrollbars=no,menub=ar,resizable=no,");
}

//-->