//Javascript Document for aragonaire.es
var d = document;

try {
	document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}



function get_selected_siteid() {
	var site_id;
	
	if (location.href.lastIndexOf('?') !=-1) {
		var firstpos=location.href.lastIndexOf('?')+1;
		var lastpos=location.href.length;
		var query_string=location.href.substring(firstpos,lastpos);
		
		var arr_vals = query_string.split("&");
		
		for (i=0;i<arr_vals.length;i++) {
			arr_vals[i] = arr_vals[i].replace("&", "");
			arr_vals[i] = arr_vals[i].replace("?", "");

			if (arr_vals[i].indexOf("site_id=") > -1) {
				arr_vals[i] = arr_vals[i].replace("site_id=", "");
				site_id = arr_vals[i];
				break;
			}//end if
	
		}//end for
		
		return site_id;
	} else {
		//no query string
		return '';
	}//end if
	
}//end function


function change_site_image(filename, title) {
	document.getElementById('large_site_image').src = filename;	
	title = title.replace("\'", "'");
	document.getElementById('photo_title').innerHTML = '<h3>'+title+'</h3>';	

	//decide whether to display link
	if (title == "Monitoring Site Photo" || title == "Foto de la estación de medición") {
		document.getElementById('photo_title_link').style.visibility = 'hidden';
	} else {
		document.getElementById('photo_title_link').style.visibility = 'visible';
	}//end if
	
}//end function



function switch_graph(site_id, g) {

		$.ajax({
		   type: "GET",
		   url: "ajax_process/switch_graph_type.php",
		   data: 'doajax=true&site_id='+site_id+'&g='+g,
		   success: function(html){
				d.getElementById('tab_content').innerHTML = html;
		
		
			}
		 });
		
}//end function

function show_exceedance_info(date, site_id, type) {

		document.getElementById('dialog').innerHTML = '';
		 $.ajax({
		   type: "GET",
		   url: "ajax_process/ozone_exceedence.php",
		   data: "date="+date+"&site_id="+site_id+"&type="+type,
		   success: function(html){
	
			document.getElementById('dialog').innerHTML = html;
			document.getElementById('dialog').title = 'Ozone Exceedence Information';
			$("#dialog").dialog('open');
	   }
	 });
}
