// Normal MM form validation.

var CountryTextArray = new Array("Ireland");
var CountryValueArray = new Array("1");


var StateTextArray = new Array("Antrim","Armagh","Belfast City","Carlow","Cavan","Clare","Cork","Derry","Donegal","Down","Dublin","Dublin Centre","Dublin North","Dublin South","Dublin West","Fermanagh","Galway","Kerry","Kildare","Kilkenny","Laois","Leitrim","Limerick","Longford","Louth","Mayo","Meath","Monaghan","Offaly","Other","Roscommon","Sligo","Tipperary","Tyrone","Waterford","Westmeath","Wexford","Wicklow");
var StateValueArray = new Array("27","28","2002","1","2","3","4","29","5","30","6","1948","1950","1951","1949","31","7","8","9","10","11","12","13","14","15","16","17","18","19","83","20","21","22","32","23","24","25","26");
var StateCountryValueArray = new Array("1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1");


function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

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) { 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'+errors);
  document.MM_returnValue = (errors == '');
}

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;
}

// Validate the user login fields.

function login_validate(form)
{
    valid = true;

    if ( form.username.value == "" || form.password.value == "" )
    {
        alert ( "Your email address and password are required fields." );
        valid = false;
    }

    return valid;
}

function fillSelects() 
	{
		var i,j;		 
		with(document.frmSearch) 
		{
			
			if(navigator.appVersion.indexOf("MSIE 4")!=-1) 
			{
				cmdUp.value="Up"
				cmdDown.value="Down"
			}
			//This code required for NS4.7 (fixed width SELECT problem). We could have just bound the SELECTs otherwise						 
			
			if(document.frmSearch.hdnCountryCode.value == 0)
			{		
				country_code[0]=null;
				//country_code.options[0] = new Option('Select a state/province...','',false,false);				
			{
			
			for(i=0;i<CountryTextArray.length;i++) 
			{

				country_code[i]=new Option(CountryTextArray[i],CountryValueArray[i]);					
			}	
				country_code.options[CountryTextArray.length] = new Option('All','0',true,true);			 
				//ProcessCountryChange ()							
			}
			
			}//close if
			 ProcessCountryChange ()
		}
	}		
	
	function ProcessCountryChange () 
	{
		var m, n, p;
		var count;
		count = 0;
 
		with(document.frmSearch) 
		{
		
			if(document.frmSearch.hdnRegionCode.value == 0)
			{
				// alert()
				if(document.frmSearch.hdnCountryCode.value == 1)
				{
					region_code.options.length = 0;		 

					for(m=0;m<StateCountryValueArray.length;m++) 
					{	
						//if (StateCountryValueArray[m]== countryselected){
						region_code[count]=new Option(StateTextArray[m],StateValueArray[m],StateCountryValueArray[m]);
						count = count + 1
						//}//CLOSE IF
					}	  //CLOSE FOR LOOP
					
					region_code.options[count] = new Option('All','0',true,true);
				}	//close if	
					//alert()
				
				if(document.frmSearch.hdnCountryCode.value == 0)
				{
					//alert()
					var cc = document.frmSearch.country_code;
					var countryselected = cc.options[cc.selectedIndex].value
	 				region_code.options.length = 0;		 

					for(m=0;m<StateCountryValueArray.length;m++) 
					{	
		  
						if (StateCountryValueArray[m]== countryselected)
						{
							region_code[count]=new Option(StateTextArray[m],StateValueArray[m],StateCountryValueArray[m]);
							count = count + 1
						}   //CLOSE IF
		
					} //CLOSE FOR LOOP
					
					region_code.options[count] = new Option('All','',true,true);
			
				}
				
			}//close if			 	
		}//close with
		return;
	}