﻿/* popbox 
var popWidth  = null;
var popHeight = null;
var popFunc   = null;
function popboxShow(doc, url, modal, retfunc, width, height) {
	popWidth  = width;
	popHeight = height;
	popFunc   = retfunc;
	document.documentElement.style.overflow = 'hidden';
	if (!modal) { document.getElementById('popboxbg').onclick = function() { popboxHide(); }; };
	document.getElementById('popboxcaption').innerHTML = doc.title;
	document.getElementById('popboxframe').src = url;
	updateWnd();			
	document.getElementById('popboxbg').style.display = 'block';
	document.getElementById('popboxwnd').style.display = 'block';
}
function popboxHide(b) {
	document.getElementById('popboxframe').src = "about:blank";
	document.getElementById('popboxbg').style.display = 'none';
	document.getElementById('popboxwnd').style.display = 'none';
	document.documentElement.style.overflow = 'auto';
	if (b == true && popFunc != null) { 
		popFunc(); // postback function
		popFunc = null;
	}
}
function findPos(o) {
	var curleft = curtop = 0;
	if (o.offsetParent) 
	{
		curleft = o.offsetLeft;
		curtop  = o.offsetTop;
		while (o = o.offsetParent) 
		{
			curleft += o.offsetLeft;
			curtop  += o.offsetTop;
		}
	}
	return [curleft,curtop];
}*/

/* code */
function trim(s) {
	return s.replace(/^\s*|\s*$/g,"");
}
function fnFormatCode(o, a) {
	
	//
	
	if (o.value == "XXXXX-XXXXX-XXXXX-XXXXX") { 
		if (a == 1) {
			return; 
		} else { 
			o.value = ""; return; 
		}
	}
	if (o.value == "" && a == 1) { 
		o.value = "XXXXX-XXXXX-XXXXX-XXXXX"; 
		return; 
	}
	
	if (o.value.length != 23) {
	
		o.value = trim(o.value);
		v = o.value.replace(/-/g, "");
		c1 = v.substring( 0,  5);
		c2 = v.substring( 5, 10);
		c3 = v.substring(10, 15);
		c4 = v.substring(15, 20);
	
		o.value = c1;
		if (c1.length == 5) o.value += "-" + c2;
		if (c2.length == 5) o.value += "-" + c3;
		if (c3.length == 5) o.value += "-" + c4;
	}
	
}
/* quiz */
function fnShow(id) {
	document.getElementById(id).style.display='block';
}
function fnHide(id) {
	document.getElementById(id).style.display='none';
}
function fnAnswer(id) {
	document.forms[0].answer.value=id;
	document.forms[0].submit();
}		
function updateWnd() {
	var w = window.innerWidth  || document.body.clientWidth;
	var h = window.innerHeight || document.body.clientHeight;
	/* quiz */
	document.getElementById('mainbg').style.height = Math.max(8,(h-162))+'px';
	document.getElementById('main').style.padding = Math.max(8, Math.min(40,((h-162)/2)-270))+'px 0 0 0';
	document.getElementById('ftbx').style.width = w+'px';
	document.getElementById('ftbx').style.top = (h-38)+'px';
	/* popbox
	var o = document.getElementById('popboxwnd');
	var f = document.getElementById('popboxframe');
	if (!popWidth) { // auto W
		o.style.width  = Math.round(w / 1.23) + 'px';
		o.style.left   = (w / 11) + 'px';
	} else {
		o.style.width  = popWidth + 'px';
		o.style.left   = ((w / 2) - (popWidth / 2)) + 'px';
	}
	if (!popHeight) { // auto H
		o.style.height = Math.round(h / 1.23) + 'px';
		o.style.top    = (h / 11) + 'px';
	} else {
		o.style.height = popHeight + 'px';
		o.style.top    = ((h / 2) - (popHeight / 2)) + 'px';
	}
	f.style.height = (parseInt(o.style.height) - 31) + 'px';	
	*/
}
window.onresize=updateWnd;
