// - Windows --------------------------------------------
var currentWindow;

function closeBackGround(){
	if (document.getElementById('closeFonId'))
		return false;
		
	obj = psCreateDiv('closeFonId');
	obj.className='psCloseBackGround';
	obj.style.height=psGetPageSize()[1]+'px';
	obj.style.width=psGetPageSize()[0]+'px';	
	document.body.style.overflowX="hidden";
}

function psOpenInPopUp (idName,url){
	closeBackGround();

	objWindow =	psCreateDiv('psWindow');
	objWindow.style.position='absolute';
	objWindow.style.zIndex=1100;
	objSrc = document.getElementById(idName);

	if(url){
		psLoadingOn();
		currentWindow = url;		
		reqMain = new JsHttpRequest();
		reqMain.caching = false;
		reqMain.open('GET',url,true);
		var sdata = Array();
		sdata['cmd']='sendlink';
		reqMain.send(sdata);	
		reqMain.onreadystatechange = function(){
			if (reqMain.readyState == 4){
				if (reqMain.responseJS){
					PageContent = reqMain.responseJS.PageContent;
					objWindow.innerHTML = PageContent;
					psPosionPopUp(objWindow);
					psLoadingOff();					
				}
			}
		}		
	}else{
		objWindow.innerHTML = objSrc.innerHTML;
		psPosionPopUp(objWindow);
	}

	return false;
}

function psClosePopUp(){
	psDeleteObj('psWindow');
	psDeleteObj('closeFonId');
	document.body.style.overflowX="auto";	
}

function psPosionPopUp(obj){
	var objTop=(((psGetPageSize()[3]-obj.offsetHeight)/2)+psGetPageScroll());
	var objLeft=((psGetPageSize()[0]-obj.offsetWidth)/2);
	obj.style.top = (objTop<=0)?'0px':objTop+'px';
	obj.style.left = (objLeft<=0)?'0px':objLeft+'px';	
}

function psLoadingOn(){
	closeBackGround();
	objLoader = psCreateDiv('psLoader');
	objLoader.innerHTML = 'Загрузка';
	psPosionPopUp(objLoader);
}

function psLoadingOff()
{
	psDeleteObj('psLoader');
}

function psPopImg(obj) {
	psLoadingOn();
	i = new Image();
	i.src = obj.href;
	i.style.cursor = 'pointer';
	i.onload = function(){
		objWindow =	psCreateDiv('psWindow');
		objWindow.appendChild(i);
		psLoadingOff();
		psPosionPopUp(objWindow);		
	}
	i.onclick = function(){
		psClosePopUp();		
	}
	return false;
}
// - Windows --------------------------------------------
// - Base Functions --------------------------------------------
function psPrint(obj)
{
  popupWin = window.open(obj.href, '', 'width=700,height=600,toolbar=no,menubar=yes,location=no,status=yes,resizable=yes,scrollbars=yes,left=50,top=50');
  popupWin.focus();
  return false;	
}

function psCreateDiv(idName){
	var obj = document.createElement('div');
	document.getElementsByTagName("body")[0].appendChild(obj);
	obj.id=idName;
	return document.getElementById(idName);
}

function psDeleteObj(idName){
	obj = document.getElementById(idName);
	document.body.removeChild(obj);	
}

function psPreloadImg(url){
    var image = new Image();
    image.src = url;    
}

function psGetPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function psGetPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	return yScroll;
}

// - Base Functions --------------------------------------------

var resId=0;
var imgWndw;
function popimg(imgLink, Title) {
  if (typeof(window.resizeBy)=='undefined') return true;
  var sl=(document.body.clientWidth-100)/2;
  var st=(document.body.clientHeight-100)/2;
  imgWndw=window.open(imgLink,'swnd','width=50,height=50,toolbar=no,menubar=no,location=no,status=no,resizable=yes,scrollbars=yes,left='+sl+',top='+st);
  imgWndw.focus();
  with (imgWndw.document){
    open();
    write('<ht'+'ml><he'+'ad><ti'+'tle>'+Title+'</ti'+'tle>'+ '</he'+'ad><bo'+'dy leftmargin="0" topmargin="0" '+ 'rightmargin="0" bottommargin="0" marginwidth="0" '+ 'style="margin:0;padding:0;position:fixed;overflow:none;" '+ 'marginheight="0"><img src="'+imgLink+'" border="0" '+ ' alt="'+Title+'" title="'+Title+'" /></bo'+ 'dy></ht'+'ml>');
    close();
  }
  resId=setInterval('imgResize()',100);
  return false
}

function poppage(pageLink,width,height,scrollShow,panelOption){
  width = (width && width !== 'auto')?width:(document.body.clientWidth-100)/1.4;
  height = (height && height !== 'auto')?height:(document.body.clientHeight-100)/1.4;
  scrollShow = (scrollShow == 'no')?'no':'yes';
  if (panelOption == 0 ) panel = 'toolbar=no,menubar=no,location=no';
  else if (panelOption == 2 ) panel = 'toolbar=yes,menubar=yes,location=yes';
  else panel = 'toolbar=no,menubar=yes,location=no';

  popupWin = window.open(pageLink, '', 'width='+width+',height='+height+','+panel+',status=yes,resizable=yes,scrollbars='+scrollShow+',left=50,top=50');
  popupWin.focus();
  return false
}

function imgResize() {
  var w=imgWndw.document.images[0].width;
  if (w>screen.availWidth) w=screen.availWidth;
  var h=imgWndw.document.images[0].height;
  if (h>screen.availHeight) h=screen.availHeight;
  if (w>50 && h>50) {
    var ww=(imgWndw.innerWidth)?imgWndw.innerWidth:((document.body)? imgWndw.document.body.clientWidth:null);
    var wh=(imgWndw.innerHeight)?imgWndw.innerHeight:((document.body)? imgWndw.document.body.clientHeight:null);
    if (ww && wh) {imgWndw.resizeBy(w-ww,h-wh);
    var sw=(document.body.clientWidth-w)/2;
    var sh=(document.body.clientHeight-h)/2;
    if (sh<0) sh=0; if (sw<0) sw=0;
    imgWndw.moveTo(sw,sh);
    }
    imgWndw.focus();
    clearInterval(resId)
  }
}

function trim(str) {
	return str.replace(/^\s*/,'').replace(/\s*$/,'');
}

function show_hide(id){
	var showObj=document.getElementById(id).style
	if (showObj.display=="none")
		{showObj.display=""}
	else {showObj.display="none"}
	}


//--------------------------------//
// Конструктор класса FlashObject //
//--------------------------------//
function Flash( ) {

	this.transparent = true;
	this.needFlashVerion = 8;           
	this.flashvars = "xml_source=/ixml/&menuselid=0";
	this.BrowserInfo( );

}

/* Метод определения типа Браузера */
Flash.prototype.BrowserInfo = function( ) {  
  
    var userAgent = navigator.userAgent.toLowerCase( );
       this.browserIE = ( userAgent.indexOf( 'msie' ) != -1 );

}

/* Метод для опеределения нужной версии флэша */
Flash.prototype.CheckVersionFlash = function( needVersion ) {
  
    if ( navigator.plugins[ 'Shockwave Flash' ] ) {
        /* определяем есть ли у браузера plugin флэшплеера */
        matchStr = new RegExp ( '^[A-Za-z ]*(.*) .*$' );
        this.flashVerion = parseInt( navigator.plugins[ 'Shockwave Flash' ].description.replace( matchStr, '$1' ) );
        return ( needVersion <= this.flashVerion );
    }
    else if ( this.browserIE ) {
        /* иначе будет создаваться ActiveX объект (IE) */
        for( var i = needVersion; i < needVersion + 10; i++ ) {
            try {
                    flashPlayer = new ActiveXObject( 'ShockwaveFlash.ShockwaveFlash.' + i );
                    this.flashVerion = i;
                    return true;
            }
            catch( e ) {
                continue;
            }
        }
        return false;      
    }
    else {
        this.flashVerion = 0;
        return false;
    }
  
}

/* Метод вставки в страницу HTML нужного кода */
Flash.prototype.Insert = function( ) {
  
    if ( this.CheckVersionFlash( this.needFlashVerion ) ) {
        document.write( this.GenerateHtmlFlash( ) );
    }
    else {
        document.write( this.GenerateHtmlImage( ) );
    }
      
}

/* Метод для генерирования флэш - кода */
Flash.prototype.GenerateHtmlFlash = function( ) {
 
    var flashCode = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
    flashCode += 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version= ' + this.flashVerion + ',0,0,0"' + ' width="' + this.width + '" height="' + this.height + '" align="middle">';
    flashCode += '<param name="allowScriptAccess" value="always"/>';
    flashCode += '<param name="movie" value="' + this.srcFlash + '"/>';
    flashCode += '<param name="quality" value="high"/>';
    if ( this.base ) {
        flashCode += '<param name="base" value="' + this.base + '"/>';
    }
    if ( this.background ) {
        flashCode += '<param name="bgcolor" value="' + this.background + '"/>';
    }
    if ( this.transparent ) {
        flashCode += '<param name="wmode" value="transparent"/>';
    }
    if ( this.flashvars ) {
        flashCode += '<param name="flashvars" value="' + this.flashvars + '"/>';
    }
 
    flashCode += '<embed quality="high" allowScriptAccess="always" type="application/x-shockwave-flash"' + ' pluginspage="http://www.macromedia.com/go/getflashplayer" ';
    flashCode += 'src="' + this.srcFlash+'" ' + '" width="' + this.width + '" height="' + this.height + '" ';
    if ( this.base ){
        flashCode += ' base="' + this.base + '"';
    }
    if ( this.background ){
        flashCode += ' bgcolor="' + this.background + '"';
    }
    if ( this.transparent ){
        flashCode += ' wmode="transparent"'
    }
    if ( this.flashvars ){
        flashCode += ' flashvars="' + this.flashvars + '"';
    }
    flashCode += '></embed>';
  
    flashCode += '</object>';
    return flashCode;
  
}

/* Метод для генерирования image - кода */
Flash.prototype.GenerateHtmlImage = function( ) {
  
    var imageCode = '<img src="' + this.srcImage + '"/>';
    return imageCode;
  
}

