// Copyright (C) 2003 STC, Inc. All rights reserved.

//wrapping escape function
function escapeSpecialSymbol(str)
{
	return escape(str).replace(/\+/g, '%2B');
}

// Create new browser window
function createWindow(url, name, params)
{
    var msgWindow=window.open(url,name,params);
    return msgWindow;
}

// Submit item item in pop-up window to the parent document
function submitFilter(form, value)
{
	opener.document.forms[form.elements["hdnParentForm"].value].elements[form.elements["hdnParentControl"].value].value = value;
	window.close();
}
    
// Show pop-up window
function showSearchWindow(name, hdnParentForm, hdnParentControl)
{
	createWindow(name + '?hdnParentForm=' + hdnParentForm + '&hdnParentControl=' + hdnParentControl, 'Search', 'width=450,height=400,scrollbars=yes,resizable=yes,menubar=no');
}
    
// Show pop-up window with parameters
function showSearchWindowParam(name, hdnParentForm, hdnParentControl, params)
{
	createWindow(name + '?hdnParentForm=' + hdnParentForm + '&hdnParentControl=' + hdnParentControl + '&' + params, 'Search', 'width=450,height=430,scrollbars=yes,resizable=yes,menubar=no');
}

// Initialize context help for web page
function applyHelp(path, context)
{
	window.parent.imshelpcontext = context;
	window.parent.imshelppath = path + "/ContextHelp.aspx";
	document.body.onhelp=showHelp;
}

// Show context help for current web page
function showHelp()
{
	var context=window.parent.imshelpcontext;
	if(context == null)
		context="about.htm";
	msgWindow=window.open(window.parent.imshelppath + "?CoreIMS_HelpContext=" + context, "Help", "resizable=yes");
	msgWindow.focus();
	return false;
}

// Check of date entered in DatePicker control is valid	
function isDateValid(strDate) 
{
	var arrDate = new Object();
	var j = 0;
	while (strDate.indexOf("/") != -1) 
	{
		var i = strDate.indexOf("/");
		arrDate[j] = parseInt(strDate.substring(0, i));
		strDate = strDate.substring(i+1, strDate.length);
		j ++
	}
	arrDate[j] = parseInt(strDate);
	if (isNaN(arrDate[0]) || isNaN(arrDate[1]) || isNaN(arrDate[2])) 
	{
		return(false)
	}
	if (arrDate[0] > 12 || arrDate[0] < 1) 
	{
		return(false)
	}
	if (arrDate[1] > 31 || arrDate[1] < 1) 
	{
		return(false)
	}
	if (arrDate[2] < 1999) 
	{
		return(false)
	}		
	return(true)
}	

// Dublicate String.Trim() function
function trim(str)
{
	var rezult, i, j;
	for (i=0; i<str.length; i++)
	{
		if (str.substring(i, i + 1)!= ' ')
			break;
	}
	if (i != str.length)
	{
		for (j = str.length-1; j != 0; j--)
		{
			if(str.substring(j, j + 1) != ' ')
				break
		}
		return str.substring(i, j + 1)
	}
	else	
		return ""
}
