function commonvalidate(r,frm){
	//r[x][0] -field name
	//r[x][1] -field form name
	//r[x][2] -length
	//r[x][3] -datatype
	//r[x][4] -nullable
	//r[x][5] -diapason min (for int,float)
	//r[x][6] -diapason max (for int,float)

	var elt=frm.elements
	var i
	for(i=0;i<r.length;i++){
		if(typeof(elt[r[i][0]])!='undefined' || typeof(elt['mm_' + r[i][0]])!='undefined'){
			switch(r[i][3]){
				case 'text_string':
				case 'text_email':
				case 'text_filename':
					val = elt[r[i][0]].value;
					if(val.length==0 && r[i][4]==1){
						alert(r[i][1] + ' cannot be empty');
						elt[r[i][0]].focus();
						return false;
					}
					if(val.length>r[i][2]){
						alert(r[i][1] + ' cannot be more than ' + r[i][2] + ' symbols');
						elt[r[i][0]].focus();
						return false;
					}
					if(r[i][3]=='text_email' && val.length && (val.indexOf('@',1)==-1 || val.indexOf('.',1)==-1)){
						alert('Please enter a valid ' + r[i][1]);
						elt[r[i][0]].focus();
						return false;
					}
					if(r[i][3]=='text_filename' && val.length && (val.indexOf(':',2)!=-1 || val.indexOf('*')!=-1 || val.indexOf('?')!=-1 || val.indexOf('"')!=-1 || val.indexOf('<')!=-1 || val.indexOf('>')!=-1 || val.indexOf('|')!=-1)){
						alert('Please enter a valid ' + r[i][1] + '\nA filename cannot contain any of the following characters: \\ / : * ? " < > | ');
						elt[r[i][0]].focus();
						return false;
					}					
					break;
				case 'select_string':
					val = '';
					if(elt[r[i][0]].options.selectedIndex!=-1) val = elt[r[i][0]].options[elt[r[i][0]].options.selectedIndex].value;
					if(r[i][4]==1 && val==''){
						alert(r[i][1] + ' cannot be empty');
						elt[r[i][0]].focus();
						return false;
					}
					break;
				case 'text_float':
					elt[r[i][0]].value = elt[r[i][0]].value.replace(/,/g,".")
				case 'select_int':
				case 'text_int':
					val = '';
					if(r[i][3]=='select_int' && elt[r[i][0]].options.selectedIndex!=-1) val = elt[r[i][0]].options[elt[r[i][0]].options.selectedIndex].value;
					else if(r[i][3]=='text_int') val = elt[r[i][0]].value;
					
					if(r[i][4]==1 && val==''){
						alert(r[i][1] + ' cannot be empty');
						elt[r[i][0]].focus();
						return false;
					}
					/*start parse string to float*/
					var digval=0;
					if(parseInt(val)>parseInt(val))	digval = parseInt(val);
					else digval = parseFloat(val);
					if(isNaN(digval)) digval=0;
					/*end parse string to float*/
					if(digval!=val){/*not a number*/
						alert(r[i][1] + ' must be a number. \n Value was corrected, please check.');
						elt[r[i][0]].value = digval;
						elt[r[i][0]].focus();
						return false;
					}else{
						if((digval<r[i][5] || digval>r[i][6]) && (r[i][5]!=r[i][6]) ){//not in period
							alert(r[i][1] + ' must be between ' + r[i][5] + ' and ' + r[i][6]);
							elt[r[i][0]].focus();
							return false;
						}
					}
					break;
				case 'date':
					if(typeof(elt[r[i][0]])!='undefined'){ //date in one field
					/* must be done	*/
					}else{ //date separated to three field mm_ dd_ yyyy_
						mm		= elt['mm_' + r[i][0]].options[elt['mm_' + r[i][0]].options.selectedIndex].value;
						dd		= elt['dd_' + r[i][0]].value;
						yyyy	= elt['yyyy_' + r[i][0]].options[elt['yyyy_' + r[i][0]].options.selectedIndex].value;
						if(r[i][4]==1){
							if(mm==''){
								alert('Please choose month for ' + r[i][1]);
								elt['mm_' + r[i][0]].focus();
								return false;
							}else if(dd==''){
								alert('Please choose day for ' + r[i][1]);
								elt['dd_' + r[i][0]].focus();
								return false;
							}else if(yyyy==''){
								alert('Please choose year for ' + r[i][1]);
								elt['yyyy_' + r[i][0]].focus();
								return false;
							}else{}
						}else if((mm=='' && ' '+dd+yyyy!=' ') || (dd=='' && ' '+mm+yyyy!=' ') || (yyyy=='' && ' '+mm+dd!=' ') ){
							alert('Please complete ' + r[i][1]);
							elt['mm_' + r[i][0]].focus();
							return false;
						}
					}
					break;
				case 'datetime':
					if(typeof(elt[r[i][0]])!='undefined'){ //datetime in one field
					/* must be done	*/
					}else{ //date separated to three field mm_ dd_ yyyy_
						mm		= elt['mm_' + r[i][0]].options[elt['mm_' + r[i][0]].options.selectedIndex].value;
						dd		= elt['dd_' + r[i][0]].value;
						yyyy	= elt['yyyy_' + r[i][0]].options[elt['yyyy_' + r[i][0]].options.selectedIndex].value;
						h		= elt['h_' + r[i][0]].value;
						m		= elt['m_' + r[i][0]].value;
						if(r[i][4]==1){
							if(mm==''){
								alert('Please choose month for ' + r[i][1]);
								elt['mm_' + r[i][0]].focus();
								return false;
							}else if(dd==''){
								alert('Please choose day for ' + r[i][1]);
								elt['dd_' + r[i][0]].focus();
								return false;
							}else if(yyyy==''){
								alert('Please choose year for ' + r[i][1]);
								elt['yyyy_' + r[i][0]].focus();
								return false;
							}else if(h==''){
								alert('Please choose hour for ' + r[i][1]);
								elt['h_' + r[i][0]].focus();
								return false;
							}else if(m==''){
								alert('Please choose minute for ' + r[i][1]);
								elt['m_' + r[i][0]].focus();
								return false;
							}else{}
						}else if((mm=='' && ' '+dd+yyyy!=' ') || 
								(dd=='' && ' '+mm+yyyy!=' ') || 
								(yyyy=='' && ' '+mm+dd!=' ') ){
							alert('Please complete ' + r[i][1]);
							elt['mm_' + r[i][0]].focus();
							return false;
						}
					}
					break;
			}
		}
	}
	return true;
}

// "Internal" function to return the decoded value of a cookie
//
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

//
//  Function to return the value of the cookie specified by "name".
//    name - String object containing the cookie name.
//    returns - String object containing the cookie value, or null if
//      the cookie does not exist.
//
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}

//
//  Function to create or update a cookie.
//    name - String object object containing the cookie name.
//    value - String object containing the cookie value.  May contain
//      any valid string characters.
//    [expires] - Date object containing the expiration data of the cookie.  If
//      omitted or null, expires the cookie at the end of the current session.
//    [path] - String object indicating the path for which the cookie is valid.
//      If omitted or null, uses the path of the calling document.
//    [domain] - String object indicating the domain for which the cookie is
//      valid.  If omitted or null, uses the domain of the calling document.
//    [secure] - Boolean (true/false) value indicating whether cookie transmission
//      requires a secure channel (HTTPS).  
//
//  The first two parameters are required.  The others, if supplied, must
//  be passed in the order listed above.  To omit an unused optional field,
//  use null as a place holder.  For example, to call SetCookie using name,
//  value and path, you would code:
//
//      SetCookie ("myCookieName", "myCookieValue", null, "/");
//
//  Note that trailing omitted parameters do not require a placeholder.
//
//  To set a secure cookie for path "/myPath", that expires after the
//  current session, you might code:
//
//      SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
//
function SetCookie (name, value) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}

function SetNavNumCookie(name, value, expire)
{
  var argv = SetNavNumCookie.arguments;
  var argc = SetNavNumCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expire)) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}
//  Function to delete a cookie. (Sets expiration date to current date/time)
//    name - String object containing the cookie name
//
function DeleteCookie (name) {
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);  // This cookie is history
  var cval = GetCookie (name);
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function openModalWnd(iH,iW,sSRC,sQS){
	var s_features ='Height = '+iH+'px,'+
					'Width = '+iW+'px,'+
					'center = yes,'+
					'resizable = yes,'+
					'scrollbars = yes,'+
					'status = no,'+
					'help = no';
					//document.location.href=sSRC+'?Search=1'+(sQS ? '&'+sQS : '');
					
	var i_result = window.open(sSRC+'?Search=1'+(sQS ? '&'+sQS : ''), '_parent', s_features);
//	if(i_result) document.location.reload();
	//if(i_result) document.forms[0].submit();
}


function getAbsOffset(oElement) {
    var initLeft = 0;
    var initTop = 0;
    while (oElement) {
        if (typeof(oElement.tagName) != 'undefined' && oElement.tagName.toUpperCase() != 'FORM') {
            initLeft += oElement.offsetLeft;
            initTop += oElement.offsetTop;
        }
        //try {
        //    oElement.style.border = '1px solid red';
        //}
        //catch (e) { }
                //alert(oElement.tagName + '-' + oElement.offsetLeft + '-' + oElement.offsetTop);
        oElement = oElement.parentNode;
    }
    var tOffset = new Array;
    tOffset.absOffsetLeft = initLeft;
    tOffset.absOffsetTop = initTop;
    return tOffset;
}





