﻿// JScript File

var isIE7 = false;
var isIE = false;
var isIE6 = false;
var isNS = false;
var change = false;

if(navigator.appVersion.indexOf('MSIE 7')!=-1) isIE7 = true;
if(navigator.appVersion.indexOf('MSIE 6')!=-1) isIE6 = true;
if(navigator.appName.indexOf('Netscape')!=-1){
	isNS = 1;
} else {
	if(navigator.appName.indexOf('Microsoft Internet Explorer')!=-1){
		isIE = 1;
	} else {
		isOtherBrowser = 1;
	}
}

var popup_close = false;
var popup_back = false;
var popup = false;

function newpopup(name, widthPop, heightPop){
/*             popup_back  = document.createElement("div");
             if(isNS){
                popup_back.setAttribute("style","position: fixed; background-color: white; width: 100%; height: 100%; top: 0px; left: 0px;");
            	popup_back.style.opacity = .82;
             } else {
                 popup_back.style.position = "fixed";
                 popup_back.style.width = "100%";
                 popup_back.style.height = "100%";
                 popup_back.style.top = "0";
                 popup_back.style.left = "0";
                 popup_back.style.backgroundColor = "white";
            	popup_back.style.filter = "alpha(opacity=" + Math.round(82) + ")";
             }*/
          popup_back = Builder.node("div", {
                        id: "popupCont",
                        style: "position: fixed; background-color: white; width: 100%; height: 100%; top: 0px; left: 0px;"
                                });
            $(popup_back).setOpacity(.82);

             if(isIE6){
                popup_back.style.position = "absolute";
                  popup_back.style.top = 0;
                  popup_back.style.left = 0;
                  popup_back.style.width = $('bodyCenter').offsetWidth;
                  popup_back.style.height = $('bodyCenter').offsetHeight;
            
            }

             popup_back.style.zIndex = 9998;
             popup_back.id = "popupback";
             if(isIE){
                popup_back.onclick = closePopup;
              } else {
                popup_back.setAttribute("onclick","closePopup(event,this)");
              }
              document.body.appendChild(popup_back);

                leftPop = (popup_back.offsetWidth - widthPop) / 2 ;
                topPop = (popup_back.offsetHeight - heightPop) / 2;

/*              popup = document.createElement("div");
              popup.id = "popupCont";


             if(isNS){
                  popup.setAttribute("style","overflow: auto; padding: 0px 0px 0px 0px; position: fixed; background-color: #FAF8F4; width: " + widthPop + "px; height: " + heightPop + "px; top: " + topPop + "px; left: " + leftPop + "px; border: 1px solid black;");
             } else {
                  popup.style.overflow = "auto";
                  popup.style.borderStyle = "solid";
                  popup.style.borderWidth = "1px";
                  popup.style.borderColor = "#ccc";
                  popup.style.position = "fixed";
                  popup.style.padding = "0px 0px 0px 0px";
                  popup.style.width = widthPop;
                  popup.style.height = heightPop;
                  popup.style.top = topPop;
                  popup.style.left = leftPop;
                  popup.style.backgroundColor="#FAF8F4";
                  popup.style.id = "fixme"
             }*/
             
             popup = Builder.node("div", {
                        id: "popupCont",
                        style: "overflow: auto; padding: 0px 0px 0px 0px; position: fixed; background-color: #FAF8F4; width: " + widthPop + "px; height: " + heightPop + "px; top: " + topPop + "px; left: " + leftPop + "px; border: 1px solid black;"
                                            });
             if(isIE6){
                popup.style.position = "absolute";
                clientWidth = document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
                clientHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
                scrollLeft = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft;
                scrollTop = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
                popup.style.left = (scrollLeft + (clientWidth - widthPop) / 2) + 'px';
                popup.style.top =  (scrollTop + (clientHeight - heightPop) / 2) + 'px';
            
            }
             popup.style.zIndex = 100000;
              document.body.appendChild(popup);

    popup.innerHTML = "<div style='height: 100%; width: 100%; background-color: #ddd;><div style='top: " + ((heightPop / 2) - 10) + ";text-align: center;'>Loading...</div></div> ";
    
        new Ajax.Updater('popupCont', '/servicePopup.aspx?name=' + name, {asynchronous:true, evalScripts: true});
              //popup.innerHTML = "<br />window " + popup_back.offsetHeight + "<br />document";// + document.body.offsetWidth;


              popup_close = document.createElement("div");

             if(isIE){
                popup_close.onclick = closePopup;
              } else {
                popup_close.setAttribute("onclick","closePopup(event,this)");
              }
              popup_close.innerHTML = "<i>click here to close...</i>"
              document.body.appendChild(popup_close);

                  popup_close.style.position = "fixed";
                  popup_close.style.cursor = "pointer";
                  popup_close.style.top = (popup.offsetTop + heightPop - popup_close.offsetHeight) + "px";
                  popup_close.style.left = popup.offsetLeft+ 1 + "px";
                  popup_close.style.backgroundColor="#FAF8F4";
                  popup_close.style.textAlign = "right";
                  popup_close.style.width = popup.offsetWidth - 2 + "px";

             popup_close.style.zIndex = 100001;

             if(isIE6){
                popup_close.style.position = "absolute";
                  popup_close.style.top = popup.offsetTop + heightPop - popup_close.offsetHeight;
                  popup_close.style.left = popup.offsetLeft + widthPop - popup_close.offsetWidth;
            
            }
}

function closePopup(e, targ) {
/*$(popup_back).hide();
$(popup).hide();
$(popup_close).hide();*/
    document.body.removeChild(popup_back);
    document.body.removeChild(popup);
    document.body.removeChild(popup_close);

}


var dayArray = null;
var maxdays = null;

//Function for makeup days to make sure only 3 checkmarks are check
function dayCheck(e){
    //Get target checkbox
    var targ = window.event ? window.event.srcElement : e;
    
    //See whether the target checkbox is checked, and verify not in array
    if(targ.checked)
    {
        //If there are already more than the maxdays, uncheck the first one checked
        if(dayArray.length >= maxdays && dayArray.length > 0) dayArray.shift().checked = false;

        //Add new checkbox to the array
        dayArray.push(targ);
    } else if(targ.checked==false) {
        //Checkbox was unchecked so remove from array
        dayArray = dayArray.without(targ);
    }
    /*svar days = '';
    dayArray.each(function(item){
        if(days.length>0) days += ',';
        days += item.id;
    });
    $('temp').innerHTML = days;*/
}

function submitMakeupDays(){
    var days = '';
    dayArray.each(function(item){
        if(days.length>0) days += ',';
        days += item.id;
    });
        new Ajax.Updater('popupCont', 'servicePopup.aspx', 
            {
                asynchronous:true, 
                evalScripts: true,
                parameters: { name: 'popupSumitMakeupDays',
                                days: days }
            });
}