function openImg(src, width, height) {
      var left= (screen.width / 2) - (width / 2);
      var top = (screen.height / 2) - (height / 2);
      wnd = window.open("", "imageWindow", 
            "left=" + left + ",top=" + top + ",width=" + width + ",height=" + height);
      var doc = wnd.document;
      doc.open();
      doc.write('<html><head><title>Большое фото</title></head>' + 
            '<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">' +
            '<img src="' + src + '" width="' + width + '" height="' + height + 
            '" vspace="0" hspace="0">' +
            '<br></body></html>'
            );
      doc.close();
      wnd.focus();
      return false;
}


function openVideo(src) {
      var width=330;
      var height=270;
      var left= (screen.width / 2) - (width / 2);
      var top = (screen.height / 2) - (height / 2);
      wnd = window.open("", "imageWindow", 
            "left=" + left + ",top=" + top + ",width=" + width + ",height=" + height);
      var doc = wnd.document;
      doc.open();
			
      doc.write('<object id="MediaPlayer"' + 
      'classid="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6"' + 
      'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715"' + 
      'standby="Loading Microsoft Windows Media Player components..."' + 
      'type="application/x-oleobject"' + 
      'width="320" height="256">' + 
      '<param name="URL" value="' + src + '">' + 
      '</object>');
			
      doc.close();
      wnd.focus();
      return false;
}


function popup(file,width,height)
{
  window.open(file,"site_path","height="+height+",width="+width+",status=no,location=no,toolbar=no,directories=no,resizable=yes,scrollbars=yes,menubar=no,top=10,left=10");
}

function makeSiteLink(name) {
  if (!window.js_base_url) {
    str = document.location.toString();
    js_base_url = str.replace("/javascript/editor/scripts/hyperlink.htm","");
    js_base_url = js_base_url.replace("/javascript/editor/scripts/moz/hyperlink.htm","");
  }
  popup(js_base_url+'/admin/index.php?mod=tree&action=mini_browser&returnname='+name,'600','400');
}

function retBack(obj, str) {
  window.close();
  obj.value = str;
}

function insertIntoWYSIWYG(str) {
  doc = "window.opener";
  for ( property in eval(doc) ) {
    fullPropertyName = "document."+property;

    if (fullPropertyName.indexOf("document.myStyle")!=-1) {
      objName = fullPropertyName.replace("document.myStyle", "");
      break;
    }
  }
  objName = eval(doc+".window."+objName);
  objName.insertCustomTag(str);
  self.window.close();
}

function check4compare(obj) {
  for(i=0; i<obj.elements.length; i++) if (obj.elements[i].type=="checkbox" && obj.elements[i].checked) return true;
  
  alert('Не выделено ни одного продукта для сравнения');
  return false;
}

function switch_loading_box (box_id) {
  
  if(document.getElementById(box_id).style.display!="none") {
    document.getElementById(box_id).style.display="none";
  }
  else {
    document.getElementById(box_id).style.display="";
    
    var ie=document.all;
    iebody=document.body;
    var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset;
    var docwidth=(ie)? iebody.clientWidth : window.innerWidth;
    docheight=(ie)? iebody.clientHeight: window.innerHeight;
    var objwidth=document.getElementById(box_id).offsetWidth;
    objheight=document.getElementById(box_id).offsetHeight;
    var test=docwidth/2-objwidth/2+"px";

    document.getElementById(box_id).style.left=docwidth/2-objwidth/2+"px";
    document.getElementById(box_id).style.top=scroll_top+docheight/2-objheight/2+"px";
  }
  
  return false;
  
}



_menu  = function(HTMLUList) {
        for (var node = HTMLUList.firstChild; node != null; node = node.nextSibling) {
            if (node.nodeName != 'LI') continue;

            node.onmouseover = function() {
            this.className += ' over';
            }

            node.onmouseout = function() {
                this.className = this.className.replace('over', '');
            }

            if (node.getElementsByTagName('UL').length) {
                
        _menu(node.getElementsByTagName('UL')[0]);

        node.className = 'non-empty';
        
            }
        }
}

var validate = {
	trim : function(str){
		return str.replace(/(^\s+)|(\s+$)/g,"");
	},
	validMail : function(str){
		return str.match(/\b(^([\.0-9a-zA-Z_-]+@[0-9a-zA-Z_\.-]+(\.[a-zA-Z]{2,4}){1,2})$)\b/gi);
	},
	validLatin : function(str){
		return str.match(/\b(^([0-9a-zA-Z_]+)$)\b/gi);
	},
	validNamber : function(str){
		return str.match(/\b(^([0-9]+)$)\b/gi);
	},
	validRur : function(str){
		return str.match(/\b(^([а-яА-Я_]+)$)\b/gi);
	}
}


function validateOtr(form){
	if (validate.trim(form['user_name'].value)==""){
		alert('Введите свое имя');
		form['user_name'].focus();
		return false;
	}
	if (!validate.validMail(form['user_mail'].value)){
		alert('Введите свой e-mail');
		form['user_mail'].focus();
		return false;
	}
	
	return false;
}

// пользовательский объект для проверки на валидность данных форм 


/*function validate(name){
	this.name = name;
	this.trim = function(){
		return 	this.name.replace(/(^\s+)|(\s+$)/g,"");
	}
}*/
