document.window_open=function(el)
{
	var a=getPageSize();//	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight,xScroll,yScroll) 
	var w=parseInt(el.style.width),h=parseInt(el.style.height);h=h?h:0;
	var sx=document.body.scrollLeft,sy=document.body.scrollTop;
	el.style.position='absolute';
	el.style.left=((((a[2]-w)/2))+sx)+'px';	el.style.top=((((a[3]-h)/3))+sy)+'px';
	el.style.display='block';
	return false;
}
	
var dlg;
document.showdialog=function(_title,_url,_formname,_target_div)
{
			document.getElementById('dlgdiv2').innerHTML='';
			dlg = new Ext.BasicDialog(document.getElementById('dlgdiv2'), {
				width:700,height:500,
				title: _title,
				modal: true,
				shadow: true
			});
			document.dlg=dlg;

			dlg.save=function()
			{
				if(document.getElementById('kb_select_id'))
				{
					if(document.getElementById('kb_select_id').value.length) FCKeditorAPI.GetInstance('txtReply').InsertHtml('<a href=\"'+document.getElementById('kb_select_url').value+'&id='+document.getElementById('kb_select_id').value+'\">'+document.getElementById('kb_select_txt').value+'</a>','txtReply');
				}
				else if(document.getElementById('dl_select_id')) 
				{
					if(document.getElementById('dl_select_id').value.length) FCKeditorAPI.GetInstance('txtReply').InsertHtml('<a href=\"'+document.getElementById('dl_select_url').value+'&id='+document.getElementById('dl_select_id').value+'\">'+document.getElementById('dl_select_txt').value+'</a>','txtReply');
				}
				else
				{
					if(_formname.length>0) 
						if(_target_div.length>0) 
							sa(document.forms[_formname],_target_div);
						else 
							sa(document.forms[_formname],function(){});
				}
				dlg.hide();
			};
			//dlg.addKeyListener(27, dlg.hide, dlg); // ESC can also close the dialog
			dlg.addButton('OK', dlg.save, dlg);    
			dlg.addButton('Cancel', dlg.hide, dlg);
			dlg.body.load({
					url: _url,
					method:"get",
					scripts:true,
					text: "Loading form..."
			   });
			dlg.show();
		}



function elem(n)
{
	return document.getElementById(n);
}

/* removes leading and trailing spaces from the string */ 
function trim(s) {
    return s.replace(/(^\s+)|(\s+$)/g, "") }

/* function that computes the mouse's coordinates in page */ 
function getMouseXY(e) {
  // browser specific
  if(window.ActiveXObject)
  {
    return new Array(window.event.x + document.body.scrollLeft, window.event.y + document.body.scrollTop);   
  }
  else
  {
    return new Array(e.pageX,e.pageY);
  }
}



function doQuote(r){
	r=">>"+r;
	
	r=r.replace(/\n/ig,'\n>>');
	document.getElementById('txtReply').value=r+'\n\n';
	document.getElementById('txtReply').focus();
}





function getScrollXY() {
  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 findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}


// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollX;
		yScroll = window.innerHeight + window.scrollY;
		//alert(window.scrollMaxY);
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	


	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight,xScroll,yScroll) 
	return arrayPageSize;
}

// -----------------------------------------------------------------------------------

//
// getKey(key)
// Gets keycode. If 'x' is pressed then it hides the lightbox.
//
function getKey(e){
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	key = String.fromCharCode(keycode).toLowerCase();
	
	if(key == 'x'){
	}
}

// -----------------------------------------------------------------------------------

//
// listenKey()
//
function listenKey () {	document.onkeypress = getKey; }
	

//function parses mysql datetime string and returns javascript Date object
//input has to be in this format: 2007-06-05 15:26:02
function mysqlTimeStampToDate(timestamp) {
	var regex=/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
	var parts=timestamp.replace(regex,"$1 $2 $3 $4 $5 $6").split(' ');
	return new Date(parts[0],parts[1],parts[2],parts[3],parts[4],parts[5]);
}

if(elem('ajax_loader')){
	elem('ajax_loader').style.left=getPageSize()[2]/2-32;
	elem('ajax_loader').style.top=getPageSize()[3]/2-32 + getScrollXY()[1];
}


////////////////////////////////////////////////////////

function strfind(s,what){
return(s.indexOf(what)>=0 ? true : false);
}

function getParentBk(x){
var el=x.parentNode,c;

while(el.tagName.toUpperCase()!="HTML" && (c=getBk(el))=="transparent")
    el=el.parentNode;
if(c=="transparent") c="#FFFFFF";
return(c);
}

function getBk(x){
var c=getStyleProp(x,"backgroundColor");

if(c==null || c=="transparent" || strfind(c,"rgba(0, 0, 0, 0)"))
    return("transparent");
return(c);
}
function getStyleProp(x,prop){
if(x.currentStyle)
    return(x.currentStyle[prop]);
if(document.defaultView.getComputedStyle)
    return(document.defaultView.getComputedStyle(x,'')[prop]);
return(null);
}


function Corners(el){
	el=document.getElementById(el);
	var b=document.createElement("b");
	b.className='roundrectwrapper';
	b.style.backgroundColor=getParentBk(el);
	
	for(f=1;f<5;f++){
		var b0=document.createElement("b");
		b0.className='rr'+f;
		b0.style.backgroundColor=getBk(el);
		b.appendChild(b0);
	}
	el.insertBefore(b,el.firstChild);
	var b=document.createElement("b");
	b.className='roundrectwrapper';
	b.style.backgroundColor=getParentBk(el);
	for(f=4;f>0;f--){
		var b0=document.createElement("b");
		b0.className='rr'+f;
		b0.style.backgroundColor=getBk(el);
		b.appendChild(b0);
	}
	el.appendChild(b);
}

//re-position _gl_def divs
re_position=function(e){
	if(e) {
		x=findPos(e)[0];
		if(x+e.offsetWidth>getPageSize()[2]) {
			e.style.left=getPageSize()[2]-30-e.offsetWidth+'px';
		}
	}
}

////////////////////////////////////////////////////////
