var dop_func;
var count_d=count_t=0;
var temp;
var filt_napr=0;



function red_state(obj, id){ /* вывод всех значений */
			id_v='&id='+id;
			loadchan('red_state', 1, 'div_all');
			view_div('div_all', obj);
}



function mail_autor(to, id){
		autor_body=document.getElementById('autor_body').value;
		who_name=document.getElementById('who_name').value;
		who_email=document.getElementById('who_email').value;
		who_phone=document.getElementById('who_phone').value;
		who_cena=document.getElementById('who_cena').value;
		who_kod=document.getElementById('who_kod').value;
		
		id_v='&go=mail_autor&to='+to+'&autor_body='+autor_body+'&who_name='+who_name+'&who_email='+who_email+'&who_phone='+who_phone+'&who_cena='+who_cena+'&who_kod='+who_kod+'&id_state='+id;

		loadchan('mailuser', 2, '');
		document.getElementById('div_all').style.display='block';
		
		

}


function mailuser(text, to, mail_t){
		id_v='&text='+text+'&to='+to+'&mail_t='+mail_t;
		loadchan('mailuser', 2, '');
}




function ch_link_type(val){
if(val==0){
document.getElementById('d_link').innerHTML='';
return true;
}
		id_v='&val='+val;
		loadchan('ch_link_type', 1, 'd_link');
}

function create_napr(c, id){

	r = document.getElementById('div_napr').getElementsByTagName('div');
	for (i = 0; i < r.length; i++){
	fo=r[i].id;
	if (fo.substr(0,9)=='div_napr_' && fo.substr(9)>(c+1)) 
		document.getElementById('div_napr').removeChild(document.getElementById(fo));
	}
	
if (c<=filt_napr)
filt_napr=c+1;
else filt_napr++;
	
if (id.substr(0,4)=='end_'){
document.getElementById('napr').value=id.substr(4);


	r = document.getElementById('div_napr').getElementsByTagName('div');
	for (i = 0; i < r.length; i++){
	fo=r[i].id;
	if (fo.substr(0,9)=='div_napr_' && fo.substr(9)>c) 
		document.getElementById('div_napr').removeChild(document.getElementById(fo));
	}
	
	
}else
if(id==0){

document.getElementById('div_napr').style.display='none';
document.getElementById('napr').value=0;


	r = document.getElementById('div_napr').getElementsByTagName('div');
	for (i = 0; i < r.length; i++){
	fo=r[i].id;
	if (fo.substr(0,9)=='div_napr_' && fo.substr(9)>c) 
		document.getElementById('div_napr').removeChild(document.getElementById(fo));
	}



}
else{

	r = document.getElementById('div_napr').getElementsByTagName('div');
	for (i = 0; i < r.length; i++){
	fo=r[i].id;
	if (fo.substr(0,9)=='div_napr_' && fo.substr(9)>(c+1)) 
		document.getElementById('div_napr').removeChild(document.getElementById(fo));
	}
		document.getElementById('napr').value=id;
		var d = document.createElement('div');
      	d.id='div_napr_'+filt_napr;
		id_v='&id='+id+'&c='+filt_napr;
		document.getElementById('div_napr').appendChild(d);
		loadchan('create_napr', 1, 'div_napr_'+filt_napr);
		document.getElementById('div_napr').style.display='block';
}
}



function hide_txt(){
hide_div("div_all");
}

function view_txt(txt, obj){
var div0=document.getElementById('div_all');
		div0.innerHTML=txt;
		div0.className='text1';
		div0.style.backgroundColor='#ffffff';
		obj_pos=getAbsolutePos(obj);
		div0.style.left=obj_pos.x;
		div0.style.top=obj_pos.y;
		div0.style.display="block";
}



function zapros_do(oper, go,  id){
	if (go=='red'){
	
	red_state(document.getElementById('num_'+id), id);
	}else{
		id_v='&do='+oper+'&id='+id+'&go='+go;
		loadchan('zapros_do', 1, 'div_all');
}
}

function zapros_user(oper, id, obj){
		id_v='&do='+oper+'&id='+id;
		loadchan('zapros_user', 1, 'div_all');
		view_div('div_all', obj);
}



function big_state(id, obj){
		id_v='&id='+id;
		loadchan('big_state', 1, 'div_all');
		var div0=document.getElementById('div_all');
		obj_pos=getAbsolutePos(obj);
		div0.style.left=obj_pos.x+30;
		div0.style.top=obj_pos.y-3;
		div0.style.display="block";
}




function view_help(obj, id){
		id_v='&id='+id;
		loadchan('view_help', 1, 'div_all');
		var div0=document.getElementById('div_all');
		obj_pos=getAbsolutePos(obj);
		div0.style.left=obj_pos.x-300;
		div0.style.top=obj_pos.y+30;
		div0.style.display="block";
}






function view_type_link(id){
var obj=document.getElementById('div_type_'+id);
if(obj.style.display=="none"){
		id_v='&id='+id;
		loadchan('view_type_link', 1, 'div_type_'+id);
		obj.style.display="block";
		}else obj.style.display="none";
		
}



function view_valut(price, valut, obj){
		id_v='&price='+price+'&valut='+valut;
		loadchan('view_valut', 1, 'div_all');
		view_div('div_all', obj);
}


	function start_foto(id){
						if (count_d==0){
								document.getElementById('ty_'+id).style.border='1 solid silver'
								count_d=id;
								count_t=0;
								ch_foto();	
								
						}
		}

		
	function ch_foto(){
						if (count_d>0){			
						reloading=1;			
						count_t++;
						id_v='&id='+count_d+'&foto='+document.getElementById('ty_'+count_d).src;
						loadchan('ch_foto', 1, 'ed_'+count_d);
						setTimeout('ch_foto()', 2500);
						}
		}
		
	function stop_foto(){
					document.getElementById('ty_'+count_d).style.border=''
					count_d=0;
					
	}
	
	
function korzina(t, id){
			if(t.checked){
				t.title="Удалить из корзины";
				id_v='&id='+id+'&op=add';
				loadchan('korzina', 2, '');
			}else{
				t.title="Добавить в корзину";
				id_v='&id='+id+'&op=del';
				loadchan('korzina', 2, '');
			}
}
	
	

function set_calendar(m, d, y){

str='<table border="0" class="text1"><tr><td width=180>Дата начало: '+d+'.'+m+'.'+y+'</td><td><input onmouseover="mouse_on(this, \'but_off\')" onmouseout="mouse_off(this, \'but_on\')" type="button" style="width:16; height:19; font-size: 8px;" value="•••" class="but_on" onclick="view_calendar(this)"></td></tr></table>';

document.getElementById('d_pok').innerHTML=str;
hide_div('div_all');
document.getElementById('pok').value=y+'.'+m+'.'+d;
}

function view_calendar(obj){
						
						date=0;
						id_v='&date='+date;
						loadchan('view_calendar', 1, 'div_all');
						view_div('div_all', obj);
}


function metod_rekl(obj){
hide_div('div_all');
var str;
if (obj.value=='2nedeli_rekl_group')
str='<table border="0" class="text1"><tr><td width=180>Дата начало: 00.00.00</td><td><input onmouseover="mouse_on(this, \'but_off\')" onmouseout="mouse_off(this, \'but_on\')" type="button" style="width:16; height:19; font-size: 8px;" value="•••" class="but_on" onclick="view_calendar(this)"></td></tr></table>';
else if (obj.value=='mesyac_rekl_group')
str='<table border="0" class="text1"><tr><td width=180>Дата начало: 00.00.00</td><td><input onmouseover="mouse_on(this, \'but_off\')" onmouseout="mouse_off(this, \'but_on\')" type="button" style="width:16; height:19; font-size: 8px;" value="•••" class="but_on" onclick="view_calendar(this)"></td></tr></table>';
else if (obj.value=='pokaz_rekl_group'){
str='<table border="0" class="text1"><tr><td width=180>Показов: 1000</td></tr></table>';
document.getElementById('pok').value='1000';
}
else str='';
document.getElementById('d_pok').innerHTML=str;
}



function ch_firma(obj, id){
if (obj.value==1){
document.getElementById('d_firma').style.display='none';
}else{
document.getElementById('firma_name').value='';
document.getElementById('firma_rekvizit').value='';
document.getElementById('d_firma').style.display='block';
}
				ch_val(obj, id, 'vid_user', 'user');
}

		

function del_it(){
			if (confirm('Уверены, что хотите удалить?'))	
				return true;
				else
				return false;
}



function loading_upload(txt){ 
		var ed=document.getElementById('status_upload');
		if (txt=='') ed.innerHTML="<img src='image/loading.gif'> идет загрузка, пожалуйста подождите..."; 
		else ed.innerHTML=txt;
}


function add_avator(txt, t){
		document.getElementById('val_foto').innerHTML = '<input type="file" name="picf" id="picf" style="width:200; height:20" class="forma"><input type="submit" name="add_avator" class="forma" style="width:130; height:20" value="Добавить аватор">';
if(t!==0){
	document.getElementById('div_foto').innerHTML="<img src='"+t+"' style='cursor:hand' onclick='big_foto(\""+t+"\")'>";
}
alert(txt);
}

function del_phone(id, a,  us){ 
if (del_it()){
	id_v='&id='+id+'&a='+a+'&us='+us;
	loadchan('del_phone', 1, 'div_phones');
}
}


function add_phone(id, us){ 
	id_v='&id='+id+'&us='+us;
	loadchan('add_phone', 1, 'div_phones');
}



function del_val(id, a){ 
if (del_it()){
	id_v='&id='+id+'&a='+a;
	loadchan('del_val', 2, '');
}}


function link_click(id){ 
	id_v='&id='+id;
	loadchan('link_click', 2, '');
}


function ok_upload(txt){ 
	id_v='&id='+temp_id+'&txt='+txt;
	loadchan('show_upload', 1, 'div_all');
}




function check_all(t, e){
	box = document.getElementById('fgg').getElementsByTagName('input');
	if (t.checked){
	for (i = 1; i < box.length; i++){
	fo=box[i].id;
	//alert(e+' '+fo.substring((fo.lastIndexOf('_')+1)));
	if (fo.substring((fo.lastIndexOf('_')+1))==e) 
		{
		
		document.getElementById(box[i].id).checked = true;
		fo=document.getElementById(box[i].id).id;
		//alert(fo.substring((fo.lastIndexOf('_')+1)));
		//check_all(document.getElementById(box[i].id), fo.substring((fo.lastIndexOf('_')+1)));
		}
	}
	}
	else {
	
		for (i = 1; i < box.length; i++){
		fo=box[i].id;
	if (fo.substring((fo.lastIndexOf('_')+1))==e) document.getElementById(box[i].id).checked = false;
}	
}
}






function CheckAll(){
	thisCheckBoxes = document.getElementById('forms').getElementsByTagName('input');
	if (document.getElementById('vse').checked){
	for (i = 1; i < thisCheckBoxes.length; i++){
	fo=thisCheckBoxes[i].id;
	if (fo.substring(0,6)=='funch_') document.getElementById(thisCheckBoxes[i].id).checked = true;
	}
	}
	else {
	
		for (i = 1; i < thisCheckBoxes.length; i++){
		fo=thisCheckBoxes[i].id;
	if (fo.substring(0,6)=='funch_') document.getElementById(thisCheckBoxes[i].id).checked = false;
}	
}
}


function mouse_on(obj, name){
obj.className = name;
}

function mouse_off(obj, name){
obj.className = name;
}



function del_foto(papka, id, ext){ /* Удалить фото */
if (del_it()){
	id_v='&papka='+papka+'&id='+id+'&ext='+ext;
	loadchan('del_foto', 2, '');
}
}


function hide_foto(){ /* Убрать фото */
document.getElementById('img_view').style.display="none";
document.body.style.overflow='';
}


function big_foto(id){ /* Посмотреть фото */

var ed=document.getElementById('img_view');
y = screen.height;
x = screen.width;
w = 400;
h = 400;

if (w>(x-10)) wid=x-10; else wid=w;
if (h>(y-150)) hig=y-150; else hig=h;

document.body.style.overflow='hidden';
	
	xtop = ((y - 200) / 2) -(hig / 2);
	xleft = ((x - 50) / 2) -(wid / 2);
	ed.innerHTML='<table border="0" onclick="hide_foto()" cellpadding="0" cellspacing="0" width="'+(x - 50)+'" height="'+(y - 200)+'"><tr><td align="center" valign="middle"><div align="center" style="width:'+(wid+2)+'; height:'+(hig+2)+';overflow: auto; border:1 solid gray"><img src="'+id+'" alt="Убрать" style="cursor:hand" onclick="hide_foto()"></div></td></tr></table>';
	ed.style.top=document.body.scrollTop;
	ed.style.left=0;
	ed.style.width=x;
	ed.style.height=y;
	ed.style.display="block";
}




var LinkDivActive = 0;
var onDiv;
var timeOnDiv;

function showLinkDiv(div, obj, id) {
reloading=0;
var ed=document.getElementById(div);
	ed.style.width=50;
	ed.style.height=10;
			id_v='&id='+id;
			loadchan('show_sub_menu', 1, div);
			
 if (timeOnDiv != null) {
  clearTimeout(timeOnDiv);
  hide_div(onDiv);
 }
 view_div(div, obj);
 onDiv = div;
}

function divOut() {
 if (LinkDivActive == 0) {
  hide_div(onDiv);
 }
 }
 
 
function LinkDivOver() {
 LinkDivActive = 1;
 clearTimeout(timeOnDiv);
}

function LinkDivOut() {
 LinkDivActive = 0;
 timeOnDiv = setTimeout("divOut()",500)
}



function getAbsolutePos(el)
{
   var r = { x: el.offsetLeft, y: el.offsetTop };
   if (el.offsetParent)
   {
       var tmp = getAbsolutePos(el.offsetParent);
       r.x += tmp.x;
       r.y += tmp.y;
   }
   return r;
}

function view_div(div, obj){
var div0=document.getElementById(div);
obj_pos=getAbsolutePos(obj);
/*
div0.style.left=obj_pos.x;
b=(screen.height-obj_pos.y-parseInt(div0.style.height)-150)-document.body.scrollTop;

if(b<0) t=(obj_pos.y+21)+b;
else t=(obj_pos.y+21);
div0.style.top=t;
*/

div0.style.left=obj_pos.x;
div0.style.top=obj_pos.y+20;
div0.style.display="block";
}

function hide_div(div){
var div0=document.getElementById(div);
div0.style.display="none";
div0.innerHTML='';
}




