var numb = '0123456789';
var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

function isValid(parm, val) 
{
	if (parm == "") 
		return true;
	for (i=0; i < parm.length; i++) {
		if ( val.indexOf(parm.charAt(i),0) == -1 ) 
			return false;
	}
	return true;
}

function isNumber(parm)
{
	return isValid(parm, numb + ".,");
}

function isLower(parm)
{
	return isValid(parm,lwr);
}

function isUpper(parm) 
{
	return isValid(parm,upr);
}

function isAlpha(parm) 
{
	return isValid(parm,lwr + upr);
}

function isAlphanum(parm) 
{
	return isValid(parm, lwr + upr + numb);
}

function string_to_hex(str) 
{
	var hex = "";
	for ( var i=0; i < str.length; i++) {
		hex = hex + str.charCodeAt(i).toString(16);
	}
	return hex;
}

function hex_to_string(str) 
{
	var r = "";
	try{
		var str_l = 0;
		str_l = str.length;
		
		if ( str_l == 0 )
			return r;
			
		var i = 0;
		var s = "";
		while( i < str_l ) {
			s = "0x" + str.substr(i, 2);
			s2 = String.fromCharCode(s);
			r = r + String.fromCharCode(s);
			i = i + 2;
		}
	}
	catch(error){}
	return r;
}

function get_param_value(param_name)
{
	var retval = "";
	aURL = document.URL;
	parPos = aURL.indexOf('?');
	ParStr = "";
	if (parPos > -1 ) {
		ParStr = aURL.substring(parPos + 1, aURL.length);
		parPos = ParStr.indexOf(param_name + '=');
		if (parPos > -1 ) {
			parPos = parPos + param_name.length + 1;
			parEnds = ParStr.indexOf("&", parPos);
			if (parEnds < 0) 
	  			parEnds = ParStr.length;
			retval = ParStr.substring(parPos, parEnds);
		}
	}
	return retval;
}

function set_cookie(name, value) {  // , expires in days, path, domain, secure
 var argv = set_cookie.arguments;  
 var argc = set_cookie.arguments.length;  
 var expires = (argc > 2) ? argv[2] : null;  
 var path = (argc > 3) ? argv[3] : null;  
 var domain = (argc > 4) ? argv[4] : null;  
 var secure = (argc > 5) ? argv[5] : false;  
 if ( expires != null ) {
 	var expDate = new Date();
	expDate.setTime(expDate.getTime() +  (24 * 60 * 60 * 1000 * expires)); 
 }
 
 document.cookie = name + "=" + escape (value) + 
    ((expires == null) ? "" : ("; expires=" + expDate.toGMTString())) + 
    ((path == null) ? "" : ("; path=" + path)) +  
    ((domain == null) ? "" : ("; domain=" + domain)) +    
    ((secure == true) ? "; secure" : "");
}
 
function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
      offset += search.length
      end = document.cookie.indexOf(";", offset);
      if (end == -1)
         end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
    }
  }
  return returnvalue;
}

function parseURL(url)
{
	if ( url.length <= 0 )
		return false;
    //save the unmodified url to href property
    //so that the object we get back contains
    //all the same properties as the built-in location object
    var loc = { 'href' : url };

    //split the URL by single-slashes to get the component parts
    var parts = url.replace('//', '/').split('/');

    //store the protocol and host
    loc.protocol = parts[0];
    loc.host = parts[1];

    //extract any port number from the host
    //from which we derive the port and hostname
    parts[1] = parts[1].split(':');
    loc.hostname = parts[1][0];
    loc.port = parts[1].length > 1 ? parts[1][1] : '';

    //splice and join the remainder to get the pathname
    parts.splice(0, 2);
    loc.pathname = '/' + parts.join('/');

    //extract any hash and remove from the pathname
    loc.pathname = loc.pathname.split('#');
    loc.hash = loc.pathname.length > 1 ? '#' + loc.pathname[1] : '';
    loc.pathname = loc.pathname[0];

    //extract any search query and remove from the pathname
    loc.pathname = loc.pathname.split('?');
    loc.search = loc.pathname.length > 1 ? '?' + loc.pathname[1] : '';
    loc.pathname = loc.pathname[0];

    //return the final object
    return loc;
}

function show_hide_obj(obj_id, show)
{
	var el = document.getElementById(obj_id);
	if ( el ) {
		if ( show )
			el.style.display = "";
		else
			el.style.display = "none";
	}
	return false;
}
 
function toggle_show_obj(obj_id)
{
	var doc_element = document.getElementById(obj_id);
	if ( doc_element ) {
		if ( doc_element.style.display == "" )
			doc_element.style.display = "none";
		else
			doc_element.style.display = "";
	}
	return false;
}


