// Some useful javascript functions 

// Confirm before clicking on a link
//  USAGE
// 	Html:	<a onclick="return ConfirmMsg(\'Are you sure you want to delete it?\')" href="#">Delete</a>
// 	Perl:	$cgi->a({-href=>$cgi->url() . "?cmd=del", -onClick=>"return ConfirmMsg('Are you sure you want to delete it?')"}, $cgi->img({-src=>"/images/icons/delete.gif", -border=>0, -align => 'absmiddle', -alt=>'Delete'}));

function ConfirmMsg(msg) {
	var agree=confirm(msg);
	if (agree)
		return true ;
	else
		return false ;
	}
	
	
function toggle(field) {
	if(document.getElementById) {
		
		// close block
		if (document.getElementById(field + '_o').style.display=="block"){
			document.getElementById(field + '_o').style.display="none";
			document.getElementById(field + '_c').style.display="block";
			//open_folder(field);
			
		// open block
		} else {
			document.getElementById(field + '_c').style.display="none";
			document.getElementById(field + '_o').style.display="block";
			//close_folder(field);
		}
	}
}


// Heinle's function for retrieving a cookie.
function getCookie(name){
	var cname = name + "=";                 
	var dc = document.cookie;             
	if (dc.length > 0) {        
	  	begin = dc.indexOf(cname);       
	    if (begin != -1) {                 
			begin += cname.length;       
	    	end = dc.indexOf(";", begin);      
		    if (end == -1) end = dc.length;
	        return unescape(dc.substring(begin, end));    
			}   
		}  
		return null;
	}

// An adaptation of Dorcht's function for setting a cookie.
function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) + 
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
  }


// An adaptation of Dorcht's function for deleting a cookie.
function delCookie (name,path,domain) {  
	if (getCookie(name)) {
	    document.cookie = name + "=" +    
		((path == null) ? "" : "; path=" + path) +
	    ((domain == null) ? "" : "; domain=" + domain) +
	    "; expires=Thu, 01-Jan-70 00:00:01 GMT";  
		}
	}
	


// Take the user back to the same vertical scroll position as they left. 
// Used in conjunction with Fish::FamilyTree
function relocateScroll()  {
  	var qs = location.search.substring(1);
	 var nv = qs.split('&');
	 var url = new Object();
	 for(i = 0; i < nv.length; i++) {
	   	eq = nv[i].indexOf('=');
	   	url[nv[i].substring(0,eq).toLowerCase()] = unescape(nv[i].substring(eq + 1));
	 	}
	
    if(url['yscroll']) { window.scrollTo(0, url['yscroll']); }
  	}


function updateScrollPos(url) {
	var y = document.body.scrollTop;
	//alert(y);
	url += '&yscroll=';
	url += y;
	//var loc = eval(url + "&y=" + y);
	location.href = url;
  	}
