var ua = navigator.userAgent.toLowerCase();
var isIE = ((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1)); 
var img_arr = new Array();

Array.prototype.in_array = function(p_val) {
    for(var i = 0, l = this.length; i < l; i++) {
        if(this[i] == p_val) {
            rowid = i;
            return true;
        }
    }
    return false;
}
function FindPos(AObject)
{
    var posX = 0, posY = 0;
    do
    {
        posX += AObject.offsetLeft;
        posY += AObject.offsetTop;
        AObject = AObject.offsetParent;
    }
    while( AObject != null );
    var pos = [];
    pos['X'] = posX;
    pos['Y'] = posY;
    return pos;
}
function isArray(obj) 
{
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}
function GetFlashMovie(movieName) 
{
	return (isIE) ? window[movieName] : document[movieName];
}
function PreloadImage(src)
{
	var img = new Image ();
	img.onload = function (){};
  img.src = src;
  img_arr.push(img);
}
function FormatArrFiles(arr)
{
	return JSToString(arr,0);
}
function JSToString(arr,nb)
{
	var res = "";
	if(nb == NaN || nb == undefined)
		nb = 0;
	if(isArray(arr))
	{
		res += "["+nb;
		for(var n=0;n<arr.length;n++)
		{
			if(n!=0)
				res +="|"+nb+"|";
			res += JSToString(arr[n],nb+1);
		}
		res += nb+"]";
	}
	else
		res = arr;
	return res;
}
function TransMail(html)
{
	reg=new RegExp("§1", "g");
	html = html.replace(reg,"@");
	reg=new RegExp("§2", "g");
	html = html.replace(reg,"a");
	reg=new RegExp("§3", "g");
	return html.replace(reg,"e");
}
function InMail(html,sty)
{
	html = TransMail(html);
	document.write('<a class="'+sty+'" href="mailto:'+html+'">'+html+'</a>'); 
}
function CancelEvent(event) 
{
	if (isIE) 
	{
		event.cancelBubble = true;
		event.returnValue = false;
	} else 
	{
		event.preventDefault();
		event.stopPropagation();
	}
};

function GetValSelect(str)
{
	var tmp=document.getElementById(str);
	return tmp.options[tmp.selectedIndex].value;
}
function GetValRadioByName(str)
{
  var arr = document.getElementsByName(str);
  for(n=0;n<arr.length;n++)
  {
  	if(arr[n].checked)
  	{
  		return arr[n].value;
  	}
  }
  return "";
}
function VerifLogUrl(str)
{
	for(var n=0;n<str.length;n++)
	{
		e=Ord(str[n]);
		if(!(e==95||e==45||e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122)) 
			return false;
	}
	return true;
}
function ValidEmail(email)
{
	var re = /^([a-zA-Z0-9]+(([\.\-\_]?[a-zA-Z0-9]+)+)?)\@(([a-zA-Z0-9]+[\.\-\_])+[a-zA-Z]{2,4})$/gi;

	result = email.match(re) ;
	
	if (result==null)
	{
	 	return false;
	}
	else
	  return true;
} 
function Ord(string) 
{
    var str = string + '';
    var code = str.charCodeAt(0);
    if (0xD800 <= code && code <= 0xDBFF) 
    { 
        var hi = code;
        if (str.length === 1) {
            return code; 
        }
        var low = str.charCodeAt(1);
        if (!low) {
             
        }
        return ((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
   }
   if (0xDC00 <= code && code <= 0xDFFF) 
   { 
        return code; 
   }
   return code;
}
function Chr(codePt)
{
	 if (codePt > 0xFFFF) 
	 {                                                                         
       codePt -= 0x10000;
       return String.fromCharCode(0xD800 + (codePt >> 10), 0xDC00 + (codePt & 0x3FF));
   }
   else 
   {       
  		return String.fromCharCode(codePt);
   }
}
function isArray(obj)
{
   return (obj.constructor.toString().indexOf("Array") !== -1);
}
function OpenUrl(url)
{
	window.open(url,'web','');
}
function InitKeys()
{
	if(document.addEventListener)
	{
		document.addEventListener("keydown",KeysCapt,false);
		document.addEventListener("keyup",KeysCapt,false);
		document.addEventListener("keypress",KeysCapt,false);
	}
	else
	{
		document.attachEvent("onkeydown",KeysCapt); 
		document.attachEvent("onkeyup",KeysCapt);
		document.attachEvent("onkeypress",KeysCapt);
	}
}

function KeysCapt(e)
{
	if(typeof window.event!="undefined")
	{
		e=window.event;//code for IE
	}
	try 
	{
		ExternalKeys(e.keyCode,e.type);
	} 
	catch (e){}
}
function addEvent(elt,act,fun)
{
if (elt.addEventListener){
  elt.addEventListener(act, fun, false);
} else if (elt.attachEvent) {
  elt.attachEvent('on'+act, fun);
}
}

