﻿// JScript File
function OnCMMenuItemClick(id) { 
    var hl = document.getElementById(id);
    if (hl) { hl.click(); }
}
function CMMenuApplyCellStyle(cell,inStyle) {
    //inStyle = "Background-color:#ff0000; Padding-Top: 10px;border-bottom: solid 5px green";
    if (cell && inStyle) {
        inStyle = inStyle.toLowerCase();

        //now split into separate styles
        var styles = inStyle.split(';');
        for (i in styles) {
            if (styles[i]) {
                try
                {
                    var KeyValue = styles[i].split(':');
                    var key = KeyValue[0];
                    key = key.replace(/ /g,'');
                    key = key.replace(/-a/g,'A').replace(/-b/g,'B').replace(/-c/g,'C').replace(/-d/g,'D').replace(/-e/g,'E');
                    key = key.replace(/-f/g,'F').replace(/-g/g,'G').replace(/-h/g,'H').replace(/-i/g,'I').replace(/-j/g,'J');
                    key = key.replace(/-k/g,'K').replace(/-l/g,'L').replace(/-m/g,'M').replace(/-n/g,'N').replace(/-o/g,'O');
                    key = key.replace(/-p/g,'P').replace(/-q/g,'Q').replace(/-r/g,'R').replace(/-s/g,'S').replace(/-t/g,'T');
                    key = key.replace(/-u/g,'U').replace(/-v/g,'V').replace(/-w/g,'W').replace(/-x/g,'X').replace(/-y/g,'Y');
                    key = key.replace(/-z/g,'Z');
                    cell.style[key] = KeyValue[1];
                }
                catch(err)
                {
                    //Handle errors here
                }
            }
        }
    } // End If
} // End Function

function TSGS_SwapImage(id,img) {
    obj = MM_findObj(id);
    obj = document.getElementById(id);
    //alert("obj: " + id);
    if (obj) { obj.src = img; }
}
var Showing = new Array;
function TSGS_SwapBGImage(obj,imgurl) {
    //obj = MM_findObj(id);
    if (obj) { obj.style.backgroundImage = 'url('+imgurl+')'; }
}
function TSGS_SwapBorder(obj,color) {
    if (obj) { obj.style.borderColor = color; }
}
function TSGS_SwapBGColor(obj,color) {
    if (obj) { obj.style.backgroundColor = color; }
}
//function lkjlk() {
//        cell.style.textAlign = horizontalalign;
//        cell.style.verticalAlign = verticalalign;

//}
function TSGS_ChangeText(id,font,color,size,style,weight,decoration) {
//alert('id: ' + id);
    obj = MM_findObj(id);
    obj = document.getElementById(id);
    if (obj) {
    //color = '';
    //decoration = '';
//alert('id=' + id + " objid: " + obj.id);
        obj.style.fontFamily = font;
        obj.style.fontWeight = weight;
        obj.style.fontStyle = style;
        obj.style.color = color;
        obj.style.fontSize = size;
        obj.style.textDecoration = decoration;
//alert('font: ' + font + '\n'+' color: ' + color + '\n'+' size: ' + size + '\n'+' style: ' + style + '\n'+' weight: ' + weight + '\n'+' decor: ' + decoration + '\n');
    }
}
function CellClicked(navurl) {
    //alert('going to: ' + navurl);
    //window.parent.location.href
    window.location.href = navurl;
}
function ShowSubMenu(obj,id,level,o,xoffset,yoffset) {
//alert('level: ' + level);
    //o = orientation, values are 'h' and 'v'
    //d = MM_findObj('Debug');
    //d.innerHTML = "Length: " + Showing.length;
    //Loop through all the open menus and hide the ones with a higher level
    for (i=Showing.length-1; i>=0; i-=1) {
        if (Showing[i][1]>=level) {
            Showing[i][0].style.zIndex = 0;
            Showing[i][0].style.visibility = 'hidden';
            Showing.splice(i,1);
        }
    }
    //Stop timer if one has been started
	if (window.timer) {
		clearTimeout(window.timer);
	}
	//make submenu visible if possible
    m = MM_findObj(id);
    m = document.getElementById(id);
    if (m) {
    //alert('x: ' + xoffset + ' y: ' + yoffset);
        m.style.visibility = 'visible';
        m.style.zIndex = 1000;
        if (o == 'h') {
            m.style.top = (docjslib_getRealTop(obj) + obj.offsetHeight + yoffset) + 'px';
            m.style.left = (docjslib_getRealLeft(obj) + xoffset) + 'px';
        } else {
            m.style.top = (docjslib_getRealTop(obj) + yoffset) + 'px';
            //alert("mtop: " + m.style.top);
            m.style.left = (docjslib_getRealLeft(obj) + obj.offsetWidth + xoffset) + 'px';
        }
        var Menu = new Array(m,level);
        Showing[Showing.length] = Menu;
    }
//alert("showsubmenu: obj=" + obj + " id=" + id + " level=" + level + " o=" + o);
}
function HideSubMenu() {
	window.timer = setTimeout("HideAll()", 1000);
}
function HideAll() {
    for (i=Showing.length-1; i>=0; i-=1) {
            Showing[i][0].style.visibility = 'hidden';
            Showing.splice(i,1);
    }
}
function docjslib_getRealTop(imgElem) {
	yPos = eval(imgElem).offsetTop;
	tempEl = eval(imgElem).offsetParent;
	//alert("ypos: " + yPos + " parent: " + tempEl.id);
	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
	return yPos;
}
function docjslib_getRealLeft(imgElem) {
	xPos = eval(imgElem).offsetLeft;
	tempEl = eval(imgElem).offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function popUp(URL,w,h) {
    //alert('here' + URL);
    var winW = "700";
    var winH = "500";
    if (w) { winW = w; }
    if (h) { winH = h; }
        
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+winW+",height="+winH+",left = 290,top = 150');");
    return false;
}

var PageLoadAdded = false;
function pageLoad( )
{
    if (!PageLoadAdded && typeof(PageLoadedHandler) != 'undefined') {
        Sys.WebForms.PageRequestManager.getInstance( ).add_pageLoaded( PageLoadedHandler );
        PageLoadAdded = true;
        //alert('loaded');
    }
}
