function Is()
{
agent = navigator.userAgent.toLowerCase();
this.major = parseInt(navigator.appVersion);
this.minor = parseFloat(navigator.appVersion);
this.ns = ((agent.indexOf('mozilla') != -1) &&
(agent.indexOf('spoofer') == -1) &&
(agent.indexOf('compatible') == -1) &&
(agent.indexOf('opera') == -1) &&
(agent.indexOf('webtv') == -1) &&
(agent.indexOf('hotjava') == -1));
this.ns6 = (this.ns && (this.major >= 5));
this.ie = ((agent.indexOf("msie") != -1) && (agent.indexOf("opera") == -1));
this.ie6 = (this.ie && (this.major == 4) && (agent.indexOf("msie 6.") != -1));
this.ie7 = (this.ie && (this.major == 4) && (agent.indexOf("msie 7.0b") != -1));
this.w3dom = (this.ns6 || this.ie6 ||this.ie7);
this.safari = (agent.indexOf('safari') != -1);
this.mac = (agent.indexOf('mac') != -1);
this.firefox = (agent.indexOf('firefox') != -1);
}

var is = new Is();
// global url get parameters
GL_param  = new Array();
GL_search = document.location.search.substring(1).split('&');
for (i in GL_search) {
	GL_t = GL_search[i].split('=');
	GL_param[GL_t[0]] = GL_t[1];
}

function getParam(name)
{
	if (GL_param[name])
		return GL_param[name];
	else
		return '';
}

function getId(id)
{
if (id=='' || id==null) return null;
return document.getElementById(id);
}

function getDomain()
{
	var d = document.location.host.split('.');
	var dom = d[d.length - 2]+'.'+d[d.length - 1];
	return dom;
}

function baseUrl()
{
	return (location.protocol+'//'+location.host);
}

function createCookie(c_name,value,expiredays)
{
	if (expiredays){
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
	}
	document.cookie=c_name+"="+escape(value)+((expiredays==null)?"":"; expires="+exdate.toGMTString())+"; path=/; domain="+getDomain()+";";
}

function readCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
	    {
	    c_start=c_start + c_name.length+1;
	    c_end=document.cookie.indexOf(";",c_start);
	    if (c_end==-1) c_end=document.cookie.length;
	    return unescape(document.cookie.substring(c_start,c_end));
	    }
	  }
	return null;
}

function delete_cookie(c_name)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()-365);
	document.cookie=c_name+"=; expires="+exdate.toGMTString()+"; path=/; domain="+getDomain()+";";
}


function callMatrix(p)
{
	stopLoad();
	top.location = baseUrl()+'/main.php';
}

function callMain(p)
{
	stopLoad();
	top.location = baseUrl()+'/main.php?'+p;
}

function callView(p)
{
	stopLoad();
	var url = baseUrl()+'/view.php?ret=1&'+p;
	if (p == 'A=Upload')
		top.location = url;
	else
		document.location = url;
}

function callPage(p)
{
	stopLoad();
	document.location = baseUrl()+'/page.php?'+p;
}

function goRef(r,t)
{
	if (t=='') document.location.href=r;
	else window.open(r,t);
}

function goHome(p)
{
	top.location = location.protocol+'//'+location.host+'/index.php';
}

function upgrade(p)
{
	top.location = location.protocol+'//'+location.host+'/products.php';
}

function urlEncode(url){
	return escape(url);
}

function resetMatrix()
{
	parent.matrixprm = null;
	parent.fullList = null;
	parent.loadList = false;
	parent.resultList = null;
	parent.selectList=null;
	parent.selectItem=null;
	callView('A=Matrix');
}

// logout
function delCookies()
{
   delete_cookie('U');
   delete_cookie('H');
   delete_cookie('M');
   delete_cookie('N');
   delete_cookie('G');
   delete_cookie('S');
   delete_cookie('PL');
}

function logout()
{
   delCookies();
   parent.location = 'signout.php';
}

// misc tools
function dateFormat()
{
	var American='%m/%d/%Y';
	var European='%d/%m/%Y';

	var d=new Date('10/28/1976');
	var s=d.toLocaleDateString();
	if(s.charAt(0)=='2')
		return European
	else
		return American;
}

function ucword(str)
{
   // split string
   firstChar = str.substring(0,1);
   remainChar = str.substring(1);

   // convert case
   firstChar = firstChar.toUpperCase();
   remainChar = remainChar.toLowerCase();

   return firstChar + remainChar

}

function formatDate(dat)
{
	d = dat.getDate();
	m = dat.getMonth()+1;
	y = dat.getFullYear();

	d = (d > 9) ? d : ('0'+d);
	m = (m > 9) ? m : ('0'+m);
	y = (y < 100) ? y : (y.toString().substring(2));

	if(dat.toLocaleDateString().charAt(0)=='2')
		return (d+"/"+m+"/"+y); // European
	else
		return (m+"/"+d+"/"+y); // American
}

function objProp(o)
{
	s = '';
	n = 0;
	for (i in o){
		n++;
		s+= '-' + i + ':' + o[i] + '\n';
		if ((n % 20) == 0) {
			alert(s);
			s = '';
		}
	}
	alert(s);
}

function inArray(val,arr)
{
	for (var i in arr){
		if (arr[i] == val) return true;
	}
	return false;
}

var preload_image = new Image();
function preloadImage(u)
{
	preload_image.src=u;
}

function s3Url(f,sz,buck,akid){
	if (f.s == "") return (imgProc(sz));
	u = 'http://s3.amazonaws.com/'+buck+'/';
	u+= f.h+'_tn_crop'+sz;
	u+= '?AWSAccessKeyId='+akid;
	u+= '&Expires='+f.s;
	return u;
}

function addOption(sid,optxt,opval)
{
	opval = (opval == null) ? optxt : opval;
	var sel = getId(sid);
	var elm = new Option(optxt,opval,false,false);
	sel.options[sel.length] = elm;
}

function getOptionsText(sel,arrayLst){
	var ret = '';
	for (var i = 0; i < sel.options.length; i++) {
		if (inArray(sel.options[i].value,arrayLst))
			ret += ','+sel.options[i].innerHTML;
	}
	return (ret.substr(1));
}

function checkEmail(email) //http://www.javascriptkit.com
{
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	return (filter.test(email));
}
//--
var ACC=new Array();
ACC['à']='a'; ACC['á']='a'; ACC['â']='a'; ACC['ã']='a'; ACC['ä']='a'; ACC['å']='a';
ACC['è']='e'; ACC['é']='e'; ACC['ê']='e'; ACC['ë']='e';
ACC['ì']='i'; ACC['í']='i'; ACC['î']='i'; ACC['ï']='i';
ACC['ò']='o'; ACC['ó']='o'; ACC['ô']='o'; ACC['õ']='o'; ACC['ö']='o';
ACC['ù']='u'; ACC['ú']='u'; ACC['û']='u'; ACC['ü']='u';
ACC['ç']='c';
function stripAccents(str)
{
	str = str.toLowerCase();
	var out = '';
	for (var i=0; i<str.length; i++)
		out += (ACC[str.charAt(i)] == null) ? str.charAt(i) : ACC[str.charAt(i)];
	return out;
}

function trim(s) {
    return s.replace(/^\s+/, '').replace(/\s+$/, '');
}

function ltrim(s) {
    return s.replace(/^\s+/, '');
}

function rtrim(s) {
    return s.replace(/\s+$/, '');
}

function stopLoad()
{
	if (window.stop)
		window.stop();
	else
		document.execCommand("Stop");
}

function imgPath(img){
	var p = '/themes/'+theme_name+'/imgs/'+img;
	preloadImage(p);
	return (p);
}

function imgColor(img){
	var p = '/themes/'+theme_color+'/imgs/'+img;
	preloadImage(p);
	return (p);
}

function imgProc(sz){
	var p = '/themes/orangepurple/imgs/proc/proc'+sz+'.jpg';
	return (p);
}

function localDate(d)
{
	var dt = d.toGMTString().split(' ');
	return (dt[1] + ' ' + dt[2] + ' ' + dt[3]);
}

function dateForm(d){
	try{
	var dt = d.split('-');
		dx = new Date();
		dx.setDate(dt[2]);
		dx.setMonth(dt[1] - 1);
		dx.setFullYear(dt[0]);
		return localDate(dx);
	}
	catch(e){
		return '';
	}
}

function dispId(lst)
{
	L = lst.split(',');
	for (i in L)
		getId(L[i]).style.display = 'inline';
}

function hideId(lst)
{
	L = lst.split(',');
	for (i in L) getId(L[i]).style.display = 'none';
}

function toggleDisplayId(id)
{
	getId(id).style.display = (getId(id).style.display == 'none') ? 'block' : 'none';
}

function resizeListHeight(list_id)
{
	var lst = getId(list_id);
	lst.style.height = '50px';
	lst.style.height = lst.offsetParent.offsetHeight+'px';
}

function isEnable(b_id){
	return (getId(b_id).className.indexOf('_d') < 0);
}

function initImgKey(path){
	p = (path) ? path : '';
	var d = SJAX(p+'gethtest.php','GET',false);
	createCookie('HTC',d.substr(0,3));
	createCookie('HT',d.substr(3));
	getId('IMGKEY').src = p+'widgets/humantest.php?nocache='+(new Date());
	delWhenComplete();
}

function delWhenComplete()
{
	if (getId('IMGKEY').complete == true)
		delete_cookie('HTC');
	else
		window.setTimeout("delWhenComplete()", 500);
}

function getSelectedCookie()
{
	var sel=Array();
	var cookie=readCookie("SEL")
	if(!cookie) return sel;
	var lst=cookie.split(',');
	for(i in lst){
		sel[parseInt(lst[i])]=true;
	}
	return sel;
}

var selectItems;
function getSelected()
{
	var i;
	var cnt=0;
	var lst=Array();
	for(i in selectItems){
		if((i!=0) && (selectItems[i]==true)) lst[cnt++]=i;
	}
	return lst;
}

function getSelectedItems()
{
	var sel=Array();
	try {
		var psl=parent.selectList;
	}
	catch(e){
		var psl = null;
	}
	if(!psl) return sel;
	var lst=psl.split(',');
	for(i in lst){
		sel[parseInt(lst[i])]=true;
	}
	return sel;
}

function initList()
{
	parent.selectList = null;
	parent.loadList = true;
}

function textMaxLength(obj,len)
{
	if (obj.value.length>len) obj.value=obj.value.substring(0,len);
}

function randBetween(num1,num2)
{
	var gen = Math.random()*(num2-num1);
	return (Math.round(num1+gen))
}

var arbzk = (randBetween(1000,2000))+'@';
function contactUs()
{
	var c1 = '2padteam.com';
	var c2 = 'mailto:contact';
	return (c2+arbzk+c1);
}

function testKey(e)
{
	if(window.event) // IE
		return e.keyCode;
	else if(e.which) // Firefox
		return e.which;
}

function pageWidth(){return window.innerWidth != null? window.innerWidth: document.body != null? document.body.clientWidth:null;}
function pageHeight(){return window.innerHeight != null? window.innerHeight: document.body != null? document.body.clientHeight:null;}
function scrWidth(){return document.documentElement.scrollWidth != null? document.documentElement.scrollWidth: document.body.scrollWidth != null? document.body.scrollWidth:null;}
function scrHeight(){return document.documentElement.scrollHeight != null? document.documentElement.scrollHeight: document.body.scrollHeight != null? document.body.scrollHeight:null;}

function btnOver(o){if (o.className.indexOf('_d') == -1) o.className+=" col2";}
function btnOut(o){o.className=o.className.replace(" col2","");}


//--Languages--
function chooseLang(){getId("LangBox").style.display = 'block';}
function hideLang(){getId("LangBox").style.display = 'none';}

function setLang(ln)
{
  	delete_cookie('L');
	createCookie('L',ln);

	var toploc=false;
	var d=SJAX('/setuserlang.php?lang='+ln);
  	var dl = document.location;

  	uhost = dl.hostname.replace('www.','');
  	uhost = uhost.replace('en.','');
  	uhost = ((ln=='en')?'en.':'www.')+uhost;

  	upath = dl.pathname;
  	if (upath.indexOf('view.php')){
  		toploc=true;
  		upath = upath.replace('view.php','main.php');
  	}

  	usearch = dl.search.replace('lang=en','');

  	url = dl.protocol+'//'+uhost+upath+usearch;

  	if (toploc===true)
    	top.location = url;
    else
	    document.location = url;
}

//--New combo box--
function comboxInit(id)
{
	element = document.getElementById(id+'_list');
	element.onkeydown = comboxKeyDown;
	if (element.captureEvents) element.captureEvents(Event.KEYDOWN);
}
function comboxOpen(obj)
{
	var prefix = obj.id.split('_');
	var obj = document.getElementById(prefix[0]+'_list');
	if (obj.style.display == "block"){
		obj.style.display = "none";
	}
	else {
		obj.style.display = "block";
		obj.focus();
	}
}
function comboxSetValue(obj)
{
	var prefix = obj.id.split('_');
	document.getElementById(prefix[0]+'_label').innerHTML = obj.options[obj.selectedIndex].innerHTML;
}
function comboxKeyDown(e)
{
	if (!e) var e = window.event
	if (e.keyCode) var code = e.keyCode;
	else if (e.which) var code = e.which;
	if (code==13) comboxOpen(this);
}

function fieldMandatory(e,fname){
	if (e.value == ""){
		e.focus();
		alert(TJAX('The field [$p1] is required',fname));
		return false;
	}
	return true;
}
var XHTTP;

//http readyState
var HRS = new Array();
HRS[0]="uninitialized";
HRS[1]="loading";
HRS[2]="loaded";
HRS[3]="interactive";
HRS[4]="complete";

//http status
var HST = new Array();
HST[100]="Continue";
HST[101]="Switching protocols";
HST[200]="OK";
HST[201]="Created";
HST[202]="Accepted";
HST[203]="Non-Authoritative Information";
HST[204]="No Content";
HST[205]="Reset Content";
HST[206]="Partial Content";
HST[300]="Multiple Choices";
HST[301]="Moved Permanently";
HST[302]="Found";
HST[303]="See Other";
HST[304]="Not Modified";
HST[305]="Use Proxy";
HST[307]="Temporary Redirect";
HST[400]="Bad Request";
HST[401]="Unauthorized";
HST[402]="Payment Required";
HST[403]="Forbidden";
HST[404]="Not Found";
HST[405]="Method Not Allowed";
HST[406]="Not Acceptable";
HST[407]="Proxy Authentication Required";
HST[408]="Request Timeout";
HST[409]="Conflict";
HST[410]="Gone";
HST[411]="Length Required";
HST[413]="Request Entity Too Large";
HST[414]="Request-URI Too Long";
HST[415]="Unsupported Media Type";
HST[416]="Requested Range Not Suitable";
HST[417]="Expectation Failed";
HST[500]="Internal Server Error";
HST[501]="Not Implemented";
HST[502]="Bad Gateway";
HST[503]="Service Unavailable";
HST[504]="Gateway Timeout";
HST[505]="HTTP Version Not Supported";

var AllowAsync = true;

function encodeFieldSp(str){
	str =  str.replace(/\=/g,"---EQL---");
	str =  str.replace(/\&/g,"---AND---");
	str =  str.replace(/\?/g,"---QST---");
	return str;
}

function decodeFieldSp(str){
	str =  str.replace(/---EQL---/g,'=');
	str =  str.replace(/---AND---/g,'&');
	str =  str.replace(/---QST---/g,'?');
	return str;
}

// create object XMLHttpRequest
function getXHTTP()
{
	try {
		XHTTP = new XMLHttpRequest();
	}
	catch(e) {
		AllowAsync = false;
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP");
		// try every versions until one works
		for (var i=0; i<XmlHttpVersions.length && !XHTTP; i++) {
			try {
				XHTTP = new ActiveXObject(XmlHttpVersions[i]);
			}
			catch (e) {}
		}
	}
	if (!XHTTP)
		displayError("Your browser doesn't handle AJAX, please use Internet explorer, Safari or firefox");
	else
		return XHTTP;
}

function XHTTP_error(st,json){
	if (json)
		return '[{"HTTP_Error":"'+st+', '+HST[st]+'"}]';
	else
		return '"HTTP_Error:'+st+', '+HST[st];
}

// Synchronous JAX Request
function SJAX(url,mtd,json)
{
	var r=null;
	if (!url) return;
	if (!mtd || !AllowAsync) mtd = "GET";
	u = URLPREP(url,mtd);

	XHTTP = getXHTTP();

	XHTTP.open(mtd, u[0], false);
	if (mtd == "POST"){
		XHTTP.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		XHTTP.setRequestHeader("Content-length", u[1].length);
		XHTTP.setRequestHeader("Connection", "close");
	}
	else{
		XHTTP.setRequestHeader('Content-Type','text/html');
	}
	if (json) XHTTP.setRequestHeader('Accept', 'application/json');

	XHTTP.send(u[1]);

	r = (XHTTP.readyState == 4 && XHTTP.status == 200) ? XHTTP.responseText : XHTTP_error(XHTTP.status,json);

	delete XHTTP;

	if (json) r = eval("("+r+")");
	return r;
}

// Asynchronous JAX Request
function AJAX(url, fcallback, mtd, json)
{
	var r=null;
	if (AllowAsync){
		if (!url) return;
		if (!mtd || !AllowAsync) mtd = "GET";
		u = URLPREP(url,mtd);

		XHTTP = getXHTTP();

	  	XHTTP.onreadystatechange = function()
	   	{
	   		try{
			    if (XHTTP.readyState == 4){
				    	r = (XHTTP.status == 200) ? XHTTP.responseText : XHTTP_error(XHTTP.status,json);
				    	delete XHTTP;
						if (json) r = eval("("+r+")");
						if (fcallback) ret = fcallback(r);
			    }
	    	}
	    	catch (e){}
		}
		XHTTP.open(mtd, u[0], true);
		if (mtd == "POST"){
			XHTTP.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			XHTTP.setRequestHeader("Content-length", u[1].length);
			XHTTP.setRequestHeader("Connection", "close");
		}
		else{
			XHTTP.setRequestHeader('Content-Type','text/html');
		}
		if (json) XHTTP.setRequestHeader('Accept', 'application/json');

		XHTTP.send(u[1]);
	}
	else {
		r = SJAX(url, mtd, json);
		if (fcallback) ret = fcallback(r);
	}
}

// synchronous TJAX Request for translation
function TJAX(tx,p1,p2,p3,p4)
{
	var r=null;
	tx = (tx) ? encodeURIComponent(tx) : '';
	p1 = (p1) ? encodeURIComponent(p1) : '';
	p2 = (p2) ? encodeURIComponent(p2) : '';
	p3 = (p3) ? encodeURIComponent(p3) : '';
	p4 = (p4) ? encodeURIComponent(p4) : '';
	u = "gettext.php?tx="+tx+"&p1="+p1+"&p2="+p2+"&p3="+p3+"&p4="+p4;
	XHTTP = getXHTTP();
	XHTTP.open('GET', u, false);
	XHTTP.setRequestHeader('Content-Type','text/html');
	XHTTP.send(null);
	r = (XHTTP.readyState == 4 && XHTTP.status == 200) ? XHTTP.responseText : XHTTP_error(XHTTP.status,null);
	delete XHTTP;
	return r;
}

function URLPREP(url,mtd)
{
	var upath   = '';
	var usearch = '';
	var uparam  = new Array();
	var nocache = new Date();

	var qm = url.indexOf('?');
	if (qm != -1){
		upath   = url.substring(0,qm);
		usearch = url.substring(qm+1);
		uparam  = usearch.split('&');
		var us=new Array();
		for (var i in uparam){
			var prm = uparam[i].split('=');
			us[i]=prm[0]+'='+encodeURIComponent(decodeFieldSp(prm[1]));
		}
		usearch = us.join('&')+'&nocache='+encodeURIComponent(nocache);
	}
	else {
		upath = url;
		usearch = 'nocache='+encodeURIComponent(nocache);
	}
	if (mtd == 'GET')
		ret = new Array((upath+'?'+usearch),null);
	else
		ret = new Array(upath,usearch);
	return ret;
}

//CALL of SQL queries by name in queries directory with dataset return in JSON format
function SJSON(Query)
{
	return SJAX('ajson.php?Q='+Query,'GET',true);
}

function AJSON(Query,Callback)
{
	AJAX('ajson.php?Q='+Query,Callback,'GET',true);
}
function boxCenter(elm)
{
	if (typeof elm == 'string') elm = document.getElementById(elm);
	var bmaxw = document.body.clientWidth - 20;
	var bmaxh = document.body.clientHeight - 20;
	elm.style.top  = parseInt((bmaxh/2)-(elm.offsetHeight/2),10)+'px';
	elm.style.left = parseInt((bmaxw/2)-(elm.offsetWidth/2) ,10)+'px';
}

function addEventSimple(obj,evt,fn) {
	if (obj.addEventListener)
		obj.addEventListener(evt,fn,false);
	else if (obj.attachEvent)
		obj.attachEvent('on'+evt,fn);
}

function removeEventSimple(obj,evt,fn) {
	if (obj.removeEventListener)
		obj.removeEventListener(evt,fn,false);
	else if (obj.detachEvent)
		obj.detachEvent('on'+evt,fn);
}

var dragDropOn = false;
dragDrop = {
	initialMouseX: undefined,
	initialMouseY: undefined,
	startX: undefined,
	startY: undefined,
	dXKeys: undefined,
	dYKeys: undefined,
	draggedObject: undefined,
	initElement: function (element) {
		if (typeof element == 'string') element = document.getElementById(element);
		element.onmousedown = dragDrop.startDragMouse;
	},
	startDragMouse: function (e) {
		if (!dragDropOn) return;
		dragDrop.startDrag(this);
		var evt = e || window.event;
		dragDrop.initialMouseX = evt.clientX;
		dragDrop.initialMouseY = evt.clientY;
		addEventSimple(document,'mousemove',dragDrop.dragMouse);
		addEventSimple(document,'mouseup',dragDrop.releaseElement);
		return false;
	},
	startDrag: function (obj) {
		if (dragDrop.draggedObject) dragDrop.releaseElement();
		dragDrop.startX = obj.offsetLeft;
		dragDrop.startY = obj.offsetTop;
		dragDrop.draggedObject = obj;
		obj.className += ' dragged';
	},
	dragMouse: function (e) {
		var evt = e || window.event;
		var dX = evt.clientX - dragDrop.initialMouseX;
		var dY = evt.clientY - dragDrop.initialMouseY;
		dragDrop.setPosition(dX,dY);
		return false;
	},
	setPosition: function (dx,dy) {
		var ddo = dragDrop.draggedObject;
		maxleft = (document.body.clientWidth - ddo.offsetWidth);
		maxtop = (document.body.clientHeight - ddo.offsetHeight);
		ddo.style.left = Math.max(Math.min(dragDrop.startX + dx,maxleft),0) + 'px';
		ddo.style.top = Math.max(Math.min(dragDrop.startY + dy,maxtop),0) + 'px';
	},
	releaseElement: function() {
		removeEventSimple(document,'mousemove',dragDrop.dragMouse);
		removeEventSimple(document,'mouseup',dragDrop.releaseElement);
		dragDrop.draggedObject.className = dragDrop.draggedObject.className.replace(/dragged/,'');
		dragDrop.draggedObject = null;
	}
}

function msgBox(title,text,typmsg,buttons,fcallback,boxclass,defval,lock,closeauto)
{
var cover=getId('HCover');
var dbox=getId('DialogBox');
var icoPath="/themes/orangepurple/imgs/";
var title=(title)?title:'Message';
var text=(text)?text:'';
var typmsg=(typmsg)?typmsg: 'info';
var buttons=(buttons)? buttons: 'OK';
var boxclass=(boxclass)? boxclass: 'trans';
dbox.defvalue=(defval)? defval : (buttons.split(',')[0]);
dbox.fnCallback=fcallback;
dbox.locked = (lock) ? lock : false;
dbox.closeAuto =(closeauto===false)?false:true;
coverReposit();
var	h='';
h+='<table class="dbmain" cellpadding="0" cellspacing="0" width="200">';
if (typmsg=='simple'){
h+='<tr><td valign="top" width="100%" align="left" nowrap>'+text+'</td></tr>';
h+='<tr><td width="100%" align="center" valign="middle" height="26" nowrap><a href="javascript:dialClose();" class="linkmedium">Close</a></td></tr>';
}
else {
h+='<tr><td valign="top">';
h+='<table  width="100%" cellpadding="0" cellspacing="3" class="dbtitlebar" onmouseover="dragDropOn=true;" onmouseout="dragDropOn=false;"><tr>';
h+='<td width="100%" nowrap>'+title+'</th>';
if (dbox.locked == false && (buttons != 'none' || buttons == 'close'))
	h+='<td valign="middle"><a href="javascript:void(0);" class="dbbtnclose" onclick="dialReturn(null);" />&nbsp;x&nbsp;</a></td>';
h+='</tr></table></td></tr>';
h+='<tr><td><table class="dbcontent" width="100%" border="0" cellpadding="0" cellspacing="4">';
h+='<tr><td style="height:8px"></td></tr>';
h+='<tr valign="top"><td>&nbsp;</td><td valign="top" width="100%" align="left" nowrap>'+text+'</td><td>&nbsp;</td></tr>';
var btnFocus = '';
if (buttons && buttons != 'none' && buttons != 'close') {
	h+='<tr><td style="height:8px"></td></tr>';
	h+='<tr><td>&nbsp;</td>';
	h+='<th align="center" nowrap="nowrap">';
	btns = buttons.split(',');
	h+='<table class="bar dialbar"><tr><td class="lbor">&nbsp;</td>';
	for (i in btns){
		var clx = "";
		if (btns.length > 1) {
			var clx = "butn";
			if (i == 0) clx = "lbutn";
			if (i == (btns.length - 1)) clx = "rbutn";
		}
		var btnId = 'DBOXBTN_'+i;
		if (btns[i].toUpperCase() == dbox.defvalue.toUpperCase()) btnFocus = btnId;
		h+='<td class="'+clx+'"><a id="'+btnId+'" href="javascript:dialReturn(\''+btns[i]+'\');">'+btns[i]+'</a></td>';
	}
	h+='<td class="rbor">&nbsp;</td></tr></table>';
	h+='</th>';
	h+='<td>&nbsp;</td>'
}
h+='<tr><td style="height:8px"></td></tr>';
h+='</tr></table>';
h+='</td></tr>';
}
h+='</table>';

dbox.onkeydown = function(e){
	var dbox = getId('DialogBox');
	if (dbox.locked) return;
	k = (is.ie) ? event.keyCode : e.which;
	if (k == 13 || k == 27){
		if (dbox.style.display != 'none'){
			if (k == 13)
				dialReturn(dbox.defvalue);
			else if (k == 27)
				dialReturn(null);
	    	if (is.ie)
		    	event.cancelBubble=true;
			else
	    		e.preventDefault();
		}
	}
}
if (cover) {
	cover.style.display = 'block';
	coverReposit();
}
dbox.innerHTML = h;
dbox.style.display = 'block';
boxCenter(dbox);
dragDrop.initElement(dbox);
dbox.focus();
elems = dbox.getElementsByTagName('input');
if (getId('DBOXINPUT_1')) getId('DBOXINPUT_1').focus();
else if (elems[0]) elems[0].focus();
else if (getId(btnFocus)) getId(btnFocus).focus();
}

function dialReturn(v)
{
	var dbox = getId('DialogBox');
	if (dbox.closeAuto===true){
		dbox.style.display = 'none';
		coverClose();
	}
	if (dbox.fnCallback!=null) {
		elems = dbox.getElementsByTagName('input');
		var datas = new Array();
		datas[0] = v;
		var j = 1;
		for (i = 1; i < 9; i++) {
			var el = document.getElementById('DBOXINPUT_'+i);
		  	if (el!=null) {
				if (el.type == "text" || el.type == "textarea" || el.type == "password" || (el.type == "radio" && el.checked) || (el.type == "checkbox" && el.checked)){
					datas[j] = el.value;
					j++;
				}
		  	}
		}
		ret = dbox.fnCallback(datas);
	}
}

function dialClose()
{
	getId('DialogBox').innerHTML = '';
	getId('DialogBox').style.display = 'none';
	coverClose();
}

function coverClose()
{
	if (getId('HCover')) getId('HCover').style.display = 'none';
}

// msgBox samples
function msgSimple(text){
	msgBox(null,text,'simple','none');
}

function msgView(text,title){
	msgBox(title,text,'info','none');
}

function msgAlert(text,title,fcallback,boxclass){
	msgBox(title,text,'warning','OK',fcallback,boxclass);
}

function msgError(text,title,fcallback,boxclass){
	msgBox(title,text,'error','OK',fcallback,boxclass);
}

function msgInfo(text,title,fcallback,boxclass){
	msgBox(title,text,'info','OK',fcallback,boxclass);
}

function msgConfirm(text,title,fcallback,boxclass,defval){
	msgBox(title,text,'question','OK,CANCEL',fcallback,boxclass,defval);
}

function msgQuestion(text,title,fcallback,boxclass,defval){
	msgBox(title,text,'question','YES,NO',fcallback,boxclass,defval);
}

function msgDecide(text,title,fcallback,boxclass,defval){
	msgBox(title,text,'question','YES,NO,CANCEL',fcallback,boxclass,defval);
}

function msgPrompt(text,title,fcallback,sz,expl,defval){
	var sz = (sz==null) ? 32 : sz;
	text += ': ' + '<input id="DBOXINPUT_1" type="text" size="'+sz+'" class="fillin"><br>';
	if (expl) text += expl;
	msgBox(title,text,'question','OK,CANCEL',fcallback,'opac',defval);
}

function msgComment(text,title,fcallback,sz,expl,defval){
	var sz = (sz==null) ? 32 : sz;
	text += ':<br>' + '<textarea id="DBOXINPUT_1" rows="5" cols="52" size="'+sz+'"></textarea><br>';
	if (expl) text += expl;
	msgBox(title,text,'question','OK',fcallback,'opac',defval,true);
}

function msgFree(text,title,fcallback,defval){
	msgBox(title,text,'none','close',fcallback,'opac',defval);
}

function msgUpgrade(text){
	text = '<center>'+text+'<br><br>';
	text+= '<input type="button" class="butnbig" value="SUBSCRIBE" onclick="upgrade()" />';
	text+= '<center><br>';
	msgBox('',text,'none','close',null,'opac');
}

function msgNotAvailable(){
	msgBox('','Sorry,this feature is not available.','info','OK');
}

function dispWait(){
	getId('MaskBox').style.display = 'block';
	getId('WaitBox').style.display = 'block';
}

function hideWait(){
	getId('MaskBox').style.display = 'none';
	getId('WaitBox').style.display = 'none';
}

function coverReposit()
{
	var cover = getId('HCover');
 	if (cover && cover.style.display == 'block'){
		cover.style.left = document.body.scrollLeft+'px';
		cover.style.top = document.body.scrollTop+'px';
		if (is.ie){
			cover.style.width = '50px';
			cover.style.width = pageWidth()+'px';
		}
	}
}

window.onscroll = coverReposit;
