// JavaScript Document
function showRecaptcha(element, submitButton, themeName) {
  Recaptcha.create("6LflWAcAAAAAAIK02F62gVprVqbLCflgpeoA2dW-", element, {
        theme: themeName,
        tabindex: 2
        //callback: Recaptcha.focus_response_field
  });
  //hideSubmitButtons();
  //document.getElementById(submitButton).style.visibility = "visible";
}
function destroyRecaptchaWidget() {
  //hideSubmitButtons();
  Recaptcha.destroy();
}

function resetSelects(){
	$('cityselect').set('html', '<select><option>Loading...</option></select>');
	$('gradesselect').set('html', '<select><option>Loading...</option></select>');
	ahtm = "webroot/helpers/city.php?x=&cat=";
	var xhtml = new Request.HTML({
		onSuccess: function(html) {
			$('cityselect').empty();
			$('cityselect').adopt(html);
		},
		onFailure: function() {
			$('cityselect').set('text', 'The request failed.');
		}
	});
	xhtml.get(ahtm);
	
	bhtm = "webroot/helpers/grades.php?x=&cat=";
	var xhtml = new Request.HTML({
		onSuccess: function(html) {
			$('gradesselect').empty();
			$('gradesselect').adopt(html);
		},
		onFailure: function() {
			$('gradesselect').set('text', 'The request failed.');
		}
	});
	xhtml.get(bhtm);
}

function reloadselect(f,i,c,cat,x){
	if(f=='city'){
		if(i){
			htm = "webroot/helpers/"+f+".php?i="+i+"&x="+x+"&c="+c+"&cat="+cat;
		} else {
			htm = "webroot/helpers/"+f+".php?x="+x+"&cat="+cat;
		}
	} else if(f=='housing' || f=='installation'){
		if(i && c){
				htm = "webroot/helpers/"+f+".php?o="+i+"&c="+c;
		} else if(i && !c) {
				htm = "webroot/helpers/"+f+".php?o="+i;
		} else if(!i && c) {
				htm = "webroot/helpers/"+f+".php?c="+c;
		} else {
			htm = "webroot/helpers/"+f+".php";
		}
	} else {
		if(i){
			htm = "webroot/helpers/"+f+".php?i="+i+"&c="+c+"&cat="+cat+"&x="+x;
		} else {
			htm = "webroot/helpers/"+f+".php?cat="+cat+"&x="+x;
		}
	}
	if(cat=='3'){
		if($('glabel')) $('glabel').set('html', 'Age Level:');	
	} else {
		if($('glabel')) $('glabel').set('html', 'Grade Level:');	
	}
	//alert(i.options[i.selectedIndex].text);
	$(f+'select').set('html', '<select><option>Loading...</option></select>');
	var xhtml = new Request.HTML({
		onSuccess: function(html) {
			$(f+'select').empty();
			$(f+'select').adopt(html);
		},
		onFailure: function() {
			$(f+'select').set('text', 'The request failed.');
		}
	});
	xhtml.get(htm);
}

function getCalendar(m) {
	url = "/includes/calendar.php"+m;
	//load url into content DIV
	new Ajax(url ,{ 
		method: 'get', 
		update: 'calendarbox',
		onComplete:function(){ 
			//setTips();
		}
	}).request();
}
function setTips() {
	var Tips1 = new Tips($$('.Tips'), {
		initialize:function(){
			this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
		},
		onShow: function(toolTip) {
			this.fx.start(1);
		},
		onHide: function(toolTip) {
			this.fx.start(0);
		},
		offsets: {x:58,y:-15},
		hideDelay: 200,
		fixed: true
	});	
}

function changeChart(el,chart,div,title,data,width,url){
	var el = new FusionCharts("charts/"+chart, title, width, "300");
	if(url){
		el.setDataURL(url+data);
	} else {
		el.setDataURL(data);
	}
	el.render(div);
}
function loadSummary(type,yr,itemm,flag){
	var req = new Request.HTML({
		url:'webroot/stats/'+type+'.php?y='+yr+'&itemm='+itemm+'&flag='+flag, 
		onSuccess: function(html) {
			$(type+'-summary').set('text', '');
			$(type+'-summary').adopt(html);
		},
		onFailure: function() {
			$(type+'-summary').set('text', 'The request failed.');
		}
	}).send();
}
function loadData(type,yr){
	var req = new Request.HTML({
		url:'webroot/stats/'+type+'.php?y='+yr, 
		onSuccess: function(html) {
			$(type+'item').set('text', '');
			$(type+'item').adopt(html);
			//if($$('div.dleft')){
//				var divs = $$('div.dleft');
//				divs.each(function(item){
//					var size = item.getSize();
//					item.getNext().setStyle('height',size.y);
//				});
//			}
		},
		onFailure: function() {
			$(type+'item').set('text', 'The request failed.');
		}
	}).send();
}
function loadSat(type,yr,gr,id){
	var req = new Request.HTML({
		url:'webroot/stats/'+type+'.php?y='+yr+'&g='+gr+'&id='+id, 
		onSuccess: function(html) {
			$(type+'item').set('text', '');
			$(type+'item').adopt(html);
		},

		onFailure: function() {
			$(type+'item').set('text', 'The request failed.');
		}
	}).send();
}
function loadSelector(type,it,id,table){
	var req = new Request.HTML({
		url:'webroot/helpers/selectors.php?seltype='+type+'&it='+it+'&id='+id+'&table='+table, 
		onSuccess: function(html) {
			$(type+'selector').set('text', '');
			$(type+'selector').adopt(html);
		},

		onFailure: function() {
			$(type+'selector').set('text', 'The request failed.');
		}
	}).send();
}
function loadText(text){
	var req = new Request.HTML({
		url:'webroot/'+text, 
		onSuccess: function(html) {
			$('newtext').set('text', '');
			$('newtext').adopt(html);
		},

		onFailure: function() {
			$('newtext').set('text', 'The request failed.');
		}
	}).send();
}
	
function MM_jumpMenuGo(objId,targ,restore){ //v9.0
  var selObj = null;  with (document) { 
  if (getElementById) selObj = getElementById(objId);
  if (selObj) eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0; }
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
	  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	  if (restore) selObj.selectedIndex=0;
	}
	
function startGallery() {			
	if($('myGallery')){
		var myGallery = new gallery($('myGallery'), {
			timed: true,
			showArrows: true,
			showCarousel: false,
			embedLinks: true
		});
	}
	if($('myGallery2')){
		var myGallery = new gallery($('myGallery2'), {
			timed: true,
			showArrows: false,
			showCarousel: false,
			embedLinks: false
		});
	}
}

function recImpress(id){
	var req = new Request({
		url: 'includes/processads.php',
		method: 'post'
	}).send('act=impress&id='+id);
}
function recClick(id){
	var req = new Request({
		url: 'includes/processads.php',
		method: 'post'
	}).send('act=click&id='+id);
}
window.addEvent('domready', function(){		
		
		if($('yearsum')){
			$('yearsum').addEvent('change', function(e) {
				e.stop();
				var log = $('satsitem');
				$('satsForm').set('send', {onComplete: function(response) { 
					//log.removeClass('ajax-loading');
					log.set('html', response);
				}});
	
				$('satsForm').send();
			});
		}
		if($('gradesum')){
			$('gradesum').addEvent('change', function(e) {
				e.stop();
				var log = $('satsitem');
				$('satsForm').set('send', {onComplete: function(response) { 
					//log.removeClass('ajax-loading');
					log.set('html', response);
				}});
	
				$('satsForm').send();
			});
		}
		if($('yearhist')){
			$('yearhist').addEvent('change', function(e) {
				e.stop();
				var log = $('sats');
				$('testForm').set('send', {onComplete: function(response) { 
					var mySats = new FusionCharts("charts/MSLine.swf", "Test Scores", "643", "300");
					mySats.setDataXML(response);
					mySats.render("satterra");
				}});
	
				$('testForm').send();
			});
		}
		if($('gradehist')){
			$('gradehist').addEvent('change', function(e) {
				e.stop();
				var log = $('sats');
				$('testForm').set('send', {onComplete: function(response) { 
					var mySats = new FusionCharts("charts/MSLine.swf", "Test Scores", "643", "300");
					mySats.setDataXML(response);
					mySats.render("satterra");
				}});
	
				$('testForm').send();
			});
		}
		if($('satsForm')){
			$('satsForm').addEvent('submit', function(e) {
				e.stop();
				var log = $('satsitem');
				this.set('send', {onComplete: function(response) { 
					//log.removeClass('ajax-loading');
					log.set('html', response);
				}});
	
				this.send();
			});
		}
		if($('testForm')){
			$('testForm').addEvent('submit', function(e) {
				e.stop();
				var log = $('sats');
				this.set('send', {onComplete: function(response) { 
					var mySats = new FusionCharts("charts/MSLine.swf", "Test Scores", "643", "300");
					mySats.setDataXML(response);
					mySats.render("satterra");
				}});
	
				this.send();
			});
		}
		
		if('gridd'){
			SqueezeBox.initialize({
				size: {x: 650, y: 330}
			});
			
//			var hovers = $$('a.hoverr');
//			hovers.each(function(p){
//				alert('done');
//				p.addEvent('mouseover',function(){
//					alert("hey");
//				});
//			});
		}

});
