function hideshow(obj)
{
	if (document.getElementById(obj).style.display == 'none') 
	{
		document.getElementById(obj).style.display = ''; 
	}
	else 
	{
		document.getElementById(obj).style.display = 'none';
	}
}
function addCookie(Name,Value)
{
var dtExpires=new Date();
var dtExpiryDate="";
dtExpires.setTime(dtExpires.getTime()+8*60*1000);
dtExpiryDate = dtExpires.toGMTString();
document.cookie=Name+"="+Value+"; expires="+dtExpiryDate+"; path=/;";
}
function addCookieForever(Name,Value)
{
var dtExpires=new Date();
var dtExpiryDate="";
dtExpires.setTime(dtExpires.getTime()+100*12*30*24*60*1000);
dtExpiryDate = dtExpires.toGMTString();
document.cookie=Name+"="+Value+"; expires="+dtExpiryDate+"; path=/;";
}
function goto_url(url)
{
	document.location.href=url; 
}
function attent()
{
	if (confirm("Вы действительно хотите УДАЛИТЬ запись?")) {return true;} else {return false;};
}
function gen_password(length) {
	symbols = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
	
	pass = "";
	
	while (pass.length < length) {
		i = Math.round((Math.random() * 10000000))%symbols.length;
		pass = pass+symbols.charAt(i);
	}
	
	return pass;
	
}
function check_number()
{	window.event.cancelBubble=true;
	if ((window.event.keyCode >=48) && (window.event.keyCode<=57)) return true
	else return false;
}
function check_date()
{	window.event.cancelBubble=true;
	if (
	((window.event.keyCode >=48)&&(window.event.keyCode<=57))||(window.event.keyCode==46)
	) 
	return true
	else return false;
}
function check_money()
{	window.event.cancelBubble=true;
	if (
	((window.event.keyCode >=48)&&(window.event.keyCode<=57))||(window.event.keyCode==46)
	)
	return true
	else return false;
}
function check_date_onblur(val)
{
	var reg= new RegExp("^[0-9]{2}[\.]{1}[0-9]{2}[\.]{1}[0-9]{4}$", 'i');
	if (!reg.test(val) && val) {alert('Ошибка при указании даты!');}
}
function get_code(code)
{
window.clipboardData.setData('Text', code);
alert('код скопирован в буфер');
}
function load_select(type,value,from_obj,to_obj) {
		document.getElementById(to_obj).options[0].selected=true;
		document.getElementById(to_obj).disabled=true;
		document.getElementById(to_obj).options[0].value = '';
		document.getElementById(to_obj).options[0].text = '- загрузка -';
		if (type=='c') script='/jshttprequest/load.php';
		if (type=='p') script='/jshttprequest/load_p.php';
		if (type=='f') script='/jshttprequest/load_f.php'; // фильтр в компаниях
        JsHttpRequest.query(
            script, // backend
            {
               // pass a text value 
                'q': value,  
                // path a file to be uploaded
                //'upl': document.getElementById("myupl")
				'from_obj': from_obj
            },
            // Function is called when an answer arrives. 
            function(result, errors) {
                // Write errors to the debug div.
				document.getElementById(to_obj).disabled=false;
                document.getElementById("debug").innerHTML = errors; 
				
				// ОЧИСТКА ОБЪЕКТА
				var i=document.getElementById(to_obj).length;
				while (i>0) //(i=opt_count; i>0; i--) 
				{
					i=i-1;
					document.getElementById(to_obj).options[i] = null;
				}
				// ОЧИСТКА ОБЪЕКТА
				
                // Write the answer.
                if (result) 
				{
					var arr_count=result.length;
					for (i=0; i<arr_count; i++) 
					{
						document.getElementById(to_obj).options[i] = new Option();
						str=result[i].split('#');
						document.getElementById(to_obj).options[i].value = str[0];
						document.getElementById(to_obj).options[i].text = str[1];
					}						
                }
				 else // если даннх для загрузки нет
				{
					document.getElementById(to_obj).options[0] = new Option();
					document.getElementById(to_obj).options[0].value = '0';
					document.getElementById(to_obj).options[0].text = 'нет данных';
				}
            },
            false  // do not disable caching
        );
    }
function show_form(rand)
{
document.getElementById("stat_calendar_"+rand).style.display='';
document.getElementById("stat_result_"+rand).style.display='none';
}
function load_stat(rand,banner_id,place_id) {
		rnd_num = Math.round((Math.random()*10000000));
		var date_beg=document.getElementById('date_beg_stat_'+rand).value;
		var date_end=document.getElementById('date_end_stat_'+rand).value;
		document.getElementById("stat_calendar_"+rand).style.display='none';
		document.getElementById("stat_result_"+rand).style.display='';
		document.getElementById("stat_result_"+rand).innerHTML='<img border="0" src="/img/working_big.gif">';
        JsHttpRequest.query(
            '/jshttprequest/load_stat.php', // backend
            {
               // pass a text value 
                'date_beg': date_beg,  
				'date_end': date_end,  
				'banner_id': banner_id,  
				'place_id': place_id,
				'rand':rnd_num
            },
            // Function is called when an answer arrives. 
            function(result, errors) {
                // Write errors to the debug div.
                document.getElementById("debug").innerHTML = errors; 
				
				
                // Write the answer.
                if (result) 
				{
					text='<span id="res'+rand+'">'+result+'<br><input value="другой период" type="Button" onclick="show_form('+rand+')"></center>';
					document.getElementById("stat_result_"+rand).innerHTML=text;
									
                }
				 else // если даннх для загрузки нет
				{
					document.getElementById("stat_result_"+rand).innerHTML='<span id="res'+rand+'"><center>нет данных</span><br><input value="другой период" type="Button" onclick="show_form('+rand+')"></center>';
				}
            },
            false  // do not disable caching
        );
    }
	
function generate_code(company_id) {
		rnd_num = Math.round((Math.random()*10000000));
        JsHttpRequest.query(
            '/jshttprequest/access_code.php?rnd_num='+rnd_num, // backend
            {
               // pass a text value 
				'company_id':company_id
            },
            // Function is called when an answer arrives. 
            function(result, errors) {
                // Write errors to the debug div.
                document.getElementById("debug").innerHTML = errors; 
                // Write the answer.
                if (result) 
				{
					document.getElementById('access_code').value=result;			
                }
            },
            false  // do not disable caching
        );
    }	
	
	
	
var v=parseInt(navigator.appVersion);
isNetscape=navigator.appName.indexOf('Netscape')>=0;
isExplorer=navigator.appName.indexOf('Explorer')>=0;
if(v>=3) self.focus();

function popupWindow(ww, wh, page) {
//ww=800;  wh=600;
positionCode='';
if(v>=4) {
   sw  = screen.width;
   sh  = screen.height;
   wbx = Math.round((sw-ww)/2);
   wby = Math.round((sh-wh)/2);
   if(isExplorer) positionCode='left='+wbx+',top='+wby+',';
   if(isNetscape) positionCode='screenX='+wbx+',screenY='+wby+',';
}

newWindow = window.open(page,'','width='+ww+',height='+wh+','+positionCode+'toolbar=0,'+'scrollbars=1,'+'resizable=0');
if(isNetscape && v>=3) newWindow.focus();
}



function checkdel(the_form, do_check)
  {
  var elts      = (typeof(document.forms[the_form].elements['selected_db[]']) != 'undefined')
                  ? document.forms[the_form].elements['selected_db[]']
                  : (typeof(document.forms[the_form].elements['selected_tbl[]']) != 'undefined')
          ? document.forms[the_form].elements['selected_tbl[]']
          : document.forms[the_form].elements['selected_fld[]'];
   var elts_cnt  = (typeof(elts.length) != 'undefined')
                  ? elts.length
                  : 0;
  var check=0; 

	if (elts_cnt) {
        for (var i = 0; i < elts_cnt; i++) {
            if (elts[i].checked) check=1;
        } // end for
    }   
				  
  if (check==0) 
  	{
  		alert('Вы не выбрали объекты');
		document.getElementById('submit_mult').options[0].selected=true;
		return false;
	} 
	else 
	{
	  if (document.form_list.submit_mult.value=='delete') 
	  	{
		if (attent()==true) document.form_list.submit();
		} 
  	 	else 
		{
		document.form_list.submit();
		}
	}
  }
  
  
function update_assigments(value) {
	str='';
	ch='';
	if (value=='') ch='1';
	if (value=='delete') 
	{
		if (attent()==true) ch=''; else ch='1';
	}
	
	if (ch=='')
	{
		rnd_num = Math.round((Math.random()*10000000));
		a.sort(); for(var i in a) if (typeof a[i] !='function') 
		{
			
			if (document.getElementById("selected_"+a[i]).checked) str=str+','+(a[i]);
		} 
		
			document.getElementById("working").innerHTML='<img border="0" src="/img/working_big.gif">';
	        JsHttpRequest.query(
	            '/jshttprequest/update_assigments.php?rnd_num='+rnd_num, // backend
	            {
	               // pass a text value 
	                'str': str,
					'value': value
	            },
	            // Function is called when an answer arrives. 
	            function(result, errors) {
	                // Write errors to the debug div.
	                document.getElementById("debug").innerHTML = errors; 
	                // Write the answer.
	                if (result) 
					{
						//document.getElementById("ans").style.display='';
						//document.getElementById("debug").style.display='';			
						document.getElementById("working").innerHTML='';		
						window.location.reload();
	                }
					 else // если даннх для загрузки нет
					{
						//document.getElementById("ans").style.display='';
						//document.getElementById("debug").style.display='';	
						document.getElementById("working").innerHTML='';	
						window.location.reload();		
					}
	            },
	            false  // do not disable caching
	        );
	}
}

function add_place(place_id,banner_id)
{
	if (place_id>0)
	{
		var TablePages=document.getElementById('add_place_'+banner_id);
		var lastRow = TablePages.rows.length;
		var iteration = lastRow;
		var row = TablePages.insertRow(lastRow);
		row.className= "tr1"; 
		row.id="tra"+banner_id+'_'+lastRow;
		
		var cellLeft = row.insertCell(0);
		var objSel = document.getElementById('site_id_'+banner_id);
		var textNode = document.createTextNode(objSel.options[objSel.selectedIndex].text);
		cellLeft.appendChild(textNode);
		
		var cellLeft = row.insertCell(1);
		var objSel = document.getElementById('place_id_'+banner_id);
		var textNode = document.createTextNode(objSel.options[objSel.selectedIndex].text);
		cellLeft.appendChild(textNode);
	}
}
// if (confirm("удалить площадку")) removeRowFromTable("a89a137a73"); return false;'

function delete_item(obj){ 
 var num=getId(obj);
 document.getElementById(obj).options[num] = null;
}

function move_option(from_obj,to_obj)
{
	var num=getId(from_obj);
	if (num>=0) {
	var items_count_dest=document.getElementById(to_obj).length;
	var item_value	=	document.getElementById(from_obj).options[num].value;
	var item_text	=	document.getElementById(from_obj).options[num].text;	
	
	if (in_option(to_obj,document.getElementById(from_obj).options[num].value)==false) {
		document.getElementById(to_obj).options[items_count_dest] = new Option();
		document.getElementById(to_obj).options[items_count_dest].value=item_value;
		document.getElementById(to_obj).options[items_count_dest].text=item_text;
		//document.getElementById(from_obj).options[num]=null;
		return items_count_dest;
		}
	}
}	
function getId(obj)
	{
	var items_count=document.getElementById(obj).length; // определяем кол-во загр элементов
	num=parseInt(document.getElementById(obj).selectedIndex);
	if (!num in [1..items_count]) {num=0;};
	ind=parseInt((document.getElementById(obj).value));
	//element = list_form.cool_list.item(num).text; 
	//alert("выделен id:" + ind + " num:" + num + " value:" + element);
	return num;
	};


function in_option(obj,id){
var i;
var ch=0;

	arr_count = document.getElementById(obj).length;

	for (i=0; i<arr_count; i++) 
		{
			if (document.getElementById(obj).options[i].value == id)
			{
			ch=1;
			}
		}
if (ch==1) return true; else return false;
};



function selectAll(obj){
var i;

	arr_count = document.getElementById(obj).length;
	for (i=0; i<arr_count; i++) 
		{
		document.getElementById(obj).options[i].selected = true;
		}
	};
