﻿function toggleBox(boxId, style) {
	document.getElementById(boxId).style.display = style.toString();
}

function toggleLink(linkId, style) {
	document.getElementById(linkId).style.display = style.toString();
}

function quickToggleBlock(boxId) {
	var box = document.getElementById(boxId);
	if (box.style.display == 'none') {
		box.style.display = 'block';
	} else {
		box.style.display = 'none';
	}
}

function newWindow(path, w, h) {
	var height = h;
	var width = w;
	var scroll = 0;
	var wleft = (screen.width - width - 20) / 2;
	var wtop = (screen.height - height) / 2;
	window.open(path, 'newWin', 'fullscreen=0,scrollbars=' + scroll + ',height=' + height + ',width=' + width + ',top=' + wtop + ',left=' + wleft + '');
}

function newWindowScroll(path, w, h) {
	var height = h;
	var width = w;
	var scroll = 1;
	var wleft = (screen.width - width - 20) / 2;
	var wtop = (screen.height - height) / 2;
	window.open(path, 'newWin', 'fullscreen=0,scrollbars=' + scroll + ',height=' + height + ',width=' + width + ',top=' + wtop + ',left=' + wleft + '');
}


function newImageWindow(imgPath) {
	newImage = new Image();
	newImage.src = (imgPath);

	wWidth = newImage.width + 20;
	wHeight = newImage.height + 20;
	window.open(imgPath, 'newWin', 'fullscreen=0,scrollbars=0,height=' + wHeight + ',width=' + wWidth);
}


function LoadGallery(pictureName, imageFile, titleCaption, captionText) {
	var picture = document.getElementById(pictureName);
	if (picture.filters) {
		picture.style.filter = "blendTrans(duration=1)";
		picture.filters.blendTrans.Apply();
	}
	picture.src = imageFile;
	if (picture.filters) {
		picture.filters.blendTrans.Play();
	}
	document.getElementById(titleCaption).innerHTML = captionText;
}

function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	return null;
}


function showLoadingCover(loadingMessage) {
	var cover = document.getElementById("loadingCover");
	if (cover != null) {
		cover.style.display = "block";
		changeLoadingMessage(loadingMessage);
	}
}

function changeLoadingMessage(loadingMessage) {
	$("#loadingMessage").html(loadingMessage);
}

function editIconInit() {
	$('.editIconWrap').parent().each(function(i) {
		$(this).bind("mouseenter", function() {
			$(this).find(".editIconWrap").fadeIn(200);
		}).bind("mouseleave", function() {
			$(this).find(".editIconWrap").fadeOut(200);
		});
	});
}

function loadSection(checkEl, loadEl, loader, time) {

	if ($(checkEl.length == 0)) {
		$(loader).show();
		setTimeout(update, time);
	}

	function update() {
		if ($(checkEl).length > 0) {
			$(loadEl).fadeIn("slow", function() { $(loader).hide() });
			clearTimeout();
		}
		else {
			setTimeout(update, time);
		}
	}
}

function fireEffect(selectedEffect, selectedItem) {
    //most effect types need no options passed by default
    var options = {};
    //check if it's scale, transfer, or size - they need options explicitly set
    if (selectedEffect == 'scale') { options = { percent: 0 }; }
    else if (selectedEffect == 'size') { options = { to: { width: 200, height: 60} }; }

    //run the effect
    $("#" + selectedItem).toggle(selectedEffect, options, 500);
}


function CheckAll(nameregex, current, check) {
    re = new RegExp(nameregex);
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'checkbox') {
            if (re.test(elm.name)) {
                elm.checked = check;
                
            }
        }
    }
    current.checked = check;
    if (current.checked)
        $("#selChecked").val("checked");
    else
        $("#selChecked").val("unchecked");
}

function SetUniqueRadioButton(nameregex, current) {
    re = new RegExp(nameregex);
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'radio') {
            if (re.test(elm.name)) {
                elm.checked = false;
            }
        }
    }
    current.checked = true;
}
