/* 
WMS Lucrasoft Javascript Standaard functies
*/

function CommitHttpRequest(Url, ComepleteFunction) {
    var http_request;
    if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/html');
        }
    } else if (window.ActiveXObject) {
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) { }
        }
    }

    if (!http_request) {
        alert('Sorry, you should get your browser up to date!');
        return false;
    }

    http_request.onreadystatechange = ComepleteFunction;

    http_request.open('GET', Url, true);
    http_request.send(null);

    return http_request;
}

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 SetHomePageIntroHeight() {
    var DivObj = document.getElementById('SiteColoredBoxText');
    if (DivObj) {
        var TrObj = document.getElementById('UpperTr');
        if (TrObj) {
            var Height = TrObj.clientHeight;
            if (Height) {
                DivObj.style.height = (Height - 37) + 'px';
            }
        }
    }
}

function AddBodyEvent(EventName, fnOnEvent) {
    if (typeof (fnOnEvent) != "undefined") {
        if (window.addEventListener) {
            window.addEventListener(EventName, fnOnEvent, false);
        } else if (document.addEventListener) {
            document.addEventListener(EventName, fnOnEvent, false);
        } else if (window.attachEvent) {
            window.attachEvent(EventName, fnOnEvent);
        }

        var isMSIE = /*@cc_on!@*/false;
        if (isMSIE) { document.attachEvent('on' + EventName, fnOnEvent) }
    }
}

var rwPopupID = null;
function Popup(Url) {
    if (rwPopupID) {
        $find(rwPopupID).SetUrl(Url);
        $find(rwPopupID).show();
    }
}

function ChangeBackgroundImage(Element, ImageURL, isBack) {
    Element.style.backgroundImage = "url('" + ImageURL + "')";

    if (isBack == true) {
        Element.parentNode.vAlign = "bottom";
    }
    else {
        Element.parentNode.vAlign = "top";
    }
}

function ChangeBorder(item) {
    item.className = item.className + "Hover";
}
function ChangeBackBorder(item) {
    item.className = item.className.substring(0, item.className.indexOf("Hover"));
}
function ReferralCheckBox(ID,Text) {

    var Count = document.getElementById('lblCount').innerHTML;
    document.getElementById('divSelected').getElementsByTagName('*')[0].innerText = ID + "|" + Text;
    var i = 1;
    while (i <= Count) {
        var Textbox = document.getElementById('div' + i);
        if (Textbox != null) {
            if (i == ID) {
                Textbox.style.visibility = "visible"
            } else {
                Textbox.style.visibility = "hidden"
            }
        }
            i++
    }
    
    
}
