function encode_utf8( s ){  return unescape( encodeURIComponent( s ) );}
function decode_utf8( s ){  return decodeURIComponent( escape( s ) );}

function encodeUTF8(string) {
	string = string.replace(/\r\n/g,"\n");
	var utftext = "";

	for (var n = 0; n < string.length; n++) 
	{
		var c = string.charCodeAt(n);

   	if (c < 128) {
   		utftext += String.fromCharCode(c);
   	}
   	else
   	{
   		if((c > 127) && (c < 2048)) 
   		{
   			utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
		}	
	}
	return utftext;
}

function decodeUTF8 (utftext) {
	var string = "";
	var i = 0;
	var c = c1 = c2 = 0;
	
	while ( i < utftext.length ) {
		c = utftext.charCodeAt(i);
		
		if (c < 128) {
			string += String.fromCharCode(c);
			i++;
		} else {
			if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			} else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
	}
	return string;
}

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + encodeURIComponent(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
 // alert(encodeURIComponent (value));
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist

function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return decodeURIComponent(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function format_text(text)
{
	tab = text.split('|');
	switch (current_language) {
		case gs_language[0] :
			if( tab[0] ) {
				text = tab[0];
			} else {
				text = tab[gs_default_language];
			}		
			break;
		case gs_language[1] :
			if( tab[1] ) {
				text = tab[1];
			} else {
				text = tab[gs_default_language];
			}		
			break;
		case gs_language[2] :
			if( tab[2] ) {
				text = tab[2];
			} else {
				text = tab[gs_default_language];
			}		
			break;
		case gs_language[3] :
			if( tab[3] ) {
				text = tab[3];
			} else {
				text = tab[gs_default_language];
			}		
			break;
		default :
			text = tab[gs_default_language];
	}   

   return text;
}

function format_dec(val, post)
{
	var decpoint;
	var begin;
	var end;
	var valstr;
	var temp_char;
	
	if ( isNaN(val) ) return '-';
	if ( val == 0 ) return '-';
	
	valstr = "" + val;
	decpoint = valstr.indexOf(".")
	if (decpoint != -1) {
		begin = valstr.substring(0,decpoint);
		end = valstr.substring(decpoint+1,valstr.length);
	}
	else {
		begin = valstr;
		end = "";
	} 
	if (end.length < post) {
		while (end.length < post) {
			end += "0";
		}
	}
	end = end.substring(0,post);
	return (begin+"."+end);
}


function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

function addClass(ele,cls) {
	if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}

function removeClass(ele,cls) {
	if (hasClass(ele,cls)) {
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,' ');
	}
}

function global_replace(text,val1,val2)
{
	var tab = text.split(val1);
	return tab.join(val2) 	
}



