﻿function PostToNewWindow() {
	var form = document.getElementById('WebForm1');
	/* if you need to open always in the same window use */
	//form.target = "osWin";
	/* if you want to open always a new window use */
	form.target = "_blank";
	form.onsubmit += "window.open('about:blank','osWin');";
	setTimeout("ClearTarget()",1000);
}
function ClearTarget(form) {
	var form = document.getElementById('WebForm1');
	form.target = "";
}

function clickButton(buttonName){
     document.getElementById('wt'+buttonName).click();
}

function clickButtonBlock(buttonName,blockName){
     document.getElementById('wt'+blockName+'_wt'+buttonName).click();
}

function FieldEnabled(relatedField,TargetField){
	if (document.getElementById('wt'+relatedField).checked)
		document.getElementById('wt'+TargetField).disabled='';
	else
		document.getElementById('wt'+TargetField).disabled='disabled';
}

function clickBlockButton(buttonName){
     document.getElementById('wtblock1'+buttonName).click();
}

function chkDiv_clickShow2(oField, sDivObjName)
{	
	oDivObj = document.getElementById(sDivObjName);	
	oDivObj.style.display = '';
	
}

function chkDiv_clickHide2(oField, sDivObjName)
{	
	oDivObj = document.getElementById(sDivObjName);	
	oDivObj.style.display = 'none';
}

function selectColor()
{
	var myColor = dlgColor.ChooseColorDlg();
	alert(myColor);
}

function newWindow(url)
{
	w = window.open (url, 'ColorPalete', 'width=155,height=130,status=no,toolbar=no,menubar=no');
}


/****************************************** Acoreana_Template ****************************************/
function StyleGuide_Common_Menu_bootstrap(activeTopMenuName)
{
    var initFunc = new Function("StyleGuide_Common_Menu_init('" + activeTopMenuName + "');");

    if (window.addEventListener)
    {
        window.addEventListener('load', initFunc, false);
    }
    else if (window.attachEvent)
    {
        window.attachEvent('onload', initFunc);
    }
}

function StyleGuide_Common_Menu_init(activeTopMenuName)
{
    // to avoid IE6 image flickering and to avoid this running on Firefox!
    var m = document.uniqueID /*IE*/
            && document.compatMode  /*>=IE6*/
            && !window.XMLHttpRequest /*<=IE6*/
            && document.execCommand;

    try
    {
        if(!!m)
            m("BackgroundImageCache", false, true); /* = IE6 only */
    }
    catch (oh)
    {
    }

    var menus = document.getElementsByClassName('Menu_Items');

    for (var j = 0; j < menus.length; ++j)
    {
        if (!menus[j].attributes.isMenu)
        {
            menus[j].isMenu = "true";
            var menuEntries = menus[j].getElementsByTagName("td");
            for (var i = 0; i < menuEntries.length; ++i)
            {
                var topMenu = menuEntries[i];
                if (topMenu.id == "")
                    topMenu.id = "menu_" + j + "_" + i;


                if (topMenu.firstChild.attributes.menuName && menuEntries[i].firstChild.attributes.menuName.value == activeTopMenuName)
                {
                    menuEntries[i].className = "Menu_ItemActive";
                }

                var dropDownMenu = null;
                if (topMenu.firstChild.attributes.dropDownMenuId && (dropDownMenu = document.getElementById(topMenu.firstChild.attributes.dropDownMenuId.value)))
                {
                    topMenu.onmouseover = new Function("StyleGuide_Common_Menu_showDropDownMenu('" + dropDownMenu.id + "', '" + topMenu.id + "', '" + activeTopMenuName + "');");

                    dropDownMenu.setAttribute('parentMenuId', topMenu.id);
                    dropDownMenu.style.position = 'absolute';
                    dropDownMenu.onmouseover = new Function("StyleGuide_Common_Menu_showDropDownMenu('" + dropDownMenu.id + "', '" + topMenu.id + "', '" + activeTopMenuName + "');");
                    dropDownMenu.onmouseout = new Function("StyleGuide_Common_Menu_showDropDownMenu('', '" + topMenu.id + "', '" + activeTopMenuName + "');");
                }
                else
                {
                     topMenu.onmouseover = new Function("StyleGuide_Common_Menu_showDropDownMenu('', '', '" + activeTopMenuName + "');");
                }
                topMenu.onmouseout = new Function("StyleGuide_Common_Menu_showDropDownMenu('', '" + topMenu.id + "', '" + activeTopMenuName + "');");
            }
        }
    }
}

function StyleGuide_Common_Menu_expandCollapseHiddenMenus(hiddenMenusContainerId, imageId)
{
    var hiddenMenus = document.getElementById(hiddenMenusContainerId);
    var image = document.getElementById(imageId);

    var menuExpanded = (StyleGuide_Common_Menu_getCookie("MenuExpanded") == "true");

    if (!menuExpanded)
    {
        new Effect.BlindRight(hiddenMenus);
        image.src = new String(image.src).replace("img/Menu_Collapsed.png", "img/Menu_Expanded.png");
    }
    else
    {
        new Effect.BlindLeft(hiddenMenus);
        image.src = new String(image.src).replace("img/Menu_Expanded.png", "img/Menu_Collapsed.png");
    }

    menuExpanded = !menuExpanded;
    StyleGuide_Common_Menu_setCookie("MenuExpanded", menuExpanded);
}

function StyleGuide_Common_Menu_showDropDownMenu(dropDownMenuId, topMenuId, activeTopMenuName)
{
    var topMenu = document.getElementById(topMenuId);
    var dropDownMenu = document.getElementById(dropDownMenuId);
    var dropDownMenus = document.getElementsByClassName('Menu_SubItems');
    if (!dropDownMenuId || (dropDownMenu && dropDownMenu.style.display != 'block'))
    {
        for (var i = 0; i < dropDownMenus.length; i++)
            dropDownMenus[i].style.display = 'none';
    }
    if (dropDownMenu)
    {
        if (dropDownMenu.style.display != 'block')
        {
            if (topMenuId)
                StyleGuide_Common_Menu_setLayer(topMenu, dropDownMenuId);
            dropDownMenu.style.display = 'block';
            var parentMenu = document.getElementById(dropDownMenu.attributes.parentMenuId.value);
            parentMenu.className = "Menu_ItemSelected";
        }
    }
    else if (!dropDownMenuId && topMenu)
    {
        if (!topMenu.firstChild.attributes.menuName || topMenu.firstChild.attributes.menuName.value != activeTopMenuName)
            topMenu.className = "Menu_Item";
        else
            topMenu.className = "Menu_ItemActive";
    }
}

function StyleGuide_Common_Menu_findPos(obj)
{
    var curleft = 0;
    var curtop = 0;
    if (obj.offsetParent)
    {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent)
        {
            if (obj.className != 'Menu')
                curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft, curtop];
}

function StyleGuide_Common_Menu_setLayer(obj, layer)
{
    var coords = StyleGuide_Common_Menu_findPos(obj);
    var x = document.getElementById(layer);
    if (obj.offsetParent && obj.offsetParent.className == 'Menu')
        x.style.top = (obj.offsetParent.offsetHeight -1) + 'px';
    else
        x.style.top = (obj.offsetHeight -1) + 'px';
    x.style.left = coords[0] + 'px';
}

function StyleGuide_Common_Menu_setCookie(name, value)
{
    var path = document.location.href;
    path = path.replace(/\/\([^\/]*/, ""); //remove sessionId
    path = path.replace(/https?:\/\/[^\/]*/i, ""); //remove protocol and server
    path = path.replace(/[^\/]+\.[^\.\/]+/, ""); //remove filename

    document.cookie = name + "=" + escape(value) + "; path=" + path;
}

function StyleGuide_Common_Menu_getCookie(name)
{
    var arg = name + "=";
    var i = 0;
    while (i < document.cookie.length)
    {
        var offset = i + arg.length;
        if (document.cookie.substring(i, offset) == arg)
        {
            var str = document.cookie.indexOf(";", offset);
            if (str == -1)
                str = document.cookie.length;
            return unescape(document.cookie.substring(offset, str));
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0)
            break;
    }
    return null;
}
/****************************************** Acoreana_Template ****************************************/
