function Init_AJAX() {
try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
try { return new XMLHttpRequest();          } catch(e) {} //Native Javascript
alert("XMLHttpRequest not supported");
return null;
};

function showNationwide(f){
//alert(f.courseType.options[f.courseType.selectedIndex].value);
if(f.courseType.options[0].selected==true){
alert("Please select course type!");
document.getElementById('nationwide-div').style.display="none";
}else{
if(f.courseType.options[f.courseType.selectedIndex].value==6){
document.getElementById('nationwide-div').style.display="";
}else{
document.getElementById('nationwide-div').style.display="none";
}
}
}

function toggleNationwide(f){
if(f.nationwide.checked==true){
f.multiarea.checked=false;
showMultiDiv(f);
}
}

function showMultiDiv(f){
//alert(f.multiarea.checked);
if(f.multiarea.checked==true){
f.nationwide.checked=false;
document.getElementById('dynamic-areas').style.display="";
}else{
document.getElementById('dynamic-areas').style.display="none";
}
}

function updCourseTypeAjax(form,cid)
{
var txt=form.courseType.options[form.courseType.selectedIndex].value;
if(txt==""){
alert("Please select course type.");
document.getElementById('dynamic-areas').innerHTML="Select course type!";
}else{
document.getElementById('dynamic-areas').innerHTML="<img src=\"http://www.findacourse.ie/images/spinning-loader.gif\">";
var actionURL="http://www.findacourse.ie/courseEdit.php?frommodule=ajaxquery&courseId="+cid+"&updcourse="+txt;
var date = new Date();
var timestamp = date.getTime();
actionURL+="&skeyajax="+timestamp;
     //alert(actionURL);
     var httpRequest= Init_AJAX();
     httpRequest.onreadystatechange = function() { saveCourseTypeAjax(httpRequest); };
     httpRequest.open('POST', actionURL, true);
     httpRequest.send(null);
}
}

function addCourseTypeAjax(form)
{
var txt=form.courseType.options[form.courseType.selectedIndex].value;
if(txt==""){
alert("Please select course type.");
document.getElementById('dynamic-areas').innerHTML="Select course type!";
}else{
document.getElementById('dynamic-areas').innerHTML="<img src=\"http://www.findacourse.ie/images/spinning-loader.gif\">";
var actionURL="http://www.findacourse.ie/courseDetail.php?frommodule=ajaxquery&updcourse="+txt;
var date = new Date();
var timestamp = date.getTime();
actionURL+="&skeyajax="+timestamp;
     //alert(actionURL);
     var httpRequest= Init_AJAX();
     httpRequest.onreadystatechange = function() { saveCourseTypeAjax(httpRequest); };
     httpRequest.open('POST', actionURL, true);
     httpRequest.send(null);
}
}

function getDynamicData(form){
var txt=form.keyword.value;
var countySel=form.county.options[form.county.selectedIndex].value;
var courseSel=form.courseType.options[form.courseType.selectedIndex].value;
//if(txt!="" || countySel!="" || courseSel!=""){
document.getElementById('dynamicdata').innerHTML="<img src=\"http://www.findacourse.ie/images/spinning-loader.gif\">";
var actionURL="http://www.findacourse.ie/searchResult.php?frommodule=ajaxquery";
if(txt!=""){actionURL+="&keyword="+encodeURIComponent(txt);}
if(countySel!=""){actionURL+="&county="+encodeURIComponent(countySel);}
if(courseSel!=""){actionURL+="&courseType="+encodeURIComponent(courseSel);}
     //alert(actionURL);
var date = new Date();
var timestamp = date.getTime();
actionURL+="&skeyajax="+timestamp;
     var httpRequest= Init_AJAX();
     httpRequest.onreadystatechange = function() { fillDynamicData(httpRequest,'indexsearch'); };
     httpRequest.open('POST', actionURL, true);
     httpRequest.send(null);
//}
}

function getDynamicData1(form){
var txt=form.keyword.value;
var countySel=form.county.options[form.county.selectedIndex].value;
var courseSel=form.courseType.options[form.courseType.selectedIndex].value;
var catSel=form.srchCat.options[form.srchCat.selectedIndex].value;

//if(txt!="" || countySel!="" || courseSel!=""){
document.getElementById('dynamicdata-quicksearch').innerHTML="<img src=\"http://www.findacourse.ie/images/spinning-loader.gif\">";
var actionURL="http://www.findacourse.ie/searchResult.php?frommodule=ajaxquery1";
if(txt!=""){actionURL+="&keyword="+encodeURIComponent(txt);}
if(countySel!=""){actionURL+="&county="+encodeURIComponent(countySel);}
if(courseSel!=""){actionURL+="&courseType="+encodeURIComponent(courseSel);}
if(catSel!=""){actionURL+="&srchCat="+encodeURIComponent(catSel);}
     //alert(actionURL);
var date = new Date();
var timestamp = date.getTime();
actionURL+="&skeyajax="+timestamp;
     var httpRequest= Init_AJAX();
     httpRequest.onreadystatechange = function() { fillDynamicData(httpRequest,'quicksearch'); };
     httpRequest.open('POST', actionURL, true);
     httpRequest.send(null);
//}
}



function fillDynamicData(httpRequest,sparam) {

        if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) {
			//alert(httpRequest.responseText);
			  if(sparam=='quicksearch'){
				  document.getElementById('dynamicdata-quicksearch').innerHTML=httpRequest.responseText;
			  }else{
			      document.getElementById('dynamicdata').innerHTML=httpRequest.responseText;
			  }
            }else {
                alert('There was a problem with the request.');
            }
        }
    }
	
function saveCourseTypeAjax(httpRequest) {

        if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) {
			//alert(httpRequest.responseText);
			document.getElementById('dynamic-areas').innerHTML=httpRequest.responseText;
            }else {
                alert('There was a problem with the request.');
            }
        }
    }
	
function showAreaDiv(jack){
if(jack==true){
document.getElementById("scroll_box").style.display="";
}else{
document.getElementById("scroll_box").style.display="none";
}
}
