
var win = null;
var elementName = ""

function openWindowOH(name)
{
	elementName = name
	win = window.open("", "", "title=1, width=350, height=170");

	// Create document
	win.document.write('<html>');
	win.document.write('<title>Carnet - Varebeskrivelse</title>');
	win.document.write('<head>');
	win.document.write('</head>');

	win.document.write('<body style="background-color:#EEEEEE">');

	win.document.write('<script type="text/javascript">');
	win.document.write('function allowInput(el, maxLength)');
	win.document.write('{');
	win.document.write('	if(el.value.length >= maxLength)');
	win.document.write('	{');
	win.document.write('		el.value = el.value.substring(0,maxLength-1);');
	win.document.write('		alert(\'Makslengde er \' + maxLength);');
	win.document.write('		return false;');
	win.document.write('	}');
	win.document.write('	var num=document.getElementById(\'numChars\');if(num) num.innerHTML=parseInt(el.value.length+1);');
	win.document.write('	return true;');
	win.document.write('}');
	win.document.write('</script>');

	win.document.write('<div>');
	win.document.write('<form>');
	win.document.write('<div style="font-weight:bold;color:red;font-size:11px;font-family:Arial;"><div style="float:left;">Maks lengde er 199. Antall tegn er&nbsp;</div><div style="float:left" id="numChars">0</div></div>');
	win.document.write('<div style="clear:left;">');
	win.document.write('<table>');
	win.document.write('<tr>');
	win.document.write('<td>');
	win.document.write('<textarea cols="30" rows="7" id="DescText" size="2" value="" maxlength="199" onkeypress="return allowInput(this, 199);"></textarea>');
	win.document.write('</td>');
	win.document.write('<td style="vertical-align:top">');
	win.document.write('<div>');
	win.document.write('<input type="button" name="Ok" value="Ok"" style="width:60px">');
	win.document.write('</div><div>');
	win.document.write('<input type="button" name="Cancel" value="Cancel"" style="width:60px">');
	win.document.write('</div>');
	win.document.write('</td>');
	win.document.write('</tr>');
	win.document.write('</table>');
	win.document.write('</div>');
	win.document.write('</form>');
	win.document.write('</div>');
	win.document.write('</body>');
	win.document.write('</html>');


	win.document.forms[0].Ok.onclick = closeWindowOH;
	win.document.forms[0].Cancel.onclick = closeWindowCancelOH;
	//win.document.forms[0].DescText.value = document.forms[0].DescText.value;
	win.document.forms[0].DescText.value = document.getElementById(name).value.replace('\t', '\n');
	
	var numLength = win.document.getElementById('numChars');
	if(numLength) numLength.innerHTML = parseInt(document.getElementById(name).value.length);
}

function closeWindowCancelOH()
{
	win.close();
}

function closeWindowOH()
{
	//document.forms[0].DescText.value = win.document.forms[0].DescText.value + ' CLOSED!';
	document.getElementById(elementName).value = win.document.getElementById("DescText").value.replace('\n', '\t').substring(0,199-1);
	win.close();
}

function setHelpText(event, elementId, HelpText)
{
	var el=document.getElementById(elementId);
	//el.style.top=parseInt(offsetTop+10)+'px';
	el.innerHTML=HelpText; 
	//el.style.visibility='visible';
	//el.style.display='block';
}

function hideHelpText(event, elementId)
{
	var el=document.getElementById(elementId);
	el.innerHTML='';
	//el.style.visibility='hidden';
	//el.style.display='none';
}


