/*function ppwin(p,id) {
    if ( ppWH && !ppWH.closed )ppWH.close();
    ppWH = window.open("/x/popup.php?p="+p+"&id="+id, "ppWH", "depent=yes, status=no, toolbar=no, menubar=no,scrollbars=no, resizable=yes, width=100, height=100"+getPosParams(100,100));
    ppWH.focus();
}*/
/*
* mod - название модуля
* part - часть модуля (так как может быть несколько оформлений) для каждого модуля
* id   - идентификатор
*/
var ppWH=null;
function pwin(mod,part,id,modid) {
    if ( ppWH && !ppWH.closed )ppWH.close();
    ppWH = window.open("/x/popup.php?mod="+mod+"&part="+part+"&id="+id+"&modid="+modid+"&js=1", "ppWH", "depent=yes, status=yes, toolbar=no, menubar=no,scrollbars=yes, resizable=yes, width=100, height=100"+getPosParams(100,100));
    ppWH.focus();
}
function getPosParams(w,h){
    var l=(screen.availWidth-w)/2;
    var t=(screen.availHeight-h)/2;
    return " top="+t+", left="+l+", screenY="+t+", screenX="+l;
}

var newwindow = ''

function popitup(url, w, h) {
	if (newwindow.location && !newwindow.closed) 
	{ newwindow.location.href = url; newwindow.focus(); } 
else 
	{ newwindow=window.open(url,'htmlname','width=' + w + ',height=' + h + ',resizable=1') ; }
}

function tidy()
{
if (newwindow.location && !newwindow.closed) { newwindow.close(); } 
}

//Routines specifically for popup feedback windows

var fbwindow
function fbpopitup(url) {
if (fbwindow && !fbwindow.closed) 
	{ fbwindow.location.href = url; fbwindow.focus(); } 
else 
	{ fbwindow=window.open(url,'fhtmlname','width=520,height=420,resizable=1,scrollbars=1,top=50,left=10'); }
}
function fbtidy(){
if (fbwindow && !fbwindow.closed) {fbwindow.close(); } }
// Based on JavaScript provided by Peter Curtis at www.pcurtis.com -->

/*
    Изменяет размер окна
*/
var edWH=null,_d=document,_s=self,_t=top,_sd=self.document,_td=top.document,_so=self.opener,_sod=self.opener!=null?self.opener.document:null;_sow=self.opener!=null?self.opener.window:null;

function getElById(e){
    return _sd.getElementById(e);
}
function _getElById(e){
    return _td.getElementById(e);
}
function get_el_by_id(e,o){
    return o.getElementById(e);
}
var piclibWH = null;
function wResize(w,h){
window.resizeTo(w,h);
window.moveTo((screen.availWidth-w)/2,(screen.availHeight-h)/2);
}
function sh_easy_design(u){
   if ( edWH && !edWH.closed )edWH.close();
   edWH = window.open(u, "edWH", "depent=yes, status=yes, toolbar=no, menubar=no,scrollbars=yes,resizable=yes,"+getAvailSize());
   edWH.focus();
}
function getAvailSize(){
    var w=screen.availWidth-30;
    var h=screen.availHeight-20;
    var l=(screen.availWidth-w)/2;
    var t=(screen.availHeight-h)/2;
    return " width="+w+", heihgt="+h+", top="+t+", left="+l+", screenY="+t+", screenX="+l;
}
function getPosParams(w,h){
    var l=(screen.availWidth-w)/2;
    var t=(screen.availHeight-h)/2;
    return " top="+t+", left="+l+", screenY="+t+", screenX="+l;
}
function sbmt(form,action,check)
{
  var obj=document;

  if(obj[form].action!=null){
     obj[form].action.value=action;
  }
  if ( check != null ){
    if (chck(form,check)){ obj[form].submit(); }
  } else{
    obj[form].submit();
  }
}
/**
 *  Возвращает тип элемента
 */
function getElementType(form,element){
  var ob = document[form];
  try{
    var obj = ob[element];
    if ( obj!=null ) {
        if(obj.length!=null) {
            if(obj[0].type) {
                return obj[0].type;
            }
        } else {
            return obj.type;
        }
    }
  }catch(e){
    return;
  }
}
/*
* Возвращает значение элемента
*/
function formElementValue(form,element)
{
  var ob=document[form];

  try{
    var obj=ob[element];

    if(obj.type=='checkbox'||obj.type=='radio'){
        if(obj.checked)return 1;else return 0;
    }else {
        if (obj[0]) {
            if(obj[0].type=='checkbox'||obj[0].type=='radio'){
                if(obj.length!=null){
                    for(var i=0;i<obj.length;i++){
                        if(obj[i].checked) return 1;
                    }
                    return null;
            } else {
                    return null;
                }
            }
        }else{
        if (obj.type=='select'){
            return obj.selected;
        }else{
            return obj.value;
        }
        }
    }
  }catch(e){
    return null;
  }
}
//suxx
function chk(s,r){return s.match(r);}

/*
* В функцию передается два параметра это имя формы, и массив.
* Фармат массива;
* [[ПОЛЕ1,ПОЛЕ2,ЧТО ВЫВЕСТИ НА ЭКРАН,ПАРАМЕТР]]
*
* ПОЛЕ1, ПОЛЕ2 - поля формы для проверки, если необходимо проверить
* только одно поле то ПОЛЕ2 должно быть нулевым.
*
* ПАРАМЕТР:
*  default  - Это значит, что если параметр не соответствует приведенным
*             типам то делается проверка ПОЛЯ1 на соответствие регулярному
*             выражению щаписанному в ПАРАМЕТР
*  '=='     - Проверить на равенство поля ПОЛЕ1 и ПОЛЕ2
*  '!='     - Проверить на неравенство поля ПОЛЕ1 и ПОЛЕ2
*  '<'      - ПОЛЕ1 меньше ПОЛЕ2
*  '>'      - ПОЛЕ1 меньше ПОЛЕ2
* 'null'    - Проверить на пустоту ПОЛЕ11
* 'warn'    - Поля в данной конструкции не участвуют, просто выводится предупреждение.
*/
function chck(form,a)
{
  var v1=null,v2=null,flg=0,flg2=0, ob;
  for(i=0;i<a.length;i++){

    ob = document[form];

    v1 = formElementValue(form,a[i][0]);
    v2 = formElementValue(form,a[i][1]);
    if(v2==null){v2=a[i][1];}

    switch(a[i][3]){
      case '<l':if(v1.length>v2){flg=1}break;
      case '>l':if(v1.length<v2){flg=1}break;
      case '==':if(v1!=v2){flg=1}break;
      case '!=':if(v1==v2){flg=1}break;
      case '<':if(v1>v2){flg=1}break;
      case '>':if(v1<v2){flg=1}break;
      case 'null':if(v1==''||v1==null){flg=1}break;
      case 'warn':if(!confirm(a[i][2])){return;}break;
      default:if(!chk(v1,a[i][1])){flg=true}
    }

    if (flg){
        if(a[i][4]=='warn'){
            return confirm(a[i][2]);
        }else{
            var elt=getElementType(form,a[i][0]);
            if(elt!='checkbox'&&elt!='radio'&&elt!='hidden'){
            ob[a[i][0]].focus();
            }
            return alert(a[i][2]);
        }
    }
  }
  return true;
}

function getObjElem(obj,out) {
    var result='';
    for(var i in obj){
        result += i+"="+obj[i]+"\r<br />";
    }
    if ( out != null && out != '' ) {
        out=result;
    } else {
        return result;
    }
}

function xtitle(obj){
	if(obj==null||obj==undefined)return;
	var text=obj.innerHTML;
	obj.title=text;
	obj.style.cursor='default';
}
function email(domen,name,text){
//    document.write('<a onfocus=this.blur() href=mailto:'+name+'@'+domen+'>'+text+'</a>');
    document.write('<a onfocus=this.blur() href=mailto:'+name+'@'+domen+'>');
}
function _email(domen,name){
    document.write(name+'@'+domen);
}

function close_tag_a(){
    document.write('</a>');
}
function preload(image) {
    var d=document;
    if(!d.img_pre){
        d.img_pre=new Array();
        var l=d.img_pre.length;
        d.img_pre[l]=new Image;
        d.img_pre[l].src=image;
    }
}
