var isMinNS4=(navigator.appName.indexOf("Netscape")>=0&&parseFloat(navigator.appVersion)>=4) ? 1 : 0;
var isMinIE4=(document.all) ? 1 : 0;
var isMinIE5=(isMinIE4&&navigator.appVersion.indexOf("5.")>=0) ? 1 : 0;


function hideLayer(layer){
	layer.style.visibility="hidden";
}

function showLayer(layer){
	layer.style.visibility="visible";
}

function inheritLayer(layer){
	layer.style.visibility="inherit";
}

function getVisibility(layer){
	return layer.style.visibility;
}

function moveLayerTo(layer,x,y){
	layer.style.left=x;
	layer.style.top =y;
}

function moveLayerBy(layer,dx,dy){
	layer.style.pixelLeft += dx;
	layer.style.pixelTop  += dy;

}

function getLeft(layer){
	return layer.style.pixelLeft;
}

function getTop(layer){
	return layer.style.pixelTop;
}

function getRight(layer){
	return layer.style.pixelLeft+getWidth(layer);
}

function getBottom(layer){
	return layer.style.pixelTop+getHeight(layer);
}

function getPageLeft(layer){
	var x;
	
	x=0;
	
	while (layer.offsetParent!=null){
		x += layer.offsetLeft;
		layer=layer.offsetParent;
	}
	
	x += layer.offsetLeft;
	return x;
}

function getPageTop(layer){
	var y;
	
	y=0;

	while (layer.offsetParent!=null){
		y += layer.offsetTop;
		layer=layer.offsetParent;
	}
	
	y += layer.offsetTop;
	return y;
}

function getWidth(layer){
	if(layer.style.pixelWidth)
		return layer.style.pixelWidth;
	else
		return layer.clientWidth;
}

function getHeight(layer){
	if(layer.style.pixelHeight)
		return layer.style.pixelHeight;
	else
		return layer.clientHeight;
}

function getzIndex(layer){
	return layer.style.zIndex;
}

function setzIndex(layer,z){
	layer.style.zIndex=z;
}


function clipLayer(layer,clipleft,cliptop,clipright,clipbottom){
	layer.style.clip='rect('+cliptop+' '+ clipright+' '+clipbottom+' '+clipleft +')';
}

function getClipLeft(layer){
	var str= layer.style.clip;
	if(!str)
		return 0;
	
	var clip=getIEClipValues(layer.style.clip);
	return(clip[3]);
}

function getClipTop(layer){

	var str= layer.style.clip;
	if(!str)
		return 0;
		
		var clip=getIEClipValues(layer.style.clip);
	return clip[0];
}

function getClipRight(layer){
	var str= layer.style.clip;
	if(!str)
		return layer.style.pixelWidth;
	
	var clip=getIEClipValues(layer.style.clip);
	return clip[1];
}

function getClipBottom(layer){
	var str= layer.style.clip;
	if(!str)
		return layer.style.pixelHeight;
	
	var clip=getIEClipValues(layer.style.clip);
	return clip[2];
}

function getClipWidth(layer){
	var str=layer.style.clip;
	if(!str)
		return layer.style.pixelWidth;
	
	var clip=getIEClipValues(layer.style.clip);
	return clip[1]-clip[3];
}

function getClipHeight(layer){
	var str= layer.style.clip;
	if(!str)
		return layer.style.pixelHeight;
		
	var clip=getIEClipValues(layer.style.clip);
	return clip[2]-clip[0];
}

function getIEClipValues(str){
	var clip=new Array();
	var i;
	
	// Parse out the clipping values for IE layers.
	
	i=str.indexOf("(");
	clip[0]=parseInt(str.substring(i+1,str.length),10);
	i=str.indexOf(" ",i+1);
	clip[1]=parseInt(str.substring(i+1,str.length),10);
	i=str.indexOf(" ",i+1);
	clip[2]=parseInt(str.substring(i+1,str.length),10);
	i=str.indexOf(" ",i+1);
	clip[3]=parseInt(str.substring(i+1,str.length),10);
	return clip;
}


function scrollLayerTo(layer,x,y,bound){
	var dx=getClipLeft(layer)-x;
	var dy=getClipTop(layer)-y;
	
	scrollLayerBy(layer,-dx,-dy,bound);
}

function scrollLayerBy(layer,dx,dy,bound){
	var cl=getClipLeft(layer);
	var ct=getClipTop(layer);
	var cr=getClipRight(layer);
	var cb=getClipBottom(layer);
	
	if(bound){
		if(cl+dx < 0)
			dx=-cl;
		else if(cr+dx > getWidth(layer))
			dx=getWidth(layer)-cr;
		
		if(ct+dy < 0)
			dy=-ct;
		else if(cb+dy > getHeight(layer))
			dy=getHeight(layer)-cb;
	}
	clipLayer(layer,cl+dx,ct+dy,cr+dx,cb+dy);
	moveLayerBy(layer,-dx,-dy);
}


function setBgColor(layer,color){
	layer.style.backgroundColor=color;
}

function setBgImage(layer,src){
	layer.style.backgroundImage="url("+src+")";
}

function getLayer(name){
	return eval('document.all.'+name);
}

function findLayer(name,doc){

	var i,layer;
	
	for (i=0; i < doc.layers.length; i++){
		layer=doc.layers[i];

		if(layer.name==name)
			return layer;
		if(layer.document.layers.length > 0)
			if((layer=findLayer(name,layer.document))!=null)
				return layer;
	}
	return null;
}


function getImage(name){
	return eval('document.all.'+name);
}

function findImage(name,doc){
	var i,img;
	
	for (i=0; i < doc.images.length; i++)
		if(doc.images[i].name==name)
			return doc.images[i];
	
	for (i=0; i < doc.layers.length; i++)
		if((img=findImage(name,doc.layers[i].document))!=null){
			img.container=doc.layers[i];
			return img;
		}
}

function getImagePageLeft(img){
	var x,obj;
	
	x=0;
	obj=img;

	while (obj.offsetParent!=null){
		x += obj.offsetLeft;
		obj=obj.offsetParent;
	}

	x += obj.offsetLeft;
	return x;
}

function getImagePageTop(img){
	var y,obj;
	
	y=0;
	obj=img;

	while (obj.offsetParent!=null){
		y += obj.offsetTop;
		obj=obj.offsetParent;
	}

	y += obj.offsetTop;
	return y;
}


function getWindowWidth(){
	return document.body.clientWidth;
}

function getWindowHeight(){
	return document.body.clientHeight;
}

function getPageWidth(){
	return document.body.scrollWidth;
}

function getPageHeight(){
	return document.body.scrollHeight;
}

function getPageScrollX(){
	return document.body.scrollLeft;
}

function getPageScrollY(){
	return document.body.scrollTop;
}
