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 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;
}

// -------------------------------------------------------
var currentWindow;

function closeBackGround(){
	obj = psCreateDiv('closeFonId');
	obj.className='psCloseBackGround';
	obj.style.height=psGetPageSize()[1]+'px';
	obj.style.width=psGetPageSize()[0]+'px';	
	document.body.style.overflowX='hidden';
}

// - Windows --------------------------------------------
function psOpenInPopUp (idName,url){
	closeBackGround();

	objWindow =	psCreateDiv('psWindow');
	objWindow.style.position='absolute';
	objWindow.style.zIndex=1100;
	objSrc = document.getElementById(idName);

	if(url){
		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);
				}
			}
		}		
	}else{
		objWindow.innerHTML = objSrc.innerHTML;
		psPosionPopUp(objWindow);
		if (objWindow.getElementsByTagName('img').length > 0){
			objWindow.getElementsByTagName('img')[0].onload = function (){
				psPosionPopUp(objWindow);
			}
		}
	}
}

function psClosePopUp(){
	psDeleteObj('psWindow');
	psDeleteObj('closeFonId');
	document.body.style.overflowX='';	
}

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';	
}
// - Windows --------------------------------------------

var resId=0;
var imgWndw;
function psPopImg(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=no,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('psImgResize()',100);
  return false
}

function psPopPage(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 psImgResize() {
  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 psShowHide(id){
	var showObj=document.getElementById(id).style
	if (showObj.display=="none")
		{showObj.display=""}
	else {showObj.display="none"}
}

function psPreloadImg(url){
	var image = new Image();
	image.src = url;	
}

//--------------------------------//
// Конструктор класса FlashObject //
//--------------------------------//
function Flash( ) {
	this.transparent = true;
	this.imgHref = false;
	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( ) {
	if (this.imgHref) {
		var imageCode = '<a href="'+this.imgHref+'"><img src="' + this.srcImage + '"  width="'+this.width+'" height="'+this.height+'" /></a>';
	}else {		
		var imageCode = '<img src="' + this.srcImage + '"/>';
	}
	return imageCode;
}





