
// cross-browser DIV manipulation (IE4+, NN4+, NS6)
//-----------------------------------------------------------------------------------------------------------------------------

//-----------------------------------------------------------------------------------------------------------------------------
// generic layer functions

function MM_findObj(n, d) { //v4.0 Dreamweaver code - required for nested layers in NS4
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_changeProp(objName,x,theProp,theValue) { //v3.0 Dreamweaver code
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)) eval("obj."+theProp+"='"+theValue+"'");
}

function MM_getProp(objName,x,theProp) { //adapted from MM_changeProp
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)) return eval("obj."+theProp);
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function preload () {
var i, args, fn;
args = preload.arguments;
if (args.length > 0) {
	
	preimage = new Array(args.length);
	for (i=0; i<(args.length); i++) {	
		fn = args[i];	
		preimage[i] = new Image();
		preimage[i].src = fn;	
	}
}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i]; 
		//window.open(a[i],'',''); 
	}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//-----------------------------------------------------------------------------------------------------------------------------
// initialise

function MT_setDimensions (objName,t,l,w,h,v) {

	// problem: NS4 has a problem with nested DIVs when STYLE attributes are defined inline,
	// e.g. <DIV ID="test1" STYLE="width:500px; height:200px;", therefore these attributes need
	// to be set in <STYLE TYPE="text/css"> block at top of document.
	// however, IE and NS6 cannot explicitly read these attributes UNLESS they are defined inline (!)
	// this function explicitly defines STYLE attributes via code, making them available to code from
	// all browsers.
	// must be run AFTER the DIV objects have been defined.
	
	var obj = MM_findObj(objName)
	if (document.layers) { 
		obj.top = t;
		obj.left = l;
		obj.clip.width = w; 
		obj.clip.height = h;
		if(v){obj.visibility = "show";}else{obj.visibility = "hide";}
	} else if (document.all) { 
		obj.style.top = t;
		obj.style.left = l;
		obj.style.pixelWidth = w;
		obj.style.pixelHeight = h;
		if(v){obj.style.visibility = "visible"}else{obj.style.visibility = "hidden";}
	} else if (document.getElementById) { 
		obj.style.top = t;
		obj.style.left = l;
		obj.style.width = w;
		obj.style.height = h;
		if(v){obj.style.visibility = "visible"}else{obj.style.visibility = "hidden";}
	}
}

function MT_setSrc (objName,url,statusbar) {
	var obj = MM_findObj(objName);

	obj.src = url;
	window.status = statusbar;
}

function MT_getTop (objName) {
	var obj = MM_findObj(objName)
	if (document.layers) { return obj.top; }
	else if (document.all) { return obj.style.top; }
	else if (document.getElementById) { return obj.style.top; }
}

function MT_getLeft (objName) {
	var obj = MM_findObj(objName)
	if (document.layers) { return obj.left; }
	else if (document.all) { return obj.style.left; }
	else if (document.getElementById) { return obj.style.left; }
}

function MT_getWidth (objName) {
	var obj = MM_findObj(objName)
	if (document.layers) { return obj.clip.width; }
	else if (document.all) { return obj.style.pixelWidth; }
	else if (document.getElementById) { return obj.style.width; }
}

function MT_getHeight (objName) {
	var obj = MM_findObj(objName)
	if (document.layers) { return obj.clip.height; }
	else if (document.all) { return obj.style.pixelHeight; }
	else if (document.getElementById) { return obj.style.height; }
}

function MT_setTop (objName,t) {
	var obj = MM_findObj(objName)
	if (document.layers) { 
		obj.top = t;
	} else if (document.all) { 
		obj.style.top = t+"px";
	} else if (document.getElementById) { 
		obj.style.top = t+"px";
	}
}

function MT_setHeight (objName,h) {
	var obj = MM_findObj(objName)
	if (document.layers) { 
		obj.clip.height = h;
	} else if (document.all) { 
		obj.style.pixelHeight = h+"px";
	} else if (document.getElementById) { 
		obj.style.height = h+"px";
	}
}

function MT_setWidth (objName,w) {
	var obj = MM_findObj(objName)
	if (document.layers) { 
		obj.clip.width = w; 
	} else if (document.all) { 
		obj.style.pixelWidth = w+"px";
	} else if (document.getElementById) { 
		obj.style.width = w+"px";
	}
}

function MT_setLeft (objName,l) {
	var obj = MM_findObj(objName)
	if (document.layers) { 
		obj.left = l;
	} else if (document.all) { 
		obj.style.left = l+"px";
	} else if (document.getElementById) { 
		obj.style.left = l+"px";
	}
}

function MT_setVisibility (objName,v) {
	var obj = MM_findObj(objName)
	if (document.layers) { 
		if(v){obj.visibility = "show";}else{obj.visibility = "hide";}
	} else if (document.all) { 
		if(v){obj.style.visibility = "visible"}else{obj.style.visibility = "hidden";}
	} else if (document.getElementById) { 
		if(v){obj.style.visibility = "visible"}else{obj.style.visibility = "hidden";}
	}
}

function MT_setClip (objName,t,r,b,l) {
	var obj = MM_findObj(objName)
	if (document.layers){
		obj.clip.top = t;
		obj.clip.right = r;
		obj.clip.bottom = b;
		obj.clip.left = l;
	}
	else if (document.all){
		obj.style.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)";
	}
	else if (document.getElementById){
		obj.style.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)";
	}
}

function convert(strng) {
      var i = parseInt(strng.slice(0,strng.length-2));
	return i;
}
function MT_getClip (objName) {
	// return array...
	var obj = MM_findObj(objName)
	var cp = new Array;
	if (document.layers){
		cp[0] = obj.clip.top;
		cp[1] = obj.clip.right;
		cp[2] = obj.clip.bottom;
		cp[3] = obj.clip.left;
	}
	else if (document.all){
		thisclip = obj.style.clip;
		thisclip = thisclip.slice(5,thisclip.length-1);
		var entries = thisclip.split(" ");		
		cp[0] = convert(entries[0]);
		cp[1] = convert(entries[1]);
		cp[2] = convert(entries[2]);
		cp[3] = convert(entries[3]);
	}
	else if (document.getElementById){
		thisclip = obj.style.clip;
		thisclip = thisclip.slice(5,thisclip.length-1);
		var entries = thisclip.split(" ");		
		cp[0] = convert(entries[0]);
		cp[1] = convert(entries[1]);
		cp[2] = convert(entries[2]);
		cp[3] = convert(entries[3]);
	}
	return cp;
}

function MT_getClientHeight (objName) {
	var obj = MM_findObj(objName);
	if (document.layers){
		return obj.document.height;
	} else if (document.all) {
		return obj.clientHeight;
	} else if (document.getElementById) {
		return obj.offsetHeight;	
	}
}

function MT_getPageScrollLeft() {
	if (document.layers){
		return window.pageXOffset;
	} else if (document.all) {
		return document.body.scrollLeft;
	} else if (document.getElementById) {
		return document.scrollLeft;
	}
}

function MT_getPageScrollTop() {
	if (document.layers){
		return window.pageYOffset;
	} else if (document.all) {
		return document.body.scrollTop;
	} else if (document.getElementById) {
		return document.scrollTop;
	}
}

function MT_getWindowWidth() {
	if (document.layers){
		return window.innerWidth;
	} else if (document.all) {
		return document.body.clientWidth;
	} else if (document.getElementById) {
		return document.offsetWidth;
	}
}
