/* 
WMS Lucrasoft Javascript Standaard functies
*/

function makeHttpRequest(url){ 
    if (window.XMLHttpRequest) { // Mozilla, Safari,... 
        http_request = new XMLHttpRequest(); 
        if (http_request.overrideMimeType) { 
            http_request.overrideMimeType('text/xml'); 
    } 
        } else if (window.ActiveXObject) { // IE 
            try { 
                http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
            } catch (e) { 
                try { 
                    http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
                } catch (e) {} 
            } 
        } 
    if (!http_request) { 
        alert('Helaas, jouw browser is te oud om deze pagina te kunnen laden.'); 
        return false; 
    } 
        http_request.open('GET', url, true); 
        http_request.send(null); 
}

function getField(fldName, strType) {
  var arrCheck = new Array;
  var blnFound = false;
  arrObjects = document.getElementsByTagName(strType.toUpperCase());

  for (i=0; i<arrObjects.length; i++) {
    if (arrObjects[i].id.split("_")[arrObjects[i].id.split("_").length - 1] == fldName) {
      blnFound = true;
      break;
    }
  }
	
  return arrObjects[i];
}

function PopUp(strPath) {
    window.open(strPath, 'WMSPOPUP', 'status=yes,resizable=yes,width=1024,height=764');
}

function MailTo(value) {
   if (value) {
		 var strTemp='';
		 for (i = value.length-1; i>=0; i--){
			 strTemp+=value.charAt(i);
		 }
		 strTemp = strTemp.split('|').join('@');
		 document.write('<a href=mailto:' + strTemp + '>' + strTemp + '</a>');
	 }
}

function OpenSubmenu(id) {
    jQuery('#' + id).children(':first-child').css('display', 'block');
}

function CloseSubmenu(id) {
    jQuery('#' + id).children(':first-child').css('display', 'none');
}

function OnClientValueChanging(sender, args) {
    if (!isSliding) return;

    var tooltip = $find("RadToolTip1");
    ResetToolTipLocation(tooltip);
    tooltip.set_text(args.get_newValue());
}

var isSliding = false;

function OnClientSlideStart(sender, args) {
    isSliding = true;

    var tooltip = $find("RadToolTip1");
    ShowRadToolTip(tooltip, sender);
}

function OnClientSlideEnd(sender, args) {
    var RadValue = document.getElementById('RadFilterCapacity_ClientState').value;
    RadValue = RadValue.replace('{', '');
    RadValue = RadValue.replace('}', '');
    var ArrRadValue = RadValue.split(',');
    for (i = 0; i < ArrRadValue.length; i++) {
        if (ArrRadValue[i].split(':')[0] == '"selectionStart"') {
            document.getElementById('tbCapacityLow').value = ArrRadValue[i].split(':')[1];
        } else if (ArrRadValue[i].split(':')[0] == '"selectionEnd"') {
            document.getElementById('tbCapacityTop').value = ArrRadValue[i].split(':')[1];
        }
    }

    isSliding = false;

    var tooltip = $find("RadToolTip1");
    tooltip.hide();
}

function OnClientValueChanged(sender, args) {
    var RadValue = document.getElementById('RadFilterCapacity_ClientState').value;
    RadValue = RadValue.replace('{', '');
    RadValue = RadValue.replace('}', '');
    var ArrRadValue = RadValue.split(',');
    for (i = 0; i < ArrRadValue.length; i++) {
        if (ArrRadValue[i].split(':')[0] == '"selectionStart"') {
            document.getElementById('tbCapacityLow').value = ArrRadValue[i].split(':')[1];
        } else if (ArrRadValue[i].split(':')[0] == '"selectionEnd"') {
            document.getElementById('tbCapacityTop').value = ArrRadValue[i].split(':')[1];
        }
    }
}

function ShowRadToolTip(tooltip, slider) {
    var activeHandle = slider.get_activeHandle();
    if (!activeHandle) return;

    tooltip.set_targetControl(activeHandle);
    ResetToolTipLocation(tooltip);
}

function ResetToolTipLocation(tooltip) {
    if (!tooltip.isVisible())
        tooltip.show();
    else
        tooltip.updateLocation();
}
function ChangeButton(ParentElement) {
    var Base;

    if (navigator.userAgent.indexOf("MSIE") != -1) {
        Base = ParentElement.childNodes[0].childNodes[0].childNodes;
    }
    else {
        Base = ParentElement.childNodes[0].childNodes[0].childNodes;
    }

    var TotalLength = Base.length;

    for (var i = 0; i < TotalLength; i++) {
        var CurrentCell = Base[i];

        if (CurrentCell.className) {
            if (CurrentCell.className.indexOf("Hover") < 0) {
                CurrentCell.className = CurrentCell.className + "Hover";
            }
            else {
                CurrentCell.className = CurrentCell.className.substring(0, CurrentCell.className.indexOf("Hover"));
            }
        }
    }
}

function OpenDetails(objectinput) {
    jQuery('.TankContainerPlus', jQuery(objectinput).parent()).toggle();
    jQuery('.TankContainerMinus', jQuery(objectinput).parent()).toggle();
    jQuery('.TankContainerOpenDetails', jQuery(objectinput).parent()).toggle();
    jQuery('.TankContainerCloseDetails', jQuery(objectinput).parent()).toggle();

    jQuery('.TankContainerDetailsLarge', jQuery(objectinput).parentsUntil('.TankContainerOuterContainer')).toggle('slow');
}

function CloseDetails(objectinput) {
    jQuery('.TankContainerPlus', jQuery(objectinput).parent()).toggle();
    jQuery('.TankContainerMinus', jQuery(objectinput).parent()).toggle();
    jQuery('.TankContainerOpenDetails', jQuery(objectinput).parent()).toggle();
    jQuery('.TankContainerCloseDetails', jQuery(objectinput).parent()).toggle();

    jQuery('.TankContainerDetailsLarge', jQuery(objectinput).parentsUntil('.TankContainerOuterContainer')).toggle('slow');
}
