function placeFocus() {
	if (document.forms.length > 0) {
		var field = document.forms[0];
		for (i = 0; i < field.length; i++) {
			if ((field.elements[i].type == "text") || (field.elements[i].type == 			"textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
				document.forms[0].elements[i].focus();
				break;
			}
		}
	}
}

function getCookieVal(offset) {
 var endstr = document.cookie.indexOf(";", offset);
 if (endstr == -1) endstr = document.cookie.length;
 return unescape(document.cookie.substring(offset, endstr));
} 

function getCookie(name) {
 var cookie = document.cookie;
 var arg = name + "=";
 var alen = arg.length;
 var clen = cookie.length;
 var i = 0;
 while (i < clen) {
	 var j = i + alen;
 	if (cookie.substring(i, j) == arg)
 	return getCookieVal (j);

 	i = cookie.indexOf(" ", i) + 1;
 	if (i == 0) break; 
 }
 return null;
}


/**
* This is the basic calendar open function for a single calender page
* @param name				: Target object name
* @param calendarURL		: Calendar URL
*/
function openSingleCalendar(name, calendarURL) {

	var monthsToDisplay = 1;
	var defaultSize = 300;

	var width = defaultSize;
	var height = defaultSize;
		
	openMultiCalendar(name, calendarURL, monthsToDisplay, height, width);
}

/**
* This is the detail calendar open function 
* @param name				: Target object name
* @param calendarURL		: Calendar URL
* @param monthsToDisplay   	: Number of months to display
* @param height   			: Windows height
* @param width   			: Windows width
*/

function openMultiCalendar(name, calendarURL, monthsToDisplay, height, width) {

	var target = null;
	var ref = null;

	//check pop-up window size		
	var maxHeight = window.screen.availHeight;
	var maxWidth = window.screen.availWidth;
	
	if(height > maxHeight)
		height = maxHeight;

	if(width > maxWidth)
		width = maxWidth;
		
	
	//check if the specified element is valid
	var element = null;
	var elementName = name;
	var elementFound = false;
	
	var position = name.indexOf('[');
	
	if(position > 0) 
		elementName = name.substring(0,position);
		
	for(i=0;i<document.forms.length && elementFound == false;i++) {
	
		for(j=0;j<document.forms(i).elements.length;j++) {
		
			element = document.forms(i).elements(j);
		
			if(element.name == elementName) {
				
				elementFound = true;
				
				target = document.forms(i).name + "." + name;
				ref = eval("document." + target);
		
		
				if(ref != null) {
					var location = calendarURL + '?field=' + target + '&monthsToDisplay=' + monthsToDisplay + '&specifiedDate=' + ref.value + '&dateNotSelectableBefore=0001-01-01&dateNotSelectableAfter=9999-12-31';
					var opener = window.open(location ,'Calendar','width=' + width +',height=' + height + ',resizable=yes,toolbar=no,location=no,menubar=no,alwaysRaised=yes');
					opener.focus();
				}
		
			 	break;
			}
		
		}
				
		
		


			
	}

}