//<!--

function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;
}


$(document).ready(function() {

$(".numericOnly").keydown(function(event) {
    // Allow only backspace and delete
    if (event.keyCode == 46 || event.keyCode == 8) {
        // let it happen, don't do anything
    }
    else {
        // Ensure that it is a number and stop the keypress
        if (event.keyCode < 48 || event.keyCode > 57) {
            event.preventDefault();
        }
    }
});


});

function selectLink(ob)
{
    var URL = ob.options[ob.selectedIndex].value;
    if (URL != '')
    {
        window.location.href = URL;
    }
} 

function save()
{

}
function loaded(item)
{

}
function conCatValueByClass(classItem)
{
    var returnitem = "";
    
    $("."+classItem).each(function()
    {
        returnitem += " " + $(this).val();
    });
    
    return returnitem;
}

function getLatLong(address,latObject,longObject)
{

    latObject = $("#"+latObject);
    longObject = $("#"+longObject);
    
    if (GBrowserIsCompatible())
    {
        var geocoder = new GClientGeocoder();
        geocoder.getLatLng(
    address,
    function(point) {
        if (!point) {
            alert(address + " not found");
        } else {
            latObject.val(point.y)
            longObject.val(point.x);
        }
    }
  );


    }
}

function removeText(object, tTxt)
{
    if (object.value == tTxt)
    {
        object.value = '';
    }
}
function setDeilveryAddress(eV)
{
    if (eV == "No")
    {
    }
    else
    {
        document.getElementById('InvoiceAddress').value         =   document.getElementById('FullAddress').value;
        document.getElementById('InvoiceAddressLine1').value    =   document.getElementById('FullAddressLine1').value;
        document.getElementById('InvoiceAddressLine2').value    =   document.getElementById('FullAddressLine2').value;
        document.getElementById('InvoiceAddressLine3').value    =   document.getElementById('FullAddressLine3').value;
        document.getElementById('InvoiceAddressLine4').value    =   document.getElementById('FullAddressLine4').value;
        document.getElementById('DeilveryAddress').value        =   document.getElementById('InvoiceAddress').value;
        document.getElementById('DeilveryAddressLine1').value   =   document.getElementById('InvoiceAddressLine1').value;
        document.getElementById('DeilveryAddressLine2').value   =   document.getElementById('InvoiceAddressLine2').value;
        document.getElementById('DeilveryAddressLine3').value   =   document.getElementById('InvoiceAddressLine3').value;
        document.getElementById('DeilveryAddressLine4').value   =   document.getElementById('InvoiceAddressLine4').value; 
    }
}

function BRPreLoad()
{
    var loadstring = "";
    for(x=0;x<document.links.length;x++)
    {
        var olink;
        olink = document.links[x];
        if (olink.getAttribute("hoverimg") != null)
        {
            MM_preloadImages(olink.getAttribute("hoverimg"));
        }
    }
    if (loadstring != "")
    {
        loadstring = loadstring.substring(1,loadstring.length)
    }
}
function setEText(es,so)
{
    var eA = es.split(',');
    for(elem in eA)
    {
       document.getElementById(eA[elem]).value = so.options[so.selectedIndex].text;
    }
}
function setData(so,ta)
{
    ta = document.getElementById(ta);
    ta.value = so.value;
}
var statusbar = null;
var customHTMLname = "";
var xmlhttp=false;
try {
	 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) 
{
	try 
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch (E) 
	{
		xmlhttp = false;
	}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
{
	xmlhttp = new XMLHttpRequest();
}
function deleteValue(o,e,t)
{
    if(e)
    {
        if (o.value == t)
        {
            o.value = ''
        }
     }
     else
     {
        o.value = ''
     }
    
}
var cmshelp = false;
function goToUrl(e)
{
    if (e.value != "")
    {
        window.location.href=e.value;
    }
}
function resetLinks()
{
        var plink = document.getElementsByTagName("a");
        for(x=0;x<plink.length;x++)
        {
            plink[x].disable = false;
            plink[x].onclick = '';  
        }
}
function inactivelinks()
{
        var plink = document.getElementsByTagName("a");
        for(x=0;x<plink.length;x++)
        {
            plink[x].disabled = true;
            plink[x].onclick = new Function("return false;");
        }
        
}
function showHide(e)
{
    if (e.style.display == "")
    {
        e.style.display = "none"
    }
    else
    {
        e.style.display = ""
    }  
}
function handleHelpRequest()
{
    if (xmlhttp.readyState == 4)
    {
        if (xmlhttp.status == 200)
        {
            if (xmlhttp.responseText == "error!")
            {
                alert('Issue with help response');
            }
        } 
    }
}
function statusbarWrite(l)
{
    if (statusbar)
    {
        statusbar.innerHTML = l;
    }
}
function saveAsCustomHTMLState()
{
    if (xmlhttp.readyState == 4)
    {
        statusbarWrite("Attempting to retrieve data");
        if (xmlhttp.status == 200)
        {
            writeCustomHTML(xmlhttp.responseText);
        }
        else
        {
            statusbarWrite("Unable to retrive data");
            alert('Save failed. Please check internet connection.\n If no issue then please contact an administrator');
        }
        
    }
}
function writeCustomHTMLState()
{
    if (xmlhttp.readyState == 4)
    {
        if (xmlhttp.status == 200)
        {
            if (xmlhttp.responseText == "success")
            {
                statusbarWrite("File saved successfully");
                alert('File Saved');
            }
            else
            {
                statusbarWrite("Failed");
                alert(xmlhttp.responseText);
                alert('Please contact an administrator');
            }
        }
        else
        {
            statusbarWrite("Failed to save.");
            alert('Save failed. Please check internet connection.\n If no issue then please contact an administrator');
        }
    }
}
function writeCustomHTML(data)
{
    if (xmlhttp)
    {
            var formdata;
            formdata = 'name='+escape(customHTMLname)+'&data='+escape(data);
            statusbarWrite("Attempting to save.");
            xmlhttp.open("POST","/admin/saveCustomHTML.asp",true);
            xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            xmlhttp.setRequestHeader("Content-length", formdata.length);
            xmlhttp.onreadystatechange = writeCustomHTMLState;
            xmlhttp.send(formdata);
    }
    else
    {
        alert('Your browser does not support this feature.');
    }
}
function saveAsCustomHTML(moduleID,name,reportTo)
{
        statusbar = document.getElementById(reportTo);
        customHTMLname = name;      
        if (xmlhttp)
        {
            statusbarWrite("Requesting Page");
            xmlhttp.open("GET","/admin/rendermodule.asp?ModuleID="+moduleID,true);
            xmlhttp.onreadystatechange = saveAsCustomHTMLState;
            xmlhttp.send(null);
        }
        else
        {
            alert('Your browser does not support this feature.');
        }    
}
function getUID()
{
var oDate = new Date;
return (oDate.getUTCMilliseconds()*Math.random(1000));
}

function ViewFile(e)
{
	e = document.getElementById(e);
	var URL = e.value;
	window.open(e.value,'Viewfile','');
}
function UploadFile(u)
{
	window.open(u,'Upload','');
}
function toggleView(e)
{
	showHide(document.getElementById(e));
}
function changeSelect(e,i)
{
	document.getElementById(e).selectedIndex = i;
}
function isEmail(v)
{
	return !(v.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)!=-1);
}
function isNumeric(v)
{
	return (v.search(/^[-|+]*\d*.{1}\d*$/)!=-1);
}
function toggleStatus(e)
{
	if(document.getElementById(e).disabled == false){document.getElementById(e).disabled = true}
	else{document.getElementById(e).disabled = false}
}
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 swapImg(oImg)
{
src = oImg.src
if (src.search('on') ==-1){oImg.src =src.replace('_off','_on')}
else {oImg.src=src.replace('_on','_off')} 
}
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 clearTextBoxText(e){
	e.value = '';
}
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(/^([-|+]){0,1}(\d){0,}(\.){0,1}(\d){0,}$/) !=-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(/(((0[1-9]|[12][0-9]|3[01])([\/])(0[13578]|10|12)([\/])(\d{4}))|(([0][1-9]|[12][0-9]|30)([\/])(0[469]|11)([\/])(\d{4}))|((0[1-9]|1[0-9]|2[0-8])([\/])(02)([\/])(\d{4}))|((29)(\.|-|\/)(02)([\/])([02468][048]00))|((29)([\/])(02)([\/])([13579][26]00))|((29)([\/])(02)([\/])([0-9][0-9][0][48]))|((29)([\/])(02)([\/])([0-9][0-9][2468][048]))|((29)([\/])(02)([\/])([0-9][0-9][13579][26])))$/)!=-1);
break;
case'Time':
validFormat=(field.search(/^(20|21|22|23|[01]\d|\d)(([:.][0-5]\d){1,2})$/)!=-1);
break;
case'Date/Time':
validFormat=(field.search(/(((0[1-9]|[12][0-9]|3[01])([\/])(0[13578]|10|12)([\/])(\d{4}))|(([0][1-9]|[12][0-9]|30)([\/])(0[469]|11)([\/])(\d{4}))|((0[1-9]|1[0-9]|2[0-8])([\/])(02)([\/])(\d{4}))|((29)(\.|-|\/)(02)([\/])([02468][048]00))|((29)([\/])(02)([\/])([13579][26]00))|((29)([\/])(02)([\/])([0-9][0-9][0][48]))|((29)([\/])(02)([\/])([0-9][0-9][2468][048]))|((29)([\/])(02)([\/])([0-9][0-9][13579][26])))\s(20|21|22|23|[01]\d|\d)(([:.][0-5]\d){1,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-PR-UWYZ]{1,2}[0-9]{1,2}[ABEHJMNPRVWXY]?)\s?([0-9][ABD-HJLNP-UW-Z]{2})|(GIR)\s?(0AA))$/)!=-1);
break;	
case'password':
break;
default:
validformat = true
break;
}			
switch(vtype){
case'numeric':
if(min!=null){
if(field.length<min){
validRange=false;
msgRange="\nIt is smaller then the minimum allowed value of "+min+"."}}
if(max!=null){
if(field.length>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)
if(!validFormat)
message+="\n'+vname+' is not in the correct format."
if(!validRange)
if(!validRadio)
if(!validMandatory)
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(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:
break;}
if(formUsed) break;
index++}
if(formUsed)
return true;
else
return false;}
function launch(e)
{
    var ni;
    ni = e.src.substring(0,e.src.lastIndexOf("_")) + e.src.substring(e.src.lastIndexOf("."));
	ImageWindow = window.open("/iView.asp?image="+ni,"iView","toolbar=no,resizeable=no,status=no");
}
function imagePop(ni)
{
	ImageWindow = window.open("/iView.asp?image="+ni,"iView","toolbar=no,resizeable=no,status=no");	    
}
function ToggleChildren(e)
{
    var cn = e.childNodes.length;
    var x=0;
    for(x=0;x<cn;x++)
    {
        var cni = e.childNodes[x];
        if (cni.nodeType == 1)
        {
            if (cni.style.display == "none")
            {
                cni.style.display = "";
            }
            else
            {
                cni.style.display = "none";
            }
        }
    }
}

function WinOpen(url,W,H)
{
winpops=window.open(url,"WinOpen","width=977,height=400,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=yes,");
}



