//<!--
//JavaScript Library -------------------------------------------------------

	function requiredField(field) {
		if (IsOK) {
			if (field) {
				if (field.value == "")  {
					errorMess(field, message[0]);
				}
			}
		}
	}

	/*
	function forbiddenField(field) {
		if (IsOK) {
			if (field) {
				if (field.value != "")  {
					errorMess(field, message[0]);
				}
			}
		}
	}
	*/

	function setField(field, set_val) {
		if (IsOK) {
			if (field) {
				if (field.value) {
					field.value = set_val;
				}
			}
		}
	}

	function checkInteger(field) {
		if (IsOK) {
			if (field) {
				if(!integerChars(field.value)) {
					errorMess(field, message[1]);
				}
			}
		}		
	}

	function checkDecimal(field) {
		if (IsOK) {
			if (field) {
				if(!decimalChars(field.value)) {
					errorMess(field, message[2]);
				}
			}
		}		
	}

	function checkDate(field) {
		if (IsOK) {
			if (field) {
				if (field.value != '') {
					if(!getDate(field, navigatorName())) {
						errorMess(field, message[3]);
					}
				}
			}
		}		
	}

	function checkTwoDatesRange(field, field2) {
		if (IsOK) {
			if (field && field2) {
				dateFrom = getDate(field, navigatorName());
				dateTo = getDate(field2, navigatorName());
				if(dateFrom > dateTo) {
					errorMess(field2, message[5]);
				}
			}
		}		
	}

	function checkEmail(field) {
		if (IsOK) {
			if (field.value) {
				if (window.RegExp) {
		    	// Rules for the email regular expression:
		    	//  The start of the email must have at least one character before the @ sign
		    	//  There may be either a . or a -, but not together before the @ sign
		    	//  There must be an @ sign
		    	//  At least once character must follow the @ sign
		    	//  There may be either a . or a -, but not together in the address
		    	//  The address must end with a . followed by at least 2 characters
		    	var re;
		    	re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
		    
					if (re.test(field.value) == false) {
						errorMess(field, message[6]);
					}
				}
			}
		}
	}

	function checkHexColor(field, length) {
		if (IsOK) {
			if (field) {
				if(!hexChars(field.value)) {
					errorMess(field, message[4]);
				}
				else if (field.value.length != length) {
					errorMess(field, message[4]);
				}
			}
		}
	}

	function hexChars(value) {
		var good_chars = "0123456789abcdefABCDEF";
		return checkGoodChars(good_chars, value);
	}

	function integerChars(value) {
		var good_chars = "-0123456789";
		return checkGoodChars(good_chars, value);
	}

	function decimalChars(value) {
		var good_chars = ".0123456789";
		var dot_check = (value.indexOf('.') == value.lastIndexOf('.'));
		return (checkGoodChars(good_chars, value) && dot_check);
	}

	function checkGoodChars(chars, value) {
		if (value != "") {
			var len = value.length;
			for (i = 0; i < len; i++) {
				if (chars.indexOf(value.charAt(i)) == -1) {
					return false;
				}
			}
		}
		return true;
	}

	function checkCheckboxList (frm, start, mess) {
		if (IsOK) {
			if (!checkboxList(frm, start)) {
				errorMess(false, message[mess]);
			}
		}
	}

	function errorMess(field, mess) {
		var id;
		var labelTag;
		IsOK = false;

		//focus
		if (field) {
			field.focus();
		}
		//select text
		if (field.type) {
			if (field.type == 'text') {
				field.select();
			}
		}
		//label
		if (field.id != '') {
			id = field.id;
		}
		else {
			id = field.name;
		}
		if (document.getElementById) {
			id = 'l.' + id;
			labelTag = document.getElementById(id);
			if (labelTag) {
				if (labelTag.innerHTML) {
					mess = '[' + labelTag.innerHTML + ']  ' + mess;
				}
			}
		}
		alert(mess);
	}

	function checkboxList(frm, start_index) {
		//at least one checkbox has to be checked
		var end_index = start_index + parseInt(frm.elements.value) - 1;
		var checked = false;
		for (i = start_index; i <= end_index; i++) {
			if (frm[i].checked) {
				checked = true;
				break;
			}
		}
		return checked;
	}

	function selectedValue(field) {
		if (field) {
			if (field.options) {
				return field.options[field.selectedIndex].value;
			}
		}
	}

	//*********** Date check - return js Date object on True *************
	function getDate(field, navName) 
	{
		var j = 0;
   
		CheckedDate = field.value;
		
		//Length check - between 4 and 10 is right
		if ((CheckedDate.length > 10) || (CheckedDate.length < 4)) 
		{
			return false;
		}
   
		//Separators check - EUR two dots is ok
		var separator = ".";
      
		for (var i = 0; i < CheckedDate.length; i++) 
		{
			if (CheckedDate.substring(i, i + 1) == separator) 
			{
				j++;
				if (j == 1)  pos1 = i;
				if (j == 2)  pos2 = i;
			}
		}
             
		if (j != 2) 
		{
			return false;
		}
	    
		//** Date Format Validity **
		Day = CheckedDate.substring(0, pos1);
		Month = CheckedDate.substring(pos1 + 1, pos2);
		Year = CheckedDate.substring(pos2 + 1, CheckedDate.length);
	 
		if (Year.length != 4) 
		{
			//fill current year if missing
			CurrentDate = new Date();
			Year = Math.abs(CurrentDate.getYear());
			if (Year < 200)
			{
				Year = Year + 1900 + "";
			}
			field.value = CheckedDate + Year;

			//return false;
		}

		//with zero start octal numbers !
		if (Month.substring(0, 1) == "0" && Month.length == 2)  
		{
			Month = Month.substring(1, 2);
		}
		if (Day.substring(0, 1) == "0" && Day.length == 2)
		{
			Day = Day.substring(1, 2);
		}

		CompDate = new Date(Year,Month - 1,Day);

		if ((Year.substring(0,2) == "19") || (navName == "netscape")) 
		{  
			CompYear = (Math.abs(CompDate.getYear())) + 1900;
		} 
    else 
		{ 
			CompYear = Math.abs(CompDate.getYear());
		}
      
		//Isn't date
		if ((CompYear != parseInt(Year)) || (CompDate.getMonth()+1) != parseInt(Month) || (CompDate.getDate() != parseInt(Day))) 
		{
			return false;
		}

		return CompDate;
	}

	//browser check ------------
	function navigatorName() { 
		if ((navigator.appName.toLowerCase().indexOf("netscape") != "-1") 
				|| (navigator.userAgent.toLowerCase().indexOf("opera") != "-1")) {
			navName = "netscape";
		}
		else {  
			navName = "explorer";
		}
		return navName;
	}

	//Print page ---------------
	function doPrint() {
		var Name = navigatorName();
		var ver = navigator.appVersion;
		var mess = "You have old version of WWW client. Please use print function from browser."; 

		if (Name =="netscape" && parseInt(ver) < 4)  alert(mess);
		else if (Name =="explorer" && ver.charAt(ver.indexOf('MSIE')+5) < 5)  alert(mess);
		else window.print(); 
	}

	//PopUp Window ---------------
	function popUp(href, width, height) {
		var newWin = window.open(href, 'popup', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0,width='+ width +',height='+ height, true);
		newWin = window.open(href, 'popup');	//REDUNDANT CALL TO FIX MAC BUG
	}

//-->

