﻿function doAJAXRefresh() {
	$j.get("./Administration/");
	SetTimer();
}
function SetTimer() {
	setTimeout("doAJAXRefresh()", 300000);
}
function MainTooltips()
{
	$j("input, select").each(function(e) {
		var inputTitle = $j(this).attr("title");
		if (inputTitle.length > 0) {
			$j(this).tooltip({
				delay: 500,
				showURL: false,
				bodyHandler: function() {
					return inputTitle;
				}
			});
		}
	});
}
function SelectFileBothAreas2(chkBoxID, anchorID, currentAreaID, secondaryAreaID) {
	SelectFile2(chkBoxID, anchorID);
	SelectFile2(chkBoxID.replace(currentAreaID, secondaryAreaID), anchorID.replace(currentAreaID, secondaryAreaID));
}
function SelectFile2(chkBoxID, anchorID) {
	var chkBox = $j("#" + chkBoxID).get(0);
	var listItem = $j("#" + anchorID).parent();

	chkBox.checked = (!chkBox.checked);
	if (!listItem.hasClass("selected")) {
		listItem.addClass("selected");
	}
	else {
		listItem.removeClass("selected");
	}
}
function CheckOrUncheckAllFiles(itemID, chkID) {
	var mainCheckBox = $j("#" + chkID).get(0);
	$j("#" + itemID + " li.file").each(function() {
		var checkBox = $j(this).find("span.filecheck input").get(0);
		if (mainCheckBox.checked) {
			$j(this).addClass("selected");
			checkBox.checked = true;
			mainCheckBox.title = "Unselect all";
		}
		else {
			$j(this).removeClass("selected");
			checkBox.checked = false;
			mainCheckBox.title = "Select all";
		}
	});
}
function InitFileManager() {
    $j(document).ready(function() {
        if ($j(".iconlink").length > 0) {
            $j(".iconlink").tooltip({
                delay: 500,
                showURL: false,
                bodyHandler: function() {
                    return $j(this).find(".tooltip").html();
                }
            });
        }
        if ($j(".filehelp_b").length > 0) {
            $j(".filehelp_b").tooltip({
            delay: 500,
            showURL: false,
            bodyHandler: function() {
            return $j(this).parent().parent().parent().find(".filehelptext").html();
            }
            });
        }
        if ($j(".togglebutton2").length > 0 && $j(".icons").length > 0 && $j(".list").length > 0) {
            if ($j(".togglebutton2 .filecheck input").get(0).checked) {
                $j(".icons").addClass("hidden");
                $j(".list").removeClass("hidden");
            }
            else {
                $j(".icons").removeClass("hidden");
                $j(".list").addClass("hidden");
            }
            $j(".togglebutton2").click(function(e) {
                $j(".togglebutton2 .filecheck input").get(0).checked = !($j(".togglebutton2 .filecheck input").get(0).checked)
                if ($j(".icons").hasClass("hidden")) {
                    $j(".icons").removeClass("hidden");
                }
                else {
                    $j(".icons").addClass("hidden");
                }
                if ($j(".list").hasClass("hidden")) {
                    $j(".list").removeClass("hidden");
                }
                else {
                    $j(".list").addClass("hidden");
                }
            });
        }
        MainTooltips();
    });
}

$j(document).ready(function() {
	MainTooltips();
	//SetTimer();
});


// Sets all checkboxes inside "elem" to value "check"
function CheckOrUncheck(elem, check)
{
	$j("input, select").each(function(e) {
		var inputTitle = $j(this).attr("title");
		if (inputTitle.length > 0) {
			$j(this).tooltip({
				delay: 500,
				showURL: false,
				bodyHandler: function() {
					return inputTitle;
				}
			});
		}
	});
}

$j(document).ready(function() {
	MainTooltips();
	//SetTimer();
});


// Sets all checkboxes inside "elem" to value "check"
function CheckOrUncheck(elem, check) {
	var i = 0;
	for (i = 0; i < elem.childNodes.length; i++) {
		if (elem.childNodes.item(i).tagName == "INPUT" && elem.childNodes.item(i).type == "checkbox" && elem.childNodes.item(i).disabled == false) {
			elem.childNodes.item(i).checked = check;
		}
		if (elem.childNodes.item(i).childNodes.length > 0) {
			CheckOrUncheck(elem.childNodes.item(i), check);
		}
	}
}
function DisableOrEnable(elem, enabled) {
	var i = 0;
	for (i = 0; i < elem.childNodes.length; i++) {
		if (elem.childNodes.item(i).tagName == "INPUT" && elem.childNodes.item(i).type == "checkbox") {
			elem.childNodes.item(i).disabled = enabled;
		}
		if (elem.childNodes.item(i).childNodes.length > 0) {
			DisableOrEnable(elem.childNodes.item(i), enabled);
		}
	}
}
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function RegisterHtmlEditorJsFiles(siteRoot) {
	var count = 0;
	var tds = document.getElementsByTagName('TextArea');
	var i = 0;
	for (i = 0; i < tds.length; i++) {
		if (tds[i].title != null) {
			if (tds[i].title == 'HtmlEditor') {
				if (count == 0) {
					document.write('<script language="JavaScript" src="' + siteRoot + 'tiny_mce3211/tiny_mce.js" type="text/javascript"></script>');
					document.write('<script language="JavaScript" src="' + siteRoot + 'TinyMCEConfig.aspx?config=/tiny_mce3211/Config_limited.js" type="text/javascript"></script>');
				}
				count++;
				break;
			}
		}
	}
}
function RegisterHtmlEditors() {
	var tds = document.getElementsByTagName('TextArea');
	var i = 0;
	for (i = 0; i < tds.length; i++) {
		if (tds[i].title != null) {
			if (tds[i].title == 'HtmlEditor') {
				//alert(tds[i].id);
				tinyMCE.execCommand('mceAddControl', false, tds[i].id);
			}
		}
	}
}
function AddHoverToElement(e, title) {
	var newTitle = "<b>" + title + "</b>";
	var breakIndex = title.indexOf(":");
	if (breakIndex != -1) {
		newTitle = "<b>" + title.substr(0, breakIndex) + "</b>" + title.substr(breakIndex, title.length - breakIndex);
		newTitle = newTitle.replace("::", "<br/><br/>");
	}
	ddrivetip(newTitle, '#FFFFCC', 250);
}
function AddHoverOutToElement(e) {
	hideddrivetip();
}
function RegisterToolTips() {

	var jQuery = typeof ($$) != "function"; // only prototype implements $$
	if (!jQuery) {
		var tds = $$('.hoverTip');
		var i = 0;
		for (i = 0; i < tds.size(); i++) {
			var title = tds[i].readAttribute('title');
			if (title != null) {
				if (title.length > 0) {
					Event.observe(tds[i], 'mouseover', AddHoverToElement.bindAsEventListener(this, title));
					Event.observe(tds[i], 'mouseout', AddHoverOutToElement.bindAsEventListener(this));
					//tds[i].alt = ''
					tds[i].writeAttribute('title', '');
				}
			}
		}
	}
	else {
		var tds = $('.hoverTip');
		var i = 0;
		for (var i = 0; i < tds.length; i++) {
			var title = tds[i].attr('title');
			if (title != null) {
				var o = tds[i];
				o.simpleTip({ content: title, fixed: false });
				//o.bind("mouseover", function(e) { AddHoverToElement(e, title) });
			}
		}
	}
}



function HideAjaxLoader(id) {

	document.getElementById(id).style.display = 'none';
}
function RegisterCorners() {
	settings = {
		tl: { radius: 50 },
		tr: { radius: 50 },
		bl: { radius: 50 },
		br: { radius: 50 },
		antiAlias: true,
		autoPad: true
	}
	var myBoxObject = new curvyCorners(settings, "myBox");
	myBoxObject.applyCornersToAll();
}

function RegisterSingleCorner(elem, radtl, radtr, radbl, radtbr) {
	settings = {
		tl: { radius: radtl },
		tr: { radius: radtr },
		bl: { radius: radbl },
		br: { radius: radtbr },
		antiAlias: true,
		autoPad: true
	}
	var myBoxObject = new curvyCorners(settings, elem);
	myBoxObject.applyCornersToAll();
}


function JSDoPostback(elemName) {
	JSDoPostback(elemName, null, null);
}
function JSDoPostback(elemName, paramHiddenName, param) {
	if (param != null)
		document.getElementById(paramHiddenName).value = param;
	document.getElementById(elemName).click();
}

function ADGDoAction(actionElem, paramElem, actionCode) {
	ADGDoAction(actionElem, paramElem, actionCode, '');
}
function ADGDoAction(actionElem, paramElem, actionCode, cmdArgument) {
	document.getElementById(paramElem + '2').value = cmdArgument;
	document.getElementById(paramElem).value = actionCode;
	document.getElementById(actionElem).click();
}
function ADGClickButton(event, buttonID) {
	if (event.type != "keypress" || event.keyCode != 13)
		return true;
	var elem = document.getElementById(buttonID);
	if (elem.tagName == "A")
		location.href = elem.href;
	if (elem.tagName == "INPUT" && elem.type == "button")
		elem.click();

	var evt = document.createEvent("HTMLEvents");
	evt.initEvent("click", true, true);
	elem.dispatchEvent(evt);

	return false;
}
function DoPopup(url) {
	window.open(url, "", 'resizable=1,height=700,width=900,scrollbars=1');
}
function DoPopup(url, width, height) {
	window.open(url, "", 'resizable=1,height=' + height + ',width=' + width + ',scrollbars=1');
}
function ShowDiv(id) {
	document.getElementById(id).style.display = 'block';
}
function ShowInlineDiv(id) {
	document.getElementById(id).style.display = 'inline';
}
function HideDiv(id) {
	document.getElementById(id).style.display = 'none';
}
function ToggleDisplayDiv(id) {
	if (document.getElementById(id).style.display == 'none')
		document.getElementById(id).style.display = 'block';
	else
		document.getElementById(id).style.display = 'none';
}
function toggleLayer(whichLayer) {
	var elem, vis;
	if (document.getElementById)
		elem = document.getElementById(whichLayer)
	vis = elem.style;
	if (vis.display == '' && elem.offsetWidth != undefined && elem.offsetHeight != undefined)
		vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0) ? 'block' : 'none';
	vis.display = (vis.display == '' || vis.display == 'block') ? 'none' : 'block';
}

/*
Fading Image Script 
*/
function makevisible(cur, which) {
	if (which == 0) {
		if (navigator.appName.indexOf("Netscape") != -1 && parseInt(navigator.appVersion) >= 5)
			cur.style.MozOpacity = 1;
		else if (navigator.appName.indexOf("Microsoft") != -1 && parseInt(navigator.appVersion) >= 4)
			cur.filters.alpha.opacity = 100;
	}
	else {
		if (navigator.appName.indexOf("Netscape") != -1 && parseInt(navigator.appVersion) >= 5)
			cur.style.MozOpacity = 0.35;
		else if (navigator.appName.indexOf("Microsoft") != -1 && parseInt(navigator.appVersion) >= 4)
			cur.filters.alpha.opacity = 35;
	}
}

