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_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_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 sendpass(dbname)
{
	//if (document.loginform.memberno.value)
	//{
		if (document.loginform.memberno.value == "")
		{
			alert("you must enter your member id into the field")
		}
		else
		{
			popupcode = "nontemplates/passreminder.asp?memberno=" + document.loginform.memberno.value + "&dbname=" + dbname
			popwin(popupcode,400,400,'passremind')
		}
	//}
}



// ================================ RIAS ONLY ABOVE ===========================================


	function redirector(redirectLocation)	{
		window.open(redirectLocation,"")
	}


	function popwin(page,wid,hght,winname)	{
		window.open(page, winname, "width="+wid+",height="+hght+",scrollbars=no");
	}

	function popwins(page,wid,hght,winname)	{
		window.open(page, winname, "width="+wid+",height="+hght+",scrollbars=yes");
	}

	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_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_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 MM_showHideLayers() { //v3.0
	  var i,p,v,obj,args=MM_showHideLayers.arguments;
	  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
		if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
		obj.visibility=v; }
	}


	function MM_callJS(jsStr) { //v2.0
	  return eval(jsStr)
	}


	function MM_validateForm() { //v4.0
	  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
	  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);

	   if (val.type == 'checkbox') 
	   { 
		if (!val.checked)
				errors+='- '+val.name+' must be selected.\n';
	   }
	   else
	   {
		if (val) { nm=val.name; if ((val=val.value)!="") {
		  if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
			if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
		  } else if (test!='R') { num = parseFloat(val);
			if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
			if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
			  min=test.substring(8,p); max=test.substring(p+1);
			  if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
		} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
		}
	  } 
	  if (errors) 
	  {
		alert('The following error(s) occurred:\n\n'+errors);
	  }
	  else
	  {
			document.frm.submit()
	  }
	}



	function MM_findObj(n, d) { //v3.0
	  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); return x;
	}



	function valForm() { //v3.0
	  var i,p,q,nm,test,num,min,max,errors='',args=valForm.arguments;
	  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
		if (val) { nm=val.name; if ((val=val.value)!="") {
		  if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
			if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
		  } else if (test!='R') { num = parseFloat(val);
			if (val!=''+num) errors+='- '+nm+' must contain a number.\n';
			if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
			  min=test.substring(8,p); max=test.substring(p+1);
			  if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
		} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' \n'; }
	  } 
		if (errors) 
		{	
			alert('Please complete the following fields before continuing :\n'+errors); 
			return false;
		} 
		else 
		{ 
			return true;
		}
	}






	function validateform()	{

		var valid, errMsg;
		valid = true;
		errMsg = "There has been an error:\n";

			

		if (document.frmContactUs.txtName.value == '')
			{
				errMsg = errMsg + "\n - You must fill in your Name";
				valid = false;
			}

		// check for numbers
		if (document.frmContactUs.txtCompany.value == '')
			{
				errMsg = errMsg + "\n - You must fill in your Company";
				valid = false;
			}
			
		if (document.frmContactUs.txtEmail.value == '')
			{
				errMsg = errMsg + "\n - You must fill in your Email Address";
				valid = false;
			}
		else
			{
				var x = document.frmContactUs.txtEmail.value;
				var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
				if (filter.test(x))
					{
						valid = true;
					}
					else
					{
					valid = false;
					errMsg = errMsg + "\n - You must fill in a valid Email Address";
					}
			}
			
			
		var myTelNo = document.getElementById('txtPhone').value;

		// If invalid number, report back error
		if (!checkUKTelephone(myTelNo))
		{
			errMsg = errMsg + "\n - You must fill in a valid Telephone Number";
			valid = false;
		}
		// Otherwise redisplay telephone number on form in corrected format
		else
		{
			// do nothing
		}
		
			
		if (document.frmContactUs.ddlVersion.value == '')
			{
				errMsg = errMsg + "\n - You must enter a Version";
				valid = false;
			}
		if (document.frmContactUs.ddlModule.value == '')
			{
				errMsg = errMsg + "\n - You must enter a Module";
				valid = false;
			}
			
		if (document.frmContactUs.txtSubject.value == '')
			{
				errMsg = errMsg + "\n - You must fill in a Question Summary";
				valid = false;
			}

		if (document.frmContactUs.txtQuestion.value == '')
			{
				errMsg = errMsg + "\n - You must fill in a Question";
				valid = false;
			}



		
		// only process the form if everythings okay
		if (valid)
			{
				document.getElementById('frmContactUs').submit();
			}
			else
			{
				alert(errMsg);
			}
	}







	function IsNumeric(sText)
		{
		   var ValidChars = "0123456789.";
		   var IsNumber=false;
		   var Char;
		
		 
		   for (i = 0; i < sText.length && IsNumber == false; i++) 
			  { 
			  Char = sText.charAt(i); 
			  if (ValidChars.indexOf(Char) == -1) 
				 {
				 IsNumber = true;
				 }
			  }
		   return IsNumber;
		   
		}
	






function checkUKTelephone(telephoneNumber) {

  // Convert into a string and check that we were provided with something
  var telnum = telephoneNumber + " ";
  var valid = true;
  if (telnum.length == 1)  {
     valid = false;
  }
  telnum.length = telnum.length - 1;

  
  // Remove spaces from the telephone number to help validation
  while (telnum.indexOf(" ")!= -1)  {
    telnum = telnum.slice (0,telnum.indexOf(" ")) + telnum.slice (telnum.indexOf(" ")+1)
  }
  
  // Remove hyphens from the telephone number to help validation
  while (telnum.indexOf("-")!= -1)  {
    telnum = telnum.slice (0,telnum.indexOf("-")) + telnum.slice (telnum.indexOf("-")+1)
  }  
  
  // Now check that all the characters are digits
  exp = /^[0-9]{10,11}$/
  if (exp.test(telnum) != true) {
	  
     valid = false;
  }

  
  // Telephone number seems to be valid - return the stripped telehone number  
  return valid;
}





	// handle the onchange event to display logos and stuff on the form
	// ajax?
	function displayTerritoryDetails()
	{
		makeRequest(document.getElementById('ddlTerritory').selectedIndex);

		
	}


    function makeRequest(nTerritoryID) {
        var httpRequest;
		url = '../lib/inc_VEWARE_ajax.asp?territoryID=' + nTerritoryID;

		// document.write(url);
        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            httpRequest = new XMLHttpRequest();
        } else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!httpRequest) {
            alert('There was a problem submitting your form, please try again.');
            return false;
        }
		
        httpRequest.onreadystatechange = function()
											{
												updateTerritoryDetails(httpRequest);

												
											};
		// set the asch value to false to wait for the response before carrying on
        httpRequest.open('GET', url, true);
        httpRequest.send(null);

        //function below deals with results...
		
    }



    function updateTerritoryDetails(httpRequest) {

		if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) {

				var territoryObject = httpRequest.responseText;
				// set the id of the form so its going to update from now on
				if (territoryObject.resID != "0")
				{
					// only do this if the id is not zero
					// now add ithe info into the page
					document.getElementById('eventName').value = territoryObject.resID;
					
				}
				else
				{
					// just add in the defaulr ies ones
					
					
				}

				
            } else {
					alert(httpRequest.responseText);
                //alert('There was a problem inserting, please try again later.');
            }
		}

    }




















