// JavaScript Document
//Functions used throughout the DRS web site  

//Name: CheckField
//Purpose: RegExP Validation Script for form fields
//Author: Shaun Hare 
//Date created 05.04.04
//Parameters: 
//			theForm (Object) - form object
//			theField(Object) - thefield attempting to check
//			theFieldDisplay(String) - Message to show back to user
//			toCheck (String) - type of validation to be performed
//********************************************************************************************

function CheckField(theForm,theField, theFieldDisplay,toCheck) { 
var objRegex= new RegExp
	// determine what needs to be checked
			switch (toCheck)
				{
				case "UKPostcode":
						objRegex=/^([A-Za-z]{1,2}[0-9]{1,2}|[A-Za-z]{3}|[A-Za-z]{1,2}[0-9][A-Za-z])( |-)[0-9][A-Za-z]{2}/;
					break;
				case "Email":
					objRegex=/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/
					break; 
				case "alpha":
					objRegex=/[a-zA-Z]/
					break;
				
				}
		//determine the field to be checked
objField = eval("document." + theForm + "." + theField); 

	if (!objField==" "){ // if is not empty check it matches the appropriate Regular expression

				if(!objRegex.test(objField.value))  {
				  alert ("Please enter a valid " + theFieldDisplay + "");
				  objField.select();
				   
				objField.focus();
				  return (false); // failed return false
				} 
	}
return (true);
} 

//Name: CheckCombo
//Purpose: check a value has been selected from the passed combobox
//Author: Shaun Hare 
//Date created 05.04.04
//Parameters: 
//			theForm (Object) - form object
//			cboBox(Object) - the field attempting to check
//			theContent(String) - Message to show back to user
//			
//********************************************************************************************

		

function CheckCombo(theform, cboBox,theContent) {
	
	objCbo=eval("document." + theform +"."+cboBox)
		if (objCbo.selectedIndex==0){
				alert("Please choose a" + theContent + ""); 
				objCbo.focus(); 
				return(false);
			}
	return(true);	
}

//Purpose: check a value is not blank
//Author: Shaun Hare 
//Date created 05.04.04
//Parameters: 
//			Val (String) passed value
//			
//********************************************************************************************
function isBlank(Val){
		if (Val=="")
		{
			return(true);
		}
	return(false); 
}

// CHecks if form fields are valid as part of registration
function valid(){
	if (CheckField('frmRegister','txtpostcode','postcode','UKPostcode')==true){
		document.frmRegister.submit();
	}
}
// opens a new window
function open_window(url) {


window.open(url,"specwin",'toolbar=NO,location=NO,directories=NO,status=NO,menubar=NO,scrollbars=NO,resizable=YES,width=780,height=520');


}
// toggle visibility of field on registration form

function queryProduct( targetId ){
   
  
		target = document.getElementById(targetId);
		if (target.style.display == "none") {
          target.style.display = "block";          
        } else {
          target.style.display = "none";
        }
 		
}
function CheckNames(theform,theField){
	
	if 	(CheckField(theform,theField,' name','alpha')){
						return(true);
								
							}
		else{
				return(false);
						}
					}
					
// resets the value of the trusts input on the registration form if an error has occured
function resetVal(nVal){
	
	 with (document.fd_register.selTrusts)
   {
      for (i = 0; i < length; i++){
        if(options[i].value==nVal)
         {
            options[i].selected=true;
			
			break;
         	}  
   		}
   }
   if (nVal==1){
   		toggleBox("extrafield",1);
		}
	else{
				toggleBox("extrafield",0);	
	
	
		}
}
//resets the title dropdown if an error occurs
function setTitle(nVal){
	with (document.fd_register.seltitle)
   {
      for (i = 0; i < length; i++){
        if(options[i].value==nVal)
         {
            options[i].selected=true;
			
			break;
         	}  
   		}
   }
}
//checks the length of a string
function stringLength(inputString)
{
  return inputString.length;
}
//toggles visibility of boxes on input form
function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}
// checks value of trust information
function checkVal(){

	if (document.fd_register.selTrusts.value==1)
		{
		toggleBox("extrafield", 1);
		document.fd_register.txtOther.focus();
		}
	else
		{
		toggleBox("extrafield",0);
		}

	}
	//Check if email entered correctly
function CheckEmail(theForm){
var objForm
	if 	(CheckField(theForm,'txtEmail','Email','Email')){
					objForm=eval("document." + theForm)
					objForm.submit();
							}
						}

// Breakout of frames on return from help
function framebreakout()
{
  
  if (top != self) top.location.href = location.href;
  
}
//-->

