function ToggleCategory(e, fld, catid) 
{
    var atcls = document.getElementById("catarticles" + catid);
    var tgl = document.getElementById("cattoggle" + catid);
    var show = (atcls.style.display == "none" || atcls.style.display == "") ? true : false;
    atcls.style.display = (show) ? "block" : "none";
    eval("tgl.src = img" +(show ? "Close" : "Open") + ".src");
}

function ToggleAnswer(e, fld, ansid) 
{
    var ans = document.getElementById("faqanswer" + ansid);
    shw = document.getElementById("faqshow" + ansid);
    var show = (ans.style.display == "none" || ans.style.display == "") ? true : false;
    ans.style.display = (show) ? "block" : "none";
    shw.style.display = (show) ? "none" : "block";
    
}


function EmailAFriend()
{
    window.open ("/email-a-friend.php", "_blank", "toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=440,height=530");
}

function OpenQuestions() 
{
    var els = getElementsByClassName("cat_14", "div");
    for (var i = 0; i < els.length; i++)
    {
        var cat = els[i].parentNode.parentNode.id;
        if (cat.substr(0, 3) == "cat")
        {
            var catId = cat.substr(3, cat.length - 3);
            ToggleCategory(null, null, catId);

            var qs = els[i].getElementsByTagName("DIV");
            for (var j = 0; j < qs.length; j++)
            {
                if (qs[j].id.indexOf("faqshow") >= 0)
                {
                    var qId = qs[j].id.substr(7, qs[j].id.length - 7);
                    ToggleAnswer(null, null, qId);
                }
            }
        }
        
    }
}

function BeginPCodeSrch()
{
    var thisPcode = "";
    //alert("srching");
    var theForm = document.frmSrch;
    var postcode = theForm.phrase.value;
    thisPcode = postcode;

    var localSearch = new GlocalSearch();
    localSearch.setSearchCompleteCallback(null,
	function() {

	    if (localSearch.results[0]) {
	        var resultLat = localSearch.results[0].lat;
	        var resultLng = localSearch.results[0].lng;
	        document.frmSrch.lat.value = resultLat;
	        document.frmSrch.lng.value = resultLng;

	        if (document.getElementById("section0").checked == true)
            {
                document.frmSrch.action = "/jewish-nursery-schools/schools.php";
            }
            else if (document.getElementById("section1").checked == true)
            {
                document.frmSrch.action = "/jewish-primary-schools/schools.php";
            }
            else if (document.getElementById("section2").checked == true) 
            {
                document.frmSrch.action = "/jewish-secondary-schools/schools.php";
            }
            //alert ("Lat = " + resultLat + ", lng = " + resultLng);

            //Submit the form
	        document.frmSrch.submit();
	        //alert(document.frmSrch.action);
	    }
	    else {
	        alert("'" + thisPcode + "' could not be found. Please enter a UK town or postcode");
	        
	    }
	});

    localSearch.execute(postcode + ", UK");

}

