// Библиотека javascript
//
// Каргаполов В.А.
//

          function create_window(urlstring){
              var w_w=screen.availWidth-10;
              var w_h=screen.availHeight-60;
              var rand=Math.round(Math.random()*1000000);
//              window.close();
              self.close();

              new_window=window.open(urlstring,'soi'+rand+'','top=0, left=0, height='+w_h+',width='+w_w+',scrollbars=yes,resizable=yes,menubar=no,status=yes');
              new_window.focus();
//              window.opener.close();
           }

          function docflow_messages(urlstring){

               new_window=window.open(urlstring,'docflow_messages','top=30, left=15, width=700,height=600,scrollbars=yes,resizable=yes,menubar=no');
               new_window.focus()
           }

          function docflow_messages_get(urlstring,user,server){

//               new_window=window.showModalDialog(urlstring,'docflow_messages_get','dialogWidth=600px;dialogHeight=10px;border=thin;help=no');
               var docflow_messages_get;
			   docflow_messages_get='docflow_messages_get'+user+server;
               new_window=window.open(urlstring,docflow_messages_get,'top=30, left=15, width=700, height=5 ,scrollbars=no,resizable=Yes,menubar=no');
               new_window.focus()
           }

           function info_doc(urlstring){
              window.open(urlstring,'viwing','top=0, left=0, width=600,height=400,scrollbars=yes,resizable=yes,menubar=yes');
           }

           function fdnavigator(urlstring){
              new_window=window.open(urlstring,'viwing','top=0, left=0, width=600,height=800,scrollbars=yes,resizable=yes,menubar=no');
              new_window.focus();
           }


          function info_func(urlstring){
               new_window=window.open(urlstring,'viwing','top=0, left=0, width=600,height=400,scrollbars=yes,resizable=yes,menubar=yes');
               new_window.focus()
             }


         function docnavigator(urlstring){
               window.open(urlstring,'viwing','top=0, left=0, width=600,height=600,scrollbars=yes,resizable=yes,menubar=yes');
             }



         function help(urlstring){
            new_window=window.open(urlstring,'help','top=15, left=15, width=450,height=600,scrollbars=yes,resizable=yes,menubar=no')
            new_window.focus()
         }



         function help_full(urlstring){
           var w_w=screen.availWidth
           var w_h=screen.availHeight
           new_window=window.open(urlstring,'help','top=15, left=15, width='+w_w+',height='+w_h+',scrollbars=yes,resizable=yes,menubar=yes')
           new_window.focus()
         }


         function click_yes_no(){
             if (confirm('Добавить новый элемент?')){
                  return true
             }else{
                  return false
             }
         }

// обновить родительское окно

        function reload_opener_window(url,type_reload){
    
        	//opener.location.reload(true);
            //opener.location=url;
            //return;
            //parent.location.reload();    
	
        //type_reload - тип обновления страницы, если 1 - без анализа формы
	
        if(opener.document.forms[0] && type_reload != 1){
        	opener.document.forms[0].submit();
        }else{	 
          if (url==''){
            opener.location.reload(true);
          }else{
            opener.location.reload(true);
            opener.location=url;
          }
         }
		}


//  обновить родительское окно и закрыть текущее

        function reload_close_window(){
           reload_opener_window('') ;
           self.close()
        }

// закрыть текущее  окно

        function close_window(){
            self.close()
        }

// показать размеры окна

        function info_window(){
            document.write('Width=');
            document.write(window.window.self.width);
            document.write("<br>")
            for (var property_name in window){
                    document.write(property_name+"<br>")
            }
        }

// create kod Submit

        function key_ctrl_enter(event_object){

//               alert(document.forms[0].name)
//               alert(document.forms[0].length)
               var name_form=document.forms[0].name
//               alert(name_form)
//               alert(event_object.keyCode)
               if(event_object.keyCode==10){
                 document.forms[0].submit()
//                 event_object.keyCode=13
              }
        }

// create  kod Enter

        function key_enter(event_object){

//                alert(event_object.keyCode)

               if(event_object.keyCode==10){
                 document.forms[0].submit()
                 event_object.keyCode==13
               }

                if(event_object.keyCode==13){
                   document.forms[0].submit()
                   event_object.keyCode=10
                   return
                }

//                key_ctrl_enter(event_object)

        }

//  обновляем фреймы по с новыми url

   function refresh_frames(url1,url2){

      parent.leftframe.location=url1;
      parent.mainframe.location=url2;

   }

// обновить левый фрейм

   function refresh_left_frames(){
      parent.leftframe.location.reload();
   }

// обновить центральный фрейм

   function refresh_main_frames(){

      parent.mainframe.location.reload();

   }

// очистить форму

   function full_erase_form(form){
      var ob=form;
      var ct=0;
      len=ob.elements.length;
      for (var ct=0; ct<len; ct++)
      {       el=ob.elements[ct].name;
          if (el == "button"){          }else{
             dat="dat=ob."+el+".value=''";
             eval(dat);
          }
      }
   }


////////////////////////////////////////////////////////////////////////////////
//
   function load_data_form(form,id_record){


//	  alert(form);
//    var ob=form;
      var ob = document.getElementById(form);
      var ct=0;
	  var dat="";
	  var data=form+"|||\n"+id_record+"|||\n";
      var dlina=0;
      var zikl=0;
      var z=0;
	  var start=0;

      len=ob.elements.length;
      String.prototype.left = extract_left;
      String.prototype.replace = replace_string;

      for (var ct=0; ct<len; ct++)
      {
       el=ob.elements[ct].name;

//if (el=="comments"){//       dlina=escape(ob.elements[ct].value).length;
//alert(dlina);
//}
//       if (dlina>300){//         zikl=Math.ceil(dlina/30);
//alert(zikl)//       }else{//       	 zikl=1;//       }

//         for (var z=0; z<zikl; z++){
//	         start=300*z;
		     val=ob.elements[ct].value;


			 val=val.replace("+","%u0999");

	         val=escape(val);


//  alert(val);
	          if (el == "button"){
	          }else{
//	             dat=el+"=ob."+el+".value"+";\n";
	             dat=""+el+"!=!"+val+"|||\n";
//alert(dat);
	           //  eval(dat);

	             data=data+dat;

	          }
//          } // end zikl
      } // end ct
//        eval(data);

//       	alert(data);

//		get_date_save_record(data);

        return data;
   }


////////////////////////////////////////////////////////////////////////////////
//
   function replace_string(find_string,replace_string){
		var temp_string=this;
		var left_string;
		var right_string;
		var start_location;

		var replace_location=temp_string.indexOf(find_string);
		while (replace_location !=-1){			left_string=temp_string.left(replace_location);
 			right_string=temp_string.substring(replace_location+find_string.length);
			temp_string=left_string+replace_string+right_string;
			start_location=replace_location+replace_string.lenght;
			replace_location=temp_string.indexOf(find_string, start_location);
		}
 		return temp_string;
   }
////////////////////////////////////////////////////////////////////////////////
//

	function extract_left(total_chars){		return this.substring(0,total_chars);	}

////////////////////////////////////////////////////////////////////////////////
//  set

   function setpoint(theAction, theRow, theDefaultColor, thePointerColor, theMarkColor, theNumber,theCount,theObject_id){

      // read background
      var bg=read_background(theRow,theObject_id);
//alert(bg.indexOf("("));

      if (bg.indexOf("(")!=-1){

         var bg=create_hex(bg);
//alert(bg);
//		 var bg=read_background(bg);

      }

      var markColor = null;
//     alert(bg);
     // over

       if (theAction=='over'){

           if (bg.toLowerCase()==theMarkColor.toLowerCase()){
           	   return ;
           }


          if (bg=='' || bg.toLowerCase()==theDefaultColor.toLowerCase()){             markColor=thePointerColor;
          }
       }

     // out
       if (theAction=='out'){

           if (bg.toLowerCase()==theMarkColor.toLowerCase()){           	   return ;           }

           markColor=theDefaultColor;


       }


     // mark
       if (theAction=='click'){

		 if (bg.toLowerCase()==theMarkColor.toLowerCase()){
            markColor=theDefaultColor;
         }else{
            markColor=theMarkColor;
         }

       }


       if (theAction=='dbclick'){

		 if (bg.toLowerCase()==theMarkColor.toLowerCase()){
            markColor=theDefaultColor;
         }else{
            markColor=theMarkColor;
         }

         var id='td'+theObject_id+'_'+theRow+'_'+theCount;
		 set_attribute(id,markColor);

		 return;
       }


       for (var t=0; t<theCount; t++){
         var id='td'+theObject_id+'_'+theRow+'_'+t;
		 set_attribute(id,markColor);

      } // end for

   }
////////////////////////////////////////////////////////////////////////////////
//
function set_attribute(id,markColor){//  return;

		 if (document.getElementById(id)){
		     var obj = document.getElementById(id);
 		 }else{
//		alert (id);
//		alert (document.getElementById(id)); 		 	return; 		 }
		 if (!obj){		 	return;		 }

		 if (typeof(obj.style.getAttribute) != 'undefined') {
			obj.style.setAttribute('background', markColor , 0);
//			obj.style.setAttribute('color', '#000000', 0);
			domDetect    = true;

	     } else{
			obj.style.backgroundColor = markColor;
//			obj.style.color = '#00000';
	        domDetect    = false;
	    }
}

////////////////////////////////////////////////////////////////////////////////
//

function create_hex(bg){

		 var stroka=bg.slice(bg.indexOf("(")+1,bg.indexOf(")"));
		 var stroka=stroka.split(",");

         var red=decimal_to_hex(stroka[0]);
         var green=decimal_to_hex(stroka[1]);
         var blue=decimal_to_hex(stroka[2]);

         return "#"+red+green+blue;
}

////////////////////////////////////////////////////////////////////////////////
//
function decimal_to_hex(decimal_value){

//alert(decimal_value);
          var hex_array = new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
          var hex_index1=Math.floor(decimal_value/16);

		  var hex_index2=decimal_value % 16;
		  var hex1=hex_array[hex_index1];
		  var hex2=hex_array[hex_index2];
//alert(hex1+hex2);
		  return hex1+hex2;

}

////////////////////////////////////////////////////////////////////////////////
//

function read_background(theRow,theObject_id){

    var id='td'+theObject_id+'_'+theRow+'_0';
    var obj = document.getElementById(id);

    if (typeof(obj.style.getAttribute) != 'undefined') {
		return obj.style.getAttribute('background');
    } else{
		return obj.style.backgroundColor;
    }

}

////////////////////////////////////////////////////////////////////////////////
//
   function delete_session(){
//        alert("Мочи сессию")   	;
		set_cookie("Se","",-1,"");
   }

////////////////////////////////////////////////////////////////////////////////
//

  function SET_HTTP_REFERER(name){

	  var cookie_string = name+"=" + escape ( opener.location );
//alert(cookie_string);
//	  if (path) cookie_string += "; path=" + escape ( path );
//	  if (domain) cookie_string += "; domain=" + escape ( domain );
//	  if (secure) cookie_string += "; secure";

	  document.cookie = cookie_string;
  }

////////////////////////////////////////////////////////////////////////////////
//

  function DELETE_HTTP_REFERER(name){

	  var cookie_string = name+"=''; expires=-1";
//alert(cookie_string);
//	  if (path) cookie_string += "; path=" + escape ( path );
//	  if (domain) cookie_string += "; domain=" + escape ( domain );
//	  if (secure) cookie_string += "; secure";

	  document.cookie = cookie_string;

  }

  
///////////////////////////////////////////////////////////////////////////////
//
  
  function block_info(type,id){
	  
	  //alert(type);
	  var markColor='fff000';
	  if(type == 1){
		  markColor='1px solid #ccc';
		  block="block";
	  }else{
		  markColor='0px solid #ccc';
		  block="none";
	  }
	  
	  var obj = document.getElementById(id);
	  var id2 = id+'_edit';
	  var obj2 = document.getElementById(id2);
	  
	  if (typeof(obj.style.getAttribute) != 'undefined') {
			obj.style.setAttribute('border', markColor , 0);
	     } else{
			obj.style.border = markColor;
			obj2.style.display = block;
			
	    }
	  
  }

//////////////////////
//
 
 function vp(spani,i){
	 
	  //alert(i); 
	 var obj = document.getElementById(spani);
	 var obj1 = document.getElementById(i);
	 markColor='#fffaaa';
	 var z =(obj1.offsetWidth-2)+'px';
	 var z2 =(obj1.offsetTop-0)+'px';
	 if (typeof(obj.style.getAttribute) != 'undefined') {
			obj.style.setAttribute('marginLeft', z , 0);
//			obj.style.setAttribute('marginTop', '-45px' , 0);
			obj1.style.setAttribute('textDecoration', 'none' , 0);
			obj1.style.setAttribute('zIndex', '9999' , 0);
	     } else{
	    	obj.style.marginLeft = z;
	    	obj1.style.textDecoration='none';
	    	obj1.style.zIndex='9999';
	    }	 
 }
 
 function vpout(i){
		 
	 //alert(i); 
	 var obj1 = document.getElementById(i);
	 if (typeof(obj1.style.getAttribute) != 'undefined') {
			obj1.style.setAttribute('zIndex', i , 0);
			obj1.style.setAttribute('textDecoration', 'underline' , 0);
	     } else{
	    	obj1.style.textDecoration='underline';
	    	obj1.style.zIndex=i;
	    	
	    		//"'"+i+"'";

	    }	 
 }





