var fixpng = null;

// WINOPEN CODE
function winOpen(f, n, w, h) {
  w = window.open(f,n,'width='+w+',height='+h+',left='+(screen.width/2-w/2)+',top='+(screen.height/2-h/2)+',toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no');
  w.focus();
}
function winFlashOpen(f, n, w, h) {
  w = window.open(f,n,'width='+w+',height='+h+',left='+(screen.width/2-w/2)+',top='+(screen.height/2-h/2)+',toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no');
  w.focus();
}

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 26 : 0;
var FFextraWidth=parseFloat(getFFVersion)>=0.1? 16 : 0; //extra height in px to add to iframe in FireFox 1.0+ browsers

var SafariExtraHeight = 0;
var SafariExtraWidth = -18;

var IE7_ExtraHeight = 48;
var IEL7_ExtraHeight = 20;

function show_window(a, n) {
	win = window.open(a.href,n,'width='+screen.width+',height='+screen.height+',left='+0+',top='+0+',toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
	win.focus();
}

function show_popup(a,n,w, h) {
	
	win_link = a.href + "&cb=1";
	
	screen_left = (screen.width/2-w/2);
	screen_top = (screen.height/2-h/2);
	
	window_options = 'width='+w+',height='+h+',left='+screen_left+',top='+screen_top+',toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes';
	
	win = window.open(win_link,'',window_options);
	
	win.focus();	
}

document.loadedWindow = function(win) {
	var heightAdjust = 0;
	var widthAdjust = 0;
	
	if (win.contentDocument && win.contentDocument.body.offsetHeight) { //ns6 syntax
		heightAdjust = win.contentDocument.body.offsetHeight+FFextraHeight; 
	} else if (win.document && win.document.body.scrollHeight) {//ie5+ syntax
		heightAdjust = win.document.body.scrollHeight+FFextraHeight;
	} else {
		heightAdjust = win.contentDocument.body.offsetHeight+FFextraHeight; 
	} 
	
	if (win.contentDocument && win.contentDocument.body.offsetHeight) { //ns6 syntax
		widthAdjust = win.contentDocument.body.offsetWidth;
	} else if (win.document && win.document.body.scrollHeight) {//ie5+ syntax
		widthAdjust = win.document.body.scrollWidth;
	} else {
		widthAdjust = win.contentDocument.body.offsetWidth;
	} 	
	
	if(BrowserDetect.browser=='Firefox') {
			widthAdjust = widthAdjust + FFextraWidth;
			heightAdjust = heightAdjust + FFextraHeight;			
	} else if(BrowserDetect.browser=='Safari') {
			widthAdjust = widthAdjust + SafariExtraWidth;
			heightAdjust = heightAdjust + SafariExtraHeight;		
	} else if(BrowserDetect.browser=='Explorer') {		
		if(BrowserDetect.version>=7) {
			heightAdjust = heightAdjust + IE7_ExtraHeight;
		} else {
			heightAdjust = heightAdjust + IEL7_ExtraHeight;
		}		
	}			
	win.resizeTo(widthAdjust, heightAdjust);
}

function resizeWindow(){
	if (currentfr){
		currentfr.style.display="block"	
		if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) { //ns6 syntax
			currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
			currentfr.style.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
		} else if (currentfr.Document && currentfr.Document.body.scrollHeight) {//ie5+ syntax
			currentfr.height = currentfr.Document.body.scrollHeight;
			currentfr.style.height = currentfr.Document.body.scrollHeight;
		} else {
			currentfr.style.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
		}
	}
	
	var dspSave = currentfr.style.display;
	currentfr.style.display = "none";
	currentfr.style.display = dspSave;
}

// flash hack
var bo_ns_id = 0;
function startIeFix() {
    if (isIE()) {
        document.write('<div id="bo_ns_id_' + bo_ns_id + '"><!-- ');
    }
}

function endIeFix() {  
    if (isIE()) {
        document.write('</div>');
        var theObject = document.getElementById("bo_ns_id_" + bo_ns_id++);
        var theCode = theObject.innerHTML;
        theCode = theCode.substring(4 ,9+theCode.indexOf("</object>"))
        document.write(theCode);
    }
}

function isIE() {
    var strBrwsr= navigator.userAgent.toLowerCase();
    if (strBrwsr.indexOf("msie") > -1 && strBrwsr.indexOf("mac") < 0) {
        if(parseInt(strBrwsr.charAt(strBrwsr.indexOf("msie")+5)) < 6) {
            return false;
        }
        if (strBrwsr.indexOf("win98") > -1
        || strBrwsr.indexOf("win 9x 4.90") > -1
        || strBrwsr.indexOf("winnt4.0") > -1
        || strBrwsr.indexOf("windows nt 5.0") > -1) {
            return false;
        }
        return true;
    } else {
        return false;
    }
}

function change_class(element, className) {
	element.className = className;
}

function change_bg(element, bg) {
	element.style.backgroundColor = bg;
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

BrowserDetect.init();