function nothing() {
	return;
}

function CheckAll(obj) { 
	var form_obj = obj.form
	for (i = 0;i < form_obj.length;i++ )	{
		if (form_obj.elements[i].type == "checkbox") { 
			form_obj.elements[i].checked = (obj.checked) ? true : false; 
		}
	}
	return;
}

function ShowD(t)
{
	var currStyle = document.getElementById(t).style.display; var cact;
	if ( currStyle == 'block' ) { cact = 'none'; } else { cact = 'block'; }
	document.getElementById(t).style.display = cact;
	return;
}

function ShowAct(t,veids) {
	if (document.getElementById(t)) {
		var currStyle = document.getElementById(t).style.display; var cact;
		if ( veids == '0' ) { cact = 'none'; } else { cact = 'block'; }
		document.getElementById(t).style.display = cact;
	}
	return;
}

function SetHTML(t,b) {
document.getElementById(t).innerHTML=b;
return;
}

function GetVal(t) {
if (document.getElementById(t)) {
	v=document.getElementById(t).value;
} else {
	v=document.getElementsByName(t)[0].value;
}
return v;
}

function GetValCheckBox(t) {
if (document.getElementById(t).checked==true) { v=1; } else { v=0; }
return v;
}

function GetValByName(t) {
return document.getElementsByName(t)[0].value;
return;
}

function GetCheckedByName(t) {
var statuss=document.getElementsByName(t)[0];
if (statuss.checked==true) { v=1;} else { v=0; }
return v;
}

function SetVal(t,v) {
document.getElementById(t).value = v;
return;
}

function SetFocus(i) {
document.getElementById(i).focus();
return;
}

function GetValByName(t) {
return document.getElementsByName(t)[0].value;
return;
}

function locate(u) {
window.location.href=u;
return;
}

function locatenew(u) {
Win=this.open(u);
return
}

function WinClose() {
window.close();
}

function RefreshCurrentPage() {
	var href = window.location.href;
	window.location.assign(href);
}

function RefreshOpenerPage() {
	var href = window.opener.location.href;
	window.opener.location.assign(href);
}

function hidediv(pass) {
var divs = document.getElementsByTagName('div');

	for(i=0;i<divs.length;i++){
		if(divs[i].id.match(pass)){
			if (document.getElementById) // DOM3 = IE5, NS6
			divs[i].style.display="none";// show/hide
		else
			if (document.layers) // Netscape 4
			document.layers[divs[i]].display = 'none';
			else // IE 4
			document.all.hideShow.divs[i].display = 'none';
		}
	}
return;
}

function showdiv(pass) {
var divs = document.getElementsByTagName('div');

	for(i=0;i<divs.length;i++){
		if(divs[i].id.match(pass)){
			if (document.getElementById) // DOM3 = IE5, NS6
			divs[i].style.display="block";// show/hide
		else
			if (document.layers) // Netscape 4
			document.layers[divs[i]].display = 'block';
			else // IE 4
			document.all.hideShow.divs[i].display = 'block';
		}
	}
return;
}

function openWin(page, i, width, height) {
	window.name = "main";
	if(!width) width=488;
	if(!height) height=270;
	Win=this.open(page, 'win'+i, "toolbar=no,scrollbars=yes,resizable=no,status=yes,height="+height+",width="+width);
	if (Win) Win.focus();
	return;
}

nereidFadeObjects = new Object();
nereidFadeTimers = new Object();

function nereidFade(object, destOp, rate, delta) {
    if (!document.all)
      return
    if (object != "[object]") {
      setTimeout("nereidFade("+object+","+destOp+","+rate+","+delta+")",0);
      return;
    }
    clearTimeout(nereidFadeTimers[object.sourceIndex]);
    diff = destOp-object.filters.alpha.opacity;
    direction = 1;
    if (object.filters.alpha.opacity > destOp) {
      direction = -1;
    }
    delta=Math.min(direction*diff,delta);
    object.filters.alpha.opacity+=direction*delta;
    if (object.filters.alpha.opacity != destOp) {
      nereidFadeObjects[object.sourceIndex]=object;
      nereidFadeTimers[object.sourceIndex]=setTimeout("nereidFade(nereidFadeObjects["+object.sourceIndex+"],"+destOp+","+rate+","+delta+")",rate);
    }
}

function echeck(str) {

var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){ return false; }
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ return false; }
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ return false; }
if (str.indexOf(at,(lat+1))!=-1){ return false; }
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ return false; }
if (str.indexOf(dot,(lat+2))==-1){ return false; }
if (str.indexOf(" ")!=-1){ return false; }
return true					
}

function trim(stringToTrim) {
return stringToTrim.replace(/^\s+|\s+$/g,"");
}


function updateTimeIndex() {
var st = document.getElementsByName("ddlStartTime")[0]
var et = document.getElementsByName("ddlEndTime")[0]
if (st.selectedIndex<84) {
et.selectedIndex=(st.selectedIndex + 12)
} else {
et.selectedIndex=(st.selectedIndex-84)
}
return false;
}

function refresh() {
window.location.reload(false);
return;
}

function ClassName(id,cl) {
if (document.getElementById(id)) {
document.getElementById(id).className=cl;
}
return;
}

function SetBody(id,b) {
document.getElementById(id).innerHTML=b;
return;
}

function ub(){getdim = getPageSizeWithScroll();y=getdim[1]; if (document.getElementById('pb')) { document.getElementById('pb').style.height=y+"px"; } return; }

function getPageSizeWithScroll(){
if (window.innerHeight && window.scrollMaxY) {
	yWithScroll = window.innerHeight + window.scrollMaxY;
	xWithScroll = window.innerWidth + window.scrollMaxX;
} else if (document.body.scrollHeight > document.body.offsetHeight){
	yWithScroll = document.body.scrollHeight;
	xWithScroll = document.body.scrollWidth;
} else {
	yWithScroll = document.body.offsetHeight;
	xWithScroll = document.body.offsetWidth;
}
arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
return arrayPageSizeWithScroll;
}

function GetInnerDimensions() {
	if (window.innerHeight) {
		win_y = window.innerHeight;
		win_x = window.innerWidth;
	} else {
		win_y = ( document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight )
		win_x = ( document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth )
	}
	return Array(win_x,win_y);
}

window.onresize = function() { ub(); return; }


function alpha(e) {
	var k;
	document.all ? k = e.keyCode : k = e.which;
	return ((k > 47 && k <= 57) || k == 43 || k == 8 || k == 0);
}

function IsNumeric(sText) {
var ValidChars = "0123456789";
var IsNumber=true;
var Char;
for (i = 0; i < sText.length && IsNumber == true; i++) { 
	Char = sText.charAt(i); 
	if (ValidChars.indexOf(Char) == -1){ IsNumber = false; }
}
return IsNumber;
}

var checkboxstarted=0;
function ChkBoxStatus(v1,v2) {
if (checkboxstarted==0) {
	checkboxstarted=1;
	v=document.getElementsByName(v1)[0].checked;
	document.getElementsByName(v2)[0].checked=v;
}
checkboxstarted=0;
return;
}

function ChkMaxVal(id,v,v2) {
if (v<v2) document.getElementsByName(id)[0].value=v;
}

function dump(arr,level) {
var dumped_text = "";
if(!level) level = 0;

var level_padding = "";
for(var j=0;j<level+1;j++) level_padding += "    ";

if(typeof(arr) == 'object') {
 for(var item in arr) {
  var value = arr[item];
 
  if(typeof(value) == 'object') {
   dumped_text += level_padding + "'" + item + "' ...\n";
   dumped_text += dump(value,level+1);
  } else {
   dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
  }
 }
} else {
 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
}
return dumped_text;
}


function uploadFile(obj) {
	ShowAct('uploader',0);
	ShowAct('loading',1);
	document.getElementById('loading').innerHTML="<img src='/site/img/loading.gif' alt='loading...'>";
	document.getElementById('UploadFormName').submit();
}

function ShowActOpener(t,veids)
{
	var currStyle = parent.document.getElementById(t).style.display; var cact;
	if ( veids == '0' ) { cact = 'none'; } else { cact = 'block'; }
	parent.document.getElementById(t).style.display = cact;
	return;
}

function DataSaved() {
ShowAct('statusWindow',1);
setTimeout("DataSavedRemove()",300);
return;
}
function DataSavedRemove() {
ShowAct('statusWindow',0);
}

function ResetCssStyle(id,fromval,toval,val) {
	toval2=toval+1;
	for (i = fromval;i<toval2; i++ ) {
		className=id+i;
		if (document.getElementById(className)) {
			document.getElementById(className).className=val;
		}
	}
}

var idtoclear;
var lastpid;
var lastid;
var lasttype;

function LoadComments(pid,id,v) {
lasttype=v;
GetUrl("/site/sw/comments.php?pid="+pid+'&v='+v,id);
}

function ClearAndRefresh() {
document.getElementsByName(idtoclear)[0].value='';
LoadComments(lastpid,lastid,lasttype);
}

function SendComment(i,p,i2,t) {
var v=document.getElementsByName(i)[0].value;
d="p="+p+"&v="+v+'&t='+t;
Sw("/site/sw/addcomment.php",d);
idtoclear=i;
lastpid=p;
lastid=i2;
setTimeout("ClearAndRefresh()",500);
}

function ActivitiesWithImage(i,q) {
if (confirm(q)) {
d="i="+i; Sw("/site/sw/image_hide.php",d);
}
}

function ActivitiesWithObservation(i,q) {
if (confirm(q)) {
d="i="+i; Sw("/site/sw/observation_hide.php",d);
}
}

function ActivitiesWithComments(i,q) {
if (confirm(q)) {
d="i="+i; Sw("/site/sw/comment_hide.php",d);
setTimeout("RefreshCurrentPage()",500);
}
}


function urlencode( str ) {
                                     
    var histogram = {}, histogram_r = {}, code = 0, tmp_arr = [];
    var ret = str.toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    
    ret = encodeURIComponent(ret);
    for (search in histogram) {
        replace = histogram[search];
        ret = replacer(search, replace, ret)
    }
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
    
    return ret;
}

function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function Get_Cookie( check_name ) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		a_temp_cookie = a_all_cookies[i].split( '=' );

		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function Delete_Cookie2() {
document.cookie = 'cfguserid= ; expires=Thu, 2 Aug 2001 20:47:11 UTC; path=/';
}

function UpdateLastObs(v) {
url='/site/sw/getlastobservations.php?v='+v;
GetUrl(url,'cfglastobsinc');
return;
}

function SetTdWdt(id,v) {
if (document.getElementById(id)) {
	alert(id +' -> '+ v);
	document.getElementById(id).style.width=v;
}
}

function GetTdWdt(id) {
if (document.getElementById(id)) {
	return document.getElementById(id).offsetWidth;
}
}

function PrintPreview(l,o) {
url='/'+l+'/print/'+o+'/';
openWin(url, 'preview'+o, 781, 600);
}