function ietruebody()
{return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;}

var selectedTab = -1;
function switchTab(tabID){
    if(selectedTab >= 0){
    	label = document.getElementById("tab" + selectedTab + "_cell").innerHTML;
	    document.getElementById("tab" + selectedTab + "_left").src = "./image/tabOff_L.PNG";
	    document.getElementById("tab" + selectedTab + "_right").src = "./image/tabOff_R.PNG";
	    document.getElementById("tab" + selectedTab + "_cell").className = "tabOff";
	    document.getElementById("tab" + selectedTab + "_cell").innerHTML = "<a href=\"javascript: switchTab(" + selectedTab + ");\" class=\"tabLink\" id=\"tab" + selectedTab + "_label\">" + label + "</a>";

        document.getElementById("tab" + selectedTab + "_div").className = 'hideMe';
    }

    selectedTab = tabID;
	document.getElementById("tab" + tabID + "_left").src = "./image/tabOn_L.PNG";
    document.getElementById("tab" + tabID + "_right").src = "./image/tabOn_R.PNG";
    document.getElementById("tab" + tabID + "_cell").className = "tabOn";
    document.getElementById("tab" + tabID + "_cell").innerHTML = document.getElementById("tab" + tabID + "_label").innerHTML;

    document.getElementById("tab" + tabID + "_div").className = 'showMe';
}

function customWindow(Wlink, Wname, Wwidth, Wheight)
{
    Swidth = screen.width;
    Sheight =  screen.height;

    Wtop = ((Sheight - Wheight)/2);
    Wleft = ((Swidth - Wwidth)/2);

    window.open(Wlink,Wname,'width=' + Wwidth + ',height=' + Wheight + ',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=yes,menubar=yes,top=' + Wtop + ',left=' + Wleft);
}

function confirmLink(labelText, link)
{
	question = confirm(labelText);
	if(question){window.location.href = link;}
}

function ClipBoard(){
    holdtext.innerText = copytext.innerText;
    Copied = holdtext.createTextRange();
    Copied.execCommand("Copy");
    alert('The weather data is now copied to the clipboard\n'+'Open Excel, select \'Edit\' then \'Paste\'');
}
// <span id="copytext" class="hideMe">copy this</span>
// <textarea id="holdtext" class="hideMe"></textarea>

/**** <GENERIC AJAX> ****/
var xmlHttp
var elmntID

function stateChanged(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById(elmntID).innerHTML=xmlHttp.responseText
	}
}

function GetXmlHttpObject(){
	var objXMLHttp=null
	if (window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject){
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}
/**** </GENERIC AJAX> ****/

/**** <CUSTOM AJAX> ****/
function updateGDD(stationID,season,action){
    elmntID = 'gddGraph';
    document.getElementById(elmntID).innerHTML = "<img src=\"http://www.hortplus2.com/image/loading.gif\" alt=\"Loading\" />Loading..."

    xmlHttp=GetXmlHttpObject()
	if(xmlHttp == null){
		alert("Browser does not support HTTP Request")
		return
	}

	var url = "index.php?pageID=gdd_calc&pageNO=ajaxpost_addplot"
	url = url + "&stationID=" + stationID
    url = url + "&season=" + season
    url = url + "&action=" + action
	url = url + "&sid=" + Math.random()
	xmlHttp.onreadystatechange=stateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}
/**** </CUSTOM AJAX> ****/