function toggle_style(div) {
	d = document.getElementById(school_div);
	if (d.className=='sch') {
		d.className='sch-act';
	} else {
		d.className='sch';
	}
}

function toggle_class(div, c1, c2) {
	d = document.getElementById(div);
	if (d.className==c1) {
		d.className=c2;
	} else {
		d.className=c1;
	}
}

//////////////
function search_school_init(sel_ctry, sel_reg, sel_city, type) {
	if (typeof(type) == 'undefined' || (type != 'select' && type != 'user_search' && type != 'school_search')) {
	    type = '';
	}
	
    search_school_country(sel_ctry, type);
    search_school_region(sel_reg, sel_ctry, type);
    if ( sel_city == 0 ) {
        search_school_city(sel_city, sel_reg, type);
    } else {
        if ( type == 'select' || type == 'user_search') {
            search_school_city(sel_city, sel_reg, type);
        }
        if ( type != 'select') {
            search_school_schools(0, sel_city, 0, type);
        }
    }
}

function search_school_country(sel, type) {
	
	div11 = document.getElementById("country");
	
	AjaxRequest.get({
		'url':'ajax_search_school/country.php'
		,'sel':sel
		,'type':type
		,'onLoading':function(req) 	{  }
		,'onSuccess':function(req) 	{ 
		    if (req.responseText=='&nbsp;') {
		        div11.style.display = 'none';
                div11.innerHTML = ''; 
		    } else {
		        div11.style.display = 'block';
                div11.innerHTML = req.responseText; 
		    }
		}
		,'onError':function(req)    { alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
	});
    
}

function search_school_region(sel, id, type) {
	
	div12 = document.getElementById("region");
	
	AjaxRequest.get({
		'url':'ajax_search_school/region.php'
		,'id':id
		,'sel':sel
		,'type':type
		,'onLoading':function(req) 	{  }
		,'onSuccess':function(req) 	{ 
		    if (req.responseText=='&nbsp;') {
		        div12.style.display = 'none';
                div12.innerHTML = ''; 
		    } else {
		        div12.style.display = 'block';
                div12.innerHTML = req.responseText; 
		    }
		}
		,'onError':function(req)    { alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
	});
    
}

function search_school_city(sel, id, type) {
	
	if ( type == 'select' || type == 'user_search') {
	    div13 = document.getElementById("city");
	} else {
        div13 = document.getElementById("search_result");
	}
	
	AjaxRequest.get({
		'url':'ajax_search_school/city.php'
		,'id':id
		,'sel':sel
		,'type':type
		,'onLoading':function(req) 	{  }
		,'onSuccess':function(req) 	{ 
		    if (req.responseText=='&nbsp;') {
		        div13.style.display = 'none';
                div13.innerHTML = ''; 
		    } else {
		        div13.style.display = 'block';
                div13.innerHTML = req.responseText; 
		    }
		}
		,'onError':function(req)    { alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
	});
    
}

function search_school_schools(sel, id, st, type) {
	if (typeof(st) == 'undefined') {
	    st = 0;
	}
	if (typeof(type) == 'undefined' || (type != 'select' && type != 'user_search')) {
	    type = '';
	}
    
	if ( type == 'select' || type == 'user_search') {
	    div14 = document.getElementById("schools");
	} else {
        div14 = document.getElementById("search_result");
	}

	AjaxRequest.get({
		'url':'ajax_search_school/schools.php'
		,'id':id
		,'st':st
		,'sel':sel
		,'type':type
		,'onLoading':function(req) 	{ 
		    if ((type != 'select') && (type != 'user_search')) { 
		        div14.innerHTML = '<img src="images/ajax-loader2.gif" border="0" alt="" />';
		    }
		}
		,'onSuccess':function(req) 	{ 
		    if (req.responseText=='&nbsp;') {
		        div14.style.display = 'none';
                div14.innerHTML = ''; 
		    } else {
		        div14.style.display = 'block';
                div14.innerHTML = req.responseText; 
		    }
		}
		,'onError':function(req)    { alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
	});
    
}

function do_search(kw, st) {
	
    div15 = document.getElementById("search_result");
    div15.style.display = 'block';
    
	AjaxRequest.get({
		'url':'ajax_search_school/search.php'
		,'kw':kw
		,'st':st
		,'onLoading':function(req) { div15.innerHTML = '<img src="images/ajax-loader2.gif" border="0" alt="" />'; }
		,'onSuccess':function(req) { div15.innerHTML = req.responseText; }
		,'onError':function(req)   { alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
	});
}

function do_search_init() {
    search_school_country('', 'school_search');
    search_school_region(0, '', 'school_search')
	x = document.getElementById('txtsearch').value;
	if (trim(x)=='') {
	    return false;
	} else {
	   do_search(trim(x), 0);
	}
}

// School not found form
function send_not_found() {
	nf_ajax_school  = document.getElementById("nf_school").value;
	nf_ajax_remarks = document.getElementById("nf_remarks").value;
	nf_ajax_zip     = document.getElementById("nf_zip").value;
	nf_ajax_city    = document.getElementById("nf_city").value;
	nf_ajax_country = document.getElementById("nf_country").value;
	nf_ajax_street  = document.getElementById("nf_street").value;
	nf_ajax_email   = document.getElementById("nf_email").value;
	
	div_nf = document.getElementById("frm_not_found_msg");
	div_nf.style.display = 'block';

	AjaxRequest.get({
		'url':'ajax_search_school/send_not_found.php'
		,'email':     nf_ajax_email
		,'school':    nf_ajax_school
		,'city':      nf_ajax_city
		,'country':   nf_ajax_country
		,'zip':       nf_ajax_zip
		,'street':    nf_ajax_street
		,'remarks':   nf_ajax_remarks
		,'onLoading': function(req) { div_nf.innerHTML = 'Sending...'; }
		,'onSuccess': function(req) {
			if ( req.responseText.indexOf('<span id="all_ok">') != -1 ) {
                clear_not_found_form();
    			window.setTimeout('Effect.Fade(\'frm_not_found\')', 10);
			}
            div_nf.innerHTML = req.responseText; 
	      }
		,'onError':   function(req) { alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
	});
}

function clear_not_found_form() {
	document.getElementById("nf_remarks").value = '';
	document.getElementById("nf_school").value  = '';
	document.getElementById("nf_zip").value     = '';
	document.getElementById("nf_city").value    = '';
	document.getElementById("nf_country").value = '';
	document.getElementById("nf_street").value  = '';
	document.getElementById("nf_email").value   = '';
}