/* ############## Declare all global variables */

//used in all admin pages, body onload OI
function checkFileBrowsing(){
	if (top.document.frames[0] == null)
		top.document.location = '../admin/Default.aspx';
}
// used in the location search
function showLoading(){
	document.getElementById("loc_loading").style.display = "block";
	document.getElementById("loc_textSearchDiv").style.display = "none";
	return false;
}
/* Methods to hide and to show favorites/email box/nearby stations */
function showhide_favorites(){
	swap("contentFavorites");
	showhide("contentEmail", false);
	showhide("contentNearbyStations", false);
	showhide("TimeZoneContent",false);
}
function showhide_email(){
	swap("contentEmail");
	showhide("contentFavorites", false);
	showhide("contentNearbyStations", false);
	showhide("TimeZoneContent",false);
}
function showhide_nearbyStations(){
	swap("contentNearbyStations");
	showhide("contentFavorites", false);
	showhide("contentEmail", false);
	showhide("TimeZoneContent",false);
}
function hide_all(){
	showhide("contentFavorites", false);
	showhide("contentEmail", false);
	showhide("contentNearbyStations", false);
}
function swap(ename) {
  var elem = document.getElementById(ename);
  if (elem != null) elem.className = elem.className.match("hiddendiv")?"showdiv":"hiddendiv";
}
function showhide(ename, show) {
  var elem = document.getElementById(ename);
  if (elem != null) elem.className = show?"showdiv":"hiddendiv";
}
/* ############## General methods required for Agri-cast app */
//setup initialization function, add function to body onLoad
//this is used by all other javascript files
function addOnloadEvent(evfunction) {
	if(typeof window.addEventListener != 'undefined') {
		window.addEventListener('load', evfunction, false);//.. gecko, safari, konqueror and standard
	} else if(typeof document.addEventListener != 'undefined') {
		document.addEventListener('load', evfunction, false);//.. opera 7
	} else if(typeof window.attachEvent != 'undefined') {
		window.attachEvent('onload', evfunction);//.. win/ie
	}
}
// General
var theForm;
function initVariables() { // this function is called in pub/xyz/pub.js
	theForm = document.forms["mainForm"];
}
addOnloadEvent(initVariables);
// sets the current pane display for the next refresh
function setView(mode) {
	document.forms.mainForm.view.value = mode;
	return true;
}
// Syngenta Intranet Search
function doIntranetSearch() {
	if (typeof(theForm.view) != 'undefined' && theForm.view.value == "IntraSearch") {
		theForm.action = "http://search1.pro.intra/Search/Syngenta_search.asp";
		theForm.pSearch.value = theForm.elements['TemplateTop:intranetSearchTxt'].value;
		return true;
	} else return false;
}
// agri.weather.view.ViewVariableTable: set the hidden field
function changeDay(fieldName,dayNum) {
	theForm.elements[fieldName].value = dayNum;
	theForm.submit();
}
// do show/hide div elements and +/- images for the weather view if link is clicked on 
// maindivid is the div element that gets hidden / displayed
// the link div class cannot changed to noPrint, this does not 
// work since style attributes overwrite class attributes
function outline(tbvalue, maindivid, imgid, imgshow, imghide) {
  if(document.getElementById(maindivid).style.display == 'none') {
  odisp(maindivid,'block');
  odisp(maindivid+'_groupview','block');
	elbyid(imgid).src = imgshow;
	elbyid(imgid).value = true;
  } else {
  odisp(maindivid,'none');
	odisp(maindivid+'_groupview','none');
	elbyid(imgid).src = imghide;
	elbyid(tbvalue).value = false;
  }
  return false;
}
function elbyid(id){return document.getElementById(id);}
function odisp(id,v){var e=elbyid(id);if(!e)return;e.style.display=v;}
// close a popup window
function closePopup() {
	window.opener.document.forms[0].submit();
	window.opener.focus();
	window.close();
	return false;
}
// open a popup window with standard options
function openPopup(url) {
	var win = window.open(url, "_popup", 
	"toolbar=0,scrollbars=1,location=0,status=0,menubar=0,resizable=1,width=700,height=800");
	win.focus();
	return false;
}
// show the report preview window (ReportEdit.ascx)
function windowPreview() {
	var win = window.open("ReportPreview.aspx", "_prevview", 
	"toolbar=0,scrollbars=1,location=0,status=0,menubar=0,resizable=1,width=700,height=800");
	win.focus();
	return false;
}
// show the report preview window (ResultsHeader.ascx)
function windowPreviewPrint() {
	var win = window.open("ReportPreview.aspx?print=true", "_prevview", 
	"toolbar=0,scrollbars=1,location=0,status=0,menubar=1,resizable=1,width=700,height=800");
	win.focus();
}
// show the chart in big size (agri.weather.view.ViewWeatherChart)
function openchartwin(id) {
	win=window.open('PlotChartPage.aspx?id='+id,'_plotchart','width=1000,height=570,scrollbars=1,resizable=1,menubar=1,status=0,toolbar=0,titlebar=0');
	win.focus();
	return false;
}
// does a submit if enter is pressd
function entersubmit(ev,id){
  if (ev.keyCode != 13)return true;
  if(__doPostBack) __doPostBack(id,'');
  else {
    var e=document.getElementById(id.Replace('$','_').Replace(':','_'));
    if (e && e.click) {
      e.click();
      return false;
    }
  }
  return true;
}
