//************************************************************************************
//Date: 090407
function vhmgetcookie(Name) {
	var search   = Name + "=";
	var lcreturn = "";
	if (document.cookie.length > 0) { // if there are any cookies
		offset = document.cookie.indexOf(search) ;
		if (offset != -1) { // if cookie exists 
			offset += search.length ;
			// set index of beginning of value
			end = document.cookie.indexOf(";", offset) ;
			// set index of end of cookie value
			if (end == -1) { end = document.cookie.length; }
			lcreturn = unescape(document.cookie.substring(offset, end));
		}
	}
	return lcreturn;
}

function vhmsetcookie(name, value, expire, path) {
	if (expire == null) {
		var today  = new Date() ;
		var expire = new Date() ;
		expire.setTime(today.getTime() + 365*24*60*60*1000) ;
	}
	document.cookie = name + "=" + escape(value) 
		+ ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
		+ ((path   == null) ? "" : ("; path="    + path                ));
}  

function vhmclearcookie(name,path) {
	var today  = new Date() ;
	var expire = new Date() ;
	var value  = "iamdone"  ;
	expire.setTime(today.getTime() - 24*60*60*1000) ;
	document.cookie = name + "=" + escape(value) + "; expires=" + expire.toGMTString()
		+ ((path == null) ? "" : ("; path=" + path));
}  

function vhmtestcookie() {
	var name  = "foo";
	var value = "bar";
	var lnrtn = 0    ;
	vhmsetcookie(name,value) ;
	if (vhmgetcookie(name)==value) {
		vhmclearcookie(name) ;
		lnrtn = 1;
	}
	return lnrtn;
}

function vhmtrimstr(stringsrc) {
    var ln = stringsrc.length - 1 ;
    var mystr = stringsrc ;
    //Trim the leading spaces
    while ( mystr.indexOf(" ")==0 && ln > 0) {
		mystr = mystr.substring(1,ln+1) ;
		ln    = mystr.length - 1 ;
    } ;
    //Trim the trailing spaces
    while ( mystr.lastIndexOf(" ")==ln && ln > 0) {
		mystr = mystr.substring(0,ln) ;
		ln    = mystr.length - 1 ;
    } ;
    if (mystr == " ") { mystr = "" ; }
    return mystr
}
