////////////////////////////////////////////////////////////////





var ns  = (document.layers) ? 1 : 0;
var ie  = (document.all) ? 1 : 0;
var dom = (document.getElementById) ? 1 : 0;
var mac = (navigator.platform.indexOf("Mac") != -1) ? 1 : 0;
var gecko     = (navigator.userAgent.indexOf("Gecko") != -1) ? 1 : 0;
var geckoVers = parseFloat(navigator.userAgent.replace(/.*rv:(\d+\.\d+).*/, '$1'));
var ieVers    = navigator.appVersion.substring(navigator.appVersion.lastIndexOf("MSIE") + 4,navigator.appVersion.lastIndexOf("MSIE") + 8);
  
var queryString = document.location.search;

var extension = 'cgi';
if(document.location.href.indexOf('cgi-php') >= 0 && document.location.href.indexOf('.php') >= 0){
  extension = 'php';
}

var isInline =  0;
if(window.name == 'wEditorInline'){
  isInline = 1;
}  

if(self == top){
  self.focus();
}

if(isInline == 1){document.write('<link rel="stylesheet" type="text/css" href="/weblication/wEditor/wGui/wStyles/style_inline.css">');}
 
     


function toogleImage(ImgObj){
  var imageSrc    = document.images[ImgObj].src;
  var isHightlighted = /_h\./;
  if (isHightlighted.test(imageSrc) != true){
    document.images[ImgObj].src = imageSrc.replace(/^(.*[\\|\/])([^\.]*)(\..*)$/, '$1$2' + '_h' + '$3');
  }
  else{
    document.images[ImgObj].src = imageSrc.replace(/^(.*[\\|\/])([^\.]*)(_h)(\..*)$/, '$1$2$4');
  }	 
}






function getParam(name) {
  var value = '';
  if(document.location.search != ''){
    var hasParam = eval('/' + name + '=([^\&]+)/i');        
    if(hasParam.test(queryString) == true){
      value = RegExp.$1;             
    }         
  }     
  return value;
}






function setParam(url, name, value) {
  var hasParam = eval('/' + name + '=([^\&]+)/i');        
  if(hasParam.test(queryString) == true){
    var replaceParam = eval('/' + name + '=([^\&]+)/i');      
    url = url.replace(replaceParam, name + '=' + value);           
  }     
  else{
    url = url + '&' + name + '=' + value;
  }
  return url;
}






function mouseOverButtonDialogSmart(button) {
  button.className = 'buttonDialogSmartMo'; 
}






function mouseOutButtonDialogSmart(button) {
  button.className = 'buttonDialogSmart'; 
}






function mouseOverButtonForm(button) {
  button.className = 'buttonFormMo'; 
}






function mouseOutButtonForm(button) {
  button.className = 'buttonForm'; 
}






function mouseOverButtonMain(button){
  button.className = 'buttonMainMo'; 
}






function mouseOutButtonMain(button) {
  button.className = 'buttonMain'; 
}






function mouseOverButtonRegister(button) {
  button.className = 'registerMo'; 
}






function mouseOutButtonRegister(button) {
  button.className = 'register'; 
}






function mouseOverButtonRegisterSub(button) {
  button.className = 'registerSubMo'; 
}






function mouseOutButtonRegisterSub(button) {
  button.className = 'registerSub'; 
}






function mouseOverButtonDialog(button) {
  button.className = 'buttonDialogMo'; 
}






function mouseOutButtonDialog(button) {
  button.className = 'buttonDialog'; 
}






function mouseOverButtonStatus(button) {
  button.className = 'buttonStatusMo'; 
}






function mouseOutButtonStatus(button) {
  button.className = 'buttonStatus'; 
}






function mouseOverButton(button) {
  button.className = 'buttonWysiwygMo'; 
}






function mouseOutButton(button) {
  button.className = 'buttonWysiwyg'; 
}






function mouseOverCell(cell) {
  if(!mac){
    cell.className='cellMo';
  }
}






function mouseOutCell(cell) {
  if(!mac){
    cell.className='cell';
  }  
}






function mouseOverObjectCell(cell) {
  if(!mac){
    cell.className='objectCellMo';
  }
}






function mouseOutObjectCell(cell) {
  if(!mac){
    cell.className='objectCell';
  }  
}






function mouseOverObjectFunction(img) {
  img.className='imgObjectFunctionMo';
}






function mouseOutObjectFunction(img) {
  img.className='imgObjectFunction';
}






function mouseOverButtonWysiwyg(button){
  button.className = 'buttonWysiwygMo';   
}





  
function mouseOutButtonWysiwyg(button){

  if(button.getAttribute('wIsActive') != '1'){    
    button.className = 'buttonWysiwyg';     
  }
}  








function showLayer(layerId, positionX, positionY){

   if(layerId == ""){
     return;
   }

	if(ie){
		if(document.all[layerId]){
			document.all[layerId].style.visibility = 'visible';
            if(positionX){
              document.all[layerId].style.left = positionX;
            }
            if(positionY){
              document.all[layerId].style.top = positionY;
            }            
		}  
	}
	else if(ns){
		if(document.layers[layerId]){
			document.layers[layerId].visibility = 'visible'; 
            if(positionX){
              document.layers[layerId].style.left = positionX;
            }      
            if(positionY){
              document.layers[layerId].style.top = positionY;
            }                       
		} 
	}
	else if(dom){
		if(document.getElementById(layerId)){
			document.getElementById(layerId).style.visibility = 'visible';  
            if(positionX){
              document.getElementById(layerId).style.left = positionX;
            }            
            if(positionY){
              document.getElementById(layerId).style.top = positionY;
            }                  
		}
	} 
}








function setClassName(elementId, className){

   if(elementId == ""){
     return;
   }

	if(ie){
      if(document.all[elementId]){
        document.all[elementId].className = className;
      }
	}
	else if(dom){
	  if(document.getElementById(elementId)){
		document.getElementById(elementId).className = className;
      }
	} 
}     








function hideLayer(layerId){

   if(layerId == ""){
     return;
   }
   
	if(ie){
		if(document.all[layerId]){
			document.all[layerId].style.visibility = 'hidden';
		}  
		
	}
	else if(ns){
		if(document.layers[layerId]){
			document.layers[layerId].visibility = 'hide'; 
		} 
	}
	else if(dom){
		if(document.getElementById(layerId)){
			document.getElementById(layerId).style.visibility = 'hidden';  
		}
	} 
}










function isVisibleLayer(layerId){

	if(ie){
		if(document.all[layerId].style.visibility == 'visible'){
			return 1;
		}  
		else{
			return 0;
		}		
	}
	else if(ns){
		if(document.layers[layerId].visibility == 'visible'){        
			return 1;
		}  
		else{
			return 0;
		}	
	}
	else if(dom){
		if(document.getElementById(layerId).style.visibility == 'visible'){        
			return 1;
		}  
		else{
			return 0;
		}	                     
	}    
}










function isVisibleLayer(layerId){

	if(ie){
		if(document.all[layerId].style.visibility == 'visible'){
			return 1;
		}  
		else{
			return 0;
		}		
	}
	else if(ns){
		if(document.layers[layerId].visibility == 'visible'){        
			return 1;
		}  
		else{
			return 0;
		}	
	}
	else if(dom){
		if(document.getElementById(layerId).style.visibility == 'visible'){        
			return 1;
		}  
		else{
			return 0;
		}	                     
	}    
}








function showLayerFrame(frame, layerId){

   if(layerId == ""){
     return;
   }
   
	if(ie){
		if(frames[frame].document.all[layerId]){
			frames[frame].document.all[layerId].style.visibility = 'visible';
		}  
	}
	else if(ns){
		if(frames[frame].document.layers[layerId]){
			frames[frame].document.layers[layerId].visibility = 'visible'; 
        } 
	}
	else if(dom){
		if(frames[frame].document.getElementById(layerId)){
			frames[frame].document.getElementById(layerId).style.visibility = 'visible';  
                
		}
	} 
}








function showLayerParent(layerId){

   if(layerId == ""){
     return;
   }
   
	if(ie){
		if(parent.document.all[layerId]){
			parent.document.all[layerId].style.visibility = 'visible';
		}  
	}
	else if(ns){
		if(parent.document.layers[layerId]){
			parent.document.layers[layerId].visibility = 'visible'; 
    } 
	}
	else if(dom){
		if(parent.document.getElementById(layerId)){
			parent.document.getElementById(layerId).style.visibility = 'visible';  
		}
	} 
}












function checkMask(windObject, maskName){

  if(windObject.maskName){
    if(windObject.maskName == maskName){
      return 1;
    }
  }
  return 0;
}

  
function showProgressbar(){
  showLayer("progressBar");
  showLayer("actionBlocker");  
}

function hideProgressbar(){
  hideLayer("progressBar");
  hideLayer("actionBlocker");  
}

function adaptClassSizeCss(className){
  var winWidth  = 800;
  var winHeight = 600;

  if(ie){
    winWidth  = document.body.clientWidth;
    winHeight = document.body.clientHeight;  
  }
  else{
    winWidth  = window.innerWidth;
    winHeight = window.innerHeight;
  }
  document.writeln('<style>.' + className + ' {height:' + (winHeight - 100) + 'px;}</style>');
}  

function adaptClassSizeCssDiff(className, diffWidth, diffHeight){
  var winWidth  = 800;
  var winHeight = 600;

  if(ie){
    winWidth  = document.body.clientWidth;
    winHeight = document.body.clientHeight;  
  }
  else{
    winWidth  = window.innerWidth;
    winHeight = window.innerHeight;
  }
  if(diffHeight && diffHeight != ""){
    document.writeln('<style>.' + className + ' {height:' + (winHeight - diffHeight) + 'px;}</style>');
  }
  if(diffWidth && diffWidth != ""){
    document.writeln('<style>.' + className + ' {width:' + (winWidth - diffWidth) + 'px;}</style>');  
  }  
}  

function adaptClassPositionTopDiff(className, diffTop){
  var winHeight = 600;

  if(ie){
    winHeight = document.body.clientHeight;  
  }
  else{
    winHeight = window.innerHeight;
  }

  document.writeln('<style>.' + className + ' {top:' + (winHeight - diffTop) + 'px;}</style>');
}  

function adaptElementPositionTopDiff(elementId, diffTop){

  var winHeight = 600;

  if(ie){
    winHeight = document.body.clientHeight;  
  }
  else{
    winHeight = window.innerHeight;
  }
  var element = document.getElementById(elementId);
  if(element){
    element.style.top = (winHeight - diffTop);
  }  
} 

 function closeEditorPopup(){
   if(top == self){self.close();}	
 }
 
 
function setOverflowAuto(className){

  document.writeln('<style>.' + className + ' {overflow:auto}</style>');

}  








function displayElement(elementId){

  if(document.getElementById(elementId)){
    document.getElementById(elementId).style.display = 'block';  
  } 
}








function hideElement(elementId){

  if(document.getElementById(elementId)){
    document.getElementById(elementId).style.display = 'none';  
  } 
}

function getUrlReload(){
  var urlReload = location.href;
  urlReload = urlReload.replace(/\&reloadid=\d+/, '');
  var dateObj = new Date();
  urlReload += '&reloadid=' + dateObj.getTime();
  return urlReload;
}  
    


function openWin(url, name, width, height, options){

  if(width == ''){
    var regWidth = /width=(\d+)/;
    regWidth.exec(options);
    width = RegExp.$1; 
    if(width == ''){   
      width = 640; 
    }
  }
  if(height == ''){
    var regHeight = /height=(\d+)/;
    regHeight.exec(options);
    height = RegExp.$1;         
    if(height == ''){   
      height = 480; 
    }    
  }  
  
  if (typeof name != 'undefined'){
    name = name.replace(/\W/g, '');
  }  
  
  if(!name && !width && !height && !options){
    window.open(url, name);
    return;
  }

  if(!options){
    options = ',resizable=no,scrollbars=no,status=no';
  }


  var posLeft = (screen.width / 2)  - (width  / 2);
  var posTop  = (screen.height / 2) - (height / 2);
  rtc = window.open(url, name, 'top='+posTop+',left='+posLeft+',width='+width+',height='+height+',' + options);
  rtc.focus();
}



function wOpenWindow(url, name, width, height, options){

    
  url = url.replace(/&amp;/g, '&');

  if (typeof name != 'undefined'){
    name = name.replace(/\W/g, '');
  }  
  
  if(!name && !width && !height && !options){
    window.open(url, name);
  }

  if(!options){
    options = ',resizable=no,scrollbars=no,status=no';
  }

  var posLeft = (screen.width / 2)  - (width  / 2);
  var posTop  = (screen.height / 2) - (height / 2);
  
  window.open(url, name, 'top='+posTop+',left='+posLeft+',width='+width+',height='+height+',' + options);
}











var request;
var wGetUrlFunctionResult;

function getUrl(url, functionResult){      

  if(document.all){
    request = new ActiveXObject("Microsoft.XMLHTTP");
  }
  else{
    request = new XMLHttpRequest();
  }
	
  request.open('GET', url, true);  
  
  wGetUrlFunctionResult = functionResult;  
  
  if(typeof functionResult == 'function'){
    request.onreadystatechange = getUrlReadyStateChange;
  }
  else{
    request.onreadystatechange = getUrlReadyStateChange;
  }
  
  request.send('');
}











function getUrlReadyStateChange(){
  
  if(request.readyState == 4){
    if(request.status == '200'){
    	wGetUrlFunctionResult();

    }  
  }
}







function EventUtils() {
  throw 'RuntimeException: EventUtils is a static utility class ' +
  ' and may not be instantiated';
}

EventUtils.addEventListener = function (target,type,callback,captures) {
  if (target.addEventListener) {
    target.addEventListener(type,callback,captures);
	}
  else if (target.attachEvent) {
	 target.attachEvent('on'+type,callback,captures);
	}
  else{
    target['on'+type] = callback;
	}
};









function keyPressed(e){

  if(typeof window_onKeyDown == 'function'){
    window_onKeyDown((window.Event) ? e.which : event.keyCode); 
    return;  
  }     
}

window.onkeydown = keyPressed;
