// web to communicate advanced module
var reqd=null;var lid;var ldp;var ltpi;var req2=null;
var cformarr=Array();
var web2com=1;
var ccx=0;var ccy=0;
if(typeof(GetRPCObject)=='undefined'){
GetRPCObject=function(process){var request=null;
 if(!request)try{request=new ActiveXObject('Msxml2.XMLHTTP');request.onreadystatechange=process;}catch(e){}
 if(!request)try{request=new ActiveXObject('Microsoft.XMLHTTP');request.onreadystatechange=process;}catch(e){}
 if(!request)try{request=new XMLHttpRequest();request.onload=process;}catch(e){}
 return request;
in_array=function(what,where){var a=false;for(var i=0;i<where.length;i++){if(what==where[i]){a=true;break;}}return a;}
}                       
}
if(typeof(GetItemById)=='undefined'){
GetItemById=function(item){return document.getElementById(item);}
}
if(typeof($)=='undefined'){
function $_(id){return GetItemById(id);}
}
function getRadioGroupValue(radioGroupObj){
 for(var i=0;i<radioGroupObj.length;i++)if(radioGroupObj[i].checked)return radioGroupObj[i].value;return null;
}
function topn(tware,tum,mode){
 req2=GetRPCObject(tpnr); 
 if(!req2){return;}
 req2.open('GET','/topns.php?tware='+tware+'&tum='+tum+'&mode='+mode,true); 
 req2.send(null);
}
function tpnr(){    
 if(req2.readyState==4)
  if(req2.status==200)eval(req2.responseText);
}
function gscrp(scrp)
{var newscp='';var machstr='';var m=0;var i=0;var b;var c;var nmachstr='';var kmachstr='';var yd;
 while((i=scrp.search('<scr'+'ipt>'))!=-1 && m<20){      
  machstr=scrp.slice(i,scrp.search('</sc'+'ript>')+9);
  yd=machstr.slice(8);
  b=yd.search('<scr'+'ipt>');
  c=scrp.search('</scr'+'ipt>');           
  nmachstr='';
  if(b+i+8<c && b!=-1){// inside s_cript only for opera  
   machstr=scrp.slice(i);
   nmachstr=scrp.slice(b+i+8,machstr.search('</sc'+'ript>')+9);
   machstr=machstr.replace(nmachstr,'');
   nmachstr=nmachstr.replace('<scr'+'ipt>','');
   nmachstr=nmachstr.replace('</scr'+'ipt>','');
   kmachstr=kmachstr+nmachstr;  
   machstr=machstr.slice(0,machstr.search('</sc'+'ript>')+9);
  }
  scrp=scrp.slice(0,i)+scrp.slice(i+machstr.length+nmachstr.length+1);//scrp.replace(machstr,'');//17
  machstr=machstr.replace('<scr'+'ipt>','');
  machstr=machstr.replace('</scr'+'ipt>','');
  newscp=newscp+machstr;
  m++;
 }
 if(kmachstr)kmachstr=kmachstr.replace(/\\'/g,'\'');               
// testwindow=window.open('', 'mywindow','');
// testwindow.moveTo(0,0);
// testwindow.document.write(kmachstr); //newscp         
// testwindow.document.write('<scr'+'ipt>'+newscp+'</scr'+'ipt>');
//alert(newscp);          
 if(newscp)eval(newscp);
 if(kmachstr)eval(kmachstr);
}  
function answermenu(id,tp,er,dp){lid=id;ldp=dp;ltpi=tp;
 reqd=GetRPCObject(sendeddready);
 // scan for other opened!!! destroy all!!!
 tt=1; 
 if(tp==1)tt=3;
 if(tp==85){if(!confirm('delete?'))return false;}                              
 if(!reqd)return false;reqd.open('GET','/postum?tt='+tt+'&tp='+tp+'&erd='+encodeURIComponent(er)+'&data='+encodeURIComponent(id)+'&dp='+encodeURIComponent(dp),true);reqd.send('');
 return false;
}

function sendeddready(){if(reqd&&reqd.readyState==4){
//  alert(reqd.responseText);
  if(ltpi==85){gscrp(reqd.responseText);location.reload(true);return false;}   
  var tts=GetItemById('answer_'+lid); 
  tts.innerHTML=reqd.responseText;
  gscrp(reqd.responseText);
 }
} 

function upres(tp,id)
{
 var tt=80;
 reqd=GetRPCObject(postedready);
 if(!reqd)return;
 reqd.open('POST','/postum?tt='+tt+'&tp='+tp+'&data='+encodeURIComponent(id),true);
 reqd.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
 reqd.send('');
}

function postanswer(formname,tp,id,dp){lid=id;ldp=dp;        
 reqd=GetRPCObject(postedready);
 if(!reqd)return;
 if(GetItemById('umbody')&&GetItemById('result')){GetItemById('umbody').value=GetItemById('result').innerHTML;}
 tt=2; 
 if(tp==1)tt=4;
 reqd.open('POST','/postum?tt='+tt+'&tp='+tp+'&data='+encodeURIComponent(id),true);
 reqd.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
 query=''; 
// tt=document.getElementsByTagName('input');
 var myform=Object();
 if(cformarr.length)
 {        
  myform.elements=Array();
  for(i=0;i<cformarr.length;i++)
   myform.elements[myform.elements.length]=GetItemById(cformarr[i]);
 }
 else 
  myform=eval('document.forms.'+formname);
 for(i=0;i<myform.elements.length;i++)
 {
  if(myform.elements[i].value.length)                                                     
  {                                                              
   if(myform.elements[i].type=='checkbox' && !myform.elements[i].checked)
    query=query+'&'+myform.elements[i].name+'='+encodeURIComponent('-1');
   else 
   if(myform.elements[i].type=='radio' && myform.elements[i].checked)
    query=query+'&'+myform.elements[i].name+'='+encodeURIComponent(myform.elements[i].value);
   else
   if(myform.elements[i].type!='radio')
    query=query+'&'+myform.elements[i].name+'='+encodeURIComponent(myform.elements[i].value);
  }
 }
// if(tp==1230)
//  alert(GetItemById('umbody').value);           
//  alert(query);
 query=query+'&uid=$uid&sid=$sid'+'&formname='+encodeURIComponent(formname)+'&id='+encodeURIComponent(id)+'&dp='+encodeURIComponent(dp);
 reqd.send(query);
} 
//--------
function postedready(){if(reqd&&reqd.readyState==4){
  var tts=GetItemById('answer_'+lid);
  if(tts)tts.innerHTML=reqd.responseText;
  else if(GetItemById('result')){
	 var rdrt=reqd.responseText;
   var olds=new Array();var cnt=0;
   var itobject=document.getElementById('result');
    for(var childItem in itobject.childNodes){
     if(itobject.childNodes[childItem].nodeType==1){//backup,save position settings 
       olds[cnt]={
id:itobject.childNodes[childItem].id,
left:itobject.childNodes[childItem].style.left,
top:itobject.childNodes[childItem].style.top,
width:itobject.childNodes[childItem].style.width,
height:itobject.childNodes[childItem].style.height,
zIndex:itobject.childNodes[childItem].style.zIndex
       };
       cnt++;
     } 
    }         
   var upp=-1;
   var upneed=''; 
   if((upp=rdrt.indexOf('upneed='))!=-1){//look for changed el                                           
    var upn=rdrt.indexOf('>',upp);
    upneed=(rdrt.substring(upp+7,upn));
   }                                  
   if(upp!=-1&&upneed){//finded  
    if((upe=rdrt.indexOf('id='+upneed+'_g'))!=-1){//king to die,let's new king                                           
     var upn=rdrt.indexOf('>',upe);
     var upb=rdrt.lastIndexOf('<',upe);
     var upneedval=(rdrt.substring(upb,upn+1));
    }
    if(GetItemById(upneed+'_g') && GetItemById(upneed+'_g').parentNode)GetItemById(upneed+'_g').parentNode.removeChild(GetItemById(upneed+'_g'));
    if(upneedval)GetItemById('result').innerHTML+=upneedval;
   }                 
   else
    GetItemById('result').innerHTML=rdrt;
   GetItemById('umbody').value=rdrt;
   for(i=0;i<cnt;i++){     
    if(olds[i].id){
     itobject=document.getElementById(olds[i].id);
     if(itobject){with(itobject){//return backuped save
		  style.position='absolute';
      style.left=olds[i].left;
      style.height=olds[i].height;
      style.width=olds[i].width;
      style.top=olds[i].top;
      style.zIndex=olds[i].zIndex;
//			move=0;
     }}
    }  
   }
//	 alert(1);
   onchangeresult();
  } 
  gscrp(reqd.responseText);
//	rtype=0;ob=0;
 }
}

//--------------

       
var curid='$um->umid';var reqmb;                                                                                                                           
function selready()
{                                                                               
 id=curid;
 if(document.selection)
  var rtext=document.selection.createRange().text;
 else
  if(window.getSelection)
   var rtext=window.getSelection();
 GetItemById('adv_'+id).innerHTML=GetItemById('edfr_'+id).innerHTML;  
 sndtoedit(id,rtext,1);
}                
function editwk(id){
 curid=id;
 obj=GetItemById('adv_'+id);
 obj.innerHTML='<span class=advs>выделите фрагмент:</span> <a href=\"#\" onclick=\"GetItemById(\'adv_\'+'+id+').innerHTML=GetItemById(\'edfr_\'+'+id+').innerHTML;return false;\">отменить</a> <div id=edfr_'+id+' style=\"border:green 2px dashed;height:400px;OVERFLOW:auto;\" onselectstart=\"this.onmouseup=function(){selready();}\">'+obj.innerHTML+'</div>';
 GetItemById('editwkb_'+id).onclick='return false;';
}
function sndtoedit(id,text,mode,dp){ 
 reqmb=GetRPCObject(edformres);
 if(!reqmb)return;reqmb.open('GET','/postum?tt=8&mode='+encodeURIComponent(mode)+'&data='+encodeURIComponent(id)+'&text='+encodeURIComponent(text)+'&dp='+encodeURIComponent(dp),true);reqmb.send('');
}                           
function edformres(){if(reqmb.readyState==4){id=curid;     
  var tts=GetItemById('adv_'+id);
  tts.innerHTML=reqmb.responseText;//gscrp(reqmb.responseText);
 }
} 

var reqrm;
function ratemore(id,mode){  
 reqrm=GetRPCObject(rmoreres);
 if(!reqrm)return;reqrm.open('GET','/postum?tt=12&mode='+encodeURIComponent(mode)+'&data='+encodeURIComponent(id),true);reqrm.send('');
 return false;
}                           
function rmoreres(){if(reqrm.readyState==4){id=curid;     
  gscrp(reqrm.responseText);
 }
} 

function selit(umid,picname)
{
 Set_Cookie('podsel',picname,'5','/','','');
// upres('1230','0');
 postanswer('updatevisitka','1230','umpic','');
 curimage=GetItemById(picname);
 GetItemById('umpic').value=picname;
// dophoto('object selected','message');
}                                                  
var JSON=JSON||{};
JSON.stringify=JSON.stringify||function(obj){var t=typeof(obj);
if(t!="object"||obj===null){if(t=="string")obj='"'+obj+'"';
return String(obj);}else{var n,v,json=[],arr=(obj&&obj.constructor==Array);
for(n in obj){v=obj[n];t=typeof(v);if(t=="string")v='"'+v+'"';else if(t=="object"&&v!==null)v=JSON.stringify(v);
json.push((arr?"":'"'+n+'":')+String(v));}return (arr?"[":"{")+String(json)+(arr?"]":"}");}};
JSON.parse=JSON.parse||function(str){if(str==="")str='""';eval("var p="+str+";");return p;};

function Set_Cookie(name,value,expires,path,domain,secure){
// if(escape(value)=='object')alert(value);;
 var today=new Date();
 today.setTime(today.getTime());
 if(expires){expires=expires*1000*60*60*24;}
 var expires_date=new Date(today.getTime()+(expires));
 document.cookie=name+"="+escape(value)+
 ((expires) ? ";expires="+ expires_date.toGMTString():"")+
 ((path)?";path="+path:"")+
 ((domain)?";domain="+domain:"")+
 ((secure)?";secure":"");
}
function Get_Cookie(check_name){
	var a_all_cookies=document.cookie.split(';');
	var a_temp_cookie='';
	var cookie_name='';
	var cookie_value='';
	var b_cookie_found=false;
	for(i=0;i<a_all_cookies.length;i++){
	 a_temp_cookie = a_all_cookies[i].split('=');
	 cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g,'');
		if(cookie_name==check_name){
			b_cookie_found=true;
			if(a_temp_cookie.length>1){
				cookie_value=unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g,''));
			}
			return cookie_value;
			break;
		}
		a_temp_cookie=null;
		cookie_name='';
	}
	if(!b_cookie_found){
		return null;
	}
}
var pl;
var moe=null;
var flagtut=0;
function veonover(md){
 if(rtype&&ob)return;
 moe=md;
 pl=1;
 md.move=1;
 with(md.style){
 cursor='move';
 paddingLeft='0px';
 paddingTop='0px';
 border='#909090 1px dotted';
 top=(md.offsetTop-pl)+'px';
 left=(md.offsetLeft-pl)+'px';
 } 
}

function revcc(){
 if(!flagtut)if(GetItemById('mw_'))GetItemById('visualeditor').removeChild(GetItemById('mw_'));
}

function veonout(md){
// setTimeout(revcc,500);
 if((rtype&&ob)||moe!=md)return;
 if(md.move){
  with(md.style){
  cursor='default'; 
  border='0';
  top=(md.offsetTop+pl)+'px';
  left=(md.offsetLeft+pl)+'px';
  }
  moe=null;
  md.move='';
 }
}
function veonmit(md,tp){
// md.style.cursor='move';
 if(tp==3)
  md.style.border='#909090 1px dashed';
 if(tp==4)
  md.style.border='#909090 1px dotted';
}

function getpageinfo(tp,id){
 var tt=80;
 reqd=GetRPCObject(postedready);
 if(!reqd)return;
 reqd.open('POST','/postum?tt='+tt+'&tp='+tp+'&data='+encodeURIComponent(id),true);
 reqd.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
 reqd.send('');
}

var mainsfx;var curname='';var curimage='';                                   
function imgalt(name){
 iframex.document.getElementById(name).alt=GetItemById('picdescr').value; 
 mainsfx.parentNode.removeChild(mainsfx);
 shadescr(0); 
}
function imgaddlink(name){
 iframex.document.body.innerHTML+='<img id="name" width=20px height=20px border=0px src="'+GetItemById('piclink').value+'" alt="'+GetItemById('picdescr').value+'">';
 mainsfx.parentNode.removeChild(mainsfx);
 shadescr(0); 
}
function closemainsfx(name){
 if(GetItemById('mainsfx_'+name))
  GetItemById('mainsfx_'+name).parentNode.removeChild(GetItemById('mainsfx_'+name));
 if(GetItemById(name) && name!='body')
  GetItemById(name).parentNode.removeChild(GetItemById(name));
 shadescr(0); 
}
function wheel(){return false;}
function setwheel_(stat_){if(stat_){if(GetItemById('body').addEventListener)GetItemById('body').addEventListener('DOMMouseScroll',wheel,false);GetItemById('body').onmousewheel=wheel;}else {if(GetItemById('body').addEventListener)GetItemById('body').addEventListener('DOMMouseScroll',null,false);GetItemById('body').onmousewheel=null;}}
function shadescr(showt){
 setwheel_(showt);
 name='shade';
 if(showt){                    
  if(GetItemById('mshade_'+name))
   GetItemById('mshade_'+name).parentNode.removeChild(GetItemById('mshade_'+name));
  mshade=document.createElement("DIV");
  mshade.id="mshade_"+name;
	with(mshade.style){
  zIndex="10001";
  paddingRight="0px";
  paddingLeft="0px";
  paddingTop="0px";
  paddingBottom="0px";
  visibility="visible";
  position="fixed";
  backgroundColor="white";
  borderRight="black 0px solid";
  borderLeft="black 0px solid";
  borderTop="black 0px solid";
  borderBottom="black 0px solid";
  fontSize="10pt";
  left="0px";
  top="0px";
  width="100%";
  height="100%";
  textAlign="left";
  paddingLeft="0px";
  paddingRignt="0px";
  KhtmlOpacity="0.8";
  MozOpacity="0.8";
  filter="filter:alpha(opacity=80);";
  filter="progid:DXImageTransform.Microsoft.Alpha(opacity=80);";  
  Opacity="0.8";
  opacity="0.8";
  background="#777777";
	}
  mshade.Opacity="0.8";
  mshade.align="left";
  mshade.innerHTML="";
  document.body.appendChild(mshade);
 }
 else{
  if(GetItemById('mshade_'+name))
   GetItemById('mshade_'+name).parentNode.removeChild(GetItemById('mshade_'+name));
 } 
}

function offit(e){
 var key; 
 if(window.event){e=window.event;ctrl=event.ctrlKey;key=event.keyCode;}
 else if(e){ctrl=(Event.META_MASK||Event.CTRL_MASK);key=e.keyCode;}
 if(!key)key=e.which;
 if(key==27)
  closemainsfx(curname); 
}

function dophoto(bname,type){
 curname=bname;
 shadescr(1);
 if(type){              
  var mr=GetItemById('umbody');
  if(bname && (type=="property" || type=="addphotolist")){
   var gdata=iframex.document.getElementById(bname);
	} 
  else
   var gdata=null;
  if(mr&&gdata){	 
   mr.style.width='0px';mr.style.height='0px';mr.style.display='block';
   cpx=addoffsetLeft(mr);cpy=(addoffsetTop(mr)-addscrollTop(mr))/2;
  }
  else
  {cpx=ccx;cpy=ccy;} 
  if(GetItemById('mainsfx_'+bname))
   GetItemById('mainsfx_'+bname).parentNode.removeChild(GetItemById('mainsfx_'+bname));
  mainsfx=document.createElement("DIV");
  mainsfx.id="mainsfx_"+bname;
  moveid=mainsfx.id;
	with(mainsfx.style){
   zIndex="10002";
   paddingRight="0px";
   paddingLeft="0px";
   paddingTop="0px";
   paddingBottom="0px";
   visibility="visible";
   position="fixed";
   backgroundColor="white";
   borderRight="black 1px solid";
   borderLeft="black 1px solid";
   borderTop="black 1px solid";
   borderBottom="black 1px solid";
   fontSize="10pt";
   left=cpx+((gdata!=null)?addoffsetLeft(gdata):0)+"px";	
   top=cpy+((gdata!=null)?gdata.offsetHeight:0)-1+"px";
   width=400+"px";
   textAlign="left";
   paddingLeft="0px";
   paddingRignt="0px";
	} 
  mainsfx.align="left";
	unselheader='<div unselectable="on" id="moveit" style="width:359px;text-align:center;display:inline-block;float:left;-moz-user-select:none;user-select:none;-khtml-user-select:none;-webkit-user-select:none">';
 if(type=='property'){ 
  mainsfx.innerHTML='<div style="padding-top:3px;padding-bottom:3px;background:#126382;width:100%;color:#ffffff;font-weight:bold;-moz-user-select:none;user-select:none;" '  
  + ' onmouseover="this.style.cursor=\'move\';" onmouseout="this.style.cursor=\'default\';" id="moveit">'
  + unselheader+'pic propertis ' 
  + bname + '</div>'
  + '<div style="width:39px;display:inline-block;text-align:right" id="moveit"><a href="#" onclick="closemainsfx(\''+bname+'\');return false;" style="color:#ffffff;font-weight:bold">[x]</a></div></div>'
  + '<div style="text-align:center"><form style="padding:0px;margin:0px" enctype="multipart/form-data" name="altsub" id="altsub" method=post action="javascript:imgalt(\'' 
  + bname + '\'); "><br><br>'+'pic description'+': <input name=picdescr id=picdescr><br><br><input type=submit value=submit></form><br><br></div>';
  document.body.appendChild(mainsfx);
  if(gdata&&gdata.alt)GetItemById('picdescr').value=gdata.alt;
  GetItemById('picdescr').focus();  
 }                
 if(type=='addphotolist'){              
  mainsfx.innerHTML='<div unselectable="on" style="padding-top:3px;padding-bottom:3px;background:#126382;width:100%;color:#ffffff;font-weight:bold;-moz-user-select:none;user-select:none;-khtml-user-select:none;-webkit-user-select:none" '
  + ' onmouseover="this.style.cursor=\'move\';" onmouseout="this.style.cursor=\'default\';" id="moveit\">'
  + unselheader+'pic position '
  + bname+'</div><div unselectable="on" style="width:39px;display:inline-block;text-align:right;-moz-user-select:none;user-select:none;-khtml-user-select:none;-webkit-user-select:none" id="moveit"><a href="#" onclick="closemainsfx(\''
  + bname+'\');return false;" style="color:#ffffff;font-weight:bold">[x]</a></div></div>'
  + "<div style=\"text-align:center\"><form style=\"padding:0px;margin:0px\" enctype=\"multipart/form-data\" name=\"altsub\" id=\"altsub\" method=post action=\"javascript: imgaddlink('"+bname+"'); \"><br><br>link: <input name=piclink id=piclink><br>description: <input name=picdescr id=picdescr><br><br><input type=submit value=submit></form><br><br></div>";
  document.body.appendChild(mainsfx);
//  GetItemById('picdescr').value=gdata.alt;
//  GetItemById('piclink').value=gdata.src;
  GetItemById('piclink').focus();  
 }
 if(type=='message'){              
  mainsfx.innerHTML="<div style=\"padding-top:3px;padding-bottom:3px;background:#126382;width:100%;color:#ffffff;font-weight:bold;-moz-user-select:none;user-select:none;\"" 
  + ' onmouseover="this.style.cursor=\'move\';" onmouseout="this.style.cursor=\'default\';" id="moveit">'+
	+unselheader+'message: '+bname+'</div><div style="width:39px;display:inline-block;text-align:right" id="moveit"><a href="#" onclick="closemainsfx(\''+bname+'\');return false;" style="color:#ffffff;font-weight:bold">[x]</a></div></div>';
  mainsfx.innerHTML+="<div style=\"text-align:center\"><form style=\"padding:0px;margin:0px\" enctype=\"multipart/form-data\" name=\"altsub\" id=\"altsub\" method=post action=\"javascript: closemainsfx('"+bname+"'); \"><br><br>"+bname+"<br><br><input type=submit value=ok id=submitit></form><br><br></div>";
  document.body.appendChild(mainsfx);
  GetItemById('submitit').focus();  
 }
 }                
}
function setopacity(obj,op){
 with(obj.style){
 KhtmlOpacity=op;
 MozOpacity=op;
 filter="filter:alpha(opacity="+(100*op)+");";
 filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+(100*op)+");";  
 Opacity=op;
 opacity=op;
 }
 obj.Opacity=op;
}                     
function testrange(obj){
 resl=GetItemById('result');
 var ch=false;
 if(resl&&ob&&ob.style.zIndex<10000){                  
  var sX=0;var sY=0;if(ob.style.position=='absolute'){if(document.documentElement && document.documentElement.scrollTop){sX=document.documentElement.scrollLeft;sY=document.documentElement.scrollTop}
  else {sX=document.body.scrollLeft;sY=document.body.scrollTop;}} 
  var relx=0;var rely=0;      
  if(obj){rely=addoffsetTop(obj);relx=addoffsetLeft(obj);}
  var basehere=GetItemById('basehere');
  var top=0;var left=0;  
  if(event.clientX-X-relx+sX<left)
   {ob.style.left=left+sX+'px';ch=true;} 
  if(event.clientY-Y-rely+sY<top)
   {ob.style.top=top+'px';ch=true;}
  var right=left+resl.offsetWidth;  
  var bottom=top+resl.offsetHeight;   
  if(basehere)
  {basehere.style.top=top+sY;basehere.style.left=left+sX;basehere.style.right=right;basehere.style.bottom=bottom;} 
  if(event.clientX-X-relx+ob.offsetWidth+sX>right)
   {ob.style.left=right-ob.offsetWidth+2+sX+'px';ch=true;} 
  if(event.clientY-Y-rely+ob.offsetHeight+sY>bottom)
   {ob.style.top=bottom-ob.offsetHeight+2+'px';ch=true;} 
 }
 return ch;
}
function addphotolist(){dophoto('body','addphotolist')};
function setcurimage(imgname){curimage=imgname;return false;niframe=frames.umfiles;curimage=niframe.document.getElementById(imgname);}     
var ob;var X=0;var Y=0;var moveid=null;var fe=0;var ccx;var ccy;var rtype;var cursel=null;var lastselname=null;
function MD(e){if(!document.getElementById){ob=document.layers[e.target.name];X=e.x;Y=e.y;return false;}
else{if(e)event=e;if(event&&!event.srcElement&&event.target)event.srcElement=event.target;if(!event)return true;ob=event.srcElement;if(ob.className!='wsigso')cursel=ob;if(ob.style.zIndex==10001)ob=null;//if(ob.id!="umfiles" && ob.id!="umbody")alert(ob.id);
 if(ob&&typeof(toolset)!='undefined')toolset(ob);
if(ob&&ob.id&&ob==curimage);else
while(ob&&((ob.id!=moveid&&ob.id=='moveit')))ob=ob.parentNode;if(ob&&ob.id&&(ob.id==moveid||ob==curimage))setopacity(ob,0.8);
X=event.offsetX;Y=event.offsetY;if(event.layerX){X=event.layerX;Y=event.layerY;}
if(fe)ob=null;if(ob&&((ob.parentNode&&ob.parentNode.id)=='result'||ob.id=='moveit'||ob==curimage||moe))return false;
}}
function returnFalse(){return false;}
function MM(e){if(e)event=e;
if(event && !event.srcElement&&event.target)
 event.srcElement=event.target;
 if(event.srcElement && event.srcElement.id=='moveit'){
  event.srcElement.onselectstart=function(){return false};
// document.onselectstart=function(){return false};
// event.style.cursor='move';alert(1);
 }
if(event){ccx=event.clientX;ccy=event.clientY;}
if(moe||rtype){// resize and move
 var relx=0;var rely=0;obj=GetItemById('result');if(obj){rely=addoffsetTop(obj);relx=addoffsetLeft(obj);}
 if(!ob&&moe){
  if(Math.abs(ccx+2-relx-moe.offsetLeft-moe.offsetWidth)<=3 && Math.abs(ccy+2-rely-moe.offsetTop-moe.offsetHeight)<=3){
   moe.style.cursor='nw-resize';
   rtype='rightbottom';
  }else 
  if(Math.abs(ccx-relx-moe.offsetLeft)<=3){
   moe.style.cursor='w-resize';
   rtype='left';
  }else 
  if(Math.abs(ccx+2-relx-moe.offsetLeft-moe.offsetWidth)<=3){
   moe.style.cursor='w-resize';
   rtype='right';
  }else
  if(Math.abs(ccy+2-rely-moe.offsetTop-moe.offsetHeight)<=3){ 
   rtype='bottom';
   moe.style.cursor='n-resize';
  }else 
  if(Math.abs(ccy-rely-moe.offsetTop)<=3){
   moe.style.cursor='n-resize';
   rtype='top';
  }else{
   moe.style.cursor='move';
   rtype='';
  }
 }  
 if(ob&&rtype&&moe){           
  if((rtype=='right'||rtype=='rightbottom')&&ccx-relx<obj.offsetWidth)
   {ob.style.width=ccx-relx-ob.offsetLeft+"px";}
  if(rtype=='left'&&ccx-relx>0 && moe.offsetWidth+(moe.offsetLeft-(ccx-relx+2))>0)
  {left=moe.offsetLeft+"px";moe.style.left=ccx-relx;moe.style.width=moe.offsetWidth+(left-(ccx-relx+2))+"px";}
  if((rtype=='bottom'||rtype=='rightbottom')&&ccy-rely<obj.offsetHeight)
   moe.style.height=ccy-rely-moe.offsetTop+"px";
  return false; 
 }
}
if(ob&&!rtype){if(!document.getElementById){ob.moveTo((e.pageX-X),(e.pageY-Y));}else
{obj=ob;while(obj&&(obj.id!='result'))obj=obj.parentNode;var relx=0;var rely=0;if(obj&&obj.id=='result'){rely=addoffsetTop(obj);relx=addoffsetLeft(obj);}
if(ob&&ob.style&&ob.style.position&&ob.style.position!='absolute'&&ob.style.position!='fixed')return true;                                   
var sX=0;var sY=0;if(ob&&ob.style&&ob.style.position=='absolute'){if(document.documentElement&&document.documentElement.scrollTop){sX=document.documentElement.scrollLeft;sY=document.documentElement.scrollTop}//||ob.style.position=='fixed' 
else {sX=document.body.scrollLeft;sY=document.body.scrollTop;}}
if(ob&&ob.style){ob.style.left=(event.clientX-X-relx+sX)+"px";ob.style.top=(event.clientY-Y-rely+sY)+"px";}
if(ob||moe)return testrange(obj);
}} if(ob||moe) return false;} 

function MU(){
var post='';if(ob&&ob.id&&ob.id.indexOf('_g')!=-1){lastselname=ob.id;setmenuopt();}
if(ob&&ob.id&&(ob.id==moveid||ob==curimage))setopacity(ob,1);
 if(ob&&typeof(toolset)!='undefined')toolset(ob);
var oldob=ob;ob=null;if(moe && rtype){post=rtype;rtype='';veonout(moe)};//?veonout
//if(GetItemById('umbody')&&GetItemById('result')){GetItemById('umbody').value=GetItemById('result').innerHTML;}
if(post){var igname=oldob.id.replace('_g','');if(oldob.id!='cropbar_g')setTimeout('postanswer(\'updatevisitka\',1230,\''+igname+'\',\'\')',100);}
}

wmvi=function(){//if(!document.getElementById){document.captureEvents(Event.MOUSEDOWN|Event.MOUSEMOVE|Event.MOUSEUP);}
 document.onmousedown=MD;
 document.onmousemove=MM;
 window.onmousemove=MM;
 //document.addEventListener("mousemove", MM, false);
 document.onmouseup=MU;
 if(typeof(gets)=='undefined' && typeof(getn)=='undefined'){// window.onkeydown=offit;// document.onkeydown=offit;
 }
}
function showit(id){if(!GetItemById(id+'_w'))return;
 var d=GetItemById(id+'_w').style;d.visibility='visible';d.display='block';setTimeout('hili(\''+id+'\',\''+GetItemById(id).style.background+'\',5);',50);return false; 
}
function hili(id,color,tm){car=Array('#ffffff','#fefefe','#e1e1e1','#a1a1a1','#888888','#777777');
 var d=GetItemById(id).style;d.background=car[tm];tm--;if(tm>=0)setTimeout('hili(\''+id+'\',\''+color+'\','+tm+');',60);//else d.background=color;
}
var fall=0;
offall=function(){
 var curt=0; 
 ts=document.getElementsByTagName('span');
 for(i=0;i<ts.length;i++)
 if(ts[i].className=='mlk_t'){
 	for(p=0;p<ts[i].childNodes.length;p++)
   if(ts[i].childNodes[p].className=='curt')
	  curt=1;
	ts[i].style.display='none';
  if(!fall && curt ){with(ts[i].style){position='absolute';top='70px';left='30%';display='block';}}
 }
 fall=1;	
}
offall();
ts=document.getElementsByTagName('a');
for(i=0;i<ts.length;i++)
 if( (ts[i].className=='ncurt' || ts[i].className=='curt') && ts[i].id.substring(0,4)=='mmt_' ){
  ts[i].onmouseover=function(){num=this.id.substring(4,this.id.length);if(at=document.getElementById('mt_'+num)){offall();
	 with(at.style){
	  position='absolute';
		top='70px';
		left='30%';
	  display='block';
	 }
	} };
}	
function thide(id,mode,o){
 if($_(id).me20==1)return;
 if(!$_(id).me20)$_(id).me20=20;
 setTimeout('thide(\''+id+'\',\''+mode+'\',\''+o+'\')',50);
 $_(id).me20--;
 $_(id).setheight=$_(id).offsetHeight;
 if(o==3)
  wth=($_(id).offsetWidth-5*(20-$_(id).me20));
 if(o==1)
  left=-($_(id).offsetWidth-5*(20-$_(id).me20));
 if($_(id).style)
 with($_(id).style){
  if(wth>0)width=wth+'px';else width=0;
  height=($_(id).setheight)+'px';
  overflow='hidden';
  whitespace='nowrap';
  opacity=($_(id).me20/20);if(opacity<=1/19)display="none";
  filter='alpha(opacity='+Math.ceil($_(id).me20*100/20)+')';
 }	
 return false;
}

function hirite(mode){
// if(mode)GetItemById('hrite').style.display="block";else GetItemById('hrite').style.display="none";return false;
 thide('hrite',mode,'3');
 if($_('rtags')){
  thide('rtags',mode,'3');
	if($_('rtags').parentNode)
  $_('rtags').parentNode.style.width='0px';
 } 
 return false;
}
function hileft(mode){
// $_('hleft').style.overflow='hidden';
 if($_('hleft')){
 $_('hleft').style.position="absolute"; 
 $_('hleft').style.width='300px'; 
 thide('hleft',mode,'3');
 }
 if($_('tags')){
 $_('tags').style.position="absolute"; 
 $_('tags').style.width='300px'; 
 thide('tags',mode,'3');
 }
 if($_('brands')){
 $_('brands').style.position="absolute"; 
 $_('brands').style.width='300px'; 
 thide('brands',mode,'3');
 }
 if($_('vtop'))thide('vtop',mode,'3');
 return false;
}

remcart=function(ummark,umsize){
 if(Get_Cookie('carts_a')){
  if(ummark=='' && umsize==''){
	 carts_a=Array();
   jsons=JSON.stringify(carts_a);
   Set_Cookie('carts_a',jsons,'5','/','','');
	 savecart();
   printcart();
	 return false;
   return;
	}
  jsons=Get_Cookie('carts_a');
	carts_a=JSON.parse(jsons);
  for(i=0;i<carts_a.length;i++)
   if(carts_a[i].ummark==ummark && carts_a[i].umsize==umsize)
 	  del=carts_a.splice(i,1);
  jsons=JSON.stringify(carts_a);
  Set_Cookie('carts_a',jsons,'5','/','','');
	savecart();
 }
 printcart();
 return false;
};
selcart=function(umid,tp,umdep,ummark,umsize,umcount,umgamma,ummodel,umprice){var noadd=0;
 if(Get_Cookie('carts_a')){
  GetItemById('carts').innerHTML='';
  jsons=Get_Cookie('carts_a');
	carts_a=JSON.parse(jsons);
 }
 if(carts_a.length>=14)alert('Limit 14 item lines per one invoice');
 for(i=0;i<carts_a.length;i++)
  if(carts_a[i].ummark==GetItemById(ummark).value && (!GetItemById(umsize) || carts_a[i].umsize==GetItemById(umsize).value) )
	{carts_a[i].umcount=Math.pow(carts_a[i].umcount,1)+Math.pow(GetItemById(umcount).value,1);noadd=1;}
 if(!noadd)	
 carts_a[carts_a.length]={
  umid:umid,
  tp:tp,
  umdep:umdep,
  ummark:GetItemById(ummark).value,
  umsize:GetItemById(umsize)?GetItemById(umsize).value:'',
  umcount:GetItemById(umcount).value,
  umgamma:GetItemById(umgamma)?GetItemById(umgamma).value:'',
  ummodel:GetItemById(ummodel)?GetItemById(ummodel).value:'',
  umprice:GetItemById(umprice).value
 }
 var jsons=JSON.stringify(carts_a);
 Set_Cookie('carts_a',jsons,'5','/','',''); 
 savecart();
 printcart();
};
var listenarr=Array();
var isinactive=0;
var carts_a=Array();
changelike=function(id1,id2){
 if(GetItemById(id1)&&GetItemById(id2))
  GetItemById(id2).selectedIndex=GetItemById(id1).selectedIndex;
};
recalccart=function(){
 if(Get_Cookie('carts_a')){
  jsons=Get_Cookie('carts_a');
	carts_a=JSON.parse(jsons);
	totalcost=0;
	totalcount=0;
	if(carts_a.length>0){
   for(i=0;i<carts_a.length;i++){
	  carts_a[i].umcount=GetItemById('countval_'+carts_a[i].ummark+'_'+carts_a[i].umsize).value;
		GetItemById('sumval_'+carts_a[i].ummark+'_'+carts_a[i].umsize).innerHTML=Math.pow(carts_a[i].umprice*carts_a[i].umcount,1);
	  totalcount+=Math.pow(carts_a[i].umcount,1);
	  totalcost+=Math.pow(carts_a[i].umprice*carts_a[i].umcount,1);
	 }
	 changesum(totalcount,totalcost);
   jsons=JSON.stringify(carts_a);
   Set_Cookie('carts_a',jsons,'5','/','','');
	 savecart();
	}
 }	 
}
eventrecalcattach=function(id){
 listenarr[listenarr.length]=id;
 GetItemById(id).onblur=function(){isinactive=0;};
 GetItemById(id).onfocus=function(){isinactive=1;};
}
cartshow=function(){
 if(Get_Cookie('carts_a')){
  jsons=Get_Cookie('carts_a');
	carts_a=JSON.parse(jsons);
 }
 return false;
}
savecart=function(){
 if(Get_Cookie('carts_a')){
  jsons=Get_Cookie('carts_a');
	if(GetItemById('umwaredescription'))GetItemById('umwaredescription').value=jsons;
 }
}

