
//see jsutil.py for generation of verifier Array and verifier funcs

function print_page()
{
	pl= document.getElementById('print_lnk')
	if (pl)
	{
		pl.style.display='none'
	}
	window.print()
	window.close()
}
function verifyform()
{
	if (typeof(verifiers)=="undefined")
	{
		return true
	}
	ok=true
	var errmsg=''
	for (var i=0; i < verifiers.length; i++)
	{
		verifier=verifiers[i]
		elem=document.getElementById(verifier.id)
		valid=verifier.call(elem)
		if (!valid)
		{
			errmsg=errmsg+verifier.errmsg+'<br/>'
			ok=false
		}
		
	}
	if (ok)
	{
		return true
	}
	emdiv=document.getElementById('errormsg')
	if (emdiv) {
		emdiv.innerHTML=errmsg
	}
	return false	
}

function getformvalues(formid)
{
	ff = document.getElementById(formid);
	if (!ff)
	{
		alert ('No such form')
		return {}
	}
	args= {}
	for (x in ff.elements)
	{
		args[ff.elements[x].name]=ff.elements[x].value
	}
	return args
}

function create_hidden(key, value) {
	kk=document.createElement('input')
	kk.setAttribute('name', key)
	kk.setAttribute('value', value)
	kk.setAttribute('type', 'hidden')
	return kk;
}
function submitform(formid, args) 
{
	ff = document.getElementById(formid);
	if (!verifyform(ff)) {
		return
	}
	for (key in args) {
		ff.appendChild(create_hidden(key, args[key]))
	}
	ff.submit()
}
//without verification
function submitform2(formid, args)
{
	ff = document.getElementById(formid);
	for (key in args) {
		kk = document.createElement('input')
		kk.setAttribute('name', key)
		kk.setAttribute('value', args[key])
		kk.setAttribute('type', 'hidden')
		ff.appendChild(kk)
	}
	ff.submit()
}

function popup_img(image_uri, w, h)
{
	specs=''
	/*center window*/
	ypos= screen.height/2- h/2
	if (ypos<0)
	{
		ypos=0
	}
	xpos=screen.width/2- w/2
	if (xpos<0)
	{
		xpos=0
	}
	specs=specs+'width='+(w*15/14)+',height='+(h*15/14)+',left='+xpos+',top='+ypos
	window.open(image_uri, '',specs)
}
function popup_form(form_uri, window_name)
{
	specs=''
	/*position window todo*/
	//ypos=screen.height/4
	ypos=0
	xpos=0// screen.width/4
	w=screen.width*8/9
	h=screen.height*6/7
	//specs=specs+'resizable=1,width='+w+',height='+h+',left='+xpos+',top='+ypos
	specs=specs+'resizable=1,width='+w+',left='+xpos+',top='+ypos
	//specs=specs+'channelmode=1'
	return window.open(form_uri, window_name,specs)
}
function popup_gallery(gallery_uri)
{
	specs=''
	ypos=screen.height/2-200
	xpos= screen.width/2-200
	w=500
	h=740
	specs=specs+'width='+w+',height='+h+',left='+xpos+',top='+ypos
	window.open(gallery_uri, '',specs)
}
function popup_help(help_uri)
{
	specs=''
	/*position window in upper right part of screen (1/6 of screen estate)*/
	ypos=0
	xpos= screen.width*2/3 -5
	w=screen.width/3
	h=screen.height/2
	specs=specs+'resizable=1,width='+w+',height='+h+',left='+xpos+',top='+ypos
	window.open(help_uri, '',specs)
}

function popup_print(print_uri)
{
	specs='scrollbars=1,channelmode=1,menubar=1,'
	/*position window in upper right part of screen (1/6 of screen estate)*/
	ypos=0
	xpos= 0
	w=1024
	h=700
	if (screen.width< 1024)
	{
		w=screen.width
	} 
	if (screen.height< 700)
	{
		h=screen.height
	} 
	specs=specs+'width='+w+',height='+h+',left='+xpos+',top='+ypos
	window.open(print_uri, 'print',specs)
}

function popup_calculator(calculator_uri)
{
specs='scrollbars=0,channelmode=0,menubar=0,'
/*position window in upper right part of screen (1/6 of screen estate)*/
ypos=100
xpos=screen.width/2
w=350
h=370
// if (screen.width< 1024)
// 	{
// 		w=screen.width
// 	} 
// if (screen.height< 700)
// 	{
// 		h=screen.height
// 	} 
specs=specs+'width='+w+',height='+h+',left='+xpos+',top='+ypos
window.open(calculator_uri, 'calculator',specs)
}

function popup(uri, window_name, pos, w, h, resizable) {
	if (!w) { w = screen.width/2; }
	if (!h) { h = screen.height/2; }
	var left = 0;
	var top = 0;
	if (pos=='topleft') {
		
	} else if (pos=='topright') {
		left = screen.width - w - 5;
	}
	specs = 'width='+w+',height='+h+',left='+left+',top='+top;
	if (resizable) {
		specs += ',resizable=1, scrollbars=1';
	}
	window.open(uri, window_name, specs);
}
function windowHeight()
{
if( typeof( window.innerHeight ) == 'number' ) {
return window.innerHeight;
} else if(document.documentElement &&
(document.documentElement.clientHeight) ) {
return document.documentElement.clientHeight;
} else if (document.body && (document.body.clientHeight)) {
return document.body.clientHeight;
}
}
function windowWidth()
{
if( typeof( window.innerWidth ) == 'number' ) {
return window.innerWidth;
} else if(document.documentElement &&
(document.documentElement.clientWidth) ) {
return document.documentElement.clientWidth;
} else if (document.body && (document.body.clientWidth)) {
return document.body.clientWidth;
}
}
