<!--
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) { //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 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 ValQuickCollege(form){
		if(document.forms["quick_college"].id.value == 0 && document.forms["quick_college"].college_name.value == "" && document.forms["quick_college"].college_abb.value == "" ) {
            alert ("You must select a college or enter either a college name or abbreviation ");
	        document.forms["quick_college"].college_name.focus();
		    return false;
        }
		return true;
     }

     function ValKeywordForm(form){
		    if (document.forms["quick_search"].query.value=="") {
				alert ("You must enter a search string");
				document.forms["quick_search"].query.focus();
				return false;
			}
            if (document.forms["quick_search"].county_id.value == 0){
				alert ("You must select a county in Ireland.");
	            document.forms["quick_search"].county_id.focus();
		        return false;
            }
			return true;
      }

     function ValSectionForm(form){
		    if (document.forms["section_search"].query.value=="") {
				alert ("You must enter a search string");
				document.forms["section_search"].query.focus();
				return false;
			}
            if (document.forms["section_search"].county_id.value == 0){
		        alert ("You must select a county in Ireland.");
			    document.forms["section_search"].county_id.focus();
		        return false;
            }
			return true;
	}

     function ValKeywordAdvForm(){
		    if (document.forms["quick_adv"].query.value=="") {
			alert ("You must enter a search string");
			document.forms["quick_adv"].query.focus();
			return false;
			}
            if (document.forms["quick_adv"].county.value ==0){
            alert ("You must select a county in Ireland.");
            document.forms["quick_adv"].county.focus();
            return false;
            }


      }

      function chkDistance() {
      	if (document.forms["quick_search"].timescale.value=="distance") {
		document.forms["quick_search"].county.value = 1;
      		document.forms["quick_search"].county.disabled = true;
      	} else {
		document.forms["quick_search"].county.disabled = false;
      	}

      }

      function chkDistanceAdv() {
      	if (document.forms["quick_adv"].timescale.value=="distance") {
		document.forms["quick_adv"].county.value = 1;
      		document.forms["quick_adv"].county.disabled = true;
      	} else {
		document.forms["quick_adv"].county.disabled = false;
      	}

      }

function ValidateBR( form ){

	if (form.name.value == ''){
		alert ('Please type Your name');
		form.name.focus();
		return false;
	} else if (form.address.value == ''){
		alert ('Please type Your Address');
		form.address.focus();
		return false;
	}
	return true;
}


function updatePostcode(county){
//	alert( county.value );
	tr = document.getElementById('trpostcode');
	sl = document.getElementById('slpostcode');
	if(county.value == 1 ){ // Dublin
	  tr.style.display = '';



	} else {
	  tr.style.display = 'none';
	}
}

var http;

function get_http(){
    var req;

    // branch for native XMLHttpRequest object (Gecko browsers)
    if (self.XMLHttpRequest)
    {
        req = new XMLHttpRequest();
    // branch for IE/Windows ActiveX version
    } else if (self.ActiveXObject){
		try {
            req=new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                req=new ActiveXObject("Microsoft.XMLHTTP");
                } catch (oc) {
	                req=null;
                }
          }
    }
    return req;
}

function loadPostcodes( id ){
	var form = document.quick_search;
	if (!form ){
		form = document.quick_adv;
	}
	if (!form ){
		form = document.section_search;
	}

	var trpc = document.getElementById('trpostcode');

	if (id.value > 0){
//		form.postcode_id.style.display = '';
//		trpc.style.display = '';
		fillPSelect(form.postcode_id,'0:Loading...');
		if (! http ){
			http = get_http();
			working = false;
		}
		if (! working && http ){
			http.open("GET", "/service/get_postcodes.php?id=" + encodeURIComponent( id.value ), true);
			http.onreadystatechange = function() {
				if (http.readyState == 4) {
					working = false;
					if (http.responseText != ''){
						trpc.style.display = '';
						fillPSelect(form.postcode_id,'0|Any\n'+http.responseText);
					} else {
						trpc.style.display = 'none';
						fillPSelect(form.postcode_id,'|');
					}

				} else {
//					setStatus(http.readyState);
				}
			}
			fillPSelect(form.postcode_id,'0|Loading...');
			working = true;
			http.send(null);
		} else {
			form.submit();
		}
	}
//	else {
//		form.postcode_id.style.display = 'none';
//		fillPSelect(form.postcode_id,'0|Loading...');
//	}
}

function fillPSelect(sel,values){
	if (values == ''){
		return;
	}
	sel.options.length = 0;
	var str = values.split("\n");
	j = 0;
	for ( i in str ){
		if (str[i] != ''){
			var param = str[i].split("|");
			sel.options[j] = new Option(param[1]);
			sel.options[j].value = param[0];
			j ++;
		}
	}
}

//V3.00.A - http://www.openjs.com/scripts/jx/
var jx = {
	http:false, //HTTP Object
	format:'text',
	callback:function(data){},
	error:false,
	//Create a xmlHttpRequest object - this is the constructor.
	getHTTPObject : function() {
		var http = false;
		//Use IE's ActiveX items to load the file.
		if(typeof ActiveXObject != 'undefined') {
			try {http = new ActiveXObject("Msxml2.XMLHTTP");}
			catch (e) {
				try {http = new ActiveXObject("Microsoft.XMLHTTP");}
				catch (E) {http = false;}
			}
		//If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document.
		} else if (XMLHttpRequest) {
			try {http = new XMLHttpRequest();}
			catch (e) {http = false;}
		}
		return http;
	},
	// This function is called from the user's script.
	//Arguments -
	//	url	- The url of the serverside script that is to be called. Append all the arguments to
	//			this url - eg. 'get_data.php?id=5&car=benz'
	//	callback - Function that must be called once the data is ready.
	//	format - The return type for this function. Could be 'xml','json' or 'text'. If it is json,
	//			the string will be 'eval'ed before returning it. Default:'text'
	load : function (url,callback,format) {
		this.init(); //The XMLHttpRequest object is recreated at every call - to defeat Cache problem in IE
		if(!this.http||!url) return;
		if (this.http.overrideMimeType) this.http.overrideMimeType('text/xml');

		this.callback=callback;
		if(!format) var format = "text";//Default return type is 'text'
		this.format = format.toLowerCase();
		var ths = this;//Closure

		if (this.http.overrideMimeType) this.http.overrideMimeType('text/xml');

		//Kill the Cache problem in IE.
		var now = "uid=" + new Date().getTime();
		url += (url.indexOf("?")+1) ? "&" : "?";
		url += now;

		this.http.open("GET", url, true);

		this.http.onreadystatechange = function () {//Call a function when the state changes.
			if(!ths) return;
			var http = ths.http;
			if (http.readyState == 4) {//Ready State will be 4 when the document is loaded.
				if(http.status == 200) {
					var result = "";
					if(http.responseText) result = http.responseText;
					//If the return is in JSON format, eval the result before returning it.
					if(ths.format.charAt(0) == "j") {
						//\n's in JSON string, when evaluated will create errors in IE
						result = result.replace(/[\n\r]/g,"");
						result = eval('('+result+')');
					}

					//Give the data to the callback function.
					if(ths.callback) ths.callback(result);
				} else { //An error occured
					if(ths.error) ths.error()
				}
			}
		}
		this.http.send(null);
	},
	init : function() {this.http = this.getHTTPObject();}
}


function selectMe(selectFieldId,linkNo,selectNo) {
	//feed selected option to the actual select field
	selectField = document.getElementById(selectFieldId);
	for(var k = 0; k < selectField.options.length; k++) {
		if(k==linkNo) {
			selectField.options[k].selected = "selected";
		}
		else {
			selectField.options[k].selected = "";
		}
	}
	//show selected option
	textVar = document.getElementById("mySelectText"+selectNo);

//	var newText = document.createTextNode(selectField.options[linkNo].value);
// Modified by PVS. We need to see a TEST, not VALUE !!!!
	var newText = document.createTextNode(selectField.options[linkNo].text);
	textVar.replaceChild(newText, textVar.childNodes[0]);

	if(selectFieldId == 'county'){ // Country was changed ... Need Update Colleges list ...
		var cl = document.getElementById("college");
		var type = document.getElementById("coursetype");
		var ts = '';
		for(var k = 0; k < type.options.length; k++) {
			if(type.options[k].selected ) {
				ts = type.options[k].value;
			}
		}
/*
		var url = 'service/colleges.php?county='+selectField.options[linkNo].value+'&coursetype='+ts;

		fillSelect(cl,"0|Loading....\n");

		jx.load(url,function (data){
			alert(data);
		});
*/
	}
}

function populateCourses(id){

    courses = document.getElementById('course');
	var url = '/service/get_courses.php?id=' + id + '&' + new Date(); // new postcode ...
	    jx.load(url,function (data){
	    fillPSelect( courses , data);
	});
}
			
