function FormDropDown(ID){
	if ($('#'+ID+'_DropList').css("display")=='none' || $('#'+ID+'_DropList').css("display")==''){			
		InitDropDowns(ID);
		$('#'+ID+'_DropList').fadeIn("fast");
	}
	else{
		$('#'+ID+'_DropList').fadeOut("fast");
	}
}

function SelectDropDown(ID,Value,Text){
	$('#'+ID).val(Text);
	$('#'+ID+'_Data').val(Value);
	$('#'+ID+'_DropList').fadeOut("fast");
}

function InitDropDowns(ID){
	var LeftOffset=-5;
	var TopOffset=22;	
	var pos=$('#'+ID+'_Src').offset();
	$('#'+ID+'_DropList').css('left',(parseInt(pos.left)+LeftOffset)+'px');
	$('#'+ID+'_DropList').css('top',(parseInt(pos.top)+TopOffset)+'px');
	var width=($('#'+ID).width()+20)+'px';
	$('#'+ID+'_DropList').css('width',width);
}
	
function FormCheck(ID,ValueOn,ValueOff){
	var ImgStr=document.getElementById(ID);
	var CheckForm=document.getElementById(ID+'_Form');
	if(ImgStr.src.indexOf('TickBoxOn')>=0){
		CheckForm.value=ValueOff;	
		ImgStr.src='/images/forms/Form_TickBoxOff.gif';
	}
	else{
		ImgStr.src='/images/forms/Form_TickBoxOn.gif';
		CheckForm.value=ValueOn;
	}
}

function FormRadio(ID,State,Option){
	document.getElementById(ID+'_Form').value=State;
	var i=1;
	do{
		try{
			if (i==Option){
				document.getElementById(ID+'_'+i).src='/images/forms/Form_RadioOn.gif';
			}
			else{
				document.getElementById(ID+'_'+i).src='/images/forms/Form_RadioOff.gif';
			}
		}
		catch(err){
			break;
		}
		i++;
	}
	while(i<10);
}	

function Validation(Field,Type,Min,Max,Field2){
	var Str=document.getElementById(Field).value;
	var Regexp;
	var ErrorText;
	var Match='';
	if (Type=='AlphaNumeric'){
		Regexp="^[\\w ]{"+Min+","+Max+"}$";
		ErrorText="Computer says no! Requires "+Min+" to "+Max+" characters. Letters, Numbers and Spaces only.";
	}
	if (Type=='TextField'){
		Regexp="^[\\w\\£\\.\\s\\+\\,!'=\\(\\)\\*\\&\\-\\$\\%;:\\\"\\/ ]{"+Min+","+Max+"}$";
		ErrorText="Computer says no! Requires "+Min+" to "+Max+" characters.";
	}
	if (Type=='PageTitle'){
		Regexp="[\\w\\- \\.\\&\\(\\)]{"+min+","+max+"}?";
		ErrorText="Computer says no! Invalid title. Requires "+Min+" to "+Max+" characters (alphanumeric,-,.,&,(,)) only";
	}
	if (Type=='NameFormat'){
		Regexp="^[\\w\\-\\. ]{"+Min+","+Max+"}$";
		ErrorText="Computer says no! Invalid name. Requires "+Min+" to "+Max+" characters. Letters, numbers, spaces, hyphens and full stops only.";
	}
	if (Type=='Numeric'){
		Regexp="^[\\d ]{"+Min+","+Max+"}$"
		ErrorText="Computer says no! Requires "+Min+" to "+Max+" digits. Numbers only.";
	}
	if (Type=='Telephone'){
		Regexp="^[\\d \\+]{"+Min+","+Max+"}$"
		ErrorText="Computer says no! Requires "+Min+" to "+Max+" digits. Numbers,Spaces and + only.";
	}
	if (Type=='Email'){
		Regexp="^[A-Za-z0-9\.\%\_\-]+@[A-Za-z0-9\.\-]+\\.(?:[A-Za-z]{2}|com|org|net|biz|info|name|aero|biz|info|jobs|museum|name)$";
		ErrorText="Computer says no! Invalid email address.";
	}
	if (Type=='EmailorNone'){
		Regexp="^([\w-_.]*[\w-_.]@[\w-_]+?[\w-_.]+\.[\w.]{3,})?$";
		ErrorText="Computer says no! Invalid email address.";
	}		
	if (Type=='Url'){
		Regexp="^(?:(?:http://|http://www\\.|www\\.)[a-zA-Z0-9]+[A-Za-z0-9\\.\\-]+\\.(?:[A-Za-z]{2}|com|org|net|biz|info|name|aero|biz|info|jobs|museum|name)){"+Min+","+Max+"}$";
		ErrorText="Computer says no! Invalid url format.";
	}		
	if (Type=='PostCode'){
		Regexp="^[a-zA-Z]+[a-zA-Z0-9]{1,3}\\s[\\d]{1}[a-zA-Z]{2}$";
		ErrorText="Computer says no! Invalid postcode.";
	}
	if (Type=='UsernameOrPassword'){
		Regexp="^[\\w-_]{"+Min+","+Max+"}$";
		ErrorText="Computer says no! Invalid username or password. Requires "+Min+" to "+Max+" characters. Alphanumeric and _- characters only."
	}
	if (Type=='UsernameOrPasswordMatch'){
		Regexp="^[\\w-_]{"+Min+","+Max+"}$";
		ErrorText="Invalid username or password. Requires "+Min+" to "+Max+" characters. Alphanumeric and _- characters only."
		if(document.getElementById(Field).value!=document.getElementById(Field2).value){
			ErrorText="Computer says no! Your passwords do not match."
			Match='Fail';
		}
	}
	if(!Str.match(Regexp) || Match=='Fail'){
		if(Field=='FooterEmail'){
			document.getElementById(Field+"_Errors").innerHTML='<img src="/images/SubscribeError.png" title="Invalid email address"/>';
			document.getElementById(Field+"_Errors").style.display='block';	
		}
		else{
			document.getElementById(Field+"_Errors").innerHTML=ErrorText;
			document.getElementById(Field+"_Errors").style.display='block';	
		}
		return 'fail';
	}
	else{
		document.getElementById(Field+"_Errors").style.display='none';
		return 'true';
	}
}
