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


//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 fillSelect(sel,data){


	if (data == ''){
		return;
	}
	sel.options.length = 0;
	var str = data.split("\n");

	j = 0;
	for ( i in str ){
		if (str[i] != ''){
			alert(str[i]);
			var param = str[i].split("|");
			sel.options[j] = new Option(param[1]);
			sel.options[j].value = param[0];
			j ++;
		} else {
			break;
		}
	}
}


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 ...
		selectPostcode = document.getElementById('postcode');
		for (i = 0 ; i < selects.length ; i ++){
			if(selects[i].id == 'postcode'){
				postcodeNo = i;
			} else if(selects[i].id == 'college'){
				collegeNo = i;
			}
		}
		if(selectField.value == 1){ // need modify Postcodes for Dublin!!!
			var url = '/service/get_postcodes.php?id=' + selectField.options[linkNo].value; // new postcode ...
			jx.load(url,function (data){
				replaceSelect( postcodeNo , "0|All Postcodes\n" + data);
				var url = '/service/get_providers.php?&county_id=' + selectField.value; // new postcode ...
				jx.load(url,function (data){
					replaceSelect( collegeNo , "0|In Any College\n" + data);
				});
			});
		} else { // reset postcodes
			var url = '/service/get_providers.php?county_id=' + selectField.value; // new postcode ...
			replaceSelect( postcodeNo, "0|All Postcodes\n" );
			jx.load(url,function (data){
				replaceSelect( collegeNo , "0|In Any College\n" + data);
			});
		}
	} else if(selectFieldId == 'postcode' && selectField.value > 0){
		var url = '/service/get_providers.php?postcode_id=' + selectField.value; // new postcode ...
		jx.load(url,function (data){
			replaceSelect( collegeNo , "0|In Any College\n" + data);
		});
	}

}

function replaceSelect( i , data ) {
	if (data == ''){
		return;
	}
	selects[i].options.length = 0;
	var str = data.split("\n");
	j = 0;

	optionsDiv = document.getElementById("optionsDiv"+i);
	optionsDiv.innerHTML = '';

	for ( k = 0; k < str.length ; k ++ ){
		if (str[k] != ''){
			var param = str[k].split("|");
			selects[i].options[j] = new Option(param[1]);
			selects[i].options[j].value = param[0];

			var optionHolder = document.createElement('p');
			var optionLink = document.createElement('a');
			var optionTxt = document.createTextNode(selects[i].options[j].text);

			//start basti
			optionLink.href = "javascript:selectMe('"+selects[i].id+"',"+j+","+i+");";
			//end basti
			optionLink.appendChild(optionTxt);
			optionHolder.appendChild(optionLink);
			optionsDiv.appendChild(optionHolder);
			j ++;
		}
	}
	selectMe(selects[i].id,0,i);
}

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

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

