var showModal=function(h){
    h.w.show();
};var closeModal=function(h){
    h.w.hide();
};function createModal(aIDs,content,p,insertSelector,posSelector,appendsel){
    var clicon=p.imgpath?p.imgpath+'/'+p.closeicon:p.closeicon;var mw=document.createElement('div');jQuery(mw).addClass("modalwin").attr("id",aIDs.themodal);var mh=jQuery('<div id="'+aIDs.modalhead+'"><table width="100%"><tbody><tr><td class="modaltext">'+p.caption+'</td> <td align="right"><a href="javascript:void(0);" class="jqmClose">'+(clicon!=''?'<img src="'+clicon+'" border="0"/>':'X')+'</a></td></tr></tbody></table> </div>').addClass("modalhead");var mc=document.createElement('div');jQuery(mc).addClass("modalcontent").attr("id",aIDs.modalcontent);jQuery(mc).append(content);mw.appendChild(mc);var loading=document.createElement("div");jQuery(loading).addClass("loading").html(p.processData||"");jQuery(mw).prepend(loading);jQuery(mw).prepend(mh);jQuery(mw).addClass("jqmWindow");if(p.drag){
        mf=document.createElement("div");mf=jQuery("<img  class='jqResize' src='"+p.imgpath+"resize.gif'/>");jQuery(mw).append(mf);
    }
    if(appendsel==true) jQuery('body').append(mw);else jQuery(mw).insertBefore(insertSelector);
    if(p.left==0&&p.top==0){
        var pos=[];
        pos=findPos(posSelector);p.left=pos[0]+4;p.top=pos[1]+4;
    }
    if(p.width==0||!p.width)p.width=300;
    if(p.height==0||!p.height)p.height=200;
    if(!p.zIndex)p.zIndex=950;
    size = getClientWidth();
    scrolls = getScrolls();
    if (parseInt(p.left)-scrolls[0] > size[0] - p.width - 30) p.left = size[0] - p.width - 30 + scrolls[0];
    if (parseInt(p.top)-scrolls[1] >30 && parseInt(p.top)-scrolls[1] > size[1] - p.height - 30) p.top = size[1] - p.height - 30 + scrolls[1];
    if (p.top < 0) {p.top = 0;}
    if (p.width != 'auto')  p.width += 'px';if (p.height != 'auto')  p.height += 'px';
    jQuery(mw).css({
        top:p.top+"px",
        left:p.left+"px",
        width:p.width,
        height:p.height,
        zIndex:p.zIndex
        });
    return false;
};function viewModal(selector,o){
    var overlay_val = (navigator.userAgent.toLowerCase().indexOf('konqueror') != -1) ? 0 : 10;
    o=jQuery.extend({
        toTop:true,
        overlay:overlay_val,
        modal:false,
        drag:true,
        onShow:showModal,
        onHide:closeModal
    },o||{});jQuery(selector).jqm(o).jqmShow();return false;
};function DnRModal(modwin,handler){
    jQuery(handler).css('cursor','move');
    jQuery(modwin).jqDrag(handler).jqResize(".jqResize");
    return false;
};
function findPos(obj){
    var curleft=curtop=0;if(obj.offsetParent){
        do{
            curleft+=obj.offsetLeft;
            curtop+=obj.offsetTop;
        }while(obj=obj.offsetParent);
    }
    //alert(document.getElementsById('div_dsbl_content'));
    if(document.getElementById('div_dsbl_content') && document.getElementById('div_dsbl_content').scrollTop) {
      var addtoscroll = document.getElementById('div_dsbl_content');
      curtop-=addtoscroll.scrollTop;
    }
    return[curleft,curtop];
};
function isArray(obj){
    if(obj.constructor.toString().indexOf("Array")==-1)
        return false;else
        return true;
};

function getClientWidth() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth, myHeight]; 
}

function getScrolls() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}
function normalizeWindowHeight(obj) {
  var win_size = getClientWidth();
  var win = jQuery('#' + obj)[0];
  if (typeof( win.innerHeight) == 'number') {
    myHeight = win.innerHeight;
  } 
  else if (win.clientHeight) {
    myHeight = win.clientHeight;
  }
  else {
    myHeight = win_size[1];
  }	
  if (myHeight > 0.90 * win_size[1]) {
    jQuery('#' + obj).css({height:parseInt(0.90 * win_size[1])+'px'});
  }
  var scrolls = getScrolls();
  jQuery('#' + obj).css({top: (scrolls[1] + 40) + 'px'});
}

function centerWindowHeight(obj, offset) {
  var win_size = getClientWidth();
  var win = jQuery('#' + obj)[0];
  if (typeof( win.innerHeight) == 'number') {
    myHeight = win.innerHeight;
  } 
  else if (win.clientHeight) {
    myHeight = win.clientHeight;
  }
  else {
    myHeight = win_size[1];
  }	
  var scrolls = getScrolls();
  jQuery('#' + obj).css({top: parseInt(scrolls[1] + offset + (win_size[1] - myHeight)/2) + 'px'});
}
function setPositionWindow(obj, vert, goriz, offset){
  var win = jQuery('#' + obj);
  var scrolls = getScrolls();
  if (vert) {
    win.css({left: f_clientWidth()/2-win[0].offsetWidth/2});
  }
  if (goriz) {
    win.css({top: f_clientHeight()/2-win[0].offsetHeight/2 + scrolls[1]});
  }
}
function f_clientHeight()
{
	return f_filterResults
	(
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}

function f_clientWidth()
{
	return f_filterResults
	(
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}

function f_filterResults(n_win, n_docel, n_body)
{
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		{n_result = n_docel;}
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
