function var_dump(obj) {
   if(typeof obj == "object") {
      return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
   } else {
      return "Type: "+typeof(obj)+"\nValue: "+obj;
   }
}//end function var_dump



//Should be part of the Login/logout files
function sofrsLogin() {
	
	var password = $F('password');
	var sha = new jsSHA(password);
	var hash = sha.getHash("HEX");
	var username = $F('logon');

	/* var parms = $('loginform').serialize(true); */
	var parms = "username=" + username + "&password=" + hash + "&ACTION=LOGIN";
		
	new Ajax.Request("/sofrs/login.php", 
		{
			method: 'post',
			parameters: parms,
			onSuccess: function(transport) {
							var foo = transport.responseText;
							if (foo == 'true') {
								window.location = "/sofrs/index.php"; 
							}
							else {
								$('badlogin').innerHTML = foo;
							}
						}
		}
	);
}

function showResp(resp) {
	alert(resp.responseText);
}

//Should be part of the Login/logout files
function sofrsLogout() {
	var parms=$('logoutform').serialize(true);
	
	new Ajax.Request("/sofrs/login.php", 
		{
			method: 'post',
			parameters: parms
		}
	);
	
	window.location = "/sofrs/";
}


function pShow(id, hide) {
	document.getElementById(id).className="visible";
	if (hide) {
		document.getElementById(hide).className="hidden";
	}
}

function pHide(id, alt) {
	document.getElementById(id).className="hidden";
	if (alt) {
		document.getElementById(alt).className="hidden";
	}
	//Element.hide(id);
}

function pToggle(id) {
	if ($(id).className == "visible") {
		$(id).className="hidden";
	}
	else if ($(id).className == "hidden") {
		$(id).className = "visible";
	}		
}


function pShowHide(show, hide) {
	this.pHide(hide);
	this.pShow(show);
}



/**
 * Take an array of field names that are listed as required. Check to see if each of these 
 * form fields has 'something' in it. If a required field is empty, push its name onto an 
 * array. Return an array containing the names of missing fields.
**/
function emptyReqField(array) {
	var retVal = new Array();

	for (i = 0; i < array.length; i++) {
		if ($F(array[i]).length < 1) {
			retVal.push(array[i]);
		}
	}
	
	if (retVal.length > 0) {
		return retVal;
	}
	else {
		return false;
	}
}

function dd2dms(dd) {
    if (dd < 0) {
        var negative = true;
        dd = Math.abs(dd);
    }
    else {
        var negative = false;
    }

	var retval = new Array();
    // Get everything before the decimal point
    if (!negative) {
        retval['deg'] = Math.floor(dd);
    }
    else {
        retval['deg'] = Math.floor(dd) * -1;
    }

    // Get everything after the decimal point and convert to minutes
    var min_total = (dd - Math.floor(dd)) * 60.0;
    retval['min'] = Math.floor(min_total);

    // Get everything after the minutes decimal point and convert to seconds
    var sec_total = (min_total - Math.floor(min_total)) * 60.0;

    // Round seconds to 4 points of precision
    var sec_temp = sec_total * 10000;
    var sec = Math.round(sec_temp) / 10000;
    retval['sec'] = sec;
    
    return retval;
}

function writePage(resp) {
	document.write(resp.responseText);
}

function showResp(resp) {
	alert(resp.responseText);
}

/* Validate email addresses */
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){
	   //alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   //alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    //alert("Invalid E-mail ID")
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    //alert("Invalid E-mail ID")
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    //alert("Invalid E-mail ID")
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    //alert("Invalid E-mail ID")
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    //alert("Invalid E-mail ID")
	    return false
	 }
	 return true					
}

function ToggleTableRow(id) { 
	var obj = document.getElementById(id); 
	var state = (arguments.length >= 2 
		&& typeof(arguments[1]) == "boolean" 
		? arguments[1] : 
		(obj.style.display.length && obj.style.display.toLowerCase() != "none" ? false : true)); 
	if (obj) obj.style.display = 
		(state ? (navigator.appName.indexOf("Microsoft") >= 0 
		? "block" : (obj.nodeName && obj.nodeName.toLowerCase() == "tbody" 
		? "table-row-group" : "table-row")) : "none"); 
}

function isArray(testObject) {   
    return testObject && !(testObject.propertyIsEnumerable('length')) && typeof testObject === 'object' && typeof testObject.length === 'number';
}