//---------------------------------------------------
//    Title: dialog javascripts
//
//    Copyright 2003 Khoosystems Ltd - all rights reserved
//    
//    History:
//	  24/02/03: Release	
//	  02/10/03: Added render_text to foreColor()
//	  06/05/06: Added getMouseClick
//----------------------------------------------------
//
// click button to submit a form only once - needs a hidden field refered to by fld to be set

function SubmitOnce(me,fld){
	me.value='Please wait...'
	me.disabled=true
	fld.value=1
	me.form.submit()
	return true
}
function getMouseEvent(e) {
	e = e || window.event;
	var cursor = {x:0, y:0};
	if (e.pageX || e.pageY) {	// not ie!
		cursor.x = e.pageX;
		cursor.y = e.pageY;
		if (e.offsetX || e.offsetY) {	// safari
			cursor.x -= e.offsetX;
			cursor.y -= e.offsetY;
		}
	} else {
		cursor.x =e.clientX + 
				(document.documentElement.scrollLeft || document.body.scrollLeft) - 
				(document.documentElement.clientLeft || document.body.clientLeft);
		cursor.y = e.clientY + 
				(document.documentElement.scrollTop || document.body.scrollTop) - 
				(document.documentElement.clientTop || document.body.clientTop);
	}     	
	
	var sc = new Array();
	sc['cursorX']=cursor.x
	sc['cursorY']=cursor.y
	
	sc['clientX']=e.clientX
	sc['clientY']=e.clientY
	
	sc['layerX']=e.layerX
	sc['layerY']=e.layerY
	
	sc['offsetX']=e.offsetX
	sc['offsetY']=e.offsetY
	
	sc['pageX']=e.pageX
	sc['pageY']=e.pageY
	
	sc['screenX']=e.screenX
	sc['screenY']=e.screenY
	
	sc['clientHeight']=document.body.clientHeight
	sc['clientWidth']=document.body.clientWidth
	
	return sc;
}
function OpenWindow(url,win,w,h) {
	openWin = window.open(url,'win',"width="+w+",height="+h+",resizable=yes,scrollbars=yes")
	openWin.focus()
}


// show library image dialog. fld is the form.field name of field to update 
// field is also the name of the directory of images
function libImageDlg(dir,fld,ncols){
	var sfld = eval('document.'+fld)
	var url = escape(escape("/pop_dialog/sel_lib_img.htm?dir="+dir+"&ncols="+ncols))	// need to double escape !!
	libimgwin = launchCenter("/pop_frame/index.htm?modal=1&title=Library%20Images&url="+url,'libimgwin',400,500,'resizable=yes,scrollbars=yes,')
	libimgwin.libfld = sfld		// set ref to our library field on dialog window
}

// show preview template window
function previewTemplate1(template){
	var url = '/urlpre_template='+template+'%26use_select=1/'
	libimgwin = launchCenter("/pop_frame/index.htm?modal=1&title=Preview%20Template&url="+url,'libimgwin',700,800,'resizable=yes,scrollbars=yes,')
}

// show preview template window
function previewTemplate(template_id,preset_cat_id){
	libimgwin = launchCenter("/pop_frame/template/index.htm?template_id="+template_id+"&preset_cat_id="+preset_cat_id,'libimgwin',700,900,'resizable=yes,scrollbars=yes,')
}

function launchCenter(url, name, height, width, str) {
	str += "height=" + height + ",innerHeight=" + height;
	str += ",width=" + width + ",innerWidth=" + width;
	if (window.screen) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;
		
		var xc = (aw - width) / 2;
		var yc = (ah - height) / 2;
		
		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
	}
	return window.open(url, name, str);
//	win.focus()
//	return win
}

function print_window() {
	if (window.location.pathname.substr(1,6) !='urlpre' && window.location.search.substr(6,6) !='urlpre') {
		if (window.location.search.substr(1,4)=='url=') {
			var url = window.location.protocol+'//'+window.location.host+'/index.php?url=/urlpre_template=content/'+window.location.search.substr(5)
		} else {
			var url = window.location.protocol+'//'+window.location.host+'/urlpre_template=content'+window.location.pathname+window.location.search
		}
		print_win = launchCenter(url,'Print_Window','600','800','resizable=yes,scrollbars=yes,')
		print_win.print()
	} else {
		window.print()		// on the urlpre window
	}
}


