 // Clear func
 function onclearform(frm) {
   for (var i = 0; i < frm.length; i++)
       if (/^(text|pass)/.test(frm.elements[i].type))
          frm.elements[i].value = '';
       else if (/^(radio|checkbox)/.test(frm.elements[i].type))
          frm.elements[i].checked = false;
       else if (/^select/.test(frm.elements[i].type))
          frm.elements[i].options.selectedIndex = (/one$/.test(frm.elements[i].type) ? 0 : -1);
}

 //  Vote func
 function write_quest(str) {
   for (var i = 0; i < str.length; i++)
        if (!isNaN(parseInt(str.elements[i].value)))
            if (str.elements[i].checked) {
                str.submit();
                return;
            }
   alert('??????????, ???????? ???? ?? ???????????? ????????? ??\? ??????????\?!');
}

function onindicatetext(str) {
   str.value = str.value.replace(/^(\s+)/gi, '');
   str.value = str.value.replace(/(\s+)$/gi, '');
   if (str.value.length > 0)
     return true;

   if(str!=null) return;
   str.select();
   str.focus();
   return false;
}

function onindicateexists(str, tmp) {
 for (var i = 0; i < tmp.length; i++)
   if (str == tmp[i])
     return true;
 return false;
}

function onindicatemail(str) {
   var tmp  = '';
   var lg   = true;
   var arr0 = new Array(45, 46, 95);

   var arr1 = str.value.match(/\b(\w((\w|\.|-)*\w)?@\w((\w|\.|-)*\w)?(\.[a-z]{2,3}))\b/gi);
   if (arr1 != null)
      for (var i = 0; (i < arr1.length && lg); i++) {
          tmp+= (tmp.length > 0 ? String.fromCharCode(59, 32) : '') + arr1[i];
          for (var j = 0; j < arr0.length; j++)
              if (arr1[i].indexOf(String.fromCharCode(arr0[j], arr0[j])) > -1) {
                 lg = false; break; }
      }


   if (!lg || (str.value.length > 0 && tmp.length == 0))
      return false;

   str.value = tmp;
   return true;
}

function onindicatehref(str)
{
	var tmp_href=str.value;

   var arr1 = tmp_href.match(/^(http:\/\/)([_a-z\d\-]+(\.[_a-z\d\-]+)+)((\/[ _a-z\d\-\\\.]+)+)*/gi);
   if(arr1!=null) return true
   else return false
}

function onformsform(frm,page) {
   var page_mas=eval(page+"_arr");
   for (var i = 0; i < frm.length; i++)
   {
       if (/^text/i.test(frm.elements[i].type))
       {
          if (!onindicatetext(frm.elements[i]))
          {
             if (onindicateexists(frm.elements[i].name, page_mas)) {
                onformsmess(frm.elements[i].name);
                return;
             }
          }
          else if (/mail$/.test(frm.elements[i].name))
          {
             if (!onindicatemail(frm.elements[i])) {
                onformsmess(frm.elements[i].name);
                return;
             }
          }
          else if(/href$/.test(frm.elements[i].name))
          {
             if (!onindicatehref(frm.elements[i])) {
                onformsmess(frm.elements[i].name);
                return;
             }
          }
       }
       else if(/sel_1$/.test(frm.elements[i].name))
       {
         if(frm.elements[i].options[frm.elements[i].selectedIndex].value==0)
         {
         	onformsmess(frm.elements[i].name);
            return;
         }
       }
   }

   frm.submit();
}

function onformsmess(str) {
   var tmp = eval(str);
   alert(tmp.length > 0 ? tmp : mess);
}

function openWindow(url, w, h) {
 var options = "width=" + w + ",height=" + h + ",";
 options += "scrollbars=yes,status=no,";
 options += "menubar=no,toolbar=no,position=center,location=no,directories=no";
 var newWindow = window.open(url, 'newWind', options);
 newWindow.focus();
}




	var new_window;

	function window_available()
   {
	   if (!new_window) return false
      else if (new_window.closed) return false
      else return true
	}

	function resize_image(path)
   {
      var img_loaded=new Image();
      img_loaded.src=path;
      new_window.window.resizeTo(img_loaded.width,img_loaded.height);
   }

	function display_image(path,title)
   {
      var img=new Image();
      img.src=path;
      img_width=img.width;
      img_height=img.height;

      add_param="menubar=no,toolbar=no,location=no,directories=no,width="+img_width+",height="+img_height;

      (window_available())? new_window.close(): new_window=false;

      new_window = window.open("","",add_param);
      new_window.document.writeln('<html>');
	   new_window.document.writeln('<head>');
	   new_window.document.writeln('<title>'+title);
	   new_window.document.writeln('<\/title>');
	   new_window.document.writeln('<\/head>');
      new_window.document.writeln('<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">');
      new_window.document.writeln("<img src='"+img.src+"'>");
	   new_window.document.writeln('<\/body>');
	   new_window.document.writeln('<\/html>');
      var img_loaded=new Image();
      img_loaded.src=path;
      new_window.window.resizeTo(img_loaded.width,img_loaded.height);
	   new_window.document.close();
   }

	function write_image(i,t) {
	   var par='location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,width='+Math.floor(screen.width/2)+',height='+Math.floor(screen.height/2);
	   var wind=window.open(SITE_URL + 'image.php?act='+i+'&title='+t,'OrattaImage',par);
	   wind.focus();
	}

	function write_blank(i)
   {
	   var par='location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=780,height=550';
	   var wind=window.open(SITE_URL + 'forms/'+i,'Blank',par);
	   wind.focus();
	}

	function write_quest(i)
   {
	   var par='location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=350,height=250';
	   var wind=window.open(SITE_URL +'quest/other/'+i,'Blank',par);
	   wind.focus();
   }
   function write_table(i)
   {
      var par='location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=500,height=300';
      var wind=window.open('/oratta/table/'+i,'Blank',par);
      wind.focus();
   }
   function write_exchange(i)
   {
      var par='location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=500,height=300';
      var wind=window.open('/oratta/links/exchange/'+i,'Blank',par);
      wind.focus();
   }
