/*** Copy Right Information ***
* Please do not remove following information.
* Modal Popup v1.0
* Author: John J Kim
* Email: john@frontendframework.com
* URL: www.FrontEndFramework.com
* 
* You are welcome to modify the codes as long as you include this copyright information.
*****************************/

//With the window size & the element size functions built-in
VNSModalPopup = function(elem, options) {
    //option default settings
    options = options || {};
    var HasBackground = (options.HasBackground != null) ? options.HasBackground : true;
    var BackgroundColor = options.BackgroundColor || '#f1f1f1';
    var BackgroundOpacity = options.BackgroundOpacity || 60; // 1-100
    BackgroundOpacity = (BackgroundOpacity > 0) ? BackgroundOpacity : 1;
    var BackgroundOnClick = options.BackgroundOnClick || function() { };
    var BackgroundCursorStyle = options.BackgroundCursorStyle || "default";
    var Zindex = options.Zindex || 90000;
    var AddLeft = options.AddLeft || 0; //in px
    var AddTop = options.AddTop || 0; //in px

    function _Convert(val) {
        if (!val) { return; }
        val = val.replace("px", "");
        if (isNaN(val)) { return 0; }
        return parseInt(val);
    }
    var popup = document.getElementById(elem);
    if (!popup) { return; }
    //set the popup layer styles
    var winW = (document.layers || (document.getElementById && !document.all)) ? window.outerWidth : (document.all ? document.body.clientWidth : 0);
    var winH = window.innerHeight ? window.innerHeight : (document.getBoxObjectFor ? Math.min(document.documentElement.clientHeight, document.body.clientHeight) : ((document.documentElement.clientHeight != 0) ? document.documentElement.clientHeight : (document.body ? document.body.clientHeight : 0)));
    
    //display the popup layer
    popup.style.display = "block";
    popup.style.visibility = "visible";
    var currentStyle;
    if (popup.currentStyle) {
        currentStyle = popup.currentStyle;
    }
    else if (window.getComputedStyle) {
        currentStyle = document.defaultView.getComputedStyle(popup, null);
    } else {
        currentStyle = popup.style;
    }
   
    var elemW = popup.offsetWidth -
		_Convert(currentStyle.marginLeft) -
		_Convert(currentStyle.marginRight) -
		_Convert(currentStyle.borderLeftWidth) -
		_Convert(currentStyle.borderRightWidth);

    var elemH = popup.offsetHeight -
		_Convert(currentStyle.marginTop) -
		_Convert(currentStyle.marginBottom) -
		_Convert(currentStyle.borderTopWidth) -
		_Convert(currentStyle.borderBottomWidth);

    popup.style.position = "fixed";
    if (elem == 'validationSummaryDiv') {
        popup.style.left = (winW / 2 - elemW / 2 + AddLeft) + "px";
        popup.style.top = (winH / 2 - elemH / 2 + AddTop - 10) + "px";
    }
    else {
        popup.style.left = "0px";
        popup.style.top = "0px";
    }

    popup.style.zIndex = Zindex + 1;
    
    
    if (HasBackground) {
        if (!VNSModalPopup._BackgroundDiv) {
            VNSModalPopup._BackgroundDiv = document.createElement('div');
            VNSModalPopup._BackgroundDiv.style.display = "none";
            VNSModalPopup._BackgroundDiv.style.width = "100%";
            
            VNSModalPopup._BackgroundDiv.style.position = "absolute";
            
            VNSModalPopup._BackgroundDiv.style.zIndex = "1";
            VNSModalPopup._BackgroundDiv.style.top = "0px";
            VNSModalPopup._BackgroundDiv.style.left = "0px";
            document.body.appendChild(VNSModalPopup._BackgroundDiv);
        }
        
        VNSModalPopup._BackgroundDiv.onclick = BackgroundOnClick;
        VNSModalPopup._BackgroundDiv.style.background = BackgroundColor;
        VNSModalPopup._BackgroundDiv.style.height = document.all ? Math.max(Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight), Math.max(document.body.offsetHeight, document.body.scrollHeight)) : (document.body ? document.body.scrollHeight : ((document.documentElement.scrollHeight != 0) ? document.documentElement.scrollHeight : 0)) + "px";
        VNSModalPopup._BackgroundDiv.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + BackgroundOpacity + ")";
        VNSModalPopup._BackgroundDiv.style.MozOpacity = BackgroundOpacity / 100;
        VNSModalPopup._BackgroundDiv.style.opacity = BackgroundOpacity / 100;
        
        
        VNSModalPopup._BackgroundDiv.style.zIndex = 1;
        VNSModalPopup._BackgroundDiv.style.cursor = BackgroundCursorStyle;
        //Display the background
        if (navigator.appName.indexOf('Microsoft') != -1)
        {
            return false;
        }
        else
         {
             VNSModalPopup._BackgroundDiv.style.display = "";
         }
       
    }
}

VNSModalPopup.Close = function(id) {
    if (id) {
        document.getElementById(id).style.display = "none";
        document.getElementById(id).style.visibility = "hidden";
    }
    if (VNSModalPopup._BackgroundDiv) {
        VNSModalPopup._BackgroundDiv.style.display = "none";
    }

}

ModalPopupColor = function(elem, options) {
    //option default settings
    options = options || {};
    var HasBackground = (options.HasBackground != null) ? options.HasBackground : true;
    var BackgroundColor = options.BackgroundColor || '#f1f1f1';
    var BackgroundOpacity = options.BackgroundOpacity || 60; // 1-100
    BackgroundOpacity = (BackgroundOpacity > 0) ? BackgroundOpacity : 1;
    var BackgroundOnClick = options.BackgroundOnClick || function() { };
    var BackgroundCursorStyle = options.BackgroundCursorStyle || "default";
    var Zindex = options.Zindex || 90000;
    var AddLeft = options.AddLeft || 0; //in px
    var AddTop = options.AddTop || 0; //in px

    function _Convert(val) {
        if (!val) { return; }
        val = val.replace("px", "");
        if (isNaN(val)) { return 0; }
        return parseInt(val);
    }
    var popup = document.getElementById(elem);
    if (!popup) { return; }
    //set the popup layer styles
    var winW = (document.layers || (document.getElementById && !document.all)) ? window.outerWidth : (document.all ? document.body.clientWidth : 0);
    var winH = window.innerHeight ? window.innerHeight : (document.getBoxObjectFor ? Math.min(document.documentElement.clientHeight, document.body.clientHeight) : ((document.documentElement.clientHeight != 0) ? document.documentElement.clientHeight : (document.body ? document.body.clientHeight : 0)));
    //display the popup layer
    popup.style.visibility = "visible";
    document.getElementById('sel1').style.display='block';
    document.getElementById('sel2').style.display='block';
    document.getElementById('sel3').style.display='block';
    document.getElementById('sel4').style.display='block';
    var currentStyle;
    if (popup.currentStyle) {
        currentStyle = popup.currentStyle;
    }
    else if (window.getComputedStyle) {
        currentStyle = document.defaultView.getComputedStyle(popup, null);
    } else {
        currentStyle = popup.style;
    }

    var elemW = popup.offsetWidth -
		_Convert(currentStyle.marginLeft) -
		_Convert(currentStyle.marginRight) -
		_Convert(currentStyle.borderLeftWidth) -
		_Convert(currentStyle.borderRightWidth);

    var elemH = popup.offsetHeight -
		_Convert(currentStyle.marginTop) -
		_Convert(currentStyle.marginBottom) -
		_Convert(currentStyle.borderTopWidth) -
		_Convert(currentStyle.borderBottomWidth);

    popup.style.position = "fixed";
    popup.style.left = "0px";
    popup.style.top = "0px";
    
    popup.style.zIndex = Zindex + 1;
     
    if (HasBackground) {
        if (!ModalPopupColor._BackgroundDiv) {
            ModalPopupColor._BackgroundDiv = document.createElement('div');
            ModalPopupColor._BackgroundDiv.style.display = "none";
            ModalPopupColor._BackgroundDiv.style.width = "100%";
            ModalPopupColor._BackgroundDiv.style.position = "absolute";
            ModalPopupColor._BackgroundDiv.style.zIndex = "1";
            ModalPopupColor._BackgroundDiv.style.top = "0px";
            ModalPopupColor._BackgroundDiv.style.left = "0px";
            document.body.appendChild(ModalPopupColor._BackgroundDiv);
        }
        ModalPopupColor._BackgroundDiv.onclick = BackgroundOnClick;
        ModalPopupColor._BackgroundDiv.style.background = BackgroundColor;
        ModalPopupColor._BackgroundDiv.style.height = document.all ? Math.max(Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight), Math.max(document.body.offsetHeight, document.body.scrollHeight)) : (document.body ? document.body.scrollHeight : ((document.documentElement.scrollHeight != 0) ? document.documentElement.scrollHeight : 0)) + "px";
        ModalPopupColor._BackgroundDiv.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + BackgroundOpacity + ")";
        ModalPopupColor._BackgroundDiv.style.MozOpacity = BackgroundOpacity / 100;
        ModalPopupColor._BackgroundDiv.style.opacity = BackgroundOpacity / 100;
        ModalPopupColor._BackgroundDiv.style.zIndex = 1;
        ModalPopupColor._BackgroundDiv.style.cursor = BackgroundCursorStyle;

        //Display the background
        if (navigator.appName.indexOf('Microsoft') != -1)
        {
            return false;
        }
        else
         {
            ModalPopupColor._BackgroundDiv.style.visibility = "visible";
         }
        //
    }

}
ModalPopupColor.Close = function(id) {
    if (id) {
        document.getElementById(id).style.visibility = "hidden";
        document.getElementById('sel1').style.display='none';
        document.getElementById('sel2').style.display='none';
        document.getElementById('sel3').style.display='none';
        document.getElementById('sel4').style.display='none';
    }
    if (ModalPopupColor._BackgroundDiv) {
         ModalPopupColor._BackgroundDiv.style.display = "none";
         //ModalPopupColor._BackgroundDiv.style.visibility = "hidden";
    }

}
function Moveover(divBorder) {
    var border = document.getElementById(divBorder);
    border.className = 'borderover';
    return false;
}
function Moveout(divBorder) {
    var border = document.getElementById(divBorder);
    border.className = 'border';
    return false;
}

//function MoreStep(divMore, divLess) {
//    var more = document.getElementById(divMore);
//    var less = document.getElementById(divLess);
//    less.style.display = 'none';
//    more.style.display = 'block';
//    var content = document.getElementById('content_bg');
//    content.style.width = '930px';
//    var divMid = document.getElementById('divMid');
//    divMid.className = 'mid';
//    return false;
//}
//function LessStep(divMore, divLess) {
//    var more = document.getElementById(divMore);
//    var less = document.getElementById(divLess);
//    less.style.display = 'block';
//    more.style.display = 'none';
//    var content = document.getElementById('content_bg');
//    content.style.width = '1090px';
//    var divMid = document.getElementById('divMid');
//    divMid.className = 'midWide';
//    return false;
//}
var step = new Array("step1", "step2", "step3", "step4");
var lnikStep = new Array("linkStep1", "linkStep2", "linkStep3", "linkStep4", "linkStep5");
function ClearStep() {
    for (var i = 0; i < step.length; i++) {
        document.getElementById(step[i]).style.display = 'none';
    }
}
function ClearStepFrame() {
    for (var i = 0; i < step.length; i++) {
        parent.document.getElementById(step[i]).style.display = 'none';
    }
}
function Step(step, lnkStep) {
    ClearStep();
    document.getElementById(step).style.display = 'block';
    document.getElementById(lnkStep).style.textDecoration = 'underline';
    return false;
}
function SelectStep1(imgstep,divSummary) 
{
    document.getElementById(imgstep).src = 'images/b1.png';
    ClearStep();
    document.getElementById(divSummary).style.display = 'block';
    return false;
}
function SelectStep2(imgstep,divSummary) 
{
    document.getElementById(imgstep).src = 'images/b2.png';
    ClearStep();
    document.getElementById(divSummary).style.display = 'block';
    return false;
}
function SelectStep3(imgstep,divSummary) 
{
    document.getElementById(imgstep).src = 'images/b3.png';
    ClearStep();
    document.getElementById(divSummary).style.display = 'block';
    return false;
}
function SelectStep4(imgstep,divSummary) 
{
    document.getElementById(imgstep).src = 'images/b4.png';
    ClearStep();
    document.getElementById(divSummary).style.display = 'block';
    return false;
}
function Next() {
    for (var i = 0; i < lnikStep.length; i++) {
        var stp = document.getElementById(lnikStep[i]);
        var stpNext;
        if (i < 4) {
            stpNext = document.getElementById(lnikStep[i + 1]);
        }
        if (i == 4) {
            stpNext = document.getElementById(lnikStep[4]);
        }
        if (stp.style.textDecoration == 'underline') {
            stp.style.textDecoration = 'none';
            stpNext.style.textDecoration = 'underline';
            break;
        }
    }
    for (var i = 0; i < step.length; i++) {
        var stp = document.getElementById(step[i]);
        var stpNext;
        if (i < 4) {
            stpNext = document.getElementById(step[i + 1]);
        }
        if (i == 4) {
            stpNext = document.getElementById(step[4]);
        }
        if (stp.style.display == 'block') {
            stp.style.display = 'none';
            stpNext.style.display = 'block';
            break;
        }
    }
    return false;
}
function Back() {
    for (var i = 0; i < lnikStep.length; i++) {
        var stp = document.getElementById(lnikStep[i]);
        var stpNext;
        if (i > 0) {
            stpNext = document.getElementById(lnikStep[i - 1]);
        }
        if (i == 0) {
            stpNext = document.getElementById(lnikStep[0]);
        }
        if (stp.style.textDecoration == 'underline') {
            stp.style.textDecoration = 'none';
            stpNext.style.textDecoration = 'underline';
            break;
        }
    }
    for (var i = 0; i < step.length; i++) {
        var stp = document.getElementById(step[i]);
        var stpNext;
        if (i > 0) {
            stpNext = document.getElementById(step[i - 1]);
        }
        if (i == 0) {
            stpNext = document.getElementById(step[0]);
        }
        if (stp.style.display == 'block') {
            stp.style.display = 'none';
            stpNext.style.display = 'block';
            break;
        }
    }
    return false;
}
