/***  variables  ***/
var dafaultPage = 'main.aspx';

/*****************************************/
/****  execute function on key press  ****/
/*****************************************/
function onPressKey(keyCode,myFunc){
	// use this function for execute desired 
	// function with key press
	keyCodes[keyCodes.length] = keyCode;
	myFuncs[myFuncs.length] = myFunc;
}

if (document.layers){
	document.captureEvents(Event.KEYPRESS)
}
function pressed(e){
	for (var i=0; i<keyCodes.length; i++){
		if (document.layers){
			if (e.which==keyCodes[i]){
				eval(myFuncs[i]);
			}
		}else{ 
			if (document.all){
				if (event.keyCode==keyCodes[i]){
					eval(myFuncs[i]);
				}
			}
		}
	}
}
var myFuncs = new Array();
var keyCodes = new Array();
document.onkeypress=pressed;

/***********************************************/
/*************   move menu  ********************/
/***********************************************/

function shiftMenu(){
	if (document.move_DIV){
		document.MenuInit();
		document.move_DIV();
	}
	if (parent && parent.move_DIV){
		parent.MenuInit();
		parent.move_DIV();
	}
}
shiftMenu()

/***********************************************/
/*************   Preloading images   ***********/
/***********************************************/


/*
var blankImage = 'http://localhost/Inform/images/samples/blank.gif';
//var currentImage = 'http://localhost/Inform/images/samples/560a.gif';

var tmpImageElement,tmpBlankImageUrl;
function noImage(){
	//imageElement.src = blankImageUrl
}
function imageExists(){
	//imageElement.src = imageUrl
}

function testImage(imageElement, imageUrl, blankImageUrl) {
	if (blankImageUrl == null) {
		blankImageUrl = blankImage; 
	}
	var tester = new Image();
	tester.onload = imageExists;
	tester.onerror = noImage;
	tester.src = imageUrl;
}
function testImageById(imageElementId, imageUrl, blankImageUrl) {
	if (document.getElementById && document.getElementById(imageElementId)) {
		testImage(document.getElementById(imageElementId), imageUrl, blankImageUrl)
	}
}
function tiById(imageElementId) {
	if (document.getElementById && document.getElementById(imageElementId)) {
		ti(document.getElementById(imageElementId))
	}
}
function ge(elementId){
	return document.getElementById(elementId)
}
function ti(fName) {
	var iTester = new Image();
	iTester.onerror = eval('e_' + fName);
	iTester.src = eval('s_' + fName + '()');;
}

//var sample = document.images.sample;
//testImage(id,url1)
*/
/************************************************/
/**** function for open new browser window  *****/
/************************************************/
function openWin(myurl, width, height, windowName){
	// open new window with url - for help, mesages, etc
	window1 = window.open(myurl, windowName,"width="+width+",height="+height+",resizable=1,status=1,menubar=0,scrollbars=1");
	window1.focus();
}
function openFullWin(myurl){
	// open new window with url - for help, mesages, etc
	window2 = window.open(myurl);
	window2.focus();
}
// webbot stopper: send email with click
function mpost(sendName,sendAt){ 
	openFullWin('mailto:' + sendName + '@' + sendAt)
}
// webbot stopper: write email on page (usage: "<script>post(sendName, sendDomain [,showName or text][, showDomain])</script>")
function post(sendName,sendAt,showName,showAt,newWindow){ 
	if (showName ==null){showName=sendName;showAt=sendAt};
	sendName='mailto:'+sendName;
	if (showAt!=null){showAt='@'+showAt}else{showAt=''}; 
	document.write('<a href="' + sendName + '@' + sendAt + '">' + showName + showAt + '</a>');
}

/************************************************/
/***** add XP style to images as buttons ********/
/************************************************/
function selOn(ctrl) {//on mouse over
	if (ctrl.disable != true) {
		ctrl.style.borderColor = '#E0E0E0';
		ctrl.style.borderStyle = 'outset';
		ctrl.style.backgroundColor = '#B0C4DE';
		ctrl.style.cursor = 'hand';	
	}
}

function selOff(ctrl) {//on mouse out
	if (ctrl.disable != true) {
		ctrl.style.borderStyle = 'solid';
		ctrl.style.borderColor = '#D0D0D0';  
		ctrl.style.backgroundColor = '#E0E0E0';
	}
}

function selDown(ctrl) {//on click
	if (ctrl.disable != true) {
		ctrl.style.borderStyle = 'inset';
		ctrl.style.backgroundColor = '#4682B4';
		ctrl.style.borderColor = '#E0E0E0';
	}
}

function selUp(ctrl) {
	if (ctrl.disable != true) {
		ctrl.style.borderStyle = 'outset';
		ctrl.style.borderColor = '#D0D0D0';  
		ctrl.style.backgroundColor = '#E0E0E0';
		ctrl.style.backgroundColor = '#B0C4DE';
	}
}

function DisableOn(ctrl) {
	ctrl.style.borderColor = '#B0B0B0';  
	ctrl.style.backgroundColor = '#C0C0C0';
	ctrl.style.cursor = 'default';	
	ctrl.disable = true
	ctrl.style.borderStyle = 'solid';
}

function DisableOff(ctrl) {
	ctrl.disable = false
	ctrl.style.borderColor = '#D0D0D0';  
	ctrl.style.backgroundColor = '#E0E0E0';
	ctrl.style.cursor = 'hand';
	ctrl.style.borderStyle = 'solid';
	
}


/********* end: xp style ********************/


function setProp(Id,Prop,Value) {
	//functon changes properties attribute for element
	var objE = document.getElementById(Id);
	for(j = 0; j < objE.attributes.length; j++){
		if (objE.attributes(j).name == Prop) {
			objE.attributes(j).value = Value;
		}
	}
}	

var workWin;
function workWindow(myurl, windowTitle, width, height){
	// function open new browser window - if possible uses existing browser window and reduce client time for creating new window
	var defaultWidth = 500;
	var defaultHeight = 450;
	var defaultWindowTitle = 'Inform';

	if (parseInt(width)=='NaN'){width=defaultWidth}
	if (parseInt(height)=='NaN'){height=defaultHeight}
	if (windowTitle == 'undefined'){windowTitle=defaultWindowTitle}

	workWin = window.open(myurl, windowTitle ,"width=" + width + ",height=" + height + ",resizable=1,status=1,menubar=0,scrollbars=1");
}

// 'replacement' for missing maxLenght property in textarea 
function checkLen(maxLength,element) {
	var maxLen = new Number;

	maxLength = maxLength - 3;
	maxLen = maxLength;

	// SQLSERVER BUG? nvarchar 4000 - update 
	if (maxLen >= 2000) {
		maxLen = 1999
	}


	// check returns (
	var returnCount = 0;
	var i = 0;
	/*
	while(i<=element.value.length) {
		if (element.value.substring(i,i+1) == "\n") {
			returnCount++;
		}
		i++;
	}
	*/
	if (element.value.length+returnCount >= maxLen) {
		element.value=element.value.substring(0,maxLen-returnCount)
	}
	//alert(element.value.length + '\n' +  returnCount + '\n' + maxLen)
}

// focus and reload opener window and close active window
function back(){
	if (window.opener){
		window.opener.location.reload();
		window.opener.focus();
	}else{
		if (window.parent){
			if (window.parent.frames['main'] && queryString){
				window.parent.frames['main'].location='edoc.aspx?' + queryString;
			}		
		}
	}
	window.close();
}

// print current page in new window
function printPage(){
	var loc = document.location.href;
	loc = addVariable(loc,'showMenu','0')
	loc = addVariable(loc,'doPrint','1')
	workWindow(loc,'Print');
}
// add variable to url 
function addVariable(url,variable,value){
	if (url.substring(url.length-1,url.length) == '/'){
		url = url + dafaultPage;
	}
	if (url.indexOf('?') > 0 ){
		url += '&';
	}else{
		url += '?';
	};
	url += variable + '=' + value;
	return url;
} 
function redirect(URL,noHistory,alsoParent){
	if (!parent){alsoParent=false};
	if (!location.replace){noHistory=false};
	if (noHistory){if (alsoParent){parent.document.location.replace(URL)}else{document.location.replace(URL)}};
	if (alsoParent){parent.document.location = URL;}else{document.location = URL};
}
// function check if (within textarea) tab key is pressed
// then add tab character to text rather than set focus to next html element. 
// Usage: add attribute onkeydown=checkTab() to textarea element.
function checkTab(elementID) {
	if (document.getElementById){
		if (document.getElementById(elementID)){
			element=document.getElementById(elementID);
			if ((9==event.keyCode) && (event.ctrlKey)) {
				element.selection = document.selection.createRange(); 
				element.selection.text=String.fromCharCode(9);
				setTimeout('element.focus()',0);
			}
		}
	}
}
function setFocus(elementID){
	if (document.getElementById){
		if (document.getElementById(elementID)){
			element=document.getElementById(elementID);
			element.focus();
			setCaretToEnd(element)
		}
	}
}
function setCaretToEnd (el) {
 if (el.createTextRange) {
   var v = el.value;
   var r = el.createTextRange();
   r.moveStart('character', v.length);
   r.select();
 }
}

// resize iframe and avoid iframe scrollbars (works only on IE? Test it!)
// call wit iframe onload function="window.parent.resizeIframe(this)"
// or
// if (window.parent && window.parent.resizeIframe) {window.parent.resizeIframe(this);}
function resizeIframe(frame, ignoreWidth){
        try{
                innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
                objToResize = (frame.style) ? frame.style : frame;
                objToResize.height = innerDoc.body.scrollHeight + 20;
                if (ignoreWidth!=true){
					//objToResize.width = innerDoc.body.scrollWidth + 20;
				}
        }catch(err){
                window.status = err.message;
        }
        shiftMenu();
}


var chr = 'CTRL-D';
var agt=navigator.userAgent.toLowerCase();
if(agt.indexOf("opera") != -1) chr = 'CTRL-T';
function bookmark(clickText, pressText){
	if (window.external)
	document.write('<a href="javascript:window.external.AddFavorite(self.location,document.title)">'+clickText+'<\/a>');
	else
	document.write(pressText + chr);
}
//**** cookies  ***
function getCookie(NameOfCookie)
{
if (document.cookie.length > 0)
{
begin = document.cookie.indexOf(NameOfCookie+"=");
if (begin != -1)
{
begin += NameOfCookie.length+1;
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end)); }
}
return null;
}


function setCookie(NameOfCookie, value, expiredays)
{
var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
document.cookie = NameOfCookie + "=" + escape(value) +
((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}


function delCookie (NameOfCookie)
{
if (getCookie(NameOfCookie)) {
document.cookie = NameOfCookie + "=" +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}
