﻿function OpenWindow(URL, Name, Width, Height) {
	var PositionX = 0;
	var PositionY = 0;
	var DefaultWidth  = 600;
	var DefaultHeight = 400;
	var WinObject, Params = 'scrollbars=1, resizable=1, left=' + PositionX + ', top=' + PositionY;
	Params += ', width=' + ((isNaN(parseInt(Width))) ? DefaultWidth : Width);
	Params += ', height=' + ((isNaN(parseInt(Height))) ? DefaultHeight : Height);
	WinObject = window.open(URL, Name, Params)
	if (!WinObject) return true;
	if (WinObject.focus) WinObject.focus();
	return false;
}

function InsertFlash(Target, ID, Version, File, Width, Height, Parameters) {
	var ParametersObjectStr = ''
	var ParametersEmbedStr = ''
	var s, v
	for (s in Parameters) {
		v = Parameters[s]
		ParametersObjectStr += '<param name="'+s+'" value="'+v+'" />'
		ParametersEmbedStr += ' '+s+'="'+v+'" '
	}
	var FlashHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ' +
			'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+Version+',0,0,0" ' +
			'width="'+Width+'" height="'+Height+'" id="'+ID+'">' +
			'<param name="movie" value="'+File+'" />' +
			ParametersObjectStr +
			'<embed src="'+File+'" menu="true" ' +
				'pluginspage="http://www.macromedia.com/go/getflashplayer"  ' +
				'type="application/x-shockwave-flash" width="'+Width+'" height="'+Height+'" name="'+ID+'" '+ParametersEmbedStr+' />' +
		'</object>'
	document.getElementById(Target).innerHTML = FlashHTML
}

function VerifyBrowserFlashSupport(FlashVersion) {
	var flashinstalled = 0;
	var flashversion = 0;
	if (navigator.plugins && navigator.plugins.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if (x) {
			flashinstalled = 2;
			if (x.description) {
				var y = x.description;
				if (y.charAt(y.indexOf('.')-1)+'' == FlashVersion+'') return true;
			}
		}
		if ((FlashVersion == 2) && (navigator.plugins["Shockwave Flash 2.0"])) {
			return true;
		}
	} else if (navigator.mimeTypes && navigator.mimeTypes.length) {
	} else {
		try{
			var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + FlashVersion);
			return true;
		}
		catch(e){
		}
	}
	return false;
}

function InsertFlashOrHTML(Target, ID, Version, File, Width, Height, Parameters, NoFlashHTML) {
	if (VerifyBrowserFlashSupport(Version)) {
		InsertFlash(Target, ID, Version, File, Width, Height, Parameters)
	} else {
		document.getElementById(Target).innerHTML = NoFlashHTML
	}
}

function __doSearch(){
	SearchFieldTrim();
	if (document.frmSearch.txtSearch.value != DummySearchString && document.frmSearch.txtSearch.value != '') {
		document.getElementById('pp'+'search').value = '200';
		document.frmSearch.action = 'search';
		document.frmSearch.submit();
	}
}

function SearchFieldTrim() {
	var s = document.frmSearch.txtSearch.value;
	var x, l, TrimLeft, TrimRight;
	l = s.length;
	TrimLeft = -1;
	TrimRight = l;
	for (x=0; x<l; x++) {
		if ((s.charAt(x) != ' ') && (s.charAt(x) != '	')) break;
		TrimLeft = x;
	}
	TrimLeft++;
	if (TrimLeft < TrimRight) {
		for (x=l-1; x>TrimLeft; x--) {
			TrimRight = x+1;
			if ((s.charAt(x) != ' ') && (s.charAt(x) != '	')) break;
		}
		s = s.substring(TrimLeft, TrimRight);
	} else {
		s = '';
	}
	document.frmSearch.txtSearch.value = s;
	return s;
}

function __focusSearch() {
	if (document.frmSearch.txtSearch.value == DummySearchString) {
		document.frmSearch.txtSearch.value = '';
	}
}

function __blurSearch() {
	SearchFieldTrim();
	if (document.frmSearch.txtSearch.value == '') {
		document.frmSearch.txtSearch.value = DummySearchString;
	}
}

function __enterSearch(event) {
	var code = 0;
	code = event.keyCode;
	if (code==13) {
		__doSearch();
	}
}

function ChkNum(sn, dn) {
	if (isNaN(sn) || sn == "" || sn == " "){
		return dn;
	} else {
		return sn;
	}
}

function no_enter() {
	return !(window.event && window.event.keyCode == 13);
}

function switchDivs(div_on, div_off){
	if(document.getElementById('o_miniselected')){
		document.getElementById('o_miniselected').id = '';
	}
	document.getElementById(div_on).style.display = 'block';
	document.getElementById(div_on).style.visibility = 'visible';
	document.getElementById(div_off).style.display = 'none';
	document.getElementById(div_off).style.visibility = 'hidden';
}

// context popup
function $$(id) {
	try {
		return document.getElementById(id);
	}
	catch (e){
		return null;
	}
}

var IE = document.all ? true : false;
if (!IE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouseXY;
var mouseX = 0;
var mouseY = 0;
document.onclick = CheckHideContextPopup;

function getMouseXY(e) {
	if (IE) {
		mouseX = event.clientX + document.documentElement.scrollLeft;
		mouseY = event.clientY  + document.documentElement.scrollTop;
	} else {
		mouseX = e.pageX;
		mouseY = e.pageY;
	}
	if (mouseX < 0) { mouseX = 0 };
	if (mouseY < 0) { mouseY = 0 };
	return true;
}

function CheckHideContextPopup(e) {
	var target = (e && e.target) || (event && event.srcElement);
	if (target.className != "ContextLink") {
		CheckContextPopupParent(target) ? HideContextPopup() : null;
	}
}

function CheckContextPopupParent(t) {
	while (t) {
		if (t == $$("ContextPopup")) {
			return false;
		}
		t = t.parentNode;
	}
	return true;
}

function ShowContextPopup(e, c) {
	HideContextPopup();
	$$("ContextPopup").style.top = mouseY + "px";
	if (mouseX > (GetWidth() - 300)) {
		mouseX = GetWidth() - 320;
	}
	document.getElementById("ContextPopup").style.left = mouseX + "px";
	$$("ContextPopup").style.display = "block";
	$$("ContextPopupContainer").innerHTML = $$(c).innerHTML;
}
function HideContextPopup() {
	if ($$("ContextPopup") != null){
		$$("ContextPopup").style.display = "none";
		$$("ContextPopupContainer").innerHTML = "";
	}
}

// Get window width & height
function GetWidth() {
	var x = 0;
	if (self.innerHeight) {
		x = self.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientHeight) {
		x = document.documentElement.clientWidth;
	}
	else if (document.body) {
		x = document.body.clientWidth;
	}
	return x;
}
function GetHeight() {
	var y = 0;
	if (self.innerHeight) {
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) {
		y = document.documentElement.clientHeight;
	}
	else if (document.body) {
		y = document.body.clientHeight;
	}
	return y;
}
