// alert('master_lib');

/*	$Id: master_lib.js,v 1.4 2003/08/24 13:15:14 smarty Exp $	*/

/* some useful MM fxes */

function MM_findObj(n, d) { //v3.0
	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);
	return x;
}

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];
	}
}

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;
}


/* The following is (c) 2003 by Yellowspace SMART Solutions, smart@yellowspace.net */

function PreLoad(imgUrl) {
	PreloadedImage = new Image();
	PreloadedImage.src = imgUrl;
	return PreloadedImage;
	// alert(imgUrl);
}

bAgent = window.navigator.userAgent;
bAppName = window.navigator.appName;

// alert(bAgent);

if (bAppName.indexOf("Netscape") >= 0) {
	Browser="Netscape";
	bVerIdx = bAgent.indexOf("Mozilla/") + 8;
}
if (bAppName.indexOf("Explorer") >= 0) {
	Browser="Explorer";
	bVerIdx = bAgent.indexOf("MSIE")+4;
}
if (bAgent.indexOf("Opera") >= 0) {
	Browser="Opera";
	bVerIdx = bAgent.indexOf("Opera")+6;
	
}
if (bAgent.indexOf("Konqueror") >= 0) {
	Browser="Konqueror";
	bVerIdx = bAgent.indexOf("Konqueror/")+10;
}
if (bAgent.indexOf("Safari") >= 0) {
	Browser="Safari";
	bVerIdx = bAgent.indexOf("Safari/") + 7;
}

if (bAgent.indexOf("Mac") >= 0)
	Platform="Mac";
if (bAgent.indexOf("Win") >= 0)
	Platform="Win";

//------------ edit by paolo: changed "bVerIdx+3" into "bVerIdx+4" sun 18 nov 2001 21:25
//------------ reason: was not recognizing explorer 5.5

BrVersion=parseFloat(bAgent.substring(bVerIdx, bVerIdx+4));
// alert(bVerIdx + "z" + bAgent + "x" + bAppName +  "y" + bAgent.substring(bVerIdx, bVerIdx+4));
// alert("Browser="+Browser+" Platform="+Platform+" BrVersion="+BrVersion);

if (BrVersion < 5.0)
	Version="4";
if ((BrVersion >= 5.0) && (BrVersion < 5.5))
	Version="5";
if ((BrVersion >= 5.5) && (BrVersion < 6.0))
	Version="5.5";
if ((BrVersion >= 6.0))
	Version="6gt";
if ((BrVersion >= 51))
	Version="51+";
// alert("Version="+Version);


switch (Browser){
	case "Netscape":
		SmartAgent="Netscape";
		switch (Version){
			case "4":
				SmartAgent="Netscape4";
				break;
			case "5":
			case "5.5":
			case "6gt":
				SmartAgent="Netscape6";
				break;
			default:
		}
	break;
	case "Explorer":
		switch (Version){
			case "4":
			case "5":
				SmartAgent="MSIE5";
				break;
			case "5.5":
			case "6gt":
				SmartAgent="MSIE5.5";
				break;
			default:
		}
	break;
	case "Opera":
		switch (Version){
			case "4":
			case "5":
			case "5.5":
			case "6gt":
			default:
				SmartAgent="Opera5";
		}
		break;
	case "Konqueror":
		switch (Version){
			case "3":
			default:
				SmartAgent="Netscape6";
		}
		break;
	case "Safari":
		switch (Version){
			case "51+":
			default:
				SmartAgent="Khtml";
		}
		break;
	default:
		alert("unsupported browser type: "+bAgent);
}

// alert("SmartAgent="+SmartAgent);


/*-------------------------------------------------------------------------------------------
copy this master to make new functions!

function Master() {

		switch (SmartAgent){
			case "Netscape4":
			case "Netscape6":
			case "Khtml":
				break;
			case "MSIE5":
				break;
			case "MSIE5.5":
			case "Opera5":
				break;
			default:
		}
-------------------------------------------------------------------------------------------*/

function SwapImage(ImgName,Url) {

		switch (SmartAgent){
			case "Opera5":	
			case "Netscape4":
			case "Netscape6":
			case "Khtml":
				document.images[ImgName].src=Url;
				break;
			case "MSIE5":
				document.all[ImgName].src=Url;
				break;
			case "MSIE5.5":
				//----------- edit by chris
				document.getElementById(ImgName).src=Url;
				//----------- edit by paolo
				//MyObj = "document." + ImgName;
				//eval(MyObj).src = Url;
				break;
			default:
				document.getElementById(ImgName).src=Url;
		}
	// alert(ImgName + " / " + Url);
}



function SwapImageInLayer(LayerName,ImgName,Url) {

		switch (SmartAgent){

			case "Netscape4":
				document.layers[LayerName].document[ImgName].src=Url;
				break;
			case "MSIE5":
				document.all[ImgName].src=Url;
				break;
			case "MSIE5.5":
				// document.getElementById(ImgName).src=Url;
				MyObj = "document." + ImgName;
				eval(MyObj).src = Url;
				break;
			case "Opera5":
			case "Netscape6":
			case "Khtml":
				MM_swapImage(ImgName,0,Url);
				break;

			default:
				document.images[ImgName].src=Url;
		}

}





function ShowHideLayers(LayerName,On) {

	ManageLayer(LayerName,On);


}

function ManageLayer(LayerName,On,Left,Top,Width,Height,ZIndex) {



/*

Notes:
if arguments are not given or false, they are not used, but they have to be in the right order. 
If you want to change only arguments at the end, like width and height, 
you can do it by setting On, Left and Top to false.

*/

		switch (SmartAgent){
				case "Netscape4":
				document.layers[LayerName].visibility = (On) ? "show" : "hide";
				TheOperation = (Left) ? document.layers[LayerName].left = Left : "nogo";
				TheOperation = (Top) ? document.layers[LayerName].top = Top : "nogo";
				TheOperation = (Width) ? document.layers[LayerName].width = Width : "nogo";
				TheOperation = (Height) ? document.layers[LayerName].height = Height : "nogo";
				TheOperation = (ZIndex) ? document.layers[LayerName].zIndex = ZIndex : "nogo";
				break;
				
			case "MSIE5":
			//  explorer 4.5 braucht diesen case
				// alert("MSIE5");
				document.all[LayerName].style.visibility = (On) ? "visible" : "hidden";
				TheOperation = (Left) ? document.all[LayerName].style.pixelLeft = Left : "nogo";
				TheOperation = (Top) ? document.all[LayerName].style.pixelTop = Top : "nogo";
				TheOperation = (Width) ? document.all[LayerName].style.pixelWidth = Width : "nogo";
				TheOperation = (Height) ? document.all[LayerName].style.pixelHeight = Height : "nogo";
				TheOperation = (ZIndex) ? document.all[LayerName].style.zIndex = ZIndex : "nogo";
				break;
				
			case "Netscape6":
			case "Khtml":
			case "MSIE5.5":
			case "Opera5":
			default:
				document.getElementById(LayerName).style.visibility = (On) ? "visible" : "hidden";
				TheOperation = (Left) ? document.getElementById(LayerName).style.left = Left : "nogo";
				TheOperation = (Top) ? document.getElementById(LayerName).style.top = Top : "nogo";
				TheOperation = (Width) ? document.getElementById(LayerName).style.width = Width : "nogo";
				TheOperation = (Height) ? document.getElementById(LayerName).style.height = Height : "nogo";
				TheOperation = (ZIndex) ? document.getElementById(LayerName).style.zIndex = ZIndex : "nogo";
				break;
		}

}


function WriteToLayer(LayerName,Content) {

/*

Notes:
if arguments are not given or false, they are not used, but they have to be in the right order. 
If you want to change only arguments at the end, like width and height, 
you can do it by setting On, Left and Top to false.

*/

		switch (SmartAgent){
			case "Netscape4":
				document.layers[LayerName].document.write(Content);
				break;
			case "MSIE5":
				document.all[LayerName].innerHTML=Content;
				break;
			case "Khtml":
			case "Netscape6":
			case "MSIE5.5":
			case "Opera5":
			default:
				document.getElementById(LayerName).innerHTML=Content;
				break;
			
		}

}


function hidden(scroll) { 

/*
don«t show any scrollbar, works for MSIE, and that is where you need it
scroll can be 'hidden', 'auto', 'visible'
Internet Explorer can not use overflow:visible.
*/

	switch (SmartAgent){
		case "Netscape4":
		case "Netscape6":
		case "Khtml":
			break;
		case "MSIE5":
		case "MSIE5.5":
		case "Opera5":
			document.body.style.overflow=scroll; 
			break;
		}
}

function GetWindowWidth() { 

/*
VORSICHT: die Abfrage funktioniert nur "onload" der Seite - nicht vorher!
VORSICHT: Entgegen dem namen der Funktion wird bei Frames die Breite und Hoehe des Frames ausgespuckt.
*/
	switch (SmartAgent){
		case "Khtml":
		case "Netscape4":
		case "Netscape6":
		case "Opera5":
			my_width = window.innerWidth;
			break;
		case "MSIE5":
		case "MSIE5.5":
			my_width = document.body.clientWidth;
			break;
		default:
			my_width = document.body.clientWidth;
		break;
	}
	return my_width;
}

function GetWindowHeight() { 
/*
VORSICHT: die Abfrage funktioniert nur "onload" der Seite - nicht vorher!
VORSICHT: Entgegen dem namen der Funktion wird bei Frames die Breite und Hoehe des Frames ausgespuckt.
*/
	switch (SmartAgent){
		case "Netscape4":
		case "Netscape6":
		case "Opera5":
		case "Khtml":
			my_height = window.innerHeight;
			break;
		case "MSIE5":
		case "MSIE5.5":
			my_height = document.body.clientHeight;
			break;
		default:
			my_height = document.body.clientHeight;
		break;
	}
	return my_height;
}



function GetScreenInfo() { 

/*
VORSICHT: die Abfrage funktioniert nur "onload" der Seite - nicht vorher!
VORSICHT: Entgegen dem namen der Funktion wird bei Frames die Breite und Hoehe des Frames ausgespuckt.
*/
	my_screen = new Array();
	switch (SmartAgent) {
		case "Netscape4":
		case "Netscape6":
		case "Opera5":
		case "MSIE5":
		case "MSIE5.5":
		case "Khtml":
		default:
			my_screen['width'] = screen.width;
			my_screen['height'] = screen.height;
			my_screen['availWidth']  = screen.availWidth;
			my_screen['availHeight'] = screen.availHeight;
			my_screen['colorDepth'] = screen.colorDepth;
	}
	return my_screen;
}

// w = window
function getSelection(w,use_whitespace) {
	var mrCheckWhitespace = new RegExp('([ \\n\\t\\v\\r\\f]|%0D|%0A|%20)+', 'g');
		switch (SmartAgent){
			case "Netscape4":
			case "Netscape6":
			case "Khtml":
				pattern = escape(w.document.getSelection());
				if(use_whitespace) pattern = pattern.replace (mrCheckWhitespace,"%20");
				break;
			case "MSIE5":
				pattern = w.document.getSelection();
				break;
			case "MSIE5.5":
			case "Opera5":
				TextRange = w.document.selection.createRange();
				pattern = TextRange.text;
				break;
			default:
		}
	return pattern;
}

