﻿// JScript File
var _windowwidth;
var _windowwidthtype;
var _windowheight;
var _windowheighttype;
var totalheight;
var imgArray = new Array();
var recs;

function resetBodyPosition1() {
    if (_windowwidthtype != "%") {
        var ileft = ((mdlGetClientWidth() - _windowwidth) / 2);
        var _obj = document.getElementById('main');

        if (_obj != null) {
            ileft = ileft < 0 ? 0 : ileft;
            _obj.style.left = ileft.toString() + "px";
        }
    }
    if (_windowheighttype != "%") {
        var itop = ((mdlGetClientHeight() - _windowheight) / 2);
        var _obj = document.getElementById('main');

        if (_obj != null) {
            itop = itop < 0 ? 0 : itop;
            _obj.style.top = itop.toString() + "px";
        }
    }
}

function resetBodyPosition() 
{
    if (_windowwidthtype != "%") {
        var ileft = ((mdlGetClientWidth() - _windowwidth) / 2);
        var _obj = document.getElementById('main');

        if (_obj != null) {
            ileft = ileft < 0 ? 0 : ileft;
            _obj.style.left = ileft.toString() + "px";
        }
    }
    if (_windowheighttype != "%") {
        var itop = ((mdlGetClientHeight() - _windowheight) / 2);
        var _obj = document.getElementById('main');

        if (_obj != null) {
            itop = itop < 0 ? 0 : itop;
            _obj.style.top = itop.toString() + "px";
        }
    } else {
        //Set Frame Height
        var _main = document.getElementById("mainbody");
        if (_main != null) {
            totalheight = mdlInt(_main.childNodes[0].scrollHeight);
            for (var i = 0; i < _main.childNodes.length; i++) {
                if (_main.childNodes[i].id.substring(0, 3) == "obj") {
                    if (_main.childNodes[i].style.height != "100%") {
                        var objoffsetheight = _main.childNodes[i].offsetTop + _main.childNodes[i].scrollHeight;
                        if (totalheight < objoffsetheight) {
                            totalheight = objoffsetheight;
                        }
                    }
                }
            }
            var _obj = window.top.document.getElementById("main");
            var _fobj = window.top.document.getElementById("mframe");
            _obj.style.height = (totalheight + 20) + "px";
            _fobj.style.height = (totalheight + 20) + "px";
            var sidebar = document.getElementById('obj5');
            if (sidebar != null) {
                sidebar.style.height = mdlInt(totalheight - 260) + "px";
            }
        }
    }
}

function getObjectById(object) {
    if (document.all) {
        return (document.all[object])
    } else if (document.layers) {
        return (document.layers[object])
    } else {
        return (document.getElementById(object))
    }
}

function getContentById(contid, div_id) {
	var url = "xmlhttp/leescontent.aspx?cid=" + contid;
    var xmlhttp = ReadData(url);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
		    getObjectById(div_id).innerHTML = xmlhttp.responseText;
		    if (document.getElementById('fieldNaam')) {
	            var vNaam = document.getElementById('fieldNaam');
	            vNaam.focus();
		    }
		}
	}
	xmlhttp.send(null);
}

function getContentDetailById(contid, div_id) {
	var url = "xmlhttp/leescontent.aspx?cid=" + contid;
    var xmlhttp = ReadData(url);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
		    getObjectById(div_id).innerHTML = xmlhttp.responseText;
		    getObjectById('disable').style.visibility = "visible";
		    getObjectById('detailtbl').style.visibility = "visible";
		}
	}
	xmlhttp.send(null);
}

function CloseContentDetail(div_id) {
    getObjectById(div_id).innerHTML = "";
    getObjectById('detailtbl').style.visibility = "hidden";
    getObjectById('disable').style.visibility = "hidden";
}

function CloseMessageDetail(div_id) {
    getObjectById(div_id).innerHTML = "";
    getObjectById('msgtbl').style.visibility = "hidden";
    getObjectById('disable').style.visibility = "hidden";
}

function clearContent(div_id) {
    getObjectById(div_id).innerHTML = "";
}

function mdlGetClientHeight()
{
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myHeight = document.body.clientHeight;
    }
    return myHeight;
}

function mdlGetClientWidth()
{
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
    }
    return myWidth;
}



function mdlInt(d_x, d_y)
{
      return isNaN(d_y = parseInt(d_x))? 0 : d_y;
}

function mdlReadData(url) {
    var xmlhttp;
    
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	xmlhttp.open("GET",url,true);
    return (xmlhttp);
}

function mdlSaveData(url) {
    var xmlhttp;
    
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
    xmlhttp.open("POST",url,false);
    return (xmlhttp);
}

function mdlGet(object) {
    if (document.all) {
        return (document.all[object])
    } else if (document.layers) {
        return (document.layers[object])
    } else {
        return (document.getElementById(object))
    }
}

function sObj(objs) {
	var obj=objs.split(",");
	for (var i=0; i<obj.length; i++) {
		if (document.getElementById('obj'+obj[i]) != null) {
			document.getElementById('obj'+obj[i]).style.display="block";
		}
	}
}

function hObj(objs) {
	var obj=objs.split(",");
	for (var i=0; i<obj.length; i++) {
		if (document.getElementById('obj'+obj[i]) != null) {
			document.getElementById('obj'+obj[i]).style.display="none";
		}
	}
}

function mdlStripCharsInBag(s, bag) {
    var i;
    var returnString = "";
    // Search through string"s characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++) {   
        // Check that current character isn"t whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function mdlIsInteger(s) {
    var i;
    for (i = 0; i < s.length; i++) {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9")) && (c != "-")) return false;
    }
    // All characters are numbers.
    return true;
}

function mdlIsFloat(s) {
    var i;
    for (i = 0; i < s.length; i++) {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9")) && (c != "-") && (c != ".") && (c != ",")) return false;
    }
    // All characters are numbers.
    return true;
}

function mdlIsAlpha(s) {
    var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var i;
    for (i = 0; i < s.length; i++) {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (alpha.indexOf(c) == -1) return false;
    }
    // All characters are numbers.
    return true;
}

function mdlCheckInternationalPhone(strPhone) {
    var phoneNumberDelimiters = "()- ";
    var validWorldPhoneChars = phoneNumberDelimiters + "+";
    var minDigitsInIPhoneNumber = 10;

    s=mdlStripCharsInBag(strPhone,validWorldPhoneChars);
    return (mdlIsInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function checkZipcode(strZipcode) {
    var zipcodeDelimiters = " ";
    var minDigitsInZipcode = 6;

    s=mdlStripCharsInBag(strZipcode,zipcodeDelimiters);
    return (mdlIsInteger(s.substring(1,4)) && mdlIsAlpha(s.substring(5,6)) && s.length >= minDigitsInZipcode);
}

function setDisclaimerHeight(color) {
    var disclaimer = document.getElementById("obj4");
    if (disclaimer == null) {
        var disclaimer = document.getElementById("obj170");
    }
    if (disclaimer == null) {
        var disclaimer = document.getElementById("obj171");
    }
    if (disclaimer != null) {
        disclaimer.style.top = totalheight + "px";
        disclaimer.style.visibility = "visible";
        if ((color != null) && (color.substring(0, 1) == "#")) {
            disclaimer.style.backgroundColor = color;
            var _obj = window.top.document.getElementById("master");
            _obj.style.backgroundColor = color;
        }
    }
}

function getFileUrl(fieldname, targetdir, showfiles) {
    var inner_window_width = 600;
    var inner_window_height = 400;
    var shell_window_top = (window.screen.availHeight / 2) - (inner_window_height / 2);
    var shell_window_left = (window.screen.availWidth / 2) - (inner_window_width / 2);
    window.open("xmlhttp/DCMGetSingleFile.aspx?dir=" + targetdir + "&fld=" + fieldname + "&list=" + showfiles, "upload", "top=" + shell_window_top + ",left=" + shell_window_left + ",width=600,height=300,resizeable=no,location=no,toolbar=no,menubar=no,status=no");
}

function updateFileUrl(url, fieldname) {
    var field = document.getElementById(fieldname);
    if (field != null) {
        field.value = url;
    }
}

function PrepareGrayboxImages(PagId, ContId, ChildName, ChildContent) {
    if (recs == null) {
        imgArray = null;
        imgArray = new Array();
        recs = -1;
    }
    else {
        recs = recs + 1;
        imgArray[recs] = { 'caption': ChildName, 'url': ChildContent };
    }
}

function ShowGrayboxImages()
{
    var index_frame = document.getElementById("mframe");
    if ((index_frame != null) && (index_frame.contentWindow != null) && (index_frame.contentWindow.document.getElementById('obj0') != null)) {
        index_frame.contentWindow.document.getElementById('obj0').style.display = "none";
    }
    GB_showImageSet(imgArray, 1);
}
