﻿var nav = window.Event ? true : false; 
if (nav) { 
    //window.captureEvents(Event.KEYDOWN); 
    window.onkeydown = NetscapeEventHandler_KeyDown; 
} else { 
    document.onkeydown = MicrosoftEventHandler_KeyDown; 
}

function NetscapeEventHandler_KeyDown(e) { 
    if (e.which == 13 && e.target.type != 'textarea' && e.target.type != 'submit' && e.target.type != 'image'){ 
        return false; 
    } else {
        return true;
    }
} 

function MicrosoftEventHandler_KeyDown() { 
    if (event.keyCode == 13 && event.srcElement.type != 'textarea' && event.srcElement.type != 'submit' && event.srcElement.type != 'image'){ 
        return false;
    } else { 
        return true;
    } 
} 

function ieSecurityWorkAround(){
    // Prevents the message 'Click to activate this control' from displaying
    objects = document.getElementsByTagName("object"); 
    for (var i = 0; i < objects.length; i++) { 
	    objects[i].outerHTML = objects[i].outerHTML; 
    }
}

function addToFavorites(strURL, strTitle){
   //if(navigator.userAgent.indexOf('MSIE') >= 0 && navigator.userAgent.indexOf('Opera') < 0){
   //if(window.external && window.external.AddFavorite) {
   if(document.all){
       window.external.AddFavorite(strURL, strTitle);
   } else if(window.sidebar) {
       window.sidebar.addPanel(strTitle, strURL, "");
   } else {
       document.body.innerHTML += '<'+'a href="'+strURL+'" title="'+strTitle+'" rel="sidebar" style="display: none;" id="addbookmark">click<'+'/a>';
       document.getElementById('addbookmark').click();
       document.getElementById('addbookmark').outerHTML = '';
   }
}

function cboKeySort_onKeyPress (cbo,caseSensitive, e) {
    if(!e) e = window.event;
    var undefined; 
    if (cbo.keypressBuffer == undefined) { 
        cbo.keypressBuffer = ''; 
    } 
    var key = String.fromCharCode(e.keyCode); 
        cbo.keypressBuffer += key;
    if (!caseSensitive) {
        cbo.keypressBuffer = cbo.keypressBuffer.toLowerCase();
    }
    var optionsLength = cbo.options.length; 
    for (var n=0; n < optionsLength; n++) { 
        var optionText = cbo.options[n].text; 
        if (!caseSensitive) {
            optionText = optionText.toLowerCase();
        }
        if (optionText.indexOf(cbo.keypressBuffer,0) == 0) { 
            cbo.selectedIndex = n; 
        return false;
        } 
    } 
    cbo.keypressBuffer = key; 
    return true;
} 

function ToolTip(strText, blnStatus) {
    var intWidth;
    var strStatusBar;
    intWidth = parseInt(strText.length * 5.6) + 20;
    if(intWidth > 240){
        intWidth = 240;
    }
    if(blnStatus == 0){
        strStatusBar = ''; 
    }else{
        strStatusBar = AUTOSTATUS; 
    }
    return overlib(strText,FGCOLOR,'#FFFFFF',BGCOLOR,'#999999',TEXTCOLOR,'#626469',WIDTH,intWidth,strStatusBar,DELAY,100);
}

function Trim(STRING){
    STRING = LTrim(STRING);
    return RTrim(STRING);
}

function RTrim(STRING){
    while(STRING.charAt((STRING.length -1))==" "){
        STRING = STRING.substring(0,STRING.length-1);
    }
return STRING;
}

function LTrim(STRING){
    while(STRING.charAt(0)==" "){
        STRING = STRING.replace(STRING.charAt(0),"");
    }
return STRING;
}

// * * * * dialog window * * * * //
function DialogWindow(strURL, lngImgWidth, lngImgHeight, blnScrollbars) {
	var lngLeftMargin;
	var lngTopMargin;
	var lngScrHeight = screen.height;
	var lngScrWidth = screen.width;
	var lngWinHeight;
	var lngWinWidth;
	var returnValue;
	if(((lngScrWidth-40)/lngImgWidth) <= ((lngScrHeight-55)/lngImgHeight)){
		// Width is leading
		if((lngScrWidth-40) < lngImgWidth){
			//Image width is larger than the screen width, change the image size
			lngImgHeight = Math.round(lngImgHeight*(lngScrWidth - 40)/lngImgWidth);
			lngImgWidth = lngScrWidth - 40;
		}
	}else{
		// Height is leading
		if((lngScrHeight-55) < lngImgHeight){
			//Image height is larger than the screen height, change the image size
			lngImgWidth = Math.round(lngImgWidth*(lngScrHeight - 55)/lngImgHeight);
			lngImgHeight = lngScrHeight - 55;
		}
	}
	lngWinWidth = lngImgWidth + 40;
	if(lngWinWidth < 420){
		lngWinWidth = 420;
	}
	lngWinHeight = lngImgHeight + 100;
	lngLeftMargin = (lngScrWidth - lngWinWidth) / 2;
	lngTopMargin = (lngScrHeight - lngWinHeight) / 2;
	if(!nav){
	    window.showModalDialog(strURL+"&intWidth="+lngImgWidth+"&intHeight="+lngImgHeight, "ValentNet", 
		"dialogWidth:"+lngWinWidth+"px;dialogHeight="+lngWinHeight+"px;dialogLeft:"+lngLeftMargin+"px;dialogTop:"+lngTopMargin+"px;edge:sunken;scroll:"+blnScrollbars+";status:1;help:0;resizable:1");
	}else{
	    window.open(strURL+'&intWidth='+lngImgWidth+'&intHeight='+lngImgHeight, 'ValentNet',
        'height='+lngWinHeight+',width='+lngWinWidth+',toolbar=no,directories=no,status=yes,menubar=no,scrollbars='+blnScrollbars+',resizable=yes ,modal=yes,left='+lngLeftMargin+',top='+lngTopMargin);
	}
}
// * * * * popup window * * * * //
function PopupWindow(strUrl, lngImgWidth, lngImgHeight)
{
    PopupWindow(strUrl, lngImgWidth, lngImgHeight, false);
}

function PopupWindow(strURL, lngImgWidth, lngImgHeight, blnScrollbars, blnResizable) {
	var lngWinWidth, lngWinHeight, lngLeftMargin, lngTopMargin;
	var lngScrWidth = screen.width;
	var lngScrHeight = screen.height;
	if(((lngScrWidth-40)/lngImgWidth) <= ((lngScrHeight-55)/lngImgHeight)){
		// Width is leading
		if((lngScrWidth-40) < lngImgWidth){
			//Image width is larger than the screen width, change the image size
			lngImgHeight = Math.round(lngImgHeight*(lngScrWidth - 40)/lngImgWidth);
			lngImgWidth = lngScrWidth - 40;
		}
	}else{
		// Height is leading
		if((lngScrHeight-55) < lngImgHeight){
			//Image height is larger than the screen height, change the image size
			lngImgWidth = Math.round(lngImgWidth*(lngScrHeight - 55)/lngImgHeight);
			lngImgHeight = lngScrHeight - 55;
		}
	}
	lngWinWidth = lngImgWidth + 40;
	if(lngWinWidth < 200){
		lngWinWidth = 200;
	}
	lngWinHeight = lngImgHeight + 55;
	lngLeftMargin = (lngScrWidth - lngWinWidth) / 2;
	lngTopMargin = (lngScrHeight - lngWinHeight) / 2;
	myWin= open(strURL+"&intWidth="+lngImgWidth+"&intHeight="+lngImgHeight, "ValentNet", 
		"width="+lngWinWidth+",height="+lngWinHeight+",status=no,toolbar=no,menubar=no,resizable="+((blnResizable)?"yes":"no")+",scrollbars="+((blnScrollbars)?"yes":"no")+",left="+lngLeftMargin+",top="+lngTopMargin);
	myWin.focus();
}

// * * * * Window Resize * * * * //
function setWinSize(intHeight, intWidth){
    if(window.outerWidth){
        window.outerWidth = intWidth;
        window.outerHeight = intHeight;
    } else if(window.resizeTo){
        window.resizeTo(intWidth,intHeight);
    }
}

// * * * * AJAX * * * * //
// * AJAX version 1 *//
var id;
var obj;
function getResponse(strUrl, strFunction, strID){
    obj = GetXmlHttpObject();
    if(obj!=null){
        if(strID != undefined && strID != null){
            if(strID.length > 0){
                id = strID;    
            }
        }
        obj.onreadystatechange = strFunction;
        obj.open("GET", strUrl+'&'+Math.random(),  true);
        obj.send(null);
    }else{
        alert('No AJAX-support!/nPlease use FireFox or Internet Explorer.');
    }
}
function GetXmlHttpObject(){ 
    var objXMLHttp = null;
    if (window.XMLHttpRequest){
        objXMLHttp=new XMLHttpRequest();
    }else if (window.ActiveXObject){
        objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return objXMLHttp;
}
// * AJAX version 2 *//
var fAJAXResponse;
var objAJAX;

function sendAJAX(strUrl, postData) {
    objAJAX = GetXmlHttpObject();
    if(objAJAX != null) {
        objAJAX.onreadystatechange = showAJAXResponse;
        objAJAX.open("GET", strUrl + '?' + postData + '&' + Math.random(),  true);
        objAJAX.send(postData);
    } else {
        alert('No AJAX-support!/nPlease use FireFox or Internet Explorer.');
    }
}
function getAJAXResponse(strURL)
{
    objAJAX = GetXmlHttpObject();
    if(objAJAX!=null)
    {
        objAJAX.onreadystatechange = showAJAXResponse;
        objAJAX.open("GET", strURL+'&'+Math.random(),  true);
        objAJAX.send(null);
    }else{
        alert('No AJAX-support!/nPlease use FireFox or Internet Explorer.');
    }
}

function showAJAXResponse()
{
    if(objAJAX.readyState == 4)
    {        
        if(objAJAX.status == 200)
        {
            fAJAXResponse();
        }
    }
}
// * AJAX version 3 - supports simultaneous requests *//

function sendAJAX3(url, postData, strReceiveFunc)
{
    var httpRequest = GetXmlHttpObject();
    httpRequest.onreadystatechange = function() { showAJAXResponse3(httpRequest, strReceiveFunc); };
    
    if (postData != null)
        httpRequest.open("GET", url + '?' + postData + '&' + Math.random(),  true);
    else
        httpRequest.open("GET", url + '?' + Math.random(),  true);
         
    httpRequest.send('');

}

function showAJAXResponse3(httpRequest, strReceiveFunc) 
{
    if (httpRequest.readyState == 4) 
    {
        if (httpRequest.status == 200) 
        {
            eval(strReceiveFunc);
   
        }
        else {
            alert('There was a problem with the request.\n' + httpRequest.status + '\n' + httpRequest.responseText);
        }
    }
}


// * * * * alerts * * * * //
function ValentNetAlert(strText,strFunction){
    var intHeight;
    var intWidth;
    var strPre;
    var strPost;
    
    if (nav) { 
      intWidth = window.innerWidth;
      intHeight = window.innerHeight;
    }else{
      intWidth = document.body.offsetWidth;
      intHeight = document.body.offsetHeight;
    }
    
    strPre = '<div class="alert"><table class="alert"><tr><td class="alertText">';
    strPost = '</td></tr>';
    strPost += '<tr class="alertFooter"><td colspan="2" style="text-align:center;">';
    strPost += '<input type="button" id="cmdAlertOk" class="button" style="width:80px;" value="Ok" onclick="javascript:cClick();'+strFunction+';">';
    strPost += '</td></tr>';
    strPost += '</table></div>';


    return overlib(strPre + strText + strPost,FULLHTML,STICKY,RELX,(intWidth/2)-160,RELY,(intHeight/2)-200);
}

function ValentNetAlertAuto(strText,strFunction){

    ValentNetAlertTimeout(strText, strFunction, 5);
    
}

function ValentNetAlertTimeout(strText, strFunction, intSeconds){
    var intMilliseconds = intSeconds * 1000;
    
    setTimeout("cClick();" + strFunction + ";",intMilliseconds);

    ValentNetAlert(strText,strFunction);   
    
}

function ValentNetConfirm(strText,strFunctionOk,strFunctionCancel, strOk, strCancel){
    var intHeight;
    var intWidth;
    var strPre;
    var strPost;
    
    if (nav) { 
      intWidth = window.innerWidth;
      intHeight = window.innerHeight;
    }else{
      intWidth = document.body.offsetWidth;
      intHeight = document.body.offsetHeight;
    }
    
    strPre = '<div class="alert"><table class="alert"><tr><td class="alertText">';
    strPost = '</td></tr>';
    strPost += '<tr class="alertFooter"><td colspan="2" style="text-align:center;">';
    strPost += '<input type="button" id="cmdAlertOk" class="button" style="width:80px;" value="'+strOk+'" onclick="javascript:cClick();'+strFunctionOk+';">';
    strPost += ' <input type="button" id="cmdAlertCancel" class="button" style="width:80px;" value="'+strCancel+'" onclick="javascript:cClick();'+strFunctionCancel+';">';
    strPost += '</td></tr>';
    strPost += '</table></div>';

    return overlib(strPre + strText + strPost,FULLHTML,STICKY,RELX,(intWidth/2)-160,RELY,(intHeight/2)-200);
}

// * * * * DTPicker *  * * * //
function clearPicker(strBase, blnTime)
{
    document.getElementById(strBase + 'txtDisplayDate').value = '';
    if(blnTime == true){
        document.getElementById(strBase + 'cboHours_cbo1').selectedIndex = 0;
        document.getElementById(strBase + 'cboMinutes_cbo1').selectedIndex = 0;
    }
    closePicker(strBase);
    document.getElementById(strBase + 'txtDisplayDate').focus();
}

function closePicker(strBase){
    document.getElementById(strBase + 'pnlPicker').style.display = 'none';
}

function getPickerDateSelected(strBase){
    return document.getElementById(strBase + 'txtDisplayDate').value;
}

function getPickerResponse(strBase, strLanguage, strBaseDate, strSelDate){
    
    fAJAXResponse = new Function('showPicker(\'' + strBase + '\',\'' + strLanguage + '\');');
        
    getAJAXResponse('/controls/DateTime/DTPickerCallbacks.aspx?lan=' + strLanguage + '&dtm=' + strBaseDate + '&dtmSel=' + strSelDate);
}

function loadPicker(strBase, strLanguage)
{
    var oDivs = document.getElementsByTagName('div');
    var strDate = getPickerDateSelected(strBase);
    var n;    
    
    // Close any other calendar popups
    for(n = 0; n < oDivs.length; n++){
        if(oDivs[n].id != null){
            if(oDivs[n].id.indexOf('pnlPicker') > 0){
                if(oDivs[n].id.indexOf(strBase) < 0){
                    oDivs[n].style.display = 'none';
                }
            }
        }
    }
    
    getPickerResponse(strBase, strLanguage, strDate, strDate);
}

function navigatePicker(strBase, strLanguage, strBaseDate){
    var strDateSelected = getPickerDateSelected(strBase);
    
    getPickerResponse(strBase, strLanguage, strBaseDate, strDateSelected);
}

function setPickerDate(strBase, strDate){
    document.getElementById(strBase + 'txtDisplayDate').value = strDate;
    document.getElementById(strBase + 'pnlPicker').style.display = 'none';
    document.getElementById(strBase + 'txtDisplayDate').focus();
}

function showPicker(strBase, strLanguage)
{   
//    alert(objAJAX.responseText);
    var intCss = 7;
    var intDay = 3;
    var intDisplay = 0;
    var intMainButtons = 5;
    var intMainDates = 0;
    var intMainMonth = 2;
    var intMainWeek = 3;
    var intMainWeekDays = 4;
    var intMainYear = 1;
    var intMonth = 4;
    var intMonthName = 5;
    var intYear = 6;
    var intWeek = 1;
    var intWeekday = 2;
    var n;
    var oButton;
    var oButtons;
    var oDate;
    var oDates;
    var oPicker = document.getElementById(strBase + 'pnlPicker');
    var oWeekDays;
    var strMonth;
    var strResult = '';
    var strWeek;
    var strYear;
    var tbCal = document.getElementById(strBase + 'tbCalendar');
    var td;
    var tr;
    var x = 0;
    var xmlDates = LoadXMLText(objAJAX.responseText);
    var y = 0;
    
    for(n = tbCal.rows.length - 1; n > 3; n--){
        tbCal.deleteRow(n);
    }
    //alert(xmlDates.childNodes[0].childNodes.length);
    oButtons = xmlDates.childNodes[0].childNodes[intMainButtons].childNodes;
    oDates = xmlDates.childNodes[0].childNodes[intMainDates].childNodes;
    oWeekDays = xmlDates.childNodes[0].childNodes[intMainWeekDays].childNodes;
    strYear = xmlDates.childNodes[0].childNodes[intMainYear].childNodes[0].nodeValue;
    strMonth = xmlDates.childNodes[0].childNodes[intMainMonth].childNodes[0].nodeValue;
    strWeek = xmlDates.childNodes[0].childNodes[intMainWeek].childNodes[0].nodeValue;
    
    //Years
    // -1
    td = tbCal.rows[1].cells[0]
    td.onclick = new Function('navigatePicker(\'' + strBase + '\', \'' + strLanguage + '\', \'' + oButtons[0].childNodes[1].childNodes[0].nodeValue + '\');');
    td.title = oButtons[0].childNodes[0].childNodes[0].nodeValue
    // -10
    td = tbCal.rows[1].cells[1]
    td.onclick = new Function('navigatePicker(\'' + strBase + '\', \'' + strLanguage + '\', \'' + oButtons[1].childNodes[1].childNodes[0].nodeValue + '\');');
    td.title = oButtons[1].childNodes[0].childNodes[0].nodeValue
    // current year
    tbCal.rows[1].cells[2].innerHTML = strYear;
    // +1
    td = tbCal.rows[1].cells[3]
    td.onclick = new Function('navigatePicker(\'' + strBase + '\', \'' + strLanguage + '\', \'' + oButtons[3].childNodes[1].childNodes[0].nodeValue + '\');');
    td.title = oButtons[3].childNodes[0].childNodes[0].nodeValue
    // +10
    td = tbCal.rows[1].cells[4]
    td.onclick = new Function('navigatePicker(\'' + strBase + '\', \'' + strLanguage + '\', \'' + oButtons[2].childNodes[1].childNodes[0].nodeValue + '\');');
    td.title = oButtons[2].childNodes[0].childNodes[0].nodeValue
    
    //Months
    // -1
    td = tbCal.rows[2].cells[0]
    td.onclick = new Function('navigatePicker(\'' + strBase + '\', \'' + strLanguage + '\', \'' + oButtons[4].childNodes[1].childNodes[0].nodeValue + '\');');
    td.title = oButtons[4].childNodes[0].childNodes[0].nodeValue
    // current month
    tbCal.rows[2].cells[1].innerHTML = strMonth;
    // +1
    td = tbCal.rows[2].cells[2]
    td.onclick = new Function('navigatePicker(\'' + strBase + '\', \'' + strLanguage + '\', \'' + oButtons[5].childNodes[1].childNodes[0].nodeValue + '\');');
    td.title = oButtons[5].childNodes[0].childNodes[0].nodeValue
    
    for(n = 0; n < 7; n++){
        tbCal.rows[3].cells[n + 1].innerHTML = oWeekDays[n].childNodes[0].nodeValue.substring(0,1);
        tbCal.rows[3].cells[n + 1].title = oWeekDays[n].childNodes[0].nodeValue;
    }
    
    for(n = 0; n < oDates.length; n++){
        oDate = oDates[n];
        if(oDate.childNodes[intWeekday].childNodes[0].nodeValue == '1'){
            tbCal.insertRow(tbCal.rows.length);
            tr = tbCal.rows[tbCal.rows.length - 1];
            tr.insertCell(tr.cells.length);
            td = tr.cells[tr.cells.length - 1];
            td.className = 'DPWeekNr';
            td.innerHTML = oDate.childNodes[intWeek].childNodes[0].nodeValue;
            td.title = strWeek + ' ' + oDate.childNodes[intWeek].childNodes[0].nodeValue;
        }
        tr.insertCell(tr.cells.length);
        td = tr.cells[tr.cells.length - 1];
        td.className = oDate.childNodes[intCss].childNodes[0].nodeValue;
        td.innerHTML = oDate.childNodes[intDay].childNodes[0].nodeValue;
        td.onclick = new Function('setPickerDate(\'' + strBase + '\', \'' + oDate.childNodes[intDisplay].childNodes[0].nodeValue + '\');');
        td.title = oWeekDays[parseInt(oDate.childNodes[intWeekday].childNodes[0].nodeValue) - 1].childNodes[0].nodeValue + ' ' + oDate.childNodes[intDay].childNodes[0].nodeValue + ' ' + oDate.childNodes[intMonthName].childNodes[0].nodeValue + ' ' + oDate.childNodes[intYear].childNodes[0].nodeValue;
    }
    x = Sys.UI.DomElement.getLocation(document.getElementById(strBase + 'txtDisplayDate')).x;
    y = Sys.UI.DomElement.getLocation(document.getElementById(strBase + 'txtDisplayDate')).y;
    
    Sys.UI.DomElement.setLocation(oPicker, x, y + 20);
    oPicker.style.display = 'block';
}

// * * * * Menu Tree * * * * //
var MT_ul = null;
function MT_AppendChilds(id, pid, mt, cmdID)
{
    var ID = 0;
    var intName = 1;
    var intTimer;
    var intURL = 2;
    var intChilds = 3;
    var t;
    var tbId;
    var n;
    var xmlItem;
    var xmlMenu = LoadXMLText(objAJAX.responseText);
    
    var img = document.getElementById(cmdID);
    var li = img.parentNode;
    var ul = document.createElement('ul');
    li.appendChild(ul);
    MT_ul = ul;
    
    for(n = 0; n < xmlMenu.childNodes[0].childNodes.length; n++)
    {
        intTimer = (n + 1) * 25;
        //MT_AppendItem(id, mt, tbId, xmlMenu.childNodes[0].childNodes[n].childNodes[ID].childNodes[0].nodeValue, xmlMenu.childNodes[0].childNodes[n].childNodes[intName].childNodes[0].nodeValue, xmlMenu.childNodes[0].childNodes[n].childNodes[intURL].childNodes[0].nodeValue, xmlMenu.childNodes[0].childNodes[n].childNodes[intChilds].childNodes[0].nodeValue);
        xmlItem = xmlMenu.childNodes[0].childNodes[n];
        setTimeout("MT_AppendItem('" + id + "', '" + mt + "', '" + ul.id + "', '" + xmlItem.childNodes[ID].childNodes[0].nodeValue + "', '" + xmlItem.childNodes[intName].childNodes[0].nodeValue + "', '" + xmlItem.childNodes[intURL].childNodes[0].nodeValue + "', '" + xmlItem.childNodes[intChilds].childNodes[0].nodeValue + "')", intTimer);
    }
    img.src = '/icons/trvmin.gif';
}

function MT_AppendItem(id, mt, ul, intMenuID, strName, strURL, intHasChilds)
{
    var image = '<img src="/icons/empty.gif"  height="16" width="16" alt="" />';
    if(intHasChilds != '0')
        image = '<img id="cmd' + intMenuID + '" src="/icons/trvplus.gif" height="16" width="16" alt="open" onclick="' + 
           'MT_ToggleChilds(\'' + id + '\', \'' + intMenuID + '\', \'' + mt + '\', this);" />';

    var li = document.createElement('li');
    li.id = 'li' + intMenuID;
    li.innerHTML = image + '<a href="' + strURL + '?ID=' + intMenuID + '" target="_self">' + strName + '</a>';
    MT_ul.appendChild(li);    
}

function MT_GetChilds(id, pid, mt, cmdID)
{    
    fAJAXResponse = new Function('MT_AppendChilds(\'' + id + '\', \'' + pid + '\', \'' + mt + '\', \'' + cmdID.id + '\');');
        
    getAJAXResponse('/controls/MenuTree/MenuTreeCallbacks.aspx?ID=' + id + '&pID=' + pid + '&mt=' + mt);
}

function MT_ShowOrHideChilds(liList, cmdID, show){
    var intTimer;
    var n;
    var src = !show ? 'plus' : 'min';
    show = !show ? 'none' : '';

    for(n = 0; n < liList.length; n++) {
        intTimer = (n + 1) * 25;
        setTimeout("document.getElementById('" + liList[n].id + "').style.display = '" + show + "'", intTimer);
    }
    cmdID.src = '/icons/trv' + src + '.gif';
}

function MT_ToggleChilds(id, pid, mt, cmdID)
{
    var li = cmdID.parentNode;
    // search for ul
    var ulList = li.getElementsByTagName('ul');
    if(ulList.length > 0) {
        var liList = ulList[0].getElementsByTagName('li');
        MT_ShowOrHideChilds(liList, cmdID, liList[0].style.display == 'none');
    } else {
        MT_GetChilds(id, pid, mt, cmdID);
    }
}

// * * * * Printing * * * * //
function printSpecial(blnAuto)
{
	if (document.getElementById != null){
		var html = '<HTML>\n<HEAD>\n';

		if (document.getElementsByTagName != null){
			var headTags = document.getElementsByTagName("head");
			if (headTags.length > 0){
				html += headTags[0].innerHTML;
			}
		}
		
		html += '\n</HE' + 'AD>\n<BODY>\n';
		
		var printReadyElem = document.getElementById("printReady");
		
		if (printReadyElem != null){
				html += printReadyElem.innerHTML;
		}else{
			alert("Could not find the printReady section in the HTML");
			return;
		}
			
		html += '\n</BO' + 'DY>\n</HT' + 'ML>';
		
		var printWin = window.open("","printSpecial");
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
		if (blnAuto){
			printWin.print();
		}
	}else{
		alert("Sorry, the print ready feature is only available in modern browsers.");
	}
}

// * * * * Email Validation * * * * //
function CheckEmail(strUrl, strFunction, id)
{
    if (id != null && id != '')
    {
        //alert(o);
        var value = document.getElementById(id).value;
        // alert(value);
        var strImgId = id.replace('txt1', 'imgStatus');
        //alert(strImgId);
        
	    imgStatus = document.getElementById(strImgId);
    	    
	    if (value==''){
	        imgStatus.src='/icons/cancel.gif';
	        return
	    }
    	    
	    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    	
	    if (filter.test(value)){
    	
	        // disable the textbox
	        document.getElementById(id).disabled = true;
    	    
	        var strHdnId = id.replace('txt1', 'hdnEmailCheckStatus');
	        hdnStatus = document.getElementById(strHdnId);
	        hdnStatus.value='0';

            imgStatus.src='/icons/loading.gif';
            //alert(strUrl);   
	        getResponse(strUrl, strFunction, id);   
	        //alert('called');          
       
        }
	    else{
    	
	        imgStatus.src='/icons/cancel.gif';
	        return    
	    }
	 }
}
// * * * * Password Validation * * * * //
function vnValidatePasswordStrength(source, args){
    var score = 0;
    var result;
    
    if(args.Value.length > 0){
        if(args.Value.length < 6){
            score = score - 1;
        }
        if(!args.Value.match(/[a-z_]/i) || !args.Value.match(/[0-9]/)){
            score = score - 1;
        }
//        if(!pass.match(/\W/)){
//          score = score - 1;
//        }
//        switch(score){
//            case 0:
//                result = 'Excellent';
//                break;
//            case -1:
//                result = 'Good';
//                break;
//            case -2:
//                result = 'Fair';
//                break;
//            default:
//                result = 'Poor';
//                break;
//        }
        if(score == 0) {
            args.IsValid = true;
        }else{
            args.IsValid = false;
        }
    }else{
       args.IsValid = true;
    }
}

// * * * * Validation * * * * //
var Page_Validators_Copy;
function addValidator(id){
    var n;
    for(n=0; n < Page_Validators_Copy.length; n++){
        if(Page_Validators_Copy[n].id.indexOf(id) >= 0){
            Page_Validators.push(Page_Validators_Copy[n]);
        }
    }
}

function disableFileUpload(){
    //alert('dis');
    var arrInput = document.getElementsByTagName('input');
    var n = 0;
    for(n = 0; n < arrInput.length; n++){
        //alert(arrInput[n].id);
        if(arrInput[n].type == 'file'){
            arrInput[n].disabled = true;
        }
    }
}

// * * * * XML * * * * //
function LoadXMLText(strText){
    var xmlDoc;

    if (window.ActiveXObject){
        // code for IE
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = "false";
        xmlDoc.loadXML(strText);
    }else if (document.implementation && document.implementation.createDocument){
        // code for Mozilla, Firefox, Opera, etc.
        var parser = new DOMParser();
        //xmlDoc.async = false;
        xmlDoc = parser.parseFromString(strText,"text/xml");
    }else{
        alert('Your browser cannot handle this script');
    }
    
    return(xmlDoc);
}

function FillFormByXML(oXML){
    var n;
    var oField;
    var oNode;
    
    if(oXML){
        if(oXML.firstChild.childNodes.length > 0){
            for(n = 0; n < oXML.firstChild.childNodes.length; n++){
                oNode= oXML.firstChild.childNodes[n];
                oField = document.getElementById(oNode.childNodes[0].firstChild.nodeValue);
                if(oField.type.toLowerCase() == 'radio'){
                    if(oNode.childNodes[1].childNodes.length > 0){;
                        if(oNode.childNodes[1].firstChild.nodeValue == '1'){
                            oField.checked = true;
                            document.getElementById(oNode.childNodes[0].firstChild.nodeValue.replace('Yes', 'No')).checked = false;
                        }else{
                            oField.checked = false;
                            document.getElementById(oNode.childNodes[0].firstChild.nodeValue.replace('Yes', 'No')).checked = true;
                        }
                    }
                }else{
                    if(oNode.childNodes[1].childNodes.length > 0){;
                        oField.value = oNode.childNodes[1].firstChild.nodeValue;
                    }else{
                        oField.value = '';
                    }
                }
            }
        }
    }
}

function ClearList(listID){
    var lb;
    var n;
    
    lb = document.getElementById(listID);
    
    for(n = lb.options.length - 1; n > -1; n--){
		lb.options[n] = null;
	}
}

function FillListByXML(listID, oXML){
    var lb;
    var li;
    var n;
    var oNode;
    
    if(oXML){
        if(oXML.firstChild.childNodes.length > 0){
            
            lb = document.getElementById(listID);
            
            for(n = 0; n < oXML.firstChild.childNodes.length; n++){
		        oNode = oXML.firstChild.childNodes[n];
		        li = new Option(oNode.childNodes[1].firstChild.nodeValue, oNode.childNodes[0].firstChild.nodeValue, false, false);
		        lb.options[lb.length] = li;
            }
        }
    }
}

function GetWindowHeight()
{
    if (nav){ 
        return window.innerHeight;
    }
    else{
	}
}
function GetWindowWidth()
{
    if (nav){ 
        return window.innerWidth;
    }else{
      return document.body.offsetWidth;
    }
}

// * * * * MaxLangth function for textarea * * * * //
function ismaxlength(obj)
{
    var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
    if (obj.getAttribute && obj.value.length>mlength)
    {
        obj.value=obj.value.substring(0,mlength)
    }
}

/* clears a dropdown list */
function clearSelectList(select_id)
{
    var select = document.getElementById(select_id);
    select.options.length = 0;
}

/********************************************************************************************
    specific functions for Invoice and Contract
********************************************************************************************/
var url = document.location.href;
var start = url.indexOf("?");
if(start > 0) url = url.substring(0, start);
var rowcount = 1;
function fillInvoiceRow(rowId) {
    var row = document.getElementById(rowId);
    if(!row) return;
    var values = objAJAX.responseText.split('|');
    fillInput(row.cells[2], values[0]);
    fillInput(row.cells[3], values[1]);
    fillInput(row.cells[4], values[2]);
    row.cells[5].innerHTML = parseFloat(values[1]) * parseFloat(values[2]);
    row.cells[6].innerHTML = values[4] + '%';
    math(row);
    addInvoiceRow(row);
}
function fillInput(cell, value) {
    var input = cell.getElementsByTagName('input');
    if(input) input[0].value = value;
}
function addInvoiceRow(row) {
    var rows = row.parentNode.rows;
    var last = rows[rowcount];
    if((last.className == 'show' && last.cells[1].getElementsByTagName('select')[0].value == '')) return;
    rowcount++;
    rows[rowcount].className = 'show';
}
function getProduct(obj) {
    var id = obj.parentNode.parentNode.id;
    fAJAXResponse = new Function("fillInvoiceRow('" + id + "');");
    sendAJAX(url, "productID=" + obj.value + "&rowID=" + id);
}
function math(obj) {
    var row = obj.tagName == 'TR' ? obj : obj.parentNode.parentNode;
    var count = parseFloat(0 + row.cells[3].getElementsByTagName('input')[0].value.replace(/_/ig,''));
    var price = parseFloat(0 + row.cells[4].getElementsByTagName('input')[0].value.replace(/_/ig,''));
    var total = (count * price).toFixed(2);
    row.cells[5].innerHTML = '&euro;' + total;
    row.cells[7].innerHTML = '&euro;' + (total * parseFloat('1.' + row.cells[6].innerHTML.replace('%',''))).toFixed(2);
    var tdAmount = document.getElementById('tdAmount');
    var tdVat = document.getElementById('tdVat');
    var tdAmountTotal = document.getElementById('tdAmountTotal');
    if(!tdAmount || !tdVat || !tdAmountTotal) return;
    var amount = 0;
    var vat = 0;
    var rows = row.parentNode.rows;
    for(i=1; i<rows.length-1; i++) {
        var cell5 = rows[i].cells[5].innerHTML;
        if(cell5 == '0' || cell5 == '') continue;
        var a = parseFloat(0 + rows[i].cells[5].innerHTML.substr(1));
        var v = parseFloat('0.' + rows[i].cells[6].innerHTML.replace('%',''));
        amount += a;
        vat += (a * v);
    }
    tdAmount.innerHTML = '&euro;' + amount.toFixed(2);
    tdVat.innerHTML = '&euro;' + vat.toFixed(2);
    tdAmountTotal.innerHTML = '&euro;' + (amount + vat).toFixed(2);
}